On Fri, Mar 20, 2015 at 12:57:47PM +0100, Mattias Gaertner wrote:
> On Fri, 20 Mar 2015 11:31:07 +0000
> Henry Vermaak <henry.verm...@gmail.com> wrote:
> 
> >[...]
> > > The gtk2 interface only knows the current size of the child
> > > control(s). It does not know the preferred size of the child control(s).
> > 
> > So how do we fix this?  If the groupbox code is changed so that it only
> > evaluates its own minimum size, will the autosize code do the rest, i.e.
> > loop over the children and take the maximum width/height?
> 
> The LCL takes care of the child sizes.

OK, so then the use of GetGTKDefaultWidgetSize() in the groupbox is
wrong, since that's what is looping through all the child controls.
I've attached a patch that works for me, it's basically cribbed from
GetGTKDefaultWidgetSize(), so maybe that needs a NoChildren parameter so
that we don't duplicate the gtk2 size request code.

Henry
Index: gtk2wsstdctrls.pp
===================================================================
--- gtk2wsstdctrls.pp	(revision 48429)
+++ gtk2wsstdctrls.pp	(working copy)
@@ -86,7 +86,7 @@
              ): boolean; override;
     class procedure GetPreferredSize(const AWinControl: TWinControl;
                         var PreferredWidth, PreferredHeight: integer;
-                        WithThemeSpace: Boolean); override;
+                        {%H-}WithThemeSpace: Boolean); override;
     class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
     class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
   end;
@@ -2376,9 +2376,18 @@
 class procedure TGtk2WSCustomGroupBox.GetPreferredSize(
   const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer;
   WithThemeSpace: Boolean);
+var
+  Widget: PGtkWidget;
+  Requisition: TGtkRequisition;
 begin
-  GetGTKDefaultWidgetSize(AWinControl, PreferredWidth, PreferredHeight,
-                          WithThemeSpace);
+  Widget := {%H-}PGtkWidget(AWinControl.Handle);
+  // set size to default
+  gtk_widget_set_size_request(Widget, -1, -1);
+  // ask default size
+  gtk_widget_size_request(Widget, @Requisition);
+  PreferredWidth := Requisition.width;
+  PreferredHeight := Requisition.height;
+  gtk_widget_set_size_request(Widget, AWinControl.Width, AWinControl.Height);
 end;
 
 class procedure TGtk2WSCustomGroupBox.SetFont(const AWinControl: TWinControl;
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to