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