Merge implementation

The points was considered during designing the merge implementation

  • Faster way to find boundary of merged range (when user clicked inside a cell) - When control receives mouse events, mouse-down or mouse-over, a full entire merged range should be selected, rather than a single cell. It is need to check whether the cell which has been clicked, is a part of merged range, and if it is, how to find the range quickly.
  • Grid lines drawing should be skipped inner a merged range - By default a spreadsheet will draw the horizontal and vertical grid lines to fill the view-port which displayed to user. But the grid lines should be skipped inside merged ranges, although the merged range displayed without any back color filled.

Before merge

Specify a logical range by predefined struct, which has a start position and an end position.
31.png

After merge

32.png
Two cells are defined as special cells, one is called merge-start-cell, another one is merge-end-cell. They are defined at the position top-left and bottom-right of the merged range.
All of cells in this range will be initialized instantly, and they will keeping two pointers reference to the merge-start-cell and merge-end-cell.
34.png
When user clicked inside any cells which is contained by a range, now it is possible to find the range by two pointers, merge-start-cell and merge-end-cell. This is very fast.

Grid lines skipping

It is need to skip drawing the grid lines inside any merged range. A grid lines skipped image like:
32.png
When there is a merged cell has been found during drawing, the skipping span can be calculated by
int skips = merge-end-cell.col - merge-start-cell.col;

33.png

Last edited Jan 14, 2014 at 3:47 PM by unvell, version 6