* Fixed crash when TToolbar.ButtonHeight = 0

* TToolbar.ButtonHeight overrules TToolbutton.Autosize (when > 0)
* Fixed caption update when TToolbar.Autosize = False
* Fixed setting Toolbutton size when alignment allowes

git-svn-id: trunk@14909 -
This commit is contained in:
marc 2008-04-20 16:31:50 +00:00
parent 13a16b7d92
commit b7569c6053
3 changed files with 109 additions and 63 deletions

View File

@ -1395,6 +1395,7 @@ type
procedure MouseLeave; override; procedure MouseLeave; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure Paint; override; procedure Paint; override;
procedure TextChanged; override;
procedure CalculatePreferredSize( procedure CalculatePreferredSize(
var PreferredWidth, PreferredHeight: integer; var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override; WithThemeSpace: Boolean); override;
@ -1414,6 +1415,9 @@ type
procedure Click; override; procedure Click; override;
procedure GetCurrentIcon(var ImageList: TCustomImageList; procedure GetCurrentIcon(var ImageList: TCustomImageList;
var TheIndex: integer); virtual; var TheIndex: integer); virtual;
procedure GetPreferredSize(var PreferredWidth, PreferredHeight: integer;
Raw: boolean = false;
WithThemeSpace: boolean = true); override;
property Index: Integer read GetIndex; property Index: Integer read GetIndex;
published published
property Action; property Action;

View File

@ -24,16 +24,18 @@ var
ToolBar: TToolBar; ToolBar: TToolBar;
Row1: Integer; Row1: Integer;
Row2: Integer; Row2: Integer;
BtnHeight: Integer; HalfBtnHeight, BtnHeight: Integer;
begin begin
Result:=0; Result:=0;
if not (Control1.Parent is TToolBar) then Exit; if not (Control1.Parent is TToolBar) then Exit;
ToolBar := TToolBar(Control1.Parent); ToolBar := TToolBar(Control1.Parent);
BtnHeight := ToolBar.FRealizedButtonHeight; BtnHeight := ToolBar.FRealizedButtonHeight;
if BtnHeight <= 0 then BtnHeight := 1;
HalfBtnHeight := BtnHeight div 2;
Row1:=(Control1.Top+(BtnHeight div 2)) div ToolBar.FRealizedButtonHeight; Row1 := (Control1.Top + HalfBtnHeight) div BtnHeight;
Row2:=(Control2.Top+(BtnHeight div 2)) div ToolBar.FRealizedButtonHeight; Row2 := (Control2.Top + HalfBtnHeight) div BtnHeight;
if Row1<Row2 then if Row1<Row2 then
Result:=-1 Result:=-1
else if Row1>Row2 then else if Row1>Row2 then
@ -362,35 +364,49 @@ var
NewWidth: Integer; NewWidth: Integer;
NewHeight: Integer; NewHeight: Integer;
i: Integer; i: Integer;
CurButton: TToolButton; ChangeW, ChangeH: Boolean;
begin begin
if (FButtonWidth=NewButtonWidth) and (FButtonHeight=NewButtonHeight) then ChangeW := FButtonWidth <> NewButtonWidth;
exit; ChangeH := FButtonHeight <> NewButtonHeight;
if not (ChangeW or ChangeH) then Exit;
FButtonWidth:=NewButtonWidth; FButtonWidth:=NewButtonWidth;
FButtonHeight:=NewButtonHeight; FButtonHeight:=NewButtonHeight;
if ([csLoading,csDestroying]*ComponentState<>[]) or (FUpdateCount > 0) then if FUpdateCount > 0 then Exit;
Exit; if [csLoading, csDestroying] * ComponentState <> [] then Exit;
// set all childs to ButtonWidth ButtonHeight // set all childs to ButtonWidth ButtonHeight
BeginUpdate; BeginUpdate;
try try
for i:=ControlCount-1 downto 0 do begin for i:=ControlCount-1 downto 0 do
CurControl:=Controls[i]; begin
if (CurControl.Align<>alNone) then continue; CurControl := Controls[i];
NewWidth:=CurControl.Width; NewWidth := CurControl.Width;
if (CurControl is TToolButton) and (not CurControl.AutoSize) then begin NewHeight := CurControl.Height;
CurButton:=TToolButton(CurControl);
if CurButton.Style in [tbsButton,tbsCheck,tbsDropDown] then begin // width
if ChangeW
and (ButtonWidth > 0)
and not CurControl.AutoSize
and (CurControl is TToolButton)
and (CurControl.Align in [alNone, alLeft, alRight])
then begin
if TToolButton(CurControl).Style in [tbsButton,tbsCheck,tbsDropDown]
then begin
CurControl.GetPreferredSize(NewWidth,NewHeight); CurControl.GetPreferredSize(NewWidth,NewHeight);
if NewWidth<FButtonWidth then if NewWidth < ButtonWidth then
NewWidth:=FButtonWidth; NewWidth := ButtonWidth;
end; end;
end; end;
if CurControl.AutoSize then
NewHeight:=CurControl.Height // height
else // in horizontal toolbars the height is set by the toolbar independent of autosize
NewHeight:=FButtonHeight; if ChangeH
CurControl.SetBounds(CurControl.Left,CurControl.Top, and (ButtonHeight > 0)
NewWidth,NewHeight); and ((Align in [alTop, alBottom]) or not CurControl.AutoSize)
then NewHeight := ButtonHeight;
CurControl.SetBounds(CurControl.Left, CurControl.Top, NewWidth, NewHeight);
end; end;
finally finally
EndUpdate; EndUpdate;
@ -433,9 +449,8 @@ var
y: Integer; y: Integer;
NewControlWidth: Integer; NewControlWidth: Integer;
CurControl: TControl; CurControl: TControl;
AlignedControls: TList; AlignedControls: TFPList;
StartX: Integer; StartX: Integer;
OrderedControls: TList;
w: LongInt; w: LongInt;
h: LongInt; h: LongInt;
@ -458,9 +473,11 @@ var
NewControlWidth:=PreferredBtnWidth; NewControlWidth:=PreferredBtnWidth;
if NewControlWidth<ButtonWidth then if NewControlWidth<ButtonWidth then
NewControlWidth:=ButtonWidth; NewControlWidth:=ButtonWidth;
end else end
else
NewControlWidth:=CurControl.Width; NewControlWidth:=CurControl.Width;
NewBounds:=Bounds(x,y,NewControlWidth,ButtonHeight); NewBounds:=Bounds(x,y,NewControlWidth,ButtonHeight);
repeat repeat
// move control to the right, until it does not overlap // move control to the right, until it does not overlap
for j:=0 to AlignedControls.Count-1 do begin for j:=0 to AlignedControls.Count-1 do begin
@ -493,6 +510,7 @@ var
end; end;
var var
OrderedControls: TFPList;
CurClientRect: TRect; CurClientRect: TRect;
AdjustClientFrame: TRect; AdjustClientFrame: TRect;
i: Integer; i: Integer;
@ -501,8 +519,8 @@ begin
Result:=true; Result:=true;
NewWidth:=0; NewWidth:=0;
NewHeight:=0; NewHeight:=0;
AlignedControls:=TList.Create; AlignedControls:=TFPList.Create;
OrderedControls:=TList.Create; OrderedControls:=TFPList.Create;
DisableAlign; DisableAlign;
BeginUpdate; BeginUpdate;
try try
@ -532,19 +550,24 @@ begin
x:=StartX; x:=StartX;
y:=ARect.Top; y:=ARect.Top;
i:=0; i:=0;
NewControlWidth:=ButtonWidth; while i<OrderedControls.Count do
while i<OrderedControls.Count do begin begin
CurControl:=TControl(OrderedControls[i]); CurControl := TControl(OrderedControls[i]);
if CurControl.Align=alNone then begin
CalculatePosition; CalculatePosition;
//DebugLn('WrapButtons ',CurControl.Name,':',CurControl.ClassName,' ',x,',',y,',',CurControl.Width,',',CurControl.Height); //DebugLn('WrapButtons ',CurControl.Name,':',CurControl.ClassName,' ',x,',',y,',',CurControl.Width,',',CurControl.Height);
if CurControl.AutoSize then begin if ButtonHeight <= 0
then h := CurControl.Height
else h := ButtonHeight;
if CurControl.AutoSize
then begin
// TODO: center vertically // TODO: center vertically
w:=CurControl.Width; w:=CurControl.Width;
h:=CurControl.Height; if not (align in [alTop, alBottom])
end else begin then h := CurControl.Height; // buttonheight overrules autosize in hor toolbar
end
else begin
w:=NewControlWidth; w:=NewControlWidth;
h:=ButtonHeight;
end; end;
w:=CurControl.Constraints.MinMaxWidth(w); w:=CurControl.Constraints.MinMaxWidth(w);
h:=CurControl.Constraints.MinMaxWidth(h); h:=CurControl.Constraints.MinMaxWidth(h);
@ -568,7 +591,7 @@ begin
x:=StartX; x:=StartX;
inc(y,ButtonHeight); inc(y,ButtonHeight);
end; end;
end;
inc(i); inc(i);
end; end;
FRealizedButtonHeight:=FButtonHeight; FRealizedButtonHeight:=FButtonHeight;

View File

@ -591,6 +591,14 @@ begin
RefreshControl; RefreshControl;
end; end;
procedure TToolButton.TextChanged;
begin
inherited TextChanged;
if FToolbar = nil then Exit;
if FToolbar.ShowCaptions
then Invalidate;
end;
procedure TToolButton.SetMouseInControl(NewMouseInControl: Boolean); procedure TToolButton.SetMouseInControl(NewMouseInControl: Boolean);
begin begin
//DebugLn('TToolButton.SetMouseInControl A ',Name,' Old=',FMouseInControl,' New=',NewMouseInControl); //DebugLn('TToolButton.SetMouseInControl A ',Name,' Old=',FMouseInControl,' New=',NewMouseInControl);
@ -658,6 +666,17 @@ begin
Result := -1; Result := -1;
end; end;
procedure TToolButton.GetPreferredSize(var PreferredWidth, PreferredHeight: integer; Raw: boolean; WithThemeSpace: boolean);
begin
inherited GetPreferredSize(PreferredWidth, PreferredHeight, Raw, WithThemeSpace);
if FToolbar = nil then Exit;
if FToolbar.ButtonHeight <= 0 then Exit;
// buttonheight overrules in hor toolbar
if FToolbar.Align in [alTop, alBottom]
then PreferredHeight := FToolbar.ButtonHeight;
end;
function TToolButton.IsWidthStored: Boolean; function TToolButton.IsWidthStored: Boolean;
begin begin
Result := Style in [tbsSeparator, tbsDivider]; Result := Style in [tbsSeparator, tbsDivider];