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 
5 use crate::InputHints;
6 use crate::InputPurpose;
7 use glib::object::Cast;
8 use glib::object::IsA;
9 use glib::signal::connect_raw;
10 use glib::signal::SignalHandlerId;
11 use glib::translate::*;
12 use glib::StaticType;
13 use glib::ToValue;
14 use std::boxed::Box as Box_;
15 use std::fmt;
16 use std::mem;
17 use std::mem::transmute;
18 use std::ptr;
19 
20 glib::wrapper! {
21     #[doc(alias = "GtkIMContext")]
22     pub struct IMContext(Object<ffi::GtkIMContext, ffi::GtkIMContextClass>);
23 
24     match fn {
25         type_ => || ffi::gtk_im_context_get_type(),
26     }
27 }
28 
29 pub const NONE_IM_CONTEXT: Option<&IMContext> = None;
30 
31 pub trait IMContextExt: 'static {
32     #[doc(alias = "gtk_im_context_delete_surrounding")]
delete_surrounding(&self, offset: i32, n_chars: i32) -> bool33     fn delete_surrounding(&self, offset: i32, n_chars: i32) -> bool;
34 
35     #[doc(alias = "gtk_im_context_filter_keypress")]
filter_keypress(&self, event: &gdk::EventKey) -> bool36     fn filter_keypress(&self, event: &gdk::EventKey) -> bool;
37 
38     #[doc(alias = "gtk_im_context_focus_in")]
focus_in(&self)39     fn focus_in(&self);
40 
41     #[doc(alias = "gtk_im_context_focus_out")]
focus_out(&self)42     fn focus_out(&self);
43 
44     #[doc(alias = "gtk_im_context_get_preedit_string")]
45     #[doc(alias = "get_preedit_string")]
preedit_string(&self) -> (glib::GString, pango::AttrList, i32)46     fn preedit_string(&self) -> (glib::GString, pango::AttrList, i32);
47 
48     #[doc(alias = "gtk_im_context_get_surrounding")]
49     #[doc(alias = "get_surrounding")]
surrounding(&self) -> Option<(glib::GString, i32)>50     fn surrounding(&self) -> Option<(glib::GString, i32)>;
51 
52     #[doc(alias = "gtk_im_context_reset")]
reset(&self)53     fn reset(&self);
54 
55     #[doc(alias = "gtk_im_context_set_client_window")]
set_client_window(&self, window: Option<&gdk::Window>)56     fn set_client_window(&self, window: Option<&gdk::Window>);
57 
58     #[doc(alias = "gtk_im_context_set_cursor_location")]
set_cursor_location(&self, area: &gdk::Rectangle)59     fn set_cursor_location(&self, area: &gdk::Rectangle);
60 
61     #[doc(alias = "gtk_im_context_set_surrounding")]
set_surrounding(&self, text: &str, cursor_index: i32)62     fn set_surrounding(&self, text: &str, cursor_index: i32);
63 
64     #[doc(alias = "gtk_im_context_set_use_preedit")]
set_use_preedit(&self, use_preedit: bool)65     fn set_use_preedit(&self, use_preedit: bool);
66 
67     #[doc(alias = "input-hints")]
input_hints(&self) -> InputHints68     fn input_hints(&self) -> InputHints;
69 
70     #[doc(alias = "input-hints")]
set_input_hints(&self, input_hints: InputHints)71     fn set_input_hints(&self, input_hints: InputHints);
72 
73     #[doc(alias = "input-purpose")]
input_purpose(&self) -> InputPurpose74     fn input_purpose(&self) -> InputPurpose;
75 
76     #[doc(alias = "input-purpose")]
set_input_purpose(&self, input_purpose: InputPurpose)77     fn set_input_purpose(&self, input_purpose: InputPurpose);
78 
79     #[doc(alias = "commit")]
connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId80     fn connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId;
81 
82     #[doc(alias = "delete-surrounding")]
connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>( &self, f: F, ) -> SignalHandlerId83     fn connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>(
84         &self,
85         f: F,
86     ) -> SignalHandlerId;
87 
88     #[doc(alias = "preedit-changed")]
connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId89     fn connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
90 
91     #[doc(alias = "preedit-end")]
connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId92     fn connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
93 
94     #[doc(alias = "preedit-start")]
connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId95     fn connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
96 
97     #[doc(alias = "retrieve-surrounding")]
connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>(&self, f: F) -> SignalHandlerId98     fn connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>(&self, f: F)
99         -> SignalHandlerId;
100 
101     #[doc(alias = "input-hints")]
connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId102     fn connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
103 
104     #[doc(alias = "input-purpose")]
connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId105     fn connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
106 }
107 
108 impl<O: IsA<IMContext>> IMContextExt for O {
delete_surrounding(&self, offset: i32, n_chars: i32) -> bool109     fn delete_surrounding(&self, offset: i32, n_chars: i32) -> bool {
110         unsafe {
111             from_glib(ffi::gtk_im_context_delete_surrounding(
112                 self.as_ref().to_glib_none().0,
113                 offset,
114                 n_chars,
115             ))
116         }
117     }
118 
filter_keypress(&self, event: &gdk::EventKey) -> bool119     fn filter_keypress(&self, event: &gdk::EventKey) -> bool {
120         unsafe {
121             from_glib(ffi::gtk_im_context_filter_keypress(
122                 self.as_ref().to_glib_none().0,
123                 mut_override(event.to_glib_none().0),
124             ))
125         }
126     }
127 
focus_in(&self)128     fn focus_in(&self) {
129         unsafe {
130             ffi::gtk_im_context_focus_in(self.as_ref().to_glib_none().0);
131         }
132     }
133 
focus_out(&self)134     fn focus_out(&self) {
135         unsafe {
136             ffi::gtk_im_context_focus_out(self.as_ref().to_glib_none().0);
137         }
138     }
139 
preedit_string(&self) -> (glib::GString, pango::AttrList, i32)140     fn preedit_string(&self) -> (glib::GString, pango::AttrList, i32) {
141         unsafe {
142             let mut str = ptr::null_mut();
143             let mut attrs = ptr::null_mut();
144             let mut cursor_pos = mem::MaybeUninit::uninit();
145             ffi::gtk_im_context_get_preedit_string(
146                 self.as_ref().to_glib_none().0,
147                 &mut str,
148                 &mut attrs,
149                 cursor_pos.as_mut_ptr(),
150             );
151             let cursor_pos = cursor_pos.assume_init();
152             (from_glib_full(str), from_glib_full(attrs), cursor_pos)
153         }
154     }
155 
surrounding(&self) -> Option<(glib::GString, i32)>156     fn surrounding(&self) -> Option<(glib::GString, i32)> {
157         unsafe {
158             let mut text = ptr::null_mut();
159             let mut cursor_index = mem::MaybeUninit::uninit();
160             let ret = from_glib(ffi::gtk_im_context_get_surrounding(
161                 self.as_ref().to_glib_none().0,
162                 &mut text,
163                 cursor_index.as_mut_ptr(),
164             ));
165             let cursor_index = cursor_index.assume_init();
166             if ret {
167                 Some((from_glib_full(text), cursor_index))
168             } else {
169                 None
170             }
171         }
172     }
173 
reset(&self)174     fn reset(&self) {
175         unsafe {
176             ffi::gtk_im_context_reset(self.as_ref().to_glib_none().0);
177         }
178     }
179 
set_client_window(&self, window: Option<&gdk::Window>)180     fn set_client_window(&self, window: Option<&gdk::Window>) {
181         unsafe {
182             ffi::gtk_im_context_set_client_window(
183                 self.as_ref().to_glib_none().0,
184                 window.to_glib_none().0,
185             );
186         }
187     }
188 
set_cursor_location(&self, area: &gdk::Rectangle)189     fn set_cursor_location(&self, area: &gdk::Rectangle) {
190         unsafe {
191             ffi::gtk_im_context_set_cursor_location(
192                 self.as_ref().to_glib_none().0,
193                 area.to_glib_none().0,
194             );
195         }
196     }
197 
set_surrounding(&self, text: &str, cursor_index: i32)198     fn set_surrounding(&self, text: &str, cursor_index: i32) {
199         let len = text.len() as i32;
200         unsafe {
201             ffi::gtk_im_context_set_surrounding(
202                 self.as_ref().to_glib_none().0,
203                 text.to_glib_none().0,
204                 len,
205                 cursor_index,
206             );
207         }
208     }
209 
set_use_preedit(&self, use_preedit: bool)210     fn set_use_preedit(&self, use_preedit: bool) {
211         unsafe {
212             ffi::gtk_im_context_set_use_preedit(
213                 self.as_ref().to_glib_none().0,
214                 use_preedit.into_glib(),
215             );
216         }
217     }
218 
input_hints(&self) -> InputHints219     fn input_hints(&self) -> InputHints {
220         unsafe {
221             let mut value = glib::Value::from_type(<InputHints as StaticType>::static_type());
222             glib::gobject_ffi::g_object_get_property(
223                 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
224                 b"input-hints\0".as_ptr() as *const _,
225                 value.to_glib_none_mut().0,
226             );
227             value
228                 .get()
229                 .expect("Return Value for property `input-hints` getter")
230         }
231     }
232 
set_input_hints(&self, input_hints: InputHints)233     fn set_input_hints(&self, input_hints: InputHints) {
234         unsafe {
235             glib::gobject_ffi::g_object_set_property(
236                 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
237                 b"input-hints\0".as_ptr() as *const _,
238                 input_hints.to_value().to_glib_none().0,
239             );
240         }
241     }
242 
input_purpose(&self) -> InputPurpose243     fn input_purpose(&self) -> InputPurpose {
244         unsafe {
245             let mut value = glib::Value::from_type(<InputPurpose as StaticType>::static_type());
246             glib::gobject_ffi::g_object_get_property(
247                 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
248                 b"input-purpose\0".as_ptr() as *const _,
249                 value.to_glib_none_mut().0,
250             );
251             value
252                 .get()
253                 .expect("Return Value for property `input-purpose` getter")
254         }
255     }
256 
set_input_purpose(&self, input_purpose: InputPurpose)257     fn set_input_purpose(&self, input_purpose: InputPurpose) {
258         unsafe {
259             glib::gobject_ffi::g_object_set_property(
260                 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
261                 b"input-purpose\0".as_ptr() as *const _,
262                 input_purpose.to_value().to_glib_none().0,
263             );
264         }
265     }
266 
connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId267     fn connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
268         unsafe extern "C" fn commit_trampoline<P: IsA<IMContext>, F: Fn(&P, &str) + 'static>(
269             this: *mut ffi::GtkIMContext,
270             str: *mut libc::c_char,
271             f: glib::ffi::gpointer,
272         ) {
273             let f: &F = &*(f as *const F);
274             f(
275                 IMContext::from_glib_borrow(this).unsafe_cast_ref(),
276                 &glib::GString::from_glib_borrow(str),
277             )
278         }
279         unsafe {
280             let f: Box_<F> = Box_::new(f);
281             connect_raw(
282                 self.as_ptr() as *mut _,
283                 b"commit\0".as_ptr() as *const _,
284                 Some(transmute::<_, unsafe extern "C" fn()>(
285                     commit_trampoline::<Self, F> as *const (),
286                 )),
287                 Box_::into_raw(f),
288             )
289         }
290     }
291 
connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>( &self, f: F, ) -> SignalHandlerId292     fn connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>(
293         &self,
294         f: F,
295     ) -> SignalHandlerId {
296         unsafe extern "C" fn delete_surrounding_trampoline<
297             P: IsA<IMContext>,
298             F: Fn(&P, i32, i32) -> bool + 'static,
299         >(
300             this: *mut ffi::GtkIMContext,
301             offset: libc::c_int,
302             n_chars: libc::c_int,
303             f: glib::ffi::gpointer,
304         ) -> glib::ffi::gboolean {
305             let f: &F = &*(f as *const F);
306             f(
307                 IMContext::from_glib_borrow(this).unsafe_cast_ref(),
308                 offset,
309                 n_chars,
310             )
311             .into_glib()
312         }
313         unsafe {
314             let f: Box_<F> = Box_::new(f);
315             connect_raw(
316                 self.as_ptr() as *mut _,
317                 b"delete-surrounding\0".as_ptr() as *const _,
318                 Some(transmute::<_, unsafe extern "C" fn()>(
319                     delete_surrounding_trampoline::<Self, F> as *const (),
320                 )),
321                 Box_::into_raw(f),
322             )
323         }
324     }
325 
connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId326     fn connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
327         unsafe extern "C" fn preedit_changed_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
328             this: *mut ffi::GtkIMContext,
329             f: glib::ffi::gpointer,
330         ) {
331             let f: &F = &*(f as *const F);
332             f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
333         }
334         unsafe {
335             let f: Box_<F> = Box_::new(f);
336             connect_raw(
337                 self.as_ptr() as *mut _,
338                 b"preedit-changed\0".as_ptr() as *const _,
339                 Some(transmute::<_, unsafe extern "C" fn()>(
340                     preedit_changed_trampoline::<Self, F> as *const (),
341                 )),
342                 Box_::into_raw(f),
343             )
344         }
345     }
346 
connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId347     fn connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
348         unsafe extern "C" fn preedit_end_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
349             this: *mut ffi::GtkIMContext,
350             f: glib::ffi::gpointer,
351         ) {
352             let f: &F = &*(f as *const F);
353             f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
354         }
355         unsafe {
356             let f: Box_<F> = Box_::new(f);
357             connect_raw(
358                 self.as_ptr() as *mut _,
359                 b"preedit-end\0".as_ptr() as *const _,
360                 Some(transmute::<_, unsafe extern "C" fn()>(
361                     preedit_end_trampoline::<Self, F> as *const (),
362                 )),
363                 Box_::into_raw(f),
364             )
365         }
366     }
367 
connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId368     fn connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
369         unsafe extern "C" fn preedit_start_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
370             this: *mut ffi::GtkIMContext,
371             f: glib::ffi::gpointer,
372         ) {
373             let f: &F = &*(f as *const F);
374             f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
375         }
376         unsafe {
377             let f: Box_<F> = Box_::new(f);
378             connect_raw(
379                 self.as_ptr() as *mut _,
380                 b"preedit-start\0".as_ptr() as *const _,
381                 Some(transmute::<_, unsafe extern "C" fn()>(
382                     preedit_start_trampoline::<Self, F> as *const (),
383                 )),
384                 Box_::into_raw(f),
385             )
386         }
387     }
388 
connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>( &self, f: F, ) -> SignalHandlerId389     fn connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>(
390         &self,
391         f: F,
392     ) -> SignalHandlerId {
393         unsafe extern "C" fn retrieve_surrounding_trampoline<
394             P: IsA<IMContext>,
395             F: Fn(&P) -> bool + 'static,
396         >(
397             this: *mut ffi::GtkIMContext,
398             f: glib::ffi::gpointer,
399         ) -> glib::ffi::gboolean {
400             let f: &F = &*(f as *const F);
401             f(IMContext::from_glib_borrow(this).unsafe_cast_ref()).into_glib()
402         }
403         unsafe {
404             let f: Box_<F> = Box_::new(f);
405             connect_raw(
406                 self.as_ptr() as *mut _,
407                 b"retrieve-surrounding\0".as_ptr() as *const _,
408                 Some(transmute::<_, unsafe extern "C" fn()>(
409                     retrieve_surrounding_trampoline::<Self, F> as *const (),
410                 )),
411                 Box_::into_raw(f),
412             )
413         }
414     }
415 
connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId416     fn connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
417         unsafe extern "C" fn notify_input_hints_trampoline<
418             P: IsA<IMContext>,
419             F: Fn(&P) + 'static,
420         >(
421             this: *mut ffi::GtkIMContext,
422             _param_spec: glib::ffi::gpointer,
423             f: glib::ffi::gpointer,
424         ) {
425             let f: &F = &*(f as *const F);
426             f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
427         }
428         unsafe {
429             let f: Box_<F> = Box_::new(f);
430             connect_raw(
431                 self.as_ptr() as *mut _,
432                 b"notify::input-hints\0".as_ptr() as *const _,
433                 Some(transmute::<_, unsafe extern "C" fn()>(
434                     notify_input_hints_trampoline::<Self, F> as *const (),
435                 )),
436                 Box_::into_raw(f),
437             )
438         }
439     }
440 
connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId441     fn connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
442         unsafe extern "C" fn notify_input_purpose_trampoline<
443             P: IsA<IMContext>,
444             F: Fn(&P) + 'static,
445         >(
446             this: *mut ffi::GtkIMContext,
447             _param_spec: glib::ffi::gpointer,
448             f: glib::ffi::gpointer,
449         ) {
450             let f: &F = &*(f as *const F);
451             f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
452         }
453         unsafe {
454             let f: Box_<F> = Box_::new(f);
455             connect_raw(
456                 self.as_ptr() as *mut _,
457                 b"notify::input-purpose\0".as_ptr() as *const _,
458                 Some(transmute::<_, unsafe extern "C" fn()>(
459                     notify_input_purpose_trampoline::<Self, F> as *const (),
460                 )),
461                 Box_::into_raw(f),
462             )
463         }
464     }
465 }
466 
467 impl fmt::Display for IMContext {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result468     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
469         f.write_str("IMContext")
470     }
471 }
472