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