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::{PageSetup, PrintContext, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
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 unsafe {
135 let f: &F = &*(f as *const F);
136 f(
137 PrintOperationPreview::from_glib_borrow(this).unsafe_cast_ref(),
138 &from_glib_borrow(context),
139 &from_glib_borrow(page_setup),
140 )
141 }
142 }
143 unsafe {
144 let f: Box_<F> = Box_::new(f);
145 connect_raw(
146 self.as_ptr() as *mut _,
147 c"got-page-size".as_ptr() as *const _,
148 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
149 got_page_size_trampoline::<Self, F> as *const (),
150 )),
151 Box_::into_raw(f),
152 )
153 }
154 }
155
156 /// The ::ready signal gets emitted once per preview operation,
157 /// before the first page is rendered.
158 ///
159 /// A handler for this signal can be used for setup tasks.
160 /// ## `context`
161 /// the current [`PrintContext`][crate::PrintContext]
162 #[doc(alias = "ready")]
163 fn connect_ready<F: Fn(&Self, &PrintContext) + 'static>(&self, f: F) -> SignalHandlerId {
164 unsafe extern "C" fn ready_trampoline<
165 P: IsA<PrintOperationPreview>,
166 F: Fn(&P, &PrintContext) + 'static,
167 >(
168 this: *mut ffi::GtkPrintOperationPreview,
169 context: *mut ffi::GtkPrintContext,
170 f: glib::ffi::gpointer,
171 ) {
172 unsafe {
173 let f: &F = &*(f as *const F);
174 f(
175 PrintOperationPreview::from_glib_borrow(this).unsafe_cast_ref(),
176 &from_glib_borrow(context),
177 )
178 }
179 }
180 unsafe {
181 let f: Box_<F> = Box_::new(f);
182 connect_raw(
183 self.as_ptr() as *mut _,
184 c"ready".as_ptr() as *const _,
185 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
186 ready_trampoline::<Self, F> as *const (),
187 )),
188 Box_::into_raw(f),
189 )
190 }
191 }
192}
193
194impl<O: IsA<PrintOperationPreview>> PrintOperationPreviewExt for O {}