[gtk+/gtk-3-10] toolbar: implement minimum and natural sizes in _get_preferred family



commit 713e798419ef7d97964e07708bb9bd800caf909e
Author: Jonh Wendell <jonh wendell intel com>
Date:   Wed Jul 31 11:42:50 2013 -0300

    toolbar: implement minimum and natural sizes in _get_preferred family
    
    currently it's using the same sizes for natural and minimum, but it
    happens that, when it's allowed to use the arrow, the minimum size
    can be smaller than natural.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=693227

 gtk/gtktoolbar.c |   71 ++++++++++++++++++++++++++++-------------------------
 1 files changed, 37 insertions(+), 34 deletions(-)
---
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index ac07f3e..d8fb693 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -918,7 +918,8 @@ get_widget_padding_and_border (GtkWidget *widget,
 
 static void
 gtk_toolbar_size_request (GtkWidget      *widget,
-                         GtkRequisition *requisition)
+                         GtkRequisition *min_requisition,
+                         GtkRequisition *nat_requisition)
 {
   GtkToolbar *toolbar = GTK_TOOLBAR (widget);
   GtkToolbarPrivate *priv = toolbar->priv;
@@ -928,10 +929,10 @@ gtk_toolbar_size_request (GtkWidget      *widget,
   gint max_homogeneous_child_width;
   gint max_homogeneous_child_height;
   gint homogeneous_size;
-  gint long_req;
   gint pack_front_size;
   GtkBorder padding;
   guint border_width;
+  gint extra_width, extra_height;
   GtkRequisition arrow_requisition;
   
   max_homogeneous_child_width = 0;
@@ -990,47 +991,43 @@ gtk_toolbar_size_request (GtkWidget      *widget,
 
       pack_front_size += size;
     }
+
+  arrow_requisition.height = 0;
+  arrow_requisition.width = 0;
   
   if (priv->show_arrow)
-    {
-      gtk_widget_get_preferred_size (priv->arrow_button,
+    gtk_widget_get_preferred_size (priv->arrow_button,
                                      &arrow_requisition, NULL);
-
-      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
-       long_req = arrow_requisition.width;
-      else
-       long_req = arrow_requisition.height;
-      
-      /* There is no point requesting space for the arrow if that would take
-       * up more space than all the items combined
-       */
-      long_req = MIN (long_req, pack_front_size);
-    }
-  else
-    {
-      arrow_requisition.height = 0;
-      arrow_requisition.width = 0;
-      
-      long_req = pack_front_size;
-    }
   
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      requisition->width = long_req;
-      requisition->height = MAX (max_child_height, arrow_requisition.height);
+      nat_requisition->width = pack_front_size;
+      nat_requisition->height = MAX (max_child_height, arrow_requisition.height);
+
+      min_requisition->width = priv->show_arrow ? arrow_requisition.width : nat_requisition->width;
+      min_requisition->height = nat_requisition->height;
     }
   else
     {
-      requisition->height = long_req;
-      requisition->width = MAX (max_child_width, arrow_requisition.width);
+      nat_requisition->height = pack_front_size;
+      nat_requisition->width = MAX (max_child_width, arrow_requisition.width);
+
+      min_requisition->height = priv->show_arrow ? arrow_requisition.height : nat_requisition->height;
+      min_requisition->width = nat_requisition->width;
     }
 
   /* Extra spacing */
   border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
   get_widget_padding_and_border (widget, &padding);
 
-  requisition->width += 2 * border_width + padding.left + padding.right;
-  requisition->height += 2 * border_width + padding.top + padding.bottom;
+  extra_width = 2 * border_width + padding.left + padding.right;
+  extra_height = 2 * border_width + padding.top + padding.bottom;
+
+  nat_requisition->width += extra_width;
+  nat_requisition->height += extra_height;
+
+  min_requisition->width += extra_width;
+  min_requisition->height += extra_height;
   
   priv->button_maxw = max_homogeneous_child_width;
   priv->button_maxh = max_homogeneous_child_height;
@@ -1041,11 +1038,14 @@ gtk_toolbar_get_preferred_width (GtkWidget *widget,
                                  gint      *minimum,
                                  gint      *natural)
 {
-  GtkRequisition requisition;
+  GtkRequisition min_requisition, nat_requisition;
 
-  gtk_toolbar_size_request (widget, &requisition);
+  gtk_toolbar_size_request (widget, &min_requisition, &nat_requisition);
 
-  *minimum = *natural = requisition.width;
+  if (minimum)
+    *minimum = min_requisition.width;
+  if (natural)
+    *natural = nat_requisition.width;
 }
 
 static void
@@ -1053,11 +1053,14 @@ gtk_toolbar_get_preferred_height (GtkWidget *widget,
                                   gint      *minimum,
                                   gint      *natural)
 {
-  GtkRequisition requisition;
+  GtkRequisition min_requisition, nat_requisition;
 
-  gtk_toolbar_size_request (widget, &requisition);
+  gtk_toolbar_size_request (widget, &min_requisition, &nat_requisition);
 
-  *minimum = *natural = requisition.height;
+  if (minimum)
+    *minimum = min_requisition.height;
+  if (natural)
+    *natural = nat_requisition.height;
 }
 
 static gint


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]