Skip to main content

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 crate::{Unit, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// GtkPaperSize handles paper sizes. It uses the standard called
10    /// [PWG 5101.1-2002 PWG: Standard for Media Standardized Names](http://www.pwg.org/standards.html)
11    /// to name the paper sizes (and to get the data for the page sizes).
12    /// In addition to standard paper sizes, GtkPaperSize allows to
13    /// construct custom paper sizes with arbitrary dimensions.
14    ///
15    /// The [`PaperSize`][crate::PaperSize] object stores not only the dimensions (width
16    /// and height) of a paper size and its name, it also provides
17    /// default [print margins][print-margins].
18    ///
19    /// Printing support has been added in GTK+ 2.10.
20    #[derive(Debug, PartialOrd, Ord, Hash)]
21    pub struct PaperSize(Boxed<ffi::GtkPaperSize>);
22
23    match fn {
24        copy => |ptr| ffi::gtk_paper_size_copy(mut_override(ptr)),
25        free => |ptr| ffi::gtk_paper_size_free(ptr),
26        type_ => || ffi::gtk_paper_size_get_type(),
27    }
28}
29
30impl PaperSize {
31    /// Creates a new [`PaperSize`][crate::PaperSize] object by parsing a
32    /// [PWG 5101.1-2002](ftp://ftp.pwg.org/pub/pwg/candidates/cs-pwgmsn10-20020226-5101.1.pdf)
33    /// paper name.
34    ///
35    /// If `name` is [`None`], the default paper size is returned,
36    /// see [`default()`][Self::default()].
37    /// ## `name`
38    /// a paper size name, or [`None`]
39    ///
40    /// # Returns
41    ///
42    /// a new [`PaperSize`][crate::PaperSize], use `gtk_paper_size_free()`
43    /// to free it
44    #[doc(alias = "gtk_paper_size_new")]
45    pub fn new(name: Option<&str>) -> PaperSize {
46        assert_initialized_main_thread!();
47        unsafe { from_glib_full(ffi::gtk_paper_size_new(name.to_glib_none().0)) }
48    }
49
50    /// Creates a new [`PaperSize`][crate::PaperSize] object with the
51    /// given parameters.
52    /// ## `name`
53    /// the paper name
54    /// ## `display_name`
55    /// the human-readable name
56    /// ## `width`
57    /// the paper width, in units of `unit`
58    /// ## `height`
59    /// the paper height, in units of `unit`
60    /// ## `unit`
61    /// the unit for `width` and `height`. not [`Unit::None`][crate::Unit::None].
62    ///
63    /// # Returns
64    ///
65    /// a new [`PaperSize`][crate::PaperSize] object, use `gtk_paper_size_free()`
66    /// to free it
67    #[doc(alias = "gtk_paper_size_new_custom")]
68    pub fn new_custom(
69        name: &str,
70        display_name: &str,
71        width: f64,
72        height: f64,
73        unit: Unit,
74    ) -> PaperSize {
75        assert_initialized_main_thread!();
76        unsafe {
77            from_glib_full(ffi::gtk_paper_size_new_custom(
78                name.to_glib_none().0,
79                display_name.to_glib_none().0,
80                width,
81                height,
82                unit.into_glib(),
83            ))
84        }
85    }
86
87    /// Deserialize a paper size from an a{sv} variant in
88    /// the format produced by [`to_gvariant()`][Self::to_gvariant()].
89    /// ## `variant`
90    /// an a{sv} [`glib::Variant`][struct@crate::glib::Variant]
91    ///
92    /// # Returns
93    ///
94    /// a new [`PaperSize`][crate::PaperSize] object
95    #[doc(alias = "gtk_paper_size_new_from_gvariant")]
96    #[doc(alias = "new_from_gvariant")]
97    pub fn from_gvariant(variant: &glib::Variant) -> PaperSize {
98        assert_initialized_main_thread!();
99        unsafe {
100            from_glib_full(ffi::gtk_paper_size_new_from_gvariant(
101                variant.to_glib_none().0,
102            ))
103        }
104    }
105
106    /// Creates a new [`PaperSize`][crate::PaperSize] object by using
107    /// IPP information.
108    ///
109    /// If `ipp_name` is not a recognized paper name,
110    /// `width` and `height` are used to
111    /// construct a custom [`PaperSize`][crate::PaperSize] object.
112    /// ## `ipp_name`
113    /// an IPP paper name
114    /// ## `width`
115    /// the paper width, in points
116    /// ## `height`
117    /// the paper height in points
118    ///
119    /// # Returns
120    ///
121    /// a new [`PaperSize`][crate::PaperSize], use `gtk_paper_size_free()`
122    /// to free it
123    #[doc(alias = "gtk_paper_size_new_from_ipp")]
124    #[doc(alias = "new_from_ipp")]
125    pub fn from_ipp(ipp_name: &str, width: f64, height: f64) -> PaperSize {
126        assert_initialized_main_thread!();
127        unsafe {
128            from_glib_full(ffi::gtk_paper_size_new_from_ipp(
129                ipp_name.to_glib_none().0,
130                width,
131                height,
132            ))
133        }
134    }
135
136    /// Reads a paper size from the group `group_name` in the key file
137    /// `key_file`.
138    /// ## `key_file`
139    /// the [`glib::KeyFile`][crate::glib::KeyFile] to retrieve the papersize from
140    /// ## `group_name`
141    /// the name of the group in the key file to read,
142    ///  or [`None`] to read the first group
143    ///
144    /// # Returns
145    ///
146    /// a new [`PaperSize`][crate::PaperSize] object with the restored
147    ///  paper size, or [`None`] if an error occurred
148    #[doc(alias = "gtk_paper_size_new_from_key_file")]
149    #[doc(alias = "new_from_key_file")]
150    pub fn from_key_file(
151        key_file: &glib::KeyFile,
152        group_name: Option<&str>,
153    ) -> Result<PaperSize, glib::Error> {
154        assert_initialized_main_thread!();
155        unsafe {
156            let mut error = std::ptr::null_mut();
157            let ret = ffi::gtk_paper_size_new_from_key_file(
158                key_file.to_glib_none().0,
159                group_name.to_glib_none().0,
160                &mut error,
161            );
162            if error.is_null() {
163                Ok(from_glib_full(ret))
164            } else {
165                Err(from_glib_full(error))
166            }
167        }
168    }
169
170    /// Creates a new [`PaperSize`][crate::PaperSize] object by using
171    /// PPD information.
172    ///
173    /// If `ppd_name` is not a recognized PPD paper name,
174    /// `ppd_display_name`, `width` and `height` are used to
175    /// construct a custom [`PaperSize`][crate::PaperSize] object.
176    /// ## `ppd_name`
177    /// a PPD paper name
178    /// ## `ppd_display_name`
179    /// the corresponding human-readable name
180    /// ## `width`
181    /// the paper width, in points
182    /// ## `height`
183    /// the paper height in points
184    ///
185    /// # Returns
186    ///
187    /// a new [`PaperSize`][crate::PaperSize], use `gtk_paper_size_free()`
188    /// to free it
189    #[doc(alias = "gtk_paper_size_new_from_ppd")]
190    #[doc(alias = "new_from_ppd")]
191    pub fn from_ppd(ppd_name: &str, ppd_display_name: &str, width: f64, height: f64) -> PaperSize {
192        assert_initialized_main_thread!();
193        unsafe {
194            from_glib_full(ffi::gtk_paper_size_new_from_ppd(
195                ppd_name.to_glib_none().0,
196                ppd_display_name.to_glib_none().0,
197                width,
198                height,
199            ))
200        }
201    }
202
203    /// Gets the default bottom margin for the [`PaperSize`][crate::PaperSize].
204    /// ## `unit`
205    /// the unit for the return value, not [`Unit::None`][crate::Unit::None]
206    ///
207    /// # Returns
208    ///
209    /// the default bottom margin
210    #[doc(alias = "gtk_paper_size_get_default_bottom_margin")]
211    #[doc(alias = "get_default_bottom_margin")]
212    pub fn default_bottom_margin(&self, unit: Unit) -> f64 {
213        unsafe {
214            ffi::gtk_paper_size_get_default_bottom_margin(
215                mut_override(self.to_glib_none().0),
216                unit.into_glib(),
217            )
218        }
219    }
220
221    /// Gets the default left margin for the [`PaperSize`][crate::PaperSize].
222    /// ## `unit`
223    /// the unit for the return value, not [`Unit::None`][crate::Unit::None]
224    ///
225    /// # Returns
226    ///
227    /// the default left margin
228    #[doc(alias = "gtk_paper_size_get_default_left_margin")]
229    #[doc(alias = "get_default_left_margin")]
230    pub fn default_left_margin(&self, unit: Unit) -> f64 {
231        unsafe {
232            ffi::gtk_paper_size_get_default_left_margin(
233                mut_override(self.to_glib_none().0),
234                unit.into_glib(),
235            )
236        }
237    }
238
239    /// Gets the default right margin for the [`PaperSize`][crate::PaperSize].
240    /// ## `unit`
241    /// the unit for the return value, not [`Unit::None`][crate::Unit::None]
242    ///
243    /// # Returns
244    ///
245    /// the default right margin
246    #[doc(alias = "gtk_paper_size_get_default_right_margin")]
247    #[doc(alias = "get_default_right_margin")]
248    pub fn default_right_margin(&self, unit: Unit) -> f64 {
249        unsafe {
250            ffi::gtk_paper_size_get_default_right_margin(
251                mut_override(self.to_glib_none().0),
252                unit.into_glib(),
253            )
254        }
255    }
256
257    /// Gets the default top margin for the [`PaperSize`][crate::PaperSize].
258    /// ## `unit`
259    /// the unit for the return value, not [`Unit::None`][crate::Unit::None]
260    ///
261    /// # Returns
262    ///
263    /// the default top margin
264    #[doc(alias = "gtk_paper_size_get_default_top_margin")]
265    #[doc(alias = "get_default_top_margin")]
266    pub fn default_top_margin(&self, unit: Unit) -> f64 {
267        unsafe {
268            ffi::gtk_paper_size_get_default_top_margin(
269                mut_override(self.to_glib_none().0),
270                unit.into_glib(),
271            )
272        }
273    }
274
275    /// Gets the human-readable name of the [`PaperSize`][crate::PaperSize].
276    ///
277    /// # Returns
278    ///
279    /// the human-readable name of `self`
280    #[doc(alias = "gtk_paper_size_get_display_name")]
281    #[doc(alias = "get_display_name")]
282    pub fn display_name(&self) -> Option<glib::GString> {
283        unsafe {
284            from_glib_none(ffi::gtk_paper_size_get_display_name(mut_override(
285                self.to_glib_none().0,
286            )))
287        }
288    }
289
290    /// Gets the paper height of the [`PaperSize`][crate::PaperSize], in
291    /// units of `unit`.
292    /// ## `unit`
293    /// the unit for the return value, not [`Unit::None`][crate::Unit::None]
294    ///
295    /// # Returns
296    ///
297    /// the paper height
298    #[doc(alias = "gtk_paper_size_get_height")]
299    #[doc(alias = "get_height")]
300    pub fn height(&self, unit: Unit) -> f64 {
301        unsafe {
302            ffi::gtk_paper_size_get_height(mut_override(self.to_glib_none().0), unit.into_glib())
303        }
304    }
305
306    /// Gets the name of the [`PaperSize`][crate::PaperSize].
307    ///
308    /// # Returns
309    ///
310    /// the name of `self`
311    #[doc(alias = "gtk_paper_size_get_name")]
312    #[doc(alias = "get_name")]
313    pub fn name(&self) -> Option<glib::GString> {
314        unsafe {
315            from_glib_none(ffi::gtk_paper_size_get_name(mut_override(
316                self.to_glib_none().0,
317            )))
318        }
319    }
320
321    /// Gets the PPD name of the [`PaperSize`][crate::PaperSize], which
322    /// may be [`None`].
323    ///
324    /// # Returns
325    ///
326    /// the PPD name of `self`
327    #[doc(alias = "gtk_paper_size_get_ppd_name")]
328    #[doc(alias = "get_ppd_name")]
329    pub fn ppd_name(&self) -> Option<glib::GString> {
330        unsafe {
331            from_glib_none(ffi::gtk_paper_size_get_ppd_name(mut_override(
332                self.to_glib_none().0,
333            )))
334        }
335    }
336
337    /// Gets the paper width of the [`PaperSize`][crate::PaperSize], in
338    /// units of `unit`.
339    /// ## `unit`
340    /// the unit for the return value, not [`Unit::None`][crate::Unit::None]
341    ///
342    /// # Returns
343    ///
344    /// the paper width
345    #[doc(alias = "gtk_paper_size_get_width")]
346    #[doc(alias = "get_width")]
347    pub fn width(&self, unit: Unit) -> f64 {
348        unsafe {
349            ffi::gtk_paper_size_get_width(mut_override(self.to_glib_none().0), unit.into_glib())
350        }
351    }
352
353    /// Returns [`true`] if `self` is not a standard paper size.
354    ///
355    /// # Returns
356    ///
357    /// whether `self` is a custom paper size.
358    #[doc(alias = "gtk_paper_size_is_custom")]
359    pub fn is_custom(&self) -> bool {
360        unsafe {
361            from_glib(ffi::gtk_paper_size_is_custom(mut_override(
362                self.to_glib_none().0,
363            )))
364        }
365    }
366
367    #[doc(alias = "gtk_paper_size_is_equal")]
368    fn is_equal(&self, size2: &PaperSize) -> bool {
369        unsafe {
370            from_glib(ffi::gtk_paper_size_is_equal(
371                mut_override(self.to_glib_none().0),
372                mut_override(size2.to_glib_none().0),
373            ))
374        }
375    }
376
377    /// Returns [`true`] if `self` is an IPP standard paper size.
378    ///
379    /// # Returns
380    ///
381    /// whether `self` is not an IPP custom paper size.
382    #[doc(alias = "gtk_paper_size_is_ipp")]
383    pub fn is_ipp(&self) -> bool {
384        unsafe {
385            from_glib(ffi::gtk_paper_size_is_ipp(mut_override(
386                self.to_glib_none().0,
387            )))
388        }
389    }
390
391    /// Changes the dimensions of a `self` to `width` x `height`.
392    /// ## `width`
393    /// the new width in units of `unit`
394    /// ## `height`
395    /// the new height in units of `unit`
396    /// ## `unit`
397    /// the unit for `width` and `height`
398    #[doc(alias = "gtk_paper_size_set_size")]
399    pub fn set_size(&mut self, width: f64, height: f64, unit: Unit) {
400        unsafe {
401            ffi::gtk_paper_size_set_size(
402                self.to_glib_none_mut().0,
403                width,
404                height,
405                unit.into_glib(),
406            );
407        }
408    }
409
410    /// Serialize a paper size to an a{sv} variant.
411    ///
412    /// # Returns
413    ///
414    /// a new, floating, [`glib::Variant`][struct@crate::glib::Variant]
415    #[doc(alias = "gtk_paper_size_to_gvariant")]
416    pub fn to_gvariant(&mut self) -> Option<glib::Variant> {
417        unsafe { from_glib_none(ffi::gtk_paper_size_to_gvariant(self.to_glib_none_mut().0)) }
418    }
419
420    /// This function adds the paper size from `self` to `key_file`.
421    /// ## `key_file`
422    /// the [`glib::KeyFile`][crate::glib::KeyFile] to save the paper size to
423    /// ## `group_name`
424    /// the group to add the settings to in `key_file`
425    #[doc(alias = "gtk_paper_size_to_key_file")]
426    pub fn to_key_file(&mut self, key_file: &glib::KeyFile, group_name: &str) {
427        unsafe {
428            ffi::gtk_paper_size_to_key_file(
429                self.to_glib_none_mut().0,
430                key_file.to_glib_none().0,
431                group_name.to_glib_none().0,
432            );
433        }
434    }
435
436    /// Returns the name of the default paper size, which
437    /// depends on the current locale.
438    ///
439    /// # Returns
440    ///
441    /// the name of the default paper size. The string
442    /// is owned by GTK+ and should not be modified.
443    #[doc(alias = "gtk_paper_size_get_default")]
444    #[doc(alias = "get_default")]
445    #[allow(clippy::should_implement_trait)]
446    pub fn default() -> Option<glib::GString> {
447        assert_initialized_main_thread!();
448        unsafe { from_glib_none(ffi::gtk_paper_size_get_default()) }
449    }
450
451    /// Creates a list of known paper sizes.
452    /// ## `include_custom`
453    /// whether to include custom paper sizes
454    ///  as defined in the page setup dialog
455    ///
456    /// # Returns
457    ///
458    /// a newly allocated list of newly
459    ///  allocated [`PaperSize`][crate::PaperSize] objects
460    #[doc(alias = "gtk_paper_size_get_paper_sizes")]
461    #[doc(alias = "get_paper_sizes")]
462    pub fn paper_sizes(include_custom: bool) -> Vec<PaperSize> {
463        assert_initialized_main_thread!();
464        unsafe {
465            FromGlibPtrContainer::from_glib_full(ffi::gtk_paper_size_get_paper_sizes(
466                include_custom.into_glib(),
467            ))
468        }
469    }
470}
471
472impl PartialEq for PaperSize {
473    #[inline]
474    fn eq(&self, other: &Self) -> bool {
475        self.is_equal(other)
476    }
477}
478
479impl Eq for PaperSize {}