Named icons are similar to the Themeable Stock Images(3) facility, and the distinction between the two may be a bit confusing. A few things to keep in mind:
- Stock images usually are used in conjunction with Stock Items(3)., such as STOCK_OK or STOCK_OPEN. Named icons are easier to set up and therefore are more useful for new icons that an application wants to add, such as application icons or window icons.
- Stock images can only be loaded at the symbolic sizes defined by the Gtk_Icon_Size enumeration, or by custom sizes defined by Gtk.Icon_Factory.Icon_Size_Register, while named icons are more flexible and any pixel size can be specified.
- Because stock images are closely tied to stock items, and thus to actions in the user interface, stock images may come in multiple variants for different widget states or writing directions.
A good rule of thumb is that if there is a stock image for what you want to use, use it, otherwise use a named icon. It turns out that internally stock images are generally defined in terms of one or more named icons. (An example of the more than one case is icons that depend on writing direction; STOCK_GO_FORWARD uses the two themed icons "gtk-stock-go-forward-ltr" and "gtk-stock-go-forward-rtl".)
In many cases, named themes are used indirectly, via Gtk_Image or stock items, rather than directly, but looking up icons directly is also simple. The Gtk_Icon_Theme object acts as a database of all the icons in the current theme. You can create new Gtk_Icon_Theme objects, but its much more efficient to use the standard icon theme for the Gdk_Screen so that the icon information is shared with other people looking up icons. In the case where the default screen is being used, looking up an icon can be as simple as: Theme := Get_Default; Pixbuf := Load_Icon (Theme, "my-icon-name", 48, 0, Error); if Pixbuf = null then Put_Line ("Error " & Get_Message (Error); Error_Free (Error); end if;
Return value: the base size, or 0, if no base size is known for the icon.
Return value: the built-in image pixbuf, or null. No extra reference is added to the returned pixbuf, so if you want to keep it around, you must use Ref. The returned image must not be modified.
Raw coordinates are somewhat strange; they are specified to be with respect to the unscaled pixmap for PNG and XPM icons, but for SVG icons, they are in a 1000x1000 coordinate space that is scaled to the final size of the icon. You can determine if the icon is an SVG icon by using Get_Filename, and seeing if it is non-empty and ends in '.svg'.
This function is provided primarily to allow compatibility wrappers for older API's, and is not expected to be useful for applications.
In addition if an icon found isn't found either in the current icon theme or the default icon theme, and an image file with the right name is found directly in one of the elements of Path, then that image will be used for the icon name. (This is legacy feature, and new icons should be put into the default icon theme, which is called DEFAULT_THEME_NAME, rather than directly on the icon path.)
In general, if you use Add_Builtin_Icon you should also install the icon in the icon theme, so that the icon is generally available.
This function will generally be used with pixbufs loaded via Gdk.Pixbuf.Gdk_New_From-Inline.
Note that you probably want to listen for icon theme changes and update the icon. This is usually done by connecting to the GtkWidget::style-set signal. If for some reason you do not want to update the icon when the icon theme changes, you should consider using Gdk.Pixbuf.Copy to make a private copy of the pixbuf returned by this function. Otherwise GTK+ may need to keep the old icon theme loaded, which would be a waste of memory.
Return value: the rendered icon; this may be a newly created icon or a new reference to an internal icon, so you must not modify the icon. Use Unref to release your reference to the icon.