1
/*
2
 * AT-SPI - Assistive Technology Service Provider Interface
3
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4
 *
5
 * Copyright 2001, 2002 Sun Microsystems Inc.,
6
 * Copyright 2001, 2002 Ximian, Inc.
7
 * Copyright 2010, 2011 Novell, Inc.
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 of the License, or (at your option) any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the
21
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
 * Boston, MA 02110-1301, USA.
23
 */
24

            
25
#include "atspi-private.h"
26

            
27
/**
28
 * AtspiSelection:
29
 *
30
 * An interface which indicates that an object exposes a 'selection' model,
31
 * allowing the selection of one or more of its children.
32
 *
33
 * An interface which indicates that an object exposes a 'selection'
34
 * model, allowing the selection of one or more of its children.
35
 * Read-only Selection instances are possible, in which case the
36
 * interface is used to programmatically determine the selected-ness
37
 * of its children.
38
 */
39

            
40
/**
41
 * atspi_selection_get_n_selected_children:
42
 * @obj: a pointer to the #AtspiSelection implementor on which to operate.
43
 *
44
 * Gets the number of children of an #AtspiSelection implementor which are
45
 *        currently selected.
46
 *
47
 * Returns: a #gint indicating the number of #Accessible children
48
 *        of the #AtspiSelection implementor which are currently selected.
49
 *
50
 **/
51
gint
52
14
atspi_selection_get_n_selected_children (AtspiSelection *obj, GError **error)
53
{
54
14
  dbus_int32_t retval = -1;
55

            
56
14
  g_return_val_if_fail (obj != NULL, -1);
57

            
58
14
  _atspi_dbus_get_property (obj, atspi_interface_selection, "NSelectedChildren", error, "i", &retval);
59

            
60
14
  return retval;
61
}
62

            
63
/**
64
 * atspi_selection_get_selected_child:
65
 * @obj: a pointer to the #AtspiSelection on which to operate.
66
 * @selected_child_index: a #gint indicating which of the selected
67
 *      children is specified.
68
 *
69
 * Gets the i-th selected #AtspiAccessible child of an #AtspiSelection.
70
 *      Note that @selected_child_index refers to the index in the list
71
 *      of 'selected'
72
 *      children and generally differs from that used in
73
 *      #atspi_accessible_get_child_at_index or returned by
74
 *      #atspi_accessible_get_index_in_parent.
75
 *      @selected_child_index must lie between 0
76
 *      and #atspi_selection_get_n_selected_children - 1, inclusive.
77
 *
78
 * Returns: (transfer full): a pointer to a selected #AtspiAccessible child
79
 *          object, specified by @selected_child_index.
80
 *
81
 **/
82
AtspiAccessible *
83
3
atspi_selection_get_selected_child (AtspiSelection *obj,
84
                                    gint selected_child_index,
85
                                    GError **error)
86
{
87
3
  dbus_int32_t d_selected_child_index = selected_child_index;
88
  DBusMessage *reply;
89

            
90
3
  g_return_val_if_fail (obj != NULL, NULL);
91

            
92
3
  reply = _atspi_dbus_call_partial (obj, atspi_interface_selection,
93
                                    "GetSelectedChild", error, "i",
94
                                    d_selected_child_index);
95

            
96
3
  return _atspi_dbus_return_accessible_from_message (reply);
97
}
98

            
99
/**
100
 * atspi_selection_select_child:
101
 * @obj: a pointer to the #AtspiSelection on which to operate.
102
 * @child_index: a #gint indicating which child of the #Accessible
103
 *              is to be selected.
104
 *
105
 * Adds a child to the selected children list of an #AtspiSelection.
106
 *         For #AtspiSelection implementors that only allow
107
 *         single selections, this may replace the (single) current
108
 *         selection.
109
 *
110
 * Returns: #TRUE if the child was successfully selected, #FALSE otherwise.
111
 **/
112
gboolean
113
6
atspi_selection_select_child (AtspiSelection *obj,
114
                              gint child_index,
115
                              GError **error)
116
{
117
6
  dbus_int32_t d_child_index = child_index;
118
6
  dbus_bool_t retval = FALSE;
119

            
120
6
  g_return_val_if_fail (obj != NULL, FALSE);
121

            
122
6
  _atspi_dbus_call (obj, atspi_interface_selection, "SelectChild", error, "i=>b", d_child_index, &retval);
123

            
124
6
  return retval;
125
}
126

            
127
/**
128
 * atspi_selection_deselect_selected_child:
129
 * @obj: a pointer to the #AtspiSelection on which to operate.
130
 * @selected_child_index: a #gint indicating which of the selected children
131
 *              of the #Accessible is to be selected.
132
 *
133
 * Removes a child from the selected children list of an #AtspiSelection.
134
 *          Note that @child_index is the index in the selected-children list,
135
 *          not the index in the parent container.  @selectedChildIndex in this
136
 *          method, and @child_index in #atspi_selection_select_child
137
 *          are asymmetric.
138
 *
139
 * Returns: #TRUE if the child was successfully deselected, #FALSE otherwise.
140
 **/
141
gboolean
142
1
atspi_selection_deselect_selected_child (AtspiSelection *obj,
143
                                         gint selected_child_index,
144
                                         GError **error)
145
{
146
1
  dbus_int32_t d_selected_child_index = selected_child_index;
147
1
  dbus_bool_t retval = FALSE;
148

            
149
1
  g_return_val_if_fail (obj != NULL, FALSE);
150

            
151
1
  _atspi_dbus_call (obj, atspi_interface_selection, "DeselectSelectedChild", error, "i=>b", d_selected_child_index, &retval);
152

            
153
1
  return retval;
154
}
155

            
156
/**
157
 * atspi_selection_deselect_child:
158
 * @obj: a pointer to the #AtspiSelection on which to operate.
159
 * @child_index: a #gint indicating which of the children
160
 *              of the #AtspiAccessible is to be de-selected.
161
 *
162
 * Deselects a specific child of an #AtspiSelection.
163
 *          Note that @child_index is the index of the child
164
 *          in the parent container.
165
 *
166
 * See #atspi_selection_deselect_selected_child
167
 *
168
 * Returns: #TRUE if the child was successfully deselected, #FALSE otherwise.
169
 **/
170
gboolean
171
1
atspi_selection_deselect_child (AtspiSelection *obj,
172
                                gint child_index,
173
                                GError **error)
174
{
175
1
  dbus_int32_t d_child_index = child_index;
176
1
  dbus_bool_t retval = FALSE;
177

            
178
1
  g_return_val_if_fail (obj != NULL, FALSE);
179

            
180
1
  _atspi_dbus_call (obj, atspi_interface_selection, "DeselectChild", error, "i=>b", d_child_index, &retval);
181

            
182
1
  return retval;
183
}
184

            
185
/**
186
 * atspi_selection_is_child_selected:
187
 * @obj: a pointer to the #AtspiSelection implementor on which to operate.
188
 * @child_index: an index into the #AtspiSelection's list of children.
189
 *
190
 * Determines whether a particular child of an #AtspiSelection implementor
191
 *        is currently selected.  Note that @child_index is the index into the
192
 *        standard #AtspiAccessible container's list of children.
193
 *
194
 * Returns: #TRUE if the specified child is currently selected,
195
 *          #FALSE otherwise.
196
 **/
197
gboolean
198
5
atspi_selection_is_child_selected (AtspiSelection *obj,
199
                                   gint child_index,
200
                                   GError **error)
201
{
202
5
  dbus_int32_t d_child_index = child_index;
203
5
  dbus_bool_t retval = FALSE;
204

            
205
5
  g_return_val_if_fail (obj != NULL, FALSE);
206

            
207
5
  _atspi_dbus_call (obj, atspi_interface_selection, "IsChildSelected", error, "i=>b", d_child_index, &retval);
208

            
209
5
  return retval;
210
}
211

            
212
/**
213
 * atspi_selection_select_all:
214
 * @obj: a pointer to the #AtspiSelection implementor on which to operate.
215
 *
216
 * Attempts to select all of the children of an #AtspiSelection implementor.
217
 * Not all #AtspiSelection implementors support this operation.
218
 *
219
 * Returns: #TRUE if successful, #FALSE otherwise.
220
 *
221
 **/
222
gboolean
223
1
atspi_selection_select_all (AtspiSelection *obj, GError **error)
224
{
225
1
  dbus_bool_t retval = FALSE;
226

            
227
1
  g_return_val_if_fail (obj != NULL, FALSE);
228

            
229
1
  _atspi_dbus_call (obj, atspi_interface_selection, "SelectAll", error, "=>b", &retval);
230

            
231
1
  return retval;
232
}
233

            
234
/**
235
 * atspi_selection_clear_selection:
236
 * @obj: a pointer to the #AtspiSelection implementor on which to operate.
237
 *
238
 * Clears the current selection, removing all selected children from the
239
 *       specified #AtspiSelection implementor's selection list.
240
 *
241
 * Returns: #TRUE if successful, #FALSE otherwise.
242
 *
243
 **/
244
gboolean
245
1
atspi_selection_clear_selection (AtspiSelection *obj, GError **error)
246
{
247
1
  dbus_bool_t retval = FALSE;
248

            
249
1
  g_return_val_if_fail (obj != NULL, FALSE);
250

            
251
1
  _atspi_dbus_call (obj, atspi_interface_selection, "ClearSelection", error, "=>b", &retval);
252

            
253
1
  return retval;
254
}
255

            
256
static void
257
4
atspi_selection_base_init (AtspiSelection *klass)
258
{
259
4
}
260

            
261
GType
262
11
atspi_selection_get_type (void)
263
{
264
  static GType type = 0;
265

            
266
11
  if (!type)
267
    {
268
      static const GTypeInfo tinfo = {
269
        sizeof (AtspiSelection),
270
        (GBaseInitFunc) atspi_selection_base_init,
271
        (GBaseFinalizeFunc) NULL,
272
      };
273

            
274
2
      type = g_type_register_static (G_TYPE_INTERFACE, "AtspiSelection", &tinfo, 0);
275
    }
276
11
  return type;
277
}