gtk/auto/
im_multicontext.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 glib::object::Cast;
6use glib::object::IsA;
7use glib::translate::*;
8use glib::GString;
9use glib::StaticType;
10use glib::ToValue;
11use gtk_sys;
12use std::fmt;
13use IMContext;
14use InputHints;
15use InputPurpose;
16
17glib_wrapper! {
18    pub struct IMMulticontext(Object<gtk_sys::GtkIMMulticontext, gtk_sys::GtkIMMulticontextClass, IMMulticontextClass>) @extends IMContext;
19
20    match fn {
21        get_type => || gtk_sys::gtk_im_multicontext_get_type(),
22    }
23}
24
25impl IMMulticontext {
26    pub fn new() -> IMMulticontext {
27        assert_initialized_main_thread!();
28        unsafe { IMContext::from_glib_full(gtk_sys::gtk_im_multicontext_new()).unsafe_cast() }
29    }
30}
31
32impl Default for IMMulticontext {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37
38pub struct IMMulticontextBuilder {
39    input_hints: Option<InputHints>,
40    input_purpose: Option<InputPurpose>,
41}
42
43impl IMMulticontextBuilder {
44    pub fn new() -> Self {
45        Self {
46            input_hints: None,
47            input_purpose: None,
48        }
49    }
50
51    pub fn build(self) -> IMMulticontext {
52        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
53        if let Some(ref input_hints) = self.input_hints {
54            properties.push(("input-hints", input_hints));
55        }
56        if let Some(ref input_purpose) = self.input_purpose {
57            properties.push(("input-purpose", input_purpose));
58        }
59        glib::Object::new(IMMulticontext::static_type(), &properties)
60            .expect("object new")
61            .downcast()
62            .expect("downcast")
63    }
64
65    pub fn input_hints(mut self, input_hints: InputHints) -> Self {
66        self.input_hints = Some(input_hints);
67        self
68    }
69
70    pub fn input_purpose(mut self, input_purpose: InputPurpose) -> Self {
71        self.input_purpose = Some(input_purpose);
72        self
73    }
74}
75
76pub const NONE_IM_MULTICONTEXT: Option<&IMMulticontext> = None;
77
78pub trait IMMulticontextExt: 'static {
79    fn get_context_id(&self) -> Option<GString>;
80
81    fn set_context_id(&self, context_id: &str);
82}
83
84impl<O: IsA<IMMulticontext>> IMMulticontextExt for O {
85    fn get_context_id(&self) -> Option<GString> {
86        unsafe {
87            from_glib_none(gtk_sys::gtk_im_multicontext_get_context_id(
88                self.as_ref().to_glib_none().0,
89            ))
90        }
91    }
92
93    fn set_context_id(&self, context_id: &str) {
94        unsafe {
95            gtk_sys::gtk_im_multicontext_set_context_id(
96                self.as_ref().to_glib_none().0,
97                context_id.to_glib_none().0,
98            );
99        }
100    }
101}
102
103impl fmt::Display for IMMulticontext {
104    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
105        write!(f, "IMMulticontext")
106    }
107}