Skip to main content

webkit6/auto/
input_method_context.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// from webkit-gir-files
4// DO NOT EDIT
5
6use 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    /// Base class for input method contexts.
17    ///
18    /// WebKitInputMethodContext defines the interface to implement WebKit input methods.
19    /// The input methods are used by WebKit, when editable content is focused, to map from
20    /// key events to Unicode character strings.
21    ///
22    /// An input method may consume multiple key events in sequence and finally
23    /// output the composed result. This is called preediting, and an input method
24    /// may provide feedback about this process by displaying the intermediate
25    /// composition states as preedit text.
26    ///
27    /// This is an Abstract Base Class, you cannot instantiate it.
28    ///
29    /// ## Properties
30    ///
31    ///
32    /// #### `input-hints`
33    ///  The [`InputHints`][crate::InputHints] of the input associated with this context.
34    ///
35    /// Readable | Writeable
36    ///
37    ///
38    /// #### `input-purpose`
39    ///  The [`InputPurpose`][crate::InputPurpose] of the input associated with this context.
40    ///
41    /// Readable | Writeable
42    ///
43    /// ## Signals
44    ///
45    ///
46    /// #### `committed`
47    ///  Emitted when a complete input sequence has been entered by the user.
48    /// This can be a single character immediately after a key press or the
49    /// final result of preediting.
50    ///
51    ///
52    ///
53    ///
54    /// #### `delete-surrounding`
55    ///  Emitted when the input method wants to delete the context surrounding the cursor.
56    /// If `offset` is a negative value, it means a position before the cursor.
57    ///
58    ///
59    ///
60    ///
61    /// #### `preedit-changed`
62    ///  Emitted whenever the preedit sequence currently being entered has changed.
63    /// It is also emitted at the end of a preedit sequence, in which case
64    /// `webkit_input_method_context_get_preedit()` returns the empty string.
65    ///
66    ///
67    ///
68    ///
69    /// #### `preedit-finished`
70    ///  Emitted when a preediting sequence has been completed or canceled.
71    ///
72    ///
73    ///
74    ///
75    /// #### `preedit-started`
76    ///  Emitted when a new preediting sequence starts.
77    ///
78    ///
79    ///
80    /// # Implements
81    ///
82    /// [`InputMethodContextExt`][trait@crate::prelude::InputMethodContextExt]
83    #[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
95/// Trait containing all [`struct@InputMethodContext`] methods.
96///
97/// # Implementors
98///
99/// [`InputMethodContext`][struct@crate::InputMethodContext]
100pub trait InputMethodContextExt: IsA<InputMethodContext> + 'static {
101    /// Allow `key_event` to be handled by the input method.
102    ///
103    /// If [`true`] is returned, then no further processing should be
104    /// done for the key event.
105    /// ## `key_event`
106    /// the key event to filter
107    ///
108    /// # Returns
109    ///
110    /// [`true`] if the key event was handled, or [`false`] otherwise
111    #[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    /// Get the value of the [`input-hints`][struct@crate::InputMethodContext#input-hints] property.
122    ///
123    /// # Returns
124    ///
125    /// the [`InputHints`][crate::InputHints] of the input associated with `self`
126    #[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    /// Get the value of the [`input-purpose`][struct@crate::InputMethodContext#input-purpose] property.
138    ///
139    /// # Returns
140    ///
141    /// the [`InputPurpose`][crate::InputPurpose] of the input associated with `self`
142    #[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_get_preedit")]
154    //#[doc(alias = "get_preedit")]
155    //fn preedit(&self, underlines: /*Unimplemented*/Vec<InputMethodUnderline>) -> (Option<glib::GString>, u32) {
156    //    unsafe { TODO: call ffi:webkit_input_method_context_get_preedit() }
157    //}
158
159    /// Notify `self` that cursor area changed in input associated.
160    /// ## `x`
161    /// the x coordinate of cursor location
162    /// ## `y`
163    /// the y coordinate of cursor location
164    /// ## `width`
165    /// the width of cursor area
166    /// ## `height`
167    /// the height of cursor area
168    #[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    /// Notify `self` that input associated has gained focus.
182    #[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    /// Notify `self` that input associated has lost focus.
190    #[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    /// Notify `self` that the context surrounding the cursor has changed.
198    ///
199    /// If there's no selection `selection_index` is the same as `cursor_index`.
200    /// ## `text`
201    /// text surrounding the insertion point
202    /// ## `length`
203    /// the length of `text`, or -1 if `text` is nul-terminated
204    /// ## `cursor_index`
205    /// the byte index of the insertion cursor within `text`.
206    /// ## `selection_index`
207    /// the byte index of the selection cursor within `text`.
208    #[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    /// Reset the `self`.
223    ///
224    /// This will typically cause the input to clear the preedit state.
225    #[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    /// Set whether `self` should enable preedit to display feedback.
233    /// ## `enabled`
234    /// whether to enable preedit
235    #[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    /// Set the value of the [`input-hints`][struct@crate::InputMethodContext#input-hints] property.
246    /// ## `hints`
247    /// a [`InputHints`][crate::InputHints]
248    #[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    /// Set the value of the [`input-purpose`][struct@crate::InputMethodContext#input-purpose] property.
260    /// ## `purpose`
261    /// a [`InputPurpose`][crate::InputPurpose]
262    #[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    /// Emitted when a complete input sequence has been entered by the user.
274    /// This can be a single character immediately after a key press or the
275    /// final result of preediting.
276    /// ## `text`
277    /// the string result
278    #[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    /// Emitted when the input method wants to delete the context surrounding the cursor.
310    /// If `offset` is a negative value, it means a position before the cursor.
311    /// ## `offset`
312    /// the character offset from the cursor position of the text to be deleted.
313    /// ## `n_chars`
314    /// the number of characters to be deleted
315    #[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    /// Emitted whenever the preedit sequence currently being entered has changed.
352    /// It is also emitted at the end of a preedit sequence, in which case
353    /// `webkit_input_method_context_get_preedit()` returns the empty string.
354    #[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    /// Emitted when a preediting sequence has been completed or canceled.
382    #[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    /// Emitted when a new preediting sequence starts.
410    #[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 {}