1use crate::{InputHints, InputPurpose, 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 = "WebKitInputMethodContext")]
84 pub struct InputMethodContext(Object<ffi::WebKitInputMethodContext, ffi::WebKitInputMethodContextClass>);
85
86 match fn {
87 type_ => || ffi::webkit_input_method_context_get_type(),
88 }
89}
90
91impl InputMethodContext {
92 pub const NONE: Option<&'static InputMethodContext> = None;
93}
94
95pub trait InputMethodContextExt: IsA<InputMethodContext> + 'static {
101 #[doc(alias = "webkit_input_method_context_filter_key_event")]
112 fn filter_key_event(&self, key_event: impl AsRef<gdk::Event>) -> bool {
113 unsafe {
114 from_glib(ffi::webkit_input_method_context_filter_key_event(
115 self.as_ref().to_glib_none().0,
116 key_event.as_ref().to_glib_none().0,
117 ))
118 }
119 }
120
121 #[doc(alias = "webkit_input_method_context_get_input_hints")]
127 #[doc(alias = "get_input_hints")]
128 #[doc(alias = "input-hints")]
129 fn input_hints(&self) -> InputHints {
130 unsafe {
131 from_glib(ffi::webkit_input_method_context_get_input_hints(
132 self.as_ref().to_glib_none().0,
133 ))
134 }
135 }
136
137 #[doc(alias = "webkit_input_method_context_get_input_purpose")]
143 #[doc(alias = "get_input_purpose")]
144 #[doc(alias = "input-purpose")]
145 fn input_purpose(&self) -> InputPurpose {
146 unsafe {
147 from_glib(ffi::webkit_input_method_context_get_input_purpose(
148 self.as_ref().to_glib_none().0,
149 ))
150 }
151 }
152
153 #[doc(alias = "webkit_input_method_context_notify_cursor_area")]
169 fn notify_cursor_area(&self, x: i32, y: i32, width: i32, height: i32) {
170 unsafe {
171 ffi::webkit_input_method_context_notify_cursor_area(
172 self.as_ref().to_glib_none().0,
173 x,
174 y,
175 width,
176 height,
177 );
178 }
179 }
180
181 #[doc(alias = "webkit_input_method_context_notify_focus_in")]
183 fn notify_focus_in(&self) {
184 unsafe {
185 ffi::webkit_input_method_context_notify_focus_in(self.as_ref().to_glib_none().0);
186 }
187 }
188
189 #[doc(alias = "webkit_input_method_context_notify_focus_out")]
191 fn notify_focus_out(&self) {
192 unsafe {
193 ffi::webkit_input_method_context_notify_focus_out(self.as_ref().to_glib_none().0);
194 }
195 }
196
197 #[doc(alias = "webkit_input_method_context_notify_surrounding")]
209 fn notify_surrounding(&self, text: &str, cursor_index: u32, selection_index: u32) {
210 let length = text.len() as _;
211 unsafe {
212 ffi::webkit_input_method_context_notify_surrounding(
213 self.as_ref().to_glib_none().0,
214 text.to_glib_none().0,
215 length,
216 cursor_index,
217 selection_index,
218 );
219 }
220 }
221
222 #[doc(alias = "webkit_input_method_context_reset")]
226 fn reset(&self) {
227 unsafe {
228 ffi::webkit_input_method_context_reset(self.as_ref().to_glib_none().0);
229 }
230 }
231
232 #[doc(alias = "webkit_input_method_context_set_enable_preedit")]
236 fn set_enable_preedit(&self, enabled: bool) {
237 unsafe {
238 ffi::webkit_input_method_context_set_enable_preedit(
239 self.as_ref().to_glib_none().0,
240 enabled.into_glib(),
241 );
242 }
243 }
244
245 #[doc(alias = "webkit_input_method_context_set_input_hints")]
249 #[doc(alias = "input-hints")]
250 fn set_input_hints(&self, hints: InputHints) {
251 unsafe {
252 ffi::webkit_input_method_context_set_input_hints(
253 self.as_ref().to_glib_none().0,
254 hints.into_glib(),
255 );
256 }
257 }
258
259 #[doc(alias = "webkit_input_method_context_set_input_purpose")]
263 #[doc(alias = "input-purpose")]
264 fn set_input_purpose(&self, purpose: InputPurpose) {
265 unsafe {
266 ffi::webkit_input_method_context_set_input_purpose(
267 self.as_ref().to_glib_none().0,
268 purpose.into_glib(),
269 );
270 }
271 }
272
273 #[doc(alias = "committed")]
279 fn connect_committed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
280 unsafe extern "C" fn committed_trampoline<
281 P: IsA<InputMethodContext>,
282 F: Fn(&P, &str) + 'static,
283 >(
284 this: *mut ffi::WebKitInputMethodContext,
285 text: *mut std::ffi::c_char,
286 f: glib::ffi::gpointer,
287 ) {
288 unsafe {
289 let f: &F = &*(f as *const F);
290 f(
291 InputMethodContext::from_glib_borrow(this).unsafe_cast_ref(),
292 &glib::GString::from_glib_borrow(text),
293 )
294 }
295 }
296 unsafe {
297 let f: Box_<F> = Box_::new(f);
298 connect_raw(
299 self.as_ptr() as *mut _,
300 c"committed".as_ptr(),
301 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
302 committed_trampoline::<Self, F> as *const (),
303 )),
304 Box_::into_raw(f),
305 )
306 }
307 }
308
309 #[doc(alias = "delete-surrounding")]
316 fn connect_delete_surrounding<F: Fn(&Self, i32, u32) + 'static>(
317 &self,
318 f: F,
319 ) -> SignalHandlerId {
320 unsafe extern "C" fn delete_surrounding_trampoline<
321 P: IsA<InputMethodContext>,
322 F: Fn(&P, i32, u32) + 'static,
323 >(
324 this: *mut ffi::WebKitInputMethodContext,
325 offset: std::ffi::c_int,
326 n_chars: std::ffi::c_uint,
327 f: glib::ffi::gpointer,
328 ) {
329 unsafe {
330 let f: &F = &*(f as *const F);
331 f(
332 InputMethodContext::from_glib_borrow(this).unsafe_cast_ref(),
333 offset,
334 n_chars,
335 )
336 }
337 }
338 unsafe {
339 let f: Box_<F> = Box_::new(f);
340 connect_raw(
341 self.as_ptr() as *mut _,
342 c"delete-surrounding".as_ptr(),
343 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
344 delete_surrounding_trampoline::<Self, F> as *const (),
345 )),
346 Box_::into_raw(f),
347 )
348 }
349 }
350
351 #[doc(alias = "preedit-changed")]
355 fn connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
356 unsafe extern "C" fn preedit_changed_trampoline<
357 P: IsA<InputMethodContext>,
358 F: Fn(&P) + 'static,
359 >(
360 this: *mut ffi::WebKitInputMethodContext,
361 f: glib::ffi::gpointer,
362 ) {
363 unsafe {
364 let f: &F = &*(f as *const F);
365 f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
366 }
367 }
368 unsafe {
369 let f: Box_<F> = Box_::new(f);
370 connect_raw(
371 self.as_ptr() as *mut _,
372 c"preedit-changed".as_ptr(),
373 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
374 preedit_changed_trampoline::<Self, F> as *const (),
375 )),
376 Box_::into_raw(f),
377 )
378 }
379 }
380
381 #[doc(alias = "preedit-finished")]
383 fn connect_preedit_finished<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
384 unsafe extern "C" fn preedit_finished_trampoline<
385 P: IsA<InputMethodContext>,
386 F: Fn(&P) + 'static,
387 >(
388 this: *mut ffi::WebKitInputMethodContext,
389 f: glib::ffi::gpointer,
390 ) {
391 unsafe {
392 let f: &F = &*(f as *const F);
393 f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
394 }
395 }
396 unsafe {
397 let f: Box_<F> = Box_::new(f);
398 connect_raw(
399 self.as_ptr() as *mut _,
400 c"preedit-finished".as_ptr(),
401 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
402 preedit_finished_trampoline::<Self, F> as *const (),
403 )),
404 Box_::into_raw(f),
405 )
406 }
407 }
408
409 #[doc(alias = "preedit-started")]
411 fn connect_preedit_started<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
412 unsafe extern "C" fn preedit_started_trampoline<
413 P: IsA<InputMethodContext>,
414 F: Fn(&P) + 'static,
415 >(
416 this: *mut ffi::WebKitInputMethodContext,
417 f: glib::ffi::gpointer,
418 ) {
419 unsafe {
420 let f: &F = &*(f as *const F);
421 f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
422 }
423 }
424 unsafe {
425 let f: Box_<F> = Box_::new(f);
426 connect_raw(
427 self.as_ptr() as *mut _,
428 c"preedit-started".as_ptr(),
429 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
430 preedit_started_trampoline::<Self, F> as *const (),
431 )),
432 Box_::into_raw(f),
433 )
434 }
435 }
436
437 #[doc(alias = "input-hints")]
438 fn connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
439 unsafe extern "C" fn notify_input_hints_trampoline<
440 P: IsA<InputMethodContext>,
441 F: Fn(&P) + 'static,
442 >(
443 this: *mut ffi::WebKitInputMethodContext,
444 _param_spec: glib::ffi::gpointer,
445 f: glib::ffi::gpointer,
446 ) {
447 unsafe {
448 let f: &F = &*(f as *const F);
449 f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
450 }
451 }
452 unsafe {
453 let f: Box_<F> = Box_::new(f);
454 connect_raw(
455 self.as_ptr() as *mut _,
456 c"notify::input-hints".as_ptr(),
457 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
458 notify_input_hints_trampoline::<Self, F> as *const (),
459 )),
460 Box_::into_raw(f),
461 )
462 }
463 }
464
465 #[doc(alias = "input-purpose")]
466 fn connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
467 unsafe extern "C" fn notify_input_purpose_trampoline<
468 P: IsA<InputMethodContext>,
469 F: Fn(&P) + 'static,
470 >(
471 this: *mut ffi::WebKitInputMethodContext,
472 _param_spec: glib::ffi::gpointer,
473 f: glib::ffi::gpointer,
474 ) {
475 unsafe {
476 let f: &F = &*(f as *const F);
477 f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
478 }
479 }
480 unsafe {
481 let f: Box_<F> = Box_::new(f);
482 connect_raw(
483 self.as_ptr() as *mut _,
484 c"notify::input-purpose".as_ptr(),
485 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
486 notify_input_purpose_trampoline::<Self, F> as *const (),
487 )),
488 Box_::into_raw(f),
489 )
490 }
491 }
492}
493
494impl<O: IsA<InputMethodContext>> InputMethodContextExt for O {}