1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use glib;
use glib::translate::*;
use glib::GString;
use gtk_sys;
use std::ptr;
use Unit;

glib_wrapper! {
    /// `PaperSize` handles paper sizes. It uses the standard called
    /// [PWG 5101.1-2002 PWG: Standard for Media Standardized Names](http://www.pwg.org/standards.html)
    /// to name the paper sizes (and to get the data for the page sizes).
    /// In addition to standard paper sizes, `PaperSize` allows to
    /// construct custom paper sizes with arbitrary dimensions.
    ///
    /// The `PaperSize` object stores not only the dimensions (width
    /// and height) of a paper size and its name, it also provides
    /// default [print margins][print-margins].
    ///
    /// Printing support has been added in GTK+ 2.10.
    #[derive(Debug, PartialOrd, Ord, Hash)]
    pub struct PaperSize(Boxed<gtk_sys::GtkPaperSize>);

    match fn {
        copy => |ptr| gtk_sys::gtk_paper_size_copy(mut_override(ptr)),
        free => |ptr| gtk_sys::gtk_paper_size_free(ptr),
        get_type => || gtk_sys::gtk_paper_size_get_type(),
    }
}

impl PaperSize {
    /// Creates a new `PaperSize` object by parsing a
    /// [PWG 5101.1-2002](ftp://ftp.pwg.org/pub/pwg/candidates/cs-pwgmsn10-20020226-5101.1.pdf)
    /// paper name.
    ///
    /// If `name` is `None`, the default paper size is returned,
    /// see `PaperSize::get_default`.
    /// ## `name`
    /// a paper size name, or `None`
    ///
    /// # Returns
    ///
    /// a new `PaperSize`, use `PaperSize::free`
    /// to free it
    pub fn new(name: Option<&str>) -> PaperSize {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(gtk_sys::gtk_paper_size_new(name.to_glib_none().0)) }
    }

    /// Creates a new `PaperSize` object with the
    /// given parameters.
    /// ## `name`
    /// the paper name
    /// ## `display_name`
    /// the human-readable name
    /// ## `width`
    /// the paper width, in units of `unit`
    /// ## `height`
    /// the paper height, in units of `unit`
    /// ## `unit`
    /// the unit for `width` and `height`. not `Unit::None`.
    ///
    /// # Returns
    ///
    /// a new `PaperSize` object, use `PaperSize::free`
    /// to free it
    pub fn new_custom(
        name: &str,
        display_name: &str,
        width: f64,
        height: f64,
        unit: Unit,
    ) -> PaperSize {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(gtk_sys::gtk_paper_size_new_custom(
                name.to_glib_none().0,
                display_name.to_glib_none().0,
                width,
                height,
                unit.to_glib(),
            ))
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn from_gvariant(variant: &glib::Variant) -> PaperSize {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(gtk_sys::gtk_paper_size_new_from_gvariant(
                variant.to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v3_16", feature = "dox"))]
    pub fn from_ipp(ipp_name: &str, width: f64, height: f64) -> PaperSize {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(gtk_sys::gtk_paper_size_new_from_ipp(
                ipp_name.to_glib_none().0,
                width,
                height,
            ))
        }
    }

    pub fn from_key_file(
        key_file: &glib::KeyFile,
        group_name: Option<&str>,
    ) -> Result<PaperSize, glib::Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = ptr::null_mut();
            let ret = gtk_sys::gtk_paper_size_new_from_key_file(
                key_file.to_glib_none().0,
                group_name.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    pub fn from_ppd(ppd_name: &str, ppd_display_name: &str, width: f64, height: f64) -> PaperSize {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(gtk_sys::gtk_paper_size_new_from_ppd(
                ppd_name.to_glib_none().0,
                ppd_display_name.to_glib_none().0,
                width,
                height,
            ))
        }
    }

    /// Gets the default bottom margin for the `PaperSize`.
    /// ## `unit`
    /// the unit for the return value, not `Unit::None`
    ///
    /// # Returns
    ///
    /// the default bottom margin
    pub fn get_default_bottom_margin(&self, unit: Unit) -> f64 {
        unsafe {
            gtk_sys::gtk_paper_size_get_default_bottom_margin(
                mut_override(self.to_glib_none().0),
                unit.to_glib(),
            )
        }
    }

    /// Gets the default left margin for the `PaperSize`.
    /// ## `unit`
    /// the unit for the return value, not `Unit::None`
    ///
    /// # Returns
    ///
    /// the default left margin
    pub fn get_default_left_margin(&self, unit: Unit) -> f64 {
        unsafe {
            gtk_sys::gtk_paper_size_get_default_left_margin(
                mut_override(self.to_glib_none().0),
                unit.to_glib(),
            )
        }
    }

    /// Gets the default right margin for the `PaperSize`.
    /// ## `unit`
    /// the unit for the return value, not `Unit::None`
    ///
    /// # Returns
    ///
    /// the default right margin
    pub fn get_default_right_margin(&self, unit: Unit) -> f64 {
        unsafe {
            gtk_sys::gtk_paper_size_get_default_right_margin(
                mut_override(self.to_glib_none().0),
                unit.to_glib(),
            )
        }
    }

    /// Gets the default top margin for the `PaperSize`.
    /// ## `unit`
    /// the unit for the return value, not `Unit::None`
    ///
    /// # Returns
    ///
    /// the default top margin
    pub fn get_default_top_margin(&self, unit: Unit) -> f64 {
        unsafe {
            gtk_sys::gtk_paper_size_get_default_top_margin(
                mut_override(self.to_glib_none().0),
                unit.to_glib(),
            )
        }
    }

    /// Gets the human-readable name of the `PaperSize`.
    ///
    /// # Returns
    ///
    /// the human-readable name of `self`
    pub fn get_display_name(&self) -> Option<GString> {
        unsafe {
            from_glib_none(gtk_sys::gtk_paper_size_get_display_name(mut_override(
                self.to_glib_none().0,
            )))
        }
    }

    /// Gets the paper height of the `PaperSize`, in
    /// units of `unit`.
    /// ## `unit`
    /// the unit for the return value, not `Unit::None`
    ///
    /// # Returns
    ///
    /// the paper height
    pub fn get_height(&self, unit: Unit) -> f64 {
        unsafe {
            gtk_sys::gtk_paper_size_get_height(mut_override(self.to_glib_none().0), unit.to_glib())
        }
    }

    /// Gets the name of the `PaperSize`.
    ///
    /// # Returns
    ///
    /// the name of `self`
    pub fn get_name(&self) -> Option<GString> {
        unsafe {
            from_glib_none(gtk_sys::gtk_paper_size_get_name(mut_override(
                self.to_glib_none().0,
            )))
        }
    }

    /// Gets the PPD name of the `PaperSize`, which
    /// may be `None`.
    ///
    /// # Returns
    ///
    /// the PPD name of `self`
    pub fn get_ppd_name(&self) -> Option<GString> {
        unsafe {
            from_glib_none(gtk_sys::gtk_paper_size_get_ppd_name(mut_override(
                self.to_glib_none().0,
            )))
        }
    }

    /// Gets the paper width of the `PaperSize`, in
    /// units of `unit`.
    /// ## `unit`
    /// the unit for the return value, not `Unit::None`
    ///
    /// # Returns
    ///
    /// the paper width
    pub fn get_width(&self, unit: Unit) -> f64 {
        unsafe {
            gtk_sys::gtk_paper_size_get_width(mut_override(self.to_glib_none().0), unit.to_glib())
        }
    }

    /// Returns `true` if `self` is not a standard paper size.
    ///
    /// # Returns
    ///
    /// whether `self` is a custom paper size.
    pub fn is_custom(&self) -> bool {
        unsafe {
            from_glib(gtk_sys::gtk_paper_size_is_custom(mut_override(
                self.to_glib_none().0,
            )))
        }
    }

    /// Compares two `PaperSize` objects.
    /// ## `size2`
    /// another `PaperSize` object
    ///
    /// # Returns
    ///
    /// `true`, if `self` and `size2`
    /// represent the same paper size
    fn is_equal(&self, size2: &PaperSize) -> bool {
        unsafe {
            from_glib(gtk_sys::gtk_paper_size_is_equal(
                mut_override(self.to_glib_none().0),
                mut_override(size2.to_glib_none().0),
            ))
        }
    }

    /// Returns `true` if `self` is an IPP standard paper size.
    ///
    /// # Returns
    ///
    /// whether `self` is not an IPP custom paper size.
    #[cfg(any(feature = "v3_16", feature = "dox"))]
    pub fn is_ipp(&self) -> bool {
        unsafe {
            from_glib(gtk_sys::gtk_paper_size_is_ipp(mut_override(
                self.to_glib_none().0,
            )))
        }
    }

    /// Changes the dimensions of a `self` to `width` x `height`.
    /// ## `width`
    /// the new width in units of `unit`
    /// ## `height`
    /// the new height in units of `unit`
    /// ## `unit`
    /// the unit for `width` and `height`
    pub fn set_size(&mut self, width: f64, height: f64, unit: Unit) {
        unsafe {
            gtk_sys::gtk_paper_size_set_size(
                self.to_glib_none_mut().0,
                width,
                height,
                unit.to_glib(),
            );
        }
    }

    /// Serialize a paper size to an a{sv} variant.
    ///
    /// Feature: `v3_22`
    ///
    ///
    /// # Returns
    ///
    /// a new, floating, `glib::Variant`
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn to_gvariant(&mut self) -> Option<glib::Variant> {
        unsafe {
            from_glib_none(gtk_sys::gtk_paper_size_to_gvariant(
                self.to_glib_none_mut().0,
            ))
        }
    }

    /// This function adds the paper size from `self` to `key_file`.
    /// ## `key_file`
    /// the `glib::KeyFile` to save the paper size to
    /// ## `group_name`
    /// the group to add the settings to in `key_file`
    pub fn to_key_file(&mut self, key_file: &glib::KeyFile, group_name: &str) {
        unsafe {
            gtk_sys::gtk_paper_size_to_key_file(
                self.to_glib_none_mut().0,
                key_file.to_glib_none().0,
                group_name.to_glib_none().0,
            );
        }
    }

    /// Returns the name of the default paper size, which
    /// depends on the current locale.
    ///
    /// # Returns
    ///
    /// the name of the default paper size. The string
    /// is owned by GTK+ and should not be modified.
    pub fn get_default() -> Option<GString> {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(gtk_sys::gtk_paper_size_get_default()) }
    }

    /// Creates a list of known paper sizes.
    /// ## `include_custom`
    /// whether to include custom paper sizes
    ///  as defined in the page setup dialog
    ///
    /// # Returns
    ///
    /// a newly allocated list of newly
    ///  allocated `PaperSize` objects
    pub fn get_paper_sizes(include_custom: bool) -> Vec<PaperSize> {
        assert_initialized_main_thread!();
        unsafe {
            FromGlibPtrContainer::from_glib_full(gtk_sys::gtk_paper_size_get_paper_sizes(
                include_custom.to_glib(),
            ))
        }
    }
}

impl PartialEq for PaperSize {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.is_equal(other)
    }
}

impl Eq for PaperSize {}