1
/* ATK -  Accessibility Toolkit
2
 * Copyright 2001 Sun Microsystems Inc.
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library; if not, write to the
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 * Boston, MA 02111-1307, USA.
18
 */
19

            
20
#include "config.h"
21

            
22
#include "atkselection.h"
23

            
24
/**
25
 * AtkSelection:
26
 *
27
 * The ATK interface implemented by container objects whose #AtkObject children can be selected.
28
 *
29
 * #AtkSelection should be implemented by UI components with children
30
 * which are exposed by #atk_object_ref_child and
31
 * #atk_object_get_n_children, if the use of the parent UI component
32
 * ordinarily involves selection of one or more of the objects
33
 * corresponding to those #AtkObject children - for example,
34
 * selectable lists.
35
 *
36
 * Note that other types of "selection" (for instance text selection)
37
 * are accomplished a other ATK interfaces - #AtkSelection is limited
38
 * to the selection/deselection of children.
39
 */
40

            
41
enum
42
{
43
  SELECTION_CHANGED,
44
  LAST_SIGNAL
45
};
46

            
47
static void atk_selection_base_init (gpointer *g_class);
48

            
49
static guint atk_selection_signals[LAST_SIGNAL] = { 0 };
50

            
51
GType
52
1976
atk_selection_get_type (void)
53
{
54
  static GType type = 0;
55

            
56
1976
  if (!type)
57
    {
58
161
      GTypeInfo tinfo = {
59
        sizeof (AtkSelectionIface),
60
        (GBaseInitFunc) atk_selection_base_init,
61
        (GBaseFinalizeFunc) NULL,
62

            
63
      };
64

            
65
161
      type = g_type_register_static (G_TYPE_INTERFACE, "AtkSelection", &tinfo, 0);
66
    }
67

            
68
1976
  return type;
69
}
70

            
71
static void
72
331
atk_selection_base_init (gpointer *g_class)
73
{
74
  static gboolean initialized = FALSE;
75

            
76
331
  if (!initialized)
77
    {
78
      /**
79
       * AtkSelection::selection-changed:
80
       * @atkselection: the object which received the signal.
81
       *
82
       * The "selection-changed" signal is emitted by an object which
83
       * implements AtkSelection interface when the selection changes.
84
       */
85
161
      atk_selection_signals[SELECTION_CHANGED] =
86
161
          g_signal_new ("selection_changed",
87
                        ATK_TYPE_SELECTION,
88
                        G_SIGNAL_RUN_LAST,
89
                        G_STRUCT_OFFSET (AtkSelectionIface, selection_changed),
90
                        (GSignalAccumulator) NULL, NULL,
91
                        g_cclosure_marshal_VOID__VOID,
92
                        G_TYPE_NONE, 0);
93

            
94
161
      initialized = TRUE;
95
    }
96
331
}
97

            
98
/**
99
 * atk_selection_add_selection:
100
 * @selection: a #GObject instance that implements AtkSelectionIface
101
 * @i: a #gint specifying the child index.
102
 *
103
 * Adds the specified accessible child of the object to the
104
 * object's selection.
105
 *
106
 * Returns: TRUE if success, FALSE otherwise.
107
 **/
108
gboolean
109
6
atk_selection_add_selection (AtkSelection *obj,
110
                             gint i)
111
{
112
  AtkSelectionIface *iface;
113

            
114
6
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
115

            
116
6
  iface = ATK_SELECTION_GET_IFACE (obj);
117

            
118
6
  if (iface->add_selection)
119
6
    return (iface->add_selection) (obj, i);
120
  else
121
    return FALSE;
122
}
123

            
124
/**
125
 * atk_selection_clear_selection:
126
 * @selection: a #GObject instance that implements AtkSelectionIface
127
 *
128
 * Clears the selection in the object so that no children in the object
129
 * are selected.
130
 *
131
 * Returns: TRUE if success, FALSE otherwise.
132
 **/
133
gboolean
134
1
atk_selection_clear_selection (AtkSelection *obj)
135
{
136
  AtkSelectionIface *iface;
137

            
138
1
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
139

            
140
1
  iface = ATK_SELECTION_GET_IFACE (obj);
141

            
142
1
  if (iface->clear_selection)
143
1
    return (iface->clear_selection) (obj);
144
  else
145
    return FALSE;
146
}
147

            
148
/**
149
 * atk_selection_ref_selection:
150
 * @selection: a #GObject instance that implements AtkSelectionIface
151
 * @i: a #gint specifying the index in the selection set.  (e.g. the
152
 * ith selection as opposed to the ith child).
153
 *
154
 * Gets a reference to the accessible object representing the specified
155
 * selected child of the object.
156
 * Note: callers should not rely on %NULL or on a zero value for
157
 * indication of whether AtkSelectionIface is implemented, they should
158
 * use type checking/interface checking macros or the
159
 * atk_get_accessible_value() convenience method.
160
 *
161
 * Returns: (nullable) (transfer full): an #AtkObject representing the
162
 * selected accessible, or %NULL if @selection does not implement this
163
 * interface.
164
 **/
165
AtkObject *
166
6
atk_selection_ref_selection (AtkSelection *obj,
167
                             gint i)
168
{
169
  AtkSelectionIface *iface;
170

            
171
6
  g_return_val_if_fail (ATK_IS_SELECTION (obj), NULL);
172

            
173
6
  iface = ATK_SELECTION_GET_IFACE (obj);
174

            
175
6
  if (iface->ref_selection)
176
6
    return (iface->ref_selection) (obj, i);
177
  else
178
    return NULL;
179
}
180

            
181
/**
182
 * atk_selection_get_selection_count:
183
 * @selection: a #GObject instance that implements AtkSelectionIface
184
 *
185
 * Gets the number of accessible children currently selected.
186
 * Note: callers should not rely on %NULL or on a zero value for
187
 * indication of whether AtkSelectionIface is implemented, they should
188
 * use type checking/interface checking macros or the
189
 * atk_get_accessible_value() convenience method.
190
 *
191
 * Returns: a gint representing the number of items selected, or 0
192
 * if @selection does not implement this interface.
193
 **/
194
gint
195
15
atk_selection_get_selection_count (AtkSelection *obj)
196
{
197
  AtkSelectionIface *iface;
198

            
199
15
  g_return_val_if_fail (ATK_IS_SELECTION (obj), 0);
200

            
201
15
  iface = ATK_SELECTION_GET_IFACE (obj);
202

            
203
15
  if (iface->get_selection_count)
204
15
    return (iface->get_selection_count) (obj);
205
  else
206
    return 0;
207
}
208

            
209
/**
210
 * atk_selection_is_child_selected:
211
 * @selection: a #GObject instance that implements AtkSelectionIface
212
 * @i: a #gint specifying the child index.
213
 *
214
 * Determines if the current child of this object is selected
215
 * Note: callers should not rely on %NULL or on a zero value for
216
 * indication of whether AtkSelectionIface is implemented, they should
217
 * use type checking/interface checking macros or the
218
 * atk_get_accessible_value() convenience method.
219
 *
220
 * Returns: a gboolean representing the specified child is selected, or 0
221
 * if @selection does not implement this interface.
222
 **/
223
gboolean
224
5
atk_selection_is_child_selected (AtkSelection *obj,
225
                                 gint i)
226
{
227
  AtkSelectionIface *iface;
228

            
229
5
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
230

            
231
5
  iface = ATK_SELECTION_GET_IFACE (obj);
232

            
233
5
  if (iface->is_child_selected)
234
5
    return (iface->is_child_selected) (obj, i);
235
  else
236
    return FALSE;
237
}
238

            
239
/**
240
 * atk_selection_remove_selection:
241
 * @selection: a #GObject instance that implements AtkSelectionIface
242
 * @i: a #gint specifying the index in the selection set.  (e.g. the
243
 * ith selection as opposed to the ith child).
244
 *
245
 * Removes the specified child of the object from the object's selection.
246
 *
247
 * Returns: TRUE if success, FALSE otherwise.
248
 **/
249
gboolean
250
2
atk_selection_remove_selection (AtkSelection *obj,
251
                                gint i)
252
{
253
  AtkSelectionIface *iface;
254

            
255
2
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
256

            
257
2
  iface = ATK_SELECTION_GET_IFACE (obj);
258

            
259
2
  if (iface->remove_selection)
260
2
    return (iface->remove_selection) (obj, i);
261
  else
262
    return FALSE;
263
}
264

            
265
/**
266
 * atk_selection_select_all_selection:
267
 * @selection: a #GObject instance that implements AtkSelectionIface
268
 *
269
 * Causes every child of the object to be selected if the object
270
 * supports multiple selections.
271
 *
272
 * Returns: TRUE if success, FALSE otherwise.
273
 **/
274
gboolean
275
1
atk_selection_select_all_selection (AtkSelection *obj)
276
{
277
  AtkSelectionIface *iface;
278

            
279
1
  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
280

            
281
1
  iface = ATK_SELECTION_GET_IFACE (obj);
282

            
283
1
  if (iface->select_all_selection)
284
1
    return (iface->select_all_selection) (obj);
285
  else
286
    return FALSE;
287
}