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