summaryrefslogtreecommitdiff
path: root/atk/atkselection.c
blob: c324a4a3271faf73242a9e57c6bcc58391ed74f4 (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
278
279
280
281
282
283
284
285
286
/* ATK -  Accessibility Toolkit
 * Copyright 2001 Sun Microsystems 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 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "atkselection.h"

/**
 * SECTION:atkselection
 * @Short_description: The ATK interface implemented by container
 *  objects whose #AtkObject children can be selected.
 * @Title:AtkSelection
 *
 * #AtkSelection 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 #AtkObject children - for example,
 * selectable lists.
 *
 * Note that other types of "selection" (for instance text selection)
 * are accomplished a other ATK interfaces - #AtkSelection is limited
 * to the selection/deselection of children.
 */


enum {
  SELECTION_CHANGED,
  LAST_SIGNAL
};

static void atk_selection_base_init (gpointer *g_class);

static guint atk_selection_signals[LAST_SIGNAL] = { 0 };

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

  if (!type) {
    GTypeInfo tinfo =
    {
      sizeof (AtkSelectionIface),
      (GBaseInitFunc)atk_selection_base_init,
      (GBaseFinalizeFunc) NULL,

    };

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

  return type;
}

static void
atk_selection_base_init (gpointer *g_class)
{
  static gboolean initialized = FALSE;

  if (! initialized)
    {
      /**
       * AtkSelection::selection-changed:
       * @atkselection: the object which received the signal.
       *
       * The "selection-changed" signal is emitted by an object which
       * implements AtkSelection interface when the selection changes.
       */
      atk_selection_signals[SELECTION_CHANGED] =
        g_signal_new ("selection_changed",
                      ATK_TYPE_SELECTION,
                      G_SIGNAL_RUN_LAST,
                      G_STRUCT_OFFSET (AtkSelectionIface, selection_changed),
                      (GSignalAccumulator) NULL, NULL,
                      g_cclosure_marshal_VOID__VOID,
                      G_TYPE_NONE, 0);


      initialized = TRUE;
    }
}

/**
 * atk_selection_add_selection:
 * @selection: a #GObject instance that implements AtkSelectionIface
 * @i: a #gint specifying the child index.
 *
 * Adds the specified accessible child of the object to the
 * object's selection.
 *
 * Returns: TRUE if success, FALSE otherwise.
 **/
gboolean
atk_selection_add_selection (AtkSelection *obj,
                             gint         i)
{
  AtkSelectionIface *iface;

  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);

  iface = ATK_SELECTION_GET_IFACE (obj);

  if (iface->add_selection)
    return (iface->add_selection) (obj, i);
  else
    return FALSE;
}

/**
 * atk_selection_clear_selection:
 * @selection: a #GObject instance that implements AtkSelectionIface
 *
 * Clears the selection in the object so that no children in the object
 * are selected.
 *
 * Returns: TRUE if success, FALSE otherwise.
 **/
gboolean
atk_selection_clear_selection (AtkSelection *obj)
{
  AtkSelectionIface *iface;

  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);

  iface = ATK_SELECTION_GET_IFACE (obj);

  if (iface->clear_selection)
    return (iface->clear_selection) (obj);
  else
    return FALSE;
}

/**
 * atk_selection_ref_selection:
 * @selection: a #GObject instance that implements AtkSelectionIface
 * @i: a #gint specifying the index in the selection set.  (e.g. the
 * ith selection as opposed to the ith child).
 *
 * Gets a reference to the accessible object representing the specified 
 * selected child of the object.
 * Note: callers should not rely on %NULL 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: (transfer full): an #AtkObject representing the selected
 * accessible , or %NULL if @selection does not implement this interface.
 **/
AtkObject*
atk_selection_ref_selection (AtkSelection *obj,
                             gint         i)
{
  AtkSelectionIface *iface;

  g_return_val_if_fail (ATK_IS_SELECTION (obj), NULL);

  iface = ATK_SELECTION_GET_IFACE (obj);

  if (iface->ref_selection)
    return (iface->ref_selection) (obj, i);
  else
    return NULL;
}

/**
 * atk_selection_get_selection_count:
 * @selection: a #GObject instance that implements AtkSelectionIface
 *
 * Gets the number of accessible children currently selected.
 * Note: callers should not rely on %NULL 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 @selection does not implement this interface.
 **/
gint
atk_selection_get_selection_count (AtkSelection *obj)
{
  AtkSelectionIface *iface;

  g_return_val_if_fail (ATK_IS_SELECTION (obj), 0);

  iface = ATK_SELECTION_GET_IFACE (obj);

  if (iface->get_selection_count)
    return (iface->get_selection_count) (obj);
  else
    return 0;
}

/**
 * atk_selection_is_child_selected:
 * @selection: a #GObject instance that implements AtkSelectionIface
 * @i: a #gint specifying the child index.
 *
 * Determines if the current child of this object is selected
 * Note: callers should not rely on %NULL 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 gboolean representing the specified child is selected, or 0
 * if @selection does not implement this interface.
 **/
gboolean
atk_selection_is_child_selected (AtkSelection *obj,
                                 gint         i)
{
  AtkSelectionIface *iface;

  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);

  iface = ATK_SELECTION_GET_IFACE (obj);

  if (iface->is_child_selected)
    return (iface->is_child_selected) (obj, i);
  else
    return FALSE;
}

/**
 * atk_selection_remove_selection:
 * @selection: a #GObject instance that implements AtkSelectionIface
 * @i: a #gint specifying the index in the selection set.  (e.g. the
 * ith selection as opposed to the ith child).
 *
 * Removes the specified child of the object from the object's selection.
 *
 * Returns: TRUE if success, FALSE otherwise.
 **/
gboolean
atk_selection_remove_selection (AtkSelection *obj,
                                gint         i)
{
  AtkSelectionIface *iface;

  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);

  iface = ATK_SELECTION_GET_IFACE (obj);

  if (iface->remove_selection)
    return (iface->remove_selection) (obj, i);
  else
    return FALSE;
}

/**
 * atk_selection_select_all_selection:
 * @selection: a #GObject instance that implements AtkSelectionIface
 *
 * Causes every child of the object to be selected if the object
 * supports multiple selections.
 *
 * Returns: TRUE if success, FALSE otherwise.
 **/
gboolean
atk_selection_select_all_selection (AtkSelection *obj)
{
  AtkSelectionIface *iface;

  g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);

  iface = ATK_SELECTION_GET_IFACE (obj);

  if (iface->select_all_selection)
    return (iface->select_all_selection) (obj);
  else
    return FALSE;
}