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;
8#[cfg(feature = "v4_10")]
9#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
10use crate::{ATContext, AccessiblePlatformState};
11use crate::{AccessibleProperty, AccessibleRelation, AccessibleRole, AccessibleState, ffi};
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 | Writeable
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    #[cfg(feature = "v4_10")]
139    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
140    #[doc(alias = "gtk_accessible_get_accessible_parent")]
141    #[doc(alias = "get_accessible_parent")]
142    #[must_use]
143    fn accessible_parent(&self) -> Option<Accessible> {
144        unsafe {
145            from_glib_full(ffi::gtk_accessible_get_accessible_parent(
146                self.as_ref().to_glib_none().0,
147            ))
148        }
149    }
150
151    /// Retrieves the accessible role of an accessible object.
152    ///
153    /// # Returns
154    ///
155    /// the accessible role
156    #[doc(alias = "gtk_accessible_get_accessible_role")]
157    #[doc(alias = "get_accessible_role")]
158    #[doc(alias = "accessible-role")]
159    fn accessible_role(&self) -> AccessibleRole {
160        unsafe {
161            from_glib(ffi::gtk_accessible_get_accessible_role(
162                self.as_ref().to_glib_none().0,
163            ))
164        }
165    }
166
167    /// Retrieves the implementation for the given accessible object.
168    ///
169    /// # Returns
170    ///
171    /// the accessible implementation object
172    #[cfg(feature = "v4_10")]
173    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
174    #[doc(alias = "gtk_accessible_get_at_context")]
175    #[doc(alias = "get_at_context")]
176    fn at_context(&self) -> ATContext {
177        unsafe {
178            from_glib_full(ffi::gtk_accessible_get_at_context(
179                self.as_ref().to_glib_none().0,
180            ))
181        }
182    }
183
184    /// Queries the coordinates and dimensions of this accessible
185    ///
186    /// This functionality can be overridden by [`Accessible`][crate::Accessible]
187    /// implementations, e.g. to get the bounds from an ignored
188    /// child widget.
189    ///
190    /// # Returns
191    ///
192    /// true if the bounds are valid, and false otherwise
193    ///
194    /// ## `x`
195    /// the x coordinate of the top left corner of the accessible
196    ///
197    /// ## `y`
198    /// the y coordinate of the top left corner of the widget
199    ///
200    /// ## `width`
201    /// the width of the accessible object
202    ///
203    /// ## `height`
204    /// the height of the accessible object
205    #[cfg(feature = "v4_10")]
206    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
207    #[doc(alias = "gtk_accessible_get_bounds")]
208    #[doc(alias = "get_bounds")]
209    fn bounds(&self) -> Option<(i32, i32, i32, i32)> {
210        unsafe {
211            let mut x = std::mem::MaybeUninit::uninit();
212            let mut y = std::mem::MaybeUninit::uninit();
213            let mut width = std::mem::MaybeUninit::uninit();
214            let mut height = std::mem::MaybeUninit::uninit();
215            let ret = from_glib(ffi::gtk_accessible_get_bounds(
216                self.as_ref().to_glib_none().0,
217                x.as_mut_ptr(),
218                y.as_mut_ptr(),
219                width.as_mut_ptr(),
220                height.as_mut_ptr(),
221            ));
222            if ret {
223                Some((
224                    x.assume_init(),
225                    y.assume_init(),
226                    width.assume_init(),
227                    height.assume_init(),
228                ))
229            } else {
230                None
231            }
232        }
233    }
234
235    /// Retrieves the first accessible child of an accessible object.
236    ///
237    /// # Returns
238    ///
239    /// the first accessible child
240    #[cfg(feature = "v4_10")]
241    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
242    #[doc(alias = "gtk_accessible_get_first_accessible_child")]
243    #[doc(alias = "get_first_accessible_child")]
244    #[must_use]
245    fn first_accessible_child(&self) -> Option<Accessible> {
246        unsafe {
247            from_glib_full(ffi::gtk_accessible_get_first_accessible_child(
248                self.as_ref().to_glib_none().0,
249            ))
250        }
251    }
252
253    /// Retrieves the next accessible sibling of an accessible object
254    ///
255    /// # Returns
256    ///
257    /// the next accessible sibling
258    #[cfg(feature = "v4_10")]
259    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
260    #[doc(alias = "gtk_accessible_get_next_accessible_sibling")]
261    #[doc(alias = "get_next_accessible_sibling")]
262    #[must_use]
263    fn next_accessible_sibling(&self) -> Option<Accessible> {
264        unsafe {
265            from_glib_full(ffi::gtk_accessible_get_next_accessible_sibling(
266                self.as_ref().to_glib_none().0,
267            ))
268        }
269    }
270
271    /// Queries a platform state, such as focus.
272    ///
273    /// This functionality can be overridden by [`Accessible`][crate::Accessible]
274    /// implementations, e.g. to get platform state from an ignored
275    /// child widget, as is the case for [`Text`][crate::Text] wrappers.
276    /// ## `state`
277    /// platform state to query
278    ///
279    /// # Returns
280    ///
281    /// the value of state for the accessible
282    #[cfg(feature = "v4_10")]
283    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
284    #[doc(alias = "gtk_accessible_get_platform_state")]
285    #[doc(alias = "get_platform_state")]
286    fn platform_state(&self, state: AccessiblePlatformState) -> bool {
287        unsafe {
288            from_glib(ffi::gtk_accessible_get_platform_state(
289                self.as_ref().to_glib_none().0,
290                state.into_glib(),
291            ))
292        }
293    }
294
295    /// Resets the accessible property to its default value.
296    /// ## `property`
297    /// the accessible property
298    #[doc(alias = "gtk_accessible_reset_property")]
299    fn reset_property(&self, property: AccessibleProperty) {
300        unsafe {
301            ffi::gtk_accessible_reset_property(
302                self.as_ref().to_glib_none().0,
303                property.into_glib(),
304            );
305        }
306    }
307
308    /// Resets the accessible relation to its default value.
309    /// ## `relation`
310    /// the accessible relation
311    #[doc(alias = "gtk_accessible_reset_relation")]
312    fn reset_relation(&self, relation: AccessibleRelation) {
313        unsafe {
314            ffi::gtk_accessible_reset_relation(
315                self.as_ref().to_glib_none().0,
316                relation.into_glib(),
317            );
318        }
319    }
320
321    /// Resets the accessible state to its default value.
322    /// ## `state`
323    /// the accessible state
324    #[doc(alias = "gtk_accessible_reset_state")]
325    fn reset_state(&self, state: AccessibleState) {
326        unsafe {
327            ffi::gtk_accessible_reset_state(self.as_ref().to_glib_none().0, state.into_glib());
328        }
329    }
330
331    /// Sets the parent and sibling of an accessible object.
332    ///
333    /// This function is meant to be used by accessible implementations that are
334    /// not part of the widget hierarchy, and but act as a logical bridge between
335    /// widgets. For instance, if a widget creates an object that holds metadata
336    /// for each child, and you want that object to implement the [`Accessible`][crate::Accessible]
337    /// interface, you will use this function to ensure that the parent of each
338    /// child widget is the metadata object, and the parent of each metadata
339    /// object is the container widget.
340    /// ## `parent`
341    /// the parent accessible object
342    /// ## `next_sibling`
343    /// the sibling accessible object
344    #[cfg(feature = "v4_10")]
345    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
346    #[doc(alias = "gtk_accessible_set_accessible_parent")]
347    fn set_accessible_parent(
348        &self,
349        parent: Option<&impl IsA<Accessible>>,
350        next_sibling: Option<&impl IsA<Accessible>>,
351    ) {
352        unsafe {
353            ffi::gtk_accessible_set_accessible_parent(
354                self.as_ref().to_glib_none().0,
355                parent.map(|p| p.as_ref()).to_glib_none().0,
356                next_sibling.map(|p| p.as_ref()).to_glib_none().0,
357            );
358        }
359    }
360
361    /// Updates the next accessible sibling.
362    ///
363    /// That might be useful when a new child of a custom accessible
364    /// is created, and it needs to be linked to a previous child.
365    /// ## `new_sibling`
366    /// the new next accessible sibling to set
367    #[cfg(feature = "v4_10")]
368    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
369    #[doc(alias = "gtk_accessible_update_next_accessible_sibling")]
370    fn update_next_accessible_sibling(&self, new_sibling: Option<&impl IsA<Accessible>>) {
371        unsafe {
372            ffi::gtk_accessible_update_next_accessible_sibling(
373                self.as_ref().to_glib_none().0,
374                new_sibling.map(|p| p.as_ref()).to_glib_none().0,
375            );
376        }
377    }
378
379    /// Informs ATs that the platform state has changed.
380    ///
381    /// This function should be used by [`Accessible`][crate::Accessible] implementations that
382    /// have a platform state but are not widgets. Widgets handle platform
383    /// states automatically.
384    /// ## `state`
385    /// the platform state to update
386    #[cfg(feature = "v4_18")]
387    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
388    #[doc(alias = "gtk_accessible_update_platform_state")]
389    fn update_platform_state(&self, state: AccessiblePlatformState) {
390        unsafe {
391            ffi::gtk_accessible_update_platform_state(
392                self.as_ref().to_glib_none().0,
393                state.into_glib(),
394            );
395        }
396    }
397
398    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
399    ///
400    /// The accessible role cannot be changed once set.
401    #[doc(alias = "accessible-role")]
402    fn set_accessible_role(&self, accessible_role: AccessibleRole) {
403        ObjectExt::set_property(self.as_ref(), "accessible-role", accessible_role)
404    }
405
406    #[doc(alias = "accessible-role")]
407    fn connect_accessible_role_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
408        unsafe extern "C" fn notify_accessible_role_trampoline<
409            P: IsA<Accessible>,
410            F: Fn(&P) + 'static,
411        >(
412            this: *mut ffi::GtkAccessible,
413            _param_spec: glib::ffi::gpointer,
414            f: glib::ffi::gpointer,
415        ) {
416            unsafe {
417                let f: &F = &*(f as *const F);
418                f(Accessible::from_glib_borrow(this).unsafe_cast_ref())
419            }
420        }
421        unsafe {
422            let f: Box_<F> = Box_::new(f);
423            connect_raw(
424                self.as_ptr() as *mut _,
425                c"notify::accessible-role".as_ptr() as *const _,
426                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
427                    notify_accessible_role_trampoline::<Self, F> as *const (),
428                )),
429                Box_::into_raw(f),
430            )
431        }
432    }
433}
434
435impl<O: IsA<Accessible>> AccessibleExt for O {}