TSpeedButton autosize does not work
Original Reporter info from Mantis: Dr.Theopolis
-
Reporter name:
Original Reporter info from Mantis: Dr.Theopolis
- Reporter name:
Description:
Whether setting autosize to true in property editor or at runtime, a TSpeedButton control will never resizes when any property is changed that should cause it to resize (for example, caption).
Steps to reproduce:
Place a speed button on a form.
Set autosize property to true.
Set caption to any value such as "test".
Place a button on the form.
At runtime, change the caption of the speedbutton. For example you can use the following handler for the button:
procedure TForm1.Button1Click(Sender: TObject);
begin
speedbutton1.caption := 'a longer caption';
end;
Click the button, and the speed button does not change size. You can also load a glyph, and the button won't change size.
Additional information:
A fix for this, where the caption property is concerned, is to make the following change in speedbutton.inc around line 280 (in Lazarus 1.0.4 or 1.0.6):
procedure TCustomSpeedButton.RealSetText(const Value: TCaption);
begin
if Caption = Value then Exit;
inherited RealSetText(Value);
InvalidatePreferredSize; //<-add this line
AdjustSize; //<-and this one
Invalidate;
end;
In tracing through the source code and comparing TBitBtn and TSpeedButton, both, at some point in the resizing process, come to the following in control.inc around line 5195 (Lazarus 1.0.4):
procedure TControl.GetPreferredSize(var PreferredWidth,
PreferredHeight: integer; Raw: boolean; WithThemeSpace: boolean);
begin
if WithThemeSpace then begin
if not (cfPreferredSizeValid in FControlFlags) then begin
CalculatePreferredSize(FPreferredWidth,FPreferredHeight,true);
Include(FControlFlags,cfPreferredSizeValid);
end;
.
.
.
A TBitBtn does not have cfPreferredSizeValid in FControlFlags when the above procedure is entered, but a TSpeedButton does, and so CalucatePreferredSize doess not happen for TSpeedButton, causing it to not change size.
cfPreferedSizeValid is excluded from FControlFlags in the procedure TControl.InvalidatePreferredSize (control.inc around line 5330). This procedure never gets called when changing a property of a speed button.
There are many other places in speedbutton.inc where a trigger for resizing can be inserted. For example, in TCustomSpeedButton.SetGlyph, .SetMargin, .SetSpacing etc.
Mantis conversion info:
- Mantis ID: 23840
- OS: all
- OS Build: all
- Platform: all
- Version: 1.0.6