Complete clipboard support for TStringGrid in case of multiple selections
Original Reporter info from Mantis: wp @wpam
-
Reporter name:
Original Reporter info from Mantis: wp @wpam
- Reporter name:
Description:
Some time ago, the feature of using multiple selections was added to the TCustomGrid component family. Clipboard support, however, is not complete for multiple selections: Currently the copy operation transfers only the first selected range to the clipboard, and pasting is even blocked in case of multiple selections.
The provided patch completes clipboard support for the case of multiple selections:
The virtual method "DoCopyToClipboard" calculates the union of all selected ranges and passes this rectangle to the "CopyCellRectToClipboard" method which appends all cell strings to a csv-string for the clipboard. The union operation is needed because cells must be in the clipboard in an ordered fashion, line by line, left to right, top to bottom. This is because the simple csv clipboard format does not provide information on the cell coordinates. To prevent non-selected cells within the union block from being written to the clipboard the method "CopyCellRectToClipboard" has got a new (optional) parameter, "SelectedOnly", which restricts the generation of the clipboard string to the selected cells only.
When pasting non-contiguous multiple selections back to the grid it could happen that cells are erased by empty clipboard cells between the formerly selected blocks. The patch does not allow this and does not write empty cells back to the grid at all. For cases in which this is not desired a set of "TClipboardOptions" was introduced in which the (so far only) element "coPasteEmptyCell" can activate pasting of empty cells.
I am not 100% happy with the pasting function, but I do not see a way to overcome the issue with the missing cell coordinates without introducing a special clipboard format (which can cause a lot of other trouble as I see with fpspreadsheet).
Mantis conversion info:
- Mantis ID: 28755
- Version: 1.5 (SVN)
- Monitored by: » @flyingsheep (Bart Broersma)