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