gtk/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
5use crate::{InputHints, InputPurpose};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem, mem::transmute, ptr};
12
13glib::wrapper! {
14    #[doc(alias = "GtkIMContext")]
15    pub struct IMContext(Object<ffi::GtkIMContext, ffi::GtkIMContextClass>);
16
17    match fn {
18        type_ => || ffi::gtk_im_context_get_type(),
19    }
20}
21
22impl IMContext {
23    pub const NONE: Option<&'static IMContext> = None;
24}
25
26mod sealed {
27    pub trait Sealed {}
28    impl<T: super::IsA<super::IMContext>> Sealed for T {}
29}
30
31pub trait IMContextExt: IsA<IMContext> + sealed::Sealed + 'static {
32    #[doc(alias = "gtk_im_context_delete_surrounding")]
33    fn delete_surrounding(&self, offset: i32, n_chars: i32) -> bool {
34        unsafe {
35            from_glib(ffi::gtk_im_context_delete_surrounding(
36                self.as_ref().to_glib_none().0,
37                offset,
38                n_chars,
39            ))
40        }
41    }
42
43    #[doc(alias = "gtk_im_context_filter_keypress")]
44    fn filter_keypress(&self, event: &gdk::EventKey) -> bool {
45        unsafe {
46            from_glib(ffi::gtk_im_context_filter_keypress(
47                self.as_ref().to_glib_none().0,
48                mut_override(event.to_glib_none().0),
49            ))
50        }
51    }
52
53    #[doc(alias = "gtk_im_context_focus_in")]
54    fn focus_in(&self) {
55        unsafe {
56            ffi::gtk_im_context_focus_in(self.as_ref().to_glib_none().0);
57        }
58    }
59
60    #[doc(alias = "gtk_im_context_focus_out")]
61    fn focus_out(&self) {
62        unsafe {
63            ffi::gtk_im_context_focus_out(self.as_ref().to_glib_none().0);
64        }
65    }
66
67    #[doc(alias = "gtk_im_context_get_preedit_string")]
68    #[doc(alias = "get_preedit_string")]
69    fn preedit_string(&self) -> (glib::GString, pango::AttrList, i32) {
70        unsafe {
71            let mut str = ptr::null_mut();
72            let mut attrs = ptr::null_mut();
73            let mut cursor_pos = mem::MaybeUninit::uninit();
74            ffi::gtk_im_context_get_preedit_string(
75                self.as_ref().to_glib_none().0,
76                &mut str,
77                &mut attrs,
78                cursor_pos.as_mut_ptr(),
79            );
80            (
81                from_glib_full(str),
82                from_glib_full(attrs),
83                cursor_pos.assume_init(),
84            )
85        }
86    }
87
88    #[doc(alias = "gtk_im_context_get_surrounding")]
89    #[doc(alias = "get_surrounding")]
90    fn surrounding(&self) -> Option<(glib::GString, i32)> {
91        unsafe {
92            let mut text = ptr::null_mut();
93            let mut cursor_index = mem::MaybeUninit::uninit();
94            let ret = from_glib(ffi::gtk_im_context_get_surrounding(
95                self.as_ref().to_glib_none().0,
96                &mut text,
97                cursor_index.as_mut_ptr(),
98            ));
99            if ret {
100                Some((from_glib_full(text), cursor_index.assume_init()))
101            } else {
102                None
103            }
104        }
105    }
106
107    #[doc(alias = "gtk_im_context_reset")]
108    fn reset(&self) {
109        unsafe {
110            ffi::gtk_im_context_reset(self.as_ref().to_glib_none().0);
111        }
112    }
113
114    #[doc(alias = "gtk_im_context_set_client_window")]
115    fn set_client_window(&self, window: Option<&gdk::Window>) {
116        unsafe {
117            ffi::gtk_im_context_set_client_window(
118                self.as_ref().to_glib_none().0,
119                window.to_glib_none().0,
120            );
121        }
122    }
123
124    #[doc(alias = "gtk_im_context_set_cursor_location")]
125    fn set_cursor_location(&self, area: &gdk::Rectangle) {
126        unsafe {
127            ffi::gtk_im_context_set_cursor_location(
128                self.as_ref().to_glib_none().0,
129                area.to_glib_none().0,
130            );
131        }
132    }
133
134    #[doc(alias = "gtk_im_context_set_surrounding")]
135    fn set_surrounding(&self, text: &str, cursor_index: i32) {
136        let len = text.len() as _;
137        unsafe {
138            ffi::gtk_im_context_set_surrounding(
139                self.as_ref().to_glib_none().0,
140                text.to_glib_none().0,
141                len,
142                cursor_index,
143            );
144        }
145    }
146
147    #[doc(alias = "gtk_im_context_set_use_preedit")]
148    fn set_use_preedit(&self, use_preedit: bool) {
149        unsafe {
150            ffi::gtk_im_context_set_use_preedit(
151                self.as_ref().to_glib_none().0,
152                use_preedit.into_glib(),
153            );
154        }
155    }
156
157    #[doc(alias = "input-hints")]
158    fn input_hints(&self) -> InputHints {
159        ObjectExt::property(self.as_ref(), "input-hints")
160    }
161
162    #[doc(alias = "input-hints")]
163    fn set_input_hints(&self, input_hints: InputHints) {
164        ObjectExt::set_property(self.as_ref(), "input-hints", input_hints)
165    }
166
167    #[doc(alias = "input-purpose")]
168    fn input_purpose(&self) -> InputPurpose {
169        ObjectExt::property(self.as_ref(), "input-purpose")
170    }
171
172    #[doc(alias = "input-purpose")]
173    fn set_input_purpose(&self, input_purpose: InputPurpose) {
174        ObjectExt::set_property(self.as_ref(), "input-purpose", input_purpose)
175    }
176
177    #[doc(alias = "commit")]
178    fn connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
179        unsafe extern "C" fn commit_trampoline<P: IsA<IMContext>, F: Fn(&P, &str) + 'static>(
180            this: *mut ffi::GtkIMContext,
181            str: *mut libc::c_char,
182            f: glib::ffi::gpointer,
183        ) {
184            let f: &F = &*(f as *const F);
185            f(
186                IMContext::from_glib_borrow(this).unsafe_cast_ref(),
187                &glib::GString::from_glib_borrow(str),
188            )
189        }
190        unsafe {
191            let f: Box_<F> = Box_::new(f);
192            connect_raw(
193                self.as_ptr() as *mut _,
194                b"commit\0".as_ptr() as *const _,
195                Some(transmute::<_, unsafe extern "C" fn()>(
196                    commit_trampoline::<Self, F> as *const (),
197                )),
198                Box_::into_raw(f),
199            )
200        }
201    }
202
203    #[doc(alias = "delete-surrounding")]
204    fn connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>(
205        &self,
206        f: F,
207    ) -> SignalHandlerId {
208        unsafe extern "C" fn delete_surrounding_trampoline<
209            P: IsA<IMContext>,
210            F: Fn(&P, i32, i32) -> bool + 'static,
211        >(
212            this: *mut ffi::GtkIMContext,
213            offset: libc::c_int,
214            n_chars: libc::c_int,
215            f: glib::ffi::gpointer,
216        ) -> glib::ffi::gboolean {
217            let f: &F = &*(f as *const F);
218            f(
219                IMContext::from_glib_borrow(this).unsafe_cast_ref(),
220                offset,
221                n_chars,
222            )
223            .into_glib()
224        }
225        unsafe {
226            let f: Box_<F> = Box_::new(f);
227            connect_raw(
228                self.as_ptr() as *mut _,
229                b"delete-surrounding\0".as_ptr() as *const _,
230                Some(transmute::<_, unsafe extern "C" fn()>(
231                    delete_surrounding_trampoline::<Self, F> as *const (),
232                )),
233                Box_::into_raw(f),
234            )
235        }
236    }
237
238    #[doc(alias = "preedit-changed")]
239    fn connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
240        unsafe extern "C" fn preedit_changed_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
241            this: *mut ffi::GtkIMContext,
242            f: glib::ffi::gpointer,
243        ) {
244            let f: &F = &*(f as *const F);
245            f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
246        }
247        unsafe {
248            let f: Box_<F> = Box_::new(f);
249            connect_raw(
250                self.as_ptr() as *mut _,
251                b"preedit-changed\0".as_ptr() as *const _,
252                Some(transmute::<_, unsafe extern "C" fn()>(
253                    preedit_changed_trampoline::<Self, F> as *const (),
254                )),
255                Box_::into_raw(f),
256            )
257        }
258    }
259
260    #[doc(alias = "preedit-end")]
261    fn connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
262        unsafe extern "C" fn preedit_end_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
263            this: *mut ffi::GtkIMContext,
264            f: glib::ffi::gpointer,
265        ) {
266            let f: &F = &*(f as *const F);
267            f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
268        }
269        unsafe {
270            let f: Box_<F> = Box_::new(f);
271            connect_raw(
272                self.as_ptr() as *mut _,
273                b"preedit-end\0".as_ptr() as *const _,
274                Some(transmute::<_, unsafe extern "C" fn()>(
275                    preedit_end_trampoline::<Self, F> as *const (),
276                )),
277                Box_::into_raw(f),
278            )
279        }
280    }
281
282    #[doc(alias = "preedit-start")]
283    fn connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
284        unsafe extern "C" fn preedit_start_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
285            this: *mut ffi::GtkIMContext,
286            f: glib::ffi::gpointer,
287        ) {
288            let f: &F = &*(f as *const F);
289            f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
290        }
291        unsafe {
292            let f: Box_<F> = Box_::new(f);
293            connect_raw(
294                self.as_ptr() as *mut _,
295                b"preedit-start\0".as_ptr() as *const _,
296                Some(transmute::<_, unsafe extern "C" fn()>(
297                    preedit_start_trampoline::<Self, F> as *const (),
298                )),
299                Box_::into_raw(f),
300            )
301        }
302    }
303
304    #[doc(alias = "retrieve-surrounding")]
305    fn connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>(
306        &self,
307        f: F,
308    ) -> SignalHandlerId {
309        unsafe extern "C" fn retrieve_surrounding_trampoline<
310            P: IsA<IMContext>,
311            F: Fn(&P) -> bool + 'static,
312        >(
313            this: *mut ffi::GtkIMContext,
314            f: glib::ffi::gpointer,
315        ) -> glib::ffi::gboolean {
316            let f: &F = &*(f as *const F);
317            f(IMContext::from_glib_borrow(this).unsafe_cast_ref()).into_glib()
318        }
319        unsafe {
320            let f: Box_<F> = Box_::new(f);
321            connect_raw(
322                self.as_ptr() as *mut _,
323                b"retrieve-surrounding\0".as_ptr() as *const _,
324                Some(transmute::<_, unsafe extern "C" fn()>(
325                    retrieve_surrounding_trampoline::<Self, F> as *const (),
326                )),
327                Box_::into_raw(f),
328            )
329        }
330    }
331
332    #[doc(alias = "input-hints")]
333    fn connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
334        unsafe extern "C" fn notify_input_hints_trampoline<
335            P: IsA<IMContext>,
336            F: Fn(&P) + 'static,
337        >(
338            this: *mut ffi::GtkIMContext,
339            _param_spec: glib::ffi::gpointer,
340            f: glib::ffi::gpointer,
341        ) {
342            let f: &F = &*(f as *const F);
343            f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
344        }
345        unsafe {
346            let f: Box_<F> = Box_::new(f);
347            connect_raw(
348                self.as_ptr() as *mut _,
349                b"notify::input-hints\0".as_ptr() as *const _,
350                Some(transmute::<_, unsafe extern "C" fn()>(
351                    notify_input_hints_trampoline::<Self, F> as *const (),
352                )),
353                Box_::into_raw(f),
354            )
355        }
356    }
357
358    #[doc(alias = "input-purpose")]
359    fn connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
360        unsafe extern "C" fn notify_input_purpose_trampoline<
361            P: IsA<IMContext>,
362            F: Fn(&P) + 'static,
363        >(
364            this: *mut ffi::GtkIMContext,
365            _param_spec: glib::ffi::gpointer,
366            f: glib::ffi::gpointer,
367        ) {
368            let f: &F = &*(f as *const F);
369            f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
370        }
371        unsafe {
372            let f: Box_<F> = Box_::new(f);
373            connect_raw(
374                self.as_ptr() as *mut _,
375                b"notify::input-purpose\0".as_ptr() as *const _,
376                Some(transmute::<_, unsafe extern "C" fn()>(
377                    notify_input_purpose_trampoline::<Self, F> as *const (),
378                )),
379                Box_::into_raw(f),
380            )
381        }
382    }
383}
384
385impl<O: IsA<IMContext>> IMContextExt for O {}
386
387impl fmt::Display for IMContext {
388    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
389        f.write_str("IMContext")
390    }
391}