gtk4/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 crate::{ffi, IMContext, InputHints, InputPurpose};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// Supports switching between multiple input methods.
10    ///
11    /// Text widgets such as [`Text`][crate::Text] or [`TextView`][crate::TextView] use a `GtkIMMultiContext`
12    /// to implement their `im-module` property for switching between different
13    /// input methods.
14    ///
15    /// # Implements
16    ///
17    /// [`IMMulticontextExt`][trait@crate::prelude::IMMulticontextExt], [`IMContextExt`][trait@crate::prelude::IMContextExt], [`trait@glib::ObjectExt`]
18    #[doc(alias = "GtkIMMulticontext")]
19    pub struct IMMulticontext(Object<ffi::GtkIMMulticontext, ffi::GtkIMMulticontextClass>) @extends IMContext;
20
21    match fn {
22        type_ => || ffi::gtk_im_multicontext_get_type(),
23    }
24}
25
26impl IMMulticontext {
27    pub const NONE: Option<&'static IMMulticontext> = None;
28
29    /// Creates a new [`IMMulticontext`][crate::IMMulticontext].
30    ///
31    /// # Returns
32    ///
33    /// a new [`IMMulticontext`][crate::IMMulticontext].
34    #[doc(alias = "gtk_im_multicontext_new")]
35    pub fn new() -> IMMulticontext {
36        assert_initialized_main_thread!();
37        unsafe { IMContext::from_glib_full(ffi::gtk_im_multicontext_new()).unsafe_cast() }
38    }
39
40    // rustdoc-stripper-ignore-next
41    /// Creates a new builder-pattern struct instance to construct [`IMMulticontext`] objects.
42    ///
43    /// This method returns an instance of [`IMMulticontextBuilder`](crate::builders::IMMulticontextBuilder) which can be used to create [`IMMulticontext`] objects.
44    pub fn builder() -> IMMulticontextBuilder {
45        IMMulticontextBuilder::new()
46    }
47}
48
49impl Default for IMMulticontext {
50    fn default() -> Self {
51        Self::new()
52    }
53}
54
55// rustdoc-stripper-ignore-next
56/// A [builder-pattern] type to construct [`IMMulticontext`] objects.
57///
58/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
59#[must_use = "The builder must be built to be used"]
60pub struct IMMulticontextBuilder {
61    builder: glib::object::ObjectBuilder<'static, IMMulticontext>,
62}
63
64impl IMMulticontextBuilder {
65    fn new() -> Self {
66        Self {
67            builder: glib::object::Object::builder(),
68        }
69    }
70
71    /// Additional hints that allow input methods to fine-tune
72    /// their behaviour.
73    pub fn input_hints(self, input_hints: InputHints) -> Self {
74        Self {
75            builder: self.builder.property("input-hints", input_hints),
76        }
77    }
78
79    /// The purpose of the text field that the `GtkIMContext is connected to.
80    ///
81    /// This property can be used by on-screen keyboards and other input
82    /// methods to adjust their behaviour.
83    pub fn input_purpose(self, input_purpose: InputPurpose) -> Self {
84        Self {
85            builder: self.builder.property("input-purpose", input_purpose),
86        }
87    }
88
89    // rustdoc-stripper-ignore-next
90    /// Build the [`IMMulticontext`].
91    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
92    pub fn build(self) -> IMMulticontext {
93        assert_initialized_main_thread!();
94        self.builder.build()
95    }
96}
97
98/// Trait containing all [`struct@IMMulticontext`] methods.
99///
100/// # Implementors
101///
102/// [`IMMulticontext`][struct@crate::IMMulticontext]
103pub trait IMMulticontextExt: IsA<IMMulticontext> + 'static {
104    /// Gets the id of the currently active delegate of the @self.
105    ///
106    /// # Returns
107    ///
108    /// the id of the currently active delegate
109    #[doc(alias = "gtk_im_multicontext_get_context_id")]
110    #[doc(alias = "get_context_id")]
111    fn context_id(&self) -> glib::GString {
112        unsafe {
113            from_glib_none(ffi::gtk_im_multicontext_get_context_id(
114                self.as_ref().to_glib_none().0,
115            ))
116        }
117    }
118
119    /// Sets the context id for @self.
120    ///
121    /// This causes the currently active delegate of @self to be
122    /// replaced by the delegate corresponding to the new context id.
123    ///
124    /// Setting this to a non-[`None`] value overrides the system-wide
125    /// IM module setting. See the [`gtk-im-module`][struct@crate::Settings#gtk-im-module]
126    /// property.
127    /// ## `context_id`
128    /// the id to use
129    #[doc(alias = "gtk_im_multicontext_set_context_id")]
130    fn set_context_id(&self, context_id: Option<&str>) {
131        unsafe {
132            ffi::gtk_im_multicontext_set_context_id(
133                self.as_ref().to_glib_none().0,
134                context_id.to_glib_none().0,
135            );
136        }
137    }
138}
139
140impl<O: IsA<IMMulticontext>> IMMulticontextExt for O {}