1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Object;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    /// [`Selection`][crate::Selection] should be implemented by UI components with children
    /// which are exposed by `atk_object_ref_child` and
    /// `atk_object_get_n_children`, if the use of the parent UI component
    /// ordinarily involves selection of one or more of the objects
    /// corresponding to those [`Object`][crate::Object] children - for example,
    /// selectable lists.
    ///
    /// Note that other types of "selection" (for instance text selection)
    /// are accomplished a other ATK interfaces - [`Selection`][crate::Selection] is limited
    /// to the selection/deselection of children.
    ///
    /// # Implements
    ///
    /// [`SelectionExt`][trait@crate::prelude::SelectionExt]
    #[doc(alias = "AtkSelection")]
    pub struct Selection(Interface<ffi::AtkSelection, ffi::AtkSelectionIface>);

    match fn {
        type_ => || ffi::atk_selection_get_type(),
    }
}

impl Selection {
    pub const NONE: Option<&'static Selection> = None;
}

/// Trait containing all [`struct@Selection`] methods.
///
/// # Implementors
///
/// [`NoOpObject`][struct@crate::NoOpObject], [`Selection`][struct@crate::Selection]
pub trait SelectionExt: 'static {
    /// Adds the specified accessible child of the object to the
    /// object's selection.
    /// ## `i`
    /// a `gint` specifying the child index.
    ///
    /// # Returns
    ///
    /// TRUE if success, FALSE otherwise.
    #[doc(alias = "atk_selection_add_selection")]
    fn add_selection(&self, i: i32) -> bool;

    /// Clears the selection in the object so that no children in the object
    /// are selected.
    ///
    /// # Returns
    ///
    /// TRUE if success, FALSE otherwise.
    #[doc(alias = "atk_selection_clear_selection")]
    fn clear_selection(&self) -> bool;

    /// Gets the number of accessible children currently selected.
    /// Note: callers should not rely on [`None`] or on a zero value for
    /// indication of whether AtkSelectionIface is implemented, they should
    /// use type checking/interface checking macros or the
    /// `atk_get_accessible_value()` convenience method.
    ///
    /// # Returns
    ///
    /// a gint representing the number of items selected, or 0
    /// if `self` does not implement this interface.
    #[doc(alias = "atk_selection_get_selection_count")]
    #[doc(alias = "get_selection_count")]
    fn selection_count(&self) -> i32;

    /// Determines if the current child of this object is selected
    /// Note: callers should not rely on [`None`] or on a zero value for
    /// indication of whether AtkSelectionIface is implemented, they should
    /// use type checking/interface checking macros or the
    /// `atk_get_accessible_value()` convenience method.
    /// ## `i`
    /// a `gint` specifying the child index.
    ///
    /// # Returns
    ///
    /// a gboolean representing the specified child is selected, or 0
    /// if `self` does not implement this interface.
    #[doc(alias = "atk_selection_is_child_selected")]
    fn is_child_selected(&self, i: i32) -> bool;

    /// Gets a reference to the accessible object representing the specified
    /// selected child of the object.
    /// Note: callers should not rely on [`None`] or on a zero value for
    /// indication of whether AtkSelectionIface is implemented, they should
    /// use type checking/interface checking macros or the
    /// `atk_get_accessible_value()` convenience method.
    /// ## `i`
    /// a `gint` specifying the index in the selection set. (e.g. the
    /// ith selection as opposed to the ith child).
    ///
    /// # Returns
    ///
    /// an [`Object`][crate::Object] representing the
    /// selected accessible, or [`None`] if `self` does not implement this
    /// interface.
    #[doc(alias = "atk_selection_ref_selection")]
    fn ref_selection(&self, i: i32) -> Option<Object>;

    /// Removes the specified child of the object from the object's selection.
    /// ## `i`
    /// a `gint` specifying the index in the selection set. (e.g. the
    /// ith selection as opposed to the ith child).
    ///
    /// # Returns
    ///
    /// TRUE if success, FALSE otherwise.
    #[doc(alias = "atk_selection_remove_selection")]
    fn remove_selection(&self, i: i32) -> bool;

    /// Causes every child of the object to be selected if the object
    /// supports multiple selections.
    ///
    /// # Returns
    ///
    /// TRUE if success, FALSE otherwise.
    #[doc(alias = "atk_selection_select_all_selection")]
    fn select_all_selection(&self) -> bool;

    /// The "selection-changed" signal is emitted by an object which
    /// implements AtkSelection interface when the selection changes.
    #[doc(alias = "selection-changed")]
    fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Selection>> SelectionExt for O {
    fn add_selection(&self, i: i32) -> bool {
        unsafe {
            from_glib(ffi::atk_selection_add_selection(
                self.as_ref().to_glib_none().0,
                i,
            ))
        }
    }

    fn clear_selection(&self) -> bool {
        unsafe {
            from_glib(ffi::atk_selection_clear_selection(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn selection_count(&self) -> i32 {
        unsafe { ffi::atk_selection_get_selection_count(self.as_ref().to_glib_none().0) }
    }

    fn is_child_selected(&self, i: i32) -> bool {
        unsafe {
            from_glib(ffi::atk_selection_is_child_selected(
                self.as_ref().to_glib_none().0,
                i,
            ))
        }
    }

    fn ref_selection(&self, i: i32) -> Option<Object> {
        unsafe {
            from_glib_full(ffi::atk_selection_ref_selection(
                self.as_ref().to_glib_none().0,
                i,
            ))
        }
    }

    fn remove_selection(&self, i: i32) -> bool {
        unsafe {
            from_glib(ffi::atk_selection_remove_selection(
                self.as_ref().to_glib_none().0,
                i,
            ))
        }
    }

    fn select_all_selection(&self) -> bool {
        unsafe {
            from_glib(ffi::atk_selection_select_all_selection(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn selection_changed_trampoline<
            P: IsA<Selection>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::AtkSelection,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Selection::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"selection-changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    selection_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for Selection {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Selection")
    }
}