Skip to main content

gtk4/auto/
at_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
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::Accessible;
8use crate::{AccessibleRole, ffi};
9use glib::{
10    object::ObjectType as _,
11    prelude::*,
12    signal::{SignalHandlerId, connect_raw},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    /// Communicates with platform-specific assistive technologies API.
19    ///
20    /// Each platform supported by GTK implements a [`ATContext`][crate::ATContext] subclass, and
21    /// is responsible for updating the accessible state in response to state
22    /// changes in [`Accessible`][crate::Accessible].
23    ///
24    /// This is an Abstract Base Class, you cannot instantiate it.
25    ///
26    /// ## Properties
27    ///
28    ///
29    /// #### `accessible`
30    ///  The [`Accessible`][crate::Accessible] that created the [`ATContext`][crate::ATContext] instance.
31    ///
32    /// Readable | Writable | Construct Only
33    ///
34    ///
35    /// #### `accessible-role`
36    ///  The accessible role used by the AT context.
37    ///
38    /// Depending on the given role, different states and properties can be
39    /// set or retrieved.
40    ///
41    /// Readable | Writable | Construct
42    ///
43    ///
44    /// #### `display`
45    ///  The [`gdk::Display`][crate::gdk::Display] for the [`ATContext`][crate::ATContext].
46    ///
47    /// Readable | Writable
48    ///
49    ///
50    /// #### `realized`
51    ///  Whether the [`ATContext`][crate::ATContext] has been realized or not.
52    ///
53    /// Readable
54    ///
55    /// ## Signals
56    ///
57    ///
58    /// #### `state-change`
59    ///  Emitted when the attributes of the accessible for the
60    /// [`ATContext`][crate::ATContext] instance change.
61    ///
62    ///
63    ///
64    /// # Implements
65    ///
66    /// [`trait@glib::ObjectExt`]
67    #[doc(alias = "GtkATContext")]
68    pub struct ATContext(Object<ffi::GtkATContext, ffi::GtkATContextClass>);
69
70    match fn {
71        type_ => || ffi::gtk_at_context_get_type(),
72    }
73}
74
75impl ATContext {
76    /// Creates a new [`ATContext`][crate::ATContext] instance for the given accessible role,
77    /// accessible instance, and display connection.
78    ///
79    /// The [`ATContext`][crate::ATContext] implementation being instantiated will depend on the
80    /// platform.
81    /// ## `accessible_role`
82    /// the accessible role used by the [`ATContext`][crate::ATContext]
83    /// ## `accessible`
84    /// the [`Accessible`][crate::Accessible] implementation using the [`ATContext`][crate::ATContext]
85    /// ## `display`
86    /// the [`gdk::Display`][crate::gdk::Display] used by the [`ATContext`][crate::ATContext]
87    ///
88    /// # Returns
89    ///
90    /// the [`ATContext`][crate::ATContext]
91    #[cfg(feature = "v4_10")]
92    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
93    #[doc(alias = "gtk_at_context_create")]
94    pub fn create(
95        accessible_role: AccessibleRole,
96        accessible: &impl IsA<Accessible>,
97        display: &impl IsA<gdk::Display>,
98    ) -> Option<ATContext> {
99        skip_assert_initialized!();
100        unsafe {
101            from_glib_full(ffi::gtk_at_context_create(
102                accessible_role.into_glib(),
103                accessible.as_ref().to_glib_none().0,
104                display.as_ref().to_glib_none().0,
105            ))
106        }
107    }
108
109    /// Retrieves the [`Accessible`][crate::Accessible] using this context.
110    ///
111    /// # Returns
112    ///
113    /// a [`Accessible`][crate::Accessible]
114    #[cfg(feature = "v4_10")]
115    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
116    #[doc(alias = "gtk_at_context_get_accessible")]
117    #[doc(alias = "get_accessible")]
118    pub fn accessible(&self) -> Accessible {
119        unsafe { from_glib_none(ffi::gtk_at_context_get_accessible(self.to_glib_none().0)) }
120    }
121
122    /// Retrieves the accessible role of this context.
123    ///
124    /// # Returns
125    ///
126    /// a [`AccessibleRole`][crate::AccessibleRole]
127    #[doc(alias = "gtk_at_context_get_accessible_role")]
128    #[doc(alias = "get_accessible_role")]
129    #[doc(alias = "accessible-role")]
130    pub fn accessible_role(&self) -> AccessibleRole {
131        unsafe {
132            from_glib(ffi::gtk_at_context_get_accessible_role(
133                self.to_glib_none().0,
134            ))
135        }
136    }
137
138    /// The accessible role used by the AT context.
139    ///
140    /// Depending on the given role, different states and properties can be
141    /// set or retrieved.
142    #[doc(alias = "accessible-role")]
143    pub fn set_accessible_role(&self, accessible_role: AccessibleRole) {
144        ObjectExt::set_property(self, "accessible-role", accessible_role)
145    }
146
147    /// The [`gdk::Display`][crate::gdk::Display] for the [`ATContext`][crate::ATContext].
148    pub fn display(&self) -> Option<gdk::Display> {
149        ObjectExt::property(self, "display")
150    }
151
152    /// The [`gdk::Display`][crate::gdk::Display] for the [`ATContext`][crate::ATContext].
153    pub fn set_display<P: IsA<gdk::Display>>(&self, display: Option<&P>) {
154        ObjectExt::set_property(self, "display", display)
155    }
156
157    /// Whether the [`ATContext`][crate::ATContext] has been realized or not.
158    #[cfg(feature = "v4_24")]
159    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
160    pub fn is_realized(&self) -> bool {
161        ObjectExt::property(self, "realized")
162    }
163
164    /// Emitted when the attributes of the accessible for the
165    /// [`ATContext`][crate::ATContext] instance change.
166    #[doc(alias = "state-change")]
167    pub fn connect_state_change<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
168        unsafe extern "C" fn state_change_trampoline<F: Fn(&ATContext) + 'static>(
169            this: *mut ffi::GtkATContext,
170            f: glib::ffi::gpointer,
171        ) {
172            unsafe {
173                let f: &F = &*(f as *const F);
174                f(&from_glib_borrow(this))
175            }
176        }
177        unsafe {
178            let f: Box_<F> = Box_::new(f);
179            connect_raw(
180                self.as_ptr() as *mut _,
181                c"state-change".as_ptr(),
182                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
183                    state_change_trampoline::<F> as *const (),
184                )),
185                Box_::into_raw(f),
186            )
187        }
188    }
189
190    #[doc(alias = "accessible-role")]
191    pub fn connect_accessible_role_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
192        unsafe extern "C" fn notify_accessible_role_trampoline<F: Fn(&ATContext) + 'static>(
193            this: *mut ffi::GtkATContext,
194            _param_spec: glib::ffi::gpointer,
195            f: glib::ffi::gpointer,
196        ) {
197            unsafe {
198                let f: &F = &*(f as *const F);
199                f(&from_glib_borrow(this))
200            }
201        }
202        unsafe {
203            let f: Box_<F> = Box_::new(f);
204            connect_raw(
205                self.as_ptr() as *mut _,
206                c"notify::accessible-role".as_ptr(),
207                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
208                    notify_accessible_role_trampoline::<F> as *const (),
209                )),
210                Box_::into_raw(f),
211            )
212        }
213    }
214
215    #[doc(alias = "display")]
216    pub fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
217        unsafe extern "C" fn notify_display_trampoline<F: Fn(&ATContext) + 'static>(
218            this: *mut ffi::GtkATContext,
219            _param_spec: glib::ffi::gpointer,
220            f: glib::ffi::gpointer,
221        ) {
222            unsafe {
223                let f: &F = &*(f as *const F);
224                f(&from_glib_borrow(this))
225            }
226        }
227        unsafe {
228            let f: Box_<F> = Box_::new(f);
229            connect_raw(
230                self.as_ptr() as *mut _,
231                c"notify::display".as_ptr(),
232                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
233                    notify_display_trampoline::<F> as *const (),
234                )),
235                Box_::into_raw(f),
236            )
237        }
238    }
239
240    #[cfg(feature = "v4_24")]
241    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
242    #[doc(alias = "realized")]
243    pub fn connect_realized_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
244        unsafe extern "C" fn notify_realized_trampoline<F: Fn(&ATContext) + 'static>(
245            this: *mut ffi::GtkATContext,
246            _param_spec: glib::ffi::gpointer,
247            f: glib::ffi::gpointer,
248        ) {
249            unsafe {
250                let f: &F = &*(f as *const F);
251                f(&from_glib_borrow(this))
252            }
253        }
254        unsafe {
255            let f: Box_<F> = Box_::new(f);
256            connect_raw(
257                self.as_ptr() as *mut _,
258                c"notify::realized".as_ptr(),
259                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
260                    notify_realized_trampoline::<F> as *const (),
261                )),
262                Box_::into_raw(f),
263            )
264        }
265    }
266}