[gtksourceview] Port to the new GtkStyleContext API.
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Port to the new GtkStyleContext API.
- Date: Sun, 5 Dec 2010 11:46:47 +0000 (UTC)
commit 0a24b162187d904b2546eda973e08b43f2ffbcca
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Dec 4 21:30:16 2010 +0100
Port to the new GtkStyleContext API.
gtksourceview/gtksourcecompletion.c | 107 +++++++++-------
gtksourceview/gtksourcecompletioninfo.c | 32 +++---
gtksourceview/gtksourcegutterrenderertext.c | 20 +--
gtksourceview/gtksourcemarkcategory.c | 10 +-
gtksourceview/gtksourcemarkcategory.h | 4 +-
gtksourceview/gtksourcestylescheme.c | 185 ++++++++++-----------------
gtksourceview/gtksourcestylescheme.h | 2 +-
gtksourceview/gtksourceview.c | 85 +++++++-----
tests/test-widget.c | 10 +-
9 files changed, 215 insertions(+), 240 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 47718aa..637f50d 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -1175,24 +1175,24 @@ update_column_sizes (GtkSourceCompletion *completion)
gint cwidth;
GtkTreeView *tv;
GtkAllocation allocation;
- gint xpad;
- gint separator;
- GtkStyle *style;
gint icon_width;
gint icon_height;
/* Resize tree view columns accordingly */
if (completion->priv->num_accelerators > 0)
{
+ GtkStyleContext *context;
+ gint xpad;
+ gint separator;
+
g_object_get (completion->priv->cell_renderer_accelerator,
"xpad", &xpad,
NULL);
- style = gtk_widget_get_style (completion->priv->tree_view_proposals);
- gtk_style_get (style,
- GTK_TYPE_TREE_VIEW,
- "horizontal-separator", &separator,
- NULL);
+ context = gtk_widget_get_style_context (completion->priv->tree_view_proposals);
+ gtk_style_context_get_style (context,
+ "horizontal-separator", &separator,
+ NULL);
cwidth = measure_accelerator_width (completion->priv->tree_view_proposals);
cwidth += (xpad + separator) * 2;
@@ -2616,17 +2616,22 @@ render_proposal_icon_func (GtkTreeViewColumn *column,
{
gboolean isheader;
GdkPixbuf *icon;
- GtkStyle *style;
isheader = gtk_source_completion_model_iter_is_header (completion->priv->model_proposals,
iter);
- style = gtk_widget_get_style (GTK_WIDGET (completion->priv->tree_view_proposals));
-
if (isheader)
{
+ GtkStyleContext *context;
+ GdkRGBA color;
+
+ context = gtk_widget_get_style_context (completion->priv->tree_view_proposals);
+ gtk_style_context_get_background_color (context,
+ GTK_STATE_FLAG_INSENSITIVE,
+ &color);
+
g_object_set (cell,
- "cell-background-gdk", &(style->bg[GTK_STATE_INSENSITIVE]),
+ "cell-background-rgba", &color,
NULL);
}
else
@@ -2661,7 +2666,6 @@ render_proposal_text_func (GtkTreeViewColumn *column,
gchar *markup;
GtkSourceCompletionProvider *provider;
gboolean isheader;
- GtkStyle *style;
isheader = gtk_source_completion_model_iter_is_header (completion->priv->model_proposals,
iter);
@@ -2669,6 +2673,9 @@ render_proposal_text_func (GtkTreeViewColumn *column,
if (isheader)
{
gchar *name;
+ GtkStyleContext *context;
+ GdkRGBA color;
+ GdkRGBA bgcolor;
gtk_tree_model_get (model,
iter,
@@ -2690,15 +2697,20 @@ render_proposal_text_func (GtkTreeViewColumn *column,
label = g_strdup_printf ("<b>%s</b>", _("Provider"));
}
- style = gtk_widget_get_style (GTK_WIDGET (completion->priv->tree_view_proposals));
-
+ context = gtk_widget_get_style_context (completion->priv->tree_view_proposals);
+ gtk_style_context_get_color (context,
+ GTK_STATE_FLAG_INSENSITIVE,
+ &color);
+ gtk_style_context_get_background_color (context,
+ GTK_STATE_FLAG_INSENSITIVE,
+ &bgcolor);
g_object_set (cell,
"markup", label,
- "cell-background-gdk", &(style->bg[GTK_STATE_INSENSITIVE]),
- "foreground-gdk", &(style->fg[GTK_STATE_INSENSITIVE]),
+ "foreground-rgba", &color,
+ "cell-background-rgba", &bgcolor,
NULL);
- g_free (label);
+ g_free (label);
g_object_unref (provider);
}
else
@@ -2766,33 +2778,43 @@ render_proposal_accelerator_func (GtkTreeViewColumn *column,
GtkTreeIter *iter,
GtkSourceCompletion *completion)
{
- GtkStyle *style;
gboolean isheader;
+ GtkStyleContext *context;
+ GdkRGBA color;
isheader = gtk_source_completion_model_iter_is_header (completion->priv->model_proposals,
iter);
- style = gtk_widget_get_style (GTK_WIDGET (completion->priv->tree_view_proposals));
+ context = gtk_widget_get_style_context (completion->priv->tree_view_proposals);
if (isheader)
{
+ gtk_style_context_get_background_color (context,
+ GTK_STATE_FLAG_INSENSITIVE,
+ &color);
+
g_object_set (cell,
- "cell-background-gdk", &(style->bg[GTK_STATE_INSENSITIVE]),
+ "cell-background-rgba", &color,
"text", NULL,
NULL);
}
else
{
+ gtk_style_context_get_color (context,
+ GTK_STATE_FLAG_INSENSITIVE,
+ &color);
+
gint accel = iter_accelerator (completion, iter);
gchar *text = NULL;
if (accel != -1)
{
- text = g_strdup_printf ("<small><b>%d</b></small>", accel == 9 ? 0 : accel + 1);
+ text = g_strdup_printf ("<small><b>%d</b></small>",
+ accel == 9 ? 0 : accel + 1);
}
g_object_set (cell,
- "foreground-gdk", &(style->fg[GTK_STATE_INSENSITIVE]),
+ "foreground-rgba", &color,
"cell-background-set", FALSE,
"markup", text,
NULL);
@@ -2830,37 +2852,28 @@ on_providers_changed (GtkSourceCompletionModel *model,
}
static void
-info_button_style_set (GtkWidget *button,
- GtkStyle *previous_style,
- GtkSourceCompletion *completion)
+info_button_style_updated (GtkWidget *button,
+ GtkSourceCompletion *completion)
{
+ GtkStyleContext *context;
gint spacing;
GtkSettings *settings;
gboolean show_image;
- gtk_style_get (gtk_widget_get_style (button),
- GTK_TYPE_BUTTON,
- "image-spacing",
- &spacing,
- NULL);
+ context = gtk_widget_get_style_context (button);
- gtk_box_set_spacing (GTK_BOX (completion->priv->hbox_info),
- spacing);
+ gtk_style_context_get_style (context,
+ "image-spacing", &spacing,
+ NULL);
+
+ gtk_box_set_spacing (GTK_BOX (completion->priv->hbox_info), spacing);
settings = gtk_widget_get_settings (button);
g_object_get (settings,
- "gtk-button-images",
- &show_image,
+ "gtk-button-images", &show_image,
NULL);
- if (show_image)
- {
- gtk_widget_show (completion->priv->image_info);
- }
- else
- {
- gtk_widget_hide (completion->priv->image_info);
- }
+ gtk_widget_set_visible (completion->priv->image_info, show_image);
}
static void
@@ -2940,9 +2953,7 @@ initialize_ui (GtkSourceCompletion *completion)
GTK_WIDGET (gtk_builder_get_object (builder,
"hbox_info"));
- info_button_style_set (completion->priv->info_button,
- NULL,
- completion);
+ info_button_style_updated (completion->priv->info_button, completion);
/* Tree view and model */
completion->priv->model_proposals = gtk_source_completion_model_new ();
@@ -3040,8 +3051,8 @@ initialize_ui (GtkSourceCompletion *completion)
completion);
g_signal_connect (toggle_button_info,
- "style-set",
- G_CALLBACK (info_button_style_set),
+ "style-updated",
+ G_CALLBACK (info_button_style_updated),
completion);
g_object_unref (builder);
diff --git a/gtksourceview/gtksourcecompletioninfo.c b/gtksourceview/gtksourcecompletioninfo.c
index 6c127c6..20120f6 100644
--- a/gtksourceview/gtksourcecompletioninfo.c
+++ b/gtksourceview/gtksourcecompletioninfo.c
@@ -110,19 +110,24 @@ get_scrolled_window_sizing (GtkSourceCompletionInfo *info,
static void
window_resize (GtkSourceCompletionInfo *info)
{
- GtkRequisition req;
gint width;
gint height;
- gint off;
- gint border;
- gint hscroll;
- gint vscroll;
- GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (info));
gtk_window_get_default_size (GTK_WINDOW (info), &width, &height);
if (info->priv->widget != NULL)
{
+ GtkStyleContext *context;
+ GtkBorder *pad;
+ GtkRequisition req;
+ gint off;
+ gint border;
+ gint hscroll;
+ gint vscroll;
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (info));
+ gtk_style_context_get (context, 0, "padding", &pad, NULL);
+
/* Try to resize to fit widget, if necessary */
gtk_widget_get_preferred_size (info->priv->widget,
&req, NULL);
@@ -134,11 +139,11 @@ window_resize (GtkSourceCompletionInfo *info)
{
if (info->priv->max_height == -1)
{
- height = req.height + style->ythickness * 2;
+ height = req.height + pad->top + pad->bottom;
}
else
{
- height = MIN (req.height + style->ythickness * 2, info->priv->max_height);
+ height = MIN (req.height + pad->top + pad->bottom, info->priv->max_height);
}
height += off + hscroll;
@@ -148,11 +153,11 @@ window_resize (GtkSourceCompletionInfo *info)
{
if (info->priv->max_width == -1)
{
- width = req.width + style->xthickness * 2;
+ width = req.width + pad->left + pad->right;
}
else
{
- width = MIN (req.width + style->xthickness * 2, info->priv->max_width);
+ width = MIN (req.width + pad->left + pad->right, info->priv->max_width);
}
width += off + vscroll;
@@ -170,7 +175,6 @@ gtk_source_completion_info_init (GtkSourceCompletionInfo *info)
/* Tooltip style */
gtk_window_set_title (GTK_WINDOW (info), _("Completion Info"));
gtk_widget_set_name (GTK_WIDGET (info), "gtk-tooltip");
- gtk_widget_ensure_style (GTK_WIDGET (info));
gtk_window_set_type_hint (GTK_WINDOW (info),
GDK_WINDOW_TYPE_HINT_NORMAL);
@@ -285,12 +289,8 @@ gtk_source_completion_info_draw (GtkWidget *widget,
{
GTK_WIDGET_CLASS (gtk_source_completion_info_parent_class)->draw (widget, cr);
- gtk_paint_shadow (gtk_widget_get_style (widget),
+ gtk_render_frame (gtk_widget_get_style_context (widget),
cr,
- GTK_STATE_NORMAL,
- GTK_SHADOW_OUT,
- widget,
- NULL,
0, 0,
gtk_widget_get_allocated_width (widget),
gtk_widget_get_allocated_height (widget));
diff --git a/gtksourceview/gtksourcegutterrenderertext.c b/gtksourceview/gtksourcegutterrenderertext.c
index a36ef40..d730d52 100644
--- a/gtksourceview/gtksourcegutterrenderertext.c
+++ b/gtksourceview/gtksourcegutterrenderertext.c
@@ -29,14 +29,14 @@ create_layout (GtkSourceGutterRendererText *renderer,
{
PangoLayout *layout;
PangoAttribute *attr;
- GdkColor color;
- GtkStyle *style;
+ GtkStyleContext *context;
+ GdkRGBA color;
PangoAttrList *attr_list;
layout = gtk_widget_create_pango_layout (widget, NULL);
- style = gtk_widget_get_style (widget);
- color = style->fg[GTK_STATE_NORMAL];
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (context, 0, &color);
attr = pango_attr_foreground_new (color.red, color.green, color.blue);
@@ -107,6 +107,7 @@ gutter_renderer_text_draw (GtkSourceGutterRenderer *renderer,
GtkTextView *view;
gint x = 0;
gint y = 0;
+ GtkStyleContext *context;
/* Chain up to draw background */
GTK_SOURCE_GUTTER_RENDERER_CLASS (
@@ -188,15 +189,8 @@ gutter_renderer_text_draw (GtkSourceGutterRenderer *renderer,
break;
}
- gtk_paint_layout (gtk_widget_get_style (GTK_WIDGET (view)),
- cr,
- gtk_widget_get_state (GTK_WIDGET (view)),
- TRUE,
- GTK_WIDGET (view),
- "gtksourcegutterrenderertext",
- x,
- y,
- text->priv->cached_layout);
+ context = gtk_widget_get_style_context (GTK_WIDGET (view));
+ gtk_render_layout (context, cr, x, y, text->priv->cached_layout);
}
static void
diff --git a/gtksourceview/gtksourcemarkcategory.c b/gtksourceview/gtksourcemarkcategory.c
index 1caaa77..d716c02 100644
--- a/gtksourceview/gtksourcemarkcategory.c
+++ b/gtksourceview/gtksourcemarkcategory.c
@@ -29,7 +29,7 @@
struct _GtkSourceMarkCategoryPrivate
{
gchar *id;
- GdkColor background;
+ GdkRGBA background;
gint priority;
GtkSourcePixbufHelper *helper;
@@ -73,7 +73,7 @@ gtk_source_mark_category_finalize (GObject *object)
static void
set_background (GtkSourceMarkCategory *category,
- const GdkColor *color)
+ const GdkRGBA *color)
{
if (color)
{
@@ -293,7 +293,7 @@ gtk_source_mark_category_class_init (GtkSourceMarkCategoryClass *klass)
g_param_spec_boxed ("background",
_("Background"),
_("The background"),
- GDK_TYPE_COLOR,
+ GDK_TYPE_RGBA,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
@@ -397,7 +397,7 @@ gtk_source_mark_category_get_id (GtkSourceMarkCategory *category)
void
gtk_source_mark_category_set_background (GtkSourceMarkCategory *category,
- const GdkColor *background)
+ const GdkRGBA *background)
{
g_return_if_fail (GTK_IS_SOURCE_MARK_CATEGORY (category));
@@ -406,7 +406,7 @@ gtk_source_mark_category_set_background (GtkSourceMarkCategory *category,
gboolean
gtk_source_mark_category_get_background (GtkSourceMarkCategory *category,
- GdkColor *background)
+ GdkRGBA *background)
{
g_return_val_if_fail (GTK_IS_SOURCE_MARK_CATEGORY (category), FALSE);
diff --git a/gtksourceview/gtksourcemarkcategory.h b/gtksourceview/gtksourcemarkcategory.h
index 1249f9f..5daa9a6 100644
--- a/gtksourceview/gtksourcemarkcategory.h
+++ b/gtksourceview/gtksourcemarkcategory.h
@@ -64,10 +64,10 @@ GtkSourceMarkCategory *gtk_source_mark_category_new (const gchar *id);
const gchar *gtk_source_mark_category_get_id (GtkSourceMarkCategory *category);
void gtk_source_mark_category_set_background (GtkSourceMarkCategory *category,
- const GdkColor *background);
+ const GdkRGBA *background);
gboolean gtk_source_mark_category_get_background (GtkSourceMarkCategory *category,
- GdkColor *background);
+ GdkRGBA *background);
void gtk_source_mark_category_set_priority (GtkSourceMarkCategory *category,
gint priority);
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index 088faa1..8937e61 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -369,7 +369,7 @@ _gtk_source_style_scheme_new (const gchar *id,
* @name: color name to find.
*
* Returns: color which corresponds to @name in the @scheme.
- * Returned value is actual color string suitable for gdk_color_parse().
+ * Returned value is actual color string suitable for gdk_rgba_parse().
* It may be @name or part of @name so copy it or something, if you need
* it to stay around.
*
@@ -385,14 +385,20 @@ get_color_by_name (GtkSourceStyleScheme *scheme,
if (name[0] == '#')
{
- GdkColor dummy;
+ GdkRGBA dummy;
- if (gdk_color_parse (name + 1, &dummy))
+ if (gdk_rgba_parse (&dummy, name + 1))
+ {
color = name + 1;
- else if (gdk_color_parse (name, &dummy))
+ }
+ else if (gdk_rgba_parse (&dummy, name))
+ {
color = name;
+ }
else
+ {
g_warning ("could not parse color '%s'", name);
+ }
}
else
{
@@ -554,35 +560,35 @@ _gtk_source_style_scheme_get_draw_spaces_style (GtkSourceStyleScheme *scheme)
static gboolean
get_color (GtkSourceStyle *style,
gboolean foreground,
- GdkColor *dest)
+ GdkRGBA *dest)
{
const gchar *color;
guint mask;
- if (style == NULL)
- return FALSE;
-
- if (foreground)
- {
- color = style->foreground;
- mask = GTK_SOURCE_STYLE_USE_FOREGROUND;
- }
- else
- {
- color = style->background;
- mask = GTK_SOURCE_STYLE_USE_BACKGROUND;
- }
-
- if (style->mask & mask)
+ if (style != NULL)
{
- if (color == NULL || !gdk_color_parse (color, dest))
+ if (foreground)
{
- g_warning ("%s: invalid color '%s'", G_STRLOC,
- color != NULL ? color : "(null)");
- return FALSE;
+ color = style->foreground;
+ mask = GTK_SOURCE_STYLE_USE_FOREGROUND;
+ }
+ else
+ {
+ color = style->background;
+ mask = GTK_SOURCE_STYLE_USE_BACKGROUND;
}
- return TRUE;
+ if (style->mask & mask)
+ {
+ if (color == NULL || !gdk_rgba_parse (dest, color))
+ {
+ g_warning ("%s: invalid color '%s'", G_STRLOC,
+ color != NULL ? color : "(null)");
+ return FALSE;
+ }
+
+ return TRUE;
+ }
}
return FALSE;
@@ -593,7 +599,7 @@ get_color (GtkSourceStyle *style,
*/
gboolean
_gtk_source_style_scheme_get_current_line_color (GtkSourceStyleScheme *scheme,
- GdkColor *color)
+ GdkRGBA *color)
{
GtkSourceStyle *style;
@@ -608,100 +614,51 @@ _gtk_source_style_scheme_get_current_line_color (GtkSourceStyleScheme *scheme,
static void
set_text_style (GtkWidget *widget,
GtkSourceStyle *style,
- GtkStateType state)
+ GtkStateFlags state)
{
- GdkColor color;
- GdkColor *color_ptr;
+ GdkRGBA color;
+ GdkRGBA *color_ptr;
if (get_color (style, FALSE, &color))
color_ptr = &color;
else
color_ptr = NULL;
- gtk_widget_modify_base (widget, state, color_ptr);
+ g_print ("BG color: %s\n", gdk_rgba_to_string (color_ptr));
+
+ gtk_widget_override_background_color (widget, state, color_ptr);
if (get_color (style, TRUE, &color))
color_ptr = &color;
else
color_ptr = NULL;
- gtk_widget_modify_text (widget, state, color_ptr);
+ g_print ("FG color: %s\n", gdk_rgba_to_string (color_ptr));
+
+ gtk_widget_override_color (widget, state, color_ptr);
}
static void
set_line_numbers_style (GtkWidget *widget,
GtkSourceStyle *style)
{
- gint i;
- GdkColor *fg_ptr = NULL;
- GdkColor *bg_ptr = NULL;
- GdkColor fg;
- GdkColor bg;
+ GdkRGBA *fg_ptr = NULL;
+ GdkRGBA *bg_ptr = NULL;
+ GdkRGBA fg;
+ GdkRGBA bg;
+ GtkStateFlags flags;
if (get_color (style, TRUE, &fg))
fg_ptr = &fg;
+
if (get_color (style, FALSE, &bg))
bg_ptr = &bg;
- for (i = 0; i < 5; ++i)
- {
- gtk_widget_modify_fg (widget, i, fg_ptr);
- gtk_widget_modify_bg (widget, i, bg_ptr);
- }
-}
-
-static void
-set_cursor_colors (GtkWidget *widget,
- const GdkColor *primary,
- const GdkColor *secondary)
-{
-#if !GTK_CHECK_VERSION(2,11,3)
- char *rc_string;
- char *widget_name;
-
- widget_name = g_strdup_printf ("gtk-source-view-%p", (gpointer) widget);
-
- rc_string = g_strdup_printf (
- "style \"%p\"\n"
- "{\n"
- " GtkWidget::cursor-color = \"#%02x%02x%02x\"\n"
- " GtkWidget::secondary-cursor-color = \"#%02x%02x%02x\"\n"
- "}\n"
- "widget \"*.%s\" style \"%p\"\n",
- (gpointer) widget,
- primary->red >> 8, primary->green >> 8, primary->blue >> 8,
- secondary->red >> 8, secondary->green >> 8, secondary->blue >> 8,
- widget_name,
- (gpointer) widget
- );
-
- gtk_rc_parse_string (rc_string);
-
- if (strcmp (widget_name, gtk_widget_get_name (widget)) != 0)
- gtk_widget_set_name (widget, widget_name);
-
- g_object_set_data (G_OBJECT (widget),
- "gtk-source-view-cursor-color-set",
- GINT_TO_POINTER (TRUE));
-
- g_free (rc_string);
- g_free (widget_name);
-#else
- gtk_widget_modify_cursor (widget, primary, secondary);
-#endif
-}
+ /* Override the color no matter what the state is */
+ flags = ~0;
-static void
-unset_cursor_colors (GtkWidget *widget)
-{
-#if !GTK_CHECK_VERSION(2,11,3)
- if (g_object_get_data (G_OBJECT (widget), "gtk-source-view-cursor-color-set") != NULL)
- set_cursor_colors (widget,
- &widget->style->text[GTK_STATE_NORMAL],
- &widget->style->text_aa[GTK_STATE_NORMAL]);
-#else
- gtk_widget_modify_cursor (widget, NULL, NULL);
-#endif
+ gtk_widget_override_color (widget, flags, fg_ptr);
+ gtk_widget_override_background_color (widget, flags, bg_ptr);
}
static void
@@ -709,8 +666,10 @@ update_cursor_colors (GtkWidget *widget,
GtkSourceStyle *style_primary,
GtkSourceStyle *style_secondary)
{
- GdkColor primary_color, secondary_color;
- GdkColor *primary = NULL, *secondary = NULL;
+ GdkRGBA primary_color;
+ GdkRGBA secondary_color;
+ GdkRGBA *primary = NULL;
+ GdkRGBA *secondary = NULL;
if (get_color (style_primary, TRUE, &primary_color))
primary = &primary_color;
@@ -720,17 +679,17 @@ update_cursor_colors (GtkWidget *widget,
if (primary != NULL && secondary == NULL)
{
- secondary_color = gtk_widget_get_style (widget)->base[GTK_STATE_NORMAL];
- secondary_color.red = ((gint) secondary_color.red + primary->red) / 2;
- secondary_color.green = ((gint) secondary_color.green + primary->green) / 2;
- secondary_color.blue = ((gint) secondary_color.blue + primary->blue) / 2;
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_background_color (context, 0, &secondary_color);
secondary = &secondary_color;
}
if (primary != NULL)
- set_cursor_colors (widget, primary, secondary);
+ gtk_widget_override_cursor (widget, primary, secondary);
else
- unset_cursor_colors (widget);
+ gtk_widget_override_cursor (widget, NULL, NULL);
}
/**
@@ -753,20 +712,19 @@ _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
{
GtkSourceStyle *style, *style2;
- gtk_widget_ensure_style (widget);
-
style = gtk_source_style_scheme_get_style (scheme, STYLE_TEXT);
- set_text_style (widget, style, GTK_STATE_NORMAL);
- set_text_style (widget, style, GTK_STATE_PRELIGHT);
- set_text_style (widget, style, GTK_STATE_INSENSITIVE);
+ set_text_style (widget, style, 0);
+ set_text_style (widget,
+ style,
+ GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_INSENSITIVE);
style = gtk_source_style_scheme_get_style (scheme, STYLE_SELECTED);
- set_text_style (widget, style, GTK_STATE_SELECTED);
+ set_text_style (widget, style, GTK_STATE_FLAG_SELECTED);
style2 = gtk_source_style_scheme_get_style (scheme, STYLE_SELECTED_UNFOCUSED);
if (style2 == NULL)
style2 = style;
- set_text_style (widget, style2, GTK_STATE_ACTIVE);
+ set_text_style (widget, style2, GTK_STATE_FLAG_ACTIVE);
style = gtk_source_style_scheme_get_style (scheme, STYLE_LINE_NUMBERS);
set_line_numbers_style (widget, style);
@@ -777,13 +735,10 @@ _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
}
else
{
- set_text_style (widget, NULL, GTK_STATE_NORMAL);
- set_text_style (widget, NULL, GTK_STATE_ACTIVE);
- set_text_style (widget, NULL, GTK_STATE_PRELIGHT);
- set_text_style (widget, NULL, GTK_STATE_INSENSITIVE);
- set_text_style (widget, NULL, GTK_STATE_SELECTED);
+ /* reset */
+ set_text_style (widget, NULL, ~0);
set_line_numbers_style (widget, NULL);
- unset_cursor_colors (widget);
+ gtk_widget_override_cursor (widget, NULL, NULL);
}
}
diff --git a/gtksourceview/gtksourcestylescheme.h b/gtksourceview/gtksourcestylescheme.h
index 816d0f7..4ba8dfc 100644
--- a/gtksourceview/gtksourcestylescheme.h
+++ b/gtksourceview/gtksourcestylescheme.h
@@ -86,7 +86,7 @@ GtkSourceStyle *_gtk_source_style_scheme_get_draw_spaces_style
(GtkSourceStyleScheme *scheme);
gboolean _gtk_source_style_scheme_get_current_line_color
(GtkSourceStyleScheme *scheme,
- GdkColor *color);
+ GdkRGBA *color);
G_END_DECLS
#endif /* __GTK_SOURCE_STYLE_SCHEME_H__ */
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 79bfc7c..434cb41 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -137,11 +137,11 @@ struct _GtkSourceViewPrivate
gboolean style_scheme_applied;
GtkSourceStyleScheme *style_scheme;
- GdkColor *right_margin_line_color;
- GdkColor *right_margin_overlay_color;
+ GdkRGBA *right_margin_line_color;
+ GdkRGBA *right_margin_overlay_color;
GtkSourceDrawSpacesFlags draw_spaces;
- GdkColor *spaces_color;
+ GdkRGBA *spaces_color;
GHashTable *mark_categories;
@@ -153,7 +153,7 @@ struct _GtkSourceViewPrivate
GtkSourceGutterRenderer *line_renderer;
GtkSourceGutterRenderer *marks_renderer;
- GdkColor current_line_color;
+ GdkRGBA current_line_color;
GtkSourceCompletion *completion;
@@ -1083,17 +1083,17 @@ gtk_source_view_finalize (GObject *object)
if (view->priv->right_margin_line_color != NULL)
{
- gdk_color_free (view->priv->right_margin_line_color);
+ gdk_rgba_free (view->priv->right_margin_line_color);
}
if (view->priv->right_margin_overlay_color != NULL)
{
- gdk_color_free (view->priv->right_margin_overlay_color);
+ gdk_rgba_free (view->priv->right_margin_overlay_color);
}
if (view->priv->spaces_color != NULL)
{
- gdk_color_free (view->priv->spaces_color);
+ gdk_rgba_free (view->priv->spaces_color);
}
if (view->priv->mark_categories)
@@ -1767,7 +1767,7 @@ gtk_source_view_paint_line_background (GtkTextView *text_view,
cairo_t *cr,
int y, /* in buffer coordinates */
int height,
- const GdkColor *color)
+ const GdkRGBA *color)
{
GdkRectangle visible_rect;
GdkRectangle line_rect;
@@ -1803,7 +1803,7 @@ gtk_source_view_paint_line_background (GtkTextView *text_view,
line_rect.x += MAX (0, margin - 1);
- gdk_cairo_set_source_color (cr, (GdkColor *)color);
+ gdk_cairo_set_source_rgba (cr, (GdkRGBA *)color);
cairo_set_line_width (cr, 1);
cairo_rectangle (cr, line_rect.x + .5, line_rect.y + .5,
line_rect.width - 1, line_rect.height - 1);
@@ -1889,7 +1889,7 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
{
gint line_to_paint;
GSList *marks;
- GdkColor background;
+ GdkRGBA background;
int priority;
line_to_paint = g_array_index (numbers, gint, i);
@@ -1904,7 +1904,7 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
{
GtkSourceMarkCategory *cat;
gint prio;
- GdkColor bg;
+ GdkRGBA bg;
cat = gtk_source_view_get_mark_category (view,
gtk_source_mark_get_category (marks->data));
@@ -2419,7 +2419,6 @@ gtk_source_view_draw (GtkWidget *widget,
{
GtkTextIter cur;
gint y, height;
- GdkColor *color;
GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
gtk_text_buffer_get_iter_at_mark (buffer,
@@ -2429,17 +2428,26 @@ gtk_source_view_draw (GtkWidget *widget,
if (view->priv->current_line_color_set)
{
- color = &view->priv->current_line_color;
+ gtk_source_view_paint_line_background (text_view,
+ cr,
+ y, height,
+ &view->priv->current_line_color);
}
else
{
- GtkStyle *style = gtk_widget_get_style (widget);
- GtkStateType state = gtk_widget_get_state (widget);
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GdkRGBA color;
- color = &style->bg[state];
- }
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+ gtk_style_context_get_color (context, state, &color);
- gtk_source_view_paint_line_background (text_view, cr, y, height, color);
+ gtk_source_view_paint_line_background (text_view,
+ cr,
+ y, height,
+ &color);
+ }
}
if (gtk_cairo_should_draw_window (cr, window))
@@ -2708,8 +2716,6 @@ gtk_source_view_set_tab_width (GtkSourceView *view,
if (view->priv->tab_width == width)
return;
- gtk_widget_ensure_style (GTK_WIDGET (view));
-
save_width = view->priv->tab_width;
view->priv->tab_width = width;
if (set_tab_stops_internal (view))
@@ -3985,13 +3991,13 @@ update_right_margin_colors (GtkSourceView *view)
if (view->priv->right_margin_line_color != NULL)
{
- gdk_color_free (view->priv->right_margin_line_color);
+ gdk_rgba_free (view->priv->right_margin_line_color);
view->priv->right_margin_line_color = NULL;
}
if (view->priv->right_margin_overlay_color != NULL)
{
- gdk_color_free (view->priv->right_margin_overlay_color);
+ gdk_rgba_free (view->priv->right_margin_overlay_color);
view->priv->right_margin_overlay_color = NULL;
}
@@ -4005,16 +4011,16 @@ update_right_margin_colors (GtkSourceView *view)
{
gchar *color_str = NULL;
gboolean color_set;
- GdkColor color;
+ GdkRGBA color;
g_object_get (style,
"foreground-set", &color_set,
"foreground", &color_str,
NULL);
- if (color_set && (color_str != NULL) && gdk_color_parse (color_str, &color))
+ if (color_set && (color_str != NULL) && gdk_rgba_parse (&color, color_str))
{
- view->priv->right_margin_line_color = gdk_color_copy (&color);
+ view->priv->right_margin_line_color = gdk_rgba_copy (&color);
}
g_free (color_str);
@@ -4025,9 +4031,9 @@ update_right_margin_colors (GtkSourceView *view)
"background", &color_str,
NULL);
- if (color_set && (color_str != NULL) && gdk_color_parse (color_str, &color))
+ if (color_set && (color_str != NULL) && gdk_rgba_parse (&color, color_str))
{
- view->priv->right_margin_overlay_color = gdk_color_copy (&color);
+ view->priv->right_margin_overlay_color = gdk_rgba_copy (&color);
}
g_free (color_str);
@@ -4036,9 +4042,13 @@ update_right_margin_colors (GtkSourceView *view)
if (view->priv->right_margin_line_color == NULL)
{
- GtkStyle *style = gtk_widget_get_style (widget);
+ GtkStyleContext *context;
+ GdkRGBA color;
+
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (context, 0, &color);
- view->priv->right_margin_line_color = gdk_color_copy (&style->text[GTK_STATE_NORMAL]);
+ view->priv->right_margin_line_color = gdk_rgba_copy (&color);
}
}
@@ -4052,7 +4062,7 @@ update_spaces_color (GtkSourceView *view)
if (view->priv->spaces_color != NULL)
{
- gdk_color_free (view->priv->spaces_color);
+ gdk_rgba_free (view->priv->spaces_color);
view->priv->spaces_color = NULL;
}
@@ -4065,15 +4075,15 @@ update_spaces_color (GtkSourceView *view)
if (style != NULL)
{
gchar *color_str = NULL;
- GdkColor color;
+ GdkRGBA color;
g_object_get (style,
"foreground", &color_str,
NULL);
- if (color_str != NULL && gdk_color_parse (color_str, &color))
+ if (color_str != NULL && gdk_rgba_parse (&color, color_str))
{
- view->priv->spaces_color = gdk_color_copy (&color);
+ view->priv->spaces_color = gdk_rgba_copy (&color);
}
g_free (color_str);
@@ -4082,9 +4092,12 @@ update_spaces_color (GtkSourceView *view)
if (view->priv->spaces_color == NULL)
{
- GtkStyle *style = gtk_widget_get_style (widget);
+ GtkStyleContext *context;
- view->priv->spaces_color = gdk_color_copy (&style->text[GTK_STATE_INSENSITIVE]);
+ context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (context,
+ GTK_STATE_FLAG_INSENSITIVE,
+ view->priv->right_margin_line_color);
}
}
@@ -4136,7 +4149,9 @@ gtk_source_view_update_style_scheme (GtkSourceView *view)
view->priv->style_scheme_applied = TRUE;
}
else
+ {
view->priv->style_scheme_applied = FALSE;
+ }
}
}
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 0511edc..53f980c 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -1307,10 +1307,10 @@ mark_tooltip_func (GtkSourceMarkCategory *category,
static void
add_source_mark_pixbufs (GtkSourceView *view)
{
- GdkColor color;
+ GdkRGBA color;
GtkSourceMarkCategory *cat;
- gdk_color_parse ("lightgreen", &color);
+ gdk_rgba_parse (&color, "lightgreen");
cat = gtk_source_view_get_mark_category (view, MARK_TYPE_1);
@@ -1323,7 +1323,7 @@ add_source_mark_pixbufs (GtkSourceView *view)
G_CALLBACK (mark_tooltip_func),
view);
- gdk_color_parse ("pink", &color);
+ gdk_rgba_parse (&color, "pink");
cat = gtk_source_view_get_mark_category (view, MARK_TYPE_2);
@@ -1423,10 +1423,10 @@ create_view_window (GtkSourceBuffer *buffer, GtkSourceView *from)
font_desc = pango_font_description_from_string ("monospace");
if (font_desc != NULL)
{
- gtk_widget_modify_font (view, font_desc);
+ gtk_widget_override_font (view, font_desc);
pango_font_description_free (font_desc);
}
-
+
/* change view attributes to match those of from */
if (from)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]