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::{ffi, Accessible, AccessibleRole};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
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            let f: &F = &*(f as *const F);
153            f(&from_glib_borrow(this))
154        }
155        unsafe {
156            let f: Box_<F> = Box_::new(f);
157            connect_raw(
158                self.as_ptr() as *mut _,
159                c"state-change".as_ptr() as *const _,
160                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
161                    state_change_trampoline::<F> as *const (),
162                )),
163                Box_::into_raw(f),
164            )
165        }
166    }
167
168    #[doc(alias = "accessible-role")]
169    pub fn connect_accessible_role_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
170        unsafe extern "C" fn notify_accessible_role_trampoline<F: Fn(&ATContext) + 'static>(
171            this: *mut ffi::GtkATContext,
172            _param_spec: glib::ffi::gpointer,
173            f: glib::ffi::gpointer,
174        ) {
175            let f: &F = &*(f as *const F);
176            f(&from_glib_borrow(this))
177        }
178        unsafe {
179            let f: Box_<F> = Box_::new(f);
180            connect_raw(
181                self.as_ptr() as *mut _,
182                c"notify::accessible-role".as_ptr() as *const _,
183                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
184                    notify_accessible_role_trampoline::<F> as *const (),
185                )),
186                Box_::into_raw(f),
187            )
188        }
189    }
190
191    #[doc(alias = "display")]
192    pub fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
193        unsafe extern "C" fn notify_display_trampoline<F: Fn(&ATContext) + 'static>(
194            this: *mut ffi::GtkATContext,
195            _param_spec: glib::ffi::gpointer,
196            f: glib::ffi::gpointer,
197        ) {
198            let f: &F = &*(f as *const F);
199            f(&from_glib_borrow(this))
200        }
201        unsafe {
202            let f: Box_<F> = Box_::new(f);
203            connect_raw(
204                self.as_ptr() as *mut _,
205                c"notify::display".as_ptr() as *const _,
206                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
207                    notify_display_trampoline::<F> as *const (),
208                )),
209                Box_::into_raw(f),
210            )
211        }
212    }
213}