[gtk/otte/for-master: 3/6] stylecontext: Change semantics of gtk_style_context_get_path()



commit 59b99b81f19ba68702acacb57100efe951c3e39e
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jan 21 02:54:55 2020 +0100

    stylecontext: Change semantics of gtk_style_context_get_path()
    
    Widget contexts now return NULL here. A non-NULL result requires a
    previous call to gtk_style_context_set_path()

 demos/gtk-demo/foreigndrawing.c |  2 +-
 gtk/gtkstylecontext.c           | 18 +++++++++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/demos/gtk-demo/foreigndrawing.c b/demos/gtk-demo/foreigndrawing.c
index d72ecfd59e..447d895487 100644
--- a/demos/gtk-demo/foreigndrawing.c
+++ b/demos/gtk-demo/foreigndrawing.c
@@ -262,7 +262,7 @@ draw_menu (GtkWidget *widget,
   gint toggle_x, toggle_y, toggle_width, toggle_height;
 
   /* This information is taken from the GtkMenu docs, see "CSS nodes" */
-  menu_context = get_style (gtk_widget_get_style_context(widget), "menu");
+  menu_context = get_style (NULL, "menu");
   hovermenuitem_context = get_style (menu_context, "menuitem:hover");
   hoveredarrowmenuitem_context = get_style (hovermenuitem_context, "arrow.right:dir(ltr)");
   menuitem_context = get_style (menu_context, "menuitem");
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index bacdf3ec33..7e7deabb9a 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -970,14 +970,26 @@ gtk_style_context_set_path (GtkStyleContext *context,
  * gtk_style_context_get_path:
  * @context: a #GtkStyleContext
  *
- * Returns the widget path used for style matching.
+ * Returns the widget path used for style matching set via
+ * gtk_style_context_set_path().
  *
- * Returns: (transfer none): A #GtkWidgetPath
+ * If no path has been set - in particular if this style context
+ * was returned from a #GtkWidget - this function returns %NULL.
+ *
+ * Returns: (transfer none) (nullable): A #GtkWidgetPath or %NULL
  **/
 const GtkWidgetPath *
 gtk_style_context_get_path (GtkStyleContext *context)
 {
-  return gtk_css_node_get_widget_path (gtk_style_context_get_root (context));
+  GtkCssNode *root;
+
+  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
+
+  root = gtk_style_context_get_root (context);
+  if (!GTK_IS_CSS_PATH_NODE (root))
+    return NULL;
+
+  return gtk_css_path_node_get_widget_path (GTK_CSS_PATH_NODE (root));
 }
 
 /**


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