Commit 101df329 authored by Benjamin Otte's avatar Benjamin Otte

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.
parent aedd193c
......@@ -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
......
......@@ -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
......
......@@ -511,6 +511,65 @@ gtk_widget_path_iter_get_sibling_index (const GtkWidgetPath *path,
return elem->sibling_index;
}
/**
* 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
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment