[Xfce4-commits] <gtk-xfce-engine:master> Render the spin buttons inside the entry part

Peter de Ridder noreply at xfce.org
Fri Feb 10 23:20:06 CET 2012


Updating branch refs/heads/master
         to 7c69418347c59383e9542fa4562cdf4019ca3672 (commit)
       from 82fb20dd2de8d56c5ee1539584751bebd4f583d7 (commit)

commit 7c69418347c59383e9542fa4562cdf4019ca3672
Author: Peter de Ridder <peter at xfce.org>
Date:   Mon Feb 6 21:58:48 2012 +0100

    Render the spin buttons inside the entry part
    
    Extended the entry part of the spin button and moved the spinner buttons
    inside. This gives more consistency with Gtk.

 gtk-2.0/xfce_theme_draw.c |   62 +++++-------
 gtk-3.0/xfce_engine.c     |  240 +++++----------------------------------------
 2 files changed, 52 insertions(+), 250 deletions(-)

diff --git a/gtk-2.0/xfce_theme_draw.c b/gtk-2.0/xfce_theme_draw.c
index e41dd33..56375c1 100644
--- a/gtk-2.0/xfce_theme_draw.c
+++ b/gtk-2.0/xfce_theme_draw.c
@@ -158,24 +158,28 @@ static void xfce_fill_background(GtkStyle * style, GdkWindow * window, GtkStateT
 {
     GradientType gradient_style = GRADIENT_VERTICAL;
     gfloat shade_start = 1.0, shade_end = 1.0;
-    gboolean draw_flat = FALSE;
+    gboolean draw_base = FALSE;
     cairo_t *cr;
 
     /* Spin buttons are a special case */
     if (widget && GTK_IS_SPIN_BUTTON (widget))
     {
-        if (DETAIL("spinbutton_up") || DETAIL("spinbutton_down"))
+        /* The entry part needs to be completed on the background */
+        if (DETAIL("spinbutton"))
         {
+            draw_base = TRUE;
+        }
+        else if (DETAIL("spinbutton_up") || DETAIL("spinbutton_down"))
+        {
+            /* Only draw the spinner buttons if you interact with them */
             if ((state_type != GTK_STATE_PRELIGHT) && (state_type != GTK_STATE_ACTIVE))
-            {
-                draw_flat = TRUE;
-            }
+                return;
         }
     }
 
     cr = ge_gdk_drawable_to_cairo(window, area);
 
-    if ((!draw_flat) && (XFCE_RC_STYLE(style->rc_style)->gradient))
+    if ((!draw_base) && (XFCE_RC_STYLE(style->rc_style)->gradient))
     {
         switch (XFCE_RC_STYLE(style->rc_style)->gradient_style)
         {
@@ -226,7 +230,7 @@ static void xfce_fill_background(GtkStyle * style, GdkWindow * window, GtkStateT
     }
     else
     {
-        gdk_cairo_set_source_color(cr, &style->bg[state_type]); 
+        gdk_cairo_set_source_color(cr, draw_base ? &style->base[state_type] : &style->bg[state_type]); 
         cairo_rectangle(cr, x, y, width, height);
         cairo_fill(cr);
     }
@@ -457,17 +461,27 @@ static void draw_shadow(GtkStyle * style, GdkWindow * window, GtkStateType state
     /* Spin buttons are a special case */
     if (widget && GTK_IS_SPIN_BUTTON (widget))
     {
-        /* GtkEntry doesn't provide the text area as frame size */
-        if (DETAIL("entry"))
+        /* The button part of the spin button is a separate window which isn't drawn correctly */
+        if (DETAIL("spinbutton"))
         {
             gint line_width = 0;
             gboolean interior_focus;
-            gdk_drawable_get_size (GTK_ENTRY(widget)->text_area, &width, NULL);
-            if (!gtk_widget_has_focus(widget))
+            if (gtk_widget_has_focus(widget))
                 gtk_widget_style_get(widget, "focus-line-width", &line_width, "interior-focus", &interior_focus, NULL);
             if (interior_focus)
                 line_width = 0;
-            width += (style->xthickness + line_width) * 2;
+
+            if (gtk_widget_get_direction(widget) != GTK_TEXT_DIR_RTL)
+            {
+                x -= widget->allocation.width - width;
+            }
+            width = widget->allocation.width;
+            if (line_width)
+                gtk_paint_focus(style, window, state_type, area, widget, detail, x, y, width, height);
+            x += line_width;
+            width -= 2 * line_width;
+            y += line_width;
+            height -= 2 * line_width;
         }
     }
 
@@ -1575,29 +1589,6 @@ static void draw_extension(GtkStyle * style, GdkWindow * window, GtkStateType st
     cairo_destroy(cr);
 }
 
-static void draw_focus(GtkStyle * style, GdkWindow * window, GtkStateType state_type, GdkRectangle * area, GtkWidget * widget, const gchar * detail, gint x, gint y, gint width, gint height)
-{
-    CHECK_ARGS;
-
-    /* Spin buttons are a special case */
-    if (widget && GTK_IS_SPIN_BUTTON (widget))
-    {
-        /* GtkEntry doesn't provide the text area as focus size */
-        if (DETAIL("entry"))
-        {
-            gint line_width = 0;
-            gboolean interior_focus;
-            gdk_drawable_get_size (GTK_ENTRY(widget)->text_area, &width, NULL);
-            gtk_widget_style_get (widget, "focus-line-width", &line_width, "interior-focus", &interior_focus, NULL);
-            if (interior_focus)
-                line_width = 0;
-            width += (style->xthickness + line_width) * 2;
-        }
-    }
-
-    parent_class->draw_focus(style, window, state_type, area, widget, detail, x, y, width, height);
-}
-
 static void draw_slider(GtkStyle * style, GdkWindow * window, GtkStateType state_type, GtkShadowType shadow_type, GdkRectangle * area, GtkWidget * widget, const gchar * detail, gint x, gint y, gint width, gint height, GtkOrientation orientation)
 {
     CHECK_ARGS;
@@ -1663,7 +1654,6 @@ static void xfce_style_class_init(XfceStyleClass * klass)
     style_class->draw_shadow_gap = draw_shadow_gap;
     style_class->draw_box_gap = draw_box_gap;
     style_class->draw_extension = draw_extension;
-    style_class->draw_focus = draw_focus;
     style_class->draw_slider = draw_slider;
     style_class->draw_handle = draw_handle;
 }
diff --git a/gtk-3.0/xfce_engine.c b/gtk-3.0/xfce_engine.c
index c8ce045..951bd77 100644
--- a/gtk-3.0/xfce_engine.c
+++ b/gtk-3.0/xfce_engine.c
@@ -373,8 +373,8 @@ static void render_line(GtkThemingEngine * engine, cairo_t * cr, gdouble x1, gdo
         thickness_light = xthick / 2;
         thickness_dark = xthick - thickness_light;
 
-	/* Compensation for the way x and y are caclculated */
-	x1 += 1 + thickness_dark - thickness_light;
+        /* Compensation for the way x and y are caclculated */
+        x1 += 1 + thickness_dark - thickness_light;
         y_2 += 1;
 
         cairo_set_line_width (cr, thickness_dark);
@@ -394,8 +394,8 @@ static void render_line(GtkThemingEngine * engine, cairo_t * cr, gdouble x1, gdo
         thickness_light = ythick / 2;
         thickness_dark = ythick - thickness_light;
 
-	/* Compensation for the way x and y are caclculated */
-	y_1 += 1 + thickness_dark - thickness_light;
+        /* Compensation for the way x and y are caclculated */
+        y_1 += 1 + thickness_dark - thickness_light;
         x2 += 1;
 
         cairo_set_line_width (cr, thickness_dark);
@@ -433,6 +433,12 @@ static void render_background(GtkThemingEngine * engine, cairo_t * cr, gdouble x
     xthick = border.left;
     ythick = border.top;
 
+    if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SPINBUTTON) && gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_BUTTON))
+    {
+        if (!(state & GTK_STATE_FLAG_ACTIVE) &&  !(state & GTK_STATE_FLAG_PRELIGHT))
+            return;
+    }
+
     cairo_save(cr);
     cairo_translate(cr, x, y);
 
@@ -482,7 +488,6 @@ static void render_frame(GtkThemingEngine * engine, cairo_t * cr, gdouble x, gdo
     GdkRGBA black = {0.0, 0.0, 0.0, 1.0}; /* black */
     gboolean smooth_edge;
     GtkBorder border;
-    GtkJunctionSides junction;
 
     state = gtk_theming_engine_get_state(engine);
     gtk_theming_engine_get(engine, state, GTK_STYLE_PROPERTY_BORDER_STYLE, &border_style, NULL);
@@ -499,204 +504,11 @@ static void render_frame(GtkThemingEngine * engine, cairo_t * cr, gdouble x, gdo
     ythick = border.top;
 
     /* Spin buttons are a special case */
-    if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SPINBUTTON))
+    if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SPINBUTTON) && gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_BUTTON))
     {
-        junction = gtk_theming_engine_get_junction_sides(engine);
-        if ((junction & GTK_JUNCTION_TOP) == GTK_JUNCTION_TOP || (junction & GTK_JUNCTION_BOTTOM) == GTK_JUNCTION_BOTTOM)
-        {
-            if (!(state & GTK_STATE_FLAG_ACTIVE))
-            {
-                border_style = GTK_BORDER_STYLE_OUTSET;
-            }
-
-            if (state == GTK_STATE_FLAG_NORMAL || state & GTK_STATE_FLAG_INSENSITIVE)
-            {
-                gtk_theming_engine_get_border_color(engine, state, &dark);
-            }
-            else
-            {
-                gtk_theming_engine_get_border_color(engine, GTK_STATE_FLAG_NORMAL, &dark);
-            }
-
-            y = floor(y);
-            height = ceil(height);
-
-            xt = MIN(xthick, width - 1);
-            yt = MIN(ythick, height - 1);
-
-            gtk_theming_engine_get(engine, state, XFCE_SMOOTH_EDGE, &smooth_edge, NULL);
-            color_dark2light_mid(&dark, &light, &mid);
-            if (smooth_edge)
-            {
-                if ((xt > 1) && (yt > 1))
-                {
-                    gdk_cairo_set_source_rgba(cr, &dark);
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        cairo_rectangle(cr, x - 2, y, 1, 1);
-                    }
-                    if ((junction & GTK_JUNCTION_BOTTOM) != GTK_JUNCTION_BOTTOM)
-                    {
-                        cairo_rectangle(cr, x - 2, y + height - 1, 1, 1);
-                    }
-                    cairo_fill(cr);
-
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        cairo_move_to(cr, x - 0.5, y + 1.5);
-                    }
-                    else
-                    {
-                        cairo_move_to(cr, x - 0.5, y + 0.5);
-                    }
-                    if ((junction & GTK_JUNCTION_BOTTOM) != GTK_JUNCTION_BOTTOM)
-                    {
-                        cairo_line_to(cr, x - 0.5, y + height - 1.5);
-                    }
-                    else
-                    {
-                        cairo_line_to(cr, x - 0.5, y + height - 0.5);
-                    }
-                    cairo_stroke(cr);
-
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        gdk_cairo_set_source_rgba(cr, &mid);
-                        cairo_rectangle(cr, x - 2, y + 1, 1, 1);
-                        cairo_fill(cr);
-                    }
-
-                    gdk_cairo_set_source_rgba(cr, &light);
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        cairo_move_to(cr, x - 1.5, y + 2.5);
-                    }
-                    else
-                    {
-                        cairo_move_to(cr, x - 1.5, y + 0.5);
-                    }
-                    if ((junction & GTK_JUNCTION_BOTTOM) != GTK_JUNCTION_BOTTOM)
-                    {
-                        cairo_line_to(cr, x - 1.5, y + height - 1.5);
-                    }
-                    else
-                    {
-                        cairo_line_to(cr, x - 1.5, y + height - 0.5);
-                    }
-                    cairo_stroke(cr);
-
-                    gdk_cairo_set_source_rgba(cr, &mid);
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        cairo_rectangle(cr, x - 1, y, 1, 1);
-                    }
-                    if ((junction & GTK_JUNCTION_BOTTOM) != GTK_JUNCTION_BOTTOM)
-                    {
-                        cairo_rectangle(cr, x - 1, y + height - 1, 1, 1);
-                    }
-                    cairo_fill(cr);
-                }
-                else if ((xt > 0) && (yt > 0))
-                {
-                    gdk_cairo_set_source_rgba(cr, &light);
-                    cairo_move_to(cr, x - 0.5, y + 0.5);
-                    cairo_line_to(cr, x - 0.5, y + height - 0.5);
-                    cairo_stroke(cr);
-
-                    gdk_cairo_set_source_rgba(cr, &mid);
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        cairo_rectangle(cr, x - 1, y, 1, 1);
-                    }
-                    if ((junction & GTK_JUNCTION_BOTTOM) != GTK_JUNCTION_BOTTOM)
-                    {
-                        cairo_rectangle(cr, x - 1, y + height - 1, 1, 1);
-                    }
-                    cairo_fill(cr);
-                }
-            }
-            else
-            {
-                if ((xt > 1) && (yt > 1))
-                {
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        gdk_cairo_set_source_rgba(cr, &dark);
-                        cairo_move_to(cr, x - 1.5, y + 0.5);
-                        cairo_line_to(cr, x - 0.5, y + 0.5);
-                        cairo_stroke(cr);
-                    }
-
-                    gdk_cairo_set_source_rgba(cr, &light);
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        cairo_move_to(cr, x - 0.5, y + 1.5);
-                    }
-                    else
-                    {
-                        cairo_move_to(cr, x - 0.5, y + 0.5);
-                    }
-                    cairo_line_to(cr, x - 0.5, y + height - 0.5);
-                    if ((junction & GTK_JUNCTION_BOTTOM) != GTK_JUNCTION_BOTTOM)
-                    {
-                        cairo_line_to(cr, x - 1.5, y + height - 0.5);
-                    }
-                    cairo_stroke(cr);
-
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        gdk_cairo_set_source_rgba(cr, &black);
-                        cairo_rectangle(cr, x - 2, y + 1, 1, 1);
-                        cairo_fill(cr);
-                    }
-
-                    gdk_cairo_set_source_rgba(cr, &dark);
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        cairo_move_to(cr, x - 1.5, y + 2.5);
-                    }
-                    else
-                    {
-                        cairo_move_to(cr, x - 1.5, y + 0.5);
-                    }
-                    if ((junction & GTK_JUNCTION_BOTTOM) != GTK_JUNCTION_BOTTOM)
-                    {
-                        cairo_line_to(cr, x - 1.5, y + height - 1.5);
-                    }
-                    else
-                    {
-                        cairo_line_to(cr, x - 1.5, y + height - 0.5);
-                    }
-                    cairo_stroke(cr);
-                }
-                else if ((xt > 0) && (yt > 0))
-                {
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        gdk_cairo_set_source_rgba(cr, &dark);
-                        cairo_rectangle(cr, x - 1, y, 1, 1);
-                        cairo_fill(cr);
-                    }
-
-                    gdk_cairo_set_source_rgba(cr, &light);
-                    if ((junction & GTK_JUNCTION_TOP) != GTK_JUNCTION_TOP)
-                    {
-                        cairo_move_to(cr, x - 0.5, y + 1.5);
-                    }
-                    else
-                    {
-                        cairo_move_to(cr, x - 0.5, y + 0.5);
-                    }
-                    cairo_line_to(cr, x - 0.5, y + height - 0.5);
-                    cairo_stroke(cr);
-                }
-            }
-
-            if (state != GTK_STATE_FLAG_NORMAL && !(state & GTK_STATE_FLAG_INSENSITIVE))
-            {
-                gtk_theming_engine_get_border_color(engine, state, &dark);
-            }
-        }
+        /* Draw an outset border when hovering a spinner button */
+        if (!(state & GTK_STATE_FLAG_ACTIVE))
+            border_style = GTK_BORDER_STYLE_OUTSET;
     }
 
     xt = MIN(xthick, width - 1);
@@ -707,17 +519,17 @@ static void render_frame(GtkThemingEngine * engine, cairo_t * cr, gdouble x, gdo
         case GTK_BORDER_STYLE_NONE:
             break;
         case GTK_BORDER_STYLE_SOLID:
-	    gdk_cairo_set_source_rgba(cr, &dark);
+            gdk_cairo_set_source_rgba(cr, &dark);
             if ((xt > 1) && (yt > 1))
             {
-		cairo_set_line_width(cr, 2.0);
+                cairo_set_line_width(cr, 2.0);
                 cairo_rectangle(cr, x + 1, y + 1, width - 2, height - 2);
-	    }
+            }
             else if ((xt > 0) && (yt > 0))
             {
                 cairo_rectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1);
             }
-	    cairo_stroke(cr);
+            cairo_stroke(cr);
             break;
         case GTK_BORDER_STYLE_INSET:
             gtk_theming_engine_get(engine, state, XFCE_SMOOTH_EDGE, &smooth_edge, NULL);
@@ -788,7 +600,7 @@ static void render_frame(GtkThemingEngine * engine, cairo_t * cr, gdouble x, gdo
             {
                 if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_TROUGH))
                 {
-		    gtk_theming_engine_get_border_color(engine, GTK_STATE_FLAG_ACTIVE, &dark);
+                    gtk_theming_engine_get_border_color(engine, GTK_STATE_FLAG_ACTIVE, &dark);
                     gdk_cairo_set_source_rgba(cr, &dark);
                     cairo_rectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1);
                     cairo_stroke(cr);
@@ -841,17 +653,17 @@ static void render_frame(GtkThemingEngine * engine, cairo_t * cr, gdouble x, gdo
             if (smooth_edge)
             {
                 if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SPINBUTTON) && !(state & GTK_STATE_FLAG_PRELIGHT))
-		{
+                {
                     /* Do nothing */
-		}
-		else if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_PROGRESSBAR))
+                }
+                else if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_PROGRESSBAR))
                 {
                     gdk_cairo_set_source_rgba(cr, &dark);
                     cairo_rectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1);
                     cairo_stroke(cr);
 
-		    gtk_theming_engine_get_border_color(engine, GTK_STATE_FLAG_NORMAL, &dark);
-		    color_dark2light_mid(&dark, &light, &mid);
+                    gtk_theming_engine_get_border_color(engine, GTK_STATE_FLAG_NORMAL, &dark);
+                    color_dark2light_mid(&dark, &light, &mid);
 
                     gdk_cairo_set_source_rgba(cr, &mid);
                     cairo_rectangle(cr, x, y, 1, 1);
@@ -1069,9 +881,9 @@ static void render_frame(GtkThemingEngine * engine, cairo_t * cr, gdouble x, gdo
             else
             {
                 if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_SPINBUTTON) && !(state & GTK_STATE_FLAG_PRELIGHT))
-		{
+                {
                     /* Do nothing */
-		}
+                }
                 else if (gtk_theming_engine_has_class(engine, GTK_STYLE_CLASS_MENUBAR))
                 {
                     if ((xt > 1) && (yt > 1))


More information about the Xfce4-commits mailing list