summaryrefslogtreecommitdiff
path: root/atspi/atspi-selection.c
blob: 0c74783598dcb0b6e0b19332c01ebe9bb0de0653 (plain)
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
 * AT-SPI - Assistive Technology Service Provider Interface
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
 *
 * Copyright 2001, 2002 Sun Microsystems Inc.,
 * Copyright 2001, 2002 Ximian, Inc.
 * Copyright 2010, 2011 Novell, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "atspi-private.h"

/**
 * AtspiSelection:
 *
 * An interface which indicates that an object exposes a 'selection' model,
 * allowing the selection of one or more of its children.
 *
 * An interface which indicates that an object exposes a 'selection'
 * model, allowing the selection of one or more of its children.
 * Read-only Selection instances are possible, in which case the
 * interface is used to programmatically determine the selected-ness
 * of its children.
 */

/**
 * atspi_selection_get_n_selected_children:
 * @obj: a pointer to the #AtspiSelection implementor on which to operate.
 *
 * Gets the number of children of an #AtspiSelection implementor which are
 *        currently selected.
 *
 * Returns: a #gint indicating the number of #Accessible children
 *        of the #AtspiSelection implementor which are currently selected.
 *
 **/
gint
atspi_selection_get_n_selected_children (AtspiSelection *obj, GError **error)
{
  dbus_int32_t retval = -1;

  g_return_val_if_fail (obj != NULL, -1);

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

  return retval;
}

/**
 * atspi_selection_get_selected_child:
 * @obj: a pointer to the #AtspiSelection on which to operate.
 * @selected_child_index: a #gint indicating which of the selected
 *      children is specified.
 *
 * Gets the i-th selected #AtspiAccessible child of an #AtspiSelection.
 *      Note that @selected_child_index refers to the index in the list
 *      of 'selected'
 *      children and generally differs from that used in
 *      #atspi_accessible_get_child_at_index or returned by
 *      #atspi_accessible_get_index_in_parent.
 *      @selected_child_index must lie between 0
 *      and #atspi_selection_get_n_selected_children - 1, inclusive.
 *
 * Returns: (transfer full): a pointer to a selected #AtspiAccessible child
 *          object, specified by @selected_child_index.
 *
 **/
AtspiAccessible *
atspi_selection_get_selected_child (AtspiSelection *obj,
                                    gint selected_child_index,
                                    GError **error)
{
  dbus_int32_t d_selected_child_index = selected_child_index;
  DBusMessage *reply;

  g_return_val_if_fail (obj != NULL, NULL);

  reply = _atspi_dbus_call_partial (obj, atspi_interface_selection,
                                    "GetSelectedChild", error, "i",
                                    d_selected_child_index);

  return _atspi_dbus_return_accessible_from_message (reply);
}

/**
 * atspi_selection_select_child:
 * @obj: a pointer to the #AtspiSelection on which to operate.
 * @child_index: a #gint indicating which child of the #Accessible
 *              is to be selected.
 *
 * Adds a child to the selected children list of an #AtspiSelection.
 *         For #AtspiSelection implementors that only allow
 *         single selections, this may replace the (single) current
 *         selection.
 *
 * Returns: #TRUE if the child was successfully selected, #FALSE otherwise.
 **/
gboolean
atspi_selection_select_child (AtspiSelection *obj,
                              gint child_index,
                              GError **error)
{
  dbus_int32_t d_child_index = child_index;
  dbus_bool_t retval = FALSE;

  g_return_val_if_fail (obj != NULL, FALSE);

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

  return retval;
}

/**
 * atspi_selection_deselect_selected_child:
 * @obj: a pointer to the #AtspiSelection on which to operate.
 * @selected_child_index: a #gint indicating which of the selected children
 *              of the #Accessible is to be selected.
 *
 * Removes a child from the selected children list of an #AtspiSelection.
 *          Note that @child_index is the index in the selected-children list,
 *          not the index in the parent container.  @selectedChildIndex in this
 *          method, and @child_index in #atspi_selection_select_child
 *          are asymmetric.
 *
 * Returns: #TRUE if the child was successfully deselected, #FALSE otherwise.
 **/
gboolean
atspi_selection_deselect_selected_child (AtspiSelection *obj,
                                         gint selected_child_index,
                                         GError **error)
{
  dbus_int32_t d_selected_child_index = selected_child_index;
  dbus_bool_t retval = FALSE;

  g_return_val_if_fail (obj != NULL, FALSE);

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

  return retval;
}

/**
 * atspi_selection_deselect_child:
 * @obj: a pointer to the #AtspiSelection on which to operate.
 * @child_index: a #gint indicating which of the children
 *              of the #AtspiAccessible is to be de-selected.
 *
 * Deselects a specific child of an #AtspiSelection.
 *          Note that @child_index is the index of the child
 *          in the parent container.
 *
 * See #atspi_selection_deselect_selected_child
 *
 * Returns: #TRUE if the child was successfully deselected, #FALSE otherwise.
 **/
gboolean
atspi_selection_deselect_child (AtspiSelection *obj,
                                gint child_index,
                                GError **error)
{
  dbus_int32_t d_child_index = child_index;
  dbus_bool_t retval = FALSE;

  g_return_val_if_fail (obj != NULL, FALSE);

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

  return retval;
}

/**
 * atspi_selection_is_child_selected:
 * @obj: a pointer to the #AtspiSelection implementor on which to operate.
 * @child_index: an index into the #AtspiSelection's list of children.
 *
 * Determines whether a particular child of an #AtspiSelection implementor
 *        is currently selected.  Note that @child_index is the index into the
 *        standard #AtspiAccessible container's list of children.
 *
 * Returns: #TRUE if the specified child is currently selected,
 *          #FALSE otherwise.
 **/
gboolean
atspi_selection_is_child_selected (AtspiSelection *obj,
                                   gint child_index,
                                   GError **error)
{
  dbus_int32_t d_child_index = child_index;
  dbus_bool_t retval = FALSE;

  g_return_val_if_fail (obj != NULL, FALSE);

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

  return retval;
}

/**
 * atspi_selection_select_all:
 * @obj: a pointer to the #AtspiSelection implementor on which to operate.
 *
 * Attempts to select all of the children of an #AtspiSelection implementor.
 * Not all #AtspiSelection implementors support this operation.
 *
 * Returns: #TRUE if successful, #FALSE otherwise.
 *
 **/
gboolean
atspi_selection_select_all (AtspiSelection *obj, GError **error)
{
  dbus_bool_t retval = FALSE;

  g_return_val_if_fail (obj != NULL, FALSE);

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

  return retval;
}

/**
 * atspi_selection_clear_selection:
 * @obj: a pointer to the #AtspiSelection implementor on which to operate.
 *
 * Clears the current selection, removing all selected children from the
 *       specified #AtspiSelection implementor's selection list.
 *
 * Returns: #TRUE if successful, #FALSE otherwise.
 *
 **/
gboolean
atspi_selection_clear_selection (AtspiSelection *obj, GError **error)
{
  dbus_bool_t retval = FALSE;

  g_return_val_if_fail (obj != NULL, FALSE);

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

  return retval;
}

static void
atspi_selection_base_init (AtspiSelection *klass)
{
}

GType
atspi_selection_get_type (void)
{
  static GType type = 0;

  if (!type)
    {
      static const GTypeInfo tinfo = {
        sizeof (AtspiSelection),
        (GBaseInitFunc) atspi_selection_base_init,
        (GBaseFinalizeFunc) NULL,
      };

      type = g_type_register_static (G_TYPE_INTERFACE, "AtspiSelection", &tinfo, 0);
    }
  return type;
}