Skip to content

Commit

Permalink
Minor tweaks regarding toAutoChnageScale: Apply also on startup and d…
Browse files Browse the repository at this point in the history
…esigntime
  • Loading branch information
joachimmarder committed Mar 16, 2024
1 parent 7971cd3 commit 7ba3d29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
26 changes: 10 additions & 16 deletions Source/VirtualTrees.BaseTree.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
property Colors: TVTColors read FColors write SetColors;
property CustomCheckImages: TCustomImageList read FCustomCheckImages write SetCustomCheckImages;
property DefaultHintKind: TVTHintKind read GetDefaultHintKind;
property DefaultNodeHeight: TDimension read FDefaultNodeHeight write SetDefaultNodeHeight stored IsStored_DefaultNodeHeight; // default 18;
property DefaultNodeHeight: TDimension read FDefaultNodeHeight write SetDefaultNodeHeight stored IsStored_DefaultNodeHeight;
property DefaultPasteMode: TVTNodeAttachMode read FDefaultPasteMode write FDefaultPasteMode default amAddChildLast;
property DragHeight: Integer read FDragHeight write FDragHeight default 350;
property DragImageKind: TVTDragImageKind read FDragImageKind write FDragImageKind default diComplete;
Expand Down Expand Up @@ -1242,7 +1242,7 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
property SelectionBlendFactor: Byte read FSelectionBlendFactor write FSelectionBlendFactor default 128;
property SelectionCurveRadius: Cardinal read FSelectionCurveRadius write SetSelectionCurveRadius default 0;
property StateImages: TCustomImageList read FStateImages write SetStateImages;
property TextMargin: TDimension read FTextMargin write SetTextMargin stored IsStored_TextMargin; // default 4;
property TextMargin: TDimension read FTextMargin write SetTextMargin stored IsStored_TextMargin;
property TreeOptions: TCustomVirtualTreeOptions read FOptions write SetOptions;
property WantTabs: Boolean read FWantTabs write FWantTabs default False;
property SyncCheckstateWithSelection[Node: PVirtualNode]: Boolean read GetSyncCheckstateWithSelection;
Expand Down Expand Up @@ -2038,7 +2038,7 @@ constructor TBaseVirtualTree.Create(AOwner: TComponent);
Height := 100;
TabStop := True;
ParentColor := False;
FDefaultNodeHeight := 18;
FDefaultNodeHeight := cInitialDefaultNodeHeight;
FDragOperations := [doCopy, doMove];
FHotCursor := crDefault;
FScrollBarOptions := TScrollBarOptions.Create(Self);
Expand Down Expand Up @@ -2085,7 +2085,7 @@ constructor TBaseVirtualTree.Create(AOwner: TComponent);

FDefaultPasteMode := amAddChildLast;
FMargin := 4;
FTextMargin := 4;
FTextMargin := cDefaultTextMargin;
FImagesMargin := 2;
FLastDragEffect := DROPEFFECT_NONE;
FDragType := dtOLE;
Expand Down Expand Up @@ -4641,7 +4641,7 @@ procedure TBaseVirtualTree.SetDefaultNodeHeight(Value: TDimension);

begin
if Value = 0 then
Value := 18;
Value := cInitialDefaultNodeHeight;
if FDefaultNodeHeight <> Value then
begin
Inc(FRoot.TotalHeight, Value - FDefaultNodeHeight);
Expand Down Expand Up @@ -5883,14 +5883,7 @@ procedure TBaseVirtualTree.CMFontChanged(var Message: TMessage);

begin
inherited;

if not (csLoading in ComponentState) then
begin
if HandleAllocated then begin
AutoScale();
Invalidate;
end
end;
AutoScale();

HeaderMessage.Msg := CM_PARENTFONTCHANGED;
HeaderMessage.WParam := 0;
Expand Down Expand Up @@ -8765,6 +8758,7 @@ procedure TBaseVirtualTree.CreateWnd;
else
DoStateChange([], [tsUseThemes, tsUseExplorerTheme]);

AutoScale();
// Because of the special recursion and update stopper when creating the window (or resizing it)
// we have to manually trigger the auto size calculation here.
if hsNeedScaling in FHeader.States then
Expand Down Expand Up @@ -15925,7 +15919,7 @@ procedure TBaseVirtualTree.AutoScale();
if HandleAllocated and (toAutoChangeScale in TreeOptions.AutoOptions) then
begin
Canvas.Font.Assign(Self.Font);
lTextHeight := Canvas.TextHeight('Tg') + {$if CompilerVersion > 31} MulDiv(2, CurrentPPI, 96) {$else} 2 {$ifend}; // See issue #1205, ScaledPixels(2) may return wrong value here
lTextHeight := Canvas.TextHeight('Tg') + TextMargin;
// By default, we only ensure that DefaultNodeHeight is large enough.
// If the form's dpi has changed, we scale up and down the DefaultNodeHeight, See issue #677.
if (lTextHeight <> Self.DefaultNodeHeight) then begin
Expand Down Expand Up @@ -19873,7 +19867,7 @@ function TBaseVirtualTree.IsStored_BottomSpace: Boolean;

function TBaseVirtualTree.IsStored_DefaultNodeHeight: Boolean;
begin
Result:= CompareValue(FDefaultNodeHeight, 18)<>EqualsValue;
Result:= CompareValue(FDefaultNodeHeight, cInitialDefaultNodeHeight)<>EqualsValue;
end;

//----------------------------------------------------------------------------------------------------------------------
Expand All @@ -19894,7 +19888,7 @@ function TBaseVirtualTree.IsStored_Margin: Boolean;

function TBaseVirtualTree.IsStored_TextMargin: Boolean;
begin
Result:= CompareValue(FTextMargin, 4)<>EqualsValue;
Result:= CompareValue(FTextMargin, cDefaultTextMargin) <> EqualsValue;
end;

//----------------------------------------------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion Source/VirtualTrees.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface
ShadowSize = 5; // Size in pixels of the hint shadow. This value has no influence on Win2K and XP systems
// as those OSes have native shadow support.
cDefaultTextMargin = 4; // The default margin of text
cInitialDefaultNodeHeight= 18; // the default value of the DefualtNodeHeight property

// Special identifiers for columns.
NoColumn = - 1;
Expand Down Expand Up @@ -333,7 +334,7 @@ TSortDirectionHelper = record helper for VirtualTrees.Types.TSortDirection
toAutoHideButtons, // Node buttons are hidden when there are child nodes, but all are invisible.
toAutoDeleteMovedNodes, // Delete nodes which where moved in a drag operation (if not directed otherwise).
toDisableAutoscrollOnFocus, // Disable scrolling a node or column into view if it gets focused.
toAutoChangeScale, // Change default node height and header height automatically according to the used font.
toAutoChangeScale, // Change default node height and header height automatically according to the height of the used font.
toAutoFreeOnCollapse, // Frees any child node after a node has been collapsed (HasChildren flag stays there).
toDisableAutoscrollOnEdit, // Do not center a node horizontally when it is edited.
toAutoBidiColumnOrdering // When set then columns (if any exist) will be reordered from lowest index to highest index
Expand Down

0 comments on commit 7ba3d29

Please sign in to comment.