webkit6/auto/
print_operation.rs1use crate::{PrintOperationResponse, WebView, ffi};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "WebKitPrintOperation")]
17 pub struct PrintOperation(Object<ffi::WebKitPrintOperation, ffi::WebKitPrintOperationClass>);
18
19 match fn {
20 type_ => || ffi::webkit_print_operation_get_type(),
21 }
22}
23
24impl PrintOperation {
25 #[doc(alias = "webkit_print_operation_new")]
26 pub fn new(web_view: &impl IsA<WebView>) -> PrintOperation {
27 skip_assert_initialized!();
28 unsafe {
29 from_glib_full(ffi::webkit_print_operation_new(
30 web_view.as_ref().to_glib_none().0,
31 ))
32 }
33 }
34
35 pub fn builder() -> PrintOperationBuilder {
40 PrintOperationBuilder::new()
41 }
42
43 #[doc(alias = "webkit_print_operation_get_page_setup")]
44 #[doc(alias = "get_page_setup")]
45 #[doc(alias = "page-setup")]
46 pub fn page_setup(&self) -> Option<gtk::PageSetup> {
47 unsafe {
48 from_glib_none(ffi::webkit_print_operation_get_page_setup(
49 self.to_glib_none().0,
50 ))
51 }
52 }
53
54 #[doc(alias = "webkit_print_operation_get_print_settings")]
55 #[doc(alias = "get_print_settings")]
56 #[doc(alias = "print-settings")]
57 pub fn print_settings(&self) -> Option<gtk::PrintSettings> {
58 unsafe {
59 from_glib_none(ffi::webkit_print_operation_get_print_settings(
60 self.to_glib_none().0,
61 ))
62 }
63 }
64
65 #[doc(alias = "webkit_print_operation_print")]
66 pub fn print(&self) {
67 unsafe {
68 ffi::webkit_print_operation_print(self.to_glib_none().0);
69 }
70 }
71
72 #[doc(alias = "webkit_print_operation_run_dialog")]
73 pub fn run_dialog(&self, parent: Option<&impl IsA<gtk::Window>>) -> PrintOperationResponse {
74 unsafe {
75 from_glib(ffi::webkit_print_operation_run_dialog(
76 self.to_glib_none().0,
77 parent.map(|p| p.as_ref()).to_glib_none().0,
78 ))
79 }
80 }
81
82 #[doc(alias = "webkit_print_operation_set_page_setup")]
83 #[doc(alias = "page-setup")]
84 pub fn set_page_setup(&self, page_setup: >k::PageSetup) {
85 unsafe {
86 ffi::webkit_print_operation_set_page_setup(
87 self.to_glib_none().0,
88 page_setup.to_glib_none().0,
89 );
90 }
91 }
92
93 #[doc(alias = "webkit_print_operation_set_print_settings")]
94 #[doc(alias = "print-settings")]
95 pub fn set_print_settings(&self, print_settings: >k::PrintSettings) {
96 unsafe {
97 ffi::webkit_print_operation_set_print_settings(
98 self.to_glib_none().0,
99 print_settings.to_glib_none().0,
100 );
101 }
102 }
103
104 #[doc(alias = "web-view")]
105 pub fn web_view(&self) -> Option<WebView> {
106 ObjectExt::property(self, "web-view")
107 }
108
109 #[doc(alias = "failed")]
110 pub fn connect_failed<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
111 unsafe extern "C" fn failed_trampoline<F: Fn(&PrintOperation, &glib::Error) + 'static>(
112 this: *mut ffi::WebKitPrintOperation,
113 error: *mut glib::ffi::GError,
114 f: glib::ffi::gpointer,
115 ) {
116 unsafe {
117 let f: &F = &*(f as *const F);
118 f(&from_glib_borrow(this), &from_glib_borrow(error))
119 }
120 }
121 unsafe {
122 let f: Box_<F> = Box_::new(f);
123 connect_raw(
124 self.as_ptr() as *mut _,
125 c"failed".as_ptr(),
126 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
127 failed_trampoline::<F> as *const (),
128 )),
129 Box_::into_raw(f),
130 )
131 }
132 }
133
134 #[doc(alias = "finished")]
135 pub fn connect_finished<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
136 unsafe extern "C" fn finished_trampoline<F: Fn(&PrintOperation) + 'static>(
137 this: *mut ffi::WebKitPrintOperation,
138 f: glib::ffi::gpointer,
139 ) {
140 unsafe {
141 let f: &F = &*(f as *const F);
142 f(&from_glib_borrow(this))
143 }
144 }
145 unsafe {
146 let f: Box_<F> = Box_::new(f);
147 connect_raw(
148 self.as_ptr() as *mut _,
149 c"finished".as_ptr(),
150 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
151 finished_trampoline::<F> as *const (),
152 )),
153 Box_::into_raw(f),
154 )
155 }
156 }
157
158 #[doc(alias = "page-setup")]
159 pub fn connect_page_setup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
160 unsafe extern "C" fn notify_page_setup_trampoline<F: Fn(&PrintOperation) + 'static>(
161 this: *mut ffi::WebKitPrintOperation,
162 _param_spec: glib::ffi::gpointer,
163 f: glib::ffi::gpointer,
164 ) {
165 unsafe {
166 let f: &F = &*(f as *const F);
167 f(&from_glib_borrow(this))
168 }
169 }
170 unsafe {
171 let f: Box_<F> = Box_::new(f);
172 connect_raw(
173 self.as_ptr() as *mut _,
174 c"notify::page-setup".as_ptr(),
175 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
176 notify_page_setup_trampoline::<F> as *const (),
177 )),
178 Box_::into_raw(f),
179 )
180 }
181 }
182
183 #[doc(alias = "print-settings")]
184 pub fn connect_print_settings_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
185 unsafe extern "C" fn notify_print_settings_trampoline<F: Fn(&PrintOperation) + 'static>(
186 this: *mut ffi::WebKitPrintOperation,
187 _param_spec: glib::ffi::gpointer,
188 f: glib::ffi::gpointer,
189 ) {
190 unsafe {
191 let f: &F = &*(f as *const F);
192 f(&from_glib_borrow(this))
193 }
194 }
195 unsafe {
196 let f: Box_<F> = Box_::new(f);
197 connect_raw(
198 self.as_ptr() as *mut _,
199 c"notify::print-settings".as_ptr(),
200 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
201 notify_print_settings_trampoline::<F> as *const (),
202 )),
203 Box_::into_raw(f),
204 )
205 }
206 }
207}
208
209impl Default for PrintOperation {
210 fn default() -> Self {
211 glib::object::Object::new::<Self>()
212 }
213}
214
215#[must_use = "The builder must be built to be used"]
220pub struct PrintOperationBuilder {
221 builder: glib::object::ObjectBuilder<'static, PrintOperation>,
222}
223
224impl PrintOperationBuilder {
225 fn new() -> Self {
226 Self {
227 builder: glib::object::Object::builder(),
228 }
229 }
230
231 pub fn page_setup(self, page_setup: >k::PageSetup) -> Self {
232 Self {
233 builder: self.builder.property("page-setup", page_setup.clone()),
234 }
235 }
236
237 pub fn print_settings(self, print_settings: >k::PrintSettings) -> Self {
238 Self {
239 builder: self
240 .builder
241 .property("print-settings", print_settings.clone()),
242 }
243 }
244
245 pub fn web_view(self, web_view: &impl IsA<WebView>) -> Self {
246 Self {
247 builder: self.builder.property("web-view", web_view.clone().upcast()),
248 }
249 }
250
251 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
254 pub fn build(self) -> PrintOperation {
255 assert_initialized_main_thread!();
256 self.builder.build()
257 }
258}