View Issue Details

IDProjectCategoryView StatusLast Update
0020252LazarusLCLpublic2011-10-22 15:17
ReportercobinesAssigned ToFelipe Monteiro de Carvalho 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformWin32OSWindows XPOS VersionSP3
Product Version0.9.31 (SVN)Product Build32171 
Target VersionFixed in Version0.9.31 (SVN) 
Summary0020252: [Patch] BitBtn with Kind<>bkCustom should not save Caption to LFM but be translated via lclstrconsts
DescriptionWhen you put a BitBtn on a form and set its kind to something different than bkCustom then the caption is set to a localized string. That string is saved to LFM file and to LRT and later PO.

If different developers add buttons to the same project using IDE with different locale then in the resulting PO template file will be strings with different languages.

It is fine for Kind=bkCustom because it is the developer who sets the caption.
However if Kind<>bkCustom then the caption should not be saved to LFM file if it does not differ to default value, unless specifically changed by the developer. Then at runtime the caption of the button should be set according to the Kind value, taking into account locale at runtime not at design time.

Of course you may change caption by hand but it should be automatic for common button types.

This also applies to TButtonPanel but if BitBtn is changed TButtonPanel should too.
TagsNo tags attached.
Fixed in Revision32648, 32657
LazTarget0.99.0
Widgetset
Attached Files
  • bitbtn_caption.diff (5,013 bytes)
    Index: lcl/buttons.pp
    ===================================================================
    --- lcl/buttons.pp	(revision 32443)
    +++ lcl/buttons.pp	(working copy)
    @@ -141,6 +141,7 @@
     
       TCustomBitBtn = class(TCustomButton)
       private
    +    FDefaultCaption: Boolean;
         FKind: TBitBtnKind;
         FLayout: TButtonLayout;
         FMargin: integer;
    @@ -165,6 +166,8 @@
         procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
         procedure GlyphChanged(Sender: TObject);
         procedure InitializeWnd; override;
    +    function IsCaptionStored: Boolean; override;
    +    procedure Loaded; override;
         procedure TextChanged; override;
         class function GetControlClassDefaultSize: TSize; override;
         procedure CMAppShowBtnGlyphChanged(var Message: TLMessage); message CM_APPSHOWBTNGLYPHCHANGED;
    @@ -176,6 +179,7 @@
         procedure LoadGlyphFromStock(idButton: Integer);
         function CanShowGlyph: Boolean;
       public
    +    property DefaultCaption: Boolean read FDefaultCaption write FDefaultCaption default False;
         property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored;
         property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1;
         property Kind: TBitBtnKind read FKind write SetKind default bkCustom;
    @@ -202,6 +206,7 @@
         property Color;
         property Constraints;
         property Default;
    +    property DefaultCaption;
         property Enabled;
         property Font;
         property Glyph;
    Index: lcl/controls.pp
    ===================================================================
    --- lcl/controls.pp	(revision 32443)
    +++ lcl/controls.pp	(working copy)
    @@ -1007,7 +1007,6 @@
         function GetUndockWidth: Integer;
         function IsAnchorsStored: boolean;
         function IsBiDiModeStored: boolean;
    -    function IsCaptionStored: Boolean;
         function IsEnabledStored: Boolean;
         function IsFontStored: Boolean;
         function IsHintStored: Boolean;
    @@ -1072,6 +1071,7 @@
         procedure DoBorderSpacingChange(Sender: TObject;
                                         InnerSpaceChanged: Boolean); virtual;
         function IsBorderSpacingInnerBorderStored: Boolean; virtual;
    +    function IsCaptionStored: Boolean; virtual;
         procedure SendMoveSizeMessages(SizeChanged, PosChanged: boolean); virtual;
         procedure ConstrainedResize(var MinWidth, MinHeight,
                                     MaxWidth, MaxHeight: TConstraintSize); virtual;
    Index: lcl/include/bitbtn.inc
    ===================================================================
    --- lcl/include/bitbtn.inc	(revision 32443)
    +++ lcl/include/bitbtn.inc	(working copy)
    @@ -22,6 +22,7 @@
     begin
       inherited Create(TheOwner);
       FCompStyle := csBitBtn;
    +  FDefaultCaption := False;
       FKind := bkCustom;
       FLayout := blGlyphLeft;
       FSpacing := 3;
    @@ -132,9 +133,10 @@
     begin
       if FKind = AValue then Exit;
       FKind := AValue;
    -  if FKind = bkCustom then Exit;
    -  
    -  RealizeKind;
    +  if FKind <> bkCustom then
    +    RealizeKind;
    +  if not (csLoading in ComponentState) then
    +    DefaultCaption := FKind <> bkCustom;
     end;
     
     procedure TCustomBitBtn.SetLayout(AValue: TButtonLayout);
    @@ -256,10 +258,23 @@
       TWSBitBtnClass(WidgetSetClass).SetSpacing(Self, FSpacing);  
     end;
     
    +function TCustomBitBtn.IsCaptionStored: Boolean;
    +begin
    +  Result := inherited IsCaptionStored and not DefaultCaption;
    +end;
    +
    +procedure TCustomBitBtn.Loaded;
    +begin
    +  inherited Loaded;
    +  if (Kind <> bkCustom) and DefaultCaption and (Caption = '') then
    +    Caption := GetCaptionOfKind(Kind);
    +end;
    +
     procedure TCustomBitBtn.TextChanged;
     begin
       inherited TextChanged;
       AdjustSize;
    +  DefaultCaption := False;
     end;
     
     class function TCustomBitBtn.GetControlClassDefaultSize: TSize;
    Index: lcl/include/control.inc
    ===================================================================
    --- lcl/include/control.inc	(revision 32443)
    +++ lcl/include/control.inc	(working copy)
    @@ -1029,6 +1029,14 @@
     end;
     
     {------------------------------------------------------------------------------
    +  TControl IsCaptionStored
    +------------------------------------------------------------------------------}
    +function TControl.IsCaptionStored: Boolean;
    +begin
    +  Result := (ActionLink = nil) or not ActionLink.IsCaptionLinked;
    +end;
    +
    +{------------------------------------------------------------------------------
       procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
     ------------------------------------------------------------------------------}
     procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
    @@ -2831,14 +2839,6 @@
       Result := TControlActionLink;
     end;
     
    -{------------------------------------------------------------------------------
    -  TControl IsCaptionStored
    -------------------------------------------------------------------------------}
    -function TControl.IsCaptionStored: Boolean;
    -begin
    -  Result := (ActionLink = nil) or not ActionLink.IsCaptionLinked;
    -end;
    -
     function TControl.IsClientHeightStored: Boolean;
     begin
       Result:=false;
    
    bitbtn_caption.diff (5,013 bytes)
  • bitbtn_caption2.diff (5,040 bytes)
    Index: lcl/buttons.pp
    ===================================================================
    --- lcl/buttons.pp	(revision 32509)
    +++ lcl/buttons.pp	(working copy)
    @@ -141,6 +141,7 @@
     
       TCustomBitBtn = class(TCustomButton)
       private
    +    FDefaultCaption: Boolean;
         FKind: TBitBtnKind;
         FLayout: TButtonLayout;
         FMargin: integer;
    @@ -165,6 +166,8 @@
         procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
         procedure GlyphChanged(Sender: TObject);
         procedure InitializeWnd; override;
    +    function IsCaptionStored: Boolean;
    +    procedure Loaded; override;
         procedure TextChanged; override;
         class function GetControlClassDefaultSize: TSize; override;
         procedure CMAppShowBtnGlyphChanged(var Message: TLMessage); message CM_APPSHOWBTNGLYPHCHANGED;
    @@ -176,6 +179,8 @@
         procedure LoadGlyphFromStock(idButton: Integer);
         function CanShowGlyph: Boolean;
       public
    +    property Caption stored IsCaptionStored;
    +    property DefaultCaption: Boolean read FDefaultCaption write FDefaultCaption default False;
         property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored;
         property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1;
         property Kind: TBitBtnKind read FKind write SetKind default bkCustom;
    @@ -202,6 +207,7 @@
         property Color;
         property Constraints;
         property Default;
    +    property DefaultCaption;
         property Enabled;
         property Font;
         property Glyph;
    Index: lcl/controls.pp
    ===================================================================
    --- lcl/controls.pp	(revision 32509)
    +++ lcl/controls.pp	(working copy)
    @@ -1009,7 +1009,6 @@
         function GetUndockWidth: Integer;
         function IsAnchorsStored: boolean;
         function IsBiDiModeStored: boolean;
    -    function IsCaptionStored: Boolean;
         function IsEnabledStored: Boolean;
         function IsFontStored: Boolean;
         function IsHintStored: Boolean;
    @@ -1074,6 +1073,7 @@
         procedure DoBorderSpacingChange(Sender: TObject;
                                         InnerSpaceChanged: Boolean); virtual;
         function IsBorderSpacingInnerBorderStored: Boolean; virtual;
    +    function IsCaptionStored: Boolean;
         procedure SendMoveSizeMessages(SizeChanged, PosChanged: boolean); virtual;
         procedure ConstrainedResize(var MinWidth, MinHeight,
                                     MaxWidth, MaxHeight: TConstraintSize); virtual;
    Index: lcl/include/bitbtn.inc
    ===================================================================
    --- lcl/include/bitbtn.inc	(revision 32509)
    +++ lcl/include/bitbtn.inc	(working copy)
    @@ -22,6 +22,7 @@
     begin
       inherited Create(TheOwner);
       FCompStyle := csBitBtn;
    +  FDefaultCaption := False;
       FKind := bkCustom;
       FLayout := blGlyphLeft;
       FSpacing := 3;
    @@ -132,9 +133,10 @@
     begin
       if FKind = AValue then Exit;
       FKind := AValue;
    -  if FKind = bkCustom then Exit;
    -  
    -  RealizeKind;
    +  if FKind <> bkCustom then
    +    RealizeKind;
    +  if not (csLoading in ComponentState) then
    +    DefaultCaption := FKind <> bkCustom;
     end;
     
     procedure TCustomBitBtn.SetLayout(AValue: TButtonLayout);
    @@ -256,10 +258,23 @@
       TWSBitBtnClass(WidgetSetClass).SetSpacing(Self, FSpacing);  
     end;
     
    +function TCustomBitBtn.IsCaptionStored: Boolean;
    +begin
    +  Result := inherited IsCaptionStored and not DefaultCaption;
    +end;
    +
    +procedure TCustomBitBtn.Loaded;
    +begin
    +  inherited Loaded;
    +  if (Kind <> bkCustom) and DefaultCaption and (Caption = '') then
    +    Caption := GetCaptionOfKind(Kind);
    +end;
    +
     procedure TCustomBitBtn.TextChanged;
     begin
       inherited TextChanged;
       AdjustSize;
    +  DefaultCaption := False;
     end;
     
     class function TCustomBitBtn.GetControlClassDefaultSize: TSize;
    Index: lcl/include/control.inc
    ===================================================================
    --- lcl/include/control.inc	(revision 32509)
    +++ lcl/include/control.inc	(working copy)
    @@ -1049,6 +1049,14 @@
     end;
     
     {------------------------------------------------------------------------------
    +  TControl IsCaptionStored
    +------------------------------------------------------------------------------}
    +function TControl.IsCaptionStored: Boolean;
    +begin
    +  Result := (ActionLink = nil) or not ActionLink.IsCaptionLinked;
    +end;
    +
    +{------------------------------------------------------------------------------
       procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
     ------------------------------------------------------------------------------}
     procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
    @@ -2866,14 +2874,6 @@
       Result := TControlActionLink;
     end;
     
    -{------------------------------------------------------------------------------
    -  TControl IsCaptionStored
    -------------------------------------------------------------------------------}
    -function TControl.IsCaptionStored: Boolean;
    -begin
    -  Result := (ActionLink = nil) or not ActionLink.IsCaptionLinked;
    -end;
    -
     function TControl.IsClientHeightStored: Boolean;
     begin
       Result:=false;
    
    bitbtn_caption2.diff (5,040 bytes)
  • bitbtn3.diff (506 bytes)
    Index: lcl/include/bitbtn.inc
    ===================================================================
    --- lcl/include/bitbtn.inc	(revision 32649)
    +++ lcl/include/bitbtn.inc	(working copy)
    @@ -267,7 +267,10 @@
     begin
       inherited Loaded;
       if (Kind <> bkCustom) and DefaultCaption and (Caption = '') then
    -    Caption := GetCaptionOfKind(Kind);
    +  begin
    +    Caption := GetCaptionOfKind(Kind); // Will trigger TextChanged
    +    DefaultCaption := True;
    +  end;
     end;
     
     procedure TCustomBitBtn.TextChanged;
    
    bitbtn3.diff (506 bytes)

Relationships

child of 0020243 resolvedJuha Manninen GraphicPropEdit: implement copy'n'paste 

Activities

2011-09-21 00:33

 

bitbtn_caption.diff (5,013 bytes)
Index: lcl/buttons.pp
===================================================================
--- lcl/buttons.pp	(revision 32443)
+++ lcl/buttons.pp	(working copy)
@@ -141,6 +141,7 @@
 
   TCustomBitBtn = class(TCustomButton)
   private
+    FDefaultCaption: Boolean;
     FKind: TBitBtnKind;
     FLayout: TButtonLayout;
     FMargin: integer;
@@ -165,6 +166,8 @@
     procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
     procedure GlyphChanged(Sender: TObject);
     procedure InitializeWnd; override;
+    function IsCaptionStored: Boolean; override;
+    procedure Loaded; override;
     procedure TextChanged; override;
     class function GetControlClassDefaultSize: TSize; override;
     procedure CMAppShowBtnGlyphChanged(var Message: TLMessage); message CM_APPSHOWBTNGLYPHCHANGED;
@@ -176,6 +179,7 @@
     procedure LoadGlyphFromStock(idButton: Integer);
     function CanShowGlyph: Boolean;
   public
+    property DefaultCaption: Boolean read FDefaultCaption write FDefaultCaption default False;
     property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored;
     property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1;
     property Kind: TBitBtnKind read FKind write SetKind default bkCustom;
@@ -202,6 +206,7 @@
     property Color;
     property Constraints;
     property Default;
+    property DefaultCaption;
     property Enabled;
     property Font;
     property Glyph;
Index: lcl/controls.pp
===================================================================
--- lcl/controls.pp	(revision 32443)
+++ lcl/controls.pp	(working copy)
@@ -1007,7 +1007,6 @@
     function GetUndockWidth: Integer;
     function IsAnchorsStored: boolean;
     function IsBiDiModeStored: boolean;
-    function IsCaptionStored: Boolean;
     function IsEnabledStored: Boolean;
     function IsFontStored: Boolean;
     function IsHintStored: Boolean;
@@ -1072,6 +1071,7 @@
     procedure DoBorderSpacingChange(Sender: TObject;
                                     InnerSpaceChanged: Boolean); virtual;
     function IsBorderSpacingInnerBorderStored: Boolean; virtual;
+    function IsCaptionStored: Boolean; virtual;
     procedure SendMoveSizeMessages(SizeChanged, PosChanged: boolean); virtual;
     procedure ConstrainedResize(var MinWidth, MinHeight,
                                 MaxWidth, MaxHeight: TConstraintSize); virtual;
Index: lcl/include/bitbtn.inc
===================================================================
--- lcl/include/bitbtn.inc	(revision 32443)
+++ lcl/include/bitbtn.inc	(working copy)
@@ -22,6 +22,7 @@
 begin
   inherited Create(TheOwner);
   FCompStyle := csBitBtn;
+  FDefaultCaption := False;
   FKind := bkCustom;
   FLayout := blGlyphLeft;
   FSpacing := 3;
@@ -132,9 +133,10 @@
 begin
   if FKind = AValue then Exit;
   FKind := AValue;
-  if FKind = bkCustom then Exit;
-  
-  RealizeKind;
+  if FKind <> bkCustom then
+    RealizeKind;
+  if not (csLoading in ComponentState) then
+    DefaultCaption := FKind <> bkCustom;
 end;
 
 procedure TCustomBitBtn.SetLayout(AValue: TButtonLayout);
@@ -256,10 +258,23 @@
   TWSBitBtnClass(WidgetSetClass).SetSpacing(Self, FSpacing);  
 end;
 
+function TCustomBitBtn.IsCaptionStored: Boolean;
+begin
+  Result := inherited IsCaptionStored and not DefaultCaption;
+end;
+
+procedure TCustomBitBtn.Loaded;
+begin
+  inherited Loaded;
+  if (Kind <> bkCustom) and DefaultCaption and (Caption = '') then
+    Caption := GetCaptionOfKind(Kind);
+end;
+
 procedure TCustomBitBtn.TextChanged;
 begin
   inherited TextChanged;
   AdjustSize;
+  DefaultCaption := False;
 end;
 
 class function TCustomBitBtn.GetControlClassDefaultSize: TSize;
Index: lcl/include/control.inc
===================================================================
--- lcl/include/control.inc	(revision 32443)
+++ lcl/include/control.inc	(working copy)
@@ -1029,6 +1029,14 @@
 end;
 
 {------------------------------------------------------------------------------
+  TControl IsCaptionStored
+------------------------------------------------------------------------------}
+function TControl.IsCaptionStored: Boolean;
+begin
+  Result := (ActionLink = nil) or not ActionLink.IsCaptionLinked;
+end;
+
+{------------------------------------------------------------------------------
   procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
 ------------------------------------------------------------------------------}
 procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
@@ -2831,14 +2839,6 @@
   Result := TControlActionLink;
 end;
 
-{------------------------------------------------------------------------------
-  TControl IsCaptionStored
-------------------------------------------------------------------------------}
-function TControl.IsCaptionStored: Boolean;
-begin
-  Result := (ActionLink = nil) or not ActionLink.IsCaptionLinked;
-end;
-
 function TControl.IsClientHeightStored: Boolean;
 begin
   Result:=false;
bitbtn_caption.diff (5,013 bytes)

cobines

2011-09-21 00:33

reporter   ~0052075

Last edited: 2011-09-21 00:35

Attached patch:
* Added new property DefaultCaption:Boolean, False by default.
* DefaultCaption is set to True when Kind is set to something <> bkCustom.
* DefaultCaption is set to False when Caption text is changed.
* When loading from LFM, if DefaultCaption is True, Caption is empty and Kind <> bkCustom then Caption is set to default caption for that Kind.
* Caption is not stored if DefaultCaption is True.

DefaultCaption actually does not have to be shown in Object Inspector but I don't know if this is possible.

Flávio Etrusco (notifications not working)

2011-09-21 10:43

developer   ~0052077

Last edited: 2011-10-07 07:55

I would prefer not to add a new virtual method...
Also, is it important to allow the Caption to be blank for non-bkCustom or use the default caption but not translate (i.e. load from the OS)? Otherwise, we could also skip the new property...

-------------------------------- lcl/buttons.pp --------------------------------
@@ -162,6 +162,8 @@ type
   protected
     FButtonGlyph: TButtonGlyph;
     class procedure WSRegisterClass; override;
+    function IsCaptionStored: Boolean;
+    procedure Loaded; override;
     procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
     procedure GlyphChanged(Sender: TObject);
     procedure InitializeWnd; override;
@@ -176,6 +178,7 @@ type
     procedure LoadGlyphFromStock(idButton: Integer);
     function CanShowGlyph: Boolean;
   public
+    property Caption stored IsCaptionStored;
     property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored;
     property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1;
     property Kind: TBitBtnKind read FKind write SetKind default bkCustom;

---------------------------- lcl/include/bitbtn.inc ----------------------------
@@ -247,6 +247,19 @@ begin
   RegisterCustomBitBtn;
 end;
 
+function TCustomBitBtn.IsCaptionStored: Boolean;
+begin
+  Result := ((ActionLink = nil) or not ActionLink.IsCaptionLinked)
+    and ((Kind = bkCustom) or (Caption <> GetCaptionOfKind(Kind)));
+end;
+
+procedure TCustomBitBtn.Loaded;
+begin
+  inherited Loaded;
+  if (Kind <> bkCustom) and (Caption = '') then
+    Caption := GetCaptionOfKind(Kind);
+end;
+
 procedure TCustomBitBtn.InitializeWnd;
 begin
   inherited InitializeWnd;

Well, we could at least set the caption to the default when the user set it empty, so the behavior is consistent.
Or save a #0 or a "token/keyword", but maybe this is a bit too hacky ;)

cobines

2011-09-21 11:52

reporter   ~0052079

Last edited: 2011-09-25 16:31

About adding DefaultCaption:
1. Someone could have used TBitBtn to display the standard glyph only with empty caption. I needed to retain compatibility so that a caption doesn't suddenly appear where previously there wasn't one.
2. If someone really wants to enter the caption in his language that coincides with the default caption then he can, just need to edit the caption text to set DefaultCaption to False.

If they are not important then DefaultCaption property is not needed.

I didn't want to duplicate code from inherited IsCaptionStored into TBitBtn.IsCaptionStored because if the code changes in the base class someone might forget to correct it in TBitBtn too. But if IsCaptionStored can be at least moved from private to protected it can still be called with inherited IsCaptionStored. Virtual is not needed indeed. I didn't know you can redefine "stored" for a property.

[Edit]
Uploaded patch without virtual. I learned how to remove property from OI, so if pt.2 above doesn't apply then I will remove it. If pt.1 also doesn't apply I will upload patch without DefaultCaption.

2011-09-25 16:29

 

bitbtn_caption2.diff (5,040 bytes)
Index: lcl/buttons.pp
===================================================================
--- lcl/buttons.pp	(revision 32509)
+++ lcl/buttons.pp	(working copy)
@@ -141,6 +141,7 @@
 
   TCustomBitBtn = class(TCustomButton)
   private
+    FDefaultCaption: Boolean;
     FKind: TBitBtnKind;
     FLayout: TButtonLayout;
     FMargin: integer;
@@ -165,6 +166,8 @@
     procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
     procedure GlyphChanged(Sender: TObject);
     procedure InitializeWnd; override;
+    function IsCaptionStored: Boolean;
+    procedure Loaded; override;
     procedure TextChanged; override;
     class function GetControlClassDefaultSize: TSize; override;
     procedure CMAppShowBtnGlyphChanged(var Message: TLMessage); message CM_APPSHOWBTNGLYPHCHANGED;
@@ -176,6 +179,8 @@
     procedure LoadGlyphFromStock(idButton: Integer);
     function CanShowGlyph: Boolean;
   public
+    property Caption stored IsCaptionStored;
+    property DefaultCaption: Boolean read FDefaultCaption write FDefaultCaption default False;
     property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored;
     property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1;
     property Kind: TBitBtnKind read FKind write SetKind default bkCustom;
@@ -202,6 +207,7 @@
     property Color;
     property Constraints;
     property Default;
+    property DefaultCaption;
     property Enabled;
     property Font;
     property Glyph;
Index: lcl/controls.pp
===================================================================
--- lcl/controls.pp	(revision 32509)
+++ lcl/controls.pp	(working copy)
@@ -1009,7 +1009,6 @@
     function GetUndockWidth: Integer;
     function IsAnchorsStored: boolean;
     function IsBiDiModeStored: boolean;
-    function IsCaptionStored: Boolean;
     function IsEnabledStored: Boolean;
     function IsFontStored: Boolean;
     function IsHintStored: Boolean;
@@ -1074,6 +1073,7 @@
     procedure DoBorderSpacingChange(Sender: TObject;
                                     InnerSpaceChanged: Boolean); virtual;
     function IsBorderSpacingInnerBorderStored: Boolean; virtual;
+    function IsCaptionStored: Boolean;
     procedure SendMoveSizeMessages(SizeChanged, PosChanged: boolean); virtual;
     procedure ConstrainedResize(var MinWidth, MinHeight,
                                 MaxWidth, MaxHeight: TConstraintSize); virtual;
Index: lcl/include/bitbtn.inc
===================================================================
--- lcl/include/bitbtn.inc	(revision 32509)
+++ lcl/include/bitbtn.inc	(working copy)
@@ -22,6 +22,7 @@
 begin
   inherited Create(TheOwner);
   FCompStyle := csBitBtn;
+  FDefaultCaption := False;
   FKind := bkCustom;
   FLayout := blGlyphLeft;
   FSpacing := 3;
@@ -132,9 +133,10 @@
 begin
   if FKind = AValue then Exit;
   FKind := AValue;
-  if FKind = bkCustom then Exit;
-  
-  RealizeKind;
+  if FKind <> bkCustom then
+    RealizeKind;
+  if not (csLoading in ComponentState) then
+    DefaultCaption := FKind <> bkCustom;
 end;
 
 procedure TCustomBitBtn.SetLayout(AValue: TButtonLayout);
@@ -256,10 +258,23 @@
   TWSBitBtnClass(WidgetSetClass).SetSpacing(Self, FSpacing);  
 end;
 
+function TCustomBitBtn.IsCaptionStored: Boolean;
+begin
+  Result := inherited IsCaptionStored and not DefaultCaption;
+end;
+
+procedure TCustomBitBtn.Loaded;
+begin
+  inherited Loaded;
+  if (Kind <> bkCustom) and DefaultCaption and (Caption = '') then
+    Caption := GetCaptionOfKind(Kind);
+end;
+
 procedure TCustomBitBtn.TextChanged;
 begin
   inherited TextChanged;
   AdjustSize;
+  DefaultCaption := False;
 end;
 
 class function TCustomBitBtn.GetControlClassDefaultSize: TSize;
Index: lcl/include/control.inc
===================================================================
--- lcl/include/control.inc	(revision 32509)
+++ lcl/include/control.inc	(working copy)
@@ -1049,6 +1049,14 @@
 end;
 
 {------------------------------------------------------------------------------
+  TControl IsCaptionStored
+------------------------------------------------------------------------------}
+function TControl.IsCaptionStored: Boolean;
+begin
+  Result := (ActionLink = nil) or not ActionLink.IsCaptionLinked;
+end;
+
+{------------------------------------------------------------------------------
   procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
 ------------------------------------------------------------------------------}
 procedure TControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean);
@@ -2866,14 +2874,6 @@
   Result := TControlActionLink;
 end;
 
-{------------------------------------------------------------------------------
-  TControl IsCaptionStored
-------------------------------------------------------------------------------}
-function TControl.IsCaptionStored: Boolean;
-begin
-  Result := (ActionLink = nil) or not ActionLink.IsCaptionLinked;
-end;
-
 function TControl.IsClientHeightStored: Boolean;
 begin
   Result:=false;
bitbtn_caption2.diff (5,040 bytes)

2011-10-03 13:29

 

bitbtn3.diff (506 bytes)
Index: lcl/include/bitbtn.inc
===================================================================
--- lcl/include/bitbtn.inc	(revision 32649)
+++ lcl/include/bitbtn.inc	(working copy)
@@ -267,7 +267,10 @@
 begin
   inherited Loaded;
   if (Kind <> bkCustom) and DefaultCaption and (Caption = '') then
-    Caption := GetCaptionOfKind(Kind);
+  begin
+    Caption := GetCaptionOfKind(Kind); // Will trigger TextChanged
+    DefaultCaption := True;
+  end;
 end;
 
 procedure TCustomBitBtn.TextChanged;
bitbtn3.diff (506 bytes)

cobines

2011-10-03 13:31

reporter   ~0052440

Sorry, I noticed a bug. DefaultCaption is reset after setting default caption. Patch "bitbtn3.diff" attached.

Flávio Etrusco (notifications not working)

2011-10-07 07:43

developer   ~0052695

Last edited: 2011-10-07 07:51

May I suggest that we make the "no custom caption" the default, for cleaner and smaller LFMs?
I.e. either rename/change logic of DefaultCaption to CustomCaption (my preferred option) or toggle its default/non-stored value.

EDIT: NoDefaultCaption or ForceCustomCaption are better yet ;-)

Issue History

Date Modified Username Field Change
2011-09-15 11:54 cobines New Issue
2011-09-21 00:33 cobines File Added: bitbtn_caption.diff
2011-09-21 00:33 cobines Note Added: 0052075
2011-09-21 00:35 cobines Note Edited: 0052075
2011-09-21 10:43 Flávio Etrusco (notifications not working) Note Added: 0052077
2011-09-21 11:52 cobines Note Added: 0052079
2011-09-25 16:29 cobines File Added: bitbtn_caption2.diff
2011-09-25 16:31 cobines Note Edited: 0052079
2011-10-03 10:49 Felipe Monteiro de Carvalho Relationship added child of 0020243
2011-10-03 10:49 Felipe Monteiro de Carvalho LazTarget => 0.99.0
2011-10-03 10:49 Felipe Monteiro de Carvalho Summary BitBtn with Kind<>bkCustom should not save Caption to LFM but be translated via lclstrconsts => [Patch] BitBtn with Kind<>bkCustom should not save Caption to LFM but be translated via lclstrconsts
2011-10-03 10:56 Felipe Monteiro de Carvalho Status new => assigned
2011-10-03 10:56 Felipe Monteiro de Carvalho Assigned To => Felipe Monteiro de Carvalho
2011-10-03 10:56 Felipe Monteiro de Carvalho Fixed in Revision => 32648
2011-10-03 10:56 Felipe Monteiro de Carvalho Status assigned => resolved
2011-10-03 10:56 Felipe Monteiro de Carvalho Fixed in Version => 0.9.31 (SVN)
2011-10-03 10:56 Felipe Monteiro de Carvalho Resolution open => fixed
2011-10-03 13:29 cobines File Added: bitbtn3.diff
2011-10-03 13:31 cobines Status resolved => assigned
2011-10-03 13:31 cobines Resolution fixed => reopened
2011-10-03 13:31 cobines Note Added: 0052440
2011-10-03 17:25 Felipe Monteiro de Carvalho Fixed in Revision 32648 => 32648, 32657
2011-10-03 17:25 Felipe Monteiro de Carvalho Status assigned => resolved
2011-10-03 17:25 Felipe Monteiro de Carvalho Resolution reopened => fixed
2011-10-07 07:43 Flávio Etrusco (notifications not working) Note Added: 0052695
2011-10-07 07:51 Flávio Etrusco (notifications not working) Note Edited: 0052695
2011-10-07 07:55 Flávio Etrusco (notifications not working) Note Edited: 0052077
2011-10-22 15:17 cobines Status resolved => closed