diff options
author | Paolo Borelli <pborelli@gnome.org> | 2011-01-29 12:47:09 +0100 |
---|---|---|
committer | Paolo Borelli <pborelli@gnome.org> | 2011-01-29 13:13:42 +0100 |
commit | 001697a22a6e094ca37f4f6c230161b08dff5c20 (patch) | |
tree | f53e6b1f69c69c858dd5601b4234660bf54ecb91 /gtk | |
parent | 9e203417752584b923cf5baec8940836ff2c0bcb (diff) | |
download | gtk+-001697a22a6e094ca37f4f6c230161b08dff5c20.tar.gz |
Move the get_cursor_color in GtkStyleContext
Move the private get_cursor_color method belongs to StyleContext. Change
the api so that retrieving both primary and secondary color is possible.
I left the method private for now, though it should probably be public
as all the other getters.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkentry.c | 9 | ||||
-rw-r--r-- | gtk/gtkstyle.c | 57 | ||||
-rw-r--r-- | gtk/gtkstylecontext.c | 50 | ||||
-rw-r--r-- | gtk/gtkstylecontextprivate.h | 3 | ||||
-rw-r--r-- | gtk/gtktextdisplay.c | 7 | ||||
-rw-r--r-- | gtk/gtkwidgetprivate.h | 3 |
6 files changed, 66 insertions, 63 deletions
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index a54f821a10..f40df25c3b 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -66,7 +66,7 @@ #include "gtkiconfactory.h" #include "gtkicontheme.h" #include "gtkwidgetprivate.h" - +#include "gtkstylecontextprivate.h" /** * SECTION:gtkentry @@ -5805,6 +5805,7 @@ gtk_entry_draw_cursor (GtkEntry *entry, } else /* overwrite_mode */ { + GtkStyleContext *context; GdkRGBA cursor_color; GdkRectangle rect; gint x, y; @@ -5818,18 +5819,18 @@ gtk_entry_draw_cursor (GtkEntry *entry, rect.width = PANGO_PIXELS (cursor_rect.width); rect.height = PANGO_PIXELS (cursor_rect.height); - _gtk_widget_get_cursor_color (widget, &cursor_color); + context = gtk_widget_get_style_context (widget); + + _gtk_style_context_get_cursor_color (context, &cursor_color, NULL); gdk_cairo_set_source_rgba (cr, &cursor_color); gdk_cairo_rectangle (cr, &rect); cairo_fill (cr); if (!block_at_line_end) { - GtkStyleContext *context; GtkStateFlags state; GdkRGBA color; - context = gtk_widget_get_style_context (widget); state = gtk_widget_get_state_flags (widget); gtk_style_context_get_background_color (context, state, &color); diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c index a234a34d23..16dafc6f3a 100644 --- a/gtk/gtkstyle.c +++ b/gtk/gtkstyle.c @@ -42,7 +42,6 @@ #include "gtkspinner.h" #include "gtkborder.h" - /** * SECTION:gtkstyle * @Short_description: An object that hold style information for widgets @@ -3971,55 +3970,6 @@ gtk_paint_spinner (GtkStyle *style, cairo_restore (cr); } -static void -get_cursor_color (GtkStyleContext *context, - gboolean primary, - GdkRGBA *color) -{ - GdkColor *style_color; - - gtk_style_context_get_style (context, - primary ? "cursor-color" : "secondary-cursor-color", - &style_color, - NULL); - - if (style_color) - { - color->red = style_color->red / 65535; - color->green = style_color->green / 65535; - color->blue = style_color->blue / 65535; - color->alpha = 1; - - gdk_color_free (style_color); - } - else - { - gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color); - - if (!primary) - { - GdkRGBA bg; - - gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg); - - color->red = (color->red + bg.red) * 0.5; - color->green = (color->green + bg.green) * 0.5; - color->blue = (color->blue + bg.blue) * 0.5; - } - } -} - -void -_gtk_widget_get_cursor_color (GtkWidget *widget, - GdkRGBA *color) -{ - GtkStyleContext *context; - - context = gtk_widget_get_style_context (widget); - - get_cursor_color (context, TRUE, color); -} - /** * gtk_draw_insertion_cursor: * @widget: a #GtkWidget @@ -4050,7 +4000,8 @@ gtk_draw_insertion_cursor (GtkWidget *widget, gfloat cursor_aspect_ratio; gint offset; GtkStyleContext *context; - GdkRGBA color; + GdkRGBA primary_color; + GdkRGBA secondary_color; g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (cr != NULL); @@ -4059,8 +4010,8 @@ gtk_draw_insertion_cursor (GtkWidget *widget, context = gtk_widget_get_style_context (widget); - get_cursor_color (context, is_primary, &color); - gdk_cairo_set_source_rgba (cr, &color); + _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color); + gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color); /* When changing the shape or size of the cursor here, * propagate the changes to gtktextview.c:text_window_invalidate_cursors(). diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index c61964f243..7cd0dab1c1 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -3596,6 +3596,56 @@ gtk_style_context_get_font (GtkStyleContext *context, return NULL; } +static void +get_cursor_color (GtkStyleContext *context, + gboolean primary, + GdkRGBA *color) +{ + GdkColor *style_color; + + gtk_style_context_get_style (context, + primary ? "cursor-color" : "secondary-cursor-color", + &style_color, + NULL); + + if (style_color) + { + color->red = style_color->red / 65535; + color->green = style_color->green / 65535; + color->blue = style_color->blue / 65535; + color->alpha = 1; + + gdk_color_free (style_color); + } + else + { + gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color); + + if (!primary) + { + GdkRGBA bg; + + gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg); + + color->red = (color->red + bg.red) * 0.5; + color->green = (color->green + bg.green) * 0.5; + color->blue = (color->blue + bg.blue) * 0.5; + } + } +} + +void +_gtk_style_context_get_cursor_color (GtkStyleContext *context, + GdkRGBA *primary_color, + GdkRGBA *secondary_color) +{ + if (primary_color) + get_cursor_color (context, TRUE, primary_color); + + if (secondary_color) + get_cursor_color (context, FALSE, secondary_color); +} + /* Paint methods */ /** diff --git a/gtk/gtkstylecontextprivate.h b/gtk/gtkstylecontextprivate.h index de70308331..57db77e5cb 100644 --- a/gtk/gtkstylecontextprivate.h +++ b/gtk/gtkstylecontextprivate.h @@ -34,6 +34,9 @@ void _gtk_style_context_coalesce_animation_areas (GtkStyleContext *c GtkWidget *widget); gboolean _gtk_style_context_check_region_name (const gchar *str); +void _gtk_style_context_get_cursor_color (GtkStyleContext *context, + GdkRGBA *primary_color, + GdkRGBA *secondary_color); G_END_DECLS diff --git a/gtk/gtktextdisplay.c b/gtk/gtktextdisplay.c index a41f5b881a..383f52d1a9 100644 --- a/gtk/gtktextdisplay.c +++ b/gtk/gtktextdisplay.c @@ -78,6 +78,7 @@ #include "config.h" #include "gtktextdisplay.h" #include "gtkwidgetprivate.h" +#include "gtkstylecontextprivate.h" #include "gtkintl.h" /* DO NOT go putting private headers in here. This file should only @@ -783,9 +784,9 @@ render_para (GtkTextRenderer *text_renderer, GdkRGBA cursor_color; cairo_t *cr = text_renderer->cr; - /* we draw text using base color on filled cursor rectangle of cursor color - * (normally white on black) */ - _gtk_widget_get_cursor_color (text_renderer->widget, &cursor_color); + /* we draw text using base color on filled cursor rectangle of cursor color + * (normally white on black) */ + _gtk_style_context_get_cursor_color (context, &cursor_color, NULL); cursor_rect.x = x + line_display->x_offset + line_display->block_cursor.x; cursor_rect.y = y + line_display->block_cursor.y + line_display->top_margin; diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index b98e2c9b24..778fff2b35 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -93,9 +93,6 @@ gboolean _gtk_widget_get_translation_to_window (GtkWidget *widget, int *x, int *y); -void _gtk_widget_get_cursor_color (GtkWidget *widget, - GdkRGBA *color); - G_END_DECLS #endif /* __GTK_WIDGET_PRIVATE_H__ */ |