Port gtk_draw_insertion_cursor to GtkStyleContext
This commit is contained in:
@ -65,6 +65,7 @@
|
|||||||
#include "gtktooltip.h"
|
#include "gtktooltip.h"
|
||||||
#include "gtkiconfactory.h"
|
#include "gtkiconfactory.h"
|
||||||
#include "gtkicontheme.h"
|
#include "gtkicontheme.h"
|
||||||
|
#include "gtkwidgetprivate.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
131
gtk/gtkstyle.c
131
gtk/gtkstyle.c
@ -3971,102 +3971,58 @@ gtk_paint_spinner (GtkStyle *style,
|
|||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _CursorInfo CursorInfo;
|
|
||||||
|
|
||||||
struct _CursorInfo
|
|
||||||
{
|
|
||||||
GType for_type;
|
|
||||||
GdkColor primary;
|
|
||||||
GdkColor secondary;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cursor_info_free (gpointer data)
|
get_cursor_color (GtkWidget *widget,
|
||||||
{
|
gboolean primary,
|
||||||
g_slice_free (CursorInfo, data);
|
GdkColor *color)
|
||||||
}
|
|
||||||
|
|
||||||
static const GdkColor *
|
|
||||||
get_insertion_cursor_color (GtkWidget *widget,
|
|
||||||
gboolean is_primary)
|
|
||||||
{
|
|
||||||
CursorInfo *cursor_info;
|
|
||||||
GtkStyle *style;
|
|
||||||
GdkColor *cursor_color;
|
|
||||||
|
|
||||||
style = gtk_widget_get_style (widget);
|
|
||||||
|
|
||||||
cursor_info = g_object_get_data (G_OBJECT (style), "gtk-style-cursor-info");
|
|
||||||
if (!cursor_info)
|
|
||||||
{
|
|
||||||
cursor_info = g_slice_new (CursorInfo);
|
|
||||||
g_object_set_data_full (G_OBJECT (style), I_("gtk-style-cursor-info"),
|
|
||||||
cursor_info, cursor_info_free);
|
|
||||||
cursor_info->for_type = G_TYPE_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We have to keep track of the type because gtk_widget_style_get()
|
|
||||||
* can return different results when called on the same property and
|
|
||||||
* same style but for different widgets. :-(. That is,
|
|
||||||
* GtkEntry::cursor-color = "red" in a style will modify the cursor
|
|
||||||
* color for entries but not for text view.
|
|
||||||
*/
|
|
||||||
if (cursor_info->for_type != G_OBJECT_TYPE (widget))
|
|
||||||
{
|
|
||||||
cursor_info->for_type = G_OBJECT_TYPE (widget);
|
|
||||||
|
|
||||||
/* Cursors in text widgets are drawn only in NORMAL state,
|
|
||||||
* so we can use text[GTK_STATE_NORMAL] as text color here
|
|
||||||
*/
|
|
||||||
gtk_widget_style_get (widget, "cursor-color", &cursor_color, NULL);
|
|
||||||
if (cursor_color)
|
|
||||||
{
|
|
||||||
cursor_info->primary = *cursor_color;
|
|
||||||
gdk_color_free (cursor_color);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cursor_info->primary = style->text[GTK_STATE_NORMAL];
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_widget_style_get (widget, "secondary-cursor-color", &cursor_color, NULL);
|
|
||||||
if (cursor_color)
|
|
||||||
{
|
|
||||||
cursor_info->secondary = *cursor_color;
|
|
||||||
gdk_color_free (cursor_color);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* text_aa is the average of text and base colors,
|
|
||||||
* in usual black-on-white case it's grey. */
|
|
||||||
cursor_info->secondary = style->text_aa[GTK_STATE_NORMAL];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_primary)
|
|
||||||
return &cursor_info->primary;
|
|
||||||
else
|
|
||||||
return &cursor_info->secondary;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
_gtk_widget_get_cursor_color (GtkWidget *widget,
|
|
||||||
GdkColor *color)
|
|
||||||
{
|
{
|
||||||
|
GtkStyleContext *context;
|
||||||
GdkColor *style_color;
|
GdkColor *style_color;
|
||||||
|
|
||||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||||
g_return_if_fail (color != NULL);
|
g_return_if_fail (color != NULL);
|
||||||
|
|
||||||
gtk_widget_style_get (widget, "cursor-color", &style_color, NULL);
|
context = gtk_widget_get_style_context (widget);
|
||||||
|
|
||||||
|
gtk_style_context_get_style (context,
|
||||||
|
primary ? "cursor-color" : "secondary-cursor-color",
|
||||||
|
&style_color,
|
||||||
|
NULL);
|
||||||
|
|
||||||
if (style_color)
|
if (style_color)
|
||||||
{
|
{
|
||||||
*color = *style_color;
|
*color = *style_color;
|
||||||
gdk_color_free (style_color);
|
gdk_color_free (style_color);
|
||||||
}
|
}
|
||||||
|
else if (primary)
|
||||||
|
{
|
||||||
|
GdkRGBA fg;
|
||||||
|
|
||||||
|
gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &fg);
|
||||||
|
|
||||||
|
color->red = fg.red * 65535;
|
||||||
|
color->green = fg.green * 65535;
|
||||||
|
color->blue = fg.blue * 65535;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
*color = gtk_widget_get_style (widget)->text[GTK_STATE_NORMAL];
|
{
|
||||||
|
GdkRGBA fg;
|
||||||
|
GdkRGBA bg;
|
||||||
|
|
||||||
|
gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &fg);
|
||||||
|
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg);
|
||||||
|
|
||||||
|
color->red = (fg.red + bg.red) * 0.5 * 65535;
|
||||||
|
color->green = (fg.green + bg.green) * 0.5 * 65535;
|
||||||
|
color->blue = (fg.blue + bg.green) * 0.5 * 65535;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_gtk_widget_get_cursor_color (GtkWidget *widget,
|
||||||
|
GdkColor *color)
|
||||||
|
{
|
||||||
|
get_cursor_color (widget, TRUE, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4098,19 +4054,26 @@ gtk_draw_insertion_cursor (GtkWidget *widget,
|
|||||||
gint x, y;
|
gint x, y;
|
||||||
gfloat cursor_aspect_ratio;
|
gfloat cursor_aspect_ratio;
|
||||||
gint offset;
|
gint offset;
|
||||||
|
GtkStyleContext *context;
|
||||||
|
GdkColor 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);
|
||||||
g_return_if_fail (location != NULL);
|
g_return_if_fail (location != NULL);
|
||||||
g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
|
g_return_if_fail (direction != GTK_TEXT_DIR_NONE);
|
||||||
|
|
||||||
gdk_cairo_set_source_color (cr, get_insertion_cursor_color (widget, is_primary));
|
context = gtk_widget_get_style_context (widget);
|
||||||
|
|
||||||
|
get_cursor_color (widget, is_primary, &color);
|
||||||
|
gdk_cairo_set_source_color (cr, &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().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
gtk_widget_style_get (widget, "cursor-aspect-ratio", &cursor_aspect_ratio, NULL);
|
gtk_style_context_get_style (context,
|
||||||
|
"cursor-aspect-ratio", &cursor_aspect_ratio,
|
||||||
|
NULL);
|
||||||
|
|
||||||
stem_width = location->height * cursor_aspect_ratio + 1;
|
stem_width = location->height * cursor_aspect_ratio + 1;
|
||||||
arrow_width = stem_width + 1;
|
arrow_width = stem_width + 1;
|
||||||
|
@ -641,15 +641,12 @@ void _gtk_style_shade (const GdkColor *a,
|
|||||||
GdkColor *b,
|
GdkColor *b,
|
||||||
gdouble k);
|
gdouble k);
|
||||||
|
|
||||||
|
|
||||||
void gtk_draw_insertion_cursor (GtkWidget *widget,
|
void gtk_draw_insertion_cursor (GtkWidget *widget,
|
||||||
cairo_t *cr,
|
cairo_t *cr,
|
||||||
const GdkRectangle *location,
|
const GdkRectangle *location,
|
||||||
gboolean is_primary,
|
gboolean is_primary,
|
||||||
GtkTextDirection direction,
|
GtkTextDirection direction,
|
||||||
gboolean draw_arrow);
|
gboolean draw_arrow);
|
||||||
void _gtk_widget_get_cursor_color (GtkWidget *widget,
|
|
||||||
GdkColor *color);
|
|
||||||
|
|
||||||
gboolean gtk_style_has_context (GtkStyle *style);
|
gboolean gtk_style_has_context (GtkStyle *style);
|
||||||
|
|
||||||
|
@ -77,7 +77,9 @@
|
|||||||
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
|
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gtktextdisplay.h"
|
#include "gtktextdisplay.h"
|
||||||
|
#include "gtkwidgetprivate.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
|
||||||
* use the semi-public headers, as with gtktextview.c.
|
* use the semi-public headers, as with gtktextview.c.
|
||||||
*/
|
*/
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
@ -80,18 +80,21 @@ void _gtk_widget_set_height_request_needed (GtkWidget *widget,
|
|||||||
gboolean height_request_needed);
|
gboolean height_request_needed);
|
||||||
|
|
||||||
void _gtk_widget_override_size_request (GtkWidget *widget,
|
void _gtk_widget_override_size_request (GtkWidget *widget,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
int *old_width,
|
int *old_width,
|
||||||
int *old_height);
|
int *old_height);
|
||||||
void _gtk_widget_restore_size_request (GtkWidget *widget,
|
void _gtk_widget_restore_size_request (GtkWidget *widget,
|
||||||
int old_width,
|
int old_width,
|
||||||
int old_height);
|
int old_height);
|
||||||
|
|
||||||
gboolean _gtk_widget_get_translation_to_window (GtkWidget *widget,
|
gboolean _gtk_widget_get_translation_to_window (GtkWidget *widget,
|
||||||
GdkWindow *window,
|
GdkWindow *window,
|
||||||
int *x,
|
int *x,
|
||||||
int *y);
|
int *y);
|
||||||
|
|
||||||
|
void _gtk_widget_get_cursor_color (GtkWidget *widget,
|
||||||
|
GdkColor *color);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user