[gtk+/gtk-style-context: 530/540] GtkStyleProperties: Turn border-width into a GtkBorder property.



commit 6a4a032b82b56281672e656f4b17af6e1e4ab9d0
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Dec 1 00:55:14 2010 +0100

    GtkStyleProperties: Turn border-width into a GtkBorder property.
    
    All current users of this CSS property have been updated to deal
    with a GtkBorder.
    
    Also a 0 border width has been set in the default CSS to ensure
    GtkStyleContext and GtkThemingEngine always provide a non-NULL
    pointer for this property.

 gtk/gtkbutton.c          |   45 +++++++------
 gtk/gtkcombobox.c        |  171 ++++++++++++++++++++++------------------------
 gtk/gtkcssprovider.c     |    3 +-
 gtk/gtkmenu.c            |  130 ++++++++++++++++++++---------------
 gtk/gtkmenubar.c         |   19 +++--
 gtk/gtkstyleproperties.c |    8 +-
 gtk/gtkthemingengine.c   |   51 ++++++++++----
 7 files changed, 237 insertions(+), 190 deletions(-)
---
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index cbfbdcb..f0e00da 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -1448,22 +1448,18 @@ gtk_button_size_allocate (GtkWidget     *widget,
   GtkStateFlags state;
   GtkWidget *child;
 
-  gint xthickness, ythickness;
   GtkBorder default_border;
-  GtkBorder inner_border;
-  gint focus_width, border_width;
+  GtkBorder inner_border, *border;
+  gint focus_width;
   gint focus_pad;
 
   context = gtk_widget_get_style_context (widget);
   state = gtk_widget_get_state_flags (widget);
 
   gtk_style_context_get (context, state,
-                         "border-width", &border_width,
+                         "border-width", &border,
                          NULL);
 
-  xthickness = border_width;
-  ythickness = border_width;
-
   gtk_button_get_props (button, &default_border, NULL, &inner_border, NULL);
   gtk_widget_style_get (GTK_WIDGET (widget),
 			"focus-line-width", &focus_width,
@@ -1482,18 +1478,18 @@ gtk_button_size_allocate (GtkWidget     *widget,
   child = gtk_bin_get_child (GTK_BIN (button));
   if (child && gtk_widget_get_visible (child))
     {
-      child_allocation.x = allocation->x + inner_border.left + xthickness;
-      child_allocation.y = allocation->y + inner_border.top + ythickness;
+      child_allocation.x = allocation->x + inner_border.left + border->left;
+      child_allocation.y = allocation->y + inner_border.top + border->top;
 
       child_allocation.width =
 	allocation->width -
-	xthickness * 2 -
+	(border->left + border->right) -
 	inner_border.left -
 	inner_border.right;
 
       child_allocation.height = 
 	allocation->height -
-	ythickness * 2 -
+	(border->top + border->bottom) -
 	inner_border.top -
 	inner_border.bottom;
 
@@ -1531,6 +1527,8 @@ gtk_button_size_allocate (GtkWidget     *widget,
 
       gtk_widget_size_allocate (child, &child_allocation);
     }
+
+  gtk_border_free (border);
 }
 
 void
@@ -1614,7 +1612,7 @@ _gtk_button_paint (GtkButton          *button,
       gint child_displacement_x;
       gint child_displacement_y;
       gboolean displace_focus;
-      gint border_width;
+      GtkBorder *border;
 
       gtk_widget_style_get (widget,
                             "child-displacement-y", &child_displacement_y,
@@ -1623,15 +1621,15 @@ _gtk_button_paint (GtkButton          *button,
                             NULL);
 
       gtk_style_context_get (context, state,
-			     "border-width", &border_width,
+			     "border-width", &border,
 			     NULL);
 
       if (interior_focus)
         {
-          x += border_width + focus_pad;
-          y += border_width + focus_pad;
-          width -= 2 * (border_width + focus_pad);
-          height -=  2 * (border_width + focus_pad);
+          x += border->left + focus_pad;
+          y += border->top + focus_pad;
+          width -= (2 * focus_pad) + border->left + border->right;
+          height -=  (2 * focus_pad) + border->top + border->bottom;
         }
       else
         {
@@ -1649,6 +1647,8 @@ _gtk_button_paint (GtkButton          *button,
 
       gtk_render_focus (context, cr,
 			x, y, width, height);
+
+      gtk_border_free (border);
     }
 }
 
@@ -1910,7 +1910,8 @@ gtk_button_get_size (GtkWidget      *widget,
   GtkBorder default_border;
   GtkBorder inner_border;
   GtkStateFlags state;
-  gint focus_width, border_width;
+  GtkBorder *border;
+  gint focus_width;
   gint focus_pad;
   gint minimum, natural;
 
@@ -1924,12 +1925,12 @@ gtk_button_get_size (GtkWidget      *widget,
   state = gtk_widget_get_state_flags (GTK_WIDGET (widget));
 
   gtk_style_context_get (context, state,
-                         "border-width", &border_width,
+                         "border-width", &border,
                          NULL);
 
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      minimum = (border_width * 2 +
+      minimum = (border->left + border->right +
 		 inner_border.left + inner_border.right);
 
       if (gtk_widget_get_can_default (GTK_WIDGET (widget)))
@@ -1937,7 +1938,7 @@ gtk_button_get_size (GtkWidget      *widget,
     }
   else
     {
-      minimum = (border_width * 2 +
+      minimum = (border->top + border->bottom +
 		 inner_border.top + inner_border.bottom);
 
       if (gtk_widget_get_can_default (GTK_WIDGET (widget)))
@@ -1966,6 +1967,8 @@ gtk_button_get_size (GtkWidget      *widget,
 
   if (natural_size)
     *natural_size = natural;
+
+  gtk_border_free (border);
 }
 
 static void 
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index 9f884a7..0cf0737 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -1739,19 +1739,22 @@ gtk_combo_box_set_popup_widget (GtkComboBox *combo_box,
     }
 }
 
-static gint
-get_widget_border_thickness (GtkWidget *widget)
+static void
+get_widget_border (GtkWidget *widget,
+                   GtkBorder *border)
 {
   GtkStyleContext *context;
-  gint thickness;
+  GtkBorder *border_width;
 
   context = gtk_widget_get_style_context (widget);
 
   gtk_style_context_get (context,
                          gtk_widget_get_state_flags (widget),
-                         "border-width", &thickness,
+                         "border-width", &border_width,
                          NULL);
-  return thickness;
+
+  *border = *border_width;
+  gtk_border_free (border_width);
 }
 
 static void
@@ -1769,7 +1772,8 @@ gtk_combo_box_menu_position_below (GtkMenu  *menu,
   GdkScreen *screen;
   gint monitor_num;
   GdkRectangle monitor;
-  
+  GtkBorder border;
+
   /* FIXME: is using the size request here broken? */
   child = gtk_bin_get_child (GTK_BIN (combo_box));
 
@@ -1785,9 +1789,8 @@ gtk_combo_box_menu_position_below (GtkMenu  *menu,
 
   gdk_window_get_root_coords (gtk_widget_get_window (child),
                               sx, sy, &sx, &sy);
-
-  if (GTK_SHADOW_NONE != combo_box->priv->shadow_type)
-    sx -= get_widget_border_thickness (GTK_WIDGET (combo_box));
+  get_widget_border (GTK_WIDGET (combo_box), &border);
+  sx -= border.left;
 
   if (combo_box->priv->popup_fixed_width)
     gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
@@ -2477,13 +2480,13 @@ gtk_combo_box_update_requested_width (GtkComboBox *combo_box,
                                  &req, NULL); 					\
   										\
   if (is_rtl) 									\
-    child.x = allocation->x + shadow_width;					\
+    child.x = allocation->x + border.right;					\
   else										\
-    child.x = allocation->x + allocation->width - req.width - shadow_width;	\
+    child.x = allocation->x + allocation->width - req.width - border.left;	\
     										\
-  child.y = allocation->y + shadow_height;					\
+  child.y = allocation->y + border.top;						\
   child.width = req.width;							\
-  child.height = allocation->height - 2 * shadow_height;			\
+  child.height = allocation->height - (border.top + border.bottom);		\
   child.width = MAX (1, child.width);						\
   child.height = MAX (1, child.height);						\
   										\
@@ -2496,47 +2499,40 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
   GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
   GtkComboBoxPrivate *priv = combo_box->priv;
   GtkWidget *child_widget;
-  gint shadow_width, shadow_height;
   gint focus_width, focus_pad;
   GtkAllocation child;
   GtkRequisition req;
+  GtkBorder border;
   gboolean is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
 
   gtk_widget_set_allocation (widget, allocation);
   child_widget = gtk_bin_get_child (GTK_BIN (widget));
+  get_widget_border (widget, &border);
 
   gtk_widget_style_get (widget,
 			"focus-line-width", &focus_width,
 			"focus-padding", &focus_pad,
 			NULL);
 
-  if (GTK_SHADOW_NONE != priv->shadow_type)
-    shadow_width = shadow_height = get_widget_border_thickness (widget);
-  else
-    {
-      shadow_width = 0;
-      shadow_height = 0;
-    }
-
   if (!priv->tree_view)
     {
       if (priv->cell_view)
         {
-          gint xthickness, ythickness;
+          GtkBorder button_border;
           gint width;
           guint border_width;
 
           /* menu mode */
-          allocation->x += shadow_width;
-          allocation->y += shadow_height;
-          allocation->width -= 2 * shadow_width;
-          allocation->height -= 2 * shadow_height;
+          allocation->x += border.left;
+          allocation->y += border.top;
+          allocation->width -= border.left + border.right;
+          allocation->height -= border.top + border.bottom;
 
           gtk_widget_size_allocate (priv->button, allocation);
 
           /* set some things ready */
           border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->button));
-          xthickness = ythickness = get_widget_border_thickness (priv->button);
+          get_widget_border (priv->button, &button_border);
 
           child.x = allocation->x;
           child.y = allocation->y;
@@ -2545,10 +2541,12 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
 
 	  if (!priv->is_cell_renderer)
 	    {
-	      child.x += border_width + xthickness + focus_width + focus_pad;
-	      child.y += border_width + ythickness + focus_width + focus_pad;
-	      width -= 2 * (child.x - allocation->x);
-	      child.height -= 2 * (child.y - allocation->y);
+	      child.x += border_width + button_border.left + focus_width + focus_pad;
+	      child.y += border_width + button_border.top + focus_width + focus_pad;
+	      width -= (2 * (border_width + focus_width + focus_pad)) +
+                button_border.left + button_border.right;
+	      child.height -= (2 * (border_width + focus_width + focus_pad)) +
+                button_border.top + button_border.bottom;
 	    }
 
 
@@ -2574,14 +2572,14 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
             {
               child.x += req.width;
               child.width = allocation->x + allocation->width 
-                - (border_width + xthickness + focus_width + focus_pad) 
+                - (border_width + button_border.right + focus_width + focus_pad) 
 		- child.x;
             }
           else 
             {
               child.width = child.x;
               child.x = allocation->x 
-		+ border_width + xthickness + focus_width + focus_pad;
+		+ border_width + button_border.left + focus_width + focus_pad;
               child.width -= child.x;
             }
 
@@ -2619,11 +2617,11 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
           GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
 
           if (is_rtl)
-            child.x = allocation->x + req.width + shadow_width;
+            child.x = allocation->x + req.width + border.right;
           else
-            child.x = allocation->x + shadow_width;
-          child.y = allocation->y + shadow_height;
-          child.width = allocation->width - req.width - 2 * shadow_width;
+            child.x = allocation->x + border.left;
+          child.y = allocation->y + border.top;
+          child.width = allocation->width - req.width - (border.left + border.right);
 	  child.width = MAX (1, child.width);
 	  child.height = MAX (1, child.height);
           gtk_widget_size_allocate (child_widget, &child);
@@ -2632,11 +2630,7 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
   else
     {
       /* list mode */
-
-      /* Combobox thickness + border-width */
       guint border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-      int delta_x = shadow_width + border_width;
-      int delta_y = shadow_height + border_width;
 
       /* button */
       GTK_COMBO_BOX_SIZE_ALLOCATE_BUTTON
@@ -2653,30 +2647,32 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
 
       if (priv->cell_view_frame)
         {
-          child.x += delta_x;
-          child.y += delta_y;
-          child.width = MAX (1, child.width - delta_x * 2);
-          child.height = MAX (1, child.height - delta_y * 2);
+          child.x += border.left + border_width;
+          child.y += border.top + border_width;
+          child.width = MAX (1, child.width - (2 * border_width) - (border.left + border.right));
+          child.height = MAX (1, child.height - (2 * border_width) - (border.top + border.bottom));
           gtk_widget_size_allocate (priv->cell_view_frame, &child);
 
           /* the sample */
           if (priv->has_frame)
             {
+              GtkBorder frame_border;
+
               border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
-              delta_x = delta_y = border_width + get_widget_border_thickness (priv->cell_view_frame);
+              get_widget_border (priv->cell_view_frame, &frame_border);
 
-              child.x += delta_x;
-              child.y += delta_y;
-              child.width -= delta_x * 2;
-              child.height -= delta_y * 2;
+              child.x += border_width + frame_border.left;
+              child.y += border_width + frame_border.right;
+              child.width -= (2 * border_width) + frame_border.left + frame_border.right;
+              child.height -= (2 * border_width) + frame_border.top + frame_border.bottom;
             }
         }
       else
         {
-          child.x += delta_x;
-          child.y += delta_y;
-          child.width -= delta_x * 2;
-          child.height -= delta_y * 2;
+          child.x += border.left + border_width;
+          child.y += border.top + border_width;
+          child.width -= (2 * border_width) - (border.left + border.right);
+          child.height -= (2 * border_width) - (border.top + border.bottom);
         }
 
       if (gtk_widget_get_visible (priv->popup_window))
@@ -6430,6 +6426,7 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
   gint                   child_min, child_nat;
   GtkStyleContext       *style_context;
   GtkStateFlags          state;
+  GtkBorder             *border;
 
   child = gtk_bin_get_child (GTK_BIN (widget));
  
@@ -6451,6 +6448,7 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
 
   gtk_style_context_get (style_context, state,
                          "font", &font_desc,
+                         "border-width", &border,
                          NULL);
 
   context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
@@ -6472,15 +6470,17 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
       if (priv->cell_view)
         {
           gint sep_width, arrow_width;
-          gint border_width, xthickness, xpad;
+          gint border_width, xpad;
+          GtkBorder button_border;
 
 	  border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
-          xthickness   = get_widget_border_thickness (priv->button);
+          get_widget_border (priv->button, &button_border);
 
           gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
           gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
 
-	  xpad = 2*(border_width + xthickness + focus_width + focus_pad);
+	  xpad = 2 * (border_width + focus_width + focus_pad) +
+            button_border.left + button_border.right;
 
           minimum_width  = child_min + sep_width + arrow_width + xpad;
           natural_width  = child_nat + sep_width + arrow_width + xpad;
@@ -6512,8 +6512,12 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
         {
 	  if (priv->has_frame)
 	    {
-	      gint border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
-	      gint xpad         = 2 * (border_width + get_widget_border_thickness (priv->cell_view_frame));
+	      gint border_width, xpad;
+              GtkBorder frame_border;
+
+              border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
+              get_widget_border (priv->cell_view_frame, &frame_border);
+              xpad = (2 * border_width) + frame_border.left + frame_border.right;
 
 	      minimum_width  += xpad;
 	      natural_width  += xpad;
@@ -6528,14 +6532,9 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
       natural_width += button_nat_width;
     }
 
-  if (GTK_SHADOW_NONE != priv->shadow_type)
-    {
-      gint thickness;
-
-      thickness = get_widget_border_thickness (GTK_WIDGET (widget));
-      minimum_width += 2 * thickness;
-      natural_width += 2 * thickness;
-    }
+  minimum_width += border->left + border->right;
+  natural_width += border->left + border->right;
+  gtk_border_free (border);
 
   if (minimum_size)
     *minimum_size = minimum_width;
@@ -6580,16 +6579,15 @@ gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
   gint                   focus_width, focus_pad;
   gint                   min_height, nat_height;
   gint                   size;
+  GtkBorder              border;
 
   gtk_widget_style_get (GTK_WIDGET (widget),
 			"focus-line-width", &focus_width,
 			"focus-padding", &focus_pad,
 			NULL);
 
-  size = avail_size;
-
-  if (GTK_SHADOW_NONE != priv->shadow_type)
-    size -= get_widget_border_thickness (widget);
+  get_widget_border (widget, &border);
+  size = avail_size - border.left;
 
   if (!priv->tree_view)
     {
@@ -6598,10 +6596,11 @@ gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
         {
 	  /* calculate x/y padding and separator/arrow size */
           gint sep_width, arrow_width, sep_height, arrow_height;
-          gint border_width, xthickness, ythickness, xpad, ypad;
+          gint border_width, xpad, ypad;
+          GtkBorder button_border;
 
 	  border_width = gtk_container_get_border_width (GTK_CONTAINER (combo_box));
-          xthickness = ythickness = get_widget_border_thickness (priv->button);
+          get_widget_border (priv->button, &button_border);
 
           gtk_widget_get_preferred_width (priv->separator, &sep_width, NULL);
           gtk_widget_get_preferred_width (priv->arrow, &arrow_width, NULL);
@@ -6610,8 +6609,10 @@ gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
           gtk_widget_get_preferred_height_for_width (priv->arrow, 
                                                      arrow_width, &arrow_height, NULL);
 
-	  xpad = 2*(border_width + xthickness + focus_width + focus_pad);
-	  ypad = 2*(border_width + ythickness + focus_width + focus_pad);
+	  xpad = 2 * (border_width + focus_width + focus_pad) +
+            button_border.left + button_border.right;
+	  ypad = 2 * (border_width + focus_width + focus_pad) +
+            button_border.top + button_border.bottom;
 
 	  size -= sep_width + arrow_width + xpad;
 
@@ -6653,14 +6654,14 @@ gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
       
       if (priv->cell_view_frame && priv->has_frame)
 	{
+          GtkBorder frame_border;
 	  gint border_width;
-          gint thickness;
 
           border_width = gtk_container_get_border_width (GTK_CONTAINER (priv->cell_view_frame));
-          thickness = get_widget_border_thickness (GTK_WIDGET (priv->cell_view_frame));
+          get_widget_border (GTK_WIDGET (priv->cell_view_frame), &frame_border);
 
-	  xpad = 2 * (border_width + thickness);
-	  ypad = 2 * (border_width + thickness);
+	  xpad = (2 * border_width) + border.left + frame_border.right;
+	  ypad = (2 * border_width) + border.top + frame_border.bottom;
 	}
 
       size -= but_width;
@@ -6676,14 +6677,8 @@ gtk_combo_box_get_preferred_height_for_width (GtkWidget *widget,
       nat_height += ypad;
     }
 
-  if (GTK_SHADOW_NONE != priv->shadow_type)
-    {
-      gint thickness;
-
-      thickness = get_widget_border_thickness (widget);
-      min_height += 2 * thickness;
-      nat_height += 2 * thickness;
-    }
+  min_height += border.top + border.bottom;
+  nat_height += border.top + border.bottom;
 
   if (minimum_size)
     *minimum_size = min_height;
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index f963669..afc8340 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -3501,7 +3501,8 @@ gtk_css_provider_get_default (void)
         "  background-color: @bg_color;\n"
         "  color: @fg_color;\n"
         "  border-color: shade (@bg_color, 0.6);\n"
-        "  padding: 2 2; \n"
+        "  padding: 2;\n"
+        "  border-width: 0;\n"
         "}\n"
         "\n"
         "*:prelight {\n"
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index e9defd3..e678198 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -2363,20 +2363,23 @@ get_arrows_border (GtkMenu   *menu,
   border->left = border->right = 0;
 }
 
-static gint
-get_menu_border_thickness (GtkWidget *widget)
+static void
+get_menu_border (GtkWidget *widget,
+                 GtkBorder *border)
 {
   GtkStyleContext *context;
   GtkStateFlags state;
-  gint thickness;
+  GtkBorder *border_width;
 
   context = gtk_widget_get_style_context (widget);
   state = gtk_widget_get_state_flags (widget);
 
   gtk_style_context_get (context, state,
-                         "border-width", &thickness,
+                         "border-width", &border_width,
                          NULL);
-  return thickness;
+
+  *border = *border_width;
+  gtk_border_free (border_width);
 }
 
 static void
@@ -2387,14 +2390,14 @@ gtk_menu_realize (GtkWidget *widget)
   GdkWindow *window;
   GdkWindowAttr attributes;
   gint attributes_mask;
-  gint border_width, thickness;
+  gint border_width;
   GtkMenu *menu;
   GtkMenuPrivate *priv;
   GtkWidget *child;
   GList *children;
   guint vertical_padding;
   guint horizontal_padding;
-  GtkBorder arrow_border;
+  GtkBorder arrow_border, border;
 
   g_return_if_fail (GTK_IS_MENU (widget));
 
@@ -2423,7 +2426,7 @@ gtk_menu_realize (GtkWidget *widget)
   gtk_widget_set_window (widget, window);
   gdk_window_set_user_data (window, widget);
 
-  thickness = get_menu_border_thickness (widget);
+  get_menu_border (widget, &border);
   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
   context = gtk_widget_get_style_context (widget);
 
@@ -2434,16 +2437,21 @@ gtk_menu_realize (GtkWidget *widget)
 
   gtk_widget_get_allocation (widget, &allocation);
 
-  attributes.x = border_width + thickness + horizontal_padding;
-  attributes.y = border_width + thickness + vertical_padding;
-  attributes.width = MAX (1, allocation.width - attributes.x * 2);
-  attributes.height = MAX (1, allocation.height - attributes.y * 2);
+  attributes.x = border_width + border.left + horizontal_padding;
+  attributes.y = border_width + border.top + vertical_padding;
+  attributes.width = allocation.width -
+    (2 * (border_width + horizontal_padding)) - border.left - border.right;
+  attributes.height = allocation.height -
+    (2 * (border_width + vertical_padding)) - border.top - border.bottom;
 
   get_arrows_border (menu, &arrow_border);
   attributes.y += arrow_border.top;
   attributes.height -= arrow_border.top;
   attributes.height -= arrow_border.bottom;
 
+  attributes.width = MAX (1, attributes.width);
+  attributes.height = MAX (1, attributes.height);
+
   menu->view_window = gdk_window_new (window,
                                       &attributes, attributes_mask);
   gdk_window_set_user_data (menu->view_window, menu);
@@ -2452,8 +2460,13 @@ gtk_menu_realize (GtkWidget *widget)
 
   attributes.x = 0;
   attributes.y = 0;
-  attributes.width = MAX (1, allocation.width - (border_width + thickness + horizontal_padding) * 2);
-  attributes.height = MAX (1, priv->requested_height - (border_width + thickness + vertical_padding) * 2);
+  attributes.width = allocation.width + (2 * (border_width + horizontal_padding)) +
+    border.left + border.right;
+  attributes.height = priv->requested_height - (2 * (border_width + vertical_padding)) +
+    border.top + border.bottom;
+
+  attributes.width = MAX (1, attributes.width);
+  attributes.height = MAX (1, attributes.height);
 
   menu->bin_window = gdk_window_new (menu->view_window,
                                      &attributes, attributes_mask);
@@ -2641,11 +2654,12 @@ gtk_menu_size_allocate (GtkWidget     *widget,
   GtkAllocation child_allocation;
   GtkMenuPrivate *priv;
   GList *children;
-  gint x, y, i, thickness;
+  gint x, y, i;
   gint width, height;
   guint border_width;
   guint vertical_padding;
   guint horizontal_padding;
+  GtkBorder border;
 
   g_return_if_fail (GTK_IS_MENU (widget));
   g_return_if_fail (allocation != NULL);
@@ -2661,7 +2675,7 @@ gtk_menu_size_allocate (GtkWidget     *widget,
                         "horizontal-padding", &horizontal_padding,
 			NULL);
 
-  thickness = get_menu_border_thickness (widget);
+  get_menu_border (widget, &border);
   border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
 
   g_free (priv->heights);
@@ -2672,15 +2686,17 @@ gtk_menu_size_allocate (GtkWidget     *widget,
 			    NULL);
 
   /* refresh our cached height request */
-  priv->requested_height = (border_width + vertical_padding + thickness) * 2;
+  priv->requested_height = (2 * (border_width + vertical_padding)) +
+    border.top + border.bottom;
   for (i = 0; i < priv->heights_length; i++)
     priv->requested_height += priv->heights[i];
 
-  x = border_width + thickness + horizontal_padding;
-  y = border_width + thickness + vertical_padding;
-
-  width = MAX (1, allocation->width - x * 2);
-  height = MAX (1, allocation->height - y * 2);
+  x = border_width + border.left + horizontal_padding;
+  y = border_width + border.top + vertical_padding;
+  width = allocation->width - (2 * (border_width + horizontal_padding)) -
+    border.left - border.right;
+  height = allocation->height - (2 * (border_width + vertical_padding)) -
+    border.top - border.bottom;
 
   if (menu_shell->active)
     gtk_menu_scroll_to (menu, menu->scroll_offset);
@@ -2695,6 +2711,9 @@ gtk_menu_size_allocate (GtkWidget     *widget,
       height -= arrow_border.bottom;
     }
 
+  width = MAX (1, width);
+  height = MAX (1, height);
+
   if (gtk_widget_get_realized (widget))
     {
       gdk_window_move_resize (gtk_widget_get_window (widget),
@@ -2820,7 +2839,7 @@ get_arrows_visible_area (GtkMenu      *menu,
   guint vertical_padding;
   guint horizontal_padding;
   gint scroll_arrow_height;
-  gint thickness;
+  GtkBorder menu_border;
 
   gtk_widget_style_get (widget,
                         "vertical-padding", &vertical_padding,
@@ -2829,10 +2848,10 @@ get_arrows_visible_area (GtkMenu      *menu,
                         "arrow-placement", &arrow_placement,
                         NULL);
 
-  thickness = get_menu_border_thickness (widget);
+  get_menu_border (widget, &menu_border);
   border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-  border->x = border_width + thickness + horizontal_padding;
-  border->y = border_width + thickness + vertical_padding;
+  border->x = border_width + menu_border.left + horizontal_padding;
+  border->y = border_width + menu_border.top + vertical_padding;
   border->width = gdk_window_get_width (gtk_widget_get_window (widget));
   border->height = gdk_window_get_height (gtk_widget_get_window (widget));
 
@@ -2880,7 +2899,7 @@ get_arrows_visible_area (GtkMenu      *menu,
        lower->x = lower->y = lower->width = lower->height = 0;
     }
 
-  *arrow_space = scroll_arrow_height - 2 * thickness;
+  *arrow_space = scroll_arrow_height - menu_border.top - menu_border.bottom;
 }
 
 static gboolean
@@ -2894,8 +2913,9 @@ gtk_menu_draw (GtkWidget *widget,
   GdkRectangle upper;
   GdkRectangle lower;
   GdkWindow *window;
-  gint arrow_space, thickness;
+  gint arrow_space;
   GtkStateFlags state;
+  GtkBorder menu_border;
 
   menu = GTK_MENU (widget);
   priv = gtk_menu_get_private (menu);
@@ -2904,9 +2924,7 @@ gtk_menu_draw (GtkWidget *widget,
   state = gtk_widget_get_state_flags (widget);
 
   get_arrows_visible_area (menu, &border, &upper, &lower, &arrow_space);
-  gtk_style_context_get (context, state,
-                         "border-width", &thickness,
-                         NULL);
+  get_menu_border (widget, &menu_border);
 
   if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
     {
@@ -2940,7 +2958,7 @@ gtk_menu_draw (GtkWidget *widget,
 
           gtk_render_arrow (context, cr, 0,
                            upper.x + (upper.width - arrow_size) / 2,
-                           upper.y + thickness + (arrow_space - arrow_size) / 2,
+                           upper.y + menu_border.top + (arrow_space - arrow_size) / 2,
 			   arrow_size);
 
           gtk_style_context_restore (context);
@@ -2960,7 +2978,7 @@ gtk_menu_draw (GtkWidget *widget,
 
           gtk_render_arrow (context, cr, G_PI,
                             lower.x + (lower.width - arrow_size) / 2,
-                            lower.y + thickness + (arrow_space - arrow_size) / 2,
+                            lower.y + menu_border.top + (arrow_space - arrow_size) / 2,
                             arrow_size);
 
           gtk_style_context_restore (context);
@@ -3023,9 +3041,10 @@ gtk_menu_get_preferred_width (GtkWidget *widget,
   guint           max_toggle_size;
   guint           max_accel_width;
   guint           horizontal_padding;
-  guint           border_width, thickness;
+  guint           border_width;
   gint            child_min, child_nat;
   gint            min_width, nat_width;
+  GtkBorder       border;
 
   menu       = GTK_MENU (widget);
   menu_shell = GTK_MENU_SHELL (widget);
@@ -3118,11 +3137,13 @@ gtk_menu_get_preferred_width (GtkWidget *widget,
                         "horizontal-padding", &horizontal_padding,
 			NULL);
 
-  thickness = get_menu_border_thickness (widget);
+  get_menu_border (widget, &border);
   border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
-  min_width   += (border_width + horizontal_padding + thickness) * 2;
-  nat_width   += (border_width + horizontal_padding + thickness) * 2;
-  
+  min_width   += (2 * (border_width + horizontal_padding)) +
+    border.left + border.right;
+  nat_width   += (2 * (border_width + horizontal_padding)) +
+    border.top + border.bottom;
+
   menu->toggle_size = max_toggle_size;
   priv->accel_size  = max_accel_width;
 
@@ -4565,10 +4586,10 @@ gtk_menu_position (GtkMenu  *menu,
       gint space_left, space_right, space_above, space_below;
       gint needed_width;
       gint needed_height;
-      gint thickness;
+      GtkBorder border;
       gboolean rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
 
-      thickness = get_menu_border_thickness (widget);
+      get_menu_border (widget, &border);
 
       /* The placement of popup menus horizontally works like this (with
        * RTL in parentheses)
@@ -4600,7 +4621,7 @@ gtk_menu_position (GtkMenu  *menu,
       /* the amount of space we need to position the menu. Note the
        * menu is offset "thickness" pixels 
        */
-      needed_width = requisition.width - thickness;
+      needed_width = requisition.width - border.left;
 
       if (needed_width <= space_left ||
 	  needed_width <= space_right)
@@ -4609,12 +4630,12 @@ gtk_menu_position (GtkMenu  *menu,
 	      (!rtl && needed_width >  space_right))
 	    {
 	      /* position left */
-	      x = x + thickness - requisition.width + 1;
+	      x = x + border.left - requisition.width + 1;
 	    }
 	  else
 	    {
 	      /* position right */
-	      x = x - thickness;
+	      x = x - border.right;
 	    }
 
 	  /* x is clamped on-screen further down */
@@ -4653,15 +4674,15 @@ gtk_menu_position (GtkMenu  *menu,
       /* Position vertically. The algorithm is the same as above, but
        * simpler because we don't have to take RTL into account.
        */
-      needed_height = requisition.height - thickness;
+      needed_height = requisition.height - border.top;
 
       if (needed_height <= space_above ||
 	  needed_height <= space_below)
 	{
 	  if (needed_height <= space_below)
-	    y = y - thickness;
+	    y = y - border.top;
 	  else
-	    y = y + thickness - requisition.height + 1;
+	    y = y + border.bottom - requisition.height + 1;
 	  
 	  y = CLAMP (y, monitor.y,
 		     monitor.y + monitor.height - requisition.height);
@@ -4773,11 +4794,11 @@ gtk_menu_scroll_to (GtkMenu *menu,
 {
   GtkMenuPrivate *priv;
   GtkAllocation allocation;
-  GtkBorder arrow_border;
+  GtkBorder arrow_border, border;
   GtkWidget *widget;
   gint x, y;
   gint view_width, view_height;
-  gint border_width, thickness;
+  gint border_width;
   gint menu_height;
   guint vertical_padding;
   guint horizontal_padding;
@@ -4806,17 +4827,18 @@ gtk_menu_scroll_to (GtkMenu *menu,
                         "horizontal-padding", &horizontal_padding,
                         NULL);
 
-  thickness = get_menu_border_thickness (widget);
+  get_menu_border (widget, &border);
   double_arrows = get_double_arrows (menu);
 
   border_width = gtk_container_get_border_width (GTK_CONTAINER (menu));
 
-  view_width -= (border_width + thickness + horizontal_padding) * 2;
-  view_height -= (border_width + thickness + vertical_padding) * 2;
-  menu_height = priv->requested_height - (border_width + thickness + vertical_padding) * 2;
+  view_width -= (2 * (border_width + horizontal_padding)) + border.left + border.right;
+  view_height -= (2 * (border_width + vertical_padding)) + border.top + border.bottom;
+  menu_height = priv->requested_height - (2 * (border_width + vertical_padding)) -
+    border.top - border.bottom;
 
-  x = border_width + thickness + horizontal_padding;
-  y = border_width + thickness + vertical_padding;
+  x = border_width + border.left + horizontal_padding;
+  y = border_width + border.top + vertical_padding;
 
   if (double_arrows && !menu->tearoff_active)
     {
diff --git a/gtk/gtkmenubar.c b/gtk/gtkmenubar.c
index 2add10a..bb48284 100644
--- a/gtk/gtkmenubar.c
+++ b/gtk/gtkmenubar.c
@@ -351,16 +351,17 @@ gtk_menu_bar_size_request (GtkWidget      *widget,
       if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
 	{
           GtkStyleContext *context;
-          gint border_width;
+          GtkBorder *border;
 
           context = gtk_widget_get_style_context (widget);
 
           gtk_style_context_get (context, 0,
-                                 "border-width", &border_width,
+                                 "border-width", &border,
                                  NULL);
 
-	  requisition->width += border_width * 2;
-	  requisition->height += border_width * 2;
+	  requisition->width += border->left + border->right;
+	  requisition->height += border->top + border->bottom;
+          gtk_border_free (border);
 	}
     }
 }
@@ -436,15 +437,17 @@ gtk_menu_bar_size_allocate (GtkWidget     *widget,
       if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
 	{
           GtkStyleContext *context;
-          gint border_width;
+          GtkBorder *border;
 
           context = gtk_widget_get_style_context (widget);
           gtk_style_context_get (context, 0,
-                                 "border-width", &border_width,
+                                 "border-width", &border,
                                  NULL);
 
-          child_allocation.x += border_width;
-          child_allocation.y += border_width;
+          child_allocation.x += border->left;
+          child_allocation.y += border->top;
+
+          gtk_border_free (border);
 	}
       
       if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index 49c05d9..9763716 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -130,10 +130,10 @@ gtk_style_properties_class_init (GtkStylePropertiesClass *klass)
                                                               "Padding",
                                                               GTK_TYPE_BORDER, 0));
   gtk_style_properties_register_property (NULL,
-                                          g_param_spec_int ("border-width",
-                                                            "Border width",
-                                                            "Border width, in pixels",
-                                                            0, G_MAXINT, 0, 0));
+                                          g_param_spec_boxed ("border-width",
+                                                              "Border width",
+                                                              "Border width, in pixels",
+                                                              GTK_TYPE_BORDER, 0));
   gtk_style_properties_register_property (NULL,
                                           g_param_spec_int ("border-radius",
                                                             "Border radius",
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 3f2324b..f3d8ab1 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -876,6 +876,7 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
   GtkStateFlags flags;
   gint exterior_size, interior_size, thickness, pad;
   GtkBorderStyle border_style;
+  GtkBorder *border;
   gint border_width;
 
   flags = gtk_theming_engine_get_state (engine);
@@ -886,9 +887,11 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
                           "background-color", &bg_color,
                           "border-color", &border_color,
                           "border-style", &border_style,
-                          "border-width", &border_width,
+                          "border-width", &border,
                           NULL);
 
+  border_width = MIN (MIN (border->top, border->bottom),
+                      MIN (border->left, border->right));
   exterior_size = MIN (width, height);
 
   if (exterior_size % 2 == 0) /* Ensure odd */
@@ -985,6 +988,7 @@ gtk_theming_engine_render_check (GtkThemingEngine *engine,
   gdk_rgba_free (fg_color);
   gdk_rgba_free (bg_color);
   gdk_rgba_free (border_color);
+  gtk_border_free (border);
 }
 
 static void
@@ -999,6 +1003,7 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
   GdkRGBA *fg_color, *bg_color, *border_color;
   gint exterior_size, interior_size, pad, thickness, border_width;
   GtkBorderStyle border_style;
+  GtkBorder *border;
   gdouble radius;
 
   flags = gtk_theming_engine_get_state (engine);
@@ -1011,10 +1016,12 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
                           "background-color", &bg_color,
                           "border-color", &border_color,
                           "border-style", &border_style,
-                          "border-width", &border_width,
+                          "border-width", &border,
                           NULL);
 
   exterior_size = MIN (width, height);
+  border_width = MIN (MIN (border->top, border->bottom),
+                      MIN (border->left, border->right));
 
   if (exterior_size % 2 == 0) /* Ensure odd */
     exterior_size -= 1;
@@ -1093,6 +1100,7 @@ gtk_theming_engine_render_option (GtkThemingEngine *engine,
   gdk_rgba_free (fg_color);
   gdk_rgba_free (bg_color);
   gdk_rgba_free (border_color);
+  gtk_border_free (border);
 }
 
 static void
@@ -1298,6 +1306,7 @@ render_background_internal (GtkThemingEngine *engine,
   gboolean running;
   gdouble progress, alpha = 1;
   gint radius, border_width;
+  GtkBorder *border;
 
   flags = gtk_theming_engine_get_state (engine);
   cairo_save (cr);
@@ -1305,11 +1314,13 @@ render_background_internal (GtkThemingEngine *engine,
   gtk_theming_engine_get (engine, flags,
                           "background-image", &pattern,
                           "background-color", &bg_color,
-                          "border-width", &border_width,
+                          "border-width", &border,
                           "border-radius", &radius,
                           NULL);
 
   running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
+  border_width = MIN (MIN (border->top, border->bottom),
+                      MIN (border->left, border->right));
 
   _cairo_round_rectangle_sides (cr, (gdouble) radius,
                                 x, y, width, height,
@@ -1527,6 +1538,7 @@ render_background_internal (GtkThemingEngine *engine,
   cairo_restore (cr);
 
   gdk_rgba_free (bg_color);
+  gtk_border_free (border);
 }
 
 static void
@@ -1543,7 +1555,8 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
   gboolean running;
   gdouble progress, alpha = 1;
   GtkJunctionSides junction;
-  gint radius, border_width;
+  GtkBorder *border;
+  gint radius;
 
   junction = gtk_theming_engine_get_junction_sides (engine);
 
@@ -1557,20 +1570,19 @@ gtk_theming_engine_render_background (GtkThemingEngine *engine,
     }
 
   gtk_theming_engine_get (engine, flags,
-                          "border-width", &border_width,
+                          "border-width", &border,
                           NULL);
 
-  if (border_width > 0)
-    {
-      x += border_width;
-      y += border_width;
-      width -= 2 * border_width;
-      height -= 2 * border_width;
-    }
+  x += border->left;
+  y += border->top;
+  width -= border->left + border->right;
+  height -= border->top + border->bottom;
 
   render_background_internal (engine, cr,
                               x, y, width, height,
                               junction);
+
+  gtk_border_free (border);
 }
 
 /* Renders the small triangle on corners so
@@ -1612,16 +1624,19 @@ render_frame_internal (GtkThemingEngine *engine,
   gint border_width, radius;
   gdouble progress, d1, d2, m;
   gboolean running;
+  GtkBorder *border;
 
   state = gtk_theming_engine_get_state (engine);
   gtk_theming_engine_get (engine, state,
                           "border-color", &border_color,
                           "border-style", &border_style,
-                          "border-width", &border_width,
+                          "border-width", &border,
                           "border-radius", &radius,
                           NULL);
 
   running = gtk_theming_engine_state_is_running (engine, GTK_STATE_PRELIGHT, &progress);
+  border_width = MIN (MIN (border->top, border->bottom),
+                      MIN (border->left, border->right));
 
   if (running)
     {
@@ -1770,6 +1785,8 @@ render_frame_internal (GtkThemingEngine *engine,
 
   if (border_color)
     gdk_rgba_free (border_color);
+
+  gtk_border_free (border);
 }
 
 static void
@@ -2202,14 +2219,18 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
   GtkStateFlags state;
   gint border_width, radius;
   gdouble x0, y0, x1, y1, xc, yc, wc, hc;
+  GtkBorder *border;
 
   state = gtk_theming_engine_get_state (engine);
   junction = gtk_theming_engine_get_junction_sides (engine);
   gtk_theming_engine_get (engine, state,
-                          "border-width", &border_width,
+                          "border-width", &border,
                           "border-radius", &radius,
                           NULL);
 
+  border_width = MIN (MIN (border->top, border->bottom),
+                      MIN (border->left, border->right));
+
   cairo_save (cr);
 
   switch (gap_side)
@@ -2279,6 +2300,8 @@ gtk_theming_engine_render_frame_gap (GtkThemingEngine *engine,
                          0, junction);
 
   cairo_restore (cr);
+
+  gtk_border_free (border);
 }
 
 static void



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