std::string dumpStyleContext(GtkStyleContext* a_StyleContext) { // char* contextDump = gtk_style_context_to_string(a_StyleContext, GTK_STYLE_CONTEXT_PRINT_RECURSE); const GtkWidgetPath* widgetPath = gtk_style_context_get_path(a_StyleContext); char* contextDump = gtk_widget_path_to_string(widgetPath); std::string result = contextDump; g_free(contextDump); return result; }
static GtkStyleContext * get_style (GtkStyleContext *parent, const char *selector) { GtkWidgetPath *path; if (parent) path = gtk_widget_path_copy (gtk_style_context_get_path (parent)); else path = gtk_widget_path_new (); append_element (path, selector); return create_context_for_path (path, parent); }
static GtkStyleContext* CreateCSSNode(const char* aName, GtkStyleContext *aParentStyle) { static auto sGtkWidgetPathIterSetObjectName = reinterpret_cast<void (*)(GtkWidgetPath *, gint, const char *)> (dlsym(RTLD_DEFAULT, "gtk_widget_path_iter_set_object_name")); GtkWidgetPath* path = gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle)); gtk_widget_path_append_type(path, G_TYPE_NONE); (*sGtkWidgetPathIterSetObjectName)(path, -1, aName); GtkStyleContext *context = gtk_style_context_new(); gtk_style_context_set_path(context, path); gtk_style_context_set_parent(context, aParentStyle); gtk_widget_path_unref(path); return context; }
static GtkStyleContext * get_style (GtkStyleContext *parent, const char *selector) { GtkWidgetPath *path; GtkStyleContext *context; if (parent) path = gtk_widget_path_copy (gtk_style_context_get_path (parent)); else path = gtk_widget_path_new (); append_element (path, selector); context = gtk_style_context_new (); gtk_style_context_set_path (context, path); gtk_style_context_set_parent (context, parent); gtk_widget_path_unref (path); return context; }
static GtkStyleContext * get_style_with_siblings (GtkStyleContext *parent, const char *selector, const char **siblings, gint position) { GtkWidgetPath *path, *siblings_path; guint i; if (parent) path = gtk_widget_path_copy (gtk_style_context_get_path (parent)); else path = gtk_widget_path_new (); siblings_path = gtk_widget_path_new (); for (i = 0; siblings[i]; i++) append_element (siblings_path, siblings[i]); gtk_widget_path_append_with_siblings (path, siblings_path, position); gtk_widget_path_unref (siblings_path); return create_context_for_path (path, parent); }
static void gtk_numerable_icon_update_properties_from_style (GtkNumerableIcon *self) { GtkStyleContext *style = self->priv->style; GtkWidgetPath *path, *saved; cairo_pattern_t *pattern = NULL; GdkRGBA background, foreground; PangoFontDescription *font = NULL; /* save an unmodified copy of the original widget path, in order * to restore it later */ path = gtk_widget_path_copy (gtk_style_context_get_path (style)); saved = gtk_widget_path_copy (path); if (!gtk_widget_path_is_type (path, GTK_TYPE_NUMERABLE_ICON)) { /* append our GType to the style context to fetch appropriate colors */ gtk_widget_path_append_type (path, GTK_TYPE_NUMERABLE_ICON); gtk_style_context_set_path (style, path); } gtk_style_context_get_background_color (style, gtk_style_context_get_state (style), &background); gtk_style_context_get_color (style, gtk_style_context_get_state (style), &foreground); if (self->priv->background != NULL) gdk_rgba_free (self->priv->background); self->priv->background = gdk_rgba_copy (&background); if (self->priv->foreground != NULL) gdk_rgba_free (self->priv->foreground); self->priv->foreground = gdk_rgba_copy (&foreground); gtk_style_context_get (style, gtk_style_context_get_state (style), GTK_STYLE_PROPERTY_BACKGROUND_IMAGE, &pattern, NULL); if (pattern != NULL) { if (self->priv->background_image != NULL) cairo_pattern_destroy (self->priv->background_image); self->priv->background_image = pattern; } gtk_style_context_get (style, gtk_style_context_get_state (style), GTK_STYLE_PROPERTY_FONT, &font, NULL); if (font != NULL) { if (self->priv->font != NULL) pango_font_description_free (self->priv->font); self->priv->font = font; } gtk_numerable_icon_ensure_emblem (self); /* restore original widget path */ gtk_style_context_set_path (style, saved); gtk_widget_path_free (path); gtk_widget_path_free (saved); }