[gtk+] Fix up GtkLabel and GtkImage sizing



commit 3b30cfa344ebc035ae7318dda5cfa11b8ab3aee7
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue May 27 00:21:46 2014 -0400

    Fix up GtkLabel and GtkImage sizing
    
    When GtkMisc was removed, I forgot to apply the style context
    padding. This caused the info-bar-message-types reftest to fail.

 gtk/gtkimage.c |   23 ++++++++++++++++++++---
 gtk/gtklabel.c |   22 +++++++++++++++-------
 2 files changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index f806cc9..115920b 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -1514,6 +1514,25 @@ get_animation_frame (GtkImage *image)
 }
 
 static void
+gtk_image_get_padding_and_border (GtkImage  *image,
+                                  GtkBorder *border)
+{
+  GtkStyleContext *context;
+  GtkStateFlags state;
+  GtkBorder tmp;
+
+  context = gtk_widget_get_style_context (GTK_WIDGET (image));
+  state = gtk_widget_get_state_flags (GTK_WIDGET (image));
+
+  gtk_style_context_get_padding (context, state, border);
+  gtk_style_context_get_border (context, state, &tmp);
+  border->top += tmp.top;
+  border->right += tmp.right;
+  border->bottom += tmp.bottom;
+  border->left += tmp.left;
+}
+
+static void
 gtk_image_get_preferred_size (GtkImage *image,
                               gint     *width_out,
                               gint     *height_out)
@@ -1522,11 +1541,9 @@ gtk_image_get_preferred_size (GtkImage *image,
   gint width, height;
   GtkBorder border;
   GtkStyleContext *context;
-  GtkStateFlags state;
 
   context = gtk_widget_get_style_context (GTK_WIDGET (image));
-  state = gtk_widget_get_state_flags (GTK_WIDGET (image));
-  gtk_style_context_get_border (context, state, &border);
+  gtk_image_get_padding_and_border (image, &border);
   _gtk_icon_helper_get_size (priv->icon_helper, context, &width, &height);
 
   width += border.left + border.right;
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 68c23d3..9bcf856 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3220,14 +3220,22 @@ gtk_label_get_measuring_layout (GtkLabel *   label,
 }
 
 static void
-gtk_label_get_border (GtkLabel *label, GtkBorder *border)
+gtk_label_get_padding_and_border (GtkLabel  *label,
+                                  GtkBorder *border)
 {
   GtkStyleContext *context;
   GtkStateFlags state;
+  GtkBorder tmp;
 
   context = gtk_widget_get_style_context (GTK_WIDGET (label));
   state = gtk_widget_get_state_flags (GTK_WIDGET (label));
-  gtk_style_context_get_border (context, state, border);
+
+  gtk_style_context_get_padding (context, state, border);
+  gtk_style_context_get_border (context, state, &tmp);
+  border->top += tmp.top;
+  border->right += tmp.right;
+  border->bottom += tmp.bottom;
+  border->left += tmp.left;
 }
 
 static void
@@ -3244,7 +3252,7 @@ gtk_label_update_layout_width (GtkLabel *label)
       PangoRectangle logical;
       gint width, height;
 
-      gtk_label_get_border (label, &border);
+      gtk_label_get_padding_and_border (label, &border);
 
       width = gtk_widget_get_allocated_width (GTK_WIDGET (label)) - border.left - border.right;
       height = gtk_widget_get_allocated_height (GTK_WIDGET (label)) - border.top - border.bottom;
@@ -3661,7 +3669,7 @@ gtk_label_get_preferred_size (GtkWidget      *widget,
   smallest_rect.width  = PANGO_PIXELS_CEIL (smallest_rect.width);
   smallest_rect.height = PANGO_PIXELS_CEIL (smallest_rect.height);
 
-  gtk_label_get_border (label, &border);
+  gtk_label_get_padding_and_border (label, &border);
 
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
@@ -3765,7 +3773,7 @@ gtk_label_get_preferred_width_for_height (GtkWidget *widget,
     {
       GtkBorder border;
 
-      gtk_label_get_border (label, &border);
+      gtk_label_get_padding_and_border (label, &border);
 
       if (priv->wrap)
         gtk_label_clear_layout (label);
@@ -3800,7 +3808,7 @@ gtk_label_get_preferred_height_and_baseline_for_width (GtkWidget *widget,
     {
       GtkBorder border;
 
-      gtk_label_get_border (label, &border);
+      gtk_label_get_padding_and_border (label, &border);
 
       if (priv->wrap)
         gtk_label_clear_layout (label);
@@ -3998,7 +4006,7 @@ get_layout_location (GtkLabel  *label,
   widget = GTK_WIDGET (label);
   priv   = label->priv;
 
-  gtk_label_get_border (label, &border);
+  gtk_label_get_padding_and_border (label, &border);
 
   xalign = halign_to_float (widget);
   yalign = valign_to_float (widget);


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