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