[gtk+] Make GtkHSV use GtkStyleContext
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Make GtkHSV use GtkStyleContext
- Date: Mon, 10 Jan 2011 02:53:17 +0000 (UTC)
commit 2f6514ce3415f42690180e09dd35054a16f57d2c
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Jan 10 02:37:26 2011 +0100
Make GtkHSV use GtkStyleContext
two custom classes replace the light/dark focus detail strings,
it doesn't make much sense to have a GTK_STYLE_CLASS_* for that.
gtk/gtkcssprovider.c | 8 +++++++
gtk/gtkhsv.c | 55 ++++++++++++++++++++++++++++++-------------------
2 files changed, 42 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 02c3fff..aba63af 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -3837,6 +3837,14 @@ gtk_css_provider_get_default (void)
" background-color: @selected_bg_color;\n"
" color: @selected_fg_color;\n"
"}\n"
+ "\n"
+ ".light-area-focus {\n"
+ " color: #000;\n"
+ "}\n"
+ "\n"
+ ".dark-area-focus {\n"
+ " color: #fff;\n"
+ "}\n"
"\n";
provider = gtk_css_provider_new ();
diff --git a/gtk/gtkhsv.c b/gtk/gtkhsv.c
index 507a03d..62356bc 100644
--- a/gtk/gtkhsv.c
+++ b/gtk/gtkhsv.c
@@ -253,8 +253,6 @@ gtk_hsv_realize (GtkWidget *widget)
priv->window = gdk_window_new (parent_window, &attr, attr_mask);
gdk_window_set_user_data (priv->window, hsv);
gdk_window_show (priv->window);
-
- gtk_widget_style_attach (widget);
}
static void
@@ -997,10 +995,11 @@ paint_triangle (GtkHSV *hsv,
gint x_start, x_end;
cairo_surface_t *source;
gdouble r, g, b;
- gchar *detail;
gint stride;
int width, height;
-
+ GtkStyleContext *context;
+ GtkStateFlags state;
+
priv = hsv->priv;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
@@ -1142,14 +1141,20 @@ paint_triangle (GtkHSV *hsv,
b = priv->v;
hsv_to_rgb (&r, &g, &b);
+ context = gtk_widget_get_style_context (widget);
+
+ gtk_style_context_save (context);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_set_state (context, state);
+
if (INTENSITY (r, g, b) > 0.5)
{
- detail = "colorwheel_light";
+ gtk_style_context_add_class (context, "light-area-focus");
cairo_set_source_rgb (cr, 0., 0., 0.);
}
else
{
- detail = "colorwheel_dark";
+ gtk_style_context_add_class (context, "dark-area-focus");
cairo_set_source_rgb (cr, 1., 1., 1.);
}
@@ -1173,15 +1178,14 @@ paint_triangle (GtkHSV *hsv,
"focus-padding", &focus_pad,
NULL);
- gtk_paint_focus (gtk_widget_get_style (widget),
- cr,
- gtk_widget_get_state (widget),
- widget, detail,
- xx - FOCUS_RADIUS - focus_width - focus_pad,
- yy - FOCUS_RADIUS - focus_width - focus_pad,
- 2 * (FOCUS_RADIUS + focus_width + focus_pad),
- 2 * (FOCUS_RADIUS + focus_width + focus_pad));
+ gtk_render_focus (context, cr,
+ xx - FOCUS_RADIUS - focus_width - focus_pad,
+ yy - FOCUS_RADIUS - focus_width - focus_pad,
+ 2 * (FOCUS_RADIUS + focus_width + focus_pad),
+ 2 * (FOCUS_RADIUS + focus_width + focus_pad));
}
+
+ gtk_style_context_restore (context);
}
/* Paints the contents of the HSV color selector */
@@ -1196,13 +1200,22 @@ gtk_hsv_draw (GtkWidget *widget,
paint_triangle (hsv, cr);
if (gtk_widget_has_focus (widget) && priv->focus_on_ring)
- gtk_paint_focus (gtk_widget_get_style (widget),
- cr,
- gtk_widget_get_state (widget),
- widget, NULL,
- 0, 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
+ {
+ GtkStyleContext *context;
+ GtkStateFlags state;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
+
+ gtk_render_focus (context, cr, 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
+ gtk_style_context_restore (context);
+ }
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]