[gtk+/wip/css: 16/153] API: Add GtkStyleContext::parent
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css: 16/153] API: Add GtkStyleContext::parent
- Date: Sat, 7 Jan 2012 01:57:55 +0000 (UTC)
commit 6af7ca9682402fbc6d96f3af1a0b41bd1ca2fabe
Author: Benjamin Otte <otte redhat com>
Date: Thu Dec 29 12:30:25 2011 +0100
API: Add GtkStyleContext::parent
We need this for proper support of CSS inherit.
docs/reference/gtk/gtk3-sections.txt | 2 +
gtk/gtk.symbols | 2 +
gtk/gtkstylecontext.c | 88 +++++++++++++++++++++++++++++++++-
gtk/gtkstylecontext.h | 4 ++
4 files changed, 95 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 02e7ce5..110c29e 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -5680,6 +5680,7 @@ gtk_style_context_add_provider_for_screen
gtk_style_context_get
gtk_style_context_get_direction
gtk_style_context_get_junction_sides
+gtk_style_context_set_parent
gtk_style_context_get_path
gtk_style_context_get_property
gtk_style_context_get_screen
@@ -5712,6 +5713,7 @@ gtk_style_context_restore
gtk_style_context_save
gtk_style_context_set_direction
gtk_style_context_set_junction_sides
+gtk_style_context_set_parent
gtk_style_context_set_path
gtk_style_context_add_class
gtk_style_context_remove_class
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 2006c17..557948a 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2532,6 +2532,7 @@ gtk_style_context_get_font
gtk_style_context_get_junction_sides
gtk_style_context_get_margin
gtk_style_context_get_padding
+gtk_style_context_get_parent
gtk_style_context_get_path
gtk_style_context_get_property
gtk_style_context_get_screen
@@ -2563,6 +2564,7 @@ gtk_style_context_scroll_animations
gtk_style_context_set_background
gtk_style_context_set_direction
gtk_style_context_set_junction_sides
+gtk_style_context_set_parent
gtk_style_context_set_path
gtk_style_context_set_screen
gtk_style_context_set_state
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index f4bd0d0..21205c3 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -368,6 +368,7 @@ struct _GtkStyleContextPrivate
GList *providers;
GList *providers_last;
+ GtkStyleContext *parent;
GtkWidgetPath *widget_path;
GHashTable *style_data;
GSList *info_stack;
@@ -388,7 +389,8 @@ struct _GtkStyleContextPrivate
enum {
PROP_0,
PROP_SCREEN,
- PROP_DIRECTION
+ PROP_DIRECTION,
+ PROP_PARENT
};
enum {
@@ -450,6 +452,21 @@ gtk_style_context_class_init (GtkStyleContextClass *klass)
GTK_TYPE_TEXT_DIRECTION,
GTK_TEXT_DIR_LTR,
GTK_PARAM_READWRITE));
+ /**
+ * GtkStyleContext:parent:
+ *
+ * Sets or gets the style context's parent. See gtk_style_context_set_parent()
+ * for details.
+ *
+ * Since: 3.4
+ */
+ g_object_class_install_property (object_class,
+ PROP_PARENT,
+ g_param_spec_object ("parent",
+ P_("Parent"),
+ P_("The parent style context"),
+ GTK_TYPE_STYLE_CONTEXT,
+ GTK_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (GtkStyleContextPrivate));
}
@@ -807,6 +824,8 @@ gtk_style_context_finalize (GObject *object)
style_context = GTK_STYLE_CONTEXT (object);
priv = style_context->priv;
+ gtk_style_context_set_parent (style_context, NULL);
+
if (priv->widget_path)
gtk_widget_path_free (priv->widget_path);
@@ -849,6 +868,10 @@ gtk_style_context_impl_set_property (GObject *object,
gtk_style_context_set_direction (style_context,
g_value_get_enum (value));
break;
+ case PROP_PARENT:
+ gtk_style_context_set_parent (style_context,
+ g_value_get_object (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -875,6 +898,9 @@ gtk_style_context_impl_get_property (GObject *object,
case PROP_DIRECTION:
g_value_set_enum (value, priv->direction);
break;
+ case PROP_PARENT:
+ g_value_set_object (value, priv->parent);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1662,6 +1688,66 @@ gtk_style_context_get_path (GtkStyleContext *context)
}
/**
+ * gtk_style_context_set_parent:
+ * @context: a #GtkStyleContext
+ * @parent: (allow-none): the new parent or %NULL
+ *
+ * Sets the parent style context for @context. The parent style
+ * context is used to implement
+ * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance>
+ * inheritance</ulink> of properties.
+ *
+ * If you are using a #GtkStyleContext returned from
+ * gtk_widget_get_style_context(), the parent will be set for you.
+ *
+ * Since: 3.4
+ **/
+void
+gtk_style_context_set_parent (GtkStyleContext *context,
+ GtkStyleContext *parent)
+{
+ GtkStyleContextPrivate *priv;
+
+ g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+ g_return_if_fail (parent == NULL || GTK_IS_STYLE_CONTEXT (parent));
+
+ priv = context->priv;
+
+ if (priv->parent == parent)
+ return;
+
+ if (parent)
+ g_object_ref (parent);
+
+ if (priv->parent)
+ g_object_unref (priv->parent);
+
+ priv->parent = parent;
+
+ g_object_notify (G_OBJECT (context), "parent");
+ gtk_style_context_invalidate (context);
+}
+
+/**
+ * gtk_style_context_get_parent:
+ * @context: a #GtkStyleContext
+ *
+ * Gets the parent context set via gtk_style_context_set_parent().
+ * See that function for details.
+ *
+ * Returns: (transfer none): the parent context or %NULL
+ *
+ * Since: 3.4
+ **/
+GtkStyleContext *
+gtk_style_context_get_parent (GtkStyleContext *context)
+{
+ g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
+
+ return context->priv->parent;
+}
+
+/**
* gtk_style_context_save:
* @context: a #GtkStyleContext
*
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 0dfb476..afdeb7b 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -740,6 +740,10 @@ void gtk_style_context_set_path (GtkStyleContext *context,
GtkWidgetPath *path);
const GtkWidgetPath * gtk_style_context_get_path (GtkStyleContext *context);
+void gtk_style_context_set_parent (GtkStyleContext *context,
+ GtkStyleContext *parent);
+GtkStyleContext *gtk_style_context_get_parent (GtkStyleContext *context);
+
GList * gtk_style_context_list_classes (GtkStyleContext *context);
void gtk_style_context_add_class (GtkStyleContext *context,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]