Synopsis
#include <gtk/gtk.h>
GtkIconSource;
GtkIconFactory;
GtkIconSet;
enum GtkIconSize;
GtkIconSource* gtk_icon_source_copy (const GtkIconSource *source);
void gtk_icon_source_free (GtkIconSource *source);
void gtk_icon_factory_add (GtkIconFactory *factory,
const gchar *stock_id,
GtkIconSet *icon_set);
void gtk_icon_factory_add_default (GtkIconFactory *factory);
GtkIconSet* gtk_icon_factory_lookup (GtkIconFactory *factory,
const gchar *stock_id);
GtkIconSet* gtk_icon_factory_lookup_default (const gchar *stock_id);
GtkIconFactory* gtk_icon_factory_new (void);
void gtk_icon_factory_remove_default (GtkIconFactory *factory);
void gtk_icon_set_add_source (GtkIconSet *icon_set,
const GtkIconSource *source);
GtkIconSet* gtk_icon_set_copy (GtkIconSet *icon_set);
GtkIconSet* gtk_icon_set_new (void);
GtkIconSet* gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf);
GtkIconSet* gtk_icon_set_ref (GtkIconSet *icon_set);
GdkPixbuf* gtk_icon_set_render_icon (GtkIconSet *icon_set,
GtkStyle *style,
GtkTextDirection direction,
GtkStateType state,
GtkIconSize size,
GtkWidget *widget,
const char *detail);
void gtk_icon_set_unref (GtkIconSet *icon_set);
gboolean gtk_icon_size_lookup (GtkIconSize size,
gint *width,
gint *height);
gboolean gtk_icon_size_lookup_for_settings (GtkSettings *settings,
GtkIconSize size,
gint *width,
gint *height);
GtkIconSize gtk_icon_size_register (const gchar *name,
gint width,
gint height);
void gtk_icon_size_register_alias (const gchar *alias,
GtkIconSize target);
GtkIconSize gtk_icon_size_from_name (const gchar *name);
const gchar* gtk_icon_size_get_name (GtkIconSize size);
void gtk_icon_set_get_sizes (GtkIconSet *icon_set,
GtkIconSize **sizes,
gint *n_sizes);
GtkTextDirection gtk_icon_source_get_direction (const GtkIconSource *source);
gboolean gtk_icon_source_get_direction_wildcarded
(const GtkIconSource *source);
const gchar* gtk_icon_source_get_filename (const GtkIconSource *source);
GdkPixbuf* gtk_icon_source_get_pixbuf (const GtkIconSource *source);
const gchar* gtk_icon_source_get_icon_name (const GtkIconSource *source);
GtkIconSize gtk_icon_source_get_size (const GtkIconSource *source);
gboolean gtk_icon_source_get_size_wildcarded (const GtkIconSource *source);
GtkStateType gtk_icon_source_get_state (const GtkIconSource *source);
gboolean gtk_icon_source_get_state_wildcarded
(const GtkIconSource *source);
GtkIconSource* gtk_icon_source_new (void);
void gtk_icon_source_set_direction (GtkIconSource *source,
GtkTextDirection direction);
void gtk_icon_source_set_direction_wildcarded
(GtkIconSource *source,
gboolean setting);
void gtk_icon_source_set_filename (GtkIconSource *source,
const gchar *filename);
void gtk_icon_source_set_pixbuf (GtkIconSource *source,
GdkPixbuf *pixbuf);
void gtk_icon_source_set_icon_name (GtkIconSource *source,
const gchar *icon_name);
void gtk_icon_source_set_size (GtkIconSource *source,
GtkIconSize size);
void gtk_icon_source_set_size_wildcarded (GtkIconSource *source,
gboolean setting);
void gtk_icon_source_set_state (GtkIconSource *source,
GtkStateType state);
void gtk_icon_source_set_state_wildcarded
(GtkIconSource *source,
gboolean setting);
DescriptionBrowse the available stock icons in the list of stock IDs found here. You can also use the gtk-demo application for this purpose.
An icon factory manages a collection of GtkIconSet; a GtkIconSet manages a
set of variants of a particular icon (i.e. a GtkIconSet contains variants for
different sizes and widget states). Icons in an icon factory are named by a
stock ID, which is a simple string identifying the icon. Each GtkStyle has a
list of GtkIconFactory derived from the current theme; those icon factories
are consulted first when searching for an icon. If the theme doesn't set a
particular icon, GTK+ looks for the icon in a list of default icon factories,
maintained by
To display an icon, always use GtkIconFactory as GtkBuildableGtkIconFactory supports a custom <sources> element, which can contain multiple <source> elements. The following attributes are allowed:
Example 4. A GtkIconFactory UI definition fragment.
<object class="GtkIconFactory" id="iconfactory1">
<sources>
<source stock-id="apple-red" filename="apple-red.png"/>
</sources>
</object>
<object class="GtkWindow" id="window1">
<child>
<object class="GtkButton" id="apple_button">
<property name="label">apple-red</property>
<property name="use-stock">True</property>
</object>
</child>
</object>
Detailsenum GtkIconSizetypedef enum
{
GTK_ICON_SIZE_INVALID,
GTK_ICON_SIZE_MENU,
GTK_ICON_SIZE_SMALL_TOOLBAR,
GTK_ICON_SIZE_LARGE_TOOLBAR,
GTK_ICON_SIZE_BUTTON,
GTK_ICON_SIZE_DND,
GTK_ICON_SIZE_DIALOG
} GtkIconSize;
gtk_icon_source_copy ()GtkIconSource* gtk_icon_source_copy (const GtkIconSource *source);
Creates a copy of
gtk_icon_source_free ()void gtk_icon_source_free (GtkIconSource *source);
Frees a dynamically-allocated icon source, along with its
filename, size, and pixbuf fields if those are not
gtk_icon_factory_add ()void gtk_icon_factory_add (GtkIconFactory *factory, const gchar *stock_id, GtkIconSet *icon_set);
Adds the given
gtk_icon_factory_add_default ()void gtk_icon_factory_add_default (GtkIconFactory *factory);
Adds an icon factory to the list of icon factories searched by
gtk_icon_factory_lookup ()GtkIconSet* gtk_icon_factory_lookup (GtkIconFactory *factory, const gchar *stock_id);
Looks up
gtk_icon_factory_lookup_default ()GtkIconSet* gtk_icon_factory_lookup_default (const gchar *stock_id);
Looks for an icon in the list of default icon factories. For
display to the user, you should use
gtk_icon_factory_new ()GtkIconFactory* gtk_icon_factory_new (void);
Creates a new GtkIconFactory. An icon factory manages a collection
of GtkIconSets; a GtkIconSet manages a set of variants of a
particular icon (i.e. a GtkIconSet contains variants for different
sizes and widget states). Icons in an icon factory are named by a
stock ID, which is a simple string identifying the icon. Each
GtkStyle has a list of GtkIconFactorys derived from the current
theme; those icon factories are consulted first when searching for
an icon. If the theme doesn't set a particular icon, GTK+ looks for
the icon in a list of default icon factories, maintained by
gtk_icon_factory_remove_default ()void gtk_icon_factory_remove_default (GtkIconFactory *factory); Removes an icon factory from the list of default icon factories. Not normally used; you might use it for a library that can be unloaded or shut down.
gtk_icon_set_add_source ()void gtk_icon_set_add_source (GtkIconSet *icon_set, const GtkIconSource *source);
Icon sets have a list of GtkIconSource, which they use as base
icons for rendering icons in different states and sizes. Icons are
scaled, made to look insensitive, etc. in
This function copies An example of when you'd use this function: a web browser's "Back to Previous Page" icon might point in a different direction in Hebrew and in English; it might look different when insensitive; and it might change size depending on toolbar mode (small/large icons). So a single icon set would contain all those variants of the icon, and you might add a separate source for each one. You should nearly always add a "default" icon source with all fields wildcarded, which will be used as a fallback if no more specific source matches. GtkIconSet always prefers more specific icon sources to more generic icon sources. The order in which you add the sources to the icon set does not matter.
gtk_icon_set_copy ()GtkIconSet* gtk_icon_set_copy (GtkIconSet *icon_set);
Copies
gtk_icon_set_new ()GtkIconSet* gtk_icon_set_new (void); Creates a new GtkIconSet. A GtkIconSet represents a single icon in various sizes and widget states. It can provide a GdkPixbuf for a given size and state on request, and automatically caches some of the rendered GdkPixbuf objects.
Normally you would use
gtk_icon_set_new_from_pixbuf ()GtkIconSet* gtk_icon_set_new_from_pixbuf (GdkPixbuf *pixbuf);
Creates a new GtkIconSet with
gtk_icon_set_ref ()GtkIconSet* gtk_icon_set_ref (GtkIconSet *icon_set);
Increments the reference count on
gtk_icon_set_render_icon ()GdkPixbuf* gtk_icon_set_render_icon (GtkIconSet *icon_set, GtkStyle *style, GtkTextDirection direction, GtkStateType state, GtkIconSize size, GtkWidget *widget, const char *detail);
Renders an icon using
gtk_icon_set_unref ()void gtk_icon_set_unref (GtkIconSet *icon_set);
Decrements the reference count on
gtk_icon_size_lookup ()gboolean gtk_icon_size_lookup (GtkIconSize size, gint *width, gint *height);
Obtains the pixel size of a semantic icon size, possibly
modified by user preferences for the default GtkSettings.
(See
gtk_icon_size_lookup_for_settings ()gboolean gtk_icon_size_lookup_for_settings (GtkSettings *settings, GtkIconSize size, gint *width, gint *height);
Obtains the pixel size of a semantic icon size, possibly
modified by user preferences for a particular
GtkSettings. Normally
Since 2.2 gtk_icon_size_register ()GtkIconSize gtk_icon_size_register (const gchar *name, gint width, gint height); Registers a new icon size, along the same lines as GTK_ICON_SIZE_MENU, etc. Returns the integer value for the size.
gtk_icon_size_register_alias ()void gtk_icon_size_register_alias (const gchar *alias,
GtkIconSize target);
Registers
gtk_icon_size_from_name ()GtkIconSize gtk_icon_size_from_name (const gchar *name);
Looks up the icon size associated with
gtk_icon_size_get_name ()const gchar* gtk_icon_size_get_name (GtkIconSize size); Gets the canonical name of the given icon size. The returned string is statically allocated and should not be freed.
gtk_icon_set_get_sizes ()void gtk_icon_set_get_sizes (GtkIconSet *icon_set, GtkIconSize **sizes, gint *n_sizes);
Obtains a list of icon sizes this icon set can render. The returned
array must be freed with
gtk_icon_source_get_direction ()GtkTextDirection gtk_icon_source_get_direction (const GtkIconSource *source); Obtains the text direction this icon source applies to. The return value is only useful/meaningful if the text direction is not wildcarded.
gtk_icon_source_get_direction_wildcarded ()gboolean gtk_icon_source_get_direction_wildcarded
(const GtkIconSource *source);
Gets the value set by
gtk_icon_source_get_filename ()const gchar* gtk_icon_source_get_filename (const GtkIconSource *source);
Retrieves the source filename, or
gtk_icon_source_get_pixbuf ()GdkPixbuf* gtk_icon_source_get_pixbuf (const GtkIconSource *source);
Retrieves the source pixbuf, or
gtk_icon_source_get_icon_name ()const gchar* gtk_icon_source_get_icon_name (const GtkIconSource *source);
Retrieves the source icon name, or
gtk_icon_source_get_size ()GtkIconSize gtk_icon_source_get_size (const GtkIconSource *source); Obtains the icon size this source applies to. The return value is only useful/meaningful if the icon size is not wildcarded.
gtk_icon_source_get_size_wildcarded ()gboolean gtk_icon_source_get_size_wildcarded (const GtkIconSource *source);
Gets the value set by
gtk_icon_source_get_state ()GtkStateType gtk_icon_source_get_state (const GtkIconSource *source); Obtains the widget state this icon source applies to. The return value is only useful/meaningful if the widget state is not wildcarded.
gtk_icon_source_get_state_wildcarded ()gboolean gtk_icon_source_get_state_wildcarded
(const GtkIconSource *source);
Gets the value set by
gtk_icon_source_new ()GtkIconSource* gtk_icon_source_new (void); Creates a new GtkIconSource. A GtkIconSource contains a GdkPixbuf (or image filename) that serves as the base image for one or more of the icons in a GtkIconSet, along with a specification for which icons in the icon set will be based on that pixbuf or image file. An icon set contains a set of icons that represent "the same" logical concept in different states, different global text directions, and different sizes. So for example a web browser's "Back to Previous Page" icon might point in a different direction in Hebrew and in English; it might look different when insensitive; and it might change size depending on toolbar mode (small/large icons). So a single icon set would contain all those variants of the icon. GtkIconSet contains a list of GtkIconSource from which it can derive specific icon variants in the set.
In the simplest case, GtkIconSet contains one source pixbuf from
which it derives all variants. The convenience function
If you want to use a different base pixbuf for different icon
variants, you create multiple icon sources, mark which variants
they'll be used to create, and add them to the icon set with
By default, the icon source has all parameters wildcarded. That is, the icon source will be used as the base icon for any desired text direction, widget state, or icon size.
gtk_icon_source_set_direction ()void gtk_icon_source_set_direction (GtkIconSource *source, GtkTextDirection direction); Sets the text direction this icon source is intended to be used with.
Setting the text direction on an icon source makes no difference
if the text direction is wildcarded. Therefore, you should usually
call
gtk_icon_source_set_direction_wildcarded ()void gtk_icon_source_set_direction_wildcarded
(GtkIconSource *source,
gboolean setting);
If the text direction is wildcarded, this source can be used
as the base image for an icon in any GtkTextDirection.
If the text direction is not wildcarded, then the
text direction the icon source applies to should be set
with GtkIconSet prefers non-wildcarded sources (exact matches) over wildcarded sources, and will use an exact match when possible.
gtk_icon_source_set_filename ()void gtk_icon_source_set_filename (GtkIconSource *source, const gchar *filename); Sets the name of an image file to use as a base image when creating icon variants for GtkIconSet. The filename must be absolute.
gtk_icon_source_set_pixbuf ()void gtk_icon_source_set_pixbuf (GtkIconSource *source, GdkPixbuf *pixbuf); Sets a pixbuf to use as a base image when creating icon variants for GtkIconSet.
gtk_icon_source_set_icon_name ()void gtk_icon_source_set_icon_name (GtkIconSource *source, const gchar *icon_name); Sets the name of an icon to look up in the current icon theme to use as a base image when creating icon variants for GtkIconSet.
gtk_icon_source_set_size ()void gtk_icon_source_set_size (GtkIconSource *source, GtkIconSize size); Sets the icon size this icon source is intended to be used with.
Setting the icon size on an icon source makes no difference
if the size is wildcarded. Therefore, you should usually
call
gtk_icon_source_set_size_wildcarded ()void gtk_icon_source_set_size_wildcarded (GtkIconSource *source, gboolean setting);
If the icon size is wildcarded, this source can be used as the base
image for an icon of any size. If the size is not wildcarded, then
the size the source applies to should be set with
GtkIconSet prefers non-wildcarded sources (exact matches) over wildcarded sources, and will use an exact match when possible. GtkIconSet will normally scale wildcarded source images to produce an appropriate icon at a given size, but will not change the size of source images that match exactly.
gtk_icon_source_set_state ()void gtk_icon_source_set_state (GtkIconSource *source, GtkStateType state); Sets the widget state this icon source is intended to be used with.
Setting the widget state on an icon source makes no difference
if the state is wildcarded. Therefore, you should usually
call
gtk_icon_source_set_state_wildcarded ()void gtk_icon_source_set_state_wildcarded
(GtkIconSource *source,
gboolean setting);
If the widget state is wildcarded, this source can be used as the
base image for an icon in any GtkStateType. If the widget state
is not wildcarded, then the state the source applies to should be
set with GtkIconSet prefers non-wildcarded sources (exact matches) over wildcarded sources, and will use an exact match when possible. GtkIconSet will normally transform wildcarded source images to produce an appropriate icon for a given state, for example lightening an image on prelight, but will not modify source images that match exactly.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||