]> Pileus Git - ~andy/gtk/commitdiff
Added minimum size parameter to GtkWidgetClass->adjust_size_allocation.
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Tue, 7 Dec 2010 14:45:48 +0000 (23:45 +0900)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Tue, 7 Dec 2010 14:47:40 +0000 (23:47 +0900)
This allows us to add a check before executing
->get_preferred_height_for_width() to ensure we always
request for at least the minimum required size (and lets
us remove the warning in gtkcontainer.c telling implementors
to do this check manually from thier container implementations).

gtk/gtkcontainer.c
gtk/gtksizerequest.c
gtk/gtkwidget.c
gtk/gtkwidget.h

index 5433766c2542f820f29127c3fabf538a33bdfbcd..a5120377cf42d01804d993a4254736852bc2b05a 100644 (file)
  * }
  * ]]></programlisting>
  *
- * Furthermore, in order to ensure correct height-for-width requests it is important
- * to check the input width against the real required minimum width. This can
- * easily be achieved as follows:
- *
- * <programlisting><![CDATA[
- * static void
- * foo_container_get_preferred_height_for_width (GtkWidget *widget, gint for_width,
- *                                               gint *min_height, gint *nat_height)
- * {
- *    if (i_am_in_height_for_width_mode)
- *      {
- *        gint min_width;
- *
- *        GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
- *
- *        for_width = MAX (min_width, for_width);
- *
- *        execute_real_height_for_width_request_code (widget, for_width, min_height, nat_height);
- *      }
- *    else
- *      {
- *        ... fall back on virtual results as mentioned in the previous example ...
- *      }
- * }
- * ]]></programlisting>
- *
  * Height for width requests are generally implemented in terms of a virtual allocation
  * of widgets in the input orientation. Assuming an height-for-width request mode, a container
  * would implement the <function>get_preferred_height_for_width()</function> virtual function by first calling
@@ -327,6 +301,7 @@ static void     gtk_container_adjust_size_request  (GtkWidget         *widget,
                                                     gint              *natural_size);
 static void     gtk_container_adjust_size_allocation (GtkWidget       *widget,
                                                       GtkOrientation   orientation,
+                                                      gint            *minimum_size,
                                                       gint            *natural_size,
                                                       gint            *allocated_pos,
                                                       gint            *allocated_size);
@@ -1809,6 +1784,7 @@ gtk_container_adjust_size_request (GtkWidget         *widget,
 static void
 gtk_container_adjust_size_allocation (GtkWidget         *widget,
                                       GtkOrientation     orientation,
+                                      gint              *minimum_size,
                                       gint              *natural_size,
                                       gint              *allocated_pos,
                                       gint              *allocated_size)
@@ -1821,7 +1797,7 @@ gtk_container_adjust_size_allocation (GtkWidget         *widget,
   if (!GTK_CONTAINER_GET_CLASS (widget)->handle_border_width)
     {
       parent_class->adjust_size_allocation (widget, orientation,
-                                           natural_size, allocated_pos,
+                                           minimum_size, natural_size, allocated_pos,
                                            allocated_size);
       return;
     }
@@ -1845,6 +1821,7 @@ gtk_container_adjust_size_allocation (GtkWidget         *widget,
   else
     {
       *allocated_pos += border_width;
+      *minimum_size -= border_width * 2;
       *natural_size -= border_width * 2;
     }
 
@@ -1856,7 +1833,7 @@ gtk_container_adjust_size_allocation (GtkWidget         *widget,
    * and padding values.
    */
   parent_class->adjust_size_allocation (widget, orientation,
-                                       natural_size, allocated_pos,
+                                       minimum_size, natural_size, allocated_pos,
                                        allocated_size);
 }
 
index ab249484ea7f8190bd54d57a4a4d7be53ab26ec4..c5e49e7db3fa4afa76dc91d4a1bd45eea2ce4822 100644 (file)
@@ -217,23 +217,26 @@ compute_size_for_orientation (GtkWidget         *widget,
             }
           else
             {
-              int ignored_position = 0;
-              int natural_height;
+              gint ignored_position = 0;
+              gint minimum_height;
+              gint natural_height;
 
              /* Pull the base natural height from the cache as it's needed to adjust
               * the proposed 'for_size' */
-             gtk_widget_get_preferred_height (widget, NULL, &natural_height);
+             gtk_widget_get_preferred_height (widget, &minimum_height, &natural_height);
 
               /* convert for_size to unadjusted height (for_size is a proposed allocation) */
               GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
                                                                      GTK_ORIENTATION_VERTICAL,
-                                                                     &natural_height,
+                                                                     &minimum_height,
+                                                                    &natural_height,
                                                                      &ignored_position,
                                                                      &for_size);
 
              push_recursion_check (widget, orientation, for_size);
-              GTK_WIDGET_GET_CLASS (widget)->get_preferred_width_for_height (widget, for_size,
-                                                                              &min_size, &nat_size);
+              GTK_WIDGET_GET_CLASS (widget)->get_preferred_width_for_height (widget, 
+                                                                            MAX (for_size, minimum_height),
+                                                                            &min_size, &nat_size);
              pop_recursion_check (widget, orientation);
             }
         }
@@ -248,22 +251,25 @@ compute_size_for_orientation (GtkWidget         *widget,
           else
             {
               int ignored_position = 0;
+              int minimum_width;
               int natural_width;
 
              /* Pull the base natural width from the cache as it's needed to adjust
               * the proposed 'for_size' */
-             gtk_widget_get_preferred_width (widget, NULL, &natural_width);
+             gtk_widget_get_preferred_width (widget, &minimum_width, &natural_width);
 
               /* convert for_size to unadjusted width (for_size is a proposed allocation) */
               GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
                                                                      GTK_ORIENTATION_HORIZONTAL,
+                                                                    &minimum_width,
                                                                      &natural_width,
                                                                      &ignored_position,
                                                                      &for_size);
 
              push_recursion_check (widget, orientation, for_size);
-              GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, for_size,
-                                                                              &min_size, &nat_size);
+              GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, 
+                                                                            MAX (for_size, minimum_width),
+                                                                            &min_size, &nat_size);
              pop_recursion_check (widget, orientation);
             }
         }
index c82b6eaa86ec3214d6e60a64707934598744b6e3..c685b26d196e30ca4ef1e07e1273487b143781ff 100644 (file)
@@ -641,6 +641,7 @@ static void             gtk_widget_real_adjust_size_request     (GtkWidget
                                                                  gint              *natural_size);
 static void             gtk_widget_real_adjust_size_allocation  (GtkWidget         *widget,
                                                                  GtkOrientation     orientation,
+                                                                 gint              *minimum_size,
                                                                  gint              *natural_size,
                                                                  gint              *allocated_pos,
                                                                  gint              *allocated_size);
@@ -4636,7 +4637,7 @@ gtk_widget_size_allocate (GtkWidget       *widget,
   gboolean alloc_needed;
   gboolean size_changed;
   gboolean position_changed;
-  gint natural_width, natural_height;
+  gint natural_width, natural_height, dummy;
   gint min_width, min_height;
 
   priv = widget->priv;
@@ -4681,7 +4682,7 @@ gtk_widget_size_allocate (GtkWidget       *widget,
        * when aligning implicitly.
        */
       gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
-      gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
+      gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
     }
   else
     {
@@ -4690,18 +4691,20 @@ gtk_widget_size_allocate (GtkWidget     *widget,
        * when aligning implicitly.
        */
       gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
-      gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
+      gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
     }
 
   /* Now that we have the right natural height and width, go ahead and remove any margins from the
    * allocated sizes and possibly limit them to the natural sizes */
   GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
                                                         GTK_ORIENTATION_HORIZONTAL,
+                                                        &dummy,
                                                         &natural_width,
                                                         &adjusted_allocation.x,
                                                         &adjusted_allocation.width);
   GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
                                                         GTK_ORIENTATION_VERTICAL,
+                                                        &dummy,
                                                         &natural_height,
                                                         &adjusted_allocation.y,
                                                         &adjusted_allocation.height);
@@ -5026,10 +5029,12 @@ adjust_for_align(GtkAlign           align,
 static void
 adjust_for_margin(gint               start_margin,
                   gint               end_margin,
+                  gint              *minimum_size,
                   gint              *natural_size,
                   gint              *allocated_pos,
                   gint              *allocated_size)
 {
+  *minimum_size -= (start_margin + end_margin);
   *natural_size -= (start_margin + end_margin);
   *allocated_pos += start_margin;
   *allocated_size -= (start_margin + end_margin);
@@ -5038,6 +5043,7 @@ adjust_for_margin(gint               start_margin,
 static void
 gtk_widget_real_adjust_size_allocation (GtkWidget         *widget,
                                         GtkOrientation     orientation,
+                                        gint              *minimum_size,
                                         gint              *natural_size,
                                         gint              *allocated_pos,
                                         gint              *allocated_size)
@@ -5050,7 +5056,8 @@ gtk_widget_real_adjust_size_allocation (GtkWidget         *widget,
     {
       adjust_for_margin (aux_info->margin.left,
                          aux_info->margin.right,
-                         natural_size, allocated_pos, allocated_size);
+                         minimum_size, natural_size, 
+                        allocated_pos, allocated_size);
       adjust_for_align (aux_info->halign,
                         natural_size, allocated_pos, allocated_size);
     }
@@ -5058,7 +5065,8 @@ gtk_widget_real_adjust_size_allocation (GtkWidget         *widget,
     {
       adjust_for_margin (aux_info->margin.top,
                          aux_info->margin.bottom,
-                         natural_size, allocated_pos, allocated_size);
+                         minimum_size, natural_size, 
+                        allocated_pos, allocated_size);
       adjust_for_align (aux_info->valign,
                         natural_size, allocated_pos, allocated_size);
     }
index 04f7772daf457c0f6ea19a7bc68f44f7867ad3e9..2a079ea0b6baef22a0dcf3a28eaa130803326183 100644 (file)
@@ -415,6 +415,7 @@ struct _GtkWidgetClass
                                            gint              *natural_size);
   void         (* adjust_size_allocation) (GtkWidget         *widget,
                                            GtkOrientation     orientation,
+                                           gint              *minimum_size,
                                            gint              *natural_size,
                                            gint              *allocated_pos,
                                            gint              *allocated_size);