[gdl] Fix drawing of switcher buttons in GdlSwitcher



commit 3111989948b814b0dc7b7f84645b923091ffab3b
Author: Johannes Schmid <jhs gnome org>
Date:   Wed Oct 27 15:13:28 2010 +0200

    Fix drawing of switcher buttons in GdlSwitcher

 gdl/gdl-switcher.c |   37 ++++++++++++++++---------------------
 1 files changed, 16 insertions(+), 21 deletions(-)
---
diff --git a/gdl/gdl-switcher.c b/gdl/gdl-switcher.c
index 046b9f3..7977818 100644
--- a/gdl/gdl-switcher.c
+++ b/gdl/gdl-switcher.c
@@ -252,10 +252,9 @@ button_toggled_callback (GtkToggleButton *toggle_button,
 
 /* Returns -1 if layout didn't happen because a resize request was queued */
 static int
-layout_buttons (GdlSwitcher *switcher)
+layout_buttons (GdlSwitcher *switcher, GtkAllocation* allocation)
 {
     GtkRequisition client_requisition = {0,};
-    GtkAllocation allocation;
     GdlSwitcherStyle switcher_style;
     gboolean icons_only;
     int num_btns = g_slist_length (switcher->priv->buttons);
@@ -270,14 +269,12 @@ layout_buttons (GdlSwitcher *switcher)
     int i;
     int rows_count;
     int last_buttons_height;
-
-    gtk_widget_get_allocation (GTK_WIDGET (switcher), &allocation);
     
     last_buttons_height = switcher->priv->buttons_height_request;
     
     GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_request (GTK_WIDGET (switcher), &client_requisition);
 
-    y = allocation.y + allocation.height - V_PADDING - 1;
+    y = allocation->y + allocation->height - V_PADDING - 1;
 
     if (num_btns == 0)
         return y;
@@ -299,10 +296,10 @@ layout_buttons (GdlSwitcher *switcher)
     }
 
     /* Figure out how many rows and columns we'll use. */
-    btns_per_row = allocation.width / (max_btn_width + H_PADDING);
+    btns_per_row = allocation->width / (max_btn_width + H_PADDING);
     
     /* If all the buttons could fit in the single row, have it so */
-    if (allocation.width >= optimal_layout_width)
+    if (allocation->width >= optimal_layout_width)
     {
         btns_per_row = num_btns;
     }
@@ -379,7 +376,7 @@ layout_buttons (GdlSwitcher *switcher)
         /* Check for possible size over flow (taking into account client
          * requisition
          */
-        if (y < (allocation.y + client_requisition.height)) {
+        if (y < (allocation->y + client_requisition.height)) {
             /* We have an overflow: Insufficient allocation */
             if (last_buttons_height < switcher->priv->buttons_height_request) {
                 /* Request for a new resize */
@@ -387,11 +384,11 @@ layout_buttons (GdlSwitcher *switcher)
                 return -1;
             }
         }
-        x = H_PADDING + allocation.x;
+        x = H_PADDING + allocation->x;
         len = g_slist_length (rows[i]);
         if (switcher_style == GDL_SWITCHER_STYLE_TEXT ||
             switcher_style == GDL_SWITCHER_STYLE_BOTH)
-            extra_width = (allocation.width - (len * max_btn_width )
+            extra_width = (allocation->width - (len * max_btn_width )
                            - (len * H_PADDING)) / len;
         else
             extra_width = 0;
@@ -429,27 +426,25 @@ layout_buttons (GdlSwitcher *switcher)
 }
 
 static void
-do_layout (GdlSwitcher *switcher)
+do_layout (GdlSwitcher *switcher, GtkAllocation* allocation)
 {
-    GtkAllocation allocation;
+    
     GtkAllocation child_allocation;
     int y;
-
-    gtk_widget_get_allocation (GTK_WIDGET (switcher), &allocation);
     
     if (switcher->priv->show) {
-        y = layout_buttons (switcher);
+        y = layout_buttons (switcher, allocation);
         if (y < 0) /* Layout did not happen and a resize was requested */
             return;
     }
     else
-        y = allocation.y + allocation.height;
+        y = allocation->y + allocation->height;
     
     /* Place the parent widget.  */
-    child_allocation.x = allocation.x;
-    child_allocation.y = allocation.y;
-    child_allocation.width = allocation.width;
-    child_allocation.height = y - allocation.y;
+    child_allocation.x = allocation->x;
+    child_allocation.y = allocation->y;
+    child_allocation.width = allocation->width;
+    child_allocation.height = y - allocation->y;
     
     GTK_WIDGET_CLASS (gdl_switcher_parent_class)->size_allocate (GTK_WIDGET (switcher), &child_allocation);
 }
@@ -535,8 +530,8 @@ gdl_switcher_size_request (GtkWidget *widget, GtkRequisition *requisition)
 static void
 gdl_switcher_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
 {
+    do_layout (GDL_SWITCHER (widget), allocation);
     gtk_widget_set_allocation (widget, allocation);
-    do_layout (GDL_SWITCHER (widget));
 }
 
 static gint



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