From 909fb619f47a888776ff5b54e0902572db8f2010 Mon Sep 17 00:00:00 2001 From: juha Date: Tue, 4 Aug 2020 20:10:17 +0000 Subject: [PATCH] LCL: Reset TBitBtn.Caption when DefaultCaption=True. Issue #37472, patch from Joeny Ang. git-svn-id: trunk@63692 - --- lcl/buttons.pp | 3 ++- lcl/include/bitbtn.inc | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lcl/buttons.pp b/lcl/buttons.pp index d4b650a6c3..e296a9b379 100644 --- a/lcl/buttons.pp +++ b/lcl/buttons.pp @@ -174,6 +174,7 @@ type procedure SetNumGlyphs(AValue: Integer); procedure SetSpacing(AValue: Integer); procedure RealizeKind(ForceDefaults: Boolean); + procedure SetDefaultCaption(const AValue: Boolean); //Return the caption associated with the aKind value. function GetCaptionOfKind(AKind: TBitBtnKind): String; function GetImages: TCustomImageList; @@ -205,7 +206,7 @@ type function CanShowGlyph(const AWithShowMode: Boolean = False): Boolean; public property Caption stored IsCaptionStored; - property DefaultCaption: Boolean read FDefaultCaption write FDefaultCaption default False; + property DefaultCaption: Boolean read FDefaultCaption write SetDefaultCaption default False; property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored; property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1; property Images: TCustomImageList read GetImages write SetImages; diff --git a/lcl/include/bitbtn.inc b/lcl/include/bitbtn.inc index 03fdd3f5da..76ec61b82d 100644 --- a/lcl/include/bitbtn.inc +++ b/lcl/include/bitbtn.inc @@ -230,7 +230,7 @@ begin if (FKind <> bkCustom) and not (csLoading in ComponentState) then RealizeKind(True); if not (csLoading in ComponentState) then - DefaultCaption := FKind <> bkCustom; + FDefaultCaption := FKind <> bkCustom; end; procedure TCustomBitBtn.SetLayout(AValue: TButtonLayout); @@ -348,6 +348,17 @@ begin end; end; +procedure TCustomBitBtn.SetDefaultCaption(const AValue: Boolean); +begin + if FDefaultCaption = AValue then Exit; + FDefaultCaption := AValue; + if (Kind <> bkCustom) and DefaultCaption then + begin + Caption := GetCaptionOfKind(FKind); // will trigger TextChanged + FDefaultCaption := True; + end; +end; + { Return the caption associated with the akind value. This function replaces BitBtnCaption const because the localizing do not work with an const array } @@ -386,7 +397,7 @@ begin if (Kind <> bkCustom) and DefaultCaption and (Caption = '') then begin Caption := GetCaptionOfKind(Kind); // Will trigger TextChanged - DefaultCaption := True; + FDefaultCaption := True; end; end; @@ -394,7 +405,7 @@ procedure TCustomBitBtn.TextChanged; begin inherited TextChanged; AdjustSize; - DefaultCaption := False; + FDefaultCaption := False; end; class function TCustomBitBtn.GetControlClassDefaultSize: TSize;