mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 22:40:56 +02:00
LCL: fixed handling BaseBounds=0x0, TButtonPanel: using Align, bug #17719
git-svn-id: trunk@27929 -
This commit is contained in:
parent
38df7bec96
commit
2e3d83111a
@ -19,8 +19,8 @@ unit ButtonPanel;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Types, SysUtils, Classes, Controls, ExtCtrls, StdCtrls, Buttons, Forms, GraphType,
|
Math, Types, SysUtils, Classes, Controls, ExtCtrls, StdCtrls, Buttons, Forms,
|
||||||
Graphics, LMessages, LCLStrConsts, Themes;
|
GraphType, Graphics, LMessages, LCLStrConsts, Themes;
|
||||||
|
|
||||||
type
|
type
|
||||||
TButtonOrder = (boDefault, boCloseCancelOK, boCloseOKCancel);
|
TButtonOrder = (boDefault, boCloseCancelOK, boCloseOKCancel);
|
||||||
@ -81,15 +81,10 @@ type
|
|||||||
procedure UpdateBevel;
|
procedure UpdateBevel;
|
||||||
procedure UpdateButtonOrder;
|
procedure UpdateButtonOrder;
|
||||||
procedure UpdateSizes;
|
procedure UpdateSizes;
|
||||||
|
procedure UpdateButtonLayout;
|
||||||
protected
|
protected
|
||||||
procedure CalculatePreferredSize(
|
|
||||||
var PreferredWidth, PreferredHeight: integer;
|
|
||||||
WithThemeSpace: Boolean); override;
|
|
||||||
function CreateControlBorderSpacing: TControlBorderSpacing; override;
|
function CreateControlBorderSpacing: TControlBorderSpacing; override;
|
||||||
function CustomAlignInsertBefore(AControl1, AControl2: TControl): Boolean; override;
|
function CustomAlignInsertBefore(AControl1, AControl2: TControl): Boolean; override;
|
||||||
procedure CustomAlignPosition(AControl: TControl; var ANewLeft, ANewTop, ANewWidth,
|
|
||||||
ANewHeight: Integer; var AlignRect: TRect;
|
|
||||||
AlignInfo: TAlignInfo); override;
|
|
||||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||||
procedure SetAlign(Value: TAlign); override;
|
procedure SetAlign(Value: TAlign); override;
|
||||||
procedure CMAppShowBtnGlyphChanged(var Message: TLMessage); message CM_APPSHOWBTNGLYPHCHANGED;
|
procedure CMAppShowBtnGlyphChanged(var Message: TLMessage); message CM_APPSHOWBTNGLYPHCHANGED;
|
||||||
@ -163,6 +158,8 @@ begin
|
|||||||
RegisterComponents('Misc', [TButtonPanel]);
|
RegisterComponents('Misc', [TButtonPanel]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TPanelBitBtn }
|
||||||
|
|
||||||
constructor TPanelBitBtn.Create(AOwner: TComponent);
|
constructor TPanelBitBtn.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
@ -170,27 +167,39 @@ begin
|
|||||||
SetSubComponent(True);
|
SetSubComponent(True);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCustomButtonPanel }
|
||||||
|
|
||||||
procedure TCustomButtonPanel.DoShowButtons;
|
procedure TCustomButtonPanel.DoShowButtons;
|
||||||
var
|
var
|
||||||
btn: TPanelButton;
|
btn: TPanelButton;
|
||||||
|
aButton: TPanelBitBtn;
|
||||||
begin
|
begin
|
||||||
|
DisableAutoSizing;
|
||||||
|
|
||||||
for btn := Low(btn) to High(btn) do
|
for btn := Low(btn) to High(btn) do
|
||||||
begin
|
begin
|
||||||
if FButtons[btn] = nil
|
if FButtons[btn] = nil
|
||||||
then CreateButton(btn);
|
then CreateButton(btn);
|
||||||
|
aButton:=FButtons[btn];
|
||||||
|
|
||||||
if btn in FShowButtons
|
if btn in FShowButtons
|
||||||
then begin
|
then begin
|
||||||
FButtons[btn].Visible := True;
|
aButton.Visible := True;
|
||||||
FButtons[btn].Enabled := True;
|
aButton.Enabled := True;
|
||||||
|
if csDesigning in ComponentState then
|
||||||
|
aButton.ControlStyle:=aButton.ControlStyle-[csNoDesignVisible];
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
FButtons[btn].Visible := False;
|
aButton.Visible := False;
|
||||||
FButtons[btn].Enabled := False;
|
aButton.Enabled := False;
|
||||||
|
if csDesigning in ComponentState then
|
||||||
|
aButton.ControlStyle:=aButton.ControlStyle+[csNoDesignVisible];
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
UpdateButtonOrder;
|
UpdateButtonOrder;
|
||||||
|
UpdateButtonLayout;
|
||||||
|
EnableAutoSizing;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomButtonPanel.SetShowButtons(Value: TPanelButtons);
|
procedure TCustomButtonPanel.SetShowButtons(Value: TPanelButtons);
|
||||||
@ -207,6 +216,7 @@ procedure TCustomButtonPanel.DoShowGlyphs;
|
|||||||
var
|
var
|
||||||
btn: TPanelButton;
|
btn: TPanelButton;
|
||||||
begin
|
begin
|
||||||
|
DisableAutoSizing;
|
||||||
for btn := Low(btn) to High(btn) do
|
for btn := Low(btn) to High(btn) do
|
||||||
begin
|
begin
|
||||||
if FButtons[btn] = nil then Continue;
|
if FButtons[btn] = nil then Continue;
|
||||||
@ -220,6 +230,7 @@ begin
|
|||||||
FButtons[btn].Glyph.Assign(nil);
|
FButtons[btn].Glyph.Assign(nil);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
EnableAutoSizing;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomButtonPanel.SetShowGlyphs(Value: TPanelButtons);
|
procedure TCustomButtonPanel.SetShowGlyphs(Value: TPanelButtons);
|
||||||
@ -243,12 +254,25 @@ begin
|
|||||||
if FBevel = nil then Exit;
|
if FBevel = nil then Exit;
|
||||||
|
|
||||||
case Align of
|
case Align of
|
||||||
alTop: FBevel.Shape := bsBottomLine;
|
alTop:
|
||||||
alLeft: FBevel.Shape := bsRightLine;
|
begin
|
||||||
alRight: FBevel.Shape := bsLeftLine;
|
FBevel.Shape := bsBottomLine;
|
||||||
|
FBevel.Align := alBottom;
|
||||||
|
end;
|
||||||
|
alLeft:
|
||||||
|
begin
|
||||||
|
FBevel.Shape := bsRightLine;
|
||||||
|
FBevel.Align := alRight;
|
||||||
|
end;
|
||||||
|
alRight:
|
||||||
|
begin
|
||||||
|
FBevel.Shape := bsLeftLine;
|
||||||
|
FBevel.Align := alLeft;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
// default to bottom
|
// default to bottom
|
||||||
FBevel.Shape := bsTopLine;
|
FBevel.Shape := bsTopLine;
|
||||||
|
FBevel.Align := alTop;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Align in [alLeft, alRight]
|
if Align in [alLeft, alRight]
|
||||||
@ -286,25 +310,28 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomButtonPanel.CalculatePreferredSize(var PreferredWidth,
|
procedure TCustomButtonPanel.UpdateButtonLayout;
|
||||||
PreferredHeight: integer; WithThemeSpace: Boolean);
|
var
|
||||||
|
aButton: TPanelBitBtn;
|
||||||
|
btn: TPanelButton;
|
||||||
begin
|
begin
|
||||||
if HandleAllocated then
|
for btn := Low(TPanelButton) to High(TPanelButton) do
|
||||||
begin
|
begin
|
||||||
UpdateSizes;
|
aButton:=FButtons[btn];
|
||||||
if Align in [alTop, alBottom] then
|
if FButtons[btn] = nil then Continue;
|
||||||
|
if Align in [alLeft,alRight] then
|
||||||
begin
|
begin
|
||||||
PreferredHeight := FButtonsHeight;
|
if btn=pbHelp then
|
||||||
if ShowBevel then
|
aButton.Align:=alBottom
|
||||||
inc(PreferredHeight, Spacing + FBevel.Height);
|
else
|
||||||
end
|
aButton.Align:=alTop;
|
||||||
else
|
end else begin
|
||||||
if Align in [alLeft, alRight] then
|
if btn=pbHelp then
|
||||||
begin
|
aButton.Align:=alLeft
|
||||||
PreferredWidth := FButtonsWidth;
|
else
|
||||||
if ShowBevel then
|
aButton.Align:=alRight;
|
||||||
inc(PreferredWidth, Spacing + FBevel.Width);
|
|
||||||
end;
|
end;
|
||||||
|
FButtons[btn].Default := FDefaultButton = btn;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -335,6 +362,7 @@ begin
|
|||||||
DisableAutoSizing;
|
DisableAutoSizing;
|
||||||
try
|
try
|
||||||
inherited SetAlign(Value);
|
inherited SetAlign(Value);
|
||||||
|
UpdateButtonLayout;
|
||||||
UpdateBevel;
|
UpdateBevel;
|
||||||
UpdateSizes;
|
UpdateSizes;
|
||||||
finally
|
finally
|
||||||
@ -391,7 +419,6 @@ begin
|
|||||||
FBevel := TBevel.Create(Self);
|
FBevel := TBevel.Create(Self);
|
||||||
FBevel.Parent := Self;
|
FBevel.Parent := Self;
|
||||||
FBevel.Name := 'Bevel';
|
FBevel.Name := 'Bevel';
|
||||||
FBevel.Align := alCustom;
|
|
||||||
|
|
||||||
UpdateBevel;
|
UpdateBevel;
|
||||||
finally
|
finally
|
||||||
@ -527,101 +554,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomButtonPanel.CustomAlignPosition(AControl: TControl; var ANewLeft, ANewTop,
|
|
||||||
ANewWidth, ANewHeight: Integer; var AlignRect: TRect; AlignInfo: TAlignInfo);
|
|
||||||
|
|
||||||
function GetPrev: TControl;
|
|
||||||
var
|
|
||||||
Index: Integer;
|
|
||||||
begin
|
|
||||||
Index := AlignInfo.ControlIndex;
|
|
||||||
while Index > 0 do
|
|
||||||
begin
|
|
||||||
dec(Index);
|
|
||||||
Result := TControl(AlignInfo.AlignList[Index]);
|
|
||||||
if Result.Visible then
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
Result := nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
Prev: TControl;
|
|
||||||
begin
|
|
||||||
if AControl = FBevel
|
|
||||||
then begin
|
|
||||||
case Align of
|
|
||||||
alTop: begin
|
|
||||||
ANewTop := AlignRect.Top + FSpacing + FButtonsHeight;
|
|
||||||
ANewLeft := AlignRect.Left;
|
|
||||||
ANewWidth := AlignRect.Right - AlignRect.Left;
|
|
||||||
end;
|
|
||||||
alLeft: begin
|
|
||||||
ANewTop := AlignRect.Top;
|
|
||||||
ANewLeft := AlignRect.Left + FSpacing + FButtonsWidth;
|
|
||||||
ANewHeight := AlignRect.Bottom - AlignRect.Top;
|
|
||||||
end;
|
|
||||||
alRight: begin
|
|
||||||
ANewTop := AlignRect.Top;
|
|
||||||
ANewLeft := AlignRect.Right - ANewWidth - FSpacing - FButtonsWidth;
|
|
||||||
ANewHeight := AlignRect.Bottom - AlignRect.Top;
|
|
||||||
end;
|
|
||||||
else
|
|
||||||
// bottom, none and custom
|
|
||||||
ANewTop := AlignRect.Bottom - ANewHeight - FSpacing - FButtonsHeight;
|
|
||||||
ANewLeft := AlignRect.Left;
|
|
||||||
ANewWidth := AlignRect.Right - AlignRect.Left;
|
|
||||||
end;
|
|
||||||
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if (csDesigning in ComponentState) and not AControl.Visible
|
|
||||||
then begin
|
|
||||||
// when designing, hide doesn't work, so position button outside panel
|
|
||||||
ANewLeft := -ANewWidth - 100;
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// make all buttons the same height
|
|
||||||
ANewHeight := FButtonsHeight;
|
|
||||||
if Align in [alLeft, alRight]
|
|
||||||
then begin
|
|
||||||
ANewWidth := FButtonsWidth;
|
|
||||||
|
|
||||||
if AControl = FButtons[pbHelp]
|
|
||||||
then begin
|
|
||||||
ANewTop := AlignRect.Bottom - ANewHeight;
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
Prev := GetPrev;
|
|
||||||
if Prev = nil then
|
|
||||||
ANewTop := AlignRect.Top
|
|
||||||
else
|
|
||||||
ANewTop := Prev.Top + Prev.Height + FSpacing;
|
|
||||||
end;
|
|
||||||
if Align = alLeft
|
|
||||||
then ANewLeft := AlignRect.Left
|
|
||||||
else ANewLeft := AlignRect.Right - ANewWidth;
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
if AControl = FButtons[pbHelp]
|
|
||||||
then begin
|
|
||||||
ANewLeft := 0
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
Prev := GetPrev;
|
|
||||||
if Prev = nil then
|
|
||||||
ANewLeft := AlignRect.Right - ANewWidth
|
|
||||||
else
|
|
||||||
ANewLeft := Prev.Left - ANewWidth - FSpacing;
|
|
||||||
end;
|
|
||||||
if Align = alTop
|
|
||||||
then ANewTop := AlignRect.Top
|
|
||||||
else ANewTop := AlignRect.Bottom - ANewHeight;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TCustomButtonPanel.Destroy;
|
destructor TCustomButtonPanel.Destroy;
|
||||||
var
|
var
|
||||||
btn: TPanelButton;
|
btn: TPanelButton;
|
||||||
|
@ -4233,6 +4233,7 @@ begin
|
|||||||
for Side:=Low(FAnchorSides) to High(FAnchorSides) do
|
for Side:=Low(FAnchorSides) to High(FAnchorSides) do
|
||||||
FAnchorSides[Side]:=TAnchorSide.Create(Self,Side);
|
FAnchorSides[Side]:=TAnchorSide.Create(Self,Side);
|
||||||
|
|
||||||
|
FBaseBounds.Right:=-1;
|
||||||
FAnchors := [akLeft,akTop];
|
FAnchors := [akLeft,akTop];
|
||||||
FAlign := alNone;
|
FAlign := alNone;
|
||||||
FCaptureMouseButtons := [mbLeft];
|
FCaptureMouseButtons := [mbLeft];
|
||||||
|
@ -37,7 +37,7 @@ const CheckClientRectName = 'LCLInterfaceRadioGroup';
|
|||||||
{off $DEFINE VerboseSizeMsg}
|
{off $DEFINE VerboseSizeMsg}
|
||||||
{off $DEFINE CHECK_POSITION}
|
{off $DEFINE CHECK_POSITION}
|
||||||
{$IFDEF CHECK_POSITION}
|
{$IFDEF CHECK_POSITION}
|
||||||
const CheckPostionClassName = 'cccBitBtn1';
|
const CheckPostionClassName = 'TButtonPanel';
|
||||||
const CheckPostionName = 'SaveAndRebuildButton';
|
const CheckPostionName = 'SaveAndRebuildButton';
|
||||||
const CheckPostionParentName = 'xxxEnvVarsPage';
|
const CheckPostionParentName = 'xxxEnvVarsPage';
|
||||||
|
|
||||||
@ -2710,8 +2710,7 @@ var
|
|||||||
|
|
||||||
// get base bounds of Control
|
// get base bounds of Control
|
||||||
CurBaseBounds:=Control.FBaseBounds;
|
CurBaseBounds:=Control.FBaseBounds;
|
||||||
if (CurBaseBounds.Right=CurBaseBounds.Left)
|
if not (cfBaseBoundsValid in FControlFlags) then
|
||||||
and (CurBaseBounds.Bottom=CurBaseBounds.Top) then
|
|
||||||
CurBaseBounds:=Control.BoundsRect;
|
CurBaseBounds:=Control.BoundsRect;
|
||||||
|
|
||||||
{$IFDEF CHECK_POSITION}
|
{$IFDEF CHECK_POSITION}
|
||||||
|
Loading…
Reference in New Issue
Block a user