[maemo-commits] [maemo-commits] r13933 - in projects/haf/trunk/gtk+: . gtk

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Thu Sep 20 14:51:00 EEST 2007
Author: tko
Date: 2007-09-20 14:50:58 +0300 (Thu, 20 Sep 2007)
New Revision: 13933

Modified:
   projects/haf/trunk/gtk+/ChangeLog
   projects/haf/trunk/gtk+/gtk/gtkhbbox.c
Log:
Refactor size requisition wit gtk_hbutton_box_get_children_sizes

2007-09-20  Tommi Komulainen  <tommi.komulainen at nokia.com>

	* gtk/gtkhbbox.c (gtk_hbutton_box_get_children_sizes,
	gtk_hbutton_box_size_allocate): Call get_children_sizes with optional
	allocation parameter so that we can use it for size requisition as
	well.
	* gtk/gtkhbbox.c (gtk_hbutton_box_size_request): Rewrite to use
	gtk_hbutton_box_get_children_sizes


Modified: projects/haf/trunk/gtk+/ChangeLog
===================================================================
--- projects/haf/trunk/gtk+/ChangeLog	2007-09-20 11:13:28 UTC (rev 13932)
+++ projects/haf/trunk/gtk+/ChangeLog	2007-09-20 11:50:58 UTC (rev 13933)
@@ -1,5 +1,14 @@
 2007-09-20  Tommi Komulainen  <tommi.komulainen at nokia.com>
 
+	* gtk/gtkhbbox.c (gtk_hbutton_box_get_children_sizes,
+	gtk_hbutton_box_size_allocate): Call get_children_sizes with optional
+	allocation parameter so that we can use it for size requisition as
+	well.
+	* gtk/gtkhbbox.c (gtk_hbutton_box_size_request): Rewrite to use
+	gtk_hbutton_box_get_children_sizes
+
+2007-09-20  Tommi Komulainen  <tommi.komulainen at nokia.com>
+
 	* gtk/gtkhbbox.c (gtk_hbutton_box_size_allocate): Replace somewhat
 	obscure defines with real variables.
 

Modified: projects/haf/trunk/gtk+/gtk/gtkhbbox.c
===================================================================
--- projects/haf/trunk/gtk+/gtk/gtkhbbox.c	2007-09-20 11:13:28 UTC (rev 13932)
+++ projects/haf/trunk/gtk+/gtk/gtkhbbox.c	2007-09-20 11:50:58 UTC (rev 13933)
@@ -105,65 +105,6 @@
   return default_layout_style;
 }
 
-
-  
-static void
-gtk_hbutton_box_size_request (GtkWidget      *widget,
-			      GtkRequisition *requisition)
-{
-  GtkBox *box;
-  GtkButtonBox *bbox;
-  gint nvis_children;
-  gint child_width;
-  gint child_height;
-  gint spacing;
-  GtkButtonBoxStyle layout;
-  
-  box = GTK_BOX (widget);
-  bbox = GTK_BUTTON_BOX (widget);
-
-  spacing = box->spacing;
-  layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
-	  ? bbox->layout_style : default_layout_style;
-  
-  _gtk_button_box_child_requisition (widget,
-                                     &nvis_children,
-				     NULL,
-                                     &child_width,
-                                     &child_height);
-
-  if (nvis_children == 0)
-  {
-    requisition->width = 0; 
-    requisition->height = 0;
-  }
-  else
-  {
-    switch (layout)
-    {
-    case GTK_BUTTONBOX_SPREAD:
-      requisition->width =
-	      nvis_children*child_width + ((nvis_children+1)*spacing);
-      break;
-    case GTK_BUTTONBOX_EDGE:
-    case GTK_BUTTONBOX_START:
-    case GTK_BUTTONBOX_END:
-    case GTK_BUTTONBOX_CENTER:
-      requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
-      break;
-    default:
-      g_assert_not_reached();
-      break;
-    }
-	  
-    requisition->height = child_height;
-  }
-	  
-  requisition->width += GTK_CONTAINER (box)->border_width * 2;
-  requisition->height += GTK_CONTAINER (box)->border_width * 2;
-}
-
-
 #if defined(MAEMO_CHANGES)
 /* This function is pretty much an abomination against reason.
    More or less it's supposed to:
@@ -182,13 +123,13 @@
 */
 static gint*
 gtk_hbutton_box_get_children_sizes (GtkWidget *widget,
+                                    GtkAllocation *allocation,
                                     gint *primary_width,
                                     gint *secondary_width,
                                     gint *child_height,
                                     gint *nvis_children,
                                     gint *n_secondaries)
 {
-  GtkAllocation *allocation = &widget->allocation;
   gint *children_widths;
   gint child_width;
   gint total_width;
@@ -211,7 +152,7 @@
   total_width = *nvis_children * child_width;
   total_spacing = (*nvis_children - 1) * GTK_BOX (widget)->spacing;
 
-  if (total_width + total_spacing > allocation->width)
+  if (allocation != NULL && total_width + total_spacing > allocation->width)
     {
       /* homogeneous allocation too wide to fit container, shrink the buttons
        * to their size requisition */
@@ -297,6 +238,67 @@
 }
 
 static void
+gtk_hbutton_box_size_request (GtkWidget      *widget,
+			      GtkRequisition *requisition)
+{
+  GtkBox *box;
+  GtkButtonBox *bbox;
+  gint primary_width;
+  gint secondary_width;
+  gint child_height;
+  gint nvis_children;
+  gint n_secondaries;
+  gint *children_widths;
+  gint spacing;
+  GtkButtonBoxStyle layout;
+
+  box = GTK_BOX (widget);
+  bbox = GTK_BUTTON_BOX (widget);
+
+  spacing = box->spacing;
+  layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
+         ? bbox->layout_style : default_layout_style;
+
+  children_widths = gtk_hbutton_box_get_children_sizes (widget,
+                                                        NULL,
+                                                        &primary_width,
+                                                        &secondary_width,
+                                                        &child_height,
+                                                        &nvis_children,
+                                                        &n_secondaries);
+  g_slice_free1 (sizeof (gint) * nvis_children, children_widths);
+
+  if (nvis_children == 0)
+    {
+      requisition->width = 0;
+      requisition->height = 0;
+    }
+  else
+    {
+      switch (layout)
+        {
+        case GTK_BUTTONBOX_SPREAD:
+          requisition->width = primary_width + secondary_width + ((nvis_children + 1) * spacing);
+          break;
+        case GTK_BUTTONBOX_EDGE:
+        case GTK_BUTTONBOX_START:
+        case GTK_BUTTONBOX_END:
+        case GTK_BUTTONBOX_CENTER:
+          requisition->width = primary_width + secondary_width + ((nvis_children - 1) * spacing);
+          break;
+        default:
+          g_assert_not_reached();
+          break;
+        }
+
+      requisition->height = child_height;
+    }
+
+  requisition->width += GTK_CONTAINER (box)->border_width * 2;
+  requisition->height += GTK_CONTAINER (box)->border_width * 2;
+}
+
+static void
 gtk_hbutton_box_size_allocate (GtkWidget     *widget,
 			       GtkAllocation *allocation)
 {
@@ -315,6 +317,7 @@
   widget->allocation = *allocation;
 
   children_widths = gtk_hbutton_box_get_children_sizes (widget,
+                                                        &widget->allocation,
 							&primary_width,
 							&secondary_width,
 							&child_height,
@@ -428,6 +431,62 @@
 
 #else
 static void
+gtk_hbutton_box_size_request (GtkWidget      *widget,
+			      GtkRequisition *requisition)
+{
+  GtkBox *box;
+  GtkButtonBox *bbox;
+  gint nvis_children;
+  gint child_width;
+  gint child_height;
+  gint spacing;
+  GtkButtonBoxStyle layout;
+  
+  box = GTK_BOX (widget);
+  bbox = GTK_BUTTON_BOX (widget);
+
+  spacing = box->spacing;
+  layout = bbox->layout_style != GTK_BUTTONBOX_DEFAULT_STYLE
+	  ? bbox->layout_style : default_layout_style;
+  
+  _gtk_button_box_child_requisition (widget,
+                                     &nvis_children,
+				     NULL,
+                                     &child_width,
+                                     &child_height);
+
+  if (nvis_children == 0)
+  {
+    requisition->width = 0; 
+    requisition->height = 0;
+  }
+  else
+  {
+    switch (layout)
+    {
+    case GTK_BUTTONBOX_SPREAD:
+      requisition->width =
+	      nvis_children*child_width + ((nvis_children+1)*spacing);
+      break;
+    case GTK_BUTTONBOX_EDGE:
+    case GTK_BUTTONBOX_START:
+    case GTK_BUTTONBOX_END:
+    case GTK_BUTTONBOX_CENTER:
+      requisition->width = nvis_children*child_width + ((nvis_children-1)*spacing);
+      break;
+    default:
+      g_assert_not_reached();
+      break;
+    }
+	  
+    requisition->height = child_height;
+  }
+	  
+  requisition->width += GTK_CONTAINER (box)->border_width * 2;
+  requisition->height += GTK_CONTAINER (box)->border_width * 2;
+}
+
+static void
 gtk_hbutton_box_size_allocate (GtkWidget     *widget,
 			       GtkAllocation *allocation)
 {


More information about the maemo-commits mailing list