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.
This commit is contained in:
Benjamin Otte 2015-10-27 01:26:20 +01:00
parent aedd193c69
commit 101df329ae
4 changed files with 84 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,