gtk/auto/
paper_size.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 glib;
6use glib::translate::*;
7use glib::GString;
8use gtk_sys;
9use std::ptr;
10use Error;
11use Unit;
12
13glib_wrapper! {
14    #[derive(Debug, PartialOrd, Ord, Hash)]
15    pub struct PaperSize(Boxed<gtk_sys::GtkPaperSize>);
16
17    match fn {
18        copy => |ptr| gtk_sys::gtk_paper_size_copy(mut_override(ptr)),
19        free => |ptr| gtk_sys::gtk_paper_size_free(ptr),
20        get_type => || gtk_sys::gtk_paper_size_get_type(),
21    }
22}
23
24impl PaperSize {
25    pub fn new(name: Option<&str>) -> PaperSize {
26        assert_initialized_main_thread!();
27        unsafe { from_glib_full(gtk_sys::gtk_paper_size_new(name.to_glib_none().0)) }
28    }
29
30    pub fn new_custom(
31        name: &str,
32        display_name: &str,
33        width: f64,
34        height: f64,
35        unit: Unit,
36    ) -> PaperSize {
37        assert_initialized_main_thread!();
38        unsafe {
39            from_glib_full(gtk_sys::gtk_paper_size_new_custom(
40                name.to_glib_none().0,
41                display_name.to_glib_none().0,
42                width,
43                height,
44                unit.to_glib(),
45            ))
46        }
47    }
48
49    #[cfg(any(feature = "v3_22", feature = "dox"))]
50    pub fn new_from_gvariant(variant: &glib::Variant) -> PaperSize {
51        assert_initialized_main_thread!();
52        unsafe {
53            from_glib_full(gtk_sys::gtk_paper_size_new_from_gvariant(
54                variant.to_glib_none().0,
55            ))
56        }
57    }
58
59    #[cfg(any(feature = "v3_16", feature = "dox"))]
60    pub fn new_from_ipp(ipp_name: &str, width: f64, height: f64) -> PaperSize {
61        assert_initialized_main_thread!();
62        unsafe {
63            from_glib_full(gtk_sys::gtk_paper_size_new_from_ipp(
64                ipp_name.to_glib_none().0,
65                width,
66                height,
67            ))
68        }
69    }
70
71    pub fn new_from_key_file(
72        key_file: &glib::KeyFile,
73        group_name: Option<&str>,
74    ) -> Result<PaperSize, Error> {
75        assert_initialized_main_thread!();
76        unsafe {
77            let mut error = ptr::null_mut();
78            let ret = gtk_sys::gtk_paper_size_new_from_key_file(
79                key_file.to_glib_none().0,
80                group_name.to_glib_none().0,
81                &mut error,
82            );
83            if error.is_null() {
84                Ok(from_glib_full(ret))
85            } else {
86                Err(from_glib_full(error))
87            }
88        }
89    }
90
91    pub fn new_from_ppd(
92        ppd_name: &str,
93        ppd_display_name: &str,
94        width: f64,
95        height: f64,
96    ) -> PaperSize {
97        assert_initialized_main_thread!();
98        unsafe {
99            from_glib_full(gtk_sys::gtk_paper_size_new_from_ppd(
100                ppd_name.to_glib_none().0,
101                ppd_display_name.to_glib_none().0,
102                width,
103                height,
104            ))
105        }
106    }
107
108    pub fn get_default_bottom_margin(&self, unit: Unit) -> f64 {
109        unsafe {
110            gtk_sys::gtk_paper_size_get_default_bottom_margin(
111                mut_override(self.to_glib_none().0),
112                unit.to_glib(),
113            )
114        }
115    }
116
117    pub fn get_default_left_margin(&self, unit: Unit) -> f64 {
118        unsafe {
119            gtk_sys::gtk_paper_size_get_default_left_margin(
120                mut_override(self.to_glib_none().0),
121                unit.to_glib(),
122            )
123        }
124    }
125
126    pub fn get_default_right_margin(&self, unit: Unit) -> f64 {
127        unsafe {
128            gtk_sys::gtk_paper_size_get_default_right_margin(
129                mut_override(self.to_glib_none().0),
130                unit.to_glib(),
131            )
132        }
133    }
134
135    pub fn get_default_top_margin(&self, unit: Unit) -> f64 {
136        unsafe {
137            gtk_sys::gtk_paper_size_get_default_top_margin(
138                mut_override(self.to_glib_none().0),
139                unit.to_glib(),
140            )
141        }
142    }
143
144    pub fn get_display_name(&self) -> Option<GString> {
145        unsafe {
146            from_glib_none(gtk_sys::gtk_paper_size_get_display_name(mut_override(
147                self.to_glib_none().0,
148            )))
149        }
150    }
151
152    pub fn get_height(&self, unit: Unit) -> f64 {
153        unsafe {
154            gtk_sys::gtk_paper_size_get_height(mut_override(self.to_glib_none().0), unit.to_glib())
155        }
156    }
157
158    pub fn get_name(&self) -> Option<GString> {
159        unsafe {
160            from_glib_none(gtk_sys::gtk_paper_size_get_name(mut_override(
161                self.to_glib_none().0,
162            )))
163        }
164    }
165
166    pub fn get_ppd_name(&self) -> Option<GString> {
167        unsafe {
168            from_glib_none(gtk_sys::gtk_paper_size_get_ppd_name(mut_override(
169                self.to_glib_none().0,
170            )))
171        }
172    }
173
174    pub fn get_width(&self, unit: Unit) -> f64 {
175        unsafe {
176            gtk_sys::gtk_paper_size_get_width(mut_override(self.to_glib_none().0), unit.to_glib())
177        }
178    }
179
180    pub fn is_custom(&self) -> bool {
181        unsafe {
182            from_glib(gtk_sys::gtk_paper_size_is_custom(mut_override(
183                self.to_glib_none().0,
184            )))
185        }
186    }
187
188    fn is_equal(&self, size2: &PaperSize) -> bool {
189        unsafe {
190            from_glib(gtk_sys::gtk_paper_size_is_equal(
191                mut_override(self.to_glib_none().0),
192                mut_override(size2.to_glib_none().0),
193            ))
194        }
195    }
196
197    #[cfg(any(feature = "v3_16", feature = "dox"))]
198    pub fn is_ipp(&self) -> bool {
199        unsafe {
200            from_glib(gtk_sys::gtk_paper_size_is_ipp(mut_override(
201                self.to_glib_none().0,
202            )))
203        }
204    }
205
206    pub fn set_size(&mut self, width: f64, height: f64, unit: Unit) {
207        unsafe {
208            gtk_sys::gtk_paper_size_set_size(
209                self.to_glib_none_mut().0,
210                width,
211                height,
212                unit.to_glib(),
213            );
214        }
215    }
216
217    #[cfg(any(feature = "v3_22", feature = "dox"))]
218    pub fn to_gvariant(&mut self) -> Option<glib::Variant> {
219        unsafe {
220            from_glib_none(gtk_sys::gtk_paper_size_to_gvariant(
221                self.to_glib_none_mut().0,
222            ))
223        }
224    }
225
226    pub fn to_key_file(&mut self, key_file: &glib::KeyFile, group_name: &str) {
227        unsafe {
228            gtk_sys::gtk_paper_size_to_key_file(
229                self.to_glib_none_mut().0,
230                key_file.to_glib_none().0,
231                group_name.to_glib_none().0,
232            );
233        }
234    }
235
236    pub fn get_default() -> Option<GString> {
237        assert_initialized_main_thread!();
238        unsafe { from_glib_none(gtk_sys::gtk_paper_size_get_default()) }
239    }
240
241    pub fn get_paper_sizes(include_custom: bool) -> Vec<PaperSize> {
242        assert_initialized_main_thread!();
243        unsafe {
244            FromGlibPtrContainer::from_glib_full(gtk_sys::gtk_paper_size_get_paper_sizes(
245                include_custom.to_glib(),
246            ))
247        }
248    }
249}
250
251impl PartialEq for PaperSize {
252    #[inline]
253    fn eq(&self, other: &Self) -> bool {
254        self.is_equal(other)
255    }
256}
257
258impl Eq for PaperSize {}