From 5af932d6f06138b84b176a8d5685b0de4a591ed0 Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 7 Nov 2007 23:10:58 +0000 Subject: [PATCH] LCL: TToolBar: implemented simple heuristic for preferredheight from Paul, and calculating NewWidth,NewHeight of WrapButtons git-svn-id: trunk@12774 - --- lcl/comctrls.pp | 2 ++ lcl/include/toolbar.inc | 38 +++++++++++++++++++++++++++++---- lcl/include/toolwindow.inc | 2 +- tools/install/create_fpc_deb.sh | 4 +--- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index beeb1e5ccf..fcd0534667 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -1491,6 +1491,8 @@ type procedure AdjustClientRect(var ARect: TRect); override; class function GetControlClassDefaultSize: TPoint; override; function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override; + procedure CalculatePreferredSize(var PreferredWidth, + PreferredHeight: integer; WithThemeSpace: Boolean); override; function CheckMenuDropdown(Button: TToolButton): Boolean; dynamic; procedure ClickButton(Button: TToolButton); dynamic; procedure CreateParams(var Params: TCreateParams); override; diff --git a/lcl/include/toolbar.inc b/lcl/include/toolbar.inc index 697431ad28..525b8a8da7 100644 --- a/lcl/include/toolbar.inc +++ b/lcl/include/toolbar.inc @@ -394,6 +394,19 @@ begin Result := WrapButtons(NewWidth, NewHeight); end; +procedure TToolBar.CalculatePreferredSize(var PreferredWidth, + PreferredHeight: integer; WithThemeSpace: Boolean); +var + ARect, Adjusted: TRect; +begin + PreferredWidth := 0; + PreferredHeight := ButtonHeight; + ARect := ClientRect; + Adjusted := ARect; + AdjustClientRect(Adjusted); + inc(PreferredHeight, (Adjusted.Top - ARect.Top) - (Adjusted.Bottom - ARect.Bottom)); +end; + {------------------------------------------------------------------------------ function TToolBar.WrapButtons(var NewWidth, NewHeight: Integer): Boolean; @@ -406,7 +419,6 @@ end; ------------------------------------------------------------------------------} function TToolBar.WrapButtons(var NewWidth, NewHeight: Integer): Boolean; var - i: Integer; ARect: TRect; x: Integer; y: Integer; @@ -471,6 +483,10 @@ var until false; end; +var + CurClientRect: TRect; + AdjustClientFrame: TRect; + i: Integer; begin //DebugLn('WrapButtons '); Result:=true; @@ -493,11 +509,16 @@ begin OrderedControls.Sort(TListSortCompare(@CompareToolBarControl)); // position OrderedControls - ARect:=ClientRect; + CurClientRect:=ClientRect; + ARect:=CurClientRect; AdjustClientRect(ARect); + AdjustClientFrame.Left:=ARect.Left-CurClientRect.Left; + AdjustClientFrame.Top:=ARect.Top-CurClientRect.Top; + AdjustClientFrame.Right:=CurClientRect.Right-ARect.Right; + AdjustClientFrame.Bottom:=CurClientRect.Bottom-ARect.Bottom; //DebugLn(['TToolBar.WrapButtons ',DbgSName(Self),' ARect=',dbgs(ARect)]); // important: top, left button must start in the AdjustClientRect top, left - // other Toolbar.AutoSize=true will create an endless loop + // otherwise Toolbar.AutoSize=true will create an endless loop StartX:=ARect.Left; x:=StartX; y:=ARect.Top; @@ -516,13 +537,22 @@ begin w:=NewControlWidth; h:=ButtonHeight; 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; - inc(x,CurControl.Width); + // 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 diff --git a/lcl/include/toolwindow.inc b/lcl/include/toolwindow.inc index 6c623ff033..f0417b620a 100644 --- a/lcl/include/toolwindow.inc +++ b/lcl/include/toolwindow.inc @@ -78,7 +78,7 @@ var ARect: TRect; begin FEdgeBorderType := 0; - if (ebTOP in FEdgeBorders) then + if (ebTop in FEdgeBorders) then FEdgeBorderType := FEdgeBorderType or longint(BF_TOP); if (ebBottom in FEdgeBorders) then FEdgeBorderType := FEdgeBorderType or longint(BF_BOTTOM); diff --git a/tools/install/create_fpc_deb.sh b/tools/install/create_fpc_deb.sh index 1fc6ec5bdd..15cfe904a1 100755 --- a/tools/install/create_fpc_deb.sh +++ b/tools/install/create_fpc_deb.sh @@ -67,9 +67,7 @@ CompilerRelease=`cat $VersionFile | grep ' *release_nr *=.*;' | sed -e 's/[^0-9] CompilerPatch=`cat $VersionFile | grep ' *patch_nr *=.*;' | sed -e 's/[^0-9]//g'` CompilerVersionStr="$CompilerVersion.$CompilerRelease.$CompilerPatch" FPCVersion="$CompilerVersion.$CompilerRelease" -if [ "$CompilerPatch" != "0" ]; then - FPCVersion="$FPCVersion.$CompilerPatch" -fi +FPCVersion="$FPCVersion.$CompilerPatch" echo " $CompilerVersionStr-$FPCRelease"