gtkmm  4.8.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::IconTheme Class Reference

Looking up icons by name. More...

#include <gtkmm/icontheme.h>

Inherits Glib::Object.

Public Member Functions

 IconTheme (IconTheme && src) noexcept
 
IconThemeoperator= (IconTheme && src) noexcept
 
 ~IconTheme () noexcept override
 
GtkIconTheme * gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkIconTheme * gobj () const
 Provides access to the underlying C GObject. More...
 
GtkIconTheme * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
Glib::RefPtr< Gdk::Displayget_display ()
 Returns the display that the Gtk::IconTheme object was created for. More...
 
Glib::RefPtr< const Gdk::Displayget_display () const
 Returns the display that the Gtk::IconTheme object was created for. More...
 
void set_search_path (const std::vector< std::string > & path)
 Sets the search path for the icon theme object. More...
 
std::vector< std::stringget_search_path () const
 Gets the current search path. More...
 
void add_search_path (const std::string & path)
 Appends a directory to the search path. More...
 
void set_resource_path (const std::vector< std::string > & path)
 Sets the resource paths that will be looked at when looking for icons, similar to search paths. More...
 
std::vector< std::stringget_resource_path () const
 Gets the current resource path. More...
 
void add_resource_path (const std::string & path)
 Adds a resource path that will be looked at when looking for icons, similar to search paths. More...
 
void set_theme_name (const Glib::ustring & theme_name)
 Sets the name of the icon theme that the Gtk::IconTheme object uses overriding system configuration. More...
 
Glib::ustring get_theme_name () const
 Gets the current icon theme name. More...
 
bool has_icon (const Glib::ustring & icon_name) const
 Checks whether an icon theme includes an icon for a particular name. More...
 
bool has_gicon (const Glib::RefPtr< const Gio::Icon > & gicon) const
 Checks whether an icon theme includes an icon for a particular Gio::Icon. More...
 
std::vector< int > get_icon_sizes (const Glib::ustring & icon_name) const
 Returns an array of integers describing the sizes at which the icon is available without scaling. More...
 
Glib::RefPtr< IconPaintablelookup_icon (const Glib::ustring & icon_name, const std::vector< Glib::ustring > & fallbacks, int size, int scale=1, TextDirection direction=TextDirection::NONE, IconLookupFlags flags=(IconLookupFlags) 0)
 Looks up a named icon for a desired size and window scale, returning a Gtk::IconPaintable. More...
 
Glib::RefPtr< IconPaintablelookup_icon (const Glib::ustring & icon_name, int size, int scale=1, TextDirection direction=TextDirection::NONE, IconLookupFlags flags=(IconLookupFlags) 0)
 A lookup_icon() convenience overload. More...
 
Glib::RefPtr< const IconPaintablelookup_icon (const Glib::ustring & icon_name, const std::vector< Glib::ustring > & fallbacks, int size, int scale=1, TextDirection direction=TextDirection::NONE, IconLookupFlags flags=(IconLookupFlags) 0) const
 Looks up a named icon for a desired size and window scale, returning a Gtk::IconPaintable. More...
 
Glib::RefPtr< const IconPaintablelookup_icon (const Glib::ustring & icon_name, int size, int scale=1, TextDirection direction=TextDirection::NONE, IconLookupFlags flags=(IconLookupFlags) 0) const
 A lookup_icon() convenience overload. More...
 
Glib::RefPtr< IconPaintablelookup_icon (const Glib::RefPtr< const Gio::Icon > & icon, int size, int scale=1, TextDirection direction=TextDirection::NONE, IconLookupFlags flags=(IconLookupFlags) 0)
 Looks up a icon for a desired size and window scale. More...
 
Glib::RefPtr< const IconPaintablelookup_icon (const Glib::RefPtr< const Gio::Icon > & icon, int size, int scale=1, TextDirection direction=TextDirection::NONE, IconLookupFlags flags=(IconLookupFlags) 0) const
 Looks up a icon for a desired size and window scale. More...
 
std::vector< Glib::ustring > get_icon_names () const
 Lists the names of icons in the current icon theme. More...
 
Glib::SignalProxy< void()> signal_changed ()
 
Glib::PropertyProxy< Glib::RefPtr< Gdk::Display > > property_display ()
 The display that this icon theme object is attached to. More...
 
Glib::PropertyProxy_ReadOnly< Glib::RefPtr< Gdk::Display > > property_display () const
 The display that this icon theme object is attached to. More...
 
Glib::PropertyProxy_ReadOnly< std::vector< Glib::ustring > > property_icon_names () const
 The icon names that are supported by the icon theme. More...
 
Glib::PropertyProxy< std::vector< std::string > > property_search_path ()
 The search path for this icon theme. More...
 
Glib::PropertyProxy_ReadOnly< std::vector< std::string > > property_search_path () const
 The search path for this icon theme. More...
 
Glib::PropertyProxy< std::vector< std::string > > property_resource_path ()
 Resource paths that will be looked at when looking for icons, similar to search paths. More...
 
Glib::PropertyProxy_ReadOnly< std::vector< std::string > > property_resource_path () const
 Resource paths that will be looked at when looking for icons, similar to search paths. More...
 
Glib::PropertyProxy< Glib::ustring > property_theme_name ()
 The name of the icon theme that is being used. More...
 
Glib::PropertyProxy_ReadOnly< Glib::ustring > property_theme_name () const
 The name of the icon theme that is being used. More...
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< IconThemecreate ()
 
static Glib::RefPtr< IconThemeget_for_display (const Glib::RefPtr< Gdk::Display > & display)
 Gets the icon theme object associated with display. More...
 

Protected Member Functions

 IconTheme ()
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gtk::IconThemewrap (GtkIconTheme * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Detailed Description

Looking up icons by name.

Gtk::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 selected by the user. The operation of icon themes on Linux and Unix follows the IconPaintable Theme Specification. There is a fallback icon theme, named hicolor, where applications should install their icons, but additional icon themes can be installed as operating system vendors and users choose.

In many cases, named themes are used indirectly, via Gtk::Image rather than directly, but looking up icons directly is also simple. The Gtk::IconTheme object acts as a database of all the icons in the current theme. You can create new Gtk::IconTheme objects, but it’s much more efficient to use the standard icon theme for the Gdk::Display so that the icon information is shared with other people looking up icons. Use get_for_display().

Constructor & Destructor Documentation

◆ IconTheme() [1/2]

Gtk::IconTheme::IconTheme ( IconTheme &&  src)
noexcept

◆ ~IconTheme()

Gtk::IconTheme::~IconTheme ( )
overridenoexcept

◆ IconTheme() [2/2]

Gtk::IconTheme::IconTheme ( )
protected

Member Function Documentation

◆ add_resource_path()

void Gtk::IconTheme::add_resource_path ( const std::string path)

Adds a resource path that will be looked at when looking for icons, similar to search paths.

See set_resource_path().

This function should be used to make application-specific icons available as part of the icon theme.

Parameters
pathA resource path.

◆ add_search_path()

void Gtk::IconTheme::add_search_path ( const std::string path)

Appends a directory to the search path.

See set_search_path().

Parameters
pathDirectory name to append to the icon path.

◆ create()

static Glib::RefPtr<IconTheme> Gtk::IconTheme::create ( )
static

◆ get_display() [1/2]

Glib::RefPtr<Gdk::Display> Gtk::IconTheme::get_display ( )

Returns the display that the Gtk::IconTheme object was created for.

Returns
The display of icon_theme.

◆ get_display() [2/2]

Glib::RefPtr<const Gdk::Display> Gtk::IconTheme::get_display ( ) const

Returns the display that the Gtk::IconTheme object was created for.

Returns
The display of icon_theme.

◆ get_for_display()

static Glib::RefPtr<IconTheme> Gtk::IconTheme::get_for_display ( const Glib::RefPtr< Gdk::Display > &  display)
static

Gets the icon theme object associated with display.

If this function has not previously been called for the given display, a new icon theme object will be created and associated with the display. Icon theme objects are fairly expensive to create, so using this function is usually a better choice than calling new() and setting the display yourself; by using this function a single icon theme object will be shared between users.

Parameters
displayA Gdk::Display.
Returns
A unique Gtk::IconTheme associated with the given display. This icon theme is associated with the display and can be used as long as the display is open. Do not ref or unref it.

◆ get_icon_names()

std::vector<Glib::ustring> Gtk::IconTheme::get_icon_names ( ) const

Lists the names of icons in the current icon theme.

Returns
A vector holding the names of all the icons in the theme.

◆ get_icon_sizes()

std::vector<int> Gtk::IconTheme::get_icon_sizes ( const Glib::ustring &  icon_name) const

Returns an array of integers describing the sizes at which the icon is available without scaling.

A size of -1 means that the icon is available in a scalable format. The array is zero-terminated.

Parameters
icon_nameThe name of an icon.
Returns
A newly allocated array describing the sizes at which the icon is available.

◆ get_resource_path()

std::vector<std::string> Gtk::IconTheme::get_resource_path ( ) const

Gets the current resource path.

See set_resource_path().

Returns
A list of resource paths.

◆ get_search_path()

std::vector<std::string> Gtk::IconTheme::get_search_path ( ) const

Gets the current search path.

See set_search_path().

Returns
A list of icon theme path directories.

◆ get_theme_name()

Glib::ustring Gtk::IconTheme::get_theme_name ( ) const

Gets the current icon theme name.

Returns
The current icon theme name,.

◆ get_type()

static GType Gtk::IconTheme::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ gobj() [1/2]

GtkIconTheme* Gtk::IconTheme::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GtkIconTheme* Gtk::IconTheme::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GtkIconTheme* Gtk::IconTheme::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ has_gicon()

bool Gtk::IconTheme::has_gicon ( const Glib::RefPtr< const Gio::Icon > &  gicon) const

Checks whether an icon theme includes an icon for a particular Gio::Icon.

Since gtkmm 4.2:
Parameters
giconA Gio::Icon.
Returns
true if self includes an icon for gicon.

◆ has_icon()

bool Gtk::IconTheme::has_icon ( const Glib::ustring &  icon_name) const

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

Parameters
icon_nameThe name of an icon.
Returns
true if self includes an icon for icon_name.

◆ lookup_icon() [1/6]

Glib::RefPtr<IconPaintable> Gtk::IconTheme::lookup_icon ( const Glib::RefPtr< const Gio::Icon > &  icon,
int  size,
int  scale = 1,
TextDirection  direction = TextDirection::NONE,
IconLookupFlags  flags = (IconLookupFlags) 0 
)

Looks up a icon for a desired size and window scale.

The icon can then be rendered by using it as a Gdk::Paintable, or you can get information such as the filename and size.

Parameters
iconThe Gio::Icon to look up.
sizeDesired icon size.
scaleThe desired scale.
directionText direction the icon will be displayed in.
flagsFlags modifying the behavior of the icon lookup.
Returns
A Gtk::IconPaintable containing information about the icon. Unref with Glib::object_unref().

◆ lookup_icon() [2/6]

Glib::RefPtr<const IconPaintable> Gtk::IconTheme::lookup_icon ( const Glib::RefPtr< const Gio::Icon > &  icon,
int  size,
int  scale = 1,
TextDirection  direction = TextDirection::NONE,
IconLookupFlags  flags = (IconLookupFlags) 0 
) const

Looks up a icon for a desired size and window scale.

The icon can then be rendered by using it as a Gdk::Paintable, or you can get information such as the filename and size.

Parameters
iconThe Gio::Icon to look up.
sizeDesired icon size.
scaleThe desired scale.
directionText direction the icon will be displayed in.
flagsFlags modifying the behavior of the icon lookup.
Returns
A Gtk::IconPaintable containing information about the icon. Unref with Glib::object_unref().

◆ lookup_icon() [3/6]

Glib::RefPtr<IconPaintable> Gtk::IconTheme::lookup_icon ( const Glib::ustring &  icon_name,
const std::vector< Glib::ustring > &  fallbacks,
int  size,
int  scale = 1,
TextDirection  direction = TextDirection::NONE,
IconLookupFlags  flags = (IconLookupFlags) 0 
)

Looks up a named icon for a desired size and window scale, returning a Gtk::IconPaintable.

The icon can then be rendered by using it as a Gdk::Paintable, or you can get information such as the filename and size.

If the available icon_name is not available and fallbacks are provided, they will be tried in order.

If no matching icon is found, then a paintable that renders the "missing icon" icon is returned. If you need to do something else for missing icons you need to use has_icon().

Note that you probably want to listen for icon theme changes and update the icon. This is usually done by overriding the GtkWidgetClass.css-changed() function.

Parameters
icon_nameThe name of the icon to lookup.
sizeDesired icon size.
scaleThe window scale this will be displayed on.
directionText direction the icon will be displayed in.
flagsFlags modifying the behavior of the icon lookup.
Returns
A Gtk::IconPaintable object containing the icon.

◆ lookup_icon() [4/6]

Glib::RefPtr<const IconPaintable> Gtk::IconTheme::lookup_icon ( const Glib::ustring &  icon_name,
const std::vector< Glib::ustring > &  fallbacks,
int  size,
int  scale = 1,
TextDirection  direction = TextDirection::NONE,
IconLookupFlags  flags = (IconLookupFlags) 0 
) const

Looks up a named icon for a desired size and window scale, returning a Gtk::IconPaintable.

The icon can then be rendered by using it as a Gdk::Paintable, or you can get information such as the filename and size.

If the available icon_name is not available and fallbacks are provided, they will be tried in order.

If no matching icon is found, then a paintable that renders the "missing icon" icon is returned. If you need to do something else for missing icons you need to use has_icon().

Note that you probably want to listen for icon theme changes and update the icon. This is usually done by overriding the GtkWidgetClass.css-changed() function.

Parameters
icon_nameThe name of the icon to lookup.
sizeDesired icon size.
scaleThe window scale this will be displayed on.
directionText direction the icon will be displayed in.
flagsFlags modifying the behavior of the icon lookup.
Returns
A Gtk::IconPaintable object containing the icon.

◆ lookup_icon() [5/6]

Glib::RefPtr<IconPaintable> Gtk::IconTheme::lookup_icon ( const Glib::ustring &  icon_name,
int  size,
int  scale = 1,
TextDirection  direction = TextDirection::NONE,
IconLookupFlags  flags = (IconLookupFlags) 0 
)

A lookup_icon() convenience overload.

◆ lookup_icon() [6/6]

Glib::RefPtr<const IconPaintable> Gtk::IconTheme::lookup_icon ( const Glib::ustring &  icon_name,
int  size,
int  scale = 1,
TextDirection  direction = TextDirection::NONE,
IconLookupFlags  flags = (IconLookupFlags) 0 
) const

A lookup_icon() convenience overload.

◆ operator=()

IconTheme& Gtk::IconTheme::operator= ( IconTheme &&  src)
noexcept

◆ property_display() [1/2]

Glib::PropertyProxy< Glib::RefPtr<Gdk::Display> > Gtk::IconTheme::property_display ( )

The display that this icon theme object is attached to.

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_display() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::RefPtr<Gdk::Display> > Gtk::IconTheme::property_display ( ) const

The display that this icon theme object is attached to.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_icon_names()

Glib::PropertyProxy_ReadOnly< std::vector<Glib::ustring> > Gtk::IconTheme::property_icon_names ( ) const

The icon names that are supported by the icon theme.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_resource_path() [1/2]

Glib::PropertyProxy< std::vector<std::string> > Gtk::IconTheme::property_resource_path ( )

Resource paths that will be looked at when looking for icons, similar to search paths.

The resources are considered as part of the hicolor icon theme and must be located in subdirectories that are defined in the hicolor icon theme, such as @a path/16x16/actions/run.png. Icons that are directly placed in the resource path instead of a subdirectory are also considered as ultimate fallback.

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_resource_path() [2/2]

Glib::PropertyProxy_ReadOnly< std::vector<std::string> > Gtk::IconTheme::property_resource_path ( ) const

Resource paths that will be looked at when looking for icons, similar to search paths.

The resources are considered as part of the hicolor icon theme and must be located in subdirectories that are defined in the hicolor icon theme, such as @a path/16x16/actions/run.png. Icons that are directly placed in the resource path instead of a subdirectory are also considered as ultimate fallback.

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_search_path() [1/2]

Glib::PropertyProxy< std::vector<std::string> > Gtk::IconTheme::property_search_path ( )

The search path for this icon theme.

When looking for icons, GTK will search for a subdirectory of one or more of the directories in the search path with the same name as the icon theme containing an index.theme file. (Themes from multiple of the path elements are combined to allow themes to be extended by adding icons in the user’s home directory.)

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_search_path() [2/2]

Glib::PropertyProxy_ReadOnly< std::vector<std::string> > Gtk::IconTheme::property_search_path ( ) const

The search path for this icon theme.

When looking for icons, GTK will search for a subdirectory of one or more of the directories in the search path with the same name as the icon theme containing an index.theme file. (Themes from multiple of the path elements are combined to allow themes to be extended by adding icons in the user’s home directory.)

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ property_theme_name() [1/2]

Glib::PropertyProxy< Glib::ustring > Gtk::IconTheme::property_theme_name ( )

The name of the icon theme that is being used.

Unless set to a different value, this will be the value of the GtkSettings:gtk-icon-theme-name property of the Gtk::Settings object associated to the display of the icontheme object.

Default value: ""

Returns
A PropertyProxy that allows you to get or set the value of the property, or receive notification when the value of the property changes.

◆ property_theme_name() [2/2]

Glib::PropertyProxy_ReadOnly< Glib::ustring > Gtk::IconTheme::property_theme_name ( ) const

The name of the icon theme that is being used.

Unless set to a different value, this will be the value of the GtkSettings:gtk-icon-theme-name property of the Gtk::Settings object associated to the display of the icontheme object.

Default value: ""

Returns
A PropertyProxy_ReadOnly that allows you to get the value of the property, or receive notification when the value of the property changes.

◆ set_resource_path()

void Gtk::IconTheme::set_resource_path ( const std::vector< std::string > &  path)

Sets the resource paths that will be looked at when looking for icons, similar to search paths.

The resources are considered as part of the hicolor icon theme and must be located in subdirectories that are defined in the hicolor icon theme, such as @a path/16x16/actions/run.png or @a path/scalable/actions/run.svg.

Icons that are directly placed in the resource path instead of a subdirectory are also considered as ultimate fallback, but they are treated like unthemed icons.

Parameters
pathnullptr-terminated array of resource paths that are searched for icons.

◆ set_search_path()

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

Sets the search path for the icon theme object.

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 containing an index.theme file. (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 fallback icon theme, which is called hicolor, rather than directly on the icon path.)

Parameters
pathnullptr-terminated array of directories that are searched for icon themes.

◆ set_theme_name()

void Gtk::IconTheme::set_theme_name ( const Glib::ustring &  theme_name)

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

This function cannot be called on the icon theme objects returned from get_for_display().

Parameters
theme_nameName of icon theme to use instead of configured theme, or nullptr to unset a previously set custom theme.

◆ signal_changed()

Glib::SignalProxy<void()> Gtk::IconTheme::signal_changed ( )
Slot Prototype:
void on_my_changed()

Flags: Run Last

Emitted when the icon theme changes.

This can happen becuase current icon theme is switched or because GTK detects that a change has occurred in the contents of the current icon theme.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gtk::IconTheme > wrap ( GtkIconTheme *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.