diff --git a/components/ideintf/componenteditors.pas b/components/ideintf/componenteditors.pas index 25b5632d0d..3ad8131a9b 100644 --- a/components/ideintf/componenteditors.pas +++ b/components/ideintf/componenteditors.pas @@ -1252,8 +1252,6 @@ begin NewToolButton.Caption := NewName; NewToolButton.Name := NewName; NewToolButton.Style := NewStyle; - if NewStyle = tbsDivider then - NewToolButton.Width := 3; // position the button next to the last button if CurToolBar.ButtonCount > 0 then begin diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index 30520348a9..92e44bf1a9 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -1953,7 +1953,7 @@ type end; TToolButtonActionLinkClass = class of TToolButtonActionLink; - + TToolBar = class; TToolButton = class(TGraphicControl) @@ -1976,6 +1976,7 @@ type function GetIndex: Integer; function GetTextSize: TSize; function IsCheckedStored: Boolean; + function IsHeightStored: Boolean; function IsImageIndexStored: Boolean; function IsWidthStored: Boolean; procedure SetDown(Value: Boolean); @@ -1992,6 +1993,9 @@ type procedure CMEnabledChanged(var Message: TLMEssage); message CM_ENABLEDCHANGED; procedure CMVisibleChanged(var Message: TLMessage); message CM_VISIBLECHANGED; procedure CMHitTest(var Message: TCMHitTest); message CM_HITTEST; + protected const + cDefSeparatorWidth = 10; + cDefDividerWidth = 5; protected FToolBar: TToolBar; class procedure WSRegisterClass; override; @@ -2045,7 +2049,7 @@ type property DropdownMenu: TPopupMenu read FDropdownMenu write SetDropdownMenu; property Enabled; property Grouped: Boolean read FGrouped write SetGrouped default False; - property Height stored False; + property Height stored IsHeightStored; property ImageIndex: TImageIndex read FImageIndex write SetImageIndex stored IsImageIndexStored default -1; property Indeterminate: Boolean read FIndeterminate write SetIndeterminate default False; property Marked: Boolean read FMarked write SetMarked default False; @@ -2149,7 +2153,11 @@ type procedure MoveSubMenuItems(SrcMenuItem, DestMenuItem: TMenuItem); procedure AddButton(Button: TToolButton); procedure RemoveButton(Button: TToolButton); + protected const + cDefButtonWidth = 23; + cDefButtonHeight = 22; protected + FPrevVertical: Boolean; function IsVertical: Boolean; virtual; class procedure WSRegisterClass; override; procedure AdjustClientRect(var ARect: TRect); override; @@ -2191,8 +2199,8 @@ type property AutoSize; property BorderSpacing; property BorderWidth; - property ButtonHeight: Integer read FButtonHeight write SetButtonHeight default 22; - property ButtonWidth: Integer read FButtonWidth write SetButtonWidth default 23; + property ButtonHeight: Integer read FButtonHeight write SetButtonHeight default cDefButtonHeight; + property ButtonWidth: Integer read FButtonWidth write SetButtonWidth default cDefButtonWidth; property Caption; property ChildSizing; property Constraints; diff --git a/lcl/include/toolbar.inc b/lcl/include/toolbar.inc index 1ed479a332..b2c4e97930 100644 --- a/lcl/include/toolbar.inc +++ b/lcl/include/toolbar.inc @@ -89,8 +89,8 @@ begin csDoubleClicks, csMenuEvents, csSetCaption, csParentBackground, csOpaque]; FFlat := True; Height := 32; - FButtonWidth := 23; - FButtonHeight := 22; + FButtonWidth := cDefButtonWidth; + FButtonHeight := cDefButtonHeight; Details := ThemeServices.GetElementDetails(ttbSplitButtonDropDownNormal); FDropDownWidth := ThemeServices.GetDetailSize(Details).cx; FNewStyle := True; @@ -833,8 +833,24 @@ begin SeparatorWidthChange := (CurControl is TToolButton) and (TToolButton(CurControl).Style in [tbsSeparator, tbsDivider]); if SeparatorWidthChange then begin - SeparatorWidthChange := (w <> CurControl.Width); - w := CurControl.Width; + if not Vertical then begin + SeparatorWidthChange := (w <> CurControl.Width); + w := CurControl.Width; + end else begin + SeparatorWidthChange := (h <> CurControl.Height); + h := CurControl.Height; + end; + end; + if Vertical <> FPrevVertical then //swap h/w when orientation changed + begin + if (CurControl is TToolButton) and + (TToolButton(CurControl).Style in [tbsSeparator, tbsDivider]) then + begin + if not Vertical then + w := CurControl.Height + else + h := CurControl.Width; + end; end; if (CurControl.Left <> x) or (CurControl.Top <> y) or (CurControl.Width <> w) or (CurControl.Height <> h) then @@ -893,6 +909,7 @@ begin FullSizeObstacleControls.Free; EndUpdate; EnableAlign; + FPrevVertical := Vertical; end; end; diff --git a/lcl/include/toolbutton.inc b/lcl/include/toolbutton.inc index d83153a837..a517373792 100644 --- a/lcl/include/toolbutton.inc +++ b/lcl/include/toolbutton.inc @@ -630,6 +630,18 @@ procedure TToolButton.SetStyle(Value: TToolButtonStyle); begin if FStyle = Value then exit; FStyle := Value; + if Width = TToolBar.cDefButtonWidth then begin + case Value of + tbsSeparator: begin + Width := cDefSeparatorWidth; + Height := cDefSeparatorWidth; + end; + tbsDivider: begin + Width := cDefDividerWidth; + Height := cDefDividerWidth; + end; + end; + end; InvalidatePreferredSize; if IsControlVisible then UpdateVisibleToolbar; @@ -808,6 +820,11 @@ begin Result := (ActionLink = nil) or not TToolButtonActionLink(ActionLink).IsCheckedLinked; end; +function TToolButton.IsHeightStored: Boolean; +begin + Result := Style in [tbsSeparator, tbsDivider]; +end; + function TToolButton.IsImageIndexStored: Boolean; begin Result := (ActionLink = nil) or not TToolButtonActionLink(ActionLink).IsImageIndexLinked; @@ -875,11 +892,19 @@ begin FToolBar := nil; if AParent is TToolBar then begin - if Style in [tbsButton,tbsDropDown,tbsCheck] then - NewWidth := TToolBar(AParent).ButtonWidth - else - NewWidth := Width; - NewHeight := TToolBar(AParent).ButtonHeight; + if not TToolBar(AParent).IsVertical then begin + if Style in [tbsButton,tbsDropDown,tbsCheck] then + NewWidth := TToolBar(AParent).ButtonWidth + else + NewWidth := Width; + NewHeight := TToolBar(AParent).ButtonHeight; + end else begin + if Style in [tbsButton,tbsDropDown,tbsCheck] then + NewHeight := TToolBar(AParent).ButtonHeight + else + NewHeight := Height; + NewWidth := TToolBar(AParent).ButtonWidth; + end; SetBoundsKeepBase(Left, Top, NewWidth, NewHeight); end; @@ -1032,15 +1057,15 @@ begin else if Style = tbsDivider then if FToolBar.IsVertical then - PreferredHeight := 5 + PreferredHeight := cDefDividerWidth else - PreferredWidth := 5 + PreferredWidth := cDefDividerWidth else if Style = tbsSeparator then if FToolBar.IsVertical then - PreferredHeight := 10 + PreferredHeight := cDefSeparatorWidth else - PreferredWidth := 10; + PreferredWidth := cDefSeparatorWidth; end; //DebugLn(['TToolButton.CalculatePreferredSize ',DbgSName(Self),' ',PreferredWidth,',',PreferredHeight,' Caption=',Caption]); end;