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.
This commit is contained in:
Paolo Borelli 2011-01-29 12:47:09 +01:00
parent 9e20341775
commit 001697a22a
6 changed files with 66 additions and 63 deletions

View File

@ -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);

View File

@ -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().

View File

@ -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 */
/**

View File

@ -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

View File

@ -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;

View File

@ -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__ */