From b7569c6053f159acf80f21fad92e4f511f5e1985 Mon Sep 17 00:00:00 2001 From: marc Date: Sun, 20 Apr 2008 16:31:50 +0000 Subject: [PATCH] * 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 - --- lcl/comctrls.pp | 4 + lcl/include/toolbar.inc | 149 +++++++++++++++++++++---------------- lcl/include/toolbutton.inc | 19 +++++ 3 files changed, 109 insertions(+), 63 deletions(-) diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index 9d05f6486a..2464710bba 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -1395,6 +1395,7 @@ type procedure MouseLeave; override; procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure Paint; override; + procedure TextChanged; override; procedure CalculatePreferredSize( var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override; @@ -1414,6 +1415,9 @@ type procedure Click; override; procedure GetCurrentIcon(var ImageList: TCustomImageList; var TheIndex: integer); virtual; + procedure GetPreferredSize(var PreferredWidth, PreferredHeight: integer; + Raw: boolean = false; + WithThemeSpace: boolean = true); override; property Index: Integer read GetIndex; published property Action; diff --git a/lcl/include/toolbar.inc b/lcl/include/toolbar.inc index 910e1232df..91c3932290 100644 --- a/lcl/include/toolbar.inc +++ b/lcl/include/toolbar.inc @@ -24,16 +24,18 @@ var ToolBar: TToolBar; Row1: Integer; Row2: Integer; - BtnHeight: Integer; + HalfBtnHeight, BtnHeight: Integer; begin Result:=0; if not (Control1.Parent is TToolBar) then Exit; ToolBar := TToolBar(Control1.Parent); BtnHeight := ToolBar.FRealizedButtonHeight; + if BtnHeight <= 0 then BtnHeight := 1; + HalfBtnHeight := BtnHeight div 2; - Row1:=(Control1.Top+(BtnHeight div 2)) div ToolBar.FRealizedButtonHeight; - Row2:=(Control2.Top+(BtnHeight div 2)) div ToolBar.FRealizedButtonHeight; + Row1 := (Control1.Top + HalfBtnHeight) div BtnHeight; + Row2 := (Control2.Top + HalfBtnHeight) div BtnHeight; if Row1Row2 then @@ -362,35 +364,49 @@ var NewWidth: Integer; NewHeight: Integer; i: Integer; - CurButton: TToolButton; + ChangeW, ChangeH: Boolean; begin - if (FButtonWidth=NewButtonWidth) and (FButtonHeight=NewButtonHeight) then - exit; + ChangeW := FButtonWidth <> NewButtonWidth; + ChangeH := FButtonHeight <> NewButtonHeight; + if not (ChangeW or ChangeH) then Exit; + FButtonWidth:=NewButtonWidth; FButtonHeight:=NewButtonHeight; - if ([csLoading,csDestroying]*ComponentState<>[]) or (FUpdateCount > 0) then - Exit; + if FUpdateCount > 0 then Exit; + if [csLoading, csDestroying] * ComponentState <> [] then Exit; + // set all childs to ButtonWidth ButtonHeight BeginUpdate; try - for i:=ControlCount-1 downto 0 do begin - CurControl:=Controls[i]; - if (CurControl.Align<>alNone) then continue; - NewWidth:=CurControl.Width; - if (CurControl is TToolButton) and (not CurControl.AutoSize) then begin - CurButton:=TToolButton(CurControl); - if CurButton.Style in [tbsButton,tbsCheck,tbsDropDown] then begin + for i:=ControlCount-1 downto 0 do + begin + CurControl := Controls[i]; + NewWidth := CurControl.Width; + NewHeight := CurControl.Height; + + // 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); - if NewWidth 0) + and ((Align in [alTop, alBottom]) or not CurControl.AutoSize) + then NewHeight := ButtonHeight; + + CurControl.SetBounds(CurControl.Left, CurControl.Top, NewWidth, NewHeight); end; finally EndUpdate; @@ -433,9 +449,8 @@ var y: Integer; NewControlWidth: Integer; CurControl: TControl; - AlignedControls: TList; + AlignedControls: TFPList; StartX: Integer; - OrderedControls: TList; w: LongInt; h: LongInt; @@ -458,9 +473,11 @@ var NewControlWidth:=PreferredBtnWidth; if NewControlWidthx) or (CurControl.Top<>y) - or (CurControl.Width<>w) or (CurControl.Height<>h) then begin - //DebugLn(['TToolBar.WrapButtons moving child: ',DbgSName(CurControl),' Old=',dbgs(CurControl.BoundsRect),' New=',dbgs(Bounds(x,y,w,h))]); - CurControl.SetBoundsKeepBase(x,y,w,h); - end; - - // adjust NewWidth, NewHeight - NewWidth:=Max(NewWidth, - CurControl.Left+CurControl.Width+AdjustClientFrame.Right); - NewHeight:=Max(NewHeight, - CurControl.Top+CurControl.Height+AdjustClientFrame.Bottom); + while i start new line - x:=StartX; - inc(y,ButtonHeight); - end; + CalculatePosition; + //DebugLn('WrapButtons ',CurControl.Name,':',CurControl.ClassName,' ',x,',',y,',',CurControl.Width,',',CurControl.Height); + if ButtonHeight <= 0 + then h := CurControl.Height + else h := ButtonHeight; + if CurControl.AutoSize + then begin + // TODO: center vertically + w:=CurControl.Width; + if not (align in [alTop, alBottom]) + then h := CurControl.Height; // buttonheight overrules autosize in hor toolbar + end + else begin + w:=NewControlWidth; end; + w:=CurControl.Constraints.MinMaxWidth(w); + h:=CurControl.Constraints.MinMaxWidth(h); + if (CurControl.Left<>x) or (CurControl.Top<>y) + or (CurControl.Width<>w) or (CurControl.Height<>h) then begin + //DebugLn(['TToolBar.WrapButtons moving child: ',DbgSName(CurControl),' Old=',dbgs(CurControl.BoundsRect),' New=',dbgs(Bounds(x,y,w,h))]); + CurControl.SetBoundsKeepBase(x,y,w,h); + end; + + // adjust NewWidth, NewHeight + NewWidth:=Max(NewWidth, + CurControl.Left+CurControl.Width+AdjustClientFrame.Right); + NewHeight:=Max(NewHeight, + CurControl.Top+CurControl.Height+AdjustClientFrame.Bottom); + + // step to next position + inc(x,w); + if (not Wrapable) and (CurControl is TToolButton) + and (TToolButton(CurControl).Wrap) then begin + // user forced wrap -> start new line + x:=StartX; + inc(y,ButtonHeight); + end; + inc(i); end; FRealizedButtonHeight:=FButtonHeight; diff --git a/lcl/include/toolbutton.inc b/lcl/include/toolbutton.inc index bae7648897..8bb3d6cd24 100644 --- a/lcl/include/toolbutton.inc +++ b/lcl/include/toolbutton.inc @@ -591,6 +591,14 @@ begin RefreshControl; end; +procedure TToolButton.TextChanged; +begin + inherited TextChanged; + if FToolbar = nil then Exit; + if FToolbar.ShowCaptions + then Invalidate; +end; + procedure TToolButton.SetMouseInControl(NewMouseInControl: Boolean); begin //DebugLn('TToolButton.SetMouseInControl A ',Name,' Old=',FMouseInControl,' New=',NewMouseInControl); @@ -658,6 +666,17 @@ begin Result := -1; 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; begin Result := Style in [tbsSeparator, tbsDivider];