Skip to main content

gtk4/auto/
accessible.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_14")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
7use crate::AccessibleAnnouncementPriority;
8use crate::{
9    ATContext, AccessiblePlatformState, AccessibleProperty, AccessibleRelation, AccessibleRole,
10    AccessibleState, ffi,
11};
12use glib::{
13    prelude::*,
14    signal::{SignalHandlerId, connect_raw},
15    translate::*,
16};
17use std::boxed::Box as Box_;
18
19glib::wrapper! {
20    /// An interface for describing UI elements for Assistive Technologies.
21    ///
22    /// Every accessible implementation has:
23    ///
24    ///  - a “role”, represented by a value of the [`AccessibleRole`][crate::AccessibleRole] enumeration
25    ///  - “attributes”, represented by a set of [`AccessibleState`][crate::AccessibleState],
26    ///    [`AccessibleProperty`][crate::AccessibleProperty] and [`AccessibleRelation`][crate::AccessibleRelation] values
27    ///
28    /// The role cannot be changed after instantiating a [`Accessible`][crate::Accessible]
29    /// implementation.
30    ///
31    /// The attributes are updated every time a UI element's state changes in
32    /// a way that should be reflected by assistive technologies. For instance,
33    /// if a [`Widget`][crate::Widget] visibility changes, the [`AccessibleState::Hidden`][crate::AccessibleState::Hidden]
34    /// state will also change to reflect the [`visible`][struct@crate::Widget#visible] property.
35    ///
36    /// Every accessible implementation is part of a tree of accessible objects.
37    /// Normally, this tree corresponds to the widget tree, but can be customized
38    /// by reimplementing the `vfunc::Gtk::Accessible::get_accessible_parent`,
39    /// `vfunc::Gtk::Accessible::get_first_accessible_child` and
40    /// `vfunc::Gtk::Accessible::get_next_accessible_sibling` virtual functions.
41    ///
42    /// Note that you can not create a top-level accessible object as of now,
43    /// which means that you must always have a parent accessible object.
44    ///
45    /// Also note that when an accessible object does not correspond to a widget,
46    /// and it has children, whose implementation you don't control,
47    /// it is necessary to ensure the correct shape of the a11y tree
48    /// by calling [`AccessibleExt::set_accessible_parent()`][crate::prelude::AccessibleExt::set_accessible_parent()] and
49    /// updating the sibling by [`AccessibleExt::update_next_accessible_sibling()`][crate::prelude::AccessibleExt::update_next_accessible_sibling()].
50    ///
51    /// ## Properties
52    ///
53    ///
54    /// #### `accessible-role`
55    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
56    ///
57    /// The accessible role cannot be changed once set.
58    ///
59    /// Readable | Writable
60    ///
61    /// # Implements
62    ///
63    /// [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
64    #[doc(alias = "GtkAccessible")]
65    pub struct Accessible(Interface<ffi::GtkAccessible, ffi::GtkAccessibleInterface>);
66
67    match fn {
68        type_ => || ffi::gtk_accessible_get_type(),
69    }
70}
71
72impl Accessible {
73    pub const NONE: Option<&'static Accessible> = None;
74}
75
76/// Trait containing all [`struct@Accessible`] methods.
77///
78/// # Implementors
79///
80/// [`AboutDialog`][struct@crate::AboutDialog], [`AccessibleHyperlink`][struct@crate::AccessibleHyperlink], [`AccessibleHypertext`][struct@crate::AccessibleHypertext], [`AccessibleRange`][struct@crate::AccessibleRange], [`AccessibleText`][struct@crate::AccessibleText], [`Accessible`][struct@crate::Accessible], [`ActionBar`][struct@crate::ActionBar], [`AppChooserButton`][struct@crate::AppChooserButton], [`AppChooserDialog`][struct@crate::AppChooserDialog], [`AppChooserWidget`][struct@crate::AppChooserWidget], [`ApplicationWindow`][struct@crate::ApplicationWindow], [`AspectFrame`][struct@crate::AspectFrame], [`Assistant`][struct@crate::Assistant], [`Box`][struct@crate::Box], [`Button`][struct@crate::Button], [`Calendar`][struct@crate::Calendar], [`CellView`][struct@crate::CellView], [`CenterBox`][struct@crate::CenterBox], [`CheckButton`][struct@crate::CheckButton], [`ColorButton`][struct@crate::ColorButton], [`ColorChooserDialog`][struct@crate::ColorChooserDialog], [`ColorChooserWidget`][struct@crate::ColorChooserWidget], [`ColorDialogButton`][struct@crate::ColorDialogButton], [`ColumnView`][struct@crate::ColumnView], [`ComboBoxText`][struct@crate::ComboBoxText], [`ComboBox`][struct@crate::ComboBox], [`Dialog`][struct@crate::Dialog], [`DragIcon`][struct@crate::DragIcon], [`DrawingArea`][struct@crate::DrawingArea], [`DropDown`][struct@crate::DropDown], [`EditableLabel`][struct@crate::EditableLabel], [`EmojiChooser`][struct@crate::EmojiChooser], [`Entry`][struct@crate::Entry], [`Expander`][struct@crate::Expander], [`FileChooserDialog`][struct@crate::FileChooserDialog], [`FileChooserWidget`][struct@crate::FileChooserWidget], [`Fixed`][struct@crate::Fixed], [`FlowBoxChild`][struct@crate::FlowBoxChild], [`FlowBox`][struct@crate::FlowBox], [`FontButton`][struct@crate::FontButton], [`FontChooserDialog`][struct@crate::FontChooserDialog], [`FontChooserWidget`][struct@crate::FontChooserWidget], [`FontDialogButton`][struct@crate::FontDialogButton], [`Frame`][struct@crate::Frame], [`GLArea`][struct@crate::GLArea], [`GraphicsOffload`][struct@crate::GraphicsOffload], [`GridView`][struct@crate::GridView], [`Grid`][struct@crate::Grid], [`HeaderBar`][struct@crate::HeaderBar], [`IconView`][struct@crate::IconView], [`Image`][struct@crate::Image], [`InfoBar`][struct@crate::InfoBar], [`Inscription`][struct@crate::Inscription], [`Label`][struct@crate::Label], [`LevelBar`][struct@crate::LevelBar], [`LinkButton`][struct@crate::LinkButton], [`ListBase`][struct@crate::ListBase], [`ListBoxRow`][struct@crate::ListBoxRow], [`ListBox`][struct@crate::ListBox], [`ListView`][struct@crate::ListView], [`LockButton`][struct@crate::LockButton], [`MediaControls`][struct@crate::MediaControls], [`MenuButton`][struct@crate::MenuButton], [`MessageDialog`][struct@crate::MessageDialog], [`Notebook`][struct@crate::Notebook], [`Overlay`][struct@crate::Overlay], [`PageSetupUnixDialog`][struct@crate::PageSetupUnixDialog], [`Paned`][struct@crate::Paned], [`PasswordEntry`][struct@crate::PasswordEntry], [`Picture`][struct@crate::Picture], [`PopoverBin`][struct@crate::PopoverBin], [`PopoverMenuBar`][struct@crate::PopoverMenuBar], [`PopoverMenu`][struct@crate::PopoverMenu], [`Popover`][struct@crate::Popover], [`PrintUnixDialog`][struct@crate::PrintUnixDialog], [`ProgressBar`][struct@crate::ProgressBar], [`Range`][struct@crate::Range], [`Revealer`][struct@crate::Revealer], [`ScaleButton`][struct@crate::ScaleButton], [`Scale`][struct@crate::Scale], [`Scrollbar`][struct@crate::Scrollbar], [`ScrolledWindow`][struct@crate::ScrolledWindow], [`SearchBar`][struct@crate::SearchBar], [`SearchEntry`][struct@crate::SearchEntry], [`Separator`][struct@crate::Separator], [`ShortcutLabel`][struct@crate::ShortcutLabel], [`ShortcutsGroup`][struct@crate::ShortcutsGroup], [`ShortcutsSection`][struct@crate::ShortcutsSection], [`ShortcutsShortcut`][struct@crate::ShortcutsShortcut], [`ShortcutsWindow`][struct@crate::ShortcutsWindow], [`SpinButton`][struct@crate::SpinButton], [`Spinner`][struct@crate::Spinner], [`StackPage`][struct@crate::StackPage], [`StackSidebar`][struct@crate::StackSidebar], [`StackSwitcher`][struct@crate::StackSwitcher], [`Stack`][struct@crate::Stack], [`Statusbar`][struct@crate::Statusbar], [`Switch`][struct@crate::Switch], [`TextView`][struct@crate::TextView], [`Text`][struct@crate::Text], [`ToggleButton`][struct@crate::ToggleButton], [`TreeExpander`][struct@crate::TreeExpander], [`TreeView`][struct@crate::TreeView], [`Video`][struct@crate::Video], [`Viewport`][struct@crate::Viewport], [`VolumeButton`][struct@crate::VolumeButton], [`Widget`][struct@crate::Widget], [`WindowControls`][struct@crate::WindowControls], [`WindowHandle`][struct@crate::WindowHandle], [`Window`][struct@crate::Window]
81pub trait AccessibleExt: IsA<Accessible> + 'static {
82    /// Requests the user's screen reader to announce the given message.
83    ///
84    /// This kind of notification is useful for messages that
85    /// either have only a visual representation or that are not
86    /// exposed visually at all, e.g. a notification about a
87    /// successful operation.
88    ///
89    /// Also, by using this API, you can ensure that the message
90    /// does not interrupts the user's current screen reader output.
91    /// ## `message`
92    /// the string to announce
93    /// ## `priority`
94    /// the priority of the announcement
95    #[cfg(feature = "v4_14")]
96    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
97    #[doc(alias = "gtk_accessible_announce")]
98    fn announce(&self, message: &str, priority: AccessibleAnnouncementPriority) {
99        unsafe {
100            ffi::gtk_accessible_announce(
101                self.as_ref().to_glib_none().0,
102                message.to_glib_none().0,
103                priority.into_glib(),
104            );
105        }
106    }
107
108    /// Retrieves the accessible identifier for the accessible object.
109    ///
110    /// This functionality can be overridden by [`Accessible`][crate::Accessible]
111    /// implementations.
112    ///
113    /// It is left to the accessible implementation to define the scope
114    /// and uniqueness of the identifier.
115    ///
116    /// # Returns
117    ///
118    /// the accessible identifier
119    #[cfg(feature = "v4_22")]
120    #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
121    #[doc(alias = "gtk_accessible_get_accessible_id")]
122    #[doc(alias = "get_accessible_id")]
123    fn accessible_id(&self) -> Option<glib::GString> {
124        unsafe {
125            from_glib_full(ffi::gtk_accessible_get_accessible_id(
126                self.as_ref().to_glib_none().0,
127            ))
128        }
129    }
130
131    /// Retrieves the accessible parent for an accessible object.
132    ///
133    /// This function returns `NULL` for top level widgets.
134    ///
135    /// # Returns
136    ///
137    /// the accessible parent
138    #[doc(alias = "gtk_accessible_get_accessible_parent")]
139    #[doc(alias = "get_accessible_parent")]
140    #[must_use]
141    fn accessible_parent(&self) -> Option<Accessible> {
142        unsafe {
143            from_glib_full(ffi::gtk_accessible_get_accessible_parent(
144                self.as_ref().to_glib_none().0,
145            ))
146        }
147    }
148
149    /// Retrieves the accessible role of an accessible object.
150    ///
151    /// # Returns
152    ///
153    /// the accessible role
154    #[doc(alias = "gtk_accessible_get_accessible_role")]
155    #[doc(alias = "get_accessible_role")]
156    #[doc(alias = "accessible-role")]
157    fn accessible_role(&self) -> AccessibleRole {
158        unsafe {
159            from_glib(ffi::gtk_accessible_get_accessible_role(
160                self.as_ref().to_glib_none().0,
161            ))
162        }
163    }
164
165    /// Retrieves the implementation for the given accessible object.
166    ///
167    /// # Returns
168    ///
169    /// the accessible implementation object
170    #[doc(alias = "gtk_accessible_get_at_context")]
171    #[doc(alias = "get_at_context")]
172    fn at_context(&self) -> ATContext {
173        unsafe {
174            from_glib_full(ffi::gtk_accessible_get_at_context(
175                self.as_ref().to_glib_none().0,
176            ))
177        }
178    }
179
180    /// Queries the coordinates and dimensions of this accessible
181    ///
182    /// This functionality can be overridden by [`Accessible`][crate::Accessible]
183    /// implementations, e.g. to get the bounds from an ignored
184    /// child widget.
185    ///
186    /// # Returns
187    ///
188    /// true if the bounds are valid, and false otherwise
189    ///
190    /// ## `x`
191    /// the x coordinate of the top left corner of the accessible
192    ///
193    /// ## `y`
194    /// the y coordinate of the top left corner of the widget
195    ///
196    /// ## `width`
197    /// the width of the accessible object
198    ///
199    /// ## `height`
200    /// the height of the accessible object
201    #[doc(alias = "gtk_accessible_get_bounds")]
202    #[doc(alias = "get_bounds")]
203    fn bounds(&self) -> Option<(i32, i32, i32, i32)> {
204        unsafe {
205            let mut x = std::mem::MaybeUninit::uninit();
206            let mut y = std::mem::MaybeUninit::uninit();
207            let mut width = std::mem::MaybeUninit::uninit();
208            let mut height = std::mem::MaybeUninit::uninit();
209            let ret = from_glib(ffi::gtk_accessible_get_bounds(
210                self.as_ref().to_glib_none().0,
211                x.as_mut_ptr(),
212                y.as_mut_ptr(),
213                width.as_mut_ptr(),
214                height.as_mut_ptr(),
215            ));
216            if ret {
217                Some((
218                    x.assume_init(),
219                    y.assume_init(),
220                    width.assume_init(),
221                    height.assume_init(),
222                ))
223            } else {
224                None
225            }
226        }
227    }
228
229    /// Retrieves the first accessible child of an accessible object.
230    ///
231    /// # Returns
232    ///
233    /// the first accessible child
234    #[doc(alias = "gtk_accessible_get_first_accessible_child")]
235    #[doc(alias = "get_first_accessible_child")]
236    #[must_use]
237    fn first_accessible_child(&self) -> Option<Accessible> {
238        unsafe {
239            from_glib_full(ffi::gtk_accessible_get_first_accessible_child(
240                self.as_ref().to_glib_none().0,
241            ))
242        }
243    }
244
245    /// Retrieves the next accessible sibling of an accessible object
246    ///
247    /// # Returns
248    ///
249    /// the next accessible sibling
250    #[doc(alias = "gtk_accessible_get_next_accessible_sibling")]
251    #[doc(alias = "get_next_accessible_sibling")]
252    #[must_use]
253    fn next_accessible_sibling(&self) -> Option<Accessible> {
254        unsafe {
255            from_glib_full(ffi::gtk_accessible_get_next_accessible_sibling(
256                self.as_ref().to_glib_none().0,
257            ))
258        }
259    }
260
261    /// Queries a platform state, such as focus.
262    ///
263    /// This functionality can be overridden by [`Accessible`][crate::Accessible]
264    /// implementations, e.g. to get platform state from an ignored
265    /// child widget, as is the case for [`Text`][crate::Text] wrappers.
266    /// ## `state`
267    /// platform state to query
268    ///
269    /// # Returns
270    ///
271    /// the value of state for the accessible
272    #[doc(alias = "gtk_accessible_get_platform_state")]
273    #[doc(alias = "get_platform_state")]
274    fn platform_state(&self, state: AccessiblePlatformState) -> bool {
275        unsafe {
276            from_glib(ffi::gtk_accessible_get_platform_state(
277                self.as_ref().to_glib_none().0,
278                state.into_glib(),
279            ))
280        }
281    }
282
283    /// Resets the accessible property to its default value.
284    /// ## `property`
285    /// the accessible property
286    #[doc(alias = "gtk_accessible_reset_property")]
287    fn reset_property(&self, property: AccessibleProperty) {
288        unsafe {
289            ffi::gtk_accessible_reset_property(
290                self.as_ref().to_glib_none().0,
291                property.into_glib(),
292            );
293        }
294    }
295
296    /// Resets the accessible relation to its default value.
297    /// ## `relation`
298    /// the accessible relation
299    #[doc(alias = "gtk_accessible_reset_relation")]
300    fn reset_relation(&self, relation: AccessibleRelation) {
301        unsafe {
302            ffi::gtk_accessible_reset_relation(
303                self.as_ref().to_glib_none().0,
304                relation.into_glib(),
305            );
306        }
307    }
308
309    /// Resets the accessible state to its default value.
310    /// ## `state`
311    /// the accessible state
312    #[doc(alias = "gtk_accessible_reset_state")]
313    fn reset_state(&self, state: AccessibleState) {
314        unsafe {
315            ffi::gtk_accessible_reset_state(self.as_ref().to_glib_none().0, state.into_glib());
316        }
317    }
318
319    /// Sets the parent and sibling of an accessible object.
320    ///
321    /// This function is meant to be used by accessible implementations that are
322    /// not part of the widget hierarchy, and but act as a logical bridge between
323    /// widgets. For instance, if a widget creates an object that holds metadata
324    /// for each child, and you want that object to implement the [`Accessible`][crate::Accessible]
325    /// interface, you will use this function to ensure that the parent of each
326    /// child widget is the metadata object, and the parent of each metadata
327    /// object is the container widget.
328    /// ## `parent`
329    /// the parent accessible object
330    /// ## `next_sibling`
331    /// the sibling accessible object
332    #[doc(alias = "gtk_accessible_set_accessible_parent")]
333    fn set_accessible_parent(
334        &self,
335        parent: Option<&impl IsA<Accessible>>,
336        next_sibling: Option<&impl IsA<Accessible>>,
337    ) {
338        unsafe {
339            ffi::gtk_accessible_set_accessible_parent(
340                self.as_ref().to_glib_none().0,
341                parent.map(|p| p.as_ref()).to_glib_none().0,
342                next_sibling.map(|p| p.as_ref()).to_glib_none().0,
343            );
344        }
345    }
346
347    /// Updates the next accessible sibling.
348    ///
349    /// That might be useful when a new child of a custom accessible
350    /// is created, and it needs to be linked to a previous child.
351    /// ## `new_sibling`
352    /// the new next accessible sibling to set
353    #[doc(alias = "gtk_accessible_update_next_accessible_sibling")]
354    fn update_next_accessible_sibling(&self, new_sibling: Option<&impl IsA<Accessible>>) {
355        unsafe {
356            ffi::gtk_accessible_update_next_accessible_sibling(
357                self.as_ref().to_glib_none().0,
358                new_sibling.map(|p| p.as_ref()).to_glib_none().0,
359            );
360        }
361    }
362
363    /// Informs ATs that the platform state has changed.
364    ///
365    /// This function should be used by [`Accessible`][crate::Accessible] implementations that
366    /// have a platform state but are not widgets. Widgets handle platform
367    /// states automatically.
368    /// ## `state`
369    /// the platform state to update
370    #[cfg(feature = "v4_18")]
371    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
372    #[doc(alias = "gtk_accessible_update_platform_state")]
373    fn update_platform_state(&self, state: AccessiblePlatformState) {
374        unsafe {
375            ffi::gtk_accessible_update_platform_state(
376                self.as_ref().to_glib_none().0,
377                state.into_glib(),
378            );
379        }
380    }
381
382    #[cfg(not(feature = "v4_10"))]
383    #[cfg_attr(docsrs, doc(cfg(not(feature = "v4_10"))))]
384    #[doc(alias = "accessible-role")]
385    fn accessible_role(&self) -> AccessibleRole {
386        ObjectExt::property(self.as_ref(), "accessible-role")
387    }
388
389    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
390    ///
391    /// The accessible role cannot be changed once set.
392    #[doc(alias = "accessible-role")]
393    fn set_accessible_role(&self, accessible_role: AccessibleRole) {
394        ObjectExt::set_property(self.as_ref(), "accessible-role", accessible_role)
395    }
396
397    #[doc(alias = "accessible-role")]
398    fn connect_accessible_role_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
399        unsafe extern "C" fn notify_accessible_role_trampoline<
400            P: IsA<Accessible>,
401            F: Fn(&P) + 'static,
402        >(
403            this: *mut ffi::GtkAccessible,
404            _param_spec: glib::ffi::gpointer,
405            f: glib::ffi::gpointer,
406        ) {
407            unsafe {
408                let f: &F = &*(f as *const F);
409                f(Accessible::from_glib_borrow(this).unsafe_cast_ref())
410            }
411        }
412        unsafe {
413            let f: Box_<F> = Box_::new(f);
414            connect_raw(
415                self.as_ptr() as *mut _,
416                c"notify::accessible-role".as_ptr(),
417                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
418                    notify_accessible_role_trampoline::<Self, F> as *const (),
419                )),
420                Box_::into_raw(f),
421            )
422        }
423    }
424}
425
426impl<O: IsA<Accessible>> AccessibleExt for O {}