1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// This file was generated by gir (6bcd52a) from gir-files (1069259)
// DO NOT EDIT

use IconSource;
use StyleContext;
#[cfg(feature = "v3_10")]
use cairo;
use ffi;
#[cfg(feature = "v3_10")]
use gdk;
use gdk_pixbuf;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    pub struct IconSet(Shared<ffi::GtkIconSet>);

    match fn {
        ref => |ptr| ffi::gtk_icon_set_ref(ptr),
        unref => |ptr| ffi::gtk_icon_set_unref(ptr),
        get_type => || ffi::gtk_icon_set_get_type(),
    }
}

impl IconSet {
    pub fn new() -> IconSet {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_icon_set_new())
        }
    }

    pub fn new_from_pixbuf(pixbuf: &gdk_pixbuf::Pixbuf) -> IconSet {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_icon_set_new_from_pixbuf(pixbuf.to_glib_none().0))
        }
    }

    pub fn add_source(&self, source: &IconSource) {
        unsafe {
            ffi::gtk_icon_set_add_source(self.to_glib_none().0, source.to_glib_none().0);
        }
    }

    pub fn copy(&self) -> Option<IconSet> {
        unsafe {
            from_glib_full(ffi::gtk_icon_set_copy(self.to_glib_none().0))
        }
    }

    pub fn get_sizes(&self) -> Vec<i32> {
        unsafe {
            let mut sizes = ptr::null_mut();
            let mut n_sizes = mem::uninitialized();
            ffi::gtk_icon_set_get_sizes(self.to_glib_none().0, &mut sizes, &mut n_sizes);
            FromGlibContainer::from_glib_full_num(sizes, n_sizes as usize)
        }
    }

    pub fn render_icon_pixbuf(&self, context: &StyleContext, size: i32) -> Option<gdk_pixbuf::Pixbuf> {
        unsafe {
            from_glib_full(ffi::gtk_icon_set_render_icon_pixbuf(self.to_glib_none().0, context.to_glib_none().0, size))
        }
    }

    #[cfg(feature = "v3_10")]
    pub fn render_icon_surface<'a, P: Into<Option<&'a gdk::Window>>>(&self, context: &StyleContext, size: i32, scale: i32, for_window: P) -> Option<cairo::Surface> {
        let for_window = for_window.into();
        let for_window = for_window.to_glib_none();
        unsafe {
            from_glib_full(ffi::gtk_icon_set_render_icon_surface(self.to_glib_none().0, context.to_glib_none().0, size, scale, for_window.0))
        }
    }
}

impl Default for IconSet {
    fn default() -> Self {
        Self::new()
    }
}