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