fpspreadsheet: Significantly speed up zooming of large worksheets

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5258 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-10-12 18:00:56 +00:00
parent e0df72b82d
commit bdeef86e41
2 changed files with 11 additions and 5 deletions

View File

@ -127,10 +127,12 @@ procedure TMainForm.GridMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin begin
if ([ssCtrl, ssShift] * Shift = [ssCtrl, ssShift]) then begin if ([ssCtrl, ssShift] * Shift = [ssCtrl, ssShift]) then begin
//Grid.BeginUpdate;
if WheelDelta > 0 then if WheelDelta > 0 then
Grid.ZoomFactor := Grid.ZoomFactor * MOUSEWHEEL_FACTOR Grid.ZoomFactor := Grid.ZoomFactor * MOUSEWHEEL_FACTOR
else else
Grid.ZoomFactor := Grid.ZoomFactor / MOUSEWHEEL_FACTOR; Grid.ZoomFactor := Grid.ZoomFactor / MOUSEWHEEL_FACTOR;
//Grid.EndUpdate;
edZoom.Value := round(Grid.ZoomFactor * 100); edZoom.Value := round(Grid.ZoomFactor * 100);
Handled := true; Handled := true;
end; end;

View File

@ -281,9 +281,9 @@ type
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure BeginUpdate;
procedure AutoColWidth(ACol: Integer); procedure AutoColWidth(ACol: Integer);
procedure AutoRowHeight(ARow: Integer); procedure AutoRowHeight(ARow: Integer);
procedure BeginUpdate;
function CellRect(ACol1, ARow1, ACol2, ARow2: Integer): TRect; overload; function CellRect(ACol1, ARow1, ACol2, ARow2: Integer): TRect; overload;
procedure Clear; procedure Clear;
procedure DefaultDrawCell(ACol, ARow: Integer; var ARect: TRect; procedure DefaultDrawCell(ACol, ARow: Integer; var ARect: TRect;
@ -291,7 +291,7 @@ type
procedure DeleteCol(AGridCol: Integer); reintroduce; procedure DeleteCol(AGridCol: Integer); reintroduce;
procedure DeleteRow(AGridRow: Integer); reintroduce; procedure DeleteRow(AGridRow: Integer); reintroduce;
procedure EditingDone; override; procedure EditingDone; override;
procedure EndUpdate; procedure EndUpdate(ARefresh: Boolean = true);
function GetGridCol(ASheetCol: Cardinal): Integer; inline; function GetGridCol(ASheetCol: Cardinal): Integer; inline;
function GetGridRow(ASheetRow: Cardinal): Integer; inline; function GetGridRow(ASheetRow: Cardinal): Integer; inline;
procedure GetSheets(const ASheets: TStrings); procedure GetSheets(const ASheets: TStrings);
@ -1173,6 +1173,7 @@ end;
procedure TsCustomWorksheetGrid.BeginUpdate; procedure TsCustomWorksheetGrid.BeginUpdate;
begin begin
inc(FLockCount); inc(FLockCount);
inherited BeginUpdate;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -2630,10 +2631,12 @@ end;
Call BeginUpdate to stop refreshing the grid, and call EndUpdate to release Call BeginUpdate to stop refreshing the grid, and call EndUpdate to release
the lock and to repaint the grid again. the lock and to repaint the grid again.
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsCustomWorksheetGrid.EndUpdate; procedure TsCustomWorksheetGrid.EndUpdate(ARefresh: Boolean = true);
begin begin
inherited EndUpdate(false);
dec(FLockCount); dec(FLockCount);
if FLockCount = 0 then Invalidate; if (FLockCount = 0) and ARefresh then
VisualChange;
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -5987,9 +5990,10 @@ end;
procedure TsCustomWorksheetGrid.SetZoomFactor(AValue: Double); procedure TsCustomWorksheetGrid.SetZoomFactor(AValue: Double);
begin begin
if (AValue <> GetZoomFactor) and Assigned(Worksheet) then begin if (AValue <> GetZoomFactor) and Assigned(Worksheet) then begin
BeginUpdate;
try try
Worksheet.ZoomFactor := abs(AValue); Worksheet.ZoomFactor := abs(AValue);
AdaptToZoomFactor; // AdaptToZoomFactor;
finally finally
EndUpdate; EndUpdate;
end; end;