Xfce Foundation Classes
Main Page  | IndexNamespace List  |  Alphabetical List  |  Class List  |  File List


Xfc::Gtk::IconTheme Class Reference

A GtkIconTheme C++ wrapper class. More...

#include <xfc/gtk/icontheme.hh>

Inheritance diagram for Xfc::Gtk::IconTheme:

Xfc::G::Object Xfc::G::TypeInstance Xfc::Trackable List of all members.

Signal Prototypes

Public Member Functions

Accessors
Methods
Signal Proxies

Static Public Member Functions

Accessors
Methods

Detailed Description

A GtkIconTheme C++ wrapper class.

IconTheme acts as a database of information about an icon theme. Normally, you retrieve the icon theme for a particular screen using Gtk::IconTeme::get_for_screen() and it will contain information about current icon theme for that screen, but you can also create a new IconTheme object and set the icon theme name explicitely using Gtk::IconTheme::set_custom_theme().

IconTheme provides a facility for looking up icons by name and size. The main reason for using a name rather than simply providing a filename is to allow different icons to be used depending on what icon theme is seleceted by the user. The operation of icon themes on Linux and Unix follows the Icon Theme Specification. There is a default icon theme, named hicolor where applications should install their icons, but more additional application themes can be installed as operating system vendors and users choose.

Named icons are similar to the Themeable Stock Images, 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, such as Gtk::StockId::OK or Gtk::StockId::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::IconSize enumeration, or by custom sizes defined by Gtk::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; Gtk::StockId::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 IconTheme object acts as a database of all the icons in the current theme. You can create new IconTheme 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:

 G::Error error;
 Gtk::IconTheme *icon_theme = Gtk::IconTheme::get_for_screen();
 Pointer<Gdk::Pixbuf> pixbuf = icon_theme->load_icon("my-icon-name", 48, 0, &error);
 
 if (!pixbuf)
 {
        g_warning("Couldn't load icon: %s", error.message());
 }
 else
 {
        // Use the pixbuf
 }


Constructor & Destructor Documentation

Xfc::Gtk::IconTheme::IconTheme ( GtkIconTheme *  icon_theme,
bool  owns_reference = true 
) [explicit, protected]

Construct a new IconTheme from an existing GtkIconTheme.

Parameters:
icon_theme A pointer to a GtkIconTheme.
owns_reference Set false if the initial reference count is floating, set true if it's not.
The icon_theme can be a newly created GtkIconTheme or an existing GtkIconTheme (see G::Object::Object).

Xfc::Gtk::IconTheme::IconTheme (  ) 

Constructs a new icon theme object with a reference count of 1 that the caller owns.

Icon theme objects are used to lookup up an icon by name in a particular icon theme Usually, you'll want to use get_for_screen() rather than creating a new icon theme object for scratch.

Xfc::Gtk::IconTheme::IconTheme ( GtkIconTheme *  icon_theme,
bool  owns_reference = true 
) [explicit, protected]

Construct a new IconTheme from an existing GtkIconTheme.

Parameters:
icon_theme A pointer to a GtkIconTheme.
owns_reference Set false if the initial reference count is floating, set true if it's not.
The icon_theme can be a newly created GtkIconTheme or an existing GtkIconTheme (see G::Object::Object).

Xfc::Gtk::IconTheme::IconTheme (  ) 

Constructs a new icon theme object with a reference count of 1 that the caller owns.

Icon theme objects are used to lookup up an icon by name in a particular icon theme Usually, you'll want to use get_for_screen() rather than creating a new icon theme object for scratch.


Member Function Documentation

std::vector<String> Xfc::Gtk::IconTheme::get_search_path (  )  const

Gets the current search path (see set_search_path()).

Returns:
A list of icon theme path directories.

String Xfc::Gtk::IconTheme::get_example_icon_name (  )  const

Gets the name of an icon that is representative of the current theme (for instance, to use when presenting a list of themes to the user).

Returns:
The name of an example icon or null.

bool Xfc::Gtk::IconTheme::has_icon ( const String icon_name  )  const

Checks whether an icon theme includes an icon for a particular name.

Parameters:
icon_name The name of an icon.
Returns:
true if icon theme includes an icon for icon_name.

std::vector<int> Xfc::Gtk::IconTheme::get_icon_sizes ( const String icon_name  )  const

Returns a vector of integers describing the sizes at which the icon is available without scaling.

Parameters:
icon_name The name of an icon.
Returns:
A vector of int describing the sizes at which the icon is available.
A size of -1 means that the icon is available in a scalable format.

static IconTheme* Xfc::Gtk::IconTheme::get_for_screen ( const Gdk::Screen screen = 0  )  [static]

Gets the icon theme object associated with screen.

Parameters:
screen A Gdk::Screen, or null for the default screen.
Returns:
A unique IconTheme associated with the given screen.
If screen is null the icon theme for the default screen is returned. The icon theme is associated with the screen and can be used as long as the screen is open.

If this method has not previously been called for the given screen, a new icon theme object will be created and associated with the screen. Icon theme objects are fairly expensive to create, so using this method is usually a better choice than constructing a new icon theme object and setting the screen yourself. By using this method a single icon theme object will be shared between users.

void Xfc::Gtk::IconTheme::set_screen ( Gdk::Screen screen  ) 

Sets the screen for an icon theme.

Parameters:
screen A Gdk::Screen.
The screen is used to track the user's currently configured icon theme, which might be different for different screens.

void Xfc::Gtk::IconTheme::set_search_path ( const std::vector< String > &  path  ) 

Sets the search path for the icon theme object.

Parameters:
path A vector of directories that are searched for icon themes.
When looking for an icon theme, GTK+ will search for a subdirectory of one or more of the directories in path with the same name as the icon theme. Note, themes from multiple of the path elements are combined to allow themes to be extended by adding icons in the user's home directory.

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.)

void Xfc::Gtk::IconTheme::append_search_path ( const String path  ) 

Appends a directory to the search path (see set_search_path()).

Parameters:
path The directory name to append to the icon path.

void Xfc::Gtk::IconTheme::prepend_search_path ( const String path  ) 

Prepends a directory to the search path (see set_search_path()).

Parameters:
path The directory name to prepend to the icon path.

void Xfc::Gtk::IconTheme::set_custom_theme ( const String theme_name  ) 

Sets the name of the icon theme that the IconTheme object uses, overriding system configuration.

Parameters:
theme_name The name of icon theme to use instead of the configured theme.
This method cannot be called on the icon theme objects returned from get_for_screen().

Pointer<IconInfo> Xfc::Gtk::IconTheme::lookup_icon ( const String icon_name,
int  size,
IconLookupFlagsField  flags 
)

Looks up a named icon and returns a structure containing information such as the filename of the icon.

Parameters:
icon_name The name of the icon to lookup.
size The desired icon size.
flags The Gtk::IconLookupFlags modifying the behavior of the icon lookup.
Returns:
An IconInfo object containing information about the icon, or null if no icon was found.
The icon can then be rendered into a pixbuf using Gtk::IconInfo::load_icon(). Gtk::IconTheme::load_icon() combines these two steps if all you need is the pixbuf.

Pointer<Gdk::Pixbuf> Xfc::Gtk::IconTheme::load_icon ( const String icon_name,
int  size,
IconLookupFlagsField  flags,
G::Error error = 0 
)

Looks up an icon in an icon theme, scales it to the given size and renders it into a pixbuf.

Parameters:
icon_name The name of the icon to lookup.
size The desired icon size.
flags The Gtk::IconLookupFlags modifying the behavior of the icon lookup.
error The location to store error information on failure, or null.
Returns:
A smart pointer to the rendered icon, or null if the icon isn't found.
This is a convenience method; if more details about the icon are needed, use lookup_icon() followed by Gtk::IconInfo::load_icon(). Note the size of the resulting icon may not be exactly the requested size (see load_icon()).

The rendered icon may be a newly created icon or a new reference to an internal icon, so you must not modify the icon.

std::vector<String> Xfc::Gtk::IconTheme::list_icons ( const String context  ) 

Lists the icons in the current icon theme.

Returns:
A vector of String holding the names of all the icons in the theme.
Only a subset of the icons can be listed by providing a context string. The set of values for the context string is system dependent, but will typically include such values as 'apps' and 'mimetypes'.
Parameters:
context A string identifying a particular type of icon, or null to list all icons.

bool Xfc::Gtk::IconTheme::rescan_if_needed (  ) 

Checks to see if the icon theme has changed; if it has, any currently cached information is discarded and will be reloaded next time the icon theme is accessed.

Returns:
true if the icon theme has changed and needed to be reloaded.

static void Xfc::Gtk::IconTheme::add_builtin_icon ( const String icon_name,
int  size,
Gdk::Pixbuf pixbuf 
) [static]

Registers a built-in icon for icon theme lookups.

Parameters:
icon_name The name of the icon to register.
size The size at which to register the icon.
pixbuf A Gdk::Pixbuf that contains the image to use for icon_name.
The idea of built-in icons is to allow an application or library that uses themed icons to function requiring files to be present in the file system. For instance, the default images for all of GTK+'s stock icons are registered as built-in icons.

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. Note different images can be registered for the same icon name at different sizes.

This method will generally be used with pixbufs loaded inline (see Gdk::Pixbuf::create(int, const unsigned char*, bool, G::Error*));


Member Data Documentation

const ChangedSignalType Xfc::Gtk::IconTheme::changed_signal [static, protected]

Changed signal (see signal_changed()).

Calls a slot with the signature:

< void function();
<


The documentation for this class was generated from the following file: Xfce Foundation Classes
Copyright © 2004-2005 The XFC Development Team XFC 4.3