[gtk+/composite-templates] Make GtkToolbar honour css border and padding



commit 22de92df8a0a38b0a26cca1151e4009b6b9e29e6
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Aug 4 17:22:38 2012 +0200

    Make GtkToolbar honour css border and padding
    
    The widget is already calling gtk_render_frame, but is not measuring css
    border and padding when negotiating its size. This patch replaces the
    already existing get_internal_padding static helper with a function that
    sums the old internal-padding value with the values specified via css.

 gtk/gtktoolbar.c |   92 +++++++++++++++++++++++++++--------------------------
 1 files changed, 47 insertions(+), 45 deletions(-)
---
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 3a389bd..6bef947 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -252,7 +252,6 @@ static gboolean   gtk_toolbar_popup_menu           (GtkWidget           *toolbar
 static void       gtk_toolbar_reconfigured         (GtkToolbar          *toolbar);
 
 static GtkReliefStyle       get_button_relief    (GtkToolbar *toolbar);
-static gint                 get_internal_padding (GtkToolbar *toolbar);
 static gint                 get_max_child_expand (GtkToolbar *toolbar);
 static GtkShadowType        get_shadow_type      (GtkToolbar *toolbar);
 
@@ -886,6 +885,29 @@ gtk_toolbar_draw (GtkWidget *widget,
 }
 
 static void
+get_widget_padding_and_border (GtkWidget *widget,
+                               GtkBorder *padding)
+{
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder tmp;
+  gint ipadding = 0;
+
+  context = gtk_widget_get_style_context (widget);
+  state = gtk_style_context_get_state (context);
+
+  gtk_style_context_get_padding (context, state, padding);
+  gtk_style_context_get_border (context, state, &tmp);
+
+  gtk_widget_style_get (widget, "internal-padding", &ipadding, NULL);
+
+  padding->top += tmp.top + ipadding;
+  padding->right += tmp.right + ipadding;
+  padding->bottom += tmp.bottom + ipadding;
+  padding->left += tmp.left + ipadding;
+}
+
+static void
 gtk_toolbar_size_request (GtkWidget      *widget,
 			  GtkRequisition *requisition)
 {
@@ -899,7 +921,7 @@ gtk_toolbar_size_request (GtkWidget      *widget,
   gint homogeneous_size;
   gint long_req;
   gint pack_front_size;
-  gint ipadding;
+  GtkBorder padding;
   guint border_width;
   GtkRequisition arrow_requisition;
   
@@ -993,14 +1015,14 @@ gtk_toolbar_size_request (GtkWidget      *widget,
       requisition->height = long_req;
       requisition->width = MAX (max_child_width, arrow_requisition.width);
     }
-  
-  /* Extra spacing */
-  ipadding = get_internal_padding (toolbar);
 
+  /* Extra spacing */
+  get_widget_padding_and_border (widget, &padding);
   border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
-  requisition->width += 2 * (ipadding + border_width);
-  requisition->height += 2 * (ipadding + border_width);
-  
+
+  requisition->width += 2 * border_width + padding.left + padding.right;
+  requisition->height += 2 * border_width + padding.top + padding.bottom;
+
   if (get_shadow_type (toolbar) != GTK_SHADOW_NONE)
     {
       GtkStyleContext *context;
@@ -1241,13 +1263,11 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
   GtkAllocation allocation;
   GtkWidget *widget = GTK_WIDGET (toolbar);
   GtkToolbarPrivate *priv = toolbar->priv;
-  GtkStyleContext *context;
-  GtkStateFlags state;
-  GtkBorder padding;
   GList *list;
   gint cur_x;
   gint cur_y;
   gint border_width;
+  GtkBorder padding;
   gboolean rtl;
   gboolean vertical;
   
@@ -1265,14 +1285,13 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
     priv->idle_id = gdk_threads_add_idle (slide_idle_handler, toolbar);
 
   gtk_widget_get_allocation (widget, &allocation);
-  context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
-  gtk_style_context_get_padding (context, state, &padding);
 
   rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
   vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
-  border_width = get_internal_padding (toolbar) + gtk_container_get_border_width (GTK_CONTAINER (toolbar));
-  
+
+  border_width = gtk_container_get_border_width (GTK_CONTAINER (toolbar));
+  get_widget_padding_and_border (GTK_WIDGET (toolbar), &padding);
+
   if (rtl)
     {
       cur_x = allocation.width - border_width - padding.right;
@@ -1479,8 +1498,6 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
   GtkAllocation *allocations;
   ItemState *new_states;
   GtkAllocation arrow_allocation;
-  GtkStyleContext *context;
-  GtkStateFlags state;
   GtkBorder padding;
   gint arrow_size;
   gint size, pos, short_size;
@@ -1498,10 +1515,6 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
   GtkAllocation item_area;
   GtkShadowType shadow_type;
 
-  context = gtk_widget_get_style_context (widget);
-  state = gtk_widget_get_state_flags (widget);
-  gtk_style_context_get_padding (context, state, &padding);
-
   gtk_widget_get_allocation (widget, &widget_allocation);
   size_changed = FALSE;
   if (widget_allocation.x != allocation->x ||
@@ -1526,17 +1539,18 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
                             allocation->width - border_width * 2,
                             allocation->height - border_width * 2);
 
-  border_width += get_internal_padding (toolbar);
 
   gtk_widget_get_preferred_size (priv->arrow_button,
                                  &arrow_requisition, NULL);
 
   shadow_type = get_shadow_type (toolbar);
 
+  get_widget_padding_and_border (widget, &padding);
+
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      available_size = size = allocation->width - 2 * border_width;
-      short_size = allocation->height - 2 * border_width;
+      available_size = size = allocation->width - 2 * border_width - padding.left - padding.right;
+      short_size = allocation->height - 2 * border_width - padding.top - padding.bottom;
       arrow_size = arrow_requisition.width;
 
       if (shadow_type != GTK_SHADOW_NONE)
@@ -1547,8 +1561,8 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
     }
   else
     {
-      available_size = size = allocation->height - 2 * border_width;
-      short_size = allocation->width - 2 * border_width;
+      available_size = size = allocation->height - 2 * border_width - padding.top - padding.bottom;
+      short_size = allocation->width - 2 * border_width - padding.left - padding.right;
       arrow_size = arrow_requisition.height;
 
       if (shadow_type != GTK_SHADOW_NONE)
@@ -1672,7 +1686,7 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
     }
 
   /* position items */
-  pos = border_width;
+  pos = border_width + padding.left;
   for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
     {
       /* Both NORMAL and OVERFLOWN items get a position.
@@ -1681,7 +1695,7 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
       if (new_states[i] == NORMAL || new_states[i] == OVERFLOWN)
         {
           allocations[i].x = pos;
-          allocations[i].y = border_width;
+          allocations[i].y = border_width + padding.top;
           allocations[i].height = short_size;
 
           pos += allocations[i].width;
@@ -1691,12 +1705,12 @@ gtk_toolbar_size_allocate (GtkWidget     *widget,
   /* position arrow */
   if (need_arrow)
     {
-      arrow_allocation.x = available_size - border_width - arrow_allocation.width;
-      arrow_allocation.y = border_width;
+      arrow_allocation.x = available_size - border_width - padding.left - arrow_allocation.width;
+      arrow_allocation.y = border_width + padding.top;
     }
 
-  item_area.x = border_width;
-  item_area.y = border_width;
+  item_area.x = border_width + padding.left;
+  item_area.y = border_width + padding.top;
   item_area.width = available_size - (need_arrow? arrow_size : 0);
   item_area.height = short_size;
 
@@ -3650,18 +3664,6 @@ get_button_relief (GtkToolbar *toolbar)
 }
 
 static gint
-get_internal_padding (GtkToolbar *toolbar)
-{
-  gint ipadding = 0;
-  
-  gtk_widget_style_get (GTK_WIDGET (toolbar),
-			"internal-padding", &ipadding,
-			NULL);
-  
-  return ipadding;
-}
-
-static gint
 get_max_child_expand (GtkToolbar *toolbar)
 {
   gint mexpand = G_MAXINT;



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