From 0b6a62b46c211f888b37d1621395892a68f4a4c3 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 19 Jan 2016 19:34:28 +0000 Subject: [PATCH] fpspreadsheet: Fix painting artefacts of TsWorksheetGrid when resizing col widths or row heights by dragging with mouse. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4443 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../fpspreadsheet/fpspreadsheetgrid.pas | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index 11ed2af99..21049d1fd 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -193,6 +193,7 @@ type function GetEditText(ACol, ARow: Integer): String; override; function GetDefaultHeaderColWidth: Integer; function HasBorder(ACell: PCell; ABorder: TsCellBorder): Boolean; + procedure HeaderSizing(const IsColumn:boolean; const AIndex,ASize:Integer); override; procedure HeaderSized(IsColumn: Boolean; AIndex: Integer); override; procedure InternalDrawTextInCell(AText: String; ARect: TRect; ACellHorAlign: TsHorAlignment; ACellVertAlign: TsVertAlignment; @@ -611,6 +612,8 @@ type {@@ inherited from ancestors} property OnHeaderSized; {@@ inherited from ancestors} + property OnHeaderSizing; + {@@ inherited from ancestors} property OnKeyDown; {@@ inherited from ancestors} property OnKeyPress; @@ -3224,6 +3227,46 @@ begin Result := ABorder in Worksheet.ReadCellBorders(ACell); end; +{@@ ---------------------------------------------------------------------------- + HeaderSizing is called while a column width or row height is resized by the + mouse. Is overridden here to enforce a grid repaint if merged cells are + affected by the resizing column/row. Otherwise parts of the merged cells would + not be updated if the cell text moves during the resizing action. +-------------------------------------------------------------------------------} +procedure TsCustomWorksheetGrid.HeaderSizing(const IsColumn:boolean; + const AIndex,ASize:Integer); +var + gc, gr: Integer; + sc, sr, sr1, sr2, sc1, sc2, si: Cardinal; + cell: PCell; +begin + inherited; + + if Worksheet = nil then + exit; + + // replaint the grid if merged cells are affected by the resizing col/row. + si := IfThen(IsColumn, GetWorksheetCol(AIndex), GetWorksheetRow(AIndex)); + for gc := GetFirstVisibleColumn to GetLastVisibleColumn do + begin + sc := GetWorksheetCol(gc); + for gr := GetFirstVisibleRow to GetLastVisibleRow do + begin + sr := GetWorksheetRow(gr); + cell := Worksheet.FindCell(gr, gc); + if Worksheet.IsMerged(cell) then begin + Worksheet.FindMergedRange(cell, sr1, sc1, sr2, sc2); + if IsColumn and InRange(si, sc1, sc2) or + (not IsColumn) and InRange(si, sr1, sr2) then + begin + InvalidateGrid; + exit; + end; + end; + end; + end; +end; + {@@ ---------------------------------------------------------------------------- Inherited from TCustomGrid. Is called when column widths or row heights have changed. Stores the new column width or row height in the worksheet.