[goffice] Canvas: track parent changes for style changes.



commit b1270e660520d3699b7eae0e2295cb6b8a0c2fae
Author: Morten Welinder <terra gnome org>
Date:   Tue Mar 26 09:02:40 2013 -0400

    Canvas: track parent changes for style changes.

 ChangeLog                 |    5 ++++
 goffice/canvas/goc-item.c |   48 ++++++++++++++++++++++++++++++++------------
 2 files changed, 40 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7414ca0..35282d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-03-26  Morten Welinder  <terra gnome org>
+
+       * goffice/canvas/goc-item.c (goc_item_get_style_context): Track
+       parent changes.
+
 2013-03-25  Jean Brefort  <jean brefort normalesup org>
 
        * goffice/canvas/goc-item.c (goc_item_draw),
diff --git a/goffice/canvas/goc-item.c b/goffice/canvas/goc-item.c
index 24ae44c..0bb3c06 100644
--- a/goffice/canvas/goc-item.c
+++ b/goffice/canvas/goc-item.c
@@ -835,6 +835,36 @@ _goc_item_transform (GocItem const *item, cairo_t *cr, gboolean scaled)
 }
 
 #ifdef GOFFICE_WITH_GTK
+
+static void
+cb_parent_changed (const GocItem *item)
+{
+       GtkStyleContext *context = goc_item_get_style_context (item);
+       GtkStyleContext *pcontext;
+       GtkWidgetPath *path;
+
+       if (item->parent) {
+               pcontext = goc_item_get_style_context (GOC_ITEM (item->parent));
+       } else if (item->canvas &&
+                  GOC_ITEM (item->canvas->root) == item) {
+               pcontext = gtk_widget_get_style_context (GTK_WIDGET (item->canvas));
+       } else {
+               pcontext = NULL;
+       }
+       if (pcontext)
+               path = gtk_widget_path_copy (gtk_style_context_get_path (pcontext));
+       else
+               path = gtk_widget_path_new ();
+
+       gtk_widget_path_append_type (path, G_TYPE_FROM_INSTANCE (item));
+       gtk_style_context_set_path (context, path);
+       gtk_widget_path_free (path);
+#ifdef HAVE_GTK_STYLE_CONTEXT_SET_PARENT
+       gtk_style_context_set_parent (context, pcontext);
+#endif
+}
+
+
 /**
  * goc_item_get_style_context:
  * @item: #GocItem
@@ -849,24 +879,16 @@ goc_item_get_style_context (const GocItem *item)
 
        context = g_object_get_qdata (G_OBJECT (item), quark_style_context);
        if (!context) {
-               GtkWidgetPath *path;
-
-               path = gtk_widget_path_new ();
-               gtk_widget_path_append_type (path, GOC_TYPE_CANVAS);
-               gtk_widget_path_append_type (path,
-                                            G_TYPE_FROM_INSTANCE (item));
-
                context = gtk_style_context_new ();
-               gtk_style_context_set_path (context, path);
-#ifdef HAVE_GTK_STYLE_CONTEXT_SET_PARENT
-               gtk_style_context_set_parent (context,
-                                             gtk_widget_get_style_context (GTK_WIDGET (item->canvas)));
-#endif
-
                g_object_set_qdata_full (G_OBJECT (item),
                                         quark_style_context,
                                         context,
                                         g_object_unref);
+
+               g_signal_connect (G_OBJECT (item),
+                                 "notify::parent", G_CALLBACK (cb_parent_changed),
+                                 NULL);
+               cb_parent_changed (item);
        }
 
        return context;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]