Skip to main content

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