From 99276082a3928bb5ee6e639c5d2046d626d4617d Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Mon, 16 Mar 2015 09:45:58 +0000 Subject: [PATCH] fpspreadsheet: Improved painting speed of TsWorksheetGrid for large files (draws borders and calculates row heights only for visual part of the grid) - still not perfect. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4038 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../visual/fpsctrls_no_install/demo_ctrls.lpi | 7 --- .../examples/visual/spready/spready.lpi | 8 --- .../fpspreadsheet/fpspreadsheetgrid.pas | 52 +++++++++++++++++-- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/components/fpspreadsheet/examples/visual/fpsctrls_no_install/demo_ctrls.lpi b/components/fpspreadsheet/examples/visual/fpsctrls_no_install/demo_ctrls.lpi index 8f6cb9564..8f924558f 100644 --- a/components/fpspreadsheet/examples/visual/fpsctrls_no_install/demo_ctrls.lpi +++ b/components/fpspreadsheet/examples/visual/fpsctrls_no_install/demo_ctrls.lpi @@ -59,13 +59,6 @@ - - - - - - - diff --git a/components/fpspreadsheet/examples/visual/spready/spready.lpi b/components/fpspreadsheet/examples/visual/spready/spready.lpi index 1b00b47b9..e46eaf3d7 100644 --- a/components/fpspreadsheet/examples/visual/spready/spready.lpi +++ b/components/fpspreadsheet/examples/visual/spready/spready.lpi @@ -27,13 +27,6 @@ - - - - - - - @@ -133,7 +126,6 @@ - diff --git a/components/fpspreadsheet/fpspreadsheetgrid.pas b/components/fpspreadsheet/fpspreadsheetgrid.pas index 0296a41ab..0282603e8 100644 --- a/components/fpspreadsheet/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/fpspreadsheetgrid.pas @@ -181,6 +181,7 @@ type procedure SetEditText(ACol, ARow: Longint; const AValue: string); override; procedure Setup; procedure Sort(AColSorting: Boolean; AIndex, AIndxFrom, AIndxTo:Integer); override; + procedure TopLeftChanged; override; function TrimToCell(ACell: PCell): String; procedure UpdateColWidths(AStartIndex: Integer = 0); procedure UpdateRowHeights(AStartIndex: Integer = 0); @@ -1483,22 +1484,41 @@ end; procedure TsCustomWorksheetGrid.DrawCellBorders; var cell: PCell; - c, r: Integer; + gc, gr: Integer; + sr1, sc1, sr2, sc2: Cardinal; rect: TRect; begin if Worksheet = nil then exit; + sr1 := GetWorksheetRow(GCache.VisibleGrid.Top); + sc1 := GetWorksheetCol(GCache.VisibleGrid.Left); + sr2 := GetWorksheetRow(GCache.VisibleGrid.Bottom); + sc2 := GetWorksheetCol(GCache.VisibleGrid.Right); + + for cell in Worksheet.Cells.GetRangeEnumerator(sr1, sc1, sr2, sc2) do + if (uffBorder in Worksheet.ReadUsedFormatting(cell)) then + begin + gc := GetGridCol(cell^.Col); + gr := GetGridRow(cell^.Row); + rect := CellRect(gc, gr); + DrawCellBorders(gc, gr, rect, cell); + end; + + { + gr := TopLeft.Y; + gc := TopLeft.X; for cell in Worksheet.Cells do begin if (uffBorder in Worksheet.ReadUsedFormatting(cell)) then begin - c := GetGridCol(cell^.Col); - r := GetGridRow(cell^.Row); - rect := CellRect(c, r); - DrawCellBorders(c, r, rect, cell); + gc := GetGridCol(cell^.Col); + gr := GetGridRow(cell^.Row); + rect := CellRect(gc, gr); + DrawCellBorders(gc, gr, rect, cell); end; end; + } end; {@@ ---------------------------------------------------------------------------- @@ -3810,6 +3830,17 @@ begin ); end; +{@@ ---------------------------------------------------------------------------- + Inherited method called whenever to grid is scrolled, i.e. the top/left cell + changes. + Is overridden to calculate the row heights of the currently visible grid +-------------------------------------------------------------------------------} +procedure TsCustomWorksheetGrid.TopLeftChanged; +begin + UpdateRowHeights; + inherited; +end; + {@@ ---------------------------------------------------------------------------- Modifies the text that is show for cells which are too narrow to hold the entire text. The method follows the behavior of Excel and Open/LibreOffice: @@ -3955,6 +3986,7 @@ var lRow: PRow; h: Integer; begin + { BeginUpdate; if AStartIndex <= 0 then AStartIndex := FHeaderCount; for i := AStartIndex to RowCount-1 do begin @@ -3968,6 +4000,16 @@ begin RowHeights[i] := h; end; EndUpdate; + } + for i:=GCache.VisibleGrid.Top to GCache.VisibleGrid.Bottom do begin + h := CalcAutoRowHeight(i); + if Worksheet <> nil then + begin + lRow := Worksheet.FindRow(i - FHeaderCount); + if (lRow <> nil) then + h := CalcRowHeight(lRow^.Height); + end; + end; end;