stylecontext: Change semantics of gtk_style_context_get_path()
authorBenjamin Otte <otte@redhat.com>
Tue, 21 Jan 2020 01:54:55 +0000 (02:54 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 21 Jan 2020 11:47:16 +0000 (12:47 +0100)
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
gtk/gtkstylecontext.c

index d72ecfd59e1222a5705c42cbfaf8c13deb64bccf..447d8954879a0a0b5c4651905b70c6bc00c95bc2 100644 (file)
@@ -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");
index bacdf3ec33e93dd5cd9d803abbbd9b8b4c391d77..7e7deabb9af343db76b1e75b26220ab604f71efb 100644 (file)
@@ -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));
 }
 
 /**