Skip to main content

gtk4/auto/
page_setup.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::{PageOrientation, PaperSize, Unit, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// , i.e. the
10    /// parts of the page that the printer cannot print on. These are different
11    /// from the layout margins that a word processor uses; they are typically
12    /// used to determine the minimal size for the layout margins.
13    ///
14    /// To obtain a [`PageSetup`][crate::PageSetup] use [`new()`][Self::new()] to get the defaults,
15    /// or use [`print_run_page_setup_dialog()`][crate::print_run_page_setup_dialog()] to show the page setup dialog
16    /// and receive the resulting page setup.
17    ///
18    /// ## A page setup dialog
19    ///
20    /// **⚠️ The following code is in c ⚠️**
21    ///
22    /// ```c
23    /// static GtkPrintSettings *settings = NULL;
24    /// static GtkPageSetup *page_setup = NULL;
25    ///
26    /// static void
27    /// do_page_setup (void)
28    /// {
29    ///   GtkPageSetup *new_page_setup;
30    ///
31    ///   if (settings == NULL)
32    ///     settings = gtk_print_settings_new ();
33    ///
34    ///   new_page_setup = gtk_print_run_page_setup_dialog (GTK_WINDOW (main_window),
35    ///                                                     page_setup, settings);
36    ///
37    ///   if (page_setup)
38    ///     g_object_unref (page_setup);
39    ///
40    ///   page_setup = new_page_setup;
41    /// }
42    /// ```
43    ///
44    /// # Implements
45    ///
46    /// [`trait@glib::ObjectExt`]
47    #[doc(alias = "GtkPageSetup")]
48    pub struct PageSetup(Object<ffi::GtkPageSetup>);
49
50    match fn {
51        type_ => || ffi::gtk_page_setup_get_type(),
52    }
53}
54
55impl PageSetup {
56    /// Creates a new [`PageSetup`][crate::PageSetup].
57    ///
58    /// # Returns
59    ///
60    /// a new [`PageSetup`][crate::PageSetup].
61    #[doc(alias = "gtk_page_setup_new")]
62    pub fn new() -> PageSetup {
63        assert_initialized_main_thread!();
64        unsafe { from_glib_full(ffi::gtk_page_setup_new()) }
65    }
66
67    /// Reads the page setup from the file @file_name.
68    ///
69    /// Returns a new [`PageSetup`][crate::PageSetup] object with the restored
70    /// page setup, or [`None`] if an error occurred.
71    /// See [`to_file()`][Self::to_file()].
72    /// ## `file_name`
73    /// the filename to read the page setup from
74    ///
75    /// # Returns
76    ///
77    /// the restored [`PageSetup`][crate::PageSetup]
78    #[doc(alias = "gtk_page_setup_new_from_file")]
79    #[doc(alias = "new_from_file")]
80    pub fn from_file(file_name: impl AsRef<std::path::Path>) -> Result<PageSetup, glib::Error> {
81        assert_initialized_main_thread!();
82        unsafe {
83            let mut error = std::ptr::null_mut();
84            let ret =
85                ffi::gtk_page_setup_new_from_file(file_name.as_ref().to_glib_none().0, &mut error);
86            if error.is_null() {
87                Ok(from_glib_full(ret))
88            } else {
89                Err(from_glib_full(error))
90            }
91        }
92    }
93
94    /// Desrialize a page setup from an a{sv} variant.
95    ///
96    /// The variant must be in the format produced by
97    /// [`to_gvariant()`][Self::to_gvariant()].
98    /// ## `variant`
99    /// an a{sv} `GVariant`
100    ///
101    /// # Returns
102    ///
103    /// a new [`PageSetup`][crate::PageSetup] object
104    #[doc(alias = "gtk_page_setup_new_from_gvariant")]
105    #[doc(alias = "new_from_gvariant")]
106    pub fn from_gvariant(variant: &glib::Variant) -> PageSetup {
107        assert_initialized_main_thread!();
108        unsafe {
109            from_glib_full(ffi::gtk_page_setup_new_from_gvariant(
110                variant.to_glib_none().0,
111            ))
112        }
113    }
114
115    /// Reads the page setup from the group @group_name in the key file
116    /// @key_file.
117    ///
118    /// Returns a new [`PageSetup`][crate::PageSetup] object with the restored
119    /// page setup, or [`None`] if an error occurred.
120    /// ## `key_file`
121    /// the `GKeyFile` to retrieve the page_setup from
122    /// ## `group_name`
123    /// Page Setup
124    ///
125    /// # Returns
126    ///
127    /// the restored [`PageSetup`][crate::PageSetup]
128    #[doc(alias = "gtk_page_setup_new_from_key_file")]
129    #[doc(alias = "new_from_key_file")]
130    pub fn from_key_file(
131        key_file: &glib::KeyFile,
132        group_name: Option<&str>,
133    ) -> Result<PageSetup, glib::Error> {
134        assert_initialized_main_thread!();
135        unsafe {
136            let mut error = std::ptr::null_mut();
137            let ret = ffi::gtk_page_setup_new_from_key_file(
138                key_file.to_glib_none().0,
139                group_name.to_glib_none().0,
140                &mut error,
141            );
142            if error.is_null() {
143                Ok(from_glib_full(ret))
144            } else {
145                Err(from_glib_full(error))
146            }
147        }
148    }
149
150    #[doc(alias = "gtk_page_setup_copy")]
151    #[must_use]
152    pub fn copy(&self) -> PageSetup {
153        unsafe { from_glib_full(ffi::gtk_page_setup_copy(self.to_glib_none().0)) }
154    }
155
156    /// Gets the bottom margin in units of @unit.
157    /// ## `unit`
158    /// the unit for the return value
159    ///
160    /// # Returns
161    ///
162    /// the bottom margin
163    #[doc(alias = "gtk_page_setup_get_bottom_margin")]
164    #[doc(alias = "get_bottom_margin")]
165    pub fn bottom_margin(&self, unit: Unit) -> f64 {
166        unsafe { ffi::gtk_page_setup_get_bottom_margin(self.to_glib_none().0, unit.into_glib()) }
167    }
168
169    /// Gets the left margin in units of @unit.
170    /// ## `unit`
171    /// the unit for the return value
172    ///
173    /// # Returns
174    ///
175    /// the left margin
176    #[doc(alias = "gtk_page_setup_get_left_margin")]
177    #[doc(alias = "get_left_margin")]
178    pub fn left_margin(&self, unit: Unit) -> f64 {
179        unsafe { ffi::gtk_page_setup_get_left_margin(self.to_glib_none().0, unit.into_glib()) }
180    }
181
182    /// Gets the page orientation of the [`PageSetup`][crate::PageSetup].
183    ///
184    /// # Returns
185    ///
186    /// the page orientation
187    #[doc(alias = "gtk_page_setup_get_orientation")]
188    #[doc(alias = "get_orientation")]
189    pub fn orientation(&self) -> PageOrientation {
190        unsafe { from_glib(ffi::gtk_page_setup_get_orientation(self.to_glib_none().0)) }
191    }
192
193    /// Returns the page height in units of @unit.
194    ///
195    /// Note that this function takes orientation
196    /// and margins into consideration.
197    /// See [`paper_height()`][Self::paper_height()].
198    /// ## `unit`
199    /// the unit for the return value
200    ///
201    /// # Returns
202    ///
203    /// the page height.
204    #[doc(alias = "gtk_page_setup_get_page_height")]
205    #[doc(alias = "get_page_height")]
206    pub fn page_height(&self, unit: Unit) -> f64 {
207        unsafe { ffi::gtk_page_setup_get_page_height(self.to_glib_none().0, unit.into_glib()) }
208    }
209
210    /// Returns the page width in units of @unit.
211    ///
212    /// Note that this function takes orientation
213    /// and margins into consideration.
214    /// See [`paper_width()`][Self::paper_width()].
215    /// ## `unit`
216    /// the unit for the return value
217    ///
218    /// # Returns
219    ///
220    /// the page width.
221    #[doc(alias = "gtk_page_setup_get_page_width")]
222    #[doc(alias = "get_page_width")]
223    pub fn page_width(&self, unit: Unit) -> f64 {
224        unsafe { ffi::gtk_page_setup_get_page_width(self.to_glib_none().0, unit.into_glib()) }
225    }
226
227    /// Returns the paper height in units of @unit.
228    ///
229    /// Note that this function takes orientation,
230    /// but not margins into consideration.
231    /// See [`page_height()`][Self::page_height()].
232    /// ## `unit`
233    /// the unit for the return value
234    ///
235    /// # Returns
236    ///
237    /// the paper height.
238    #[doc(alias = "gtk_page_setup_get_paper_height")]
239    #[doc(alias = "get_paper_height")]
240    pub fn paper_height(&self, unit: Unit) -> f64 {
241        unsafe { ffi::gtk_page_setup_get_paper_height(self.to_glib_none().0, unit.into_glib()) }
242    }
243
244    /// Gets the paper size of the [`PageSetup`][crate::PageSetup].
245    ///
246    /// # Returns
247    ///
248    /// the paper size
249    #[doc(alias = "gtk_page_setup_get_paper_size")]
250    #[doc(alias = "get_paper_size")]
251    pub fn paper_size(&self) -> PaperSize {
252        unsafe { from_glib_none(ffi::gtk_page_setup_get_paper_size(self.to_glib_none().0)) }
253    }
254
255    /// Returns the paper width in units of @unit.
256    ///
257    /// Note that this function takes orientation,
258    /// but not margins into consideration.
259    /// See [`page_width()`][Self::page_width()].
260    /// ## `unit`
261    /// the unit for the return value
262    ///
263    /// # Returns
264    ///
265    /// the paper width.
266    #[doc(alias = "gtk_page_setup_get_paper_width")]
267    #[doc(alias = "get_paper_width")]
268    pub fn paper_width(&self, unit: Unit) -> f64 {
269        unsafe { ffi::gtk_page_setup_get_paper_width(self.to_glib_none().0, unit.into_glib()) }
270    }
271
272    /// Gets the right margin in units of @unit.
273    /// ## `unit`
274    /// the unit for the return value
275    ///
276    /// # Returns
277    ///
278    /// the right margin
279    #[doc(alias = "gtk_page_setup_get_right_margin")]
280    #[doc(alias = "get_right_margin")]
281    pub fn right_margin(&self, unit: Unit) -> f64 {
282        unsafe { ffi::gtk_page_setup_get_right_margin(self.to_glib_none().0, unit.into_glib()) }
283    }
284
285    /// Gets the top margin in units of @unit.
286    /// ## `unit`
287    /// the unit for the return value
288    ///
289    /// # Returns
290    ///
291    /// the top margin
292    #[doc(alias = "gtk_page_setup_get_top_margin")]
293    #[doc(alias = "get_top_margin")]
294    pub fn top_margin(&self, unit: Unit) -> f64 {
295        unsafe { ffi::gtk_page_setup_get_top_margin(self.to_glib_none().0, unit.into_glib()) }
296    }
297
298    /// Reads the page setup from the file @file_name.
299    ///
300    /// See [`to_file()`][Self::to_file()].
301    /// ## `file_name`
302    /// the filename to read the page setup from
303    ///
304    /// # Returns
305    ///
306    /// [`true`] on success
307    #[doc(alias = "gtk_page_setup_load_file")]
308    pub fn load_file(&self, file_name: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
309        unsafe {
310            let mut error = std::ptr::null_mut();
311            let is_ok = ffi::gtk_page_setup_load_file(
312                self.to_glib_none().0,
313                file_name.as_ref().to_glib_none().0,
314                &mut error,
315            );
316            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
317            if error.is_null() {
318                Ok(())
319            } else {
320                Err(from_glib_full(error))
321            }
322        }
323    }
324
325    /// Reads the page setup from the group @group_name in the key file
326    /// @key_file.
327    /// ## `key_file`
328    /// the `GKeyFile` to retrieve the page_setup from
329    /// ## `group_name`
330    /// Page Setup
331    ///
332    /// # Returns
333    ///
334    /// [`true`] on success
335    #[doc(alias = "gtk_page_setup_load_key_file")]
336    pub fn load_key_file(
337        &self,
338        key_file: &glib::KeyFile,
339        group_name: Option<&str>,
340    ) -> Result<(), glib::Error> {
341        unsafe {
342            let mut error = std::ptr::null_mut();
343            let is_ok = ffi::gtk_page_setup_load_key_file(
344                self.to_glib_none().0,
345                key_file.to_glib_none().0,
346                group_name.to_glib_none().0,
347                &mut error,
348            );
349            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
350            if error.is_null() {
351                Ok(())
352            } else {
353                Err(from_glib_full(error))
354            }
355        }
356    }
357
358    /// Sets the bottom margin of the [`PageSetup`][crate::PageSetup].
359    /// ## `margin`
360    /// the new bottom margin in units of @unit
361    /// ## `unit`
362    /// the units for @margin
363    #[doc(alias = "gtk_page_setup_set_bottom_margin")]
364    pub fn set_bottom_margin(&self, margin: f64, unit: Unit) {
365        unsafe {
366            ffi::gtk_page_setup_set_bottom_margin(self.to_glib_none().0, margin, unit.into_glib());
367        }
368    }
369
370    /// Sets the left margin of the [`PageSetup`][crate::PageSetup].
371    /// ## `margin`
372    /// the new left margin in units of @unit
373    /// ## `unit`
374    /// the units for @margin
375    #[doc(alias = "gtk_page_setup_set_left_margin")]
376    pub fn set_left_margin(&self, margin: f64, unit: Unit) {
377        unsafe {
378            ffi::gtk_page_setup_set_left_margin(self.to_glib_none().0, margin, unit.into_glib());
379        }
380    }
381
382    /// Sets the page orientation of the [`PageSetup`][crate::PageSetup].
383    /// ## `orientation`
384    /// a [`PageOrientation`][crate::PageOrientation] value
385    #[doc(alias = "gtk_page_setup_set_orientation")]
386    pub fn set_orientation(&self, orientation: PageOrientation) {
387        unsafe {
388            ffi::gtk_page_setup_set_orientation(self.to_glib_none().0, orientation.into_glib());
389        }
390    }
391
392    /// Sets the paper size of the [`PageSetup`][crate::PageSetup] without
393    /// changing the margins.
394    ///
395    /// See [`set_paper_size_and_default_margins()`][Self::set_paper_size_and_default_margins()].
396    /// ## `size`
397    /// a [`PaperSize`][crate::PaperSize]
398    #[doc(alias = "gtk_page_setup_set_paper_size")]
399    pub fn set_paper_size(&self, size: &PaperSize) {
400        unsafe {
401            ffi::gtk_page_setup_set_paper_size(
402                self.to_glib_none().0,
403                mut_override(size.to_glib_none().0),
404            );
405        }
406    }
407
408    /// Sets the paper size of the [`PageSetup`][crate::PageSetup] and modifies
409    /// the margins according to the new paper size.
410    /// ## `size`
411    /// a [`PaperSize`][crate::PaperSize]
412    #[doc(alias = "gtk_page_setup_set_paper_size_and_default_margins")]
413    pub fn set_paper_size_and_default_margins(&self, size: &PaperSize) {
414        unsafe {
415            ffi::gtk_page_setup_set_paper_size_and_default_margins(
416                self.to_glib_none().0,
417                mut_override(size.to_glib_none().0),
418            );
419        }
420    }
421
422    /// Sets the right margin of the [`PageSetup`][crate::PageSetup].
423    /// ## `margin`
424    /// the new right margin in units of @unit
425    /// ## `unit`
426    /// the units for @margin
427    #[doc(alias = "gtk_page_setup_set_right_margin")]
428    pub fn set_right_margin(&self, margin: f64, unit: Unit) {
429        unsafe {
430            ffi::gtk_page_setup_set_right_margin(self.to_glib_none().0, margin, unit.into_glib());
431        }
432    }
433
434    /// Sets the top margin of the [`PageSetup`][crate::PageSetup].
435    /// ## `margin`
436    /// the new top margin in units of @unit
437    /// ## `unit`
438    /// the units for @margin
439    #[doc(alias = "gtk_page_setup_set_top_margin")]
440    pub fn set_top_margin(&self, margin: f64, unit: Unit) {
441        unsafe {
442            ffi::gtk_page_setup_set_top_margin(self.to_glib_none().0, margin, unit.into_glib());
443        }
444    }
445
446    /// This function saves the information from @self to @file_name.
447    /// ## `file_name`
448    /// the file to save to
449    ///
450    /// # Returns
451    ///
452    /// [`true`] on success
453    #[doc(alias = "gtk_page_setup_to_file")]
454    pub fn to_file(&self, file_name: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
455        unsafe {
456            let mut error = std::ptr::null_mut();
457            let is_ok = ffi::gtk_page_setup_to_file(
458                self.to_glib_none().0,
459                file_name.as_ref().to_glib_none().0,
460                &mut error,
461            );
462            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
463            if error.is_null() {
464                Ok(())
465            } else {
466                Err(from_glib_full(error))
467            }
468        }
469    }
470
471    /// Serialize page setup to an a{sv} variant.
472    ///
473    /// # Returns
474    ///
475    /// a new, floating, `GVariant`
476    #[doc(alias = "gtk_page_setup_to_gvariant")]
477    pub fn to_gvariant(&self) -> glib::Variant {
478        unsafe { from_glib_none(ffi::gtk_page_setup_to_gvariant(self.to_glib_none().0)) }
479    }
480
481    /// This function adds the page setup from @self to @key_file.
482    /// ## `key_file`
483    /// the `GKeyFile` to save the page setup to
484    /// ## `group_name`
485    /// Page Setup
486    #[doc(alias = "gtk_page_setup_to_key_file")]
487    pub fn to_key_file(&self, key_file: &glib::KeyFile, group_name: Option<&str>) {
488        unsafe {
489            ffi::gtk_page_setup_to_key_file(
490                self.to_glib_none().0,
491                key_file.to_glib_none().0,
492                group_name.to_glib_none().0,
493            );
494        }
495    }
496}
497
498impl Default for PageSetup {
499    fn default() -> Self {
500        Self::new()
501    }
502}