[gdl] bgo#633499 - prepare for the demise of size_request



commit 051ab74c4e6f24fae1c5185405cc4e5d755fefe0
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Nov 2 12:18:11 2010 +0100

    bgo#633499 - prepare for the demise of size_request

 gdl/gdl-dock-bar.c               |   33 ++++++++++-
 gdl/gdl-dock-item-button-image.c |   25 +++++---
 gdl/gdl-dock-item-grip.c         |  103 +++++++++++++++++++++-------------
 gdl/gdl-dock-item.c              |  114 ++++++++++++++++++++++++--------------
 gdl/gdl-dock-tablabel.c          |   65 ++++++++++++++++------
 gdl/gdl-dock.c                   |   62 ++++++++++++--------
 gdl/gdl-switcher.c               |   60 ++++++++++++++------
 7 files changed, 308 insertions(+), 154 deletions(-)
---
diff --git a/gdl/gdl-dock-bar.c b/gdl/gdl-dock-bar.c
index b6175bd..3798da7 100644
--- a/gdl/gdl-dock-bar.c
+++ b/gdl/gdl-dock-bar.c
@@ -71,8 +71,12 @@ struct _GdlDockBarPrivate {
 
 G_DEFINE_TYPE (GdlDockBar, gdl_dock_bar, GTK_TYPE_BOX)
 
-static void gdl_dock_bar_size_request (GtkWidget *widget,
-		                       GtkRequisition *requisition );
+static void gdl_dock_bar_get_preferred_width  (GtkWidget *widget,
+                                               gint      *minimum,
+                                               gint      *natural);
+static void gdl_dock_bar_get_preferred_height (GtkWidget *widget,
+                                               gint      *minimum,
+                                               gint      *natural);
 static void gdl_dock_bar_size_allocate (GtkWidget *widget,
 		                       GtkAllocation *allocation );
 static void gdl_dock_bar_size_vrequest (GtkWidget *widget,
@@ -115,7 +119,8 @@ gdl_dock_bar_class_init (GdlDockBarClass *klass)
                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
     widget_class = GTK_WIDGET_CLASS (klass);
-    widget_class->size_request = gdl_dock_bar_size_request;
+    widget_class->get_preferred_width = gdl_dock_bar_get_preferred_width;
+    widget_class->get_preferred_height = gdl_dock_bar_get_preferred_height;
     widget_class->size_allocate = gdl_dock_bar_size_allocate;
 }
 
@@ -433,6 +438,28 @@ static void gdl_dock_bar_size_request (GtkWidget *widget,
     }
 }
 
+static void gdl_dock_bar_get_preferred_width (GtkWidget *widget,
+                                              gint      *minimum,
+                                              gint      *natural)
+{
+    GtkRequisition requisition;
+
+    gdl_dock_bar_size_request (widget, &requisition);
+
+   *minimum = *natural = requisition.width;
+}
+
+static void gdl_dock_bar_get_preferred_height (GtkWidget *widget,
+                                               gint      *minimum,
+                                               gint      *natural)
+{
+    GtkRequisition requisition;
+
+    gdl_dock_bar_size_request (widget, &requisition);
+
+   *minimum = *natural = requisition.height;
+}
+
 static void gdl_dock_bar_size_allocate (GtkWidget *widget,
 		                       GtkAllocation *allocation )
 {
diff --git a/gdl/gdl-dock-item-button-image.c b/gdl/gdl-dock-item-button-image.c
index c4915ad..2468161 100644
--- a/gdl/gdl-dock-item-button-image.c
+++ b/gdl/gdl-dock-item-button-image.c
@@ -115,14 +115,19 @@ gdl_dock_item_button_image_init (
 }
 
 static void
-gdl_dock_item_button_image_size_request (GtkWidget      *widget,
-                                         GtkRequisition *requisition)
+gdl_dock_item_button_image_get_preferred_width (GtkWidget *widget,
+                                                gint      *minimum,
+                                                gint      *natural)
 {
-    g_return_if_fail (GDL_IS_DOCK_ITEM_BUTTON_IMAGE (widget));
-    g_return_if_fail (requisition != NULL);
-    
-    requisition->width = ICON_SIZE;
-    requisition->height = ICON_SIZE;
+   *minimum = *natural = ICON_SIZE;
+}
+
+static void
+gdl_dock_item_button_image_get_preferred_height (GtkWidget *widget,
+                                                 gint      *minimum,
+                                                 gint      *natural)
+{
+   *minimum = *natural = ICON_SIZE;
 }
 
 static void
@@ -134,8 +139,10 @@ gdl_dock_item_button_image_class_init (
     
     widget_class->draw =
         gdl_dock_item_button_image_draw;
-    widget_class->size_request =
-        gdl_dock_item_button_image_size_request;
+    widget_class->get_preferred_width =
+        gdl_dock_item_button_image_get_preferred_width;
+    widget_class->get_preferred_height =
+        gdl_dock_item_button_image_get_preferred_height;
 }
 
 /* ----- Public interface ----- */
diff --git a/gdl/gdl-dock-item-grip.c b/gdl/gdl-dock-item-grip.c
index 9e26b38..c3adec2 100644
--- a/gdl/gdl-dock-item-grip.c
+++ b/gdl/gdl-dock-item-grip.c
@@ -461,43 +461,67 @@ gdl_dock_item_grip_unmap (GtkWidget *widget)
 }
 
 static void
-gdl_dock_item_grip_size_request (GtkWidget      *widget,
-                                 GtkRequisition *requisition)
+gdl_dock_item_grip_get_preferred_width (GtkWidget *widget,
+                                        gint      *minimum,
+                                        gint      *natural)
 {
-    GtkRequisition   child_requisition;
     GdlDockItemGrip *grip;
-    gint             layout_height = 0;
-    guint            border_width;
+    gint child_min, child_nat;
 
     g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (widget));
-    g_return_if_fail (requisition != NULL);
 
-    border_width  = gtk_container_get_border_width (GTK_CONTAINER (widget));
     grip = GDL_DOCK_ITEM_GRIP (widget);
-    
-    requisition->width = border_width * 2/* + ALIGN_BORDER*/;
-    requisition->height = border_width * 2;
 
-    if(grip->_priv->handle_shown)
-        requisition->width += DRAG_HANDLE_SIZE;
+    *minimum = *natural = 0;
+
+    if(grip->_priv->handle_shown) {
+        *minimum += DRAG_HANDLE_SIZE;
+        *natural += DRAG_HANDLE_SIZE;
+    }
 
-    gtk_widget_size_request (grip->_priv->close_button, &child_requisition);
-    layout_height = MAX (layout_height, child_requisition.height);
     if (gtk_widget_get_visible (grip->_priv->close_button)) {
-       requisition->width += child_requisition.width;
+       gtk_widget_get_preferred_width (grip->_priv->close_button, &child_min, &child_nat);
+       *minimum += child_min;
+       *natural += child_nat;
     }
-    
-    gtk_widget_size_request (grip->_priv->iconify_button, &child_requisition);
-    layout_height = MAX (layout_height, child_requisition.height);
+
     if (gtk_widget_get_visible (grip->_priv->iconify_button)) {
-        requisition->width += child_requisition.width;
+        gtk_widget_get_preferred_width (grip->_priv->iconify_button, &child_min, &child_nat);
+       *minimum += child_min;
+       *natural += child_nat;
     }
-   
-    gtk_widget_size_request (grip->_priv->label, &child_requisition);
-    requisition->width += child_requisition.width;
-    layout_height = MAX (layout_height, child_requisition.height);
-    
-    requisition->height += layout_height;
+
+    gtk_widget_get_preferred_width (grip->_priv->label, &child_min, &child_nat);
+    *minimum += child_min;
+    *natural += child_nat;
+}
+
+static void
+gdl_dock_item_grip_get_preferred_height (GtkWidget *widget,
+                                         gint      *minimum,
+                                         gint      *natural)
+{
+    GdlDockItemGrip *grip;
+    gint child_min, child_nat;
+    gint layout_height = 0;
+
+    g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (widget));
+
+    grip = GDL_DOCK_ITEM_GRIP (widget);
+
+    *minimum = *natural = 0;
+
+    gtk_widget_get_preferred_height (grip->_priv->close_button, &child_min, &child_nat);
+    *minimum = MAX (*minimum, child_min);
+    *natural = MAX (*natural, child_nat);
+
+    gtk_widget_get_preferred_height (grip->_priv->iconify_button, &child_min, &child_nat);
+    *minimum = MAX (*minimum, child_min);
+    *natural = MAX (*natural, child_nat);
+
+    gtk_widget_get_preferred_height (grip->_priv->label, &child_min, &child_nat);
+    *minimum = MAX (*minimum, child_min);
+    *natural = MAX (*natural, child_nat);
 }
 
 static void
@@ -509,34 +533,31 @@ gdl_dock_item_grip_size_allocate (GtkWidget     *widget,
     GtkRequisition   iconify_requisition = { 0, };
     GtkAllocation    child_allocation;
     GdkRectangle     label_area;
-    guint            border_width;
 
     g_return_if_fail (GDL_IS_DOCK_ITEM_GRIP (widget));
     g_return_if_fail (allocation != NULL);
   
     grip = GDL_DOCK_ITEM_GRIP (widget);
-    border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
 
     GTK_WIDGET_CLASS (gdl_dock_item_grip_parent_class)->size_allocate (widget, allocation);
 
-    gtk_widget_size_request (grip->_priv->close_button,
-        &close_requisition);
-    gtk_widget_size_request (grip->_priv->iconify_button,
-        &iconify_requisition);
+    gtk_widget_get_preferred_size (grip->_priv->close_button,
+        &close_requisition, NULL);
+    gtk_widget_get_preferred_size (grip->_priv->iconify_button,
+        &iconify_requisition, NULL);
     
     /* Calculate the Minimum Width where buttons will fit */
-    int min_width = close_requisition.width + iconify_requisition.width
-        + border_width * 2;
+    int min_width = close_requisition.width + iconify_requisition.width;
     if(grip->_priv->handle_shown)
       min_width += DRAG_HANDLE_SIZE;
     const gboolean space_for_buttons = (allocation->width >= min_width);
         
     /* Set up the rolling child_allocation rectangle */
     if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
-        child_allocation.x = border_width/* + ALIGN_BORDER*/;
+        child_allocation.x = 0;
     else
-        child_allocation.x = allocation->width - border_width;
-    child_allocation.y = border_width;
+        child_allocation.x = allocation->width;
+    child_allocation.y = 0;
 
     /* Layout Close Button */
     if (gtk_widget_get_visible (grip->_priv->close_button)) {
@@ -579,7 +600,7 @@ gdl_dock_item_grip_size_allocate (GtkWidget     *widget,
     /* Layout the Grip Handle*/
     if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL) {
         child_allocation.width = child_allocation.x;
-        child_allocation.x = border_width/* + ALIGN_BORDER*/;
+        child_allocation.x = 0;
         
         if(grip->_priv->handle_shown) {
             child_allocation.x += DRAG_HANDLE_SIZE;
@@ -597,8 +618,8 @@ gdl_dock_item_grip_size_allocate (GtkWidget     *widget,
     if(child_allocation.width < 0)
       child_allocation.width = 0;
     
-    child_allocation.y = border_width;
-    child_allocation.height = allocation->height - border_width * 2;
+    child_allocation.y = 0;
+    child_allocation.height = allocation->height;
     if(grip->_priv->label) {
       gtk_widget_size_allocate (grip->_priv->label, &child_allocation);
     }
@@ -675,13 +696,15 @@ gdl_dock_item_grip_class_init (GdlDockItemGripClass *klass)
     widget_class->unrealize = gdl_dock_item_grip_unrealize;
     widget_class->map = gdl_dock_item_grip_map;
     widget_class->unmap = gdl_dock_item_grip_unmap;
-    widget_class->size_request = gdl_dock_item_grip_size_request;
+    widget_class->get_preferred_width = gdl_dock_item_grip_get_preferred_width;
+    widget_class->get_preferred_height = gdl_dock_item_grip_get_preferred_height;
     widget_class->size_allocate = gdl_dock_item_grip_size_allocate;
 
     container_class->add = gdl_dock_item_grip_add;
     container_class->remove = gdl_dock_item_grip_remove;
     container_class->forall = gdl_dock_item_grip_forall;
     container_class->child_type = gdl_dock_item_grip_child_type;
+    gtk_container_class_handle_border_width (container_class);
 
     g_object_class_install_property (
         gobject_class, PROP_ITEM,
diff --git a/gdl/gdl-dock-item.c b/gdl/gdl-dock-item.c
index b8c5ffa..0975e66 100644
--- a/gdl/gdl-dock-item.c
+++ b/gdl/gdl-dock-item.c
@@ -79,8 +79,13 @@ static void  gdl_dock_item_forall        (GtkContainer *container,
                                           gpointer      callback_data);
 static GType gdl_dock_item_child_type  (GtkContainer *container);
 
-static void  gdl_dock_item_size_request  (GtkWidget *widget,
-                                          GtkRequisition *requisition);
+static void  gdl_dock_item_get_preferred_width  (GtkWidget *widget,
+                                                 gint      *minimum,
+                                                 gint      *natural);
+static void  gdl_dock_item_get_preferred_height (GtkWidget *widget,
+                                                 gint      *minimum,
+                                                 gint      *natural);
+
 static void  gdl_dock_item_size_allocate (GtkWidget *widget,
                                           GtkAllocation *allocation);
 static void  gdl_dock_item_map           (GtkWidget *widget);
@@ -215,7 +220,8 @@ gdl_dock_item_class_init (GdlDockItemClass *klass)
     widget_class->realize = gdl_dock_item_realize;
     widget_class->map = gdl_dock_item_map;
     widget_class->unmap = gdl_dock_item_unmap;
-    widget_class->size_request = gdl_dock_item_size_request;
+    widget_class->get_preferred_width = gdl_dock_item_get_preferred_width;
+    widget_class->get_preferred_height = gdl_dock_item_get_preferred_height;
     widget_class->size_allocate = gdl_dock_item_size_allocate;
     widget_class->style_set = gdl_dock_item_style_set;
     widget_class->button_press_event = gdl_dock_item_button_changed;
@@ -227,6 +233,7 @@ gdl_dock_item_class_init (GdlDockItemClass *klass)
     container_class->remove = gdl_dock_item_remove;
     container_class->forall = gdl_dock_item_forall;
     container_class->child_type = gdl_dock_item_child_type;
+    gtk_container_class_handle_border_width (container_class);
     
     object_class->is_compound = FALSE;
 
@@ -719,64 +726,91 @@ gdl_dock_item_child_type (GtkContainer *container)
 }
 
 static void
-gdl_dock_item_size_request (GtkWidget      *widget,
-                            GtkRequisition *requisition)
+gdl_dock_item_get_preferred_width (GtkWidget *widget,
+                                   gint      *minimum,
+                                   gint      *natural)
 {
     GdlDockItem    *item;
-    GtkRequisition  child_requisition;
-    GtkRequisition  grip_requisition;
+    gint child_min, child_nat;
     GtkStyle       *style;
-    guint           border_width;
 
     g_return_if_fail (GDL_IS_DOCK_ITEM (widget));
-    g_return_if_fail (requisition != NULL);
 
     item = GDL_DOCK_ITEM (widget);
 
     /* If our child is not visible, we still request its size, since
        we won't have any useful hint for our size otherwise.  */
     if (item->child)
-        gtk_widget_size_request (item->child, &child_requisition);
-    else {
-        child_requisition.width = 0;
-        child_requisition.height = 0;
-    }
+        gtk_widget_get_preferred_width (item->child, &child_min, &child_nat);
+    else
+        child_min = child_nat = 0;
 
     if (item->orientation == GTK_ORIENTATION_HORIZONTAL) {
         if (GDL_DOCK_ITEM_GRIP_SHOWN (item)) {
-            gtk_widget_size_request (item->_priv->grip, &grip_requisition);
-            requisition->width = grip_requisition.width;
-        } else {
-            requisition->width = 0;
+            gtk_widget_get_preferred_width (item->_priv->grip, minimum, natural);
+        } else
+            *minimum = *natural = 0;
+
+        if (item->child) {
+            *minimum += child_min;
+            *natural += child_nat;
         }
+    } else {
+        if (item->child) {
+            *minimum = child_min;
+            *natural = child_nat;
+        } else
+            *minimum = *natural = 0;
+    }
+
+    style = gtk_widget_get_style (widget);
+
+    *minimum += style->xthickness * 2;
+    *natural += style->xthickness * 2;
+}
+
+static void
+gdl_dock_item_get_preferred_height (GtkWidget *widget,
+                                    gint      *minimum,
+                                    gint      *natural)
+{
+    GdlDockItem    *item;
+    gint child_min, child_nat;
+    GtkStyle       *style;
+
+    g_return_if_fail (GDL_IS_DOCK_ITEM (widget));
+
+    item = GDL_DOCK_ITEM (widget);
+
+    /* If our child is not visible, we still request its size, since
+       we won't have any useful hint for our size otherwise.  */
+    if (item->child)
+        gtk_widget_get_preferred_height (item->child, &child_min, &child_nat);
+    else
+        child_min = child_nat = 0;
 
+    if (item->orientation == GTK_ORIENTATION_HORIZONTAL) {
         if (item->child) {
-            requisition->width += child_requisition.width;
-            requisition->height = child_requisition.height;
+            *minimum = child_min;
+            *natural = child_nat;
         } else
-            requisition->height = 0;
+            *minimum = *natural = 0;
     } else {
         if (GDL_DOCK_ITEM_GRIP_SHOWN (item)) {
-            gtk_widget_size_request (item->_priv->grip, &grip_requisition);
-            requisition->height = grip_requisition.height;
-        } else {
-            requisition->height = 0;
-        }
+            gtk_widget_get_preferred_height (item->_priv->grip, minimum, natural);
+        } else
+            *minimum = *natural = 0;
 
         if (item->child) {
-            requisition->width = child_requisition.width;
-            requisition->height += child_requisition.height;
-        } else
-            requisition->width = 0;
+            *minimum += child_min;
+            *natural += child_nat;
+        }
     }
 
-    border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
     style = gtk_widget_get_style (widget);
 
-    requisition->width += (border_width + style->xthickness) * 2;
-    requisition->height += (border_width + style->ythickness) * 2;
-
-    //gtk_widget_size_request (widget, requisition);    
+    *minimum += style->ythickness * 2;
+    *natural += style->ythickness * 2;
 }
 
 static void
@@ -806,17 +840,15 @@ gdl_dock_item_size_allocate (GtkWidget     *widget,
     if (item->child && gtk_widget_get_visible (item->child)) {
         GtkAllocation  child_allocation;
         GtkStyle      *style;
-        guint          border_width;
 
-        border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
         style = gtk_widget_get_style (widget);
 
-        child_allocation.x = border_width + style->xthickness;
-        child_allocation.y = border_width + style->ythickness;
+        child_allocation.x = style->xthickness;
+        child_allocation.y = style->ythickness;
         child_allocation.width = allocation->width
-            - 2 * (border_width + style->xthickness);
+            - 2 * style->xthickness;
         child_allocation.height = allocation->height
-            - 2 * (border_width + style->ythickness);
+            - 2 * style->ythickness;
         
         if (GDL_DOCK_ITEM_GRIP_SHOWN (item)) {
             GtkAllocation grip_alloc = child_allocation;
diff --git a/gdl/gdl-dock-tablabel.c b/gdl/gdl-dock-tablabel.c
index 52bc38d..abdf19f 100644
--- a/gdl/gdl-dock-tablabel.c
+++ b/gdl/gdl-dock-tablabel.c
@@ -50,8 +50,12 @@ static void  gdl_dock_tablabel_item_notify   (GObject            *master,
                                               GParamSpec         *pspec,
                                               gpointer            data);
 
-static void  gdl_dock_tablabel_size_request  (GtkWidget          *widget,
-                                              GtkRequisition     *requisition);
+static void  gdl_dock_tablabel_get_preferred_width  (GtkWidget *widget,
+                                                     gint      *minimum,
+                                                     gint      *natural);
+static void  gdl_dock_tablabel_get_preferred_height (GtkWidget *widget,
+                                                     gint      *minimum,
+                                                     gint      *natural);
 static void  gdl_dock_tablabel_size_allocate (GtkWidget          *widget,
                                               GtkAllocation      *allocation);
                                               
@@ -107,7 +111,8 @@ gdl_dock_tablabel_class_init (GdlDockTablabelClass *klass)
     g_object_class->set_property = gdl_dock_tablabel_set_property;
     g_object_class->get_property = gdl_dock_tablabel_get_property;
 
-    widget_class->size_request = gdl_dock_tablabel_size_request;
+    widget_class->get_preferred_width = gdl_dock_tablabel_get_preferred_width;
+    widget_class->get_preferred_height = gdl_dock_tablabel_get_preferred_height;
     widget_class->size_allocate = gdl_dock_tablabel_size_allocate;
     widget_class->draw = gdl_dock_tablabel_draw;
     widget_class->button_press_event = gdl_dock_tablabel_button_event;
@@ -269,38 +274,62 @@ gdl_dock_tablabel_item_notify (GObject    *master,
 }
 
 static void
-gdl_dock_tablabel_size_request (GtkWidget      *widget,
-                                GtkRequisition *requisition)
+gdl_dock_tablabel_get_preferred_width (GtkWidget *widget,
+                                       gint      *minimum,
+                                       gint      *natural)
 {
     GtkBin          *bin;
-    GtkRequisition   child_req;
+    gint child_min, child_nat;
     GdlDockTablabel *tablabel;
     guint            border_width;
 
     g_return_if_fail (widget != NULL);
     g_return_if_fail (GDL_IS_DOCK_TABLABEL (widget));
-    g_return_if_fail (requisition != NULL);
 
     tablabel = GDL_DOCK_TABLABEL (widget);
     bin = GTK_BIN (widget);
 
-    requisition->width = tablabel->drag_handle_size;
-    requisition->height = 0;
+    *minimum = *natural = tablabel->drag_handle_size;
 
     if (gtk_bin_get_child (bin))
-        gtk_widget_size_request (gtk_bin_get_child (bin), &child_req);
+        gtk_widget_get_preferred_width (gtk_bin_get_child (bin), &child_min, &child_nat);
     else
-        child_req.width = child_req.height = 0;
-        
-    requisition->width += child_req.width;
-    requisition->height += child_req.height;
+        child_min = child_nat = 0;
 
-    border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+    *minimum += child_min + border_width * 2;
+    *natural += child_nat + border_width * 2;
+}
 
-    requisition->width += border_width * 2;
-    requisition->height += border_width * 2;
+static void
+gdl_dock_tablabel_get_preferred_height (GtkWidget *widget,
+                                        gint      *minimum,
+                                        gint      *natural)
+{
+    GtkBin          *bin;
+    gint child_min, child_nat;
+    GdlDockTablabel *tablabel;
+    guint            border_width;
+
+    g_return_if_fail (widget != NULL);
+    g_return_if_fail (GDL_IS_DOCK_TABLABEL (widget));
+
+    tablabel = GDL_DOCK_TABLABEL (widget);
+    bin = GTK_BIN (widget);
+
+    *minimum = *natural = 0;
+
+    if (gtk_bin_get_child (bin))
+        gtk_widget_get_preferred_height (gtk_bin_get_child (bin), &child_min, &child_nat);
+    else
+        child_min = child_nat = 0;
+
+    *minimum = child_min;
+    *natural = child_nat;
+
+    border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
 
-    //gtk_widget_size_request (widget, requisition);    
+    *minimum += border_width * 2;
+    *natural += border_width * 2;
 }
 
 static void
diff --git a/gdl/gdl-dock.c b/gdl/gdl-dock.c
index ba20cce..d4003b0 100644
--- a/gdl/gdl-dock.c
+++ b/gdl/gdl-dock.c
@@ -64,8 +64,13 @@ static void  gdl_dock_set_title       (GdlDock      *dock);
 
 static void  gdl_dock_destroy         (GtkWidget    *object);
 
-static void  gdl_dock_size_request    (GtkWidget      *widget,
-                                       GtkRequisition *requisition);
+static void  gdl_dock_get_preferred_width  (GtkWidget *widget,
+                                            gint      *minimum,
+                                            gint      *natural);
+static void  gdl_dock_get_preferred_height (GtkWidget *widget,
+                                            gint      *minimum,
+                                            gint      *natural);
+
 static void  gdl_dock_size_allocate   (GtkWidget      *widget,
                                        GtkAllocation  *allocation);
 static void  gdl_dock_map             (GtkWidget      *widget);
@@ -218,7 +223,8 @@ gdl_dock_class_init (GdlDockClass *klass)
     
     widget_class->destroy = gdl_dock_destroy;
 
-    widget_class->size_request = gdl_dock_size_request;
+    widget_class->get_preferred_width = gdl_dock_get_preferred_width;
+    widget_class->get_preferred_height = gdl_dock_get_preferred_height;
     widget_class->size_allocate = gdl_dock_size_allocate;
     widget_class->map = gdl_dock_map;
     widget_class->unmap = gdl_dock_unmap;
@@ -229,7 +235,8 @@ gdl_dock_class_init (GdlDockClass *klass)
     container_class->remove = gdl_dock_remove;
     container_class->forall = gdl_dock_forall;
     container_class->child_type = gdl_dock_child_type;
-    
+    gtk_container_class_handle_border_width (container_class);
+
     object_class->is_compound = TRUE;
     
     object_class->detach = gdl_dock_detach;
@@ -527,32 +534,45 @@ gdl_dock_destroy (GtkWidget *object)
 }
 
 static void
-gdl_dock_size_request (GtkWidget      *widget,
-                       GtkRequisition *requisition)
+gdl_dock_get_preferred_width (GtkWidget *widget,
+                              gint      *minimum,
+                              gint      *natural)
 {
     GdlDock       *dock;
     GtkContainer  *container;
-    guint          border_width;
 
     g_return_if_fail (widget != NULL);
     g_return_if_fail (GDL_IS_DOCK (widget));
 
     dock = GDL_DOCK (widget);
     container = GTK_CONTAINER (widget);
-    border_width = gtk_container_get_border_width (container);
 
     /* make request to root */
     if (dock->root && gtk_widget_get_visible (GTK_WIDGET (dock->root)))
-        gtk_widget_size_request (GTK_WIDGET (dock->root), requisition);
-    else {
-        requisition->width = 0;
-        requisition->height = 0;
-    };
+        gtk_widget_get_preferred_width (GTK_WIDGET (dock->root), minimum, natural);
+    else
+        *minimum = *natural = 0;
+}
+
+static void
+gdl_dock_get_preferred_height (GtkWidget *widget,
+                               gint      *minimum,
+                               gint      *natural)
+{
+    GdlDock       *dock;
+    GtkContainer  *container;
 
-    requisition->width += 2 * border_width;
-    requisition->height += 2 * border_width;
+    g_return_if_fail (widget != NULL);
+    g_return_if_fail (GDL_IS_DOCK (widget));
+
+    dock = GDL_DOCK (widget);
+    container = GTK_CONTAINER (widget);
 
-    //gtk_widget_size_request (widget, requisition);    
+    /* make request to root */
+    if (dock->root && gtk_widget_get_visible (GTK_WIDGET (dock->root)))
+        gtk_widget_get_preferred_height (GTK_WIDGET (dock->root), minimum, natural);
+    else
+        *minimum = *natural = 0;
 }
 
 static void
@@ -561,23 +581,15 @@ gdl_dock_size_allocate (GtkWidget     *widget,
 {
     GdlDock       *dock;
     GtkContainer  *container;
-    guint          border_width;
 
     g_return_if_fail (widget != NULL);
     g_return_if_fail (GDL_IS_DOCK (widget));
-    
+
     dock = GDL_DOCK (widget);
     container = GTK_CONTAINER (widget);
-    border_width = gtk_container_get_border_width (container);
 
     gtk_widget_set_allocation (widget, allocation);
 
-    /* reduce allocation by border width */
-    allocation->x += border_width;
-    allocation->y += border_width;
-    allocation->width = MAX (1, allocation->width - 2 * border_width);
-    allocation->height = MAX (1, allocation->height - 2 * border_width);
-
     if (dock->root && gtk_widget_get_visible (GTK_WIDGET (dock->root)))
         gtk_widget_size_allocate (GTK_WIDGET (dock->root), allocation);
 }
diff --git a/gdl/gdl-switcher.c b/gdl/gdl-switcher.c
index 7977818..1377e5f 100644
--- a/gdl/gdl-switcher.c
+++ b/gdl/gdl-switcher.c
@@ -254,7 +254,7 @@ button_toggled_callback (GtkToggleButton *toggle_button,
 static int
 layout_buttons (GdlSwitcher *switcher, GtkAllocation* allocation)
 {
-    GtkRequisition client_requisition = {0,};
+    gint min_height, nat_height;
     GdlSwitcherStyle switcher_style;
     gboolean icons_only;
     int num_btns = g_slist_length (switcher->priv->buttons);
@@ -272,7 +272,7 @@ layout_buttons (GdlSwitcher *switcher, GtkAllocation* allocation)
     
     last_buttons_height = switcher->priv->buttons_height_request;
     
-    GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_request (GTK_WIDGET (switcher), &client_requisition);
+    GTK_WIDGET_CLASS (gdl_switcher_parent_class)->get_preferred_height (GTK_WIDGET (switcher), &min_height, &nat_height);
 
     y = allocation->y + allocation->height - V_PADDING - 1;
 
@@ -288,8 +288,8 @@ layout_buttons (GdlSwitcher *switcher, GtkAllocation* allocation)
         GtkRequisition requisition;
 
         button = p->data;
-        gtk_widget_size_request (GTK_WIDGET (button->button_widget),
-                                 &requisition);
+        gtk_widget_get_preferred_size (GTK_WIDGET (button->button_widget),
+                                       &requisition, NULL);
         optimal_layout_width += requisition.width + H_PADDING;
         max_btn_height = MAX (max_btn_height, requisition.height);
         max_btn_width = MAX (max_btn_width, requisition.width);    
@@ -376,7 +376,7 @@ layout_buttons (GdlSwitcher *switcher, GtkAllocation* allocation)
         /* Check for possible size over flow (taking into account client
          * requisition
          */
-        if (y < (allocation->y + client_requisition.height)) {
+        if (y < (allocation->y + min_height)) {
             /* We have an overflow: Insufficient allocation */
             if (last_buttons_height < switcher->priv->buttons_height_request) {
                 /* Request for a new resize */
@@ -400,8 +400,8 @@ layout_buttons (GdlSwitcher *switcher, GtkAllocation* allocation)
             if (rows_count == 1 && row_number == 0)
             {
                 GtkRequisition child_requisition;
-                gtk_widget_size_request (GTK_WIDGET (p->data),
-                                         &child_requisition);
+                gtk_widget_get_preferred_size (GTK_WIDGET (p->data),
+                                               &child_requisition, NULL);
                 child_allocation.width = child_requisition.width;
             }
             else
@@ -497,13 +497,13 @@ gdl_switcher_remove (GtkContainer *container, GtkWidget *widget)
 /* GtkWidget methods.  */
 
 static void
-gdl_switcher_size_request (GtkWidget *widget, GtkRequisition *requisition)
+gdl_switcher_get_preferred_width (GtkWidget *widget, gint *minimum, gint *natural)
 {
     GdlSwitcher *switcher = GDL_SWITCHER (widget);
     GSList *p;
     gint button_height = 0;
     
-    GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_request (GTK_WIDGET (switcher), requisition);
+    GTK_WIDGET_CLASS (gdl_switcher_parent_class)->get_preferred_width (GTK_WIDGET (switcher), minimum, natural);
 
     if (!switcher->priv->show)
         return;
@@ -511,19 +511,42 @@ gdl_switcher_size_request (GtkWidget *widget, GtkRequisition *requisition)
     for (p = switcher->priv->buttons; p != NULL; p = p->next) {
         gint button_width;
         Button *button = p->data;
-        GtkRequisition button_requisition;
+        gint min, nat;
 
-        gtk_widget_size_request (button->button_widget, &button_requisition);
-        button_width = button_requisition.width + 2 * H_PADDING;
-        requisition->width = MAX (requisition->width, button_width);
-        button_height = MAX (button_height,
-                             button_requisition.height + 2 * V_PADDING);
+        gtk_widget_get_preferred_width(button->button_widget, &min, &nat);
+        *minimum = MAX (*minimum, min + 2 * H_PADDING);
+        *natural = MAX (*natural, nat + 2 * H_PADDING);
     }
+}
+
+static void
+gdl_switcher_get_preferred_height (GtkWidget *widget, gint *minimum, gint *natural)
+{
+    GdlSwitcher *switcher = GDL_SWITCHER (widget);
+    GSList *p;
+    gint button_min = 0;
+    gint button_nat = 0;
+ 
+    GTK_WIDGET_CLASS (gdl_switcher_parent_class)->get_preferred_height (GTK_WIDGET (switcher), minimum, natural);
+
+    if (!switcher->priv->show)
+        return;
     
+    for (p = switcher->priv->buttons; p != NULL; p = p->next) {
+        Button *button = p->data;
+        gint min, nat;
+
+        gtk_widget_get_preferred_height (button->button_widget, &min, &nat);
+        button_min = MAX (button_min, min + 2 * V_PADDING);
+        button_nat = MAX (button_nat, nat + 2 * V_PADDING);
+    }
+
     if (switcher->priv->buttons_height_request > 0) {
-        requisition->height += switcher->priv->buttons_height_request;
+        *minimum += switcher->priv->buttons_height_request;
+        *natural += switcher->priv->buttons_height_request;
     } else {
-        requisition->height += button_height + V_PADDING;
+        *minimum += button_min + V_PADDING;
+        *natural += button_nat + V_PADDING;
     }
 }
 
@@ -707,7 +730,8 @@ gdl_switcher_class_init (GdlSwitcherClass *klass)
     container_class->forall = gdl_switcher_forall;
     container_class->remove = gdl_switcher_remove;
 
-    widget_class->size_request = gdl_switcher_size_request;
+    widget_class->get_preferred_width = gdl_switcher_get_preferred_width;
+    widget_class->get_preferred_height = gdl_switcher_get_preferred_height;
     widget_class->size_allocate = gdl_switcher_size_allocate;
     widget_class->draw = gdl_switcher_draw;
     widget_class->map = gdl_switcher_map;



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