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