You've already forked lazarus-ccr
fpspreadsheet: Fix "row height 0" issue after one of the recent commits. Call row height calculation after scrolling.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5221 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -79,6 +79,8 @@ type
|
|||||||
FDefRowHeight100: Integer; // Default row height for 100% zoom factor, in pixels
|
FDefRowHeight100: Integer; // Default row height for 100% zoom factor, in pixels
|
||||||
FDefColWidth100: Integer; // Default col width for 100% zoom factor, in pixels
|
FDefColWidth100: Integer; // Default col width for 100% zoom factor, in pixels
|
||||||
FZoomLock: Integer;
|
FZoomLock: Integer;
|
||||||
|
FRowHeightLock: Integer;
|
||||||
|
FOldTopRow: Integer;
|
||||||
// FSetupDelayed: Boolean;
|
// FSetupDelayed: Boolean;
|
||||||
FOnClickHyperlink: TsHyperlinkClickEvent;
|
FOnClickHyperlink: TsHyperlinkClickEvent;
|
||||||
function CalcAutoRowHeight(ARow: Integer): Integer;
|
function CalcAutoRowHeight(ARow: Integer): Integer;
|
||||||
@ -980,19 +982,27 @@ end;
|
|||||||
@param AOwner Owner of the grid
|
@param AOwner Owner of the grid
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
constructor TsCustomWorksheetGrid.Create(AOwner: TComponent);
|
constructor TsCustomWorksheetGrid.Create(AOwner: TComponent);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
inc(FRowHeightLock);
|
||||||
|
|
||||||
FInternalWorkbookSource := TsWorkbookSource.Create(self);
|
FInternalWorkbookSource := TsWorkbookSource.Create(self);
|
||||||
FInternalWorkbookSource.Name := 'internal';
|
FInternalWorkbookSource.Name := 'internal';
|
||||||
|
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
|
|
||||||
AutoAdvance := aaDown;
|
AutoAdvance := aaDown;
|
||||||
ExtendedSelect := true;
|
ExtendedSelect := true;
|
||||||
FHeaderCount := 1;
|
FHeaderCount := 1;
|
||||||
ColCount := DEFAULT_COL_COUNT + FHeaderCount;
|
ColCount := DEFAULT_COL_COUNT + FHeaderCount;
|
||||||
RowCount := DEFAULT_ROW_COUNT + FHeaderCount;
|
RowCount := DEFAULT_ROW_COUNT + FHeaderCount;
|
||||||
|
FDefRowHeight100 := inherited DefaultRowHeight;
|
||||||
|
FDefColWidth100 := inherited DefaultColWidth;
|
||||||
|
//FOldTopRow := -1;
|
||||||
FCellFont := TFont.Create;
|
FCellFont := TFont.Create;
|
||||||
FSelPen := TsSelPen.Create;
|
FSelPen := TsSelPen.Create;
|
||||||
FSelPen.Style := psSolid;
|
FSelPen.Style := psSolid;
|
||||||
// FSelPen.Width := 3;
|
|
||||||
FSelPen.Color := clBlack;
|
FSelPen.Color := clBlack;
|
||||||
FSelPen.JoinStyle := pjsMiter;
|
FSelPen.JoinStyle := pjsMiter;
|
||||||
FSelPen.OnChange := @SelPenChangeHandler;
|
FSelPen.OnChange := @SelPenChangeHandler;
|
||||||
@ -1004,6 +1014,9 @@ begin
|
|||||||
{$IFNDEF FPS_NO_GRID_MULTISELECT}
|
{$IFNDEF FPS_NO_GRID_MULTISELECT}
|
||||||
RangeSelectMode := rsmMulti;
|
RangeSelectMode := rsmMulti;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
dec(FRowHeightLock);
|
||||||
|
UpdateRowHeights;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
@ -1550,6 +1563,8 @@ end;
|
|||||||
|
|
||||||
procedure TsCustomWorksheetGrid.DefineProperties(Filer: TFiler);
|
procedure TsCustomWorksheetGrid.DefineProperties(Filer: TFiler);
|
||||||
begin
|
begin
|
||||||
|
//inherited;
|
||||||
|
|
||||||
// Don't call inherited, this is where the ColWidths/RowHeights are written
|
// Don't call inherited, this is where the ColWidths/RowHeights are written
|
||||||
// to the lfm file - we don't need them, we get them from the workbook!
|
// to the lfm file - we don't need them, we get them from the workbook!
|
||||||
Unused(Filer);
|
Unused(Filer);
|
||||||
@ -3506,6 +3521,7 @@ procedure TsCustomWorksheetGrid.HeaderSized(IsColumn: Boolean; AIndex: Integer);
|
|||||||
const
|
const
|
||||||
EPS = 0.1;
|
EPS = 0.1;
|
||||||
var
|
var
|
||||||
|
idx: Integer;
|
||||||
w, h, wdef, hdef: Single;
|
w, h, wdef, hdef: Single;
|
||||||
begin
|
begin
|
||||||
if (Worksheet = nil) or (FZoomLock <> 0) then
|
if (Worksheet = nil) or (FZoomLock <> 0) then
|
||||||
@ -3515,14 +3531,20 @@ begin
|
|||||||
begin
|
begin
|
||||||
w := CalcWorksheetColWidth(ColWidths[AIndex]); // w and wdef are at 100% zoom
|
w := CalcWorksheetColWidth(ColWidths[AIndex]); // w and wdef are at 100% zoom
|
||||||
wdef := Worksheet.ReadDefaultColWidth(Workbook.Units);
|
wdef := Worksheet.ReadDefaultColWidth(Workbook.Units);
|
||||||
if not SameValue(w, wdef, EPS) then
|
if not SameValue(w, wdef, EPS) then begin
|
||||||
Worksheet.WriteColWidth(GetWorksheetCol(AIndex), w, Workbook.Units);
|
idx := GetWorksheetCol(AIndex);
|
||||||
|
if idx >= 0 then
|
||||||
|
Worksheet.WriteColWidth(GetWorksheetCol(AIndex), w, Workbook.Units);
|
||||||
|
end;
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
h := CalcWorksheetRowHeight(RowHeights[AIndex]);
|
h := CalcWorksheetRowHeight(RowHeights[AIndex]);
|
||||||
hdef := Worksheet.ReadDefaultRowHeight(Workbook.Units);
|
hdef := Worksheet.ReadDefaultRowHeight(Workbook.Units);
|
||||||
if not SameValue(h, hdef, EPS) then
|
if not SameValue(h, hdef, EPS) then begin
|
||||||
Worksheet.WriteRowHeight(GetWorksheetRow(AIndex), h, Workbook.Units);
|
idx := GetWorksheetRow(AIndex);
|
||||||
|
if idx >= 0 then
|
||||||
|
Worksheet.WriteRowHeight(GetWorksheetRow(AIndex), h, Workbook.Units);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3911,6 +3933,7 @@ end;
|
|||||||
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
|
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
|
||||||
AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer);
|
AFormat: TsSpreadsheetFormat; AWorksheetIndex: Integer);
|
||||||
begin
|
begin
|
||||||
|
ZoomFactor := 1.0;
|
||||||
GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AFormat, AWorksheetIndex);
|
GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AFormat, AWorksheetIndex);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3929,6 +3952,7 @@ end;
|
|||||||
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
|
procedure TsCustomWorksheetGrid.LoadFromSpreadsheetFile(AFileName: string;
|
||||||
AFormatID: TsSpreadFormatID = sfidUnknown; AWorksheetIndex: Integer = -1);
|
AFormatID: TsSpreadFormatID = sfidUnknown; AWorksheetIndex: Integer = -1);
|
||||||
begin
|
begin
|
||||||
|
ZoomFactor := 1.0;
|
||||||
GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AFormatID, AWorksheetIndex);
|
GetWorkbookSource.LoadFromSpreadsheetFile(AFileName, AFormatID, AWorksheetIndex);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3945,6 +3969,7 @@ end;
|
|||||||
procedure TsCustomWorksheetGrid.LoadSheetFromSpreadsheetFile(AFileName: String;
|
procedure TsCustomWorksheetGrid.LoadSheetFromSpreadsheetFile(AFileName: String;
|
||||||
AWorksheetIndex: Integer = -1; AFormatID: TsSpreadFormatID = sfidUnknown);
|
AWorksheetIndex: Integer = -1; AFormatID: TsSpreadFormatID = sfidUnknown);
|
||||||
begin
|
begin
|
||||||
|
ZoomFactor := 1.0;
|
||||||
GetWorkbookSource.LoadFromSpreadsheetFile(AFilename, AFormatID, AWorksheetIndex);
|
GetWorkbookSource.LoadFromSpreadsheetFile(AFilename, AFormatID, AWorksheetIndex);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -3961,6 +3986,7 @@ end;
|
|||||||
procedure TsCustomWorksheetGrid.LoadFromWorkbook(AWorkbook: TsWorkbook;
|
procedure TsCustomWorksheetGrid.LoadFromWorkbook(AWorkbook: TsWorkbook;
|
||||||
AWorksheetIndex: Integer = -1);
|
AWorksheetIndex: Integer = -1);
|
||||||
begin
|
begin
|
||||||
|
ZoomFactor := 1.0;
|
||||||
GetWorkbookSource.LoadFromWorkbook(AWorkbook, AWorksheetIndex);
|
GetWorkbookSource.LoadFromWorkbook(AWorkbook, AWorksheetIndex);
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
@ -4546,7 +4572,9 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsCustomWorksheetGrid.TopLeftChanged;
|
procedure TsCustomWorksheetGrid.TopLeftChanged;
|
||||||
begin
|
begin
|
||||||
UpdateRowHeights;
|
if FOldTopRow <> TopRow then
|
||||||
|
UpdateRowHeights;
|
||||||
|
FOldTopRow := TopRow;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -4718,6 +4746,9 @@ end;
|
|||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Updates row heights by using the data from the TRow records or by auto-
|
Updates row heights by using the data from the TRow records or by auto-
|
||||||
calculating the row height from the max of the cell heights
|
calculating the row height from the max of the cell heights
|
||||||
|
Because there may be many rows only the visible rows are updated. Therefore,
|
||||||
|
this method is called whenever the grid is scrolled and the coordinates of
|
||||||
|
the top-left cell changes.
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TsCustomWorksheetGrid.UpdateRowHeights(AStartIndex: Integer = 0);
|
procedure TsCustomWorksheetGrid.UpdateRowHeights(AStartIndex: Integer = 0);
|
||||||
const
|
const
|
||||||
@ -4729,23 +4760,11 @@ var
|
|||||||
begin
|
begin
|
||||||
Unused(AStartIndex);
|
Unused(AStartIndex);
|
||||||
|
|
||||||
{
|
if FRowHeightLock > 0 then
|
||||||
BeginUpdate;
|
exit;
|
||||||
if AStartIndex <= 0 then AStartIndex := FHeaderCount;
|
|
||||||
for i := AStartIndex to RowCount-1 do begin
|
r1 := Max(FHeaderCount, TopRow - DELTA);
|
||||||
h := CalcAutoRowHeight(i);
|
r2 := Min(RowCount-1, TopRow + VisibleRowCount + DELTA);
|
||||||
if Worksheet <> nil then
|
|
||||||
begin
|
|
||||||
lRow := Worksheet.FindRow(i - FHeaderCount);
|
|
||||||
if (lRow <> nil) then
|
|
||||||
h := CalcRowHeight(lRow^.Height);
|
|
||||||
end;
|
|
||||||
RowHeights[i] := h;
|
|
||||||
end;
|
|
||||||
EndUpdate;
|
|
||||||
}
|
|
||||||
r1 := Max(FHeaderCount, GCache.VisibleGrid.Top - DELTA);
|
|
||||||
r2 := Min(RowCount-1, GCache.VisibleGrid.Bottom + DELTA);
|
|
||||||
for r:=r1 to r2 do
|
for r:=r1 to r2 do
|
||||||
begin
|
begin
|
||||||
if Worksheet <> nil then
|
if Worksheet <> nil then
|
||||||
@ -5550,7 +5569,7 @@ begin
|
|||||||
if AValue = GetDefRowHeight then
|
if AValue = GetDefRowHeight then
|
||||||
exit;
|
exit;
|
||||||
// AValue contains the zoom factor
|
// AValue contains the zoom factor
|
||||||
// FDefRowHeight100 is the row height with zoom factor 1.0
|
// FDefRowHeight100 is the row height at zoom factor 1.0
|
||||||
FDefRowHeight100 := round(AValue / ZoomFactor);
|
FDefRowHeight100 := round(AValue / ZoomFactor);
|
||||||
inherited DefaultRowHeight := AValue;
|
inherited DefaultRowHeight := AValue;
|
||||||
if FHeaderCount > 0 then
|
if FHeaderCount > 0 then
|
||||||
|
Reference in New Issue
Block a user