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;
6use glib::translate::*;
7use std::ptr;
8
9glib::wrapper! {
10 /// GtkPaperSize handles paper sizes. It uses the standard called
11 /// [PWG 5101.1-2002 PWG: Standard for Media Standardized Names](http://www.pwg.org/standards.html)
12 /// to name the paper sizes (and to get the data for the page sizes).
13 /// In addition to standard paper sizes, GtkPaperSize allows to
14 /// construct custom paper sizes with arbitrary dimensions.
15 ///
16 /// The [`PaperSize`][crate::PaperSize] object stores not only the dimensions (width
17 /// and height) of a paper size and its name, it also provides
18 /// default [print margins][print-margins].
19 ///
20 /// Printing support has been added in GTK+ 2.10.
21 #[derive(Debug, PartialOrd, Ord, Hash)]
22 pub struct PaperSize(Boxed<ffi::GtkPaperSize>);
23
24 match fn {
25 copy => |ptr| ffi::gtk_paper_size_copy(mut_override(ptr)),
26 free => |ptr| ffi::gtk_paper_size_free(ptr),
27 type_ => || ffi::gtk_paper_size_get_type(),
28 }
29}
30
31impl PaperSize {
32 /// Creates a new [`PaperSize`][crate::PaperSize] object by parsing a
33 /// [PWG 5101.1-2002](ftp://ftp.pwg.org/pub/pwg/candidates/cs-pwgmsn10-20020226-5101.1.pdf)
34 /// paper name.
35 ///
36 /// If `name` is [`None`], the default paper size is returned,
37 /// see [`default()`][Self::default()].
38 /// ## `name`
39 /// a paper size name, or [`None`]
40 ///
41 /// # Returns
42 ///
43 /// a new [`PaperSize`][crate::PaperSize], use `gtk_paper_size_free()`
44 /// to free it
45 #[doc(alias = "gtk_paper_size_new")]
46 pub fn new(name: Option<&str>) -> PaperSize {
47 assert_initialized_main_thread!();
48 unsafe { from_glib_full(ffi::gtk_paper_size_new(name.to_glib_none().0)) }
49 }
50
51 /// Creates a new [`PaperSize`][crate::PaperSize] object with the
52 /// given parameters.
53 /// ## `name`
54 /// the paper name
55 /// ## `display_name`
56 /// the human-readable name
57 /// ## `width`
58 /// the paper width, in units of `unit`
59 /// ## `height`
60 /// the paper height, in units of `unit`
61 /// ## `unit`
62 /// the unit for `width` and `height`. not [`Unit::None`][crate::Unit::None].
63 ///
64 /// # Returns
65 ///
66 /// a new [`PaperSize`][crate::PaperSize] object, use `gtk_paper_size_free()`
67 /// to free it
68 #[doc(alias = "gtk_paper_size_new_custom")]
69 pub fn new_custom(
70 name: &str,
71 display_name: &str,
72 width: f64,
73 height: f64,
74 unit: Unit,
75 ) -> PaperSize {
76 assert_initialized_main_thread!();
77 unsafe {
78 from_glib_full(ffi::gtk_paper_size_new_custom(
79 name.to_glib_none().0,
80 display_name.to_glib_none().0,
81 width,
82 height,
83 unit.into_glib(),
84 ))
85 }
86 }
87
88 /// Deserialize a paper size from an a{sv} variant in
89 /// the format produced by [`to_gvariant()`][Self::to_gvariant()].
90 /// ## `variant`
91 /// an a{sv} [`glib::Variant`][struct@crate::glib::Variant]
92 ///
93 /// # Returns
94 ///
95 /// a new [`PaperSize`][crate::PaperSize] object
96 #[doc(alias = "gtk_paper_size_new_from_gvariant")]
97 #[doc(alias = "new_from_gvariant")]
98 pub fn from_gvariant(variant: &glib::Variant) -> PaperSize {
99 assert_initialized_main_thread!();
100 unsafe {
101 from_glib_full(ffi::gtk_paper_size_new_from_gvariant(
102 variant.to_glib_none().0,
103 ))
104 }
105 }
106
107 /// Creates a new [`PaperSize`][crate::PaperSize] object by using
108 /// IPP information.
109 ///
110 /// If `ipp_name` is not a recognized paper name,
111 /// `width` and `height` are used to
112 /// construct a custom [`PaperSize`][crate::PaperSize] object.
113 /// ## `ipp_name`
114 /// an IPP paper name
115 /// ## `width`
116 /// the paper width, in points
117 /// ## `height`
118 /// the paper height in points
119 ///
120 /// # Returns
121 ///
122 /// a new [`PaperSize`][crate::PaperSize], use `gtk_paper_size_free()`
123 /// to free it
124 #[doc(alias = "gtk_paper_size_new_from_ipp")]
125 #[doc(alias = "new_from_ipp")]
126 pub fn from_ipp(ipp_name: &str, width: f64, height: f64) -> PaperSize {
127 assert_initialized_main_thread!();
128 unsafe {
129 from_glib_full(ffi::gtk_paper_size_new_from_ipp(
130 ipp_name.to_glib_none().0,
131 width,
132 height,
133 ))
134 }
135 }
136
137 /// Reads a paper size from the group `group_name` in the key file
138 /// `key_file`.
139 /// ## `key_file`
140 /// the [`glib::KeyFile`][crate::glib::KeyFile] to retrieve the papersize from
141 /// ## `group_name`
142 /// the name of the group in the key file to read,
143 /// or [`None`] to read the first group
144 ///
145 /// # Returns
146 ///
147 /// a new [`PaperSize`][crate::PaperSize] object with the restored
148 /// paper size, or [`None`] if an error occurred
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 = 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_paper_size_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) -> Option<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) -> Option<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) -> Option<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, [`glib::Variant`][struct@crate::glib::Variant]
416 #[doc(alias = "gtk_paper_size_to_gvariant")]
417 pub fn to_gvariant(&mut self) -> Option<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 [`glib::KeyFile`][crate::glib::KeyFile] 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() -> Option<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 {}