Skip to main content

gtk/auto/
print_operation_preview.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::{PageSetup, PrintContext};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14    ///
15    ///
16    /// ## Signals
17    ///
18    ///
19    /// #### `got-page-size`
20    ///  The ::got-page-size signal is emitted once for each page
21    /// that gets rendered to the preview.
22    ///
23    /// A handler for this signal should update the `context`
24    /// according to `page_setup` and set up a suitable cairo
25    /// context, using [`PrintContext::set_cairo_context()`][crate::PrintContext::set_cairo_context()].
26    ///
27    ///
28    ///
29    ///
30    /// #### `ready`
31    ///  The ::ready signal gets emitted once per preview operation,
32    /// before the first page is rendered.
33    ///
34    /// A handler for this signal can be used for setup tasks.
35    ///
36    ///
37    ///
38    /// # Implements
39    ///
40    /// [`PrintOperationPreviewExt`][trait@crate::prelude::PrintOperationPreviewExt]
41    #[doc(alias = "GtkPrintOperationPreview")]
42    pub struct PrintOperationPreview(Interface<ffi::GtkPrintOperationPreview, ffi::GtkPrintOperationPreviewIface>);
43
44    match fn {
45        type_ => || ffi::gtk_print_operation_preview_get_type(),
46    }
47}
48
49impl PrintOperationPreview {
50    pub const NONE: Option<&'static PrintOperationPreview> = None;
51}
52
53mod sealed {
54    pub trait Sealed {}
55    impl<T: super::IsA<super::PrintOperationPreview>> Sealed for T {}
56}
57
58/// Trait containing all [`struct@PrintOperationPreview`] methods.
59///
60/// # Implementors
61///
62/// [`PrintOperationPreview`][struct@crate::PrintOperationPreview], [`PrintOperation`][struct@crate::PrintOperation]
63pub trait PrintOperationPreviewExt: IsA<PrintOperationPreview> + sealed::Sealed + 'static {
64    /// Ends a preview.
65    ///
66    /// This function must be called to finish a custom print preview.
67    #[doc(alias = "gtk_print_operation_preview_end_preview")]
68    fn end_preview(&self) {
69        unsafe {
70            ffi::gtk_print_operation_preview_end_preview(self.as_ref().to_glib_none().0);
71        }
72    }
73
74    /// Returns whether the given page is included in the set of pages that
75    /// have been selected for printing.
76    /// ## `page_nr`
77    /// a page number
78    ///
79    /// # Returns
80    ///
81    /// [`true`] if the page has been selected for printing
82    #[doc(alias = "gtk_print_operation_preview_is_selected")]
83    fn is_selected(&self, page_nr: i32) -> bool {
84        unsafe {
85            from_glib(ffi::gtk_print_operation_preview_is_selected(
86                self.as_ref().to_glib_none().0,
87                page_nr,
88            ))
89        }
90    }
91
92    /// Renders a page to the preview, using the print context that
93    /// was passed to the [`preview`][struct@crate::PrintOperation#preview] handler together
94    /// with `self`.
95    ///
96    /// A custom iprint preview should use this function in its ::expose
97    /// handler to render the currently selected page.
98    ///
99    /// Note that this function requires a suitable cairo context to
100    /// be associated with the print context.
101    /// ## `page_nr`
102    /// the page to render
103    #[doc(alias = "gtk_print_operation_preview_render_page")]
104    fn render_page(&self, page_nr: i32) {
105        unsafe {
106            ffi::gtk_print_operation_preview_render_page(self.as_ref().to_glib_none().0, page_nr);
107        }
108    }
109
110    /// The ::got-page-size signal is emitted once for each page
111    /// that gets rendered to the preview.
112    ///
113    /// A handler for this signal should update the `context`
114    /// according to `page_setup` and set up a suitable cairo
115    /// context, using [`PrintContext::set_cairo_context()`][crate::PrintContext::set_cairo_context()].
116    /// ## `context`
117    /// the current [`PrintContext`][crate::PrintContext]
118    /// ## `page_setup`
119    /// the [`PageSetup`][crate::PageSetup] for the current page
120    #[doc(alias = "got-page-size")]
121    fn connect_got_page_size<F: Fn(&Self, &PrintContext, &PageSetup) + 'static>(
122        &self,
123        f: F,
124    ) -> SignalHandlerId {
125        unsafe extern "C" fn got_page_size_trampoline<
126            P: IsA<PrintOperationPreview>,
127            F: Fn(&P, &PrintContext, &PageSetup) + 'static,
128        >(
129            this: *mut ffi::GtkPrintOperationPreview,
130            context: *mut ffi::GtkPrintContext,
131            page_setup: *mut ffi::GtkPageSetup,
132            f: glib::ffi::gpointer,
133        ) {
134            let f: &F = &*(f as *const F);
135            f(
136                PrintOperationPreview::from_glib_borrow(this).unsafe_cast_ref(),
137                &from_glib_borrow(context),
138                &from_glib_borrow(page_setup),
139            )
140        }
141        unsafe {
142            let f: Box_<F> = Box_::new(f);
143            connect_raw(
144                self.as_ptr() as *mut _,
145                b"got-page-size\0".as_ptr() as *const _,
146                Some(transmute::<_, unsafe extern "C" fn()>(
147                    got_page_size_trampoline::<Self, F> as *const (),
148                )),
149                Box_::into_raw(f),
150            )
151        }
152    }
153
154    /// The ::ready signal gets emitted once per preview operation,
155    /// before the first page is rendered.
156    ///
157    /// A handler for this signal can be used for setup tasks.
158    /// ## `context`
159    /// the current [`PrintContext`][crate::PrintContext]
160    #[doc(alias = "ready")]
161    fn connect_ready<F: Fn(&Self, &PrintContext) + 'static>(&self, f: F) -> SignalHandlerId {
162        unsafe extern "C" fn ready_trampoline<
163            P: IsA<PrintOperationPreview>,
164            F: Fn(&P, &PrintContext) + 'static,
165        >(
166            this: *mut ffi::GtkPrintOperationPreview,
167            context: *mut ffi::GtkPrintContext,
168            f: glib::ffi::gpointer,
169        ) {
170            let f: &F = &*(f as *const F);
171            f(
172                PrintOperationPreview::from_glib_borrow(this).unsafe_cast_ref(),
173                &from_glib_borrow(context),
174            )
175        }
176        unsafe {
177            let f: Box_<F> = Box_::new(f);
178            connect_raw(
179                self.as_ptr() as *mut _,
180                b"ready\0".as_ptr() as *const _,
181                Some(transmute::<_, unsafe extern "C" fn()>(
182                    ready_trampoline::<Self, F> as *const (),
183                )),
184                Box_::into_raw(f),
185            )
186        }
187    }
188}
189
190impl<O: IsA<PrintOperationPreview>> PrintOperationPreviewExt for O {}
191
192impl fmt::Display for PrintOperationPreview {
193    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
194        f.write_str("PrintOperationPreview")
195    }
196}