GdkPixbuf *CreateStockIcon(const char *stockid, GtkIconSize size) { // FIXME: This code is not 100% correct, because stock pixmap are // context-dependent and may be affected by theme engine, the // correct value can only be obtained for given GtkWidget object. // // Fool-proof implementation of stock bitmaps would extend wxBitmap // with "stock-id" representation (in addition to pixmap and pixbuf // ones) and would convert it to pixbuf when rendered. GtkWidget* widget = wxGTKPrivate::GetButtonWidget(); #ifdef __WXGTK3__ GtkStyleContext* sc = gtk_widget_get_style_context(widget); GtkIconSet* iconset = gtk_style_context_lookup_icon_set(sc, stockid); GdkPixbuf* pixbuf = NULL; if (iconset) pixbuf = gtk_icon_set_render_icon_pixbuf(iconset, sc, size); return pixbuf; #else GtkStyle* style = gtk_widget_get_style(widget); GtkIconSet* iconset = gtk_style_lookup_icon_set(style, stockid); if (!iconset) return NULL; return gtk_icon_set_render_icon(iconset, style, gtk_widget_get_default_direction(), GTK_STATE_NORMAL, size, NULL, NULL); #endif }
static void ensure_stated_surface_from_info (GtkIconHelper *self, GtkStyleContext *context, GtkIconInfo *info, int scale) { GdkPixbuf *destination = NULL; cairo_surface_t *surface; gboolean symbolic; symbolic = FALSE; if (info) destination = gtk_icon_info_load_symbolic_for_context (info, context, &symbolic, NULL); if (destination == NULL) { GtkIconSet *icon_set; G_GNUC_BEGIN_IGNORE_DEPRECATIONS; icon_set = gtk_icon_factory_lookup_default (GTK_STOCK_MISSING_IMAGE); destination = gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size); G_GNUC_END_IGNORE_DEPRECATIONS; } else if (!symbolic) { GdkPixbuf *rendered; rendered = ensure_stated_pixbuf_from_pixbuf (self, context, destination); g_object_unref (destination); destination = rendered; } surface = NULL; if (destination) { surface = gdk_cairo_surface_create_from_pixbuf (destination, scale, self->priv->window); self->priv->rendered_surface_width = (gdk_pixbuf_get_width (destination) + scale - 1) / scale; self->priv->rendered_surface_height = (gdk_pixbuf_get_height (destination) + scale - 1) / scale; g_object_unref (destination); } self->priv->rendered_surface = surface; }
static void ensure_pixbuf_for_icon_set (GtkIconHelper *self, GtkStyleContext *context, GtkIconSet *icon_set) { if (!check_invalidate_pixbuf (self, context)) return; self->priv->rendered_pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size); }
static void ensure_pixbuf_for_icon_set (GtkIconHelper *self, GtkStyleContext *context, GtkIconSet *icon_set) { if (!check_invalidate_pixbuf (self, context)) return; G_GNUC_BEGIN_IGNORE_DEPRECATIONS; self->priv->rendered_pixbuf = gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size); G_GNUC_END_IGNORE_DEPRECATIONS; }
static GdkPixbuf * ensure_stated_icon_from_info (GtkIconHelper *self, GtkStyleContext *context, GtkIconInfo *info) { GdkPixbuf *destination = NULL; gboolean symbolic; symbolic = FALSE; if (info) destination = gtk_icon_info_load_symbolic_for_context (info, context, &symbolic, NULL); if (destination == NULL) { GtkIconSet *icon_set; icon_set = gtk_style_context_lookup_icon_set (context, GTK_STOCK_MISSING_IMAGE); destination = gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size); } else if (!symbolic) { GtkIconSource *source; GdkPixbuf *rendered; source = gtk_icon_source_new (); gtk_icon_source_set_pixbuf (source, destination); /* The size here is arbitrary; since size isn't * wildcarded in the source, it isn't supposed to be * scaled by the engine function */ gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_icon_source_set_size_wildcarded (source, FALSE); rendered = gtk_render_icon_pixbuf (context, source, (GtkIconSize) -1); gtk_icon_source_free (source); g_object_unref (destination); destination = rendered; } return destination; }