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