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