atk/auto/selection.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
5use crate::{Object, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// The ATK interface implemented by container objects whose [`Object`][crate::Object] children can be selected.
16 ///
17 /// [`Selection`][crate::Selection] should be implemented by UI components with children
18 /// which are exposed by `atk_object_ref_child` and
19 /// `atk_object_get_n_children`, if the use of the parent UI component
20 /// ordinarily involves selection of one or more of the objects
21 /// corresponding to those [`Object`][crate::Object] children - for example,
22 /// selectable lists.
23 ///
24 /// Note that other types of "selection" (for instance text selection)
25 /// are accomplished a other ATK interfaces - [`Selection`][crate::Selection] is limited
26 /// to the selection/deselection of children.
27 ///
28 /// ## Signals
29 ///
30 ///
31 /// #### `selection-changed`
32 /// The "selection-changed" signal is emitted by an object which
33 /// implements AtkSelection interface when the selection changes.
34 ///
35 ///
36 ///
37 /// # Implements
38 ///
39 /// [`SelectionExt`][trait@crate::prelude::SelectionExt]
40 #[doc(alias = "AtkSelection")]
41 pub struct Selection(Interface<ffi::AtkSelection, ffi::AtkSelectionIface>);
42
43 match fn {
44 type_ => || ffi::atk_selection_get_type(),
45 }
46}
47
48impl Selection {
49 pub const NONE: Option<&'static Selection> = None;
50}
51
52/// Trait containing all [`struct@Selection`] methods.
53///
54/// # Implementors
55///
56/// [`NoOpObject`][struct@crate::NoOpObject], [`Selection`][struct@crate::Selection]
57pub trait SelectionExt: IsA<Selection> + 'static {
58 /// Adds the specified accessible child of the object to the
59 /// object's selection.
60 /// ## `i`
61 /// a `gint` specifying the child index.
62 ///
63 /// # Returns
64 ///
65 /// TRUE if success, FALSE otherwise.
66 #[doc(alias = "atk_selection_add_selection")]
67 fn add_selection(&self, i: i32) -> bool {
68 unsafe {
69 from_glib(ffi::atk_selection_add_selection(
70 self.as_ref().to_glib_none().0,
71 i,
72 ))
73 }
74 }
75
76 /// Clears the selection in the object so that no children in the object
77 /// are selected.
78 ///
79 /// # Returns
80 ///
81 /// TRUE if success, FALSE otherwise.
82 #[doc(alias = "atk_selection_clear_selection")]
83 fn clear_selection(&self) -> bool {
84 unsafe {
85 from_glib(ffi::atk_selection_clear_selection(
86 self.as_ref().to_glib_none().0,
87 ))
88 }
89 }
90
91 /// Gets the number of accessible children currently selected.
92 /// Note: callers should not rely on [`None`] or on a zero value for
93 /// indication of whether AtkSelectionIface is implemented, they should
94 /// use type checking/interface checking macros or the
95 /// `atk_get_accessible_value()` convenience method.
96 ///
97 /// # Returns
98 ///
99 /// a gint representing the number of items selected, or 0
100 /// if `self` does not implement this interface.
101 #[doc(alias = "atk_selection_get_selection_count")]
102 #[doc(alias = "get_selection_count")]
103 fn selection_count(&self) -> i32 {
104 unsafe { ffi::atk_selection_get_selection_count(self.as_ref().to_glib_none().0) }
105 }
106
107 /// Determines if the current child of this object is selected
108 /// Note: callers should not rely on [`None`] or on a zero value for
109 /// indication of whether AtkSelectionIface is implemented, they should
110 /// use type checking/interface checking macros or the
111 /// `atk_get_accessible_value()` convenience method.
112 /// ## `i`
113 /// a `gint` specifying the child index.
114 ///
115 /// # Returns
116 ///
117 /// a gboolean representing the specified child is selected, or 0
118 /// if `self` does not implement this interface.
119 #[doc(alias = "atk_selection_is_child_selected")]
120 fn is_child_selected(&self, i: i32) -> bool {
121 unsafe {
122 from_glib(ffi::atk_selection_is_child_selected(
123 self.as_ref().to_glib_none().0,
124 i,
125 ))
126 }
127 }
128
129 /// Gets a reference to the accessible object representing the specified
130 /// selected child of the object.
131 /// Note: callers should not rely on [`None`] or on a zero value for
132 /// indication of whether AtkSelectionIface is implemented, they should
133 /// use type checking/interface checking macros or the
134 /// `atk_get_accessible_value()` convenience method.
135 /// ## `i`
136 /// a `gint` specifying the index in the selection set. (e.g. the
137 /// ith selection as opposed to the ith child).
138 ///
139 /// # Returns
140 ///
141 /// an [`Object`][crate::Object] representing the
142 /// selected accessible, or [`None`] if `self` does not implement this
143 /// interface.
144 #[doc(alias = "atk_selection_ref_selection")]
145 fn ref_selection(&self, i: i32) -> Option<Object> {
146 unsafe {
147 from_glib_full(ffi::atk_selection_ref_selection(
148 self.as_ref().to_glib_none().0,
149 i,
150 ))
151 }
152 }
153
154 /// Removes the specified child of the object from the object's selection.
155 /// ## `i`
156 /// a `gint` specifying the index in the selection set. (e.g. the
157 /// ith selection as opposed to the ith child).
158 ///
159 /// # Returns
160 ///
161 /// TRUE if success, FALSE otherwise.
162 #[doc(alias = "atk_selection_remove_selection")]
163 fn remove_selection(&self, i: i32) -> bool {
164 unsafe {
165 from_glib(ffi::atk_selection_remove_selection(
166 self.as_ref().to_glib_none().0,
167 i,
168 ))
169 }
170 }
171
172 /// Causes every child of the object to be selected if the object
173 /// supports multiple selections.
174 ///
175 /// # Returns
176 ///
177 /// TRUE if success, FALSE otherwise.
178 #[doc(alias = "atk_selection_select_all_selection")]
179 fn select_all_selection(&self) -> bool {
180 unsafe {
181 from_glib(ffi::atk_selection_select_all_selection(
182 self.as_ref().to_glib_none().0,
183 ))
184 }
185 }
186
187 /// The "selection-changed" signal is emitted by an object which
188 /// implements AtkSelection interface when the selection changes.
189 #[doc(alias = "selection-changed")]
190 fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
191 unsafe extern "C" fn selection_changed_trampoline<
192 P: IsA<Selection>,
193 F: Fn(&P) + 'static,
194 >(
195 this: *mut ffi::AtkSelection,
196 f: glib::ffi::gpointer,
197 ) {
198 unsafe {
199 let f: &F = &*(f as *const F);
200 f(Selection::from_glib_borrow(this).unsafe_cast_ref())
201 }
202 }
203 unsafe {
204 let f: Box_<F> = Box_::new(f);
205 connect_raw(
206 self.as_ptr() as *mut _,
207 c"selection-changed".as_ptr(),
208 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
209 selection_changed_trampoline::<Self, F> as *const (),
210 )),
211 Box_::into_raw(f),
212 )
213 }
214 }
215}
216
217impl<O: IsA<Selection>> SelectionExt for O {}