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:
parent
9e20341775
commit
001697a22a
@ -66,7 +66,7 @@
|
|||||||
#include "gtkiconfactory.h"
|
#include "gtkiconfactory.h"
|
||||||
#include "gtkicontheme.h"
|
#include "gtkicontheme.h"
|
||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
|
#include "gtkstylecontextprivate.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:gtkentry
|
* SECTION:gtkentry
|
||||||
@ -5805,6 +5805,7 @@ gtk_entry_draw_cursor (GtkEntry *entry,
|
|||||||
}
|
}
|
||||||
else /* overwrite_mode */
|
else /* overwrite_mode */
|
||||||
{
|
{
|
||||||
|
GtkStyleContext *context;
|
||||||
GdkRGBA cursor_color;
|
GdkRGBA cursor_color;
|
||||||
GdkRectangle rect;
|
GdkRectangle rect;
|
||||||
gint x, y;
|
gint x, y;
|
||||||
@ -5818,18 +5819,18 @@ gtk_entry_draw_cursor (GtkEntry *entry,
|
|||||||
rect.width = PANGO_PIXELS (cursor_rect.width);
|
rect.width = PANGO_PIXELS (cursor_rect.width);
|
||||||
rect.height = PANGO_PIXELS (cursor_rect.height);
|
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_set_source_rgba (cr, &cursor_color);
|
||||||
gdk_cairo_rectangle (cr, &rect);
|
gdk_cairo_rectangle (cr, &rect);
|
||||||
cairo_fill (cr);
|
cairo_fill (cr);
|
||||||
|
|
||||||
if (!block_at_line_end)
|
if (!block_at_line_end)
|
||||||
{
|
{
|
||||||
GtkStyleContext *context;
|
|
||||||
GtkStateFlags state;
|
GtkStateFlags state;
|
||||||
GdkRGBA color;
|
GdkRGBA color;
|
||||||
|
|
||||||
context = gtk_widget_get_style_context (widget);
|
|
||||||
state = gtk_widget_get_state_flags (widget);
|
state = gtk_widget_get_state_flags (widget);
|
||||||
gtk_style_context_get_background_color (context, state, &color);
|
gtk_style_context_get_background_color (context, state, &color);
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@
|
|||||||
#include "gtkspinner.h"
|
#include "gtkspinner.h"
|
||||||
#include "gtkborder.h"
|
#include "gtkborder.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:gtkstyle
|
* SECTION:gtkstyle
|
||||||
* @Short_description: An object that hold style information for widgets
|
* @Short_description: An object that hold style information for widgets
|
||||||
@ -3971,55 +3970,6 @@ gtk_paint_spinner (GtkStyle *style,
|
|||||||
cairo_restore (cr);
|
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:
|
* gtk_draw_insertion_cursor:
|
||||||
* @widget: a #GtkWidget
|
* @widget: a #GtkWidget
|
||||||
@ -4050,7 +4000,8 @@ gtk_draw_insertion_cursor (GtkWidget *widget,
|
|||||||
gfloat cursor_aspect_ratio;
|
gfloat cursor_aspect_ratio;
|
||||||
gint offset;
|
gint offset;
|
||||||
GtkStyleContext *context;
|
GtkStyleContext *context;
|
||||||
GdkRGBA color;
|
GdkRGBA primary_color;
|
||||||
|
GdkRGBA secondary_color;
|
||||||
|
|
||||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||||
g_return_if_fail (cr != NULL);
|
g_return_if_fail (cr != NULL);
|
||||||
@ -4059,8 +4010,8 @@ gtk_draw_insertion_cursor (GtkWidget *widget,
|
|||||||
|
|
||||||
context = gtk_widget_get_style_context (widget);
|
context = gtk_widget_get_style_context (widget);
|
||||||
|
|
||||||
get_cursor_color (context, is_primary, &color);
|
_gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
|
||||||
gdk_cairo_set_source_rgba (cr, &color);
|
gdk_cairo_set_source_rgba (cr, is_primary ? &primary_color : &secondary_color);
|
||||||
|
|
||||||
/* When changing the shape or size of the cursor here,
|
/* When changing the shape or size of the cursor here,
|
||||||
* propagate the changes to gtktextview.c:text_window_invalidate_cursors().
|
* propagate the changes to gtktextview.c:text_window_invalidate_cursors().
|
||||||
|
@ -3596,6 +3596,56 @@ gtk_style_context_get_font (GtkStyleContext *context,
|
|||||||
return NULL;
|
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 */
|
/* Paint methods */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +34,9 @@ void _gtk_style_context_coalesce_animation_areas (GtkStyleContext *c
|
|||||||
GtkWidget *widget);
|
GtkWidget *widget);
|
||||||
gboolean _gtk_style_context_check_region_name (const gchar *str);
|
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
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gtktextdisplay.h"
|
#include "gtktextdisplay.h"
|
||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
|
#include "gtkstylecontextprivate.h"
|
||||||
#include "gtkintl.h"
|
#include "gtkintl.h"
|
||||||
|
|
||||||
/* DO NOT go putting private headers in here. This file should only
|
/* DO NOT go putting private headers in here. This file should only
|
||||||
@ -783,9 +784,9 @@ render_para (GtkTextRenderer *text_renderer,
|
|||||||
GdkRGBA cursor_color;
|
GdkRGBA cursor_color;
|
||||||
cairo_t *cr = text_renderer->cr;
|
cairo_t *cr = text_renderer->cr;
|
||||||
|
|
||||||
/* we draw text using base color on filled cursor rectangle of cursor color
|
/* we draw text using base color on filled cursor rectangle of cursor color
|
||||||
* (normally white on black) */
|
* (normally white on black) */
|
||||||
_gtk_widget_get_cursor_color (text_renderer->widget, &cursor_color);
|
_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.x = x + line_display->x_offset + line_display->block_cursor.x;
|
||||||
cursor_rect.y = y + line_display->block_cursor.y + line_display->top_margin;
|
cursor_rect.y = y + line_display->block_cursor.y + line_display->top_margin;
|
||||||
|
@ -93,9 +93,6 @@ gboolean _gtk_widget_get_translation_to_window (GtkWidget *widget,
|
|||||||
int *x,
|
int *x,
|
||||||
int *y);
|
int *y);
|
||||||
|
|
||||||
void _gtk_widget_get_cursor_color (GtkWidget *widget,
|
|
||||||
GdkRGBA *color);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GTK_WIDGET_PRIVATE_H__ */
|
#endif /* __GTK_WIDGET_PRIVATE_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user