[gtk+] API: Add gtk_widget_path_iter_set_object_name()



commit 101df329ae7d4df779230ac565a7507fda44025d
Author: Benjamin Otte <otte redhat com>
Date:   Tue Oct 27 01:26:20 2015 +0100

    API: Add gtk_widget_path_iter_set_object_name()
    
    ... and gtk_widget_path_iter_get_object_name(). This allows applications
    that still use widget paths to use the new object names to get the
    correct styling.
    
    Mutter and webkit-gtk are examples here.

 docs/reference/gtk/gtk3-sections.txt |    2 +
 gtk/gtkcssmatcher.c                  |   18 +++++++++-
 gtk/gtkwidgetpath.c                  |   59 ++++++++++++++++++++++++++++++++++
 gtk/gtkwidgetpath.h                  |    7 ++++
 4 files changed, 84 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 360a69c..453fdac 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -5949,6 +5949,7 @@ gtk_widget_path_iter_add_region
 gtk_widget_path_iter_clear_classes
 gtk_widget_path_iter_clear_regions
 gtk_widget_path_iter_get_name
+gtk_widget_path_iter_get_object_name
 gtk_widget_path_iter_get_object_type
 gtk_widget_path_iter_get_siblings
 gtk_widget_path_iter_get_sibling_index
@@ -5964,6 +5965,7 @@ gtk_widget_path_iter_list_regions
 gtk_widget_path_iter_remove_class
 gtk_widget_path_iter_remove_region
 gtk_widget_path_iter_set_name
+gtk_widget_path_iter_set_object_name
 gtk_widget_path_iter_set_object_type
 gtk_widget_path_iter_set_state
 gtk_widget_path_length
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index 36b6872..71a4cba 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -84,9 +84,23 @@ gtk_css_matcher_widget_path_has_name (const GtkCssMatcher     *matcher,
 
   siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
   if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, 
matcher->path.index))
-    return g_type_is_a (gtk_widget_path_iter_get_object_type (siblings, matcher->path.sibling_index), type);
+    {
+      const char *path_name = gtk_widget_path_iter_get_object_name (siblings, matcher->path.sibling_index);
+
+      if (path_name == NULL)
+        return g_type_is_a (gtk_widget_path_iter_get_object_type (siblings, matcher->path.sibling_index), 
type);
+
+      return path_name == name;
+    }
   else
-    return g_type_is_a (gtk_widget_path_iter_get_object_type (matcher->path.path, matcher->path.index), 
type);
+    {
+      const char *path_name = gtk_widget_path_iter_get_object_name (matcher->path.path, matcher->path.index);
+
+      if (path_name == NULL)
+        return g_type_is_a (gtk_widget_path_iter_get_object_type (matcher->path.path, matcher->path.index), 
type);
+
+      return path_name == name;
+    }
 }
 
 static gboolean
diff --git a/gtk/gtkwidgetpath.c b/gtk/gtkwidgetpath.c
index 0c309d3..f28ddc9 100644
--- a/gtk/gtkwidgetpath.c
+++ b/gtk/gtkwidgetpath.c
@@ -512,6 +512,65 @@ gtk_widget_path_iter_get_sibling_index (const GtkWidgetPath *path,
 }
 
 /**
+ * gtk_widget_path_iter_get_object_name:
+ * @path: a #GtkWidgetPath
+ * @pos: position to get the object name for, -1 for the path head
+ *
+ * Returns the object name that is at position @pos in the widget
+ * hierarchy defined in @path.
+ *
+ * Returns: the name or %NULL
+ *
+ * Since: 3.20
+ **/
+const char *
+gtk_widget_path_iter_get_object_name (const GtkWidgetPath *path,
+                                      gint                 pos)
+{
+  GtkPathElement *elem;
+
+  gtk_internal_return_val_if_fail (path != NULL, NULL);
+  gtk_internal_return_val_if_fail (path->elems->len != 0, NULL);
+
+  if (pos < 0 || pos >= path->elems->len)
+    pos = path->elems->len - 1;
+
+  elem = &g_array_index (path->elems, GtkPathElement, pos);
+  return gtk_css_node_declaration_get_name (elem->decl);
+}
+
+/**
+ * gtk_widget_path_iter_set_object_name:
+ * @path: a #GtkWidgetPath
+ * @pos: position to modify, -1 for the path head
+ * @name: (allow-none): object name to set or %NULL to unset
+ *
+ * Sets the object name for a given position in the widget hierarchy
+ * defined by @path.
+ *
+ * When set, the object name overrides the object type when matching
+ * CSS.
+ *
+ * Since: 3.20
+ **/
+void
+gtk_widget_path_iter_set_object_name (GtkWidgetPath *path,
+                                      gint           pos,
+                                      const char    *name)
+{
+  GtkPathElement *elem;
+
+  gtk_internal_return_if_fail (path != NULL);
+  gtk_internal_return_if_fail (path->elems->len != 0);
+
+  if (pos < 0 || pos >= path->elems->len)
+    pos = path->elems->len - 1;
+
+  elem = &g_array_index (path->elems, GtkPathElement, pos);
+  gtk_css_node_declaration_set_name (&elem->decl, g_intern_string (name));
+}
+
+/**
  * gtk_widget_path_iter_get_object_type:
  * @path: a #GtkWidgetPath
  * @pos: position to get the object type for, -1 for the path head
diff --git a/gtk/gtkwidgetpath.h b/gtk/gtkwidgetpath.h
index bd86434..6ef1dbc 100644
--- a/gtk/gtkwidgetpath.h
+++ b/gtk/gtkwidgetpath.h
@@ -72,6 +72,13 @@ GDK_AVAILABLE_IN_ALL
 void                gtk_widget_path_iter_set_object_type  (GtkWidgetPath       *path,
                                                            gint                 pos,
                                                            GType                type);
+GDK_AVAILABLE_IN_3_20
+const char *        gtk_widget_path_iter_get_object_name  (const GtkWidgetPath *path,
+                                                           gint                 pos);
+GDK_AVAILABLE_IN_3_20
+void                gtk_widget_path_iter_set_object_name  (GtkWidgetPath       *path,
+                                                           gint                 pos,
+                                                           const char          *name);
 GDK_AVAILABLE_IN_ALL
 const GtkWidgetPath *
                     gtk_widget_path_iter_get_siblings     (const GtkWidgetPath *path,


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