[gtk+/gtk-2-24] spinbutton: paint an additional slice of background



commit 55642822fed69f1dd93e034065963f634a837d4b
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Jan 25 16:57:10 2013 -0500

    spinbutton: paint an additional slice of background
    
    Normally, the xthickness in the style maps to the space on the sides of
    the widget, to accommodate for its border - GtkEntry's text area
    background width is calculated as (allocation->width - 2 * xthickness),
    and the border is rendered in that area.
    GtkSpinButton has an additional panel for the buttons though, which will
    render the right-side (left-side for RTL) border itself, taking
    xthickness into account. This results in the xthickness for that side
    being applied twice, both to the spinbutton panel and to the entry's
    text area.
    Visually, a slice with no painted background can be seen in spinbuttons
    on the right side (left side when RTL) of the text area, where the
    border would be rendered by the entry, which looks bad.
    
    This patch makes GtkSpinButton render the same background of the entry
    in that slice, to compensate for the xthickness being allocated to the
    button panel instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683511

 gtk/gtkspinbutton.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 1bfa035..9f74f7a 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -766,7 +766,34 @@ gtk_spin_button_expose (GtkWidget      *widget,
 	  gtk_spin_button_draw_arrow (spin, &event->area, GTK_ARROW_DOWN);
 	}
       else
-	GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->expose_event (widget, event);
+        {
+          if (event->window == widget->window)
+            {
+              gint text_x, text_y, text_width, text_height, slice_x;
+
+              /* Since we reuse xthickness for the buttons panel on one side, and GtkEntry
+               * always sizes its background to (allocation->width - 2 * xthickness), we
+               * have to manually render the missing slice of the background on the panel
+               * side.
+               */
+              GTK_ENTRY_GET_CLASS (spin)->get_text_area_size (GTK_ENTRY (spin),
+                                                              &text_x, &text_y,
+                                                              &text_width, &text_height);
+
+              if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+                slice_x = text_x - widget->style->xthickness;
+              else
+                slice_x = text_x + text_width;
+
+              gtk_paint_flat_box (widget->style, widget->window,
+                                  gtk_widget_get_state (widget), GTK_SHADOW_NONE,
+                                  &event->area, widget, "entry_bg",
+                                  slice_x, text_y,
+                                  widget->style->xthickness, text_height);
+            }
+
+          GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->expose_event (widget, event);
+        }
     }
   
   return FALSE;



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