diff --git a/docs/xml/lcl/comctrls.xml b/docs/xml/lcl/comctrls.xml
index 89f082c8e5..e805732b55 100644
--- a/docs/xml/lcl/comctrls.xml
+++ b/docs/xml/lcl/comctrls.xml
@@ -17422,6 +17422,10 @@ the comparision is case sensitive.
+
+ Show/Hide caption
+ The ToolBar.ShowCaptions has precendence. Hiding will only work if ToolBar.List is true.
+
diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp
index 4e990032ab..09404bf1d9 100644
--- a/lcl/comctrls.pp
+++ b/lcl/comctrls.pp
@@ -1524,6 +1524,7 @@ type
FMarked: Boolean;
FMenuItem: TMenuItem;
FMouseInControl: boolean;
+ FShowCaption: boolean;
FStyle: TToolButtonStyle;
FToolButtonFlags: TToolButtonFlags;
FUpdateCount: Integer;
@@ -1541,6 +1542,7 @@ type
procedure SetIndeterminate(Value: Boolean);
procedure SetMarked(Value: Boolean);
procedure SetMenuItem(Value: TMenuItem);
+ procedure SetShowCaption(const AValue: boolean);
procedure SetStyle(Value: TToolButtonStyle);
procedure SetWrap(Value: Boolean);
procedure SetMouseInControl(NewMouseInControl: Boolean);
@@ -1606,13 +1608,6 @@ type
property Indeterminate: Boolean read FIndeterminate write SetIndeterminate default False;
property Marked: Boolean read FMarked write SetMarked default False;
property MenuItem: TMenuItem read FMenuItem write SetMenuItem;
- property ParentShowHint;
- property PopupMenu;
- property Wrap: Boolean read FWrap write SetWrap default False;
- property ShowHint;
- property Style: TToolButtonStyle read FStyle write SetStyle default tbsButton;
- property Visible;
- property Width stored IsWidthStored;
property OnClick;
property OnContextPopup;
property OnDragDrop;
@@ -1624,6 +1619,14 @@ type
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
+ property ParentShowHint;
+ property PopupMenu;
+ property ShowCaption: boolean read FShowCaption write SetShowCaption default true;
+ property ShowHint;
+ property Style: TToolButtonStyle read FStyle write SetStyle default tbsButton;
+ property Visible;
+ property Width stored IsWidthStored;
+ property Wrap: Boolean read FWrap write SetWrap default False;
end;
{ TToolBarEnumerator }
diff --git a/lcl/include/toolbutton.inc b/lcl/include/toolbutton.inc
index 50b4cc8192..343595a352 100644
--- a/lcl/include/toolbutton.inc
+++ b/lcl/include/toolbutton.inc
@@ -59,6 +59,7 @@ begin
inherited Create(TheOwner);
FImageIndex := -1;
FStyle := tbsButton;
+ FShowCaption := true;
ControlStyle := [csCaptureMouse, csSetCaption, csDesignNoSmoothResize];
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
@@ -259,9 +260,11 @@ begin
// calculate text size
TextSize.cx:=0;
TextSize.cy:=0;
- if (Style in [tbsButton, tbsDropDown, tbsCheck]) and
- (FToolBar.ShowCaptions) and
- (Caption <> '') then
+ if (Style in [tbsButton, tbsDropDown, tbsCheck]) and (FToolBar.ShowCaptions)
+ and ((FToolbar.List and ShowCaption) //Allow hide caption only in list mode
+ or not FToolBar.List)
+ and (Caption <> '')
+ then
TextSize := GetTextSize;
// calculate icon size
@@ -563,7 +566,7 @@ begin
if FImageIndex = Value then exit;
//debugln('TToolButton.SetImageIndex ',Name,':',ClassName,' Old=',FImageIndex,' New=',Value);
FImageIndex := Value;
- if Visible and (FToolBar <> nil) then
+ if IsControlVisible and (FToolBar <> nil) then
begin
RefreshControl;
Invalidate;
@@ -600,12 +603,23 @@ begin
FMenuItem.FreeNotification(Self);
end;
+procedure TToolButton.SetShowCaption(const AValue: boolean);
+begin
+ if FShowCaption=AValue then exit;
+ FShowCaption:=AValue;
+ if IsControlVisible then
+ begin
+ InvalidatePreferredSize;
+ UpdateVisibleToolbar;
+ end;
+end;
+
procedure TToolButton.SetStyle(Value: TToolButtonStyle);
begin
if FStyle = Value then exit;
FStyle := Value;
InvalidatePreferredSize;
- if Visible then
+ if IsControlVisible then
UpdateVisibleToolbar;
end;
@@ -929,7 +943,9 @@ begin
// calculate text size
TextSize.cx:=0;
TextSize.cy:=0;
- if (Style in [tbsButton,tbsDropDown,tbsCheck]) and (FToolBar.ShowCaptions) then
+ if (Style in [tbsButton,tbsDropDown,tbsCheck]) and (FToolBar.ShowCaptions) and
+ //Allow hide caption only in list mode
+ ((FToolBar.List and ShowCaption) or not FToolBar.List) then
begin
if (Caption<>'') then
begin