You've already forked lazarus-ccr
fpspreadsheet: Unless enforced, no row height calculation for rows without row record. Remove useless Disable/EnableControls methods of TsWorkbookSource.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5256 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -409,6 +409,7 @@ type
|
|||||||
function GetLastRowNumber: Cardinal; deprecated 'Use GetLastRowIndex';
|
function GetLastRowNumber: Cardinal; deprecated 'Use GetLastRowIndex';
|
||||||
|
|
||||||
{ Data manipulation methods - For Rows and Cols }
|
{ Data manipulation methods - For Rows and Cols }
|
||||||
|
function AddRow(ARow: Cardinal): PRow;
|
||||||
function CalcAutoRowHeight(ARow: Cardinal): Single;
|
function CalcAutoRowHeight(ARow: Cardinal): Single;
|
||||||
function CalcRowHeight(ARow: Cardinal): Single;
|
function CalcRowHeight(ARow: Cardinal): Single;
|
||||||
function FindRow(ARow: Cardinal): PRow;
|
function FindRow(ARow: Cardinal): PRow;
|
||||||
@ -6399,7 +6400,19 @@ end;
|
|||||||
function TsWorksheet.GetRow(ARow: Cardinal): PRow;
|
function TsWorksheet.GetRow(ARow: Cardinal): PRow;
|
||||||
begin
|
begin
|
||||||
Result := FindRow(ARow);
|
Result := FindRow(ARow);
|
||||||
if (Result = nil) then begin
|
if (Result = nil) then
|
||||||
|
Result := AddRow(ARow);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Creates a new row record for the specific row index. It is not checked whether
|
||||||
|
a row record already exists for this index. Dupliate records must be avoided!
|
||||||
|
|
||||||
|
@param ARow Index of the row considered
|
||||||
|
@return Pointer to the row record with this row index.
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
function TsWorksheet.AddRow(ARow: Cardinal): PRow;
|
||||||
|
begin
|
||||||
Result := GetMem(SizeOf(TRow));
|
Result := GetMem(SizeOf(TRow));
|
||||||
FillChar(Result^, SizeOf(TRow), #0);
|
FillChar(Result^, SizeOf(TRow), #0);
|
||||||
Result^.Row := ARow;
|
Result^.Row := ARow;
|
||||||
@ -6408,7 +6421,6 @@ begin
|
|||||||
FLastRowIndex := GetLastRowIndex(true)
|
FLastRowIndex := GetLastRowIndex(true)
|
||||||
else
|
else
|
||||||
FLastRowIndex := Max(FLastRowIndex, ARow);
|
FLastRowIndex := Max(FLastRowIndex, ARow);
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
@ -64,7 +64,7 @@ type
|
|||||||
FUserFileFormatID: TsSpreadFormatID;
|
FUserFileFormatID: TsSpreadFormatID;
|
||||||
FPendingSelection: TsCellRangeArray;
|
FPendingSelection: TsCellRangeArray;
|
||||||
FPendingOperation: TsCopyOperation;
|
FPendingOperation: TsCopyOperation;
|
||||||
FControlLockCount: Integer;
|
// FControlLockCount: Integer;
|
||||||
FOptions: TsWorkbookOptions;
|
FOptions: TsWorkbookOptions;
|
||||||
FOnError: TsWorkbookSourceErrorEvent;
|
FOnError: TsWorkbookSourceErrorEvent;
|
||||||
|
|
||||||
@ -128,8 +128,8 @@ type
|
|||||||
procedure SaveToSpreadsheetFile(AFileName: string; AFormatID: TsSpreadFormatID;
|
procedure SaveToSpreadsheetFile(AFileName: string; AFormatID: TsSpreadFormatID;
|
||||||
AOverwriteExisting: Boolean = true); overload;
|
AOverwriteExisting: Boolean = true); overload;
|
||||||
|
|
||||||
procedure DisableControls;
|
// procedure DisableControls;
|
||||||
procedure EnableControls;
|
// procedure EnableControls;
|
||||||
|
|
||||||
procedure SelectCell(ASheetRow, ASheetCol: Cardinal);
|
procedure SelectCell(ASheetRow, ASheetCol: Cardinal);
|
||||||
procedure SelectWorksheet(AWorkSheet: TsWorksheet);
|
procedure SelectWorksheet(AWorkSheet: TsWorksheet);
|
||||||
@ -779,14 +779,14 @@ begin
|
|||||||
FWorksheet := FWorkbook.AddWorksheet(Format(rsDefaultSheetName,[1]));
|
FWorksheet := FWorkbook.AddWorksheet(Format(rsDefaultSheetName,[1]));
|
||||||
SelectWorksheet(FWorksheet);
|
SelectWorksheet(FWorksheet);
|
||||||
end;
|
end;
|
||||||
|
(*
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Disables notification of listening controls
|
Disables notification of listening controls
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsWorkbookSource.DisableControls;
|
procedure TsWorkbookSource.DisableControls;
|
||||||
begin
|
begin
|
||||||
inc(FControlLockCount);
|
inc(FControlLockCount);
|
||||||
end;
|
end; *)
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
An error has occured during loading of the workbook. Shows a message box by
|
An error has occured during loading of the workbook. Shows a message box by
|
||||||
@ -804,14 +804,14 @@ begin
|
|||||||
else
|
else
|
||||||
MessageDlg(AErrorMsg, mtError, [mbOK], 0);
|
MessageDlg(AErrorMsg, mtError, [mbOK], 0);
|
||||||
end;
|
end;
|
||||||
|
(*
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Enables notification of listening controls
|
Enables notification of listening controls
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsWorkbookSource.EnableControls;
|
procedure TsWorkbookSource.EnableControls;
|
||||||
begin
|
begin
|
||||||
dec(FControlLockCount);
|
dec(FControlLockCount);
|
||||||
end;
|
end; *)
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Executes a "pending operation"
|
Executes a "pending operation"
|
||||||
@ -969,12 +969,13 @@ begin
|
|||||||
book.ReadFromFile(AFileName, AFormatID);
|
book.ReadFromFile(AFileName, AFormatID);
|
||||||
except
|
except
|
||||||
book.AddErrorMsg(rsCannotReadFile, [AFileName]);
|
book.AddErrorMsg(rsCannotReadFile, [AFileName]);
|
||||||
// Code executed subsequently will be a pain if there is no worksheet!
|
// Code executed subsequently will be a pain if there is no worksheet! --> Add one.
|
||||||
if book.GetWorksheetCount = 0 then
|
if book.GetWorksheetCount = 0 then
|
||||||
book.AddWorksheet(Format(rsDefaultSheetName, [1]));
|
book.AddWorksheet(Format(rsDefaultSheetName, [1]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
InternalLoadFromWorkbook(book, AWorksheetIndex);
|
InternalLoadFromWorkbook(book, AWorksheetIndex);
|
||||||
|
|
||||||
(*
|
(*
|
||||||
|
|
||||||
|
|
||||||
@ -1016,6 +1017,8 @@ end;
|
|||||||
procedure TsWorkbookSource.InternalLoadFromWorkbook(AWorkbook: TsWorkbook;
|
procedure TsWorkbookSource.InternalLoadFromWorkbook(AWorkbook: TsWorkbook;
|
||||||
AWorksheetIndex: Integer = -1);
|
AWorksheetIndex: Integer = -1);
|
||||||
begin
|
begin
|
||||||
|
AWorkbook.DisableNotifications;
|
||||||
|
|
||||||
InternalCreateNewWorkbook(AWorkbook);
|
InternalCreateNewWorkbook(AWorkbook);
|
||||||
WorkbookOpenedHandler(self);
|
WorkbookOpenedHandler(self);
|
||||||
|
|
||||||
@ -1027,6 +1030,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
SelectWorksheet(FWorkbook.GetWorksheetByIndex(AWorksheetIndex));
|
SelectWorksheet(FWorkbook.GetWorksheetByIndex(AWorksheetIndex));
|
||||||
|
|
||||||
|
AWorkbook.EnableNotifications;
|
||||||
|
|
||||||
// If required, display loading error message
|
// If required, display loading error message
|
||||||
if FWorkbook.ErrorMsg <> '' then
|
if FWorkbook.ErrorMsg <> '' then
|
||||||
DoShowError(FWorkbook.ErrorMsg);
|
DoShowError(FWorkbook.ErrorMsg);
|
||||||
|
@ -966,6 +966,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{*******************************************************************************
|
||||||
|
* TsSelPen *
|
||||||
|
*******************************************************************************}
|
||||||
constructor TsSelPen.Create;
|
constructor TsSelPen.Create;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
@ -973,6 +976,7 @@ begin
|
|||||||
JoinStyle := pjsMiter;
|
JoinStyle := pjsMiter;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{*******************************************************************************
|
{*******************************************************************************
|
||||||
* TsCustomWorksheetGrid *
|
* TsCustomWorksheetGrid *
|
||||||
*******************************************************************************}
|
*******************************************************************************}
|
||||||
@ -4475,6 +4479,7 @@ begin
|
|||||||
//Avoid crash when accessing the canvas, e.g. in GetDefaultHeaderColWidth
|
//Avoid crash when accessing the canvas, e.g. in GetDefaultHeaderColWidth
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Worksheet = nil) or (Worksheet.GetCellCount = 0) then begin
|
if (Worksheet = nil) or (Worksheet.GetCellCount = 0) then begin
|
||||||
FixedCols := FFrozenCols + FHeaderCount;
|
FixedCols := FFrozenCols + FHeaderCount;
|
||||||
FixedRows := FFrozenRows + FHeaderCount;
|
FixedRows := FFrozenRows + FHeaderCount;
|
||||||
@ -4824,13 +4829,15 @@ procedure TsCustomWorksheetGrid.UpdateRowHeight(ARow: Integer;
|
|||||||
AEnforceCalcRowHeight: Boolean = false);
|
AEnforceCalcRowHeight: Boolean = false);
|
||||||
var
|
var
|
||||||
lRow: PRow;
|
lRow: PRow;
|
||||||
|
sr: Cardinal;
|
||||||
h: Integer; // Row height, in pixels. Contains zoom factor.
|
h: Integer; // Row height, in pixels. Contains zoom factor.
|
||||||
doCalcRowHeight: Boolean;
|
doCalcRowHeight: Boolean;
|
||||||
begin
|
begin
|
||||||
h := 0;
|
h := 0;
|
||||||
if Worksheet <> nil then
|
if Worksheet <> nil then
|
||||||
begin
|
begin
|
||||||
lRow := Worksheet.FindRow(ARow - FHeaderCount);
|
sr := ARow - FHeaderCount; // worksheet row index
|
||||||
|
lRow := Worksheet.FindRow(sr);
|
||||||
if (lRow <> nil) then begin
|
if (lRow <> nil) then begin
|
||||||
case lRow^.RowHeightType of
|
case lRow^.RowHeightType of
|
||||||
rhtCustom:
|
rhtCustom:
|
||||||
@ -4856,11 +4863,13 @@ begin
|
|||||||
end; // case
|
end; // case
|
||||||
end else
|
end else
|
||||||
// No row record so far.
|
// No row record so far.
|
||||||
if Worksheet.GetCellCountInRow(ARow - FHeaderCount) > 0 then
|
if Worksheet.GetCellCountInRow(sr) > 0 then
|
||||||
begin
|
begin
|
||||||
// Case 1: This row does contain cells
|
// Case 1: This row does contain cells
|
||||||
lRow := Worksheet.GetRow(ARow - FHeaderCount);
|
lRow := Worksheet.AddRow(sr);
|
||||||
h := CalcAutoRowHeight(ARow);
|
if AEnforceCalcRowHeight then
|
||||||
|
h := CalcAutoRowHeight(ARow) else
|
||||||
|
h := DefaultRowHeight;
|
||||||
lRow^.Height := CalcRowHeightToSheet(round(h / ZoomFactor));
|
lRow^.Height := CalcRowHeightToSheet(round(h / ZoomFactor));
|
||||||
if h <> DefaultRowHeight then
|
if h <> DefaultRowHeight then
|
||||||
lRow^.RowHeightType := rhtAuto
|
lRow^.RowHeightType := rhtAuto
|
||||||
@ -5972,8 +5981,12 @@ 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
|
||||||
|
try
|
||||||
Worksheet.ZoomFactor := abs(AValue);
|
Worksheet.ZoomFactor := abs(AValue);
|
||||||
AdaptToZoomFactor;
|
AdaptToZoomFactor;
|
||||||
|
finally
|
||||||
|
EndUpdate;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user