You've already forked lazarus-ccr
fpspreadsheet: Fix severe speed issue in WorksheetGrid (unnecessarily seeking last sheet column in DrawRow, needed for cell text overflow).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4039 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -59,6 +59,13 @@
|
|||||||
<OtherUnitFiles Value="..\..\.."/>
|
<OtherUnitFiles Value="..\..\.."/>
|
||||||
<UnitOutputDirectory Value="..\..\lib\$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="..\..\lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
|
<Linking>
|
||||||
|
<Options>
|
||||||
|
<Win32>
|
||||||
|
<GraphicApplication Value="True"/>
|
||||||
|
</Win32>
|
||||||
|
</Options>
|
||||||
|
</Linking>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
<Debugging>
|
<Debugging>
|
||||||
<Exceptions Count="3">
|
<Exceptions Count="3">
|
||||||
|
@ -7,7 +7,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
||||||
StdCtrls, ComCtrls, ExtCtrls, Grids, Buttons, Menus, ActnList, StdActns,
|
StdCtrls, ComCtrls, ExtCtrls, Grids, Buttons, Menus, ActnList, StdActns,
|
||||||
fpstypes, fpspreadsheet, fpspreadsheetctrls, fpSpreadsheetGrid, fpsActions;
|
fpsTypes, fpSpreadsheet, fpSpreadsheetCtrls, fpSpreadsheetGrid, fpsActions;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
@ -98,9 +98,9 @@ type
|
|||||||
FLeftPaneWidth: Integer;
|
FLeftPaneWidth: Integer;
|
||||||
FTopPaneHeight: Integer;
|
FTopPaneHeight: Integer;
|
||||||
FOptions: TsSheetOptions;
|
FOptions: TsSheetOptions;
|
||||||
FLastFoundCell: PCell;
|
// FLastFoundCell: PCell;
|
||||||
FLastFoundRow: Cardinal;
|
// FLastFoundRow: Cardinal;
|
||||||
FLastFoundCol: Cardinal;
|
// FLastFoundCol: Cardinal;
|
||||||
FFirstRowIndex: Cardinal;
|
FFirstRowIndex: Cardinal;
|
||||||
FFirstColIndex: Cardinal;
|
FFirstColIndex: Cardinal;
|
||||||
FLastRowIndex: Cardinal;
|
FLastRowIndex: Cardinal;
|
||||||
@ -1108,9 +1108,9 @@ begin
|
|||||||
FActiveCellRow := Cardinal(-1);
|
FActiveCellRow := Cardinal(-1);
|
||||||
FActiveCellCol := Cardinal(-1);
|
FActiveCellCol := Cardinal(-1);
|
||||||
|
|
||||||
FLastFoundCell := nil;
|
{ FLastFoundCell := nil;
|
||||||
FLastFoundRow := Cardinal(-1);
|
FLastFoundRow := Cardinal(-1);
|
||||||
FLastFoundCol := Cardinal(-1);
|
FLastFoundCol := Cardinal(-1);}
|
||||||
|
|
||||||
FOptions := [soShowGridLines, soShowHeaders];
|
FOptions := [soShowGridLines, soShowHeaders];
|
||||||
end;
|
end;
|
||||||
@ -2085,7 +2085,7 @@ begin
|
|||||||
FLastFoundRow := ARow;
|
FLastFoundRow := ARow;
|
||||||
FLastFoundCol := ACol;
|
FLastFoundCol := ACol;
|
||||||
end;
|
end;
|
||||||
}
|
}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
@ -816,30 +816,22 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsWorkbookSource.InternalLoadFromFile(AFileName: string;
|
procedure TsWorkbookSource.InternalLoadFromFile(AFileName: string;
|
||||||
AAutoDetect: Boolean; AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer = 0);
|
AAutoDetect: Boolean; AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer = 0);
|
||||||
var
|
|
||||||
t: TTime;
|
|
||||||
begin
|
begin
|
||||||
// Create a new empty workbook
|
// Create a new empty workbook
|
||||||
t := now;
|
|
||||||
InternalCreateNewWorkbook;
|
InternalCreateNewWorkbook;
|
||||||
DebugLn(Format('[Timer] Create workbook: %.3f sec', [(now-t)*24*3600]));
|
|
||||||
|
|
||||||
DisableControls;
|
DisableControls;
|
||||||
try
|
try
|
||||||
t := Now;
|
|
||||||
// Read workbook from file and get worksheet
|
// Read workbook from file and get worksheet
|
||||||
if AAutoDetect then
|
if AAutoDetect then
|
||||||
FWorkbook.ReadFromFile(AFileName)
|
FWorkbook.ReadFromFile(AFileName)
|
||||||
else
|
else
|
||||||
FWorkbook.ReadFromFile(AFileName, AFormat);
|
FWorkbook.ReadFromFile(AFileName, AFormat);
|
||||||
DebugLn(Format('[Timer] Read file: %.3f sec', [(now-t)*24*3600]))
|
|
||||||
finally
|
finally
|
||||||
EnableControls;
|
EnableControls;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
t := now;
|
|
||||||
SelectWorksheet(FWorkbook.GetWorkSheetByIndex(AWorksheetIndex));
|
SelectWorksheet(FWorkbook.GetWorkSheetByIndex(AWorksheetIndex));
|
||||||
DebugLn(Format('[Timer] Select worksheet: %.3f sec', [(now-t)*24*3600]));
|
|
||||||
|
|
||||||
// If required, display loading error message
|
// If required, display loading error message
|
||||||
if FWorkbook.ErrorMsg <> '' then
|
if FWorkbook.ErrorMsg <> '' then
|
||||||
|
@ -1454,7 +1454,6 @@ var
|
|||||||
tmp: Integer = 0;
|
tmp: Integer = 0;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
|
||||||
Canvas.SaveHandleState;
|
Canvas.SaveHandleState;
|
||||||
try
|
try
|
||||||
// Avoid painting into the header cells
|
// Avoid painting into the header cells
|
||||||
@ -1463,15 +1462,12 @@ begin
|
|||||||
ColRowToOffset(True, True, FixedCols-1, tmp, cliprect.Left);
|
ColRowToOffset(True, True, FixedCols-1, tmp, cliprect.Left);
|
||||||
if FixedRows > 0 then
|
if FixedRows > 0 then
|
||||||
ColRowToOffset(False, True, FixedRows-1, tmp, cliprect.Top);
|
ColRowToOffset(False, True, FixedRows-1, tmp, cliprect.Top);
|
||||||
|
|
||||||
DrawFrozenPaneBorders(clipRect);
|
DrawFrozenPaneBorders(clipRect);
|
||||||
|
|
||||||
rgn := CreateRectRgn(cliprect.Left, cliprect.top, cliprect.Right, cliprect.Bottom);
|
rgn := CreateRectRgn(cliprect.Left, cliprect.top, cliprect.Right, cliprect.Bottom);
|
||||||
SelectClipRgn(Canvas.Handle, Rgn);
|
SelectClipRgn(Canvas.Handle, Rgn);
|
||||||
|
|
||||||
DrawCellBorders;
|
DrawCellBorders;
|
||||||
DrawSelection;
|
DrawSelection;
|
||||||
|
|
||||||
DeleteObject(rgn);
|
DeleteObject(rgn);
|
||||||
finally
|
finally
|
||||||
Canvas.RestoreHandleState;
|
Canvas.RestoreHandleState;
|
||||||
@ -1770,7 +1766,7 @@ end;
|
|||||||
procedure TsCustomWorksheetGrid.DrawRow(ARow: Integer);
|
procedure TsCustomWorksheetGrid.DrawRow(ARow: Integer);
|
||||||
var
|
var
|
||||||
gds: TGridDrawState;
|
gds: TGridDrawState;
|
||||||
sr, sr1,sc1,sr2,sc2: Cardinal; // sheet row/column
|
sr, sr1,sc1,sr2,sc2, scLastUsed: Cardinal; // sheet row/column
|
||||||
gr, gc, gcNext, gcLast, gc1, gc2, gcLastUsed: Integer; // grid row/column
|
gr, gc, gcNext, gcLast, gc1, gc2, gcLastUsed: Integer; // grid row/column
|
||||||
i: Integer;
|
i: Integer;
|
||||||
rct, saved_rct, temp_rct, commentcell_rct: TRect;
|
rct, saved_rct, temp_rct, commentcell_rct: TRect;
|
||||||
@ -1835,11 +1831,13 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
scLastused := Worksheet.GetLastColIndex;
|
||||||
sr := GetWorksheetRow(ARow);
|
sr := GetWorksheetRow(ARow);
|
||||||
|
|
||||||
// Draw columns in this row
|
// Draw columns in this row
|
||||||
with GCache.VisibleGrid do
|
with GCache.VisibleGrid do
|
||||||
begin
|
begin
|
||||||
|
gcLast := Right;
|
||||||
gc := Left;
|
gc := Left;
|
||||||
|
|
||||||
// Because of possible cell overflow from cells left of the visible range
|
// Because of possible cell overflow from cells left of the visible range
|
||||||
@ -1873,7 +1871,7 @@ begin
|
|||||||
gcLast := Right;
|
gcLast := Right;
|
||||||
if FTextOverflow and (sr <> Cardinal(-1)) and Assigned(Worksheet) then
|
if FTextOverflow and (sr <> Cardinal(-1)) and Assigned(Worksheet) then
|
||||||
begin
|
begin
|
||||||
gcLastUsed := GetGridCol(Worksheet.GetLastOccupiedColIndex);
|
gcLastUsed := GetGridCol(scLastUsed);
|
||||||
while (gcLast < ColCount-1) and (gcLast < gcLastUsed) do begin
|
while (gcLast < ColCount-1) and (gcLast < gcLastUsed) do begin
|
||||||
inc(gcLast);
|
inc(gcLast);
|
||||||
cell := Worksheet.FindCell(sr, GetWorksheetCol(gcLast));
|
cell := Worksheet.FindCell(sr, GetWorksheetCol(gcLast));
|
||||||
@ -3338,8 +3336,6 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
|
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
|
||||||
AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer);
|
AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer);
|
||||||
var
|
|
||||||
t: TTime;
|
|
||||||
begin
|
begin
|
||||||
if FOwnsWorkbook then
|
if FOwnsWorkbook then
|
||||||
FreeAndNil(FOwnedWorkbook);
|
FreeAndNil(FOwnedWorkbook);
|
||||||
@ -3350,17 +3346,9 @@ begin
|
|||||||
begin
|
begin
|
||||||
BeginUpdate;
|
BeginUpdate;
|
||||||
try
|
try
|
||||||
t := now;
|
|
||||||
CreateNewWorkbook;
|
CreateNewWorkbook;
|
||||||
DebugLn(Format('[Timer] Create workbook: %.3f sec', [(now - t)*24*3600]));
|
|
||||||
|
|
||||||
t := now;
|
|
||||||
Workbook.ReadFromFile(AFileName, AFormat);
|
Workbook.ReadFromFile(AFileName, AFormat);
|
||||||
DebugLn(Format('[Timer] Read file: %.3f sec', [(now - t)*24*3600]));
|
|
||||||
|
|
||||||
t := now;
|
|
||||||
LoadFromWorksheet(Workbook.GetWorksheetByIndex(AWorksheetIndex));
|
LoadFromWorksheet(Workbook.GetWorksheetByIndex(AWorksheetIndex));
|
||||||
DebugLn(Format('[Timer] Load into grid: %.3f sec', [(now - t)*24*3600]));
|
|
||||||
finally
|
finally
|
||||||
EndUpdate;
|
EndUpdate;
|
||||||
end;
|
end;
|
||||||
@ -3376,8 +3364,6 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
|
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
|
||||||
AWorksheetIndex: Integer);
|
AWorksheetIndex: Integer);
|
||||||
var
|
|
||||||
t: TTime;
|
|
||||||
begin
|
begin
|
||||||
if FOwnsWorkbook then
|
if FOwnsWorkbook then
|
||||||
FreeAndNil(FOwnedWorkbook);
|
FreeAndNil(FOwnedWorkbook);
|
||||||
@ -3388,17 +3374,9 @@ begin
|
|||||||
begin
|
begin
|
||||||
BeginUpdate;
|
BeginUpdate;
|
||||||
try
|
try
|
||||||
t := now;
|
|
||||||
CreateNewWorkbook;
|
CreateNewWorkbook;
|
||||||
DebugLn(Format('[Timer] Create workbook: %.3f sec', [(now - t)*24*3600]));
|
|
||||||
|
|
||||||
t := now;
|
|
||||||
Workbook.ReadFromFile(AFilename);
|
Workbook.ReadFromFile(AFilename);
|
||||||
DebugLn(Format('[Timer] Read file: %.3f sec', [(now - t)*24*3600]));
|
|
||||||
|
|
||||||
t := now;
|
|
||||||
LoadFromWorksheet(Workbook.GetWorksheetByIndex(AWorksheetIndex));
|
LoadFromWorksheet(Workbook.GetWorksheetByIndex(AWorksheetIndex));
|
||||||
DebugLn(Format('[Timer] Load into grid: %.3f sec', [(now - t)*24*3600]));
|
|
||||||
finally
|
finally
|
||||||
EndUpdate;
|
EndUpdate;
|
||||||
end;
|
end;
|
||||||
@ -3678,12 +3656,12 @@ end;
|
|||||||
|
|
||||||
@param AFileName Name of the file to which the workbook is to be
|
@param AFileName Name of the file to which the workbook is to be
|
||||||
saved
|
saved
|
||||||
If the file format is not known is is written
|
If the file format is not known it is written
|
||||||
as BIFF8/XLS.
|
as BIFF8/XLS.
|
||||||
@param AOverwriteExisting If this file already exists it is overwritten if
|
@param AOverwriteExisting If this file already exists it is overwritten if
|
||||||
AOverwriteExisting = true, or an exception is
|
AOverwriteExisting = true, or an exception is
|
||||||
raised if AOverwriteExisting = false.
|
raised if AOverwriteExisting = false.
|
||||||
}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsCustomWorksheetGrid.SaveToSpreadsheetFile(AFileName: String;
|
procedure TsCustomWorksheetGrid.SaveToSpreadsheetFile(AFileName: String;
|
||||||
AOverwriteExisting: Boolean = true);
|
AOverwriteExisting: Boolean = true);
|
||||||
begin
|
begin
|
||||||
|
Reference in New Issue
Block a user