[gtk+/nth-child: 2/33] API: Add gtk_widget_path_append_for_widget()



commit f016bfedf8006f6faf49d31c97d9f69266c3be1e
Author: Benjamin Otte <otte redhat com>
Date:   Wed May 25 20:42:27 2011 +0200

    API: Add gtk_widget_path_append_for_widget()
    
    Includes a bunch of header shuffling so we can use GtkWidget* in
    gtkwidgetpath.h

 gtk/gtkstyle.h      |    5 ---
 gtk/gtkwidget.c     |   70 +++++++++++++++++++++++++++++++++++---------------
 gtk/gtkwidgetpath.h |    7 +++++
 3 files changed, 56 insertions(+), 26 deletions(-)
---
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index 5396b26..e06f696 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -61,11 +61,6 @@ typedef gboolean (*GtkRcPropertyParser) (const GParamSpec *pspec,
 					 const GString    *rc_string,
 					 GValue           *property_value);
 
-/* We make this forward declaration here, since we pass
- * GtkWidget's to the draw functions.
- */
-typedef struct _GtkWidget      GtkWidget;
-
 /**
  * GTK_STYLE_ATTACHED:
  * @style: a #GtkStyle.
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index cece4de..7b2d4ef 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -14228,6 +14228,52 @@ _gtk_widget_get_sizegroups (GtkWidget    *widget)
 }
 
 /**
+ * gtk_widget_path_append_for_widget:
+ * @path: a widget path
+ * @widget: the widget to append to the widget path
+ *
+ * Appends the data from @widget to the widget hierarchy represented
+ * by @path. This function is a shortcut for adding information from
+ * @widget to the given @path. This includes setting the name or
+ * adding the style classes from @widget.
+ *
+ * Returns: the position where the data was inserted
+ *
+ * Since: 3.2
+ **/
+gint
+gtk_widget_path_append_for_widget (GtkWidgetPath *path,
+                                   GtkWidget     *widget)
+{
+  gint pos;
+
+  g_return_val_if_fail (path != NULL, 0);
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+  pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
+
+  if (widget->priv->name)
+    gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
+
+  if (widget->priv->context)
+    {
+      GList *classes, *l;
+
+      /* Also add any persistent classes in
+       * the style context the widget path
+       */
+      classes = gtk_style_context_list_classes (widget->priv->context);
+
+      for (l = classes; l; l = l->next)
+        gtk_widget_path_iter_add_class (path, pos, l->data);
+
+      g_list_free (classes);
+    }
+
+  return pos;
+}
+
+/**
  * gtk_widget_get_path:
  * @widget: a #GtkWidget
  *
@@ -14257,7 +14303,6 @@ gtk_widget_get_path (GtkWidget *widget)
   if (!widget->priv->path)
     {
       GtkWidget *parent;
-      guint pos;
 
       parent = widget->priv->parent;
 
@@ -14273,28 +14318,11 @@ gtk_widget_get_path (GtkWidget *widget)
           widget->priv->path = gtk_widget_path_new ();
         }
 
-      pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
-
-      if (widget->priv->name)
-        gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
+      gtk_widget_path_append_for_widget (widget->priv->path, widget);
 
       if (widget->priv->context)
-        {
-          GList *classes, *l;
-
-          /* Also add any persistent classes in
-           * the style context the widget path
-           */
-          classes = gtk_style_context_list_classes (widget->priv->context);
-
-          for (l = classes; l; l = l->next)
-            gtk_widget_path_iter_add_class (widget->priv->path, pos, l->data);
-
-          gtk_style_context_set_path (widget->priv->context,
-                                      widget->priv->path);
-
-          g_list_free (classes);
-        }
+        gtk_style_context_set_path (widget->priv->context,
+                                    widget->priv->path);
     }
 
   return widget->priv->path;
diff --git a/gtk/gtkwidgetpath.h b/gtk/gtkwidgetpath.h
index c33b059..e44824f 100644
--- a/gtk/gtkwidgetpath.h
+++ b/gtk/gtkwidgetpath.h
@@ -31,6 +31,10 @@ G_BEGIN_DECLS
 
 typedef struct _GtkWidgetPath GtkWidgetPath;
 
+/* We make this forward declaration here, since gtkwidget.h includes us.
+ */
+typedef struct _GtkWidget      GtkWidget;
+
 #define GTK_TYPE_WIDGET_PATH (gtk_widget_path_get_type ())
 
 GType           gtk_widget_path_get_type            (void) G_GNUC_CONST;
@@ -46,6 +50,9 @@ gint            gtk_widget_path_append_type         (GtkWidgetPath       *path,
                                                      GType                type);
 void            gtk_widget_path_prepend_type        (GtkWidgetPath       *path,
                                                      GType                type);
+/* gtk_widget_path_append_for_widget() is declared in gtkwidget.c */
+gint            gtk_widget_path_append_for_widget   (GtkWidgetPath       *path,
+                                                     GtkWidget           *widget);
 
 GType               gtk_widget_path_iter_get_object_type (const GtkWidgetPath *path,
                                                           gint                 pos);



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