Skip to main content

gtk4/auto/
im_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// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{InputHints, InputPurpose, Widget, 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    ///  sign.
17    ///
18    /// Additional input methods can be made available for use by GTK widgets as
19    /// loadable modules. An input method module is a small shared library which
20    /// provides a `GIOExtension` for the extension point named "gtk-im-module".
21    ///
22    /// To connect a widget to the users preferred input method, you should use
23    /// [`IMMulticontext`][crate::IMMulticontext].
24    ///
25    /// This is an Abstract Base Class, you cannot instantiate it.
26    ///
27    /// ## Properties
28    ///
29    ///
30    /// #### `input-hints`
31    ///  Additional hints that allow input methods to fine-tune
32    /// their behaviour.
33    ///
34    /// Readable | Writable
35    ///
36    ///
37    /// #### `input-purpose`
38    ///  The purpose of the text field that the `GtkIMContext is connected to.
39    ///
40    /// This property can be used by on-screen keyboards and other input
41    /// methods to adjust their behaviour.
42    ///
43    /// Readable | Writable
44    ///
45    /// ## Signals
46    ///
47    ///
48    /// #### `commit`
49    ///  The ::commit signal is emitted when a complete input sequence
50    /// has been entered by the user.
51    ///
52    /// If the commit comes after a preediting sequence, the
53    /// ::commit signal is emitted after ::preedit-end.
54    ///
55    /// This can be a single character immediately after a key press or
56    /// the final result of preediting.
57    ///
58    ///
59    ///
60    ///
61    /// #### `delete-surrounding`
62    ///  The ::delete-surrounding signal is emitted when the input method
63    /// needs to delete all or part of the context surrounding the cursor.
64    ///
65    ///
66    ///
67    ///
68    /// #### `invalid-composition`
69    ///  Emitted when the filtered keys do not compose to a single valid character.
70    ///
71    ///
72    ///
73    ///
74    /// #### `preedit-changed`
75    ///  The ::preedit-changed signal is emitted whenever the preedit sequence
76    /// currently being entered has changed.
77    ///
78    /// It is also emitted at the end of a preedit sequence, in which case
79    /// [`IMContextExt::preedit_string()`][crate::prelude::IMContextExt::preedit_string()] returns the empty string.
80    ///
81    ///
82    ///
83    ///
84    /// #### `preedit-end`
85    ///  The ::preedit-end signal is emitted when a preediting sequence
86    /// has been completed or canceled.
87    ///
88    ///
89    ///
90    ///
91    /// #### `preedit-start`
92    ///  The ::preedit-start signal is emitted when a new preediting sequence
93    /// starts.
94    ///
95    ///
96    ///
97    ///
98    /// #### `retrieve-surrounding`
99    ///  The ::retrieve-surrounding signal is emitted when the input method
100    /// requires the context surrounding the cursor.
101    ///
102    /// The callback should set the input method surrounding context by
103    /// calling the [`IMContextExt::set_surrounding()`][crate::prelude::IMContextExt::set_surrounding()] method.
104    ///
105    ///
106    ///
107    /// # Implements
108    ///
109    /// [`IMContextExt`][trait@crate::prelude::IMContextExt], [`trait@glib::ObjectExt`]
110    #[doc(alias = "GtkIMContext")]
111    pub struct IMContext(Object<ffi::GtkIMContext, ffi::GtkIMContextClass>);
112
113    match fn {
114        type_ => || ffi::gtk_im_context_get_type(),
115    }
116}
117
118impl IMContext {
119    pub const NONE: Option<&'static IMContext> = None;
120}
121
122/// Trait containing all [`struct@IMContext`] methods.
123///
124/// # Implementors
125///
126/// [`IMContextSimple`][struct@crate::IMContextSimple], [`IMContext`][struct@crate::IMContext], [`IMMulticontext`][struct@crate::IMMulticontext]
127pub trait IMContextExt: IsA<IMContext> + 'static {
128    /// Requests the platform to show an on-screen keyboard for user input.
129    ///
130    /// This method will return [`true`] if this request was actually performed
131    /// to the platform, other environmental factors may result in an on-screen
132    /// keyboard effectively not showing up.
133    /// ## `event`
134    /// a [`gdk::Event`][crate::gdk::Event]
135    ///
136    /// # Returns
137    ///
138    /// [`true`] if an on-screen keyboard could be requested to the platform.
139    #[cfg(feature = "v4_14")]
140    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
141    #[doc(alias = "gtk_im_context_activate_osk")]
142    fn activate_osk(&self, event: Option<impl AsRef<gdk::Event>>) -> bool {
143        unsafe {
144            from_glib(ffi::gtk_im_context_activate_osk(
145                self.as_ref().to_glib_none().0,
146                event.as_ref().map(|p| p.as_ref()).to_glib_none().0,
147            ))
148        }
149    }
150
151    /// Asks the widget that the input context is attached to delete
152    /// characters around the cursor position by emitting the
153    /// `::delete_surrounding` signal.
154    ///
155    /// Note that @offset and @n_chars are in characters not in bytes
156    /// which differs from the usage other places in [`IMContext`][crate::IMContext].
157    ///
158    /// In order to use this function, you should first call
159    /// [`surrounding()`][Self::surrounding()] to get the current context,
160    /// and call this function immediately afterwards to make sure that you
161    /// know what you are deleting. You should also account for the fact
162    /// that even if the signal was handled, the input context might not
163    /// have deleted all the characters that were requested to be deleted.
164    ///
165    /// This function is used by an input method that wants to make
166    /// substitutions in the existing text in response to new input.
167    /// It is not useful for applications.
168    /// ## `offset`
169    /// offset from cursor position in chars;
170    ///    a negative value means start before the cursor.
171    /// ## `n_chars`
172    /// number of characters to delete.
173    ///
174    /// # Returns
175    ///
176    /// [`true`] if the signal was handled.
177    #[doc(alias = "gtk_im_context_delete_surrounding")]
178    fn delete_surrounding(&self, offset: i32, n_chars: i32) -> bool {
179        unsafe {
180            from_glib(ffi::gtk_im_context_delete_surrounding(
181                self.as_ref().to_glib_none().0,
182                offset,
183                n_chars,
184            ))
185        }
186    }
187
188    /// Allow an input method to forward key press and release events
189    /// to another input method without necessarily having a [`gdk::Event`][crate::gdk::Event]
190    /// available.
191    /// ## `press`
192    /// whether to forward a key press or release event
193    /// ## `surface`
194    /// the surface the event is for
195    /// ## `device`
196    /// the device that the event is for
197    /// ## `time`
198    /// the timestamp for the event
199    /// ## `keycode`
200    /// the keycode for the event
201    /// ## `state`
202    /// modifier state for the event
203    /// ## `group`
204    /// the active keyboard group for the event
205    ///
206    /// # Returns
207    ///
208    /// [`true`] if the input method handled the key event.
209    #[doc(alias = "gtk_im_context_filter_key")]
210    fn filter_key(
211        &self,
212        press: bool,
213        surface: &impl IsA<gdk::Surface>,
214        device: &gdk::Device,
215        time: u32,
216        keycode: u32,
217        state: gdk::ModifierType,
218        group: i32,
219    ) -> bool {
220        unsafe {
221            from_glib(ffi::gtk_im_context_filter_key(
222                self.as_ref().to_glib_none().0,
223                press.into_glib(),
224                surface.as_ref().to_glib_none().0,
225                device.to_glib_none().0,
226                time,
227                keycode,
228                state.into_glib(),
229                group,
230            ))
231        }
232    }
233
234    /// Allow an input method to internally handle key press and release
235    /// events.
236    ///
237    /// If this function returns [`true`], then no further processing
238    /// should be done for this key event.
239    /// ## `event`
240    /// the key event
241    ///
242    /// # Returns
243    ///
244    /// [`true`] if the input method handled the key event.
245    #[doc(alias = "gtk_im_context_filter_keypress")]
246    fn filter_keypress(&self, event: impl AsRef<gdk::Event>) -> bool {
247        unsafe {
248            from_glib(ffi::gtk_im_context_filter_keypress(
249                self.as_ref().to_glib_none().0,
250                event.as_ref().to_glib_none().0,
251            ))
252        }
253    }
254
255    /// Notify the input method that the widget to which this
256    /// input context corresponds has gained focus.
257    ///
258    /// The input method may, for example, change the displayed
259    /// feedback to reflect this change.
260    #[doc(alias = "gtk_im_context_focus_in")]
261    fn focus_in(&self) {
262        unsafe {
263            ffi::gtk_im_context_focus_in(self.as_ref().to_glib_none().0);
264        }
265    }
266
267    /// Notify the input method that the widget to which this
268    /// input context corresponds has lost focus.
269    ///
270    /// The input method may, for example, change the displayed
271    /// feedback or reset the contexts state to reflect this change.
272    #[doc(alias = "gtk_im_context_focus_out")]
273    fn focus_out(&self) {
274        unsafe {
275            ffi::gtk_im_context_focus_out(self.as_ref().to_glib_none().0);
276        }
277    }
278
279    /// Retrieve the current preedit string for the input context,
280    /// and a list of attributes to apply to the string.
281    ///
282    /// This string should be displayed inserted at the insertion point.
283    ///
284    /// # Returns
285    ///
286    ///
287    /// ## `str`
288    /// location to store the retrieved
289    ///   string. The string retrieved must be freed with g_free().
290    ///
291    /// ## `attrs`
292    /// location to store the retrieved
293    ///   attribute list. When you are done with this list, you
294    ///   must unreference it with `Pango::AttrList::unref()`.
295    ///
296    /// ## `cursor_pos`
297    /// location to store position of cursor
298    ///   (in characters) within the preedit string.
299    #[doc(alias = "gtk_im_context_get_preedit_string")]
300    #[doc(alias = "get_preedit_string")]
301    fn preedit_string(&self) -> (glib::GString, pango::AttrList, i32) {
302        unsafe {
303            let mut str = std::ptr::null_mut();
304            let mut attrs = std::ptr::null_mut();
305            let mut cursor_pos = std::mem::MaybeUninit::uninit();
306            ffi::gtk_im_context_get_preedit_string(
307                self.as_ref().to_glib_none().0,
308                &mut str,
309                &mut attrs,
310                cursor_pos.as_mut_ptr(),
311            );
312            (
313                from_glib_full(str),
314                from_glib_full(attrs),
315                cursor_pos.assume_init(),
316            )
317        }
318    }
319
320    /// Retrieves context around the insertion point.
321    ///
322    /// Input methods typically want context in order to constrain input text
323    /// based on existing text; this is important for languages such as Thai
324    /// where only some sequences of characters are allowed.
325    ///
326    /// This function is implemented by emitting the
327    /// [`retrieve-surrounding`][struct@crate::IMContext#retrieve-surrounding] signal on the input method;
328    /// in response to this signal, a widget should provide as much context as
329    /// is available, up to an entire paragraph, by calling
330    /// [`set_surrounding()`][Self::set_surrounding()].
331    ///
332    /// Note that there is no obligation for a widget to respond to the
333    /// `::retrieve-surrounding` signal, so input methods must be prepared to
334    /// function without context.
335    ///
336    /// # Deprecated since 4.2
337    ///
338    /// Use [`surrounding_with_selection()`][Self::surrounding_with_selection()] instead.
339    ///
340    /// # Returns
341    ///
342    /// `TRUE` if surrounding text was provided; in this case
343    ///    you must free the result stored in `text`.
344    ///
345    /// ## `text`
346    /// location to store a UTF-8 encoded
347    ///   string of text holding context around the insertion point.
348    ///   If the function returns [`true`], then you must free the result
349    ///   stored in this location with g_free().
350    ///
351    /// ## `cursor_index`
352    /// location to store byte index of the insertion
353    ///   cursor within @text.
354    #[cfg_attr(feature = "v4_2", deprecated = "Since 4.2")]
355    #[allow(deprecated)]
356    #[doc(alias = "gtk_im_context_get_surrounding")]
357    #[doc(alias = "get_surrounding")]
358    fn surrounding(&self) -> Option<(glib::GString, i32)> {
359        unsafe {
360            let mut text = std::ptr::null_mut();
361            let mut cursor_index = std::mem::MaybeUninit::uninit();
362            let ret = from_glib(ffi::gtk_im_context_get_surrounding(
363                self.as_ref().to_glib_none().0,
364                &mut text,
365                cursor_index.as_mut_ptr(),
366            ));
367            if ret {
368                Some((from_glib_full(text), cursor_index.assume_init()))
369            } else {
370                None
371            }
372        }
373    }
374
375    /// Retrieves context around the insertion point.
376    ///
377    /// Input methods typically want context in order to constrain input
378    /// text based on existing text; this is important for languages such
379    /// as Thai where only some sequences of characters are allowed.
380    ///
381    /// This function is implemented by emitting the
382    /// [`retrieve-surrounding`][struct@crate::IMContext#retrieve-surrounding] signal on the input method;
383    /// in response to this signal, a widget should provide as much context as
384    /// is available, up to an entire paragraph, by calling
385    /// [`set_surrounding_with_selection()`][Self::set_surrounding_with_selection()].
386    ///
387    /// Note that there is no obligation for a widget to respond to the
388    /// `::retrieve-surrounding` signal, so input methods must be prepared to
389    /// function without context.
390    ///
391    /// # Returns
392    ///
393    /// `TRUE` if surrounding text was provided; in this case
394    ///   you must free the result stored in `text`.
395    ///
396    /// ## `text`
397    /// location to store a UTF-8 encoded
398    ///   string of text holding context around the insertion point.
399    ///   If the function returns [`true`], then you must free the result
400    ///   stored in this location with g_free().
401    ///
402    /// ## `cursor_index`
403    /// location to store byte index of the insertion
404    ///   cursor within @text.
405    ///
406    /// ## `anchor_index`
407    /// location to store byte index of the selection
408    ///   bound within @text
409    #[cfg(feature = "v4_2")]
410    #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
411    #[doc(alias = "gtk_im_context_get_surrounding_with_selection")]
412    #[doc(alias = "get_surrounding_with_selection")]
413    fn surrounding_with_selection(&self) -> Option<(glib::GString, i32, i32)> {
414        unsafe {
415            let mut text = std::ptr::null_mut();
416            let mut cursor_index = std::mem::MaybeUninit::uninit();
417            let mut anchor_index = std::mem::MaybeUninit::uninit();
418            let ret = from_glib(ffi::gtk_im_context_get_surrounding_with_selection(
419                self.as_ref().to_glib_none().0,
420                &mut text,
421                cursor_index.as_mut_ptr(),
422                anchor_index.as_mut_ptr(),
423            ));
424            if ret {
425                Some((
426                    from_glib_full(text),
427                    cursor_index.assume_init(),
428                    anchor_index.assume_init(),
429                ))
430            } else {
431                None
432            }
433        }
434    }
435
436    /// Notify the input method that a change such as a change in cursor
437    /// position has been made.
438    ///
439    /// This will typically cause the input method to clear the preedit state.
440    #[doc(alias = "gtk_im_context_reset")]
441    fn reset(&self) {
442        unsafe {
443            ffi::gtk_im_context_reset(self.as_ref().to_glib_none().0);
444        }
445    }
446
447    /// Set the client widget for the input context.
448    ///
449    /// This is the [`Widget`][crate::Widget] holding the input focus. This widget is
450    /// used in order to correctly position status windows, and may
451    /// also be used for purposes internal to the input method.
452    /// ## `widget`
453    /// the client widget. This may be [`None`] to indicate
454    ///   that the previous client widget no longer exists.
455    #[doc(alias = "gtk_im_context_set_client_widget")]
456    fn set_client_widget(&self, widget: Option<&impl IsA<Widget>>) {
457        unsafe {
458            ffi::gtk_im_context_set_client_widget(
459                self.as_ref().to_glib_none().0,
460                widget.map(|p| p.as_ref()).to_glib_none().0,
461            );
462        }
463    }
464
465    /// Notify the input method that a change in cursor
466    /// position has been made.
467    ///
468    /// The location is relative to the client widget.
469    /// ## `area`
470    /// new location
471    #[doc(alias = "gtk_im_context_set_cursor_location")]
472    fn set_cursor_location(&self, area: &gdk::Rectangle) {
473        unsafe {
474            ffi::gtk_im_context_set_cursor_location(
475                self.as_ref().to_glib_none().0,
476                area.to_glib_none().0,
477            );
478        }
479    }
480
481    /// Sets surrounding context around the insertion point and preedit
482    /// string.
483    ///
484    /// This function is expected to be called in response to the
485    /// [`retrieve-surrounding`][struct@crate::IMContext#retrieve-surrounding] signal, and will
486    /// likely have no effect if called at other times.
487    ///
488    /// # Deprecated since 4.2
489    ///
490    /// Use [`set_surrounding_with_selection()`][Self::set_surrounding_with_selection()] instead
491    /// ## `text`
492    /// text surrounding the insertion point, as UTF-8.
493    ///   the preedit string should not be included within @text
494    /// ## `len`
495    /// the length of @text, or -1 if @text is nul-terminated
496    /// ## `cursor_index`
497    /// the byte index of the insertion cursor within @text.
498    #[cfg_attr(feature = "v4_2", deprecated = "Since 4.2")]
499    #[allow(deprecated)]
500    #[doc(alias = "gtk_im_context_set_surrounding")]
501    fn set_surrounding(&self, text: &str, cursor_index: i32) {
502        let len = text.len() as _;
503        unsafe {
504            ffi::gtk_im_context_set_surrounding(
505                self.as_ref().to_glib_none().0,
506                text.to_glib_none().0,
507                len,
508                cursor_index,
509            );
510        }
511    }
512
513    /// Sets surrounding context around the insertion point and preedit
514    /// string. This function is expected to be called in response to the
515    /// [`retrieve_surrounding`][struct@crate::IMContext#retrieve_surrounding] signal, and will likely
516    /// have no effect if called at other times.
517    /// ## `text`
518    /// text surrounding the insertion point, as UTF-8.
519    ///   the preedit string should not be included within @text
520    /// ## `len`
521    /// the length of @text, or -1 if @text is nul-terminated
522    /// ## `cursor_index`
523    /// the byte index of the insertion cursor within @text
524    /// ## `anchor_index`
525    /// the byte index of the selection bound within @text
526    #[cfg(feature = "v4_2")]
527    #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
528    #[doc(alias = "gtk_im_context_set_surrounding_with_selection")]
529    fn set_surrounding_with_selection(&self, text: &str, cursor_index: i32, anchor_index: i32) {
530        let len = text.len() as _;
531        unsafe {
532            ffi::gtk_im_context_set_surrounding_with_selection(
533                self.as_ref().to_glib_none().0,
534                text.to_glib_none().0,
535                len,
536                cursor_index,
537                anchor_index,
538            );
539        }
540    }
541
542    /// Sets whether the IM context should use the preedit string
543    /// to display feedback.
544    ///
545    /// If @use_preedit is [`false`] (default is [`true`]), then the IM context
546    /// may use some other method to display feedback, such as displaying
547    /// it in a child of the root window.
548    /// ## `use_preedit`
549    /// whether the IM context should use the preedit string.
550    #[doc(alias = "gtk_im_context_set_use_preedit")]
551    fn set_use_preedit(&self, use_preedit: bool) {
552        unsafe {
553            ffi::gtk_im_context_set_use_preedit(
554                self.as_ref().to_glib_none().0,
555                use_preedit.into_glib(),
556            );
557        }
558    }
559
560    /// Additional hints that allow input methods to fine-tune
561    /// their behaviour.
562    #[doc(alias = "input-hints")]
563    fn input_hints(&self) -> InputHints {
564        ObjectExt::property(self.as_ref(), "input-hints")
565    }
566
567    /// Additional hints that allow input methods to fine-tune
568    /// their behaviour.
569    #[doc(alias = "input-hints")]
570    fn set_input_hints(&self, input_hints: InputHints) {
571        ObjectExt::set_property(self.as_ref(), "input-hints", input_hints)
572    }
573
574    /// The purpose of the text field that the `GtkIMContext is connected to.
575    ///
576    /// This property can be used by on-screen keyboards and other input
577    /// methods to adjust their behaviour.
578    #[doc(alias = "input-purpose")]
579    fn input_purpose(&self) -> InputPurpose {
580        ObjectExt::property(self.as_ref(), "input-purpose")
581    }
582
583    /// The purpose of the text field that the `GtkIMContext is connected to.
584    ///
585    /// This property can be used by on-screen keyboards and other input
586    /// methods to adjust their behaviour.
587    #[doc(alias = "input-purpose")]
588    fn set_input_purpose(&self, input_purpose: InputPurpose) {
589        ObjectExt::set_property(self.as_ref(), "input-purpose", input_purpose)
590    }
591
592    /// The ::commit signal is emitted when a complete input sequence
593    /// has been entered by the user.
594    ///
595    /// If the commit comes after a preediting sequence, the
596    /// ::commit signal is emitted after ::preedit-end.
597    ///
598    /// This can be a single character immediately after a key press or
599    /// the final result of preediting.
600    /// ## `str`
601    /// the completed character(s) entered by the user
602    #[doc(alias = "commit")]
603    fn connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
604        unsafe extern "C" fn commit_trampoline<P: IsA<IMContext>, F: Fn(&P, &str) + 'static>(
605            this: *mut ffi::GtkIMContext,
606            str: *mut std::ffi::c_char,
607            f: glib::ffi::gpointer,
608        ) {
609            unsafe {
610                let f: &F = &*(f as *const F);
611                f(
612                    IMContext::from_glib_borrow(this).unsafe_cast_ref(),
613                    &glib::GString::from_glib_borrow(str),
614                )
615            }
616        }
617        unsafe {
618            let f: Box_<F> = Box_::new(f);
619            connect_raw(
620                self.as_ptr() as *mut _,
621                c"commit".as_ptr(),
622                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
623                    commit_trampoline::<Self, F> as *const (),
624                )),
625                Box_::into_raw(f),
626            )
627        }
628    }
629
630    /// The ::delete-surrounding signal is emitted when the input method
631    /// needs to delete all or part of the context surrounding the cursor.
632    /// ## `offset`
633    /// the character offset from the cursor position of the text
634    ///   to be deleted. A negative value indicates a position before
635    ///   the cursor.
636    /// ## `n_chars`
637    /// the number of characters to be deleted
638    ///
639    /// # Returns
640    ///
641    /// [`true`] if the signal was handled.
642    #[doc(alias = "delete-surrounding")]
643    fn connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>(
644        &self,
645        f: F,
646    ) -> SignalHandlerId {
647        unsafe extern "C" fn delete_surrounding_trampoline<
648            P: IsA<IMContext>,
649            F: Fn(&P, i32, i32) -> bool + 'static,
650        >(
651            this: *mut ffi::GtkIMContext,
652            offset: std::ffi::c_int,
653            n_chars: std::ffi::c_int,
654            f: glib::ffi::gpointer,
655        ) -> glib::ffi::gboolean {
656            unsafe {
657                let f: &F = &*(f as *const F);
658                f(
659                    IMContext::from_glib_borrow(this).unsafe_cast_ref(),
660                    offset,
661                    n_chars,
662                )
663                .into_glib()
664            }
665        }
666        unsafe {
667            let f: Box_<F> = Box_::new(f);
668            connect_raw(
669                self.as_ptr() as *mut _,
670                c"delete-surrounding".as_ptr(),
671                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
672                    delete_surrounding_trampoline::<Self, F> as *const (),
673                )),
674                Box_::into_raw(f),
675            )
676        }
677    }
678
679    /// Emitted when the filtered keys do not compose to a single valid character.
680    /// ## `str`
681    /// the completed character(s) entered by the user
682    ///
683    /// # Returns
684    ///
685    /// true if the IM context avoid beeping on invalid composition
686    #[cfg(feature = "v4_22")]
687    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
688    #[doc(alias = "invalid-composition")]
689    fn connect_invalid_composition<F: Fn(&Self, &str) -> bool + 'static>(
690        &self,
691        f: F,
692    ) -> SignalHandlerId {
693        unsafe extern "C" fn invalid_composition_trampoline<
694            P: IsA<IMContext>,
695            F: Fn(&P, &str) -> bool + 'static,
696        >(
697            this: *mut ffi::GtkIMContext,
698            str: *mut std::ffi::c_char,
699            f: glib::ffi::gpointer,
700        ) -> glib::ffi::gboolean {
701            unsafe {
702                let f: &F = &*(f as *const F);
703                f(
704                    IMContext::from_glib_borrow(this).unsafe_cast_ref(),
705                    &glib::GString::from_glib_borrow(str),
706                )
707                .into_glib()
708            }
709        }
710        unsafe {
711            let f: Box_<F> = Box_::new(f);
712            connect_raw(
713                self.as_ptr() as *mut _,
714                c"invalid-composition".as_ptr(),
715                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
716                    invalid_composition_trampoline::<Self, F> as *const (),
717                )),
718                Box_::into_raw(f),
719            )
720        }
721    }
722
723    /// The ::preedit-changed signal is emitted whenever the preedit sequence
724    /// currently being entered has changed.
725    ///
726    /// It is also emitted at the end of a preedit sequence, in which case
727    /// [`preedit_string()`][Self::preedit_string()] returns the empty string.
728    #[doc(alias = "preedit-changed")]
729    fn connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
730        unsafe extern "C" fn preedit_changed_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
731            this: *mut ffi::GtkIMContext,
732            f: glib::ffi::gpointer,
733        ) {
734            unsafe {
735                let f: &F = &*(f as *const F);
736                f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
737            }
738        }
739        unsafe {
740            let f: Box_<F> = Box_::new(f);
741            connect_raw(
742                self.as_ptr() as *mut _,
743                c"preedit-changed".as_ptr(),
744                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
745                    preedit_changed_trampoline::<Self, F> as *const (),
746                )),
747                Box_::into_raw(f),
748            )
749        }
750    }
751
752    /// The ::preedit-end signal is emitted when a preediting sequence
753    /// has been completed or canceled.
754    #[doc(alias = "preedit-end")]
755    fn connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
756        unsafe extern "C" fn preedit_end_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
757            this: *mut ffi::GtkIMContext,
758            f: glib::ffi::gpointer,
759        ) {
760            unsafe {
761                let f: &F = &*(f as *const F);
762                f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
763            }
764        }
765        unsafe {
766            let f: Box_<F> = Box_::new(f);
767            connect_raw(
768                self.as_ptr() as *mut _,
769                c"preedit-end".as_ptr(),
770                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
771                    preedit_end_trampoline::<Self, F> as *const (),
772                )),
773                Box_::into_raw(f),
774            )
775        }
776    }
777
778    /// The ::preedit-start signal is emitted when a new preediting sequence
779    /// starts.
780    #[doc(alias = "preedit-start")]
781    fn connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
782        unsafe extern "C" fn preedit_start_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
783            this: *mut ffi::GtkIMContext,
784            f: glib::ffi::gpointer,
785        ) {
786            unsafe {
787                let f: &F = &*(f as *const F);
788                f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
789            }
790        }
791        unsafe {
792            let f: Box_<F> = Box_::new(f);
793            connect_raw(
794                self.as_ptr() as *mut _,
795                c"preedit-start".as_ptr(),
796                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
797                    preedit_start_trampoline::<Self, F> as *const (),
798                )),
799                Box_::into_raw(f),
800            )
801        }
802    }
803
804    /// The ::retrieve-surrounding signal is emitted when the input method
805    /// requires the context surrounding the cursor.
806    ///
807    /// The callback should set the input method surrounding context by
808    /// calling the [`set_surrounding()`][Self::set_surrounding()] method.
809    ///
810    /// # Returns
811    ///
812    /// [`true`] if the signal was handled.
813    #[doc(alias = "retrieve-surrounding")]
814    fn connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>(
815        &self,
816        f: F,
817    ) -> SignalHandlerId {
818        unsafe extern "C" fn retrieve_surrounding_trampoline<
819            P: IsA<IMContext>,
820            F: Fn(&P) -> bool + 'static,
821        >(
822            this: *mut ffi::GtkIMContext,
823            f: glib::ffi::gpointer,
824        ) -> glib::ffi::gboolean {
825            unsafe {
826                let f: &F = &*(f as *const F);
827                f(IMContext::from_glib_borrow(this).unsafe_cast_ref()).into_glib()
828            }
829        }
830        unsafe {
831            let f: Box_<F> = Box_::new(f);
832            connect_raw(
833                self.as_ptr() as *mut _,
834                c"retrieve-surrounding".as_ptr(),
835                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
836                    retrieve_surrounding_trampoline::<Self, F> as *const (),
837                )),
838                Box_::into_raw(f),
839            )
840        }
841    }
842
843    #[doc(alias = "input-hints")]
844    fn connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
845        unsafe extern "C" fn notify_input_hints_trampoline<
846            P: IsA<IMContext>,
847            F: Fn(&P) + 'static,
848        >(
849            this: *mut ffi::GtkIMContext,
850            _param_spec: glib::ffi::gpointer,
851            f: glib::ffi::gpointer,
852        ) {
853            unsafe {
854                let f: &F = &*(f as *const F);
855                f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
856            }
857        }
858        unsafe {
859            let f: Box_<F> = Box_::new(f);
860            connect_raw(
861                self.as_ptr() as *mut _,
862                c"notify::input-hints".as_ptr(),
863                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
864                    notify_input_hints_trampoline::<Self, F> as *const (),
865                )),
866                Box_::into_raw(f),
867            )
868        }
869    }
870
871    #[doc(alias = "input-purpose")]
872    fn connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
873        unsafe extern "C" fn notify_input_purpose_trampoline<
874            P: IsA<IMContext>,
875            F: Fn(&P) + 'static,
876        >(
877            this: *mut ffi::GtkIMContext,
878            _param_spec: glib::ffi::gpointer,
879            f: glib::ffi::gpointer,
880        ) {
881            unsafe {
882                let f: &F = &*(f as *const F);
883                f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
884            }
885        }
886        unsafe {
887            let f: Box_<F> = Box_::new(f);
888            connect_raw(
889                self.as_ptr() as *mut _,
890                c"notify::input-purpose".as_ptr(),
891                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
892                    notify_input_purpose_trampoline::<Self, F> as *const (),
893                )),
894                Box_::into_raw(f),
895            )
896        }
897    }
898}
899
900impl<O: IsA<IMContext>> IMContextExt for O {}