Skip to main content

gtk/auto/
icon_theme.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{IconInfo, IconLookupFlags, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// [`IconTheme`][crate::IconTheme] provides a facility for looking up icons by name
16    /// and size. The main reason for using a name rather than simply
17    /// providing a filename is to allow different icons to be used
18    /// depending on what “icon theme” is selected
19    /// by the user. The operation of icon themes on Linux and Unix
20    /// follows the [Icon Theme Specification](http://www.freedesktop.org/Standards/icon-theme-spec)
21    /// There is a fallback icon theme, named `hicolor`, where applications
22    /// should install their icons, but additional icon themes can be installed
23    /// as operating system vendors and users choose.
24    ///
25    /// Named icons are similar to the deprecated [Stock Items][gtkstock],
26    /// and the distinction between the two may be a bit confusing.
27    /// A few things to keep in mind:
28    ///
29    /// - Stock images usually are used in conjunction with
30    ///  [Stock Items][gtkstock], such as `GTK_STOCK_OK` or
31    ///  `GTK_STOCK_OPEN`. Named icons are easier to set up and therefore
32    ///  are more useful for new icons that an application wants to
33    ///  add, such as application icons or window icons.
34    ///
35    /// - Stock images can only be loaded at the symbolic sizes defined
36    ///  by the [`IconSize`][crate::IconSize] enumeration, or by custom sizes defined
37    ///  by `gtk_icon_size_register()`, while named icons are more flexible
38    ///  and any pixel size can be specified.
39    ///
40    /// - Because stock images are closely tied to stock items, and thus
41    ///  to actions in the user interface, stock images may come in
42    ///  multiple variants for different widget states or writing
43    ///  directions.
44    ///
45    /// A good rule of thumb is that if there is a stock image for what
46    /// you want to use, use it, otherwise use a named icon. It turns
47    /// out that internally stock images are generally defined in
48    /// terms of one or more named icons. (An example of the
49    /// more than one case is icons that depend on writing direction;
50    /// `GTK_STOCK_GO_FORWARD` uses the two themed icons
51    /// “gtk-stock-go-forward-ltr” and “gtk-stock-go-forward-rtl”.)
52    ///
53    /// In many cases, named themes are used indirectly, via [`Image`][crate::Image]
54    /// or stock items, rather than directly, but looking up icons
55    /// directly is also simple. The [`IconTheme`][crate::IconTheme] object acts
56    /// as a database of all the icons in the current theme. You
57    /// can create new [`IconTheme`][crate::IconTheme] objects, but it’s much more
58    /// efficient to use the standard icon theme for the [`gdk::Screen`][crate::gdk::Screen]
59    /// so that the icon information is shared with other people
60    /// looking up icons.
61    ///
62    ///
63    /// **⚠️ The following code is in C ⚠️**
64    ///
65    /// ```C
66    /// GError *error = NULL;
67    /// GtkIconTheme *icon_theme;
68    /// GdkPixbuf *pixbuf;
69    ///
70    /// icon_theme = gtk_icon_theme_get_default ();
71    /// pixbuf = gtk_icon_theme_load_icon (icon_theme,
72    ///                                    "my-icon-name", // icon name
73    ///                                    48, // icon size
74    ///                                    0,  // flags
75    ///                                    &error);
76    /// if (!pixbuf)
77    ///   {
78    ///     g_warning ("Couldn’t load icon: %s", error->message);
79    ///     g_error_free (error);
80    ///   }
81    /// else
82    ///   {
83    ///     // Use the pixbuf
84    ///     g_object_unref (pixbuf);
85    ///   }
86    /// ```
87    ///
88    /// ## Signals
89    ///
90    ///
91    /// #### `changed`
92    ///  Emitted when the current icon theme is switched or GTK+ detects
93    /// that a change has occurred in the contents of the current
94    /// icon theme.
95    ///
96    ///
97    ///
98    /// # Implements
99    ///
100    /// [`IconThemeExt`][trait@crate::prelude::IconThemeExt], [`trait@glib::ObjectExt`]
101    #[doc(alias = "GtkIconTheme")]
102    pub struct IconTheme(Object<ffi::GtkIconTheme, ffi::GtkIconThemeClass>);
103
104    match fn {
105        type_ => || ffi::gtk_icon_theme_get_type(),
106    }
107}
108
109impl IconTheme {
110    pub const NONE: Option<&'static IconTheme> = None;
111
112    /// Creates a new icon theme object. Icon theme objects are used
113    /// to lookup up an icon by name in a particular icon theme.
114    /// Usually, you’ll want to use [`default()`][Self::default()]
115    /// or [`for_screen()`][Self::for_screen()] rather than creating
116    /// a new icon theme object for scratch.
117    ///
118    /// # Returns
119    ///
120    /// the newly created [`IconTheme`][crate::IconTheme] object.
121    #[doc(alias = "gtk_icon_theme_new")]
122    pub fn new() -> IconTheme {
123        assert_initialized_main_thread!();
124        unsafe { from_glib_full(ffi::gtk_icon_theme_new()) }
125    }
126
127    /// Gets the icon theme for the default screen. See
128    /// [`for_screen()`][Self::for_screen()].
129    ///
130    /// # Returns
131    ///
132    /// A unique [`IconTheme`][crate::IconTheme] associated with
133    ///  the default screen. This icon theme is associated with
134    ///  the screen and can be used as long as the screen
135    ///  is open. Do not ref or unref it.
136    #[doc(alias = "gtk_icon_theme_get_default")]
137    #[doc(alias = "get_default")]
138    #[allow(clippy::should_implement_trait)]
139    pub fn default() -> Option<IconTheme> {
140        assert_initialized_main_thread!();
141        unsafe { from_glib_none(ffi::gtk_icon_theme_get_default()) }
142    }
143
144    /// Gets the icon theme object associated with `screen`; if this
145    /// function has not previously been called for the given
146    /// screen, a new icon theme object will be created and
147    /// associated with the screen. Icon theme objects are
148    /// fairly expensive to create, so using this function
149    /// is usually a better choice than calling than [`new()`][Self::new()]
150    /// and setting the screen yourself; by using this function
151    /// a single icon theme object will be shared between users.
152    /// ## `screen`
153    /// a [`gdk::Screen`][crate::gdk::Screen]
154    ///
155    /// # Returns
156    ///
157    /// A unique [`IconTheme`][crate::IconTheme] associated with
158    ///  the given screen. This icon theme is associated with
159    ///  the screen and can be used as long as the screen
160    ///  is open. Do not ref or unref it.
161    #[doc(alias = "gtk_icon_theme_get_for_screen")]
162    #[doc(alias = "get_for_screen")]
163    pub fn for_screen(screen: &gdk::Screen) -> Option<IconTheme> {
164        assert_initialized_main_thread!();
165        unsafe { from_glib_none(ffi::gtk_icon_theme_get_for_screen(screen.to_glib_none().0)) }
166    }
167}
168
169impl Default for IconTheme {
170    fn default() -> Self {
171        Self::new()
172    }
173}
174
175/// Trait containing all [`struct@IconTheme`] methods.
176///
177/// # Implementors
178///
179/// [`IconTheme`][struct@crate::IconTheme]
180pub trait IconThemeExt: IsA<IconTheme> + 'static {
181    /// Adds a resource path that will be looked at when looking
182    /// for icons, similar to search paths.
183    ///
184    /// This function should be used to make application-specific icons
185    /// available as part of the icon theme.
186    ///
187    /// The resources are considered as part of the hicolor icon theme
188    /// and must be located in subdirectories that are defined in the
189    /// hicolor icon theme, such as ``path`/16x16/actions/run.png`.
190    /// Icons that are directly placed in the resource path instead
191    /// of a subdirectory are also considered as ultimate fallback.
192    /// ## `path`
193    /// a resource path
194    #[doc(alias = "gtk_icon_theme_add_resource_path")]
195    fn add_resource_path(&self, path: &str) {
196        unsafe {
197            ffi::gtk_icon_theme_add_resource_path(
198                self.as_ref().to_glib_none().0,
199                path.to_glib_none().0,
200            );
201        }
202    }
203
204    /// Appends a directory to the search path.
205    /// See `gtk_icon_theme_set_search_path()`.
206    /// ## `path`
207    /// directory name to append to the icon path
208    #[doc(alias = "gtk_icon_theme_append_search_path")]
209    fn append_search_path(&self, path: impl AsRef<std::path::Path>) {
210        unsafe {
211            ffi::gtk_icon_theme_append_search_path(
212                self.as_ref().to_glib_none().0,
213                path.as_ref().to_glib_none().0,
214            );
215        }
216    }
217
218    /// Gets the name of an icon that is representative of the
219    /// current theme (for instance, to use when presenting
220    /// a list of themes to the user.)
221    ///
222    /// # Returns
223    ///
224    /// the name of an example icon or [`None`].
225    ///  Free with `g_free()`.
226    #[doc(alias = "gtk_icon_theme_get_example_icon_name")]
227    #[doc(alias = "get_example_icon_name")]
228    fn example_icon_name(&self) -> Option<glib::GString> {
229        unsafe {
230            from_glib_full(ffi::gtk_icon_theme_get_example_icon_name(
231                self.as_ref().to_glib_none().0,
232            ))
233        }
234    }
235
236    /// Checks whether an icon theme includes an icon
237    /// for a particular name.
238    /// ## `icon_name`
239    /// the name of an icon
240    ///
241    /// # Returns
242    ///
243    /// [`true`] if `self` includes an
244    ///  icon for `icon_name`.
245    #[doc(alias = "gtk_icon_theme_has_icon")]
246    fn has_icon(&self, icon_name: &str) -> bool {
247        unsafe {
248            from_glib(ffi::gtk_icon_theme_has_icon(
249                self.as_ref().to_glib_none().0,
250                icon_name.to_glib_none().0,
251            ))
252        }
253    }
254
255    /// Gets the list of contexts available within the current
256    /// hierarchy of icon themes.
257    /// See [`list_icons()`][Self::list_icons()] for details about contexts.
258    ///
259    /// # Returns
260    ///
261    /// a `GList` list
262    ///  holding the names of all the contexts in the theme. You must first
263    ///  free each element in the list with `g_free()`, then free the list
264    ///  itself with `g_list_free()`.
265    #[doc(alias = "gtk_icon_theme_list_contexts")]
266    fn list_contexts(&self) -> Vec<glib::GString> {
267        unsafe {
268            FromGlibPtrContainer::from_glib_full(ffi::gtk_icon_theme_list_contexts(
269                self.as_ref().to_glib_none().0,
270            ))
271        }
272    }
273
274    /// Lists the icons in the current icon theme. Only a subset
275    /// of the icons can be listed by providing a context string.
276    /// The set of values for the context string is system dependent,
277    /// but will typically include such values as “Applications” and
278    /// “MimeTypes”. Contexts are explained in the
279    /// [Icon Theme Specification](http://www.freedesktop.org/wiki/Specifications/icon-theme-spec).
280    /// The standard contexts are listed in the
281    /// [Icon Naming Specification](http://www.freedesktop.org/wiki/Specifications/icon-naming-spec).
282    /// Also see [`list_contexts()`][Self::list_contexts()].
283    /// ## `context`
284    /// a string identifying a particular type of
285    ///  icon, or [`None`] to list all icons.
286    ///
287    /// # Returns
288    ///
289    /// a `GList` list
290    ///  holding the names of all the icons in the theme. You must
291    ///  first free each element in the list with `g_free()`, then
292    ///  free the list itself with `g_list_free()`.
293    #[doc(alias = "gtk_icon_theme_list_icons")]
294    fn list_icons(&self, context: Option<&str>) -> Vec<glib::GString> {
295        unsafe {
296            FromGlibPtrContainer::from_glib_full(ffi::gtk_icon_theme_list_icons(
297                self.as_ref().to_glib_none().0,
298                context.to_glib_none().0,
299            ))
300        }
301    }
302
303    /// Looks up an icon in an icon theme, scales it to the given size
304    /// and renders it into a pixbuf. This is a convenience function;
305    /// if more details about the icon are needed, use
306    /// [`lookup_icon()`][Self::lookup_icon()] followed by [`IconInfo::load_icon()`][crate::IconInfo::load_icon()].
307    ///
308    /// Note that you probably want to listen for icon theme changes and
309    /// update the icon. This is usually done by connecting to the
310    /// GtkWidget::style-set signal. If for some reason you do not want to
311    /// update the icon when the icon theme changes, you should consider
312    /// using `gdk_pixbuf_copy()` to make a private copy of the pixbuf
313    /// returned by this function. Otherwise GTK+ may need to keep the old
314    /// icon theme loaded, which would be a waste of memory.
315    /// ## `icon_name`
316    /// the name of the icon to lookup
317    /// ## `size`
318    /// the desired icon size. The resulting icon may not be
319    ///  exactly this size; see [`IconInfo::load_icon()`][crate::IconInfo::load_icon()].
320    /// ## `flags`
321    /// flags modifying the behavior of the icon lookup
322    ///
323    /// # Returns
324    ///
325    /// the rendered icon; this may be
326    ///  a newly created icon or a new reference to an internal icon, so
327    ///  you must not modify the icon. Use `g_object_unref()` to release
328    ///  your reference to the icon. [`None`] if the icon isn’t found.
329    #[doc(alias = "gtk_icon_theme_load_icon")]
330    fn load_icon(
331        &self,
332        icon_name: &str,
333        size: i32,
334        flags: IconLookupFlags,
335    ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error> {
336        unsafe {
337            let mut error = std::ptr::null_mut();
338            let ret = ffi::gtk_icon_theme_load_icon(
339                self.as_ref().to_glib_none().0,
340                icon_name.to_glib_none().0,
341                size,
342                flags.into_glib(),
343                &mut error,
344            );
345            if error.is_null() {
346                Ok(from_glib_full(ret))
347            } else {
348                Err(from_glib_full(error))
349            }
350        }
351    }
352
353    /// Looks up an icon in an icon theme for a particular window scale,
354    /// scales it to the given size and renders it into a pixbuf. This is a
355    /// convenience function; if more details about the icon are needed,
356    /// use [`lookup_icon()`][Self::lookup_icon()] followed by
357    /// [`IconInfo::load_icon()`][crate::IconInfo::load_icon()].
358    ///
359    /// Note that you probably want to listen for icon theme changes and
360    /// update the icon. This is usually done by connecting to the
361    /// GtkWidget::style-set signal. If for some reason you do not want to
362    /// update the icon when the icon theme changes, you should consider
363    /// using `gdk_pixbuf_copy()` to make a private copy of the pixbuf
364    /// returned by this function. Otherwise GTK+ may need to keep the old
365    /// icon theme loaded, which would be a waste of memory.
366    /// ## `icon_name`
367    /// the name of the icon to lookup
368    /// ## `size`
369    /// the desired icon size. The resulting icon may not be
370    ///  exactly this size; see [`IconInfo::load_icon()`][crate::IconInfo::load_icon()].
371    /// ## `scale`
372    /// desired scale
373    /// ## `flags`
374    /// flags modifying the behavior of the icon lookup
375    ///
376    /// # Returns
377    ///
378    /// the rendered icon; this may be
379    ///  a newly created icon or a new reference to an internal icon, so
380    ///  you must not modify the icon. Use `g_object_unref()` to release
381    ///  your reference to the icon. [`None`] if the icon isn’t found.
382    #[doc(alias = "gtk_icon_theme_load_icon_for_scale")]
383    fn load_icon_for_scale(
384        &self,
385        icon_name: &str,
386        size: i32,
387        scale: i32,
388        flags: IconLookupFlags,
389    ) -> Result<Option<gdk_pixbuf::Pixbuf>, glib::Error> {
390        unsafe {
391            let mut error = std::ptr::null_mut();
392            let ret = ffi::gtk_icon_theme_load_icon_for_scale(
393                self.as_ref().to_glib_none().0,
394                icon_name.to_glib_none().0,
395                size,
396                scale,
397                flags.into_glib(),
398                &mut error,
399            );
400            if error.is_null() {
401                Ok(from_glib_full(ret))
402            } else {
403                Err(from_glib_full(error))
404            }
405        }
406    }
407
408    /// Looks up an icon in an icon theme for a particular window scale,
409    /// scales it to the given size and renders it into a cairo surface. This is a
410    /// convenience function; if more details about the icon are needed,
411    /// use [`lookup_icon()`][Self::lookup_icon()] followed by
412    /// [`IconInfo::load_surface()`][crate::IconInfo::load_surface()].
413    ///
414    /// Note that you probably want to listen for icon theme changes and
415    /// update the icon. This is usually done by connecting to the
416    /// GtkWidget::style-set signal.
417    /// ## `icon_name`
418    /// the name of the icon to lookup
419    /// ## `size`
420    /// the desired icon size. The resulting icon may not be
421    ///  exactly this size; see [`IconInfo::load_icon()`][crate::IconInfo::load_icon()].
422    /// ## `scale`
423    /// desired scale
424    /// ## `for_window`
425    /// [`gdk::Window`][crate::gdk::Window] to optimize drawing for, or [`None`]
426    /// ## `flags`
427    /// flags modifying the behavior of the icon lookup
428    ///
429    /// # Returns
430    ///
431    /// the rendered icon; this may be
432    ///  a newly created icon or a new reference to an internal icon, so
433    ///  you must not modify the icon. Use `cairo_surface_destroy()` to
434    ///  release your reference to the icon. [`None`] if the icon isn’t
435    ///  found.
436    #[doc(alias = "gtk_icon_theme_load_surface")]
437    fn load_surface(
438        &self,
439        icon_name: &str,
440        size: i32,
441        scale: i32,
442        for_window: Option<&gdk::Window>,
443        flags: IconLookupFlags,
444    ) -> Result<Option<cairo::Surface>, glib::Error> {
445        unsafe {
446            let mut error = std::ptr::null_mut();
447            let ret = ffi::gtk_icon_theme_load_surface(
448                self.as_ref().to_glib_none().0,
449                icon_name.to_glib_none().0,
450                size,
451                scale,
452                for_window.to_glib_none().0,
453                flags.into_glib(),
454                &mut error,
455            );
456            if error.is_null() {
457                Ok(from_glib_full(ret))
458            } else {
459                Err(from_glib_full(error))
460            }
461        }
462    }
463
464    /// Looks up an icon and returns a [`IconInfo`][crate::IconInfo] containing information
465    /// such as the filename of the icon. The icon can then be rendered
466    /// into a pixbuf using [`IconInfo::load_icon()`][crate::IconInfo::load_icon()].
467    ///
468    /// When rendering on displays with high pixel densities you should not
469    /// use a `size` multiplied by the scaling factor returned by functions
470    /// like [`Window::scale_factor()`][crate::gdk::Window::scale_factor()]. Instead, you should use
471    /// [`lookup_by_gicon_for_scale()`][Self::lookup_by_gicon_for_scale()], as the assets loaded
472    /// for a given scaling factor may be different.
473    /// ## `icon`
474    /// the [`gio::Icon`][crate::gio::Icon] to look up
475    /// ## `size`
476    /// desired icon size
477    /// ## `flags`
478    /// flags modifying the behavior of the icon lookup
479    ///
480    /// # Returns
481    ///
482    /// a [`IconInfo`][crate::IconInfo] containing
483    ///  information about the icon, or [`None`] if the icon wasn’t
484    ///  found. Unref with `g_object_unref()`
485    #[doc(alias = "gtk_icon_theme_lookup_by_gicon")]
486    fn lookup_by_gicon(
487        &self,
488        icon: &impl IsA<gio::Icon>,
489        size: i32,
490        flags: IconLookupFlags,
491    ) -> Option<IconInfo> {
492        unsafe {
493            from_glib_full(ffi::gtk_icon_theme_lookup_by_gicon(
494                self.as_ref().to_glib_none().0,
495                icon.as_ref().to_glib_none().0,
496                size,
497                flags.into_glib(),
498            ))
499        }
500    }
501
502    /// Looks up an icon and returns a [`IconInfo`][crate::IconInfo] containing information
503    /// such as the filename of the icon. The icon can then be rendered into
504    /// a pixbuf using [`IconInfo::load_icon()`][crate::IconInfo::load_icon()].
505    /// ## `icon`
506    /// the [`gio::Icon`][crate::gio::Icon] to look up
507    /// ## `size`
508    /// desired icon size
509    /// ## `scale`
510    /// the desired scale
511    /// ## `flags`
512    /// flags modifying the behavior of the icon lookup
513    ///
514    /// # Returns
515    ///
516    /// a [`IconInfo`][crate::IconInfo] containing
517    ///  information about the icon, or [`None`] if the icon wasn’t
518    ///  found. Unref with `g_object_unref()`
519    #[doc(alias = "gtk_icon_theme_lookup_by_gicon_for_scale")]
520    fn lookup_by_gicon_for_scale(
521        &self,
522        icon: &impl IsA<gio::Icon>,
523        size: i32,
524        scale: i32,
525        flags: IconLookupFlags,
526    ) -> Option<IconInfo> {
527        unsafe {
528            from_glib_full(ffi::gtk_icon_theme_lookup_by_gicon_for_scale(
529                self.as_ref().to_glib_none().0,
530                icon.as_ref().to_glib_none().0,
531                size,
532                scale,
533                flags.into_glib(),
534            ))
535        }
536    }
537
538    /// Looks up a named icon and returns a [`IconInfo`][crate::IconInfo] containing
539    /// information such as the filename of the icon. The icon
540    /// can then be rendered into a pixbuf using
541    /// [`IconInfo::load_icon()`][crate::IconInfo::load_icon()]. ([`load_icon()`][Self::load_icon()]
542    /// combines these two steps if all you need is the pixbuf.)
543    ///
544    /// When rendering on displays with high pixel densities you should not
545    /// use a `size` multiplied by the scaling factor returned by functions
546    /// like [`Window::scale_factor()`][crate::gdk::Window::scale_factor()]. Instead, you should use
547    /// [`lookup_icon_for_scale()`][Self::lookup_icon_for_scale()], as the assets loaded
548    /// for a given scaling factor may be different.
549    /// ## `icon_name`
550    /// the name of the icon to lookup
551    /// ## `size`
552    /// desired icon size
553    /// ## `flags`
554    /// flags modifying the behavior of the icon lookup
555    ///
556    /// # Returns
557    ///
558    /// a [`IconInfo`][crate::IconInfo] object
559    ///  containing information about the icon, or [`None`] if the
560    ///  icon wasn’t found.
561    #[doc(alias = "gtk_icon_theme_lookup_icon")]
562    fn lookup_icon(&self, icon_name: &str, size: i32, flags: IconLookupFlags) -> Option<IconInfo> {
563        unsafe {
564            from_glib_full(ffi::gtk_icon_theme_lookup_icon(
565                self.as_ref().to_glib_none().0,
566                icon_name.to_glib_none().0,
567                size,
568                flags.into_glib(),
569            ))
570        }
571    }
572
573    /// Looks up a named icon for a particular window scale and returns a
574    /// [`IconInfo`][crate::IconInfo] containing information such as the filename of the
575    /// icon. The icon can then be rendered into a pixbuf using
576    /// [`IconInfo::load_icon()`][crate::IconInfo::load_icon()]. ([`load_icon()`][Self::load_icon()] combines
577    /// these two steps if all you need is the pixbuf.)
578    /// ## `icon_name`
579    /// the name of the icon to lookup
580    /// ## `size`
581    /// desired icon size
582    /// ## `scale`
583    /// the desired scale
584    /// ## `flags`
585    /// flags modifying the behavior of the icon lookup
586    ///
587    /// # Returns
588    ///
589    /// a [`IconInfo`][crate::IconInfo] object
590    ///  containing information about the icon, or [`None`] if the
591    ///  icon wasn’t found.
592    #[doc(alias = "gtk_icon_theme_lookup_icon_for_scale")]
593    fn lookup_icon_for_scale(
594        &self,
595        icon_name: &str,
596        size: i32,
597        scale: i32,
598        flags: IconLookupFlags,
599    ) -> Option<IconInfo> {
600        unsafe {
601            from_glib_full(ffi::gtk_icon_theme_lookup_icon_for_scale(
602                self.as_ref().to_glib_none().0,
603                icon_name.to_glib_none().0,
604                size,
605                scale,
606                flags.into_glib(),
607            ))
608        }
609    }
610
611    /// Prepends a directory to the search path.
612    /// See `gtk_icon_theme_set_search_path()`.
613    /// ## `path`
614    /// directory name to prepend to the icon path
615    #[doc(alias = "gtk_icon_theme_prepend_search_path")]
616    fn prepend_search_path(&self, path: impl AsRef<std::path::Path>) {
617        unsafe {
618            ffi::gtk_icon_theme_prepend_search_path(
619                self.as_ref().to_glib_none().0,
620                path.as_ref().to_glib_none().0,
621            );
622        }
623    }
624
625    /// Checks to see if the icon theme has changed; if it has, any
626    /// currently cached information is discarded and will be reloaded
627    /// next time `self` is accessed.
628    ///
629    /// # Returns
630    ///
631    /// [`true`] if the icon theme has changed and needed
632    ///  to be reloaded.
633    #[doc(alias = "gtk_icon_theme_rescan_if_needed")]
634    fn rescan_if_needed(&self) -> bool {
635        unsafe {
636            from_glib(ffi::gtk_icon_theme_rescan_if_needed(
637                self.as_ref().to_glib_none().0,
638            ))
639        }
640    }
641
642    /// Sets the name of the icon theme that the [`IconTheme`][crate::IconTheme] object uses
643    /// overriding system configuration. This function cannot be called
644    /// on the icon theme objects returned from [`IconTheme::default()`][crate::IconTheme::default()]
645    /// and [`IconTheme::for_screen()`][crate::IconTheme::for_screen()].
646    /// ## `theme_name`
647    /// name of icon theme to use instead of
648    ///  configured theme, or [`None`] to unset a previously set custom theme
649    #[doc(alias = "gtk_icon_theme_set_custom_theme")]
650    fn set_custom_theme(&self, theme_name: Option<&str>) {
651        unsafe {
652            ffi::gtk_icon_theme_set_custom_theme(
653                self.as_ref().to_glib_none().0,
654                theme_name.to_glib_none().0,
655            );
656        }
657    }
658
659    /// Sets the screen for an icon theme; the screen is used
660    /// to track the user’s currently configured icon theme,
661    /// which might be different for different screens.
662    /// ## `screen`
663    /// a [`gdk::Screen`][crate::gdk::Screen]
664    #[doc(alias = "gtk_icon_theme_set_screen")]
665    fn set_screen(&self, screen: &gdk::Screen) {
666        unsafe {
667            ffi::gtk_icon_theme_set_screen(self.as_ref().to_glib_none().0, screen.to_glib_none().0);
668        }
669    }
670
671    /// Emitted when the current icon theme is switched or GTK+ detects
672    /// that a change has occurred in the contents of the current
673    /// icon theme.
674    #[doc(alias = "changed")]
675    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
676        unsafe extern "C" fn changed_trampoline<P: IsA<IconTheme>, F: Fn(&P) + 'static>(
677            this: *mut ffi::GtkIconTheme,
678            f: glib::ffi::gpointer,
679        ) {
680            unsafe {
681                let f: &F = &*(f as *const F);
682                f(IconTheme::from_glib_borrow(this).unsafe_cast_ref())
683            }
684        }
685        unsafe {
686            let f: Box_<F> = Box_::new(f);
687            connect_raw(
688                self.as_ptr() as *mut _,
689                c"changed".as_ptr(),
690                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
691                    changed_trampoline::<Self, F> as *const (),
692                )),
693                Box_::into_raw(f),
694            )
695        }
696    }
697}
698
699impl<O: IsA<IconTheme>> IconThemeExt for O {}