[gtk+/wip/cssvalue: 143/165] stylecontext: Listen to the new changed signal
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cssvalue: 143/165] stylecontext: Listen to the new changed signal
- Date: Fri, 13 Apr 2012 23:14:48 +0000 (UTC)
commit f319ca74b5d974492b285aa46ae3016a662c3e42
Author: Benjamin Otte <otte redhat com>
Date: Sun Apr 8 17:34:17 2012 +0200
stylecontext: Listen to the new changed signal
gtk/gtkcsstypes.c | 4 ++-
gtk/gtkcsstypesprivate.h | 3 +-
gtk/gtkstylecontext.c | 74 +++++++++++++++++++++++++++++++++++++---------
3 files changed, 65 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index e3519a0..f83880a 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -56,6 +56,7 @@ _gtk_css_change_for_sibling (GtkCssChange match)
{ GTK_CSS_CHANGE_NAME, GTK_CSS_CHANGE_SIBLING_NAME },
{ GTK_CSS_CHANGE_POSITION, GTK_CSS_CHANGE_SIBLING_POSITION },
{ GTK_CSS_CHANGE_STATE, GTK_CSS_CHANGE_SIBLING_STATE },
+ { GTK_CSS_CHANGE_SOURCE, 0 }
};
return gtk_css_change_translate (match, table, G_N_ELEMENTS (table));
@@ -72,7 +73,8 @@ _gtk_css_change_for_child (GtkCssChange match)
{ GTK_CSS_CHANGE_SIBLING_CLASS, GTK_CSS_CHANGE_PARENT_SIBLING_CLASS },
{ GTK_CSS_CHANGE_SIBLING_NAME, GTK_CSS_CHANGE_PARENT_SIBLING_NAME },
{ GTK_CSS_CHANGE_SIBLING_POSITION, GTK_CSS_CHANGE_PARENT_SIBLING_POSITION },
- { GTK_CSS_CHANGE_SIBLING_STATE, GTK_CSS_CHANGE_PARENT_SIBLING_STATE }
+ { GTK_CSS_CHANGE_SIBLING_STATE, GTK_CSS_CHANGE_PARENT_SIBLING_STATE },
+ { GTK_CSS_CHANGE_SOURCE, 0 },
};
return gtk_css_change_translate (match, table, G_N_ELEMENTS (table));
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 22c1546..8890a5c 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -43,9 +43,10 @@ typedef enum { /*< skip >*/
GTK_CSS_CHANGE_PARENT_SIBLING_POSITION = (1 << 14),
GTK_CSS_CHANGE_PARENT_SIBLING_STATE = (1 << 15),
/* add more */
+ GTK_CSS_CHANGE_SOURCE = (1 << 16)
} GtkCssChange;
-#define GTK_CSS_CHANGE_ANY ((1 << 16) - 1)
+#define GTK_CSS_CHANGE_ANY ((1 << 17) - 1)
#define GTK_CSS_CHANGE_ANY_SELF (GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_POSITION | GTK_CSS_CHANGE_STATE)
#define GTK_CSS_CHANGE_ANY_SIBLING (GTK_CSS_CHANGE_SIBLING_CLASS | GTK_CSS_CHANGE_SIBLING_NAME | \
GTK_CSS_CHANGE_SIBLING_POSITION | GTK_CSS_CHANGE_SIBLING_STATE)
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 2d8023c..de37c06 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -304,7 +304,7 @@
/* When these change we do a full restyling. Otherwise we try to figure out
* if we need to change things. */
-#define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS)
+#define GTK_STYLE_CONTEXT_RADICAL_CHANGE (GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_SOURCE)
/* When these change we don't clear the cache. This takes more memory but makes
* things go faster. */
#define GTK_STYLE_CONTEXT_CACHED_CHANGE (GTK_CSS_CHANGE_STATE)
@@ -601,6 +601,52 @@ style_data_free (StyleData *data)
}
static void
+gtk_style_context_cascade_changed (GtkStyleCascade *cascade,
+ GtkStyleContext *context)
+{
+ GtkStyleContextPrivate *priv = context->priv;
+
+ if (priv->widget)
+ _gtk_style_context_queue_invalidate (context, GTK_CSS_CHANGE_SOURCE);
+ else
+ gtk_style_context_invalidate (context);
+}
+
+static void
+gtk_style_context_set_cascade (GtkStyleContext *context,
+ GtkStyleCascade *cascade)
+{
+ GtkStyleContextPrivate *priv;
+
+ priv = context->priv;
+
+ if (priv->cascade == cascade)
+ return;
+
+ if (cascade)
+ {
+ g_object_ref (cascade);
+ g_signal_connect (cascade,
+ "-gtk-private-changed",
+ G_CALLBACK (gtk_style_context_cascade_changed),
+ context);
+ }
+
+ if (priv->cascade)
+ {
+ g_signal_handlers_disconnect_by_func (priv->cascade,
+ gtk_style_context_cascade_changed,
+ context);
+ g_object_unref (priv->cascade);
+ }
+
+ priv->cascade = cascade;
+
+ if (cascade)
+ gtk_style_context_cascade_changed (cascade, context);
+}
+
+static void
gtk_style_context_init (GtkStyleContext *style_context)
{
GtkStyleContextPrivate *priv;
@@ -618,13 +664,14 @@ gtk_style_context_init (GtkStyleContext *style_context)
priv->direction = GTK_TEXT_DIR_LTR;
priv->screen = gdk_screen_get_default ();
- priv->cascade = _gtk_style_cascade_get_for_screen (priv->screen);
- g_object_ref (priv->cascade);
priv->relevant_changes = GTK_CSS_CHANGE_ANY;
/* Create default info store */
info = style_info_new ();
priv->info_stack = g_slist_prepend (priv->info_stack, info);
+
+ gtk_style_context_set_cascade (style_context,
+ _gtk_style_cascade_get_for_screen (priv->screen));
}
static void
@@ -641,13 +688,13 @@ gtk_style_context_finalize (GObject *object)
gtk_style_context_set_parent (style_context, NULL);
+ gtk_style_context_set_cascade (style_context, NULL);
+
if (priv->widget_path)
gtk_widget_path_free (priv->widget_path);
g_hash_table_destroy (priv->style_data);
- g_object_unref (priv->cascade);
-
g_slist_free_full (priv->info_stack, (GDestroyNotify) style_info_free);
G_OBJECT_CLASS (gtk_style_context_parent_class)->finalize (object);
@@ -931,13 +978,14 @@ gtk_style_context_add_provider (GtkStyleContext *context,
new_cascade = _gtk_style_cascade_new ();
_gtk_style_cascade_set_parent (new_cascade, priv->cascade);
- g_object_unref (priv->cascade);
- priv->cascade = new_cascade;
+ _gtk_style_cascade_add_provider (new_cascade, provider, priority);
+ gtk_style_context_set_cascade (context, new_cascade);
+ g_object_unref (new_cascade);
+ }
+ else
+ {
+ _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
}
-
- _gtk_style_cascade_add_provider (priv->cascade, provider, priority);
-
- gtk_style_context_invalidate (context);
}
/**
@@ -2369,9 +2417,7 @@ gtk_style_context_set_screen (GtkStyleContext *context,
if (priv->cascade == _gtk_style_cascade_get_for_screen (priv->screen))
{
- g_object_unref (priv->cascade);
- priv->cascade = _gtk_style_cascade_get_for_screen (screen);
- g_object_ref (priv->cascade);
+ gtk_style_context_set_cascade (context, _gtk_style_cascade_get_for_screen (screen));
}
else
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]