summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-08-27 23:55:29 +0200
committerDebarshi Ray <debarshir@gnome.org>2015-08-28 18:35:23 +0200
commit7e0dd4b15ea80673f62249ac092763b10fc226ad (patch)
tree82bd73e0b9effffe49e71c8884c3e601d50adc93
parent8af0b5d665b309c455b7d337f36e258f253bd599 (diff)
downloadlibgd-7e0dd4b15ea80673f62249ac092763b10fc226ad.tar.gz
GdTaggedEntryTag: Use entry's style context
Reuse the entry's style context via save()/restore() instead of creating a new style context all the time. Solves a bunch of styling problems, such as value inheritance.
-rw-r--r--libgd/gd-tagged-entry.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/libgd/gd-tagged-entry.c b/libgd/gd-tagged-entry.c
index 82baed4..35c481d 100644
--- a/libgd/gd-tagged-entry.c
+++ b/libgd/gd-tagged-entry.c
@@ -95,7 +95,7 @@ gd_tagged_entry_tag_get_margin (GdTaggedEntryTag *tag,
context = gd_tagged_entry_tag_get_context (tag, entry);
gtk_style_context_get_margin (context, 0, margin);
- g_object_unref (context);
+ gtk_style_context_restore (context);
}
static void
@@ -238,19 +238,17 @@ gd_tagged_entry_tag_get_context (GdTaggedEntryTag *tag,
GdTaggedEntry *entry)
{
GtkWidget *widget = GTK_WIDGET (entry);
- GtkWidgetPath *path;
- gint pos;
GtkStyleContext *retval;
+ GList *l, *list;
- retval = gtk_style_context_new ();
- path = gtk_widget_path_copy (gtk_widget_get_path (widget));
-
- pos = gtk_widget_path_append_type (path, GD_TYPE_TAGGED_ENTRY);
- gtk_widget_path_iter_add_class (path, pos, tag->priv->style);
+ retval = gtk_widget_get_style_context (widget);
+ gtk_style_context_save (retval);
- gtk_style_context_set_path (retval, path);
-
- gtk_widget_path_unref (path);
+ list = gtk_style_context_list_classes (retval);
+ for (l = list; l; l = l->next)
+ gtk_style_context_remove_class (retval, l->data);
+ g_list_free (list);
+ gtk_style_context_add_class (retval, tag->priv->style);
return retval;
}
@@ -278,7 +276,7 @@ gd_tagged_entry_tag_get_width (GdTaggedEntryTag *tag,
gd_tagged_entry_tag_ensure_close_surface (tag, context);
- g_object_unref (context);
+ gtk_style_context_restore (context);
button_width = 0;
if (entry->priv->button_visible && tag->priv->has_close_button)
@@ -393,7 +391,7 @@ gd_tagged_entry_tag_event_is_button (GdTaggedEntryTag *tag,
context = gd_tagged_entry_tag_get_context (tag, entry);
gd_tagged_entry_tag_get_relative_allocations (tag, entry, context, NULL, NULL, &button_allocation);
- g_object_unref (context);
+ gtk_style_context_restore (context);
/* see if the event falls into the button allocation */
if ((event_x >= button_allocation.x &&
@@ -497,9 +495,9 @@ gd_tagged_entry_tag_draw (GdTaggedEntryTag *tag,
button_allocation.x, button_allocation.y);
done:
- cairo_restore (cr);
+ gtk_style_context_restore (context);
- g_object_unref (context);
+ cairo_restore (cr);
}
static void