[gtk+/gtk-style-context: 19/206] Add GtkWidgetPath.



commit 79a7d75bfa00eac0de753eb67346389df68c2e02
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 12 18:55:54 2010 +0100

    Add GtkWidgetPath.
    
    GtkWidgetPath represents a widget path. It will mainly used by theming
    engines to know detail about the widget hierarchy without actually
    accessing the widget.

 gtk/Makefile.am     |    2 +
 gtk/gtk.h           |    1 +
 gtk/gtkwidgetpath.c |  182 +++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkwidgetpath.h |   52 +++++++++++++++
 4 files changed, 237 insertions(+), 0 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 44b9c81..fd7a638 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -338,6 +338,7 @@ gtk_public_h_sources =          \
 	gtkvscrollbar.h		\
 	gtkvseparator.h		\
 	gtkwidget.h		\
+	gtkwidgetpath.h		\
 	gtkwindow.h
 
 if OS_UNIX
@@ -623,6 +624,7 @@ gtk_base_c_sources =            \
 	gtkvscrollbar.c		\
 	gtkvseparator.c		\
 	gtkwidget.c		\
+	gtkwidgetpath.c		\
 	gtkwindow-decorate.c    \
 	gtkwindow.c		\
 	$(gtk_clipboard_dnd_c_sources)
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 4a54718..e7ace32 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -220,6 +220,7 @@
 #include <gtk/gtkvscrollbar.h>
 #include <gtk/gtkvseparator.h>
 #include <gtk/gtkwidget.h>
+#include <gtk/gtkwidgetpath.h>
 #include <gtk/gtkwindow.h>
 
 #undef __GTK_H_INSIDE__
diff --git a/gtk/gtkwidgetpath.c b/gtk/gtkwidgetpath.c
new file mode 100644
index 0000000..2af624f
--- /dev/null
+++ b/gtk/gtkwidgetpath.c
@@ -0,0 +1,182 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include "gtkwidget.h"
+#include "gtkwidgetpath.h"
+
+typedef struct GtkPathElement GtkPathElement;
+
+struct GtkPathElement
+{
+  GType type;
+  gchar *name;
+};
+
+struct GtkWidgetPath
+{
+  GSList *elems;
+  GSList *last; /* Last element contains the described widget */
+};
+
+GtkWidgetPath *
+gtk_widget_path_new (void)
+{
+  GtkWidgetPath *path;
+
+  path = g_slice_new0 (GtkWidgetPath);
+
+  return path;
+}
+
+static GtkPathElement *
+path_element_new (GType        type,
+                  const gchar *name)
+{
+  GtkPathElement *elem;
+
+  elem = g_slice_new (GtkPathElement);
+  elem->type = type;
+  elem->name = g_strdup (name);
+
+  return elem;
+}
+
+static void
+path_element_free (GtkPathElement *elem)
+{
+  g_free (elem->name);
+  g_slice_free (GtkPathElement, elem);
+}
+
+void
+gtk_widget_path_prepend_widget_desc (GtkWidgetPath *path,
+                                     GType          type,
+                                     const gchar   *name)
+{
+  g_return_if_fail (path != NULL);
+  g_return_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET));
+
+  if (!path->elems)
+    {
+      path->elems = g_slist_prepend (NULL, path_element_new (type, name));
+      path->last = path->elems;
+    }
+  else
+    {
+      path->last->next = g_slist_alloc ();
+      path->last->next->data = path_element_new (type, name);
+      path->last = path->last->next;
+    }
+}
+
+GtkWidgetPath *
+gtk_widget_path_copy (GtkWidgetPath *path)
+{
+  GtkWidgetPath *new_path;
+  GSList *elems;
+
+  new_path = gtk_widget_path_new ();
+  elems = path->elems;
+
+  while (elems)
+    {
+      GtkPathElement *elem;
+      GSList *link;
+
+      elem = elems->data;
+      link = g_slist_alloc ();
+      link->data = path_element_new (elem->type, elem->name);
+
+      if (!new_path->elems)
+        new_path->last = new_path->elems = link;
+      else
+        {
+          new_path->last->next = link;
+          new_path->last = link;
+        }
+
+      elems = elems->next;
+    }
+
+  return new_path;
+}
+
+void
+gtk_widget_path_free (GtkWidgetPath *path)
+{
+  g_return_if_fail (path != NULL);
+
+  g_slist_foreach (path->elems, (GFunc) path_element_free, NULL);
+  g_slist_free (path->elems);
+
+  g_slice_free (GtkWidgetPath, path);
+}
+
+gboolean
+gtk_widget_path_has_parent (GtkWidgetPath *path,
+                            GType          type)
+{
+  g_return_val_if_fail (path != NULL, FALSE);
+  g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), FALSE);
+
+  GSList *elems = path->elems;
+
+  while (elems)
+    {
+      GtkPathElement *elem;
+
+      elem = elems->data;
+
+      if (elem->type == type ||
+          g_type_is_a (elem->type, type))
+        return TRUE;
+
+      elems = elems->next;
+    }
+
+  return FALSE;
+}
+
+void
+gtk_widget_path_foreach (GtkWidgetPath            *path,
+                         GtkWidgetPathForeachFunc  func,
+                         gpointer                  user_data)
+{
+  GSList *elems;
+
+  g_return_if_fail (path != NULL);
+  g_return_if_fail (func != NULL);
+
+  elems = path->elems;
+
+  while (elems)
+    {
+      GtkPathElement *elem;
+
+      elem = elems->data;
+      elems = elems->next;
+
+      if ((func) (elem->type, elem->name, user_data))
+        return;
+    }
+}
diff --git a/gtk/gtkwidgetpath.h b/gtk/gtkwidgetpath.h
new file mode 100644
index 0000000..664562c
--- /dev/null
+++ b/gtk/gtkwidgetpath.h
@@ -0,0 +1,52 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_WIDGET_PATH_H__
+#define __GTK_WIDGET_PATH_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct GtkWidgetPath GtkWidgetPath;
+
+typedef gboolean (* GtkWidgetPathForeachFunc) (GType        type,
+                                               const gchar *name,
+                                               gpointer     user_data);
+
+GtkWidgetPath * gtk_widget_path_new (void);
+
+void            gtk_widget_path_prepend_widget_desc (GtkWidgetPath *path,
+                                                     GType          type,
+                                                     const gchar   *name);
+
+GtkWidgetPath * gtk_widget_path_copy                (GtkWidgetPath *path);
+void            gtk_widget_path_free                (GtkWidgetPath *path);
+
+gboolean        gtk_widget_path_has_parent          (GtkWidgetPath *path,
+                                                     GType          type);
+
+void            gtk_widget_path_foreach             (GtkWidgetPath            *path,
+                                                     GtkWidgetPathForeachFunc  func,
+                                                     gpointer                  user_data);
+
+
+G_END_DECLS
+
+#endif /* __GTK_WIDGET_PATH_H__ */



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