From 1ed37fa1548484a46deec3bfcd8abdeb49bdf7ff Mon Sep 17 00:00:00 2001 From: wp Date: Wed, 31 Oct 2018 17:28:54 +0000 Subject: [PATCH] VirtualTreeView: LCL scaling of column widths git-svn-id: trunk@59403 - --- components/virtualtreeview/VirtualTrees.pas | 44 +++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/components/virtualtreeview/VirtualTrees.pas b/components/virtualtreeview/VirtualTrees.pas index 194b7b1996..161ec2c877 100644 --- a/components/virtualtreeview/VirtualTrees.pas +++ b/components/virtualtreeview/VirtualTrees.pas @@ -235,6 +235,7 @@ const {$endif} DEFAULT_CHECK_WIDTH = 16; + DEFAULT_COLUMN_WIDTH = 50; DEFAULT_HEADER_HEIGHT = 19; DEFAULT_NODE_HEIGHT = 18; @@ -987,6 +988,7 @@ type function IsBiDiModeStored: Boolean; function IsCaptionAlignmentStored: Boolean; function IsColorStored: Boolean; + function IsWidthStored: Boolean; procedure SetAlignment(const Value: TAlignment); procedure SetBiDiMode(Value: TBiDiMode); procedure SetCaptionAlignment(const Value: TAlignment); @@ -1054,7 +1056,7 @@ type property Style: TVirtualTreeColumnStyle read FStyle write SetStyle default vsText; property Tag: NativeInt read FTag write FTag default 0; property Text: TTranslateString read GetText write SetText; - property Width: Integer read FWidth write SetWidth default 50; + property Width: Integer read FWidth write SetWidth stored IsWidthStored; end; TVirtualTreeColumnClass = class of TVirtualTreeColumn; @@ -1079,6 +1081,7 @@ type function GetItem(Index: TColumnIndex): TVirtualTreeColumn; function GetNewIndex(P: TPoint; var OldIndex: TColumnIndex): Boolean; + function IsDefaultWidthStored: Boolean; procedure SetDefaultWidth(Value: Integer); procedure SetItem(Index: TColumnIndex; Value: TVirtualTreeColumn); protected @@ -1143,7 +1146,7 @@ type function TotalWidth: Integer; property ClickIndex: TColumnIndex read FClickIndex; - property DefaultWidth: Integer read FDefaultWidth write SetDefaultWidth default 50; + property DefaultWidth: Integer read FDefaultWidth write SetDefaultWidth stored IsDefaultWidthStored; property Items[Index: TColumnIndex]: TVirtualTreeColumn read GetItem write SetItem; default; property Header: TVTHeader read FHeader; property TrackIndex: TColumnIndex read FTrackIndex; @@ -6803,6 +6806,7 @@ begin FWidth := Owner.FDefaultWidth; FLastWidth := Owner.FDefaultWidth; + //lcl: setting FPosition here will override the Design time value //FPosition := Owner.Count - 1; // Read parent bidi mode and color values as default values. @@ -6916,6 +6920,13 @@ end; //---------------------------------------------------------------------------------------------------------------------- +function TVirtualTreeColumn.IsWidthStored: Boolean; +begin + Result := FWidth <> Owner.DefaultWidth; +end; + +//---------------------------------------------------------------------------------------------------------------------- + procedure TVirtualTreeColumn.SetAlignment(const Value: TAlignment); begin @@ -7932,7 +7943,11 @@ begin FClickIndex := NoColumn; FDropTarget := NoColumn; FTrackIndex := NoColumn; - FDefaultWidth := 50; + {$IF LCL_FullVersion >= 1080000} + FDefaultWidth := Header.TreeView.Scale96ToFont(DEFAULT_COLUMN_WIDTH); + {$ELSE} + FDefaultWidth := DEFAULT_COLUMN_WIDTH; + {$IFEND} end; //---------------------------------------------------------------------------------------------------------------------- @@ -7977,6 +7992,17 @@ end; //---------------------------------------------------------------------------------------------------------------------- +function TVirtualTreeColumns.IsDefaultWidthStored: Boolean; +begin + {$IF LCL_FullVersion >= 1080000} + Result := FDefaultWidth <> Header.TreeView.Scale96ToFont(DEFAULT_COLUMN_WIDTH); + {$ELSE} + Result := FDefaultWidth <> DEFAULT_COLUMN_WIDTH; + {$IFEND} +end; + +//---------------------------------------------------------------------------------------------------------------------- + procedure TVirtualTreeColumns.SetDefaultWidth(Value: Integer); begin @@ -11259,12 +11285,24 @@ end; {$IF LCL_FullVersion >= 1080000} procedure TVTHeader.AutoAdjustLayout(const AXProportion, AYProportion: Double); +var + i: Integer; + col: TVirtualTreeColumn; begin if IsDefaultHeightStored then FDefaultHeight := Round(FDefaultHeight * AYProportion); if IsHeightStored then FHeight := Round(FHeight * AYProportion); + + if Columns.IsDefaultWidthStored then + Columns.DefaultWidth := Round(Columns.DefaultWidth * AXProportion); + + for i := 0 to Columns.Count-1 do begin + col := Columns[i]; + if col.IsWidthStored then + col.Width := Round(col.Width * AXProportion); + end; end; {$IFEND}