lcl: toolbar: add DropDownWidth property

git-svn-id: trunk@50900 -
This commit is contained in:
ondrej 2015-12-18 10:13:17 +00:00
parent f28fd32f87
commit 540bd3a671
5 changed files with 34 additions and 7 deletions

View File

@ -18804,6 +18804,8 @@ the comparision is case sensitive.
<short>Show/Hide caption</short> <short>Show/Hide caption</short>
<descr>The ToolBar.ShowCaptions has precendence. Hiding will only work if ToolBar.List is true.</descr> <descr>The ToolBar.ShowCaptions has precendence. Hiding will only work if ToolBar.List is true.</descr>
</element> </element>
<element name="TToolBar.DropDownWidth"><short>Width of the drop down arrow button.</short><descr>Use a negative value (-1) for theme default.</descr>
</element>
</module> </module>
<!-- ComCtrls --> <!-- ComCtrls -->
</package> </package>

View File

@ -2138,6 +2138,7 @@ type
FDisabledImageChangeLink: TChangeLink; FDisabledImageChangeLink: TChangeLink;
FDisabledImages: TCustomImageList; FDisabledImages: TCustomImageList;
FDropDownWidth: integer; FDropDownWidth: integer;
FThemeDropDownWidth: integer;
FDropDownButton: TToolButton; FDropDownButton: TToolButton;
FFlat: Boolean; FFlat: Boolean;
FHotImageChangeLink: TChangeLink; FHotImageChangeLink: TChangeLink;
@ -2163,6 +2164,7 @@ type
procedure SetButtonHeight(const AValue: Integer); procedure SetButtonHeight(const AValue: Integer);
procedure SetButtonWidth(const AValue: Integer); procedure SetButtonWidth(const AValue: Integer);
procedure SetDisabledImages(const AValue: TCustomImageList); procedure SetDisabledImages(const AValue: TCustomImageList);
procedure SetDropDownWidth(const aDropDownWidth: Integer);
procedure SetFlat(const AValue: Boolean); procedure SetFlat(const AValue: Boolean);
procedure SetHotImages(const AValue: TCustomImageList); procedure SetHotImages(const AValue: TCustomImageList);
procedure SetImages(const AValue: TCustomImageList); procedure SetImages(const AValue: TCustomImageList);
@ -2182,6 +2184,7 @@ type
protected const protected const
cDefButtonWidth = 23; cDefButtonWidth = 23;
cDefButtonHeight = 22; cDefButtonHeight = 22;
cDropDownWidth = -1;
protected protected
FPrevVertical: Boolean; FPrevVertical: Boolean;
function IsVertical: Boolean; virtual; function IsVertical: Boolean; virtual;
@ -2214,6 +2217,7 @@ type
function GetEnumerator: TToolBarEnumerator; function GetEnumerator: TToolBarEnumerator;
procedure SetButtonSize(NewButtonWidth, NewButtonHeight: integer); procedure SetButtonSize(NewButtonWidth, NewButtonHeight: integer);
function CanFocus: Boolean; override; function CanFocus: Boolean; override;
function GetRealDropDownWidth: Integer;
public public
property ButtonCount: Integer read GetButtonCount; property ButtonCount: Integer read GetButtonCount;
property Buttons[Index: Integer]: TToolButton read GetButton; property Buttons[Index: Integer]: TToolButton read GetButton;
@ -2236,6 +2240,7 @@ type
property DragCursor; property DragCursor;
property DragKind; property DragKind;
property DragMode; property DragMode;
property DropDownWidth: Integer read FDropDownWidth write SetDropDownWidth default cDropDownWidth;
property EdgeBorders default [ebTop]; property EdgeBorders default [ebTop];
property EdgeInner; property EdgeInner;
property EdgeOuter; property EdgeOuter;

View File

@ -92,7 +92,8 @@ begin
FButtonWidth := cDefButtonWidth; FButtonWidth := cDefButtonWidth;
FButtonHeight := cDefButtonHeight; FButtonHeight := cDefButtonHeight;
Details := ThemeServices.GetElementDetails(ttbSplitButtonDropDownNormal); Details := ThemeServices.GetElementDetails(ttbSplitButtonDropDownNormal);
FDropDownWidth := ThemeServices.GetDetailSize(Details).cx; FDropDownWidth := cDropDownWidth;
FThemeDropDownWidth := ThemeServices.GetDetailSize(Details).cx;
FNewStyle := True; FNewStyle := True;
FWrapable := True; FWrapable := True;
FButtons := TList.Create; FButtons := TList.Create;
@ -352,6 +353,13 @@ begin
UpdateVisibleBar; UpdateVisibleBar;
end; end;
procedure TToolBar.SetDropDownWidth(const aDropDownWidth: Integer);
begin
if FDropDownWidth = aDropDownWidth then Exit;
FDropDownWidth := aDropDownWidth;
UpdateVisibleBar;
end;
procedure TToolBar.HotImageListChange(Sender: TObject); procedure TToolBar.HotImageListChange(Sender: TObject);
begin begin
if (Sender = HotImages) then UpdateVisibleBar; if (Sender = HotImages) then UpdateVisibleBar;
@ -417,6 +425,14 @@ begin
Result := TToolBarEnumerator.Create(Self); Result := TToolBarEnumerator.Create(Self);
end; end;
function TToolBar.GetRealDropDownWidth: Integer;
begin
if FDropDownWidth < 0 then
Result := FThemeDropDownWidth
else
Result := FDropDownWidth;
end;
procedure TToolBar.Paint; procedure TToolBar.Paint;
begin begin
if csDesigning in ComponentState then if csDesigning in ComponentState then

View File

@ -84,7 +84,7 @@ begin
// therefore the condition is always met. // therefore the condition is always met.
if Enabled and not(GetTickCount64 < FLastDropDownTick + 100) then if Enabled and not(GetTickCount64 < FLastDropDownTick + 100) then
begin begin
if (Style = tbsDropDown) and (FToolBar <> nil) and (X > ClientWidth - FToolBar.FDropDownWidth) then if (Style = tbsDropDown) and (FToolBar <> nil) and (X > ClientWidth - FToolBar.GetRealDropDownWidth) then
Include(NewFlags, tbfArrowPressed) Include(NewFlags, tbfArrowPressed)
else else
Include(NewFlags, tbfPressed); Include(NewFlags, tbfPressed);
@ -302,7 +302,7 @@ begin
if Style in [tbsDropDown, tbsButtonDrop] then if Style in [tbsDropDown, tbsButtonDrop] then
begin begin
DropDownButtonRect := ButtonRect; DropDownButtonRect := ButtonRect;
DropDownButtonRect.Left := Max(0, DropDownButtonRect.Right-FToolBar.FDropDownWidth); DropDownButtonRect.Left := Max(0, DropDownButtonRect.Right-FToolBar.GetRealDropDownWidth);
MainBtnRect.Right := DropDownButtonRect.Left; MainBtnRect.Right := DropDownButtonRect.Left;
if Style = tbsDropDown then if Style = tbsDropDown then
ButtonRect := MainBtnRect ButtonRect := MainBtnRect
@ -1103,8 +1103,8 @@ begin
PreferredWidth := Max(PreferredWidth, FToolBar.ButtonWidth); PreferredWidth := Max(PreferredWidth, FToolBar.ButtonWidth);
PreferredHeight := Max(PreferredHeight, FToolBar.ButtonHeight); PreferredHeight := Max(PreferredHeight, FToolBar.ButtonHeight);
case Style of case Style of
tbsDropDown: inc(PreferredWidth, FToolBar.FDropDownWidth); tbsDropDown: inc(PreferredWidth, FToolBar.GetRealDropDownWidth);
tbsButtonDrop: inc(PreferredWidth, FToolBar.FDropDownWidth-cDefButtonDropDecArrowWidth); tbsButtonDrop: inc(PreferredWidth, FToolBar.GetRealDropDownWidth-cDefButtonDropDecArrowWidth);
end; end;
end end
else else

View File

@ -1972,14 +1972,18 @@ end;
procedure TThemeServices.DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect; ClipRect: PRect = nil); procedure TThemeServices.DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect; ClipRect: PRect = nil);
procedure DrawDropDownArrow(const DropDownButtonRect: TRect); procedure DrawDropDownArrow(const DropDownButtonRect: TRect);
const
cArrowWidth = 10;
var var
ArrowRect: TRect; ArrowRect: TRect;
Points: array[1..3] of TPoint; Points: array[1..3] of TPoint;
OldBrush, Brush: HBrush; OldBrush, Brush: HBrush;
begin begin
ArrowRect := DropDownButtonRect; ArrowRect := DropDownButtonRect;
ArrowRect.Left := DropDownButtonRect.Left + 3; ArrowRect.Left := (DropDownButtonRect.Left+DropDownButtonRect.Right-cArrowWidth-1) div 2;
ArrowRect.Right := Max(DropDownButtonRect.Right - 3, ArrowRect.Left); ArrowRect.Right := ArrowRect.Left+cArrowWidth;
ArrowRect.Left := ArrowRect.Left + 3;
ArrowRect.Right := Max(ArrowRect.Right - 3, ArrowRect.Left);
ArrowRect.Top := (DropDownButtonRect.Top + DropDownButtonRect.Bottom + ArrowRect.Top := (DropDownButtonRect.Top + DropDownButtonRect.Bottom +
ArrowRect.Left - ArrowRect.Right) div 2; ArrowRect.Left - ArrowRect.Right) div 2;
ArrowRect.Bottom := ArrowRect.Top + Min(2, ArrowRect.Right - ArrowRect.Left); ArrowRect.Bottom := ArrowRect.Top + Min(2, ArrowRect.Right - ArrowRect.Left);