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    /// ## Signals
47    ///
48    ///
49    /// #### `state-change`
50    ///  Emitted when the attributes of the accessible for the
51    /// [`ATContext`][crate::ATContext] instance change.
52    ///
53    ///
54    ///
55    /// # Implements
56    ///
57    /// [`trait@glib::ObjectExt`]
58    #[doc(alias = "GtkATContext")]
59    pub struct ATContext(Object<ffi::GtkATContext, ffi::GtkATContextClass>);
60
61    match fn {
62        type_ => || ffi::gtk_at_context_get_type(),
63    }
64}
65
66impl ATContext {
67    /// Creates a new [`ATContext`][crate::ATContext] instance for the given accessible role,
68    /// accessible instance, and display connection.
69    ///
70    /// The [`ATContext`][crate::ATContext] implementation being instantiated will depend on the
71    /// platform.
72    /// ## `accessible_role`
73    /// the accessible role used by the [`ATContext`][crate::ATContext]
74    /// ## `accessible`
75    /// the [`Accessible`][crate::Accessible] implementation using the [`ATContext`][crate::ATContext]
76    /// ## `display`
77    /// the [`gdk::Display`][crate::gdk::Display] used by the [`ATContext`][crate::ATContext]
78    ///
79    /// # Returns
80    ///
81    /// the [`ATContext`][crate::ATContext]
82    #[doc(alias = "gtk_at_context_create")]
83    pub fn create(
84        accessible_role: AccessibleRole,
85        accessible: &impl IsA<Accessible>,
86        display: &impl IsA<gdk::Display>,
87    ) -> Option<ATContext> {
88        skip_assert_initialized!();
89        unsafe {
90            from_glib_full(ffi::gtk_at_context_create(
91                accessible_role.into_glib(),
92                accessible.as_ref().to_glib_none().0,
93                display.as_ref().to_glib_none().0,
94            ))
95        }
96    }
97
98    /// Retrieves the [`Accessible`][crate::Accessible] using this context.
99    ///
100    /// # Returns
101    ///
102    /// a [`Accessible`][crate::Accessible]
103    #[doc(alias = "gtk_at_context_get_accessible")]
104    #[doc(alias = "get_accessible")]
105    pub fn accessible(&self) -> Accessible {
106        unsafe { from_glib_none(ffi::gtk_at_context_get_accessible(self.to_glib_none().0)) }
107    }
108
109    /// Retrieves the accessible role of this context.
110    ///
111    /// # Returns
112    ///
113    /// a [`AccessibleRole`][crate::AccessibleRole]
114    #[doc(alias = "gtk_at_context_get_accessible_role")]
115    #[doc(alias = "get_accessible_role")]
116    #[doc(alias = "accessible-role")]
117    pub fn accessible_role(&self) -> AccessibleRole {
118        unsafe {
119            from_glib(ffi::gtk_at_context_get_accessible_role(
120                self.to_glib_none().0,
121            ))
122        }
123    }
124
125    /// The accessible role used by the AT context.
126    ///
127    /// Depending on the given role, different states and properties can be
128    /// set or retrieved.
129    #[doc(alias = "accessible-role")]
130    pub fn set_accessible_role(&self, accessible_role: AccessibleRole) {
131        ObjectExt::set_property(self, "accessible-role", accessible_role)
132    }
133
134    /// The [`gdk::Display`][crate::gdk::Display] for the [`ATContext`][crate::ATContext].
135    pub fn display(&self) -> Option<gdk::Display> {
136        ObjectExt::property(self, "display")
137    }
138
139    /// The [`gdk::Display`][crate::gdk::Display] for the [`ATContext`][crate::ATContext].
140    pub fn set_display<P: IsA<gdk::Display>>(&self, display: Option<&P>) {
141        ObjectExt::set_property(self, "display", display)
142    }
143
144    /// Emitted when the attributes of the accessible for the
145    /// [`ATContext`][crate::ATContext] instance change.
146    #[doc(alias = "state-change")]
147    pub fn connect_state_change<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
148        unsafe extern "C" fn state_change_trampoline<F: Fn(&ATContext) + 'static>(
149            this: *mut ffi::GtkATContext,
150            f: glib::ffi::gpointer,
151        ) {
152            unsafe {
153                let f: &F = &*(f as *const F);
154                f(&from_glib_borrow(this))
155            }
156        }
157        unsafe {
158            let f: Box_<F> = Box_::new(f);
159            connect_raw(
160                self.as_ptr() as *mut _,
161                c"state-change".as_ptr() as *const _,
162                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
163                    state_change_trampoline::<F> as *const (),
164                )),
165                Box_::into_raw(f),
166            )
167        }
168    }
169
170    #[doc(alias = "accessible-role")]
171    pub fn connect_accessible_role_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
172        unsafe extern "C" fn notify_accessible_role_trampoline<F: Fn(&ATContext) + 'static>(
173            this: *mut ffi::GtkATContext,
174            _param_spec: glib::ffi::gpointer,
175            f: glib::ffi::gpointer,
176        ) {
177            unsafe {
178                let f: &F = &*(f as *const F);
179                f(&from_glib_borrow(this))
180            }
181        }
182        unsafe {
183            let f: Box_<F> = Box_::new(f);
184            connect_raw(
185                self.as_ptr() as *mut _,
186                c"notify::accessible-role".as_ptr() as *const _,
187                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
188                    notify_accessible_role_trampoline::<F> as *const (),
189                )),
190                Box_::into_raw(f),
191            )
192        }
193    }
194
195    #[doc(alias = "display")]
196    pub fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
197        unsafe extern "C" fn notify_display_trampoline<F: Fn(&ATContext) + 'static>(
198            this: *mut ffi::GtkATContext,
199            _param_spec: glib::ffi::gpointer,
200            f: glib::ffi::gpointer,
201        ) {
202            unsafe {
203                let f: &F = &*(f as *const F);
204                f(&from_glib_borrow(this))
205            }
206        }
207        unsafe {
208            let f: Box_<F> = Box_::new(f);
209            connect_raw(
210                self.as_ptr() as *mut _,
211                c"notify::display".as_ptr() as *const _,
212                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
213                    notify_display_trampoline::<F> as *const (),
214                )),
215                Box_::into_raw(f),
216            )
217        }
218    }
219}