gtk4/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::{ffi, PageSetup, PrintContext};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// The interface that is used to implement print preview.
16    ///
17    /// A [`PrintOperationPreview`][crate::PrintOperationPreview] object is passed to the
18    /// [`preview`][struct@crate::PrintOperation#preview] signal by
19    /// [`PrintOperation`][crate::PrintOperation].
20    ///
21    /// ## Signals
22    ///
23    ///
24    /// #### `got-page-size`
25    ///  Emitted once for each page that gets rendered to the preview.
26    ///
27    /// A handler for this signal should update the @context
28    /// according to @page_setup and set up a suitable cairo
29    /// context, using [`PrintContext::set_cairo_context()`][crate::PrintContext::set_cairo_context()].
30    ///
31    ///
32    ///
33    ///
34    /// #### `ready`
35    ///  The ::ready signal gets emitted once per preview operation,
36    /// before the first page is rendered.
37    ///
38    /// A handler for this signal can be used for setup tasks.
39    ///
40    ///
41    ///
42    /// # Implements
43    ///
44    /// [`PrintOperationPreviewExt`][trait@crate::prelude::PrintOperationPreviewExt]
45    #[doc(alias = "GtkPrintOperationPreview")]
46    pub struct PrintOperationPreview(Interface<ffi::GtkPrintOperationPreview, ffi::GtkPrintOperationPreviewIface>);
47
48    match fn {
49        type_ => || ffi::gtk_print_operation_preview_get_type(),
50    }
51}
52
53impl PrintOperationPreview {
54    pub const NONE: Option<&'static PrintOperationPreview> = None;
55}
56
57/// Trait containing all [`struct@PrintOperationPreview`] methods.
58///
59/// # Implementors
60///
61/// [`PrintOperationPreview`][struct@crate::PrintOperationPreview], [`PrintOperation`][struct@crate::PrintOperation]
62pub trait PrintOperationPreviewExt: IsA<PrintOperationPreview> + 'static {
63    /// Ends a preview.
64    ///
65    /// This function must be called to finish a custom print preview.
66    #[doc(alias = "gtk_print_operation_preview_end_preview")]
67    fn end_preview(&self) {
68        unsafe {
69            ffi::gtk_print_operation_preview_end_preview(self.as_ref().to_glib_none().0);
70        }
71    }
72
73    /// Returns whether the given page is included in the set of pages that
74    /// have been selected for printing.
75    /// ## `page_nr`
76    /// a page number
77    ///
78    /// # Returns
79    ///
80    /// [`true`] if the page has been selected for printing
81    #[doc(alias = "gtk_print_operation_preview_is_selected")]
82    fn is_selected(&self, page_nr: i32) -> bool {
83        unsafe {
84            from_glib(ffi::gtk_print_operation_preview_is_selected(
85                self.as_ref().to_glib_none().0,
86                page_nr,
87            ))
88        }
89    }
90
91    /// Renders a page to the preview.
92    ///
93    /// This is using the print context that was passed to the
94    /// [`preview`][struct@crate::PrintOperation#preview] handler together
95    /// with @self.
96    ///
97    /// A custom print preview should use this function to render
98    /// the currently selected page.
99    ///
100    /// Note that this function requires a suitable cairo context to
101    /// be associated with the print context.
102    /// ## `page_nr`
103    /// the page to render
104    #[doc(alias = "gtk_print_operation_preview_render_page")]
105    fn render_page(&self, page_nr: i32) {
106        unsafe {
107            ffi::gtk_print_operation_preview_render_page(self.as_ref().to_glib_none().0, page_nr);
108        }
109    }
110
111    /// Emitted once for each page 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                c"got-page-size".as_ptr() as *const _,
146                Some(std::mem::transmute::<*const (), 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                c"ready".as_ptr() as *const _,
181                Some(std::mem::transmute::<*const (), 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 {}