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