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