lcl: grids: Hi-DPI: row heights and column width. New default (system) value is -1. Solves part of issue #31715

git-svn-id: trunk@54816 -
This commit is contained in:
ondrej 2017-05-05 22:38:49 +00:00
parent 118cfb3d98
commit 43e271b439

View File

@ -72,7 +72,6 @@ const
const const
DEFCOLWIDTH = 64; DEFCOLWIDTH = 64;
DEFROWHEIGHT = 20;
DEFBUTTONWIDTH = 25; DEFBUTTONWIDTH = 25;
DEFIMAGEPADDING = 2; DEFIMAGEPADDING = 2;
DEFAUTOADJPADDING = 8; DEFAUTOADJPADDING = 8;
@ -154,7 +153,7 @@ type
TTitleStyle = (tsLazarus, tsStandard, tsNative); TTitleStyle = (tsLazarus, tsStandard, tsNative);
TGridFlagsOption = (gfEditorUpdateLock, gfNeedsSelectActive, gfEditorTab, TGridFlagsOption = (gfEditorUpdateLock, gfNeedsSelectActive, gfEditorTab,
gfRevEditorTab, gfVisualChange, gfDefRowHeightChanged, gfColumnsLocked, gfRevEditorTab, gfVisualChange, gfColumnsLocked,
gfEditingDone, gfSizingStarted, gfPainting, gfUpdatingSize, gfClientRectChange, gfEditingDone, gfSizingStarted, gfPainting, gfUpdatingSize, gfClientRectChange,
gfAutoEditPending); gfAutoEditPending);
TGridFlags = set of TGridFlagsOption; TGridFlags = set of TGridFlagsOption;
@ -587,11 +586,11 @@ type
property MaxSize: Integer read GetMaxSize write SetMaxSize stored isMaxSizeStored; property MaxSize: Integer read GetMaxSize write SetMaxSize stored isMaxSizeStored;
property PickList: TStrings read GetPickList write SetPickList; property PickList: TStrings read GetPickList write SetPickList;
property ReadOnly: Boolean read GetReadOnly write SetReadOnly stored IsReadOnlyStored; property ReadOnly: Boolean read GetReadOnly write SetReadOnly stored IsReadOnlyStored;
property SizePriority: Integer read GetSizePriority write SetSizePriority stored IsSizePriorityStored default 1; property SizePriority: Integer read GetSizePriority write SetSizePriority stored IsSizePriorityStored;
property Tag: PtrInt read FTag write FTag default 0; property Tag: PtrInt read FTag write FTag default 0;
property Title: TGridColumnTitle read FTitle write SetTitle; property Title: TGridColumnTitle read FTitle write SetTitle;
property Width: Integer read GetWidth write SetWidth stored IsWidthStored default DEFCOLWIDTH; property Width: Integer read GetWidth write SetWidth stored IsWidthStored;
property Visible: Boolean read GetVisible write SetVisible stored IsVisibleStored default true; property Visible: Boolean read GetVisible write SetVisible stored IsVisibleStored;
property ValueChecked: string read GetValueChecked write SetValueChecked property ValueChecked: string read GetValueChecked write SetValueChecked
stored IsValueCheckedStored; stored IsValueCheckedStored;
property ValueUnchecked: string read GetValueUnchecked write SetValueUnchecked property ValueUnchecked: string read GetValueUnchecked write SetValueUnchecked
@ -726,6 +725,7 @@ type
FGridLineStyle: TPenStyle; FGridLineStyle: TPenStyle;
FGridLineWidth: Integer; FGridLineWidth: Integer;
FDefColWidth, FDefRowHeight: Integer; FDefColWidth, FDefRowHeight: Integer;
FRealizedDefColWidth, FRealizedDefRowHeight: Integer;
FCol,FRow, FFixedCols, FFixedRows: Integer; FCol,FRow, FFixedCols, FFixedRows: Integer;
FOnEditButtonClick: TNotifyEvent; FOnEditButtonClick: TNotifyEvent;
FOnButtonClick: TOnSelectEvent; FOnButtonClick: TOnSelectEvent;
@ -795,7 +795,6 @@ type
procedure SetQuickColRow(AValue: TPoint); procedure SetQuickColRow(AValue: TPoint);
function IsCellButtonColumn(ACell: TPoint): boolean; function IsCellButtonColumn(ACell: TPoint): boolean;
function GetSelectedColumn: TGridColumn; function GetSelectedColumn: TGridColumn;
function IsDefRowHeightStored: boolean;
function IsTitleImageListStored: boolean; function IsTitleImageListStored: boolean;
procedure SetAlternateColor(const AValue: TColor); procedure SetAlternateColor(const AValue: TColor);
procedure SetAutoFillColumns(const AValue: boolean); procedure SetAutoFillColumns(const AValue: boolean);
@ -1023,6 +1022,8 @@ type
function GetDefaultColumnTitle(Column: Integer): string; virtual; function GetDefaultColumnTitle(Column: Integer): string; virtual;
function GetDefaultEditor(Column: Integer): TWinControl; virtual; function GetDefaultEditor(Column: Integer): TWinControl; virtual;
function GetDefaultRowHeight: integer; virtual; function GetDefaultRowHeight: integer; virtual;
function GetRealDefaultColWidth: integer;
function GetRealDefaultRowHeight: integer;
function GetGridDrawState(ACol, ARow: Integer): TGridDrawState; function GetGridDrawState(ACol, ARow: Integer): TGridDrawState;
function GetImageForCheckBox(const aCol,aRow: Integer; function GetImageForCheckBox(const aCol,aRow: Integer;
CheckBoxView: TCheckBoxState): TBitmap; virtual; CheckBoxView: TCheckBoxState): TBitmap; virtual;
@ -1141,8 +1142,8 @@ type
property ColumnClickSorts: boolean read FColumnClickSorts write SetColumnClickSorts default false; property ColumnClickSorts: boolean read FColumnClickSorts write SetColumnClickSorts default false;
property Columns: TGridColumns read GetColumns write SetColumns stored IsColumnsStored; property Columns: TGridColumns read GetColumns write SetColumns stored IsColumnsStored;
property ColWidths[aCol: Integer]: Integer read GetColWidths write SetColWidths; property ColWidths[aCol: Integer]: Integer read GetColWidths write SetColWidths;
property DefaultColWidth: Integer read FDefColWidth write SetDefColWidth default DEFCOLWIDTH; property DefaultColWidth: Integer read FDefColWidth write SetDefColWidth default -1;
property DefaultRowHeight: Integer read FDefRowHeight write SetDefRowHeight stored IsDefRowHeightStored; property DefaultRowHeight: Integer read FDefRowHeight write SetDefRowHeight default -1;
property DefaultDrawing: Boolean read FDefaultDrawing write SetDefaultDrawing default True; property DefaultDrawing: Boolean read FDefaultDrawing write SetDefaultDrawing default True;
property DefaultTextStyle: TTextStyle read FDefaultTextStyle write FDefaultTextStyle; property DefaultTextStyle: TTextStyle read FDefaultTextStyle write FDefaultTextStyle;
property DragDx: Integer read FDragDx write FDragDx; property DragDx: Integer read FDragDx write FDragDx;
@ -2078,7 +2079,7 @@ begin
Result:=integer(PtrUInt(FRows[aRow])) Result:=integer(PtrUInt(FRows[aRow]))
else else
Result:=-1; Result:=-1;
if Result<0 then Result:=fDefRowHeight; if Result<0 then Result:=GetRealDefaultRowHeight;
end; end;
function TCustomGrid.GetTopRow: Longint; function TCustomGrid.GetTopRow: Longint;
@ -2498,6 +2499,7 @@ begin
else else
result := FDefColWidth; result := FDefColWidth;
end; end;
if Result<0 then Result:=GetRealDefaultColWidth;
end; end;
procedure TCustomGrid.SetEditor(AValue: TWinControl); procedure TCustomGrid.SetEditor(AValue: TWinControl);
@ -2922,8 +2924,6 @@ begin
Target.FixedCols := FixedCols; Target.FixedCols := FixedCols;
Target.FixedRows := FixedRows; Target.FixedRows := FixedRows;
Target.DefaultRowHeight := DefaultRowHeight; Target.DefaultRowHeight := DefaultRowHeight;
if not IsDefRowHeightStored then
Target.GridFlags := Target.GridFlags - [gfDefRowHeightChanged];
Target.DefaultColWidth := DefaultColWidth; Target.DefaultColWidth := DefaultColWidth;
if not Columns.Enabled then if not Columns.Enabled then
Target.FCols.Assign(FCols); Target.FCols.Assign(FCols);
@ -3017,7 +3017,6 @@ var
OldTop,OldBottom,NewTop,NewBottom: Integer; OldTop,OldBottom,NewTop,NewBottom: Integer;
begin begin
if (AValue<>fDefRowHeight) or (csLoading in ComponentState) then begin if (AValue<>fDefRowHeight) or (csLoading in ComponentState) then begin
include(FGridFlags, gfDefRowHeightChanged);
FDefRowheight:=AValue; FDefRowheight:=AValue;
if EditorMode then if EditorMode then
@ -3159,7 +3158,7 @@ end;
procedure TCustomGrid.VisualChange; procedure TCustomGrid.VisualChange;
begin begin
if (FUpdateCount<>0) or (not HandleAllocated) or AutoSizeDelayed then if (FUpdateCount<>0) or (not HandleAllocated) then
exit; exit;
{$ifdef DbgVisualChange} {$ifdef DbgVisualChange}
@ -4965,11 +4964,11 @@ end;
procedure TCustomGrid.UpdateSizes; procedure TCustomGrid.UpdateSizes;
begin begin
Include(FGridFlags, gfVisualChange); if (FUpdateCount<>0) or (not HandleAllocated) then
if (FUpdateCount<>0) or (not HandleAllocated) or AutoSizeDelayed then
exit; exit;
Include(FGridFlags, gfVisualChange);
UpdateCachedSizes; UpdateCachedSizes;
CacheVisibleGrid; CacheVisibleGrid;
CalcScrollbarsRange; CalcScrollbarsRange;
@ -5150,16 +5149,33 @@ begin
end; end;
end; end;
function TCustomGrid.GetRealDefaultColWidth: integer;
begin
if FDefColWidth < 0 then
begin
if FRealizedDefColWidth = 0 then
FRealizedDefColWidth := MulDiv(DEFCOLWIDTH, Font.PixelsPerInch, 96);
Result := FRealizedDefColWidth;
end else
Result := FDefColWidth;
end;
function TCustomGrid.GetRealDefaultRowHeight: integer;
begin
if FDefRowHeight < 0 then
begin
if FRealizedDefRowHeight = 0 then
FRealizedDefRowHeight := GetDefaultRowHeight;
Result := FRealizedDefRowHeight;
end else
Result := FDefRowHeight;
end;
function TCustomGrid.GetSelectedColumn: TGridColumn; function TCustomGrid.GetSelectedColumn: TGridColumn;
begin begin
Result := ColumnFromGridColumn(Col); Result := ColumnFromGridColumn(Col);
end; end;
function TCustomGrid.IsDefRowHeightStored: boolean;
begin
result := (gfDefRowHeightChanged in GridFlags);
end;
function TCustomGrid.IsAltColorStored: boolean; function TCustomGrid.IsAltColorStored: boolean;
begin begin
result := FAlternateColor <> Color; result := FAlternateColor <> Color;
@ -6795,15 +6811,22 @@ begin
C := Columns.Items[i]; C := Columns.Items[i];
C.MaxSize := Round(C.MaxSize * AXProportion); C.MaxSize := Round(C.MaxSize * AXProportion);
C.MinSize := Round(C.MinSize * AXProportion); C.MinSize := Round(C.MinSize * AXProportion);
if C.IsWidthStored then
C.Width := Round(C.Width * AXProportion); C.Width := Round(C.Width * AXProportion);
end; end;
for i := RowCount - 1 downto 0 do for i := FRows.Count - 1 downto 0 do
RowHeights[i] := Round(RowHeights[i] * AYProportion); FRows[i] := Pointer(Round(PtrInt(FRows[i]) * AYProportion));
for i := FCols.Count - 1 downto 0 do
FCols[i] := Pointer(Round(PtrInt(FCols[i]) * AXProportion));
if FDefColWidth>0 then
FDefColWidth := Round(FDefColWidth * AXProportion); FDefColWidth := Round(FDefColWidth * AXProportion);
if FDefRowHeight>0 then
FDefRowHeight := Round(FDefRowHeight * AYProportion); FDefRowHeight := Round(FDefRowHeight * AYProportion);
Include(FGridFlags, gfDefRowHeightChanged); FRealizedDefRowHeight := 0;
FRealizedDefColWidth := 0;
finally finally
EndUpdate; EndUpdate;
end; end;
@ -7998,6 +8021,8 @@ end;
procedure TCustomGrid.FontChanged(Sender: TObject); procedure TCustomGrid.FontChanged(Sender: TObject);
begin begin
FRealizedDefRowHeight := 0;
FRealizedDefColWidth := 0;
if csCustomPaint in ControlState then if csCustomPaint in ControlState then
Canvas.Font := Font Canvas.Font := Font
else begin else begin
@ -8884,7 +8909,6 @@ begin
Cfg.SetValue('grid/design/fixedcols', FixedCols); Cfg.SetValue('grid/design/fixedcols', FixedCols);
Cfg.SetValue('grid/design/fixedrows', Fixedrows); Cfg.SetValue('grid/design/fixedrows', Fixedrows);
Cfg.SetValue('grid/design/defaultcolwidth', DefaultColWidth); Cfg.SetValue('grid/design/defaultcolwidth', DefaultColWidth);
Cfg.SetValue('grid/design/isdefaultrowheight', ord(IsDefRowHeightStored));
Cfg.SetValue('grid/design/defaultrowheight',DefaultRowHeight); Cfg.SetValue('grid/design/defaultrowheight',DefaultRowHeight);
Cfg.Setvalue('grid/design/color',ColorToString(Color)); Cfg.Setvalue('grid/design/color',ColorToString(Color));
@ -9047,10 +9071,8 @@ begin
RowCount:=Cfg.GetValue('grid/design/rowcount', 5); RowCount:=Cfg.GetValue('grid/design/rowcount', 5);
FixedCols:=Cfg.GetValue('grid/design/fixedcols', 1); FixedCols:=Cfg.GetValue('grid/design/fixedcols', 1);
FixedRows:=Cfg.GetValue('grid/design/fixedrows', 1); FixedRows:=Cfg.GetValue('grid/design/fixedrows', 1);
k := Cfg.GetValue('grid/design/isdefaultrowheight', -1); DefaultRowheight:=Cfg.GetValue('grid/design/defaultrowheight', -1);
if k<>0 then DefaultColWidth:=Cfg.getValue('grid/design/defaultcolwidth', -1);
DefaultRowheight:=Cfg.GetValue('grid/design/defaultrowheight', DEFROWHEIGHT);
DefaultColWidth:=Cfg.getValue('grid/design/defaultcolwidth', DEFCOLWIDTH);
try try
Color := StringToColor(cfg.GetValue('grid/design/color', 'clWindow')); Color := StringToColor(cfg.GetValue('grid/design/color', 'clWindow'));
except except
@ -9186,8 +9208,8 @@ begin
goSmoothScroll ]; goSmoothScroll ];
FScrollbars:=ssAutoBoth; FScrollbars:=ssAutoBoth;
fGridState:=gsNormal; fGridState:=gsNormal;
FDefColWidth:=DEFCOLWIDTH; FDefColWidth:=-1;
FDefRowHeight:=GetDefaultRowHeight; FDefRowHeight:=-1;
FGridLineColor:=clSilver; FGridLineColor:=clSilver;
FFixedGridLineColor := cl3DDKShadow; FFixedGridLineColor := cl3DDKShadow;
FGridLineStyle:=psSolid; FGridLineStyle:=psSolid;
@ -11647,6 +11669,8 @@ begin
end; end;
function TGridColumn.GetWidth: Integer; function TGridColumn.GetWidth: Integer;
var
tmpGrid: TCustomGrid;
begin begin
{$ifdef newcols} {$ifdef newcols}
if not Visible then if not Visible then
@ -11656,6 +11680,12 @@ begin
result := GetDefaultWidth result := GetDefaultWidth
else else
result := FWidth^; result := FWidth^;
if (result<0) then
begin
tmpGrid := Grid;
if tmpGrid<>nil then
result := tmpGrid.GetRealDefaultColWidth;
end;
end; end;
function TGridColumn.IsAlignmentStored: boolean; function TGridColumn.IsAlignmentStored: boolean;
@ -11928,7 +11958,7 @@ begin
if tmpGrid<>nil then if tmpGrid<>nil then
result := tmpGrid.DefaultColWidth result := tmpGrid.DefaultColWidth
else else
result := DEFCOLWIDTH; result := -1;
end; end;
function TGridColumn.GetDefaultMaxSize: Integer; function TGridColumn.GetDefaultMaxSize: Integer;