1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from webkit-gir-files
// DO NOT EDIT

use crate::{ffi, InputHints, InputPurpose};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// Base class for input method contexts.
    ///
    /// WebKitInputMethodContext defines the interface to implement WebKit input methods.
    /// The input methods are used by WebKit, when editable content is focused, to map from
    /// key events to Unicode character strings.
    ///
    /// An input method may consume multiple key events in sequence and finally
    /// output the composed result. This is called preediting, and an input method
    /// may provide feedback about this process by displaying the intermediate
    /// composition states as preedit text.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// ## Properties
    ///
    ///
    /// #### `input-hints`
    ///  The #WebKitInputHints of the input associated with this context.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `input-purpose`
    ///  The #WebKitInputPurpose of the input associated with this context.
    ///
    /// Readable | Writeable
    ///
    /// ## Signals
    ///
    ///
    /// #### `committed`
    ///  Emitted when a complete input sequence has been entered by the user.
    /// This can be a single character immediately after a key press or the
    /// final result of preediting.
    ///
    ///
    ///
    ///
    /// #### `delete-surrounding`
    ///  Emitted when the input method wants to delete the context surrounding the cursor.
    /// If @offset is a negative value, it means a position before the cursor.
    ///
    ///
    ///
    ///
    /// #### `preedit-changed`
    ///  Emitted whenever the preedit sequence currently being entered has changed.
    /// It is also emitted at the end of a preedit sequence, in which case
    /// webkit_input_method_context_get_preedit() returns the empty string.
    ///
    ///
    ///
    ///
    /// #### `preedit-finished`
    ///  Emitted when a preediting sequence has been completed or canceled.
    ///
    ///
    ///
    ///
    /// #### `preedit-started`
    ///  Emitted when a new preediting sequence starts.
    ///
    ///
    ///
    /// # Implements
    ///
    /// [`InputMethodContextExt`][trait@crate::prelude::InputMethodContextExt]
    #[doc(alias = "WebKitInputMethodContext")]
    pub struct InputMethodContext(Object<ffi::WebKitInputMethodContext, ffi::WebKitInputMethodContextClass>);

    match fn {
        type_ => || ffi::webkit_input_method_context_get_type(),
    }
}

impl InputMethodContext {
    pub const NONE: Option<&'static InputMethodContext> = None;
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::InputMethodContext>> Sealed for T {}
}

/// Trait containing all [`struct@InputMethodContext`] methods.
///
/// # Implementors
///
/// [`InputMethodContext`][struct@crate::InputMethodContext]
pub trait InputMethodContextExt: IsA<InputMethodContext> + sealed::Sealed + 'static {
    /// Allow @key_event to be handled by the input method.
    ///
    /// If [`true`] is returned, then no further processing should be
    /// done for the key event.
    /// ## `key_event`
    /// the key event to filter
    ///
    /// # Returns
    ///
    /// [`true`] if the key event was handled, or [`false`] otherwise
    #[doc(alias = "webkit_input_method_context_filter_key_event")]
    fn filter_key_event(&self, key_event: impl AsRef<gdk::Event>) -> bool {
        unsafe {
            from_glib(ffi::webkit_input_method_context_filter_key_event(
                self.as_ref().to_glib_none().0,
                key_event.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Get the value of the #WebKitInputMethodContext:input-hints property.
    ///
    /// # Returns
    ///
    /// the #WebKitInputHints of the input associated with @self
    #[doc(alias = "webkit_input_method_context_get_input_hints")]
    #[doc(alias = "get_input_hints")]
    #[doc(alias = "input-hints")]
    fn input_hints(&self) -> InputHints {
        unsafe {
            from_glib(ffi::webkit_input_method_context_get_input_hints(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Get the value of the #WebKitInputMethodContext:input-purpose property.
    ///
    /// # Returns
    ///
    /// the #WebKitInputPurpose of the input associated with @self
    #[doc(alias = "webkit_input_method_context_get_input_purpose")]
    #[doc(alias = "get_input_purpose")]
    #[doc(alias = "input-purpose")]
    fn input_purpose(&self) -> InputPurpose {
        unsafe {
            from_glib(ffi::webkit_input_method_context_get_input_purpose(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    //#[doc(alias = "webkit_input_method_context_get_preedit")]
    //#[doc(alias = "get_preedit")]
    //fn preedit(&self, underlines: /*Unimplemented*/Vec<InputMethodUnderline>) -> (Option<glib::GString>, u32) {
    //    unsafe { TODO: call ffi:webkit_input_method_context_get_preedit() }
    //}

    /// Notify @self that cursor area changed in input associated.
    /// ## `x`
    /// the x coordinate of cursor location
    /// ## `y`
    /// the y coordinate of cursor location
    /// ## `width`
    /// the width of cursor area
    /// ## `height`
    /// the height of cursor area
    #[doc(alias = "webkit_input_method_context_notify_cursor_area")]
    fn notify_cursor_area(&self, x: i32, y: i32, width: i32, height: i32) {
        unsafe {
            ffi::webkit_input_method_context_notify_cursor_area(
                self.as_ref().to_glib_none().0,
                x,
                y,
                width,
                height,
            );
        }
    }

    /// Notify @self that input associated has gained focus.
    #[doc(alias = "webkit_input_method_context_notify_focus_in")]
    fn notify_focus_in(&self) {
        unsafe {
            ffi::webkit_input_method_context_notify_focus_in(self.as_ref().to_glib_none().0);
        }
    }

    /// Notify @self that input associated has lost focus.
    #[doc(alias = "webkit_input_method_context_notify_focus_out")]
    fn notify_focus_out(&self) {
        unsafe {
            ffi::webkit_input_method_context_notify_focus_out(self.as_ref().to_glib_none().0);
        }
    }

    /// Notify @self that the context surrounding the cursor has changed.
    ///
    /// If there's no selection @selection_index is the same as @cursor_index.
    /// ## `text`
    /// text surrounding the insertion point
    /// ## `length`
    /// the length of @text, or -1 if @text is nul-terminated
    /// ## `cursor_index`
    /// the byte index of the insertion cursor within @text.
    /// ## `selection_index`
    /// the byte index of the selection cursor within @text.
    #[doc(alias = "webkit_input_method_context_notify_surrounding")]
    fn notify_surrounding(&self, text: &str, cursor_index: u32, selection_index: u32) {
        let length = text.len() as _;
        unsafe {
            ffi::webkit_input_method_context_notify_surrounding(
                self.as_ref().to_glib_none().0,
                text.to_glib_none().0,
                length,
                cursor_index,
                selection_index,
            );
        }
    }

    /// Reset the @self.
    ///
    /// This will typically cause the input to clear the preedit state.
    #[doc(alias = "webkit_input_method_context_reset")]
    fn reset(&self) {
        unsafe {
            ffi::webkit_input_method_context_reset(self.as_ref().to_glib_none().0);
        }
    }

    /// Set whether @self should enable preedit to display feedback.
    /// ## `enabled`
    /// whether to enable preedit
    #[doc(alias = "webkit_input_method_context_set_enable_preedit")]
    fn set_enable_preedit(&self, enabled: bool) {
        unsafe {
            ffi::webkit_input_method_context_set_enable_preedit(
                self.as_ref().to_glib_none().0,
                enabled.into_glib(),
            );
        }
    }

    /// Set the value of the #WebKitInputMethodContext:input-hints property.
    /// ## `hints`
    /// a #WebKitInputHints
    #[doc(alias = "webkit_input_method_context_set_input_hints")]
    #[doc(alias = "input-hints")]
    fn set_input_hints(&self, hints: InputHints) {
        unsafe {
            ffi::webkit_input_method_context_set_input_hints(
                self.as_ref().to_glib_none().0,
                hints.into_glib(),
            );
        }
    }

    /// Set the value of the #WebKitInputMethodContext:input-purpose property.
    /// ## `purpose`
    /// a #WebKitInputPurpose
    #[doc(alias = "webkit_input_method_context_set_input_purpose")]
    #[doc(alias = "input-purpose")]
    fn set_input_purpose(&self, purpose: InputPurpose) {
        unsafe {
            ffi::webkit_input_method_context_set_input_purpose(
                self.as_ref().to_glib_none().0,
                purpose.into_glib(),
            );
        }
    }

    /// Emitted when a complete input sequence has been entered by the user.
    /// This can be a single character immediately after a key press or the
    /// final result of preediting.
    /// ## `text`
    /// the string result
    #[doc(alias = "committed")]
    fn connect_committed<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn committed_trampoline<
            P: IsA<InputMethodContext>,
            F: Fn(&P, &str) + 'static,
        >(
            this: *mut ffi::WebKitInputMethodContext,
            text: *mut libc::c_char,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                InputMethodContext::from_glib_borrow(this).unsafe_cast_ref(),
                &glib::GString::from_glib_borrow(text),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"committed\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    committed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when the input method wants to delete the context surrounding the cursor.
    /// If @offset is a negative value, it means a position before the cursor.
    /// ## `offset`
    /// the character offset from the cursor position of the text to be deleted.
    /// ## `n_chars`
    /// the number of characters to be deleted
    #[doc(alias = "delete-surrounding")]
    fn connect_delete_surrounding<F: Fn(&Self, i32, u32) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn delete_surrounding_trampoline<
            P: IsA<InputMethodContext>,
            F: Fn(&P, i32, u32) + 'static,
        >(
            this: *mut ffi::WebKitInputMethodContext,
            offset: libc::c_int,
            n_chars: libc::c_uint,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                InputMethodContext::from_glib_borrow(this).unsafe_cast_ref(),
                offset,
                n_chars,
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"delete-surrounding\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    delete_surrounding_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted whenever the preedit sequence currently being entered has changed.
    /// It is also emitted at the end of a preedit sequence, in which case
    /// webkit_input_method_context_get_preedit() returns the empty string.
    #[doc(alias = "preedit-changed")]
    fn connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn preedit_changed_trampoline<
            P: IsA<InputMethodContext>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::WebKitInputMethodContext,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"preedit-changed\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    preedit_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when a preediting sequence has been completed or canceled.
    #[doc(alias = "preedit-finished")]
    fn connect_preedit_finished<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn preedit_finished_trampoline<
            P: IsA<InputMethodContext>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::WebKitInputMethodContext,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"preedit-finished\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    preedit_finished_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when a new preediting sequence starts.
    #[doc(alias = "preedit-started")]
    fn connect_preedit_started<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn preedit_started_trampoline<
            P: IsA<InputMethodContext>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::WebKitInputMethodContext,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"preedit-started\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    preedit_started_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "input-hints")]
    fn connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_input_hints_trampoline<
            P: IsA<InputMethodContext>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::WebKitInputMethodContext,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::input-hints\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_input_hints_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "input-purpose")]
    fn connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_input_purpose_trampoline<
            P: IsA<InputMethodContext>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::WebKitInputMethodContext,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(InputMethodContext::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::input-purpose\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_input_purpose_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<InputMethodContext>> InputMethodContextExt for O {}