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