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::{ffi, AccessibleProperty, AccessibleRelation, AccessibleRole, AccessibleState};
9#[cfg(feature = "v4_10")]
10#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
11use crate::{ATContext, AccessiblePlatformState};
12use glib::{
13    prelude::*,
14    signal::{connect_raw, SignalHandlerId},
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    ///  - an “attribute”, 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    /// Note that you can not create a top-level accessible object as of now,
42    /// which means that you must always have a parent accessible object.
43    /// Also note that when an accessible object does not correspond to a widget,
44    /// and it has children, whose implementation you don't control,
45    /// it is necessary to ensure the correct shape of the a11y tree
46    /// by calling [`AccessibleExt::set_accessible_parent()`][crate::prelude::AccessibleExt::set_accessible_parent()] and
47    /// updating the sibling by [`AccessibleExt::update_next_accessible_sibling()`][crate::prelude::AccessibleExt::update_next_accessible_sibling()].
48    ///
49    /// ## Properties
50    ///
51    ///
52    /// #### `accessible-role`
53    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
54    ///
55    /// The accessible role cannot be changed once set.
56    ///
57    /// Readable | Writeable
58    ///
59    /// # Implements
60    ///
61    /// [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
62    #[doc(alias = "GtkAccessible")]
63    pub struct Accessible(Interface<ffi::GtkAccessible, ffi::GtkAccessibleInterface>);
64
65    match fn {
66        type_ => || ffi::gtk_accessible_get_type(),
67    }
68}
69
70impl Accessible {
71    pub const NONE: Option<&'static Accessible> = None;
72}
73
74mod sealed {
75    pub trait Sealed {}
76    impl<T: super::IsA<super::Accessible>> Sealed for T {}
77}
78
79/// Trait containing all [`struct@Accessible`] methods.
80///
81/// # Implementors
82///
83/// [`AboutDialog`][struct@crate::AboutDialog], [`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], [`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]
84pub trait AccessibleExt: IsA<Accessible> + sealed::Sealed + 'static {
85    /// Requests the user's screen reader to announce the given message.
86    ///
87    /// This kind of notification is useful for messages that
88    /// either have only a visual representation or that are not
89    /// exposed visually at all, e.g. a notification about a
90    /// successful operation.
91    ///
92    /// Also, by using this API, you can ensure that the message
93    /// does not interrupts the user's current screen reader output.
94    /// ## `message`
95    /// the string to announce
96    /// ## `priority`
97    /// the priority of the announcement
98    #[cfg(feature = "v4_14")]
99    #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
100    #[doc(alias = "gtk_accessible_announce")]
101    fn announce(&self, message: &str, priority: AccessibleAnnouncementPriority) {
102        unsafe {
103            ffi::gtk_accessible_announce(
104                self.as_ref().to_glib_none().0,
105                message.to_glib_none().0,
106                priority.into_glib(),
107            );
108        }
109    }
110
111    /// Retrieves the accessible parent for an accessible object.
112    ///
113    /// This function returns `NULL` for top level widgets.
114    ///
115    /// # Returns
116    ///
117    /// the accessible parent
118    #[cfg(feature = "v4_10")]
119    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
120    #[doc(alias = "gtk_accessible_get_accessible_parent")]
121    #[doc(alias = "get_accessible_parent")]
122    #[must_use]
123    fn accessible_parent(&self) -> Option<Accessible> {
124        unsafe {
125            from_glib_full(ffi::gtk_accessible_get_accessible_parent(
126                self.as_ref().to_glib_none().0,
127            ))
128        }
129    }
130
131    /// Retrieves the accessible role of an accessible object.
132    ///
133    /// # Returns
134    ///
135    /// the accessible role
136    #[doc(alias = "gtk_accessible_get_accessible_role")]
137    #[doc(alias = "get_accessible_role")]
138    #[doc(alias = "accessible-role")]
139    fn accessible_role(&self) -> AccessibleRole {
140        unsafe {
141            from_glib(ffi::gtk_accessible_get_accessible_role(
142                self.as_ref().to_glib_none().0,
143            ))
144        }
145    }
146
147    /// Retrieves the implementation for the given accessible object.
148    ///
149    /// # Returns
150    ///
151    /// the accessible implementation object
152    #[cfg(feature = "v4_10")]
153    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
154    #[doc(alias = "gtk_accessible_get_at_context")]
155    #[doc(alias = "get_at_context")]
156    fn at_context(&self) -> ATContext {
157        unsafe {
158            from_glib_full(ffi::gtk_accessible_get_at_context(
159                self.as_ref().to_glib_none().0,
160            ))
161        }
162    }
163
164    /// Queries the coordinates and dimensions of this accessible
165    ///
166    /// This functionality can be overridden by [`Accessible`][crate::Accessible]
167    /// implementations, e.g. to get the bounds from an ignored
168    /// child widget.
169    ///
170    /// # Returns
171    ///
172    /// true if the bounds are valid, and false otherwise
173    ///
174    /// ## `x`
175    /// the x coordinate of the top left corner of the accessible
176    ///
177    /// ## `y`
178    /// the y coordinate of the top left corner of the widget
179    ///
180    /// ## `width`
181    /// the width of the accessible object
182    ///
183    /// ## `height`
184    /// the height of the accessible object
185    #[cfg(feature = "v4_10")]
186    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
187    #[doc(alias = "gtk_accessible_get_bounds")]
188    #[doc(alias = "get_bounds")]
189    fn bounds(&self) -> Option<(i32, i32, i32, i32)> {
190        unsafe {
191            let mut x = std::mem::MaybeUninit::uninit();
192            let mut y = std::mem::MaybeUninit::uninit();
193            let mut width = std::mem::MaybeUninit::uninit();
194            let mut height = std::mem::MaybeUninit::uninit();
195            let ret = from_glib(ffi::gtk_accessible_get_bounds(
196                self.as_ref().to_glib_none().0,
197                x.as_mut_ptr(),
198                y.as_mut_ptr(),
199                width.as_mut_ptr(),
200                height.as_mut_ptr(),
201            ));
202            if ret {
203                Some((
204                    x.assume_init(),
205                    y.assume_init(),
206                    width.assume_init(),
207                    height.assume_init(),
208                ))
209            } else {
210                None
211            }
212        }
213    }
214
215    /// Retrieves the first accessible child of an accessible object.
216    ///
217    /// # Returns
218    ///
219    /// the first accessible child
220    #[cfg(feature = "v4_10")]
221    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
222    #[doc(alias = "gtk_accessible_get_first_accessible_child")]
223    #[doc(alias = "get_first_accessible_child")]
224    #[must_use]
225    fn first_accessible_child(&self) -> Option<Accessible> {
226        unsafe {
227            from_glib_full(ffi::gtk_accessible_get_first_accessible_child(
228                self.as_ref().to_glib_none().0,
229            ))
230        }
231    }
232
233    /// Retrieves the next accessible sibling of an accessible object
234    ///
235    /// # Returns
236    ///
237    /// the next accessible sibling
238    #[cfg(feature = "v4_10")]
239    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
240    #[doc(alias = "gtk_accessible_get_next_accessible_sibling")]
241    #[doc(alias = "get_next_accessible_sibling")]
242    #[must_use]
243    fn next_accessible_sibling(&self) -> Option<Accessible> {
244        unsafe {
245            from_glib_full(ffi::gtk_accessible_get_next_accessible_sibling(
246                self.as_ref().to_glib_none().0,
247            ))
248        }
249    }
250
251    /// Queries a platform state, such as focus.
252    ///
253    /// This functionality can be overridden by [`Accessible`][crate::Accessible]
254    /// implementations, e.g. to get platform state from an ignored
255    /// child widget, as is the case for [`Text`][crate::Text] wrappers.
256    /// ## `state`
257    /// platform state to query
258    ///
259    /// # Returns
260    ///
261    /// the value of state for the accessible
262    #[cfg(feature = "v4_10")]
263    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
264    #[doc(alias = "gtk_accessible_get_platform_state")]
265    #[doc(alias = "get_platform_state")]
266    fn platform_state(&self, state: AccessiblePlatformState) -> bool {
267        unsafe {
268            from_glib(ffi::gtk_accessible_get_platform_state(
269                self.as_ref().to_glib_none().0,
270                state.into_glib(),
271            ))
272        }
273    }
274
275    /// Resets the accessible property to its default value.
276    /// ## `property`
277    /// the accessible property
278    #[doc(alias = "gtk_accessible_reset_property")]
279    fn reset_property(&self, property: AccessibleProperty) {
280        unsafe {
281            ffi::gtk_accessible_reset_property(
282                self.as_ref().to_glib_none().0,
283                property.into_glib(),
284            );
285        }
286    }
287
288    /// Resets the accessible relation to its default value.
289    /// ## `relation`
290    /// the accessible relation
291    #[doc(alias = "gtk_accessible_reset_relation")]
292    fn reset_relation(&self, relation: AccessibleRelation) {
293        unsafe {
294            ffi::gtk_accessible_reset_relation(
295                self.as_ref().to_glib_none().0,
296                relation.into_glib(),
297            );
298        }
299    }
300
301    /// Resets the accessible state to its default value.
302    /// ## `state`
303    /// the accessible state
304    #[doc(alias = "gtk_accessible_reset_state")]
305    fn reset_state(&self, state: AccessibleState) {
306        unsafe {
307            ffi::gtk_accessible_reset_state(self.as_ref().to_glib_none().0, state.into_glib());
308        }
309    }
310
311    /// Sets the parent and sibling of an accessible object.
312    ///
313    /// This function is meant to be used by accessible implementations that are
314    /// not part of the widget hierarchy, and but act as a logical bridge between
315    /// widgets. For instance, if a widget creates an object that holds metadata
316    /// for each child, and you want that object to implement the [`Accessible`][crate::Accessible]
317    /// interface, you will use this function to ensure that the parent of each
318    /// child widget is the metadata object, and the parent of each metadata
319    /// object is the container widget.
320    /// ## `parent`
321    /// the parent accessible object
322    /// ## `next_sibling`
323    /// the sibling accessible object
324    #[cfg(feature = "v4_10")]
325    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
326    #[doc(alias = "gtk_accessible_set_accessible_parent")]
327    fn set_accessible_parent(
328        &self,
329        parent: Option<&impl IsA<Accessible>>,
330        next_sibling: Option<&impl IsA<Accessible>>,
331    ) {
332        unsafe {
333            ffi::gtk_accessible_set_accessible_parent(
334                self.as_ref().to_glib_none().0,
335                parent.map(|p| p.as_ref()).to_glib_none().0,
336                next_sibling.map(|p| p.as_ref()).to_glib_none().0,
337            );
338        }
339    }
340
341    /// Updates the next accessible sibling.
342    ///
343    /// That might be useful when a new child of a custom accessible
344    /// is created, and it needs to be linked to a previous child.
345    /// ## `new_sibling`
346    /// the new next accessible sibling to set
347    #[cfg(feature = "v4_10")]
348    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
349    #[doc(alias = "gtk_accessible_update_next_accessible_sibling")]
350    fn update_next_accessible_sibling(&self, new_sibling: Option<&impl IsA<Accessible>>) {
351        unsafe {
352            ffi::gtk_accessible_update_next_accessible_sibling(
353                self.as_ref().to_glib_none().0,
354                new_sibling.map(|p| p.as_ref()).to_glib_none().0,
355            );
356        }
357    }
358
359    /// Informs ATs that the platform state has changed.
360    ///
361    /// This function should be used by [`Accessible`][crate::Accessible] implementations that
362    /// have a platform state but are not widgets. Widgets handle platform
363    /// states automatically.
364    /// ## `state`
365    /// the platform state to update
366    #[cfg(feature = "v4_18")]
367    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
368    #[doc(alias = "gtk_accessible_update_platform_state")]
369    fn update_platform_state(&self, state: AccessiblePlatformState) {
370        unsafe {
371            ffi::gtk_accessible_update_platform_state(
372                self.as_ref().to_glib_none().0,
373                state.into_glib(),
374            );
375        }
376    }
377
378    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
379    ///
380    /// The accessible role cannot be changed once set.
381    #[doc(alias = "accessible-role")]
382    fn set_accessible_role(&self, accessible_role: AccessibleRole) {
383        ObjectExt::set_property(self.as_ref(), "accessible-role", accessible_role)
384    }
385
386    #[doc(alias = "accessible-role")]
387    fn connect_accessible_role_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
388        unsafe extern "C" fn notify_accessible_role_trampoline<
389            P: IsA<Accessible>,
390            F: Fn(&P) + 'static,
391        >(
392            this: *mut ffi::GtkAccessible,
393            _param_spec: glib::ffi::gpointer,
394            f: glib::ffi::gpointer,
395        ) {
396            let f: &F = &*(f as *const F);
397            f(Accessible::from_glib_borrow(this).unsafe_cast_ref())
398        }
399        unsafe {
400            let f: Box_<F> = Box_::new(f);
401            connect_raw(
402                self.as_ptr() as *mut _,
403                b"notify::accessible-role\0".as_ptr() as *const _,
404                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
405                    notify_accessible_role_trampoline::<Self, F> as *const (),
406                )),
407                Box_::into_raw(f),
408            )
409        }
410    }
411}
412
413impl<O: IsA<Accessible>> AccessibleExt for O {}