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