static GtkStateFlags gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher) { const GtkWidgetPath *siblings; if (matcher->path.decl) return gtk_css_node_declaration_get_state (matcher->path.decl); 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 gtk_widget_path_iter_get_state (siblings, matcher->path.sibling_index); else return gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index); }
static GtkStyleContext * create_context_for_path (GtkWidgetPath *path, GtkStyleContext *parent) { GtkStyleContext *context; context = gtk_style_context_new (); gtk_style_context_set_path (context, path); gtk_style_context_set_parent (context, parent); /* Unfortunately, we have to explicitly set the state again here * for it to take effect */ gtk_style_context_set_state (context, gtk_widget_path_iter_get_state (path, -1)); gtk_widget_path_unref (path); return context; }
static void append_element (GtkWidgetPath *path, const char *selector) { static const struct { const char *name; GtkStateFlags state_flag; } pseudo_classes[] = { { "active", GTK_STATE_FLAG_ACTIVE }, { "hover", GTK_STATE_FLAG_PRELIGHT }, { "selected", GTK_STATE_FLAG_SELECTED }, { "disabled", GTK_STATE_FLAG_INSENSITIVE }, { "indeterminate", GTK_STATE_FLAG_INCONSISTENT }, { "focus", GTK_STATE_FLAG_FOCUSED }, { "backdrop", GTK_STATE_FLAG_BACKDROP }, { "dir(ltr)", GTK_STATE_FLAG_DIR_LTR }, { "dir(rtl)", GTK_STATE_FLAG_DIR_RTL }, { "link", GTK_STATE_FLAG_LINK }, { "visited", GTK_STATE_FLAG_VISITED }, { "checked", GTK_STATE_FLAG_CHECKED }, { "drop(active)", GTK_STATE_FLAG_DROP_ACTIVE } }; const char *next; char *name; char type; guint i; next = strpbrk (selector, "#.:"); if (next == NULL) next = selector + strlen (selector); name = g_strndup (selector, next - selector); if (g_ascii_isupper (selector[0])) { GType gtype; gtype = g_type_from_name (name); if (gtype == G_TYPE_INVALID) { g_critical ("Unknown type name `%s'", name); g_free (name); return; } gtk_widget_path_append_type (path, gtype); } else { /* Omit type, we're using name */ gtk_widget_path_append_type (path, G_TYPE_NONE); gtk_widget_path_iter_set_object_name (path, -1, name); } g_free (name); while (*next != '\0') { type = *next; selector = next + 1; next = strpbrk (selector, "#.:"); if (next == NULL) next = selector + strlen (selector); name = g_strndup (selector, next - selector); switch (type) { case '#': gtk_widget_path_iter_set_name (path, -1, name); break; case '.': gtk_widget_path_iter_add_class (path, -1, name); break; case ':': for (i = 0; i < G_N_ELEMENTS (pseudo_classes); i++) { if (g_str_equal (pseudo_classes[i].name, name)) { gtk_widget_path_iter_set_state (path, -1, gtk_widget_path_iter_get_state (path, -1) | pseudo_classes[i].state_flag); break; } } if (i == G_N_ELEMENTS (pseudo_classes)) g_critical ("Unknown pseudo-class :%s", name); break; default: g_assert_not_reached (); break; } g_free (name); } }