Beispiel #1
0
/**
 * @param stock_id	stock name
 * @return		this @a stock_id's pixbuf (or NULL for invalid stock ids)
 *
 * Return the pixbuf associated with @a stock_id, the pixbuf is
 * owned by the stock system and persists throughout runtime.
 * To display stock icons in widgets use gxk_stock_image() and not
 * this pixbuf.
 */
GdkPixbuf*
gxk_stock_fallback_pixbuf (const gchar *stock_id)
{
  static GData *stock_pixbuf_repo = NULL;
  GdkPixbuf *pixbuf;

  g_return_val_if_fail (stock_id != NULL, NULL);

  pixbuf = g_datalist_get_data (&stock_pixbuf_repo, stock_id);
  if (!pixbuf)
    {
      GtkIconSet *iset = gtk_icon_factory_lookup_default (stock_id);

      if (iset)
	{
	  static GtkStyle *style = NULL;	/* FIXME: GTKFIX: gtk_icon_set_render_icon() shouldn't demand a style */
	  if (!style)
	    style = gtk_style_new ();
	  pixbuf = gtk_icon_set_render_icon (iset, style, GTK_TEXT_DIR_NONE,
					     GTK_STATE_NORMAL, -1, NULL, NULL);
	  g_datalist_set_data (&stock_pixbuf_repo, stock_id, pixbuf);
	}
    }
  return pixbuf;
}
Beispiel #2
0
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
}
Beispiel #3
0
static void
fm_menu__item_image_from_stock(GtkWidget* menu, GtkWidget* item, char* stock_id)
{
	GtkIconSet* set = gtk_style_lookup_icon_set(gtk_widget_get_style(menu), stock_id);
	GdkPixbuf* pixbuf = gtk_icon_set_render_icon(set, gtk_widget_get_style(menu), GTK_TEXT_DIR_LTR, GTK_STATE_NORMAL, GTK_ICON_SIZE_MENU, menu, NULL);

	GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf);
	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), icon);
	g_object_unref(pixbuf);
}
GRefPtr<GdkPixbuf> RenderThemeGtk::getStockIcon(GType widgetType, const char* iconName, gint direction, gint state, gint iconSize)
{
    ASSERT(widgetType == GTK_TYPE_CONTAINER || widgetType == GTK_TYPE_ENTRY);
    GtkWidget* widget = widgetType == GTK_TYPE_CONTAINER ? GTK_WIDGET(gtkContainer()) : gtkEntry();
    GtkStyle* style = gtk_widget_get_style(widget);
    GtkIconSet* iconSet = gtk_style_lookup_icon_set(style, iconName);
    return adoptGRef(gtk_icon_set_render_icon(iconSet, style,
                                              static_cast<GtkTextDirection>(direction),
                                              static_cast<GtkStateType>(state),
                                              static_cast<GtkIconSize>(iconSize), 0, 0));
}
static void
create_button_images (AppearanceData  *data)
{
  GtkWidget *widget = (GtkWidget*)data->wp_view;
  GtkStyle *style = gtk_widget_get_style (widget);
  GtkIconSet *icon_set;
  GdkPixbuf *pixbuf, *pb, *pb2;
  gint i, w, h;

  icon_set = gtk_style_lookup_icon_set (style, "gtk-media-play");
  pb = gtk_icon_set_render_icon (icon_set,
                                 style,
                                 GTK_TEXT_DIR_RTL,
                                 GTK_STATE_NORMAL,
                                 GTK_ICON_SIZE_MENU,
                                 widget,
                                 NULL);
  pb2 = gtk_icon_set_render_icon (icon_set,
                                  style,
                                  GTK_TEXT_DIR_LTR,
                                  GTK_STATE_NORMAL,
                                  GTK_ICON_SIZE_MENU,
                                  widget,
                                  NULL);
  w = gdk_pixbuf_get_width (pb);
  h = gdk_pixbuf_get_height (pb);

  for (i = 0; i < 3; i++) {
    pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 2 * w, h);
    gdk_pixbuf_fill (pixbuf, 0);
    if (i > 0)
      gdk_pixbuf_composite (pb, pixbuf, 0, 0, w, h, 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
    if (i < 2)
      gdk_pixbuf_composite (pb2, pixbuf, w, 0, w, h, w, 0, 1, 1, GDK_INTERP_NEAREST, 255);

    buttons[i] = pixbuf;
  }

  g_object_unref (pb);
  g_object_unref (pb2);
}
Beispiel #6
0
static VALUE
rg_render_icon(int argc, VALUE *argv, VALUE self)
{
    VALUE style, direction, state, size, widget, detail;

    rb_scan_args(argc, argv, "42", &style, &direction, &state, &size, &widget, &detail);
    return GOBJ2RVAL(gtk_icon_set_render_icon(_SELF(self),
                                              RVAL2GOBJ(style),
                                              RVAL2GENUM(direction, GTK_TYPE_TEXT_DIRECTION),
                                              RVAL2GENUM(state, GTK_TYPE_STATE_TYPE),
                                              RVAL2GENUM(size, GTK_TYPE_ICON_SIZE),
                                              NIL_P(widget) ? NULL : RVAL2GOBJ(widget),
                                              NIL_P(detail) ? NULL : RVAL2CSTR(detail)));
}
Beispiel #7
0
static void accessx_applet_add_stock_icons(AccessxStatusApplet* sapplet, GtkWidget* widget)
{
    GtkIconFactory* factory = gtk_icon_factory_new();
    gint i = 0;
    GtkIconSet* icon_set;

    gtk_icon_factory_add_default(factory);

    while (i <  G_N_ELEMENTS(stock_icons))
    {
        gchar* set_name = stock_icons[i].stock_id;
        icon_set = gtk_icon_set_new();

        do {
            char* filename;
            GtkIconSource* source = gtk_icon_source_new();
            filename = g_build_filename(ACCESSX_PIXMAPS_DIR, stock_icons[i].name, NULL);

            if (g_file_test(filename, G_FILE_TEST_EXISTS) && g_file_test(filename, G_FILE_TEST_IS_REGULAR))
            {
                gtk_icon_source_set_filename(source, filename);
            }
            else
            {
                GtkIconSet* default_set = gtk_icon_factory_lookup_default(GTK_STOCK_MISSING_IMAGE);
                gtk_icon_source_set_pixbuf(source, gtk_icon_set_render_icon(default_set, gtk_widget_get_style(widget), GTK_TEXT_DIR_NONE, GTK_STATE_NORMAL, icon_size_spec, widget, NULL));
            }
            g_free(filename);
            gtk_icon_source_set_state(source, stock_icons[i].state);
            gtk_icon_source_set_state_wildcarded(source, stock_icons[i].wildcarded);
            gtk_icon_set_add_source(icon_set, source);
            gtk_icon_source_free(source);
            ++i;
        } while (set_name == stock_icons[i].stock_id);
        gtk_icon_factory_add(factory, set_name, icon_set);
        gtk_icon_set_unref(icon_set);
    }
    /* now create the stock icons for AltGr, which are internationalized */
    icon_set = accessx_status_applet_altgraph_icon_set (sapplet, widget);
    gtk_icon_factory_add(factory, ALTGRAPH_KEY_ICON, icon_set);
    gtk_icon_set_unref(icon_set);
    sapplet->icon_factory = factory;
}
Beispiel #8
0
/* Create a MaskedPixmap from a GTK stock ID. Always returns
 * a valid image.
 */
static MaskedPixmap *mp_from_stock(const char *stock_id, int size)
{
	//printf("mp_from_stock()...\n");
	GtkIconSet *icon_set;
	GdkPixbuf  *pixbuf;
	MaskedPixmap *retval;

	icon_set = gtk_icon_factory_lookup_default(stock_id);
	if (!icon_set) return get_bad_image();
	
	pixbuf = gtk_icon_set_render_icon(icon_set,
                                     gtk_widget_get_default_style(), /* Gtk bug */
                                     GTK_TEXT_DIR_LTR,
                                     GTK_STATE_NORMAL,
                                     size,
                                     NULL,
                                     NULL);
	retval = masked_pixmap_new(pixbuf);
	g_object_unref(pixbuf);

	return retval;
}
nsresult
nsIconChannel::Init(nsIURI* aURI)
{
    nsCOMPtr<nsIMozIconURI> iconURI = do_QueryInterface(aURI);
    NS_ASSERTION(iconURI, "URI is not an nsIMozIconURI");

    nsAutoCString stockIcon;
    iconURI->GetStockIcon(stockIcon);
    if (stockIcon.IsEmpty()) {
#ifdef MOZ_ENABLE_GNOMEUI
        return InitWithGnome(iconURI);
#else
#ifdef MOZ_ENABLE_GIO
        return InitWithGIO(iconURI);
#else
        return NS_ERROR_NOT_AVAILABLE;
#endif
#endif
    }

    // Search for stockIcon
    nsAutoCString iconSizeString;
    iconURI->GetIconSize(iconSizeString);

    nsAutoCString iconStateString;
    iconURI->GetIconState(iconStateString);

    GtkIconSize icon_size = moz_gtk_icon_size(iconSizeString.get());
    GtkStateType state = iconStateString.EqualsLiteral("disabled") ?
                         GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL;

    // First lookup the icon by stock id and text direction.
    GtkTextDirection direction = GTK_TEXT_DIR_NONE;
    if (StringEndsWith(stockIcon, NS_LITERAL_CSTRING("-ltr"))) {
        direction = GTK_TEXT_DIR_LTR;
    } else if (StringEndsWith(stockIcon, NS_LITERAL_CSTRING("-rtl"))) {
        direction = GTK_TEXT_DIR_RTL;
    }

    bool forceDirection = direction != GTK_TEXT_DIR_NONE;
    nsAutoCString stockID;
    bool useIconName = false;
    if (!forceDirection) {
        direction = gtk_widget_get_default_direction();
        stockID = stockIcon;
    } else {
        // GTK versions < 2.22 use icon names from concatenating stock id with
        // -(rtl|ltr), which is how the moz-icon stock name is interpreted here.
        stockID = Substring(stockIcon, 0, stockIcon.Length() - 4);
        // However, if we lookup bidi icons by the stock name, then GTK versions
        // >= 2.22 will use a bidi lookup convention that most icon themes do not
        // yet follow.  Therefore, we first check to see if the theme supports the
        // old icon name as this will have bidi support (if found).
        GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
        // Micking what gtk_icon_set_render_icon does with sizes, though it's not
        // critical as icons will be scaled to suit size.  It just means we follow
        // the same pathes and so share caches.
        gint width, height;
        if (gtk_icon_size_lookup(icon_size, &width, &height)) {
            gint size = NS_MIN(width, height);
            // We use gtk_icon_theme_lookup_icon() without
            // GTK_ICON_LOOKUP_USE_BUILTIN instead of gtk_icon_theme_has_icon() so
            // we don't pick up fallback icons added by distributions for backward
            // compatibility.
            GtkIconInfo *icon =
                gtk_icon_theme_lookup_icon(icon_theme, stockIcon.get(),
                                           size, (GtkIconLookupFlags)0);
            if (icon) {
                useIconName = true;
                gtk_icon_info_free(icon);
            }
        }
    }

    ensure_stock_image_widget();
    GtkStyle *style = gtk_widget_get_style(gStockImageWidget);
    GtkIconSet *icon_set = NULL;
    if (!useIconName) {
        icon_set = gtk_style_lookup_icon_set(style, stockID.get());
    }

    if (!icon_set) {
        // Either we have choosen icon-name lookup for a bidi icon, or stockIcon is
        // not a stock id so we assume it is an icon name.
        useIconName = true;
        // Creating a GtkIconSet is a convenient way to allow the style to
        // render the icon, possibly with variations suitable for insensitive
        // states.
        icon_set = gtk_icon_set_new();
        GtkIconSource *icon_source = gtk_icon_source_new();

        gtk_icon_source_set_icon_name(icon_source, stockIcon.get());
        gtk_icon_set_add_source(icon_set, icon_source);
        gtk_icon_source_free(icon_source);
    }

    GdkPixbuf *icon =
        gtk_icon_set_render_icon (icon_set, style, direction, state,
                                  icon_size, gStockImageWidget, NULL);
    if (useIconName) {
        gtk_icon_set_unref(icon_set);
    }

    // According to documentation, gtk_icon_set_render_icon() never returns
    // NULL, but it does return NULL when we have the problem reported here:
    // https://bugzilla.gnome.org/show_bug.cgi?id=629878#c13
    if (!icon)
        return NS_ERROR_NOT_AVAILABLE;

    nsresult rv = moz_gdk_pixbuf_to_channel(icon, iconURI,
                                            getter_AddRefs(mRealChannel));

    g_object_unref(icon);

    return rv;
}