Release 2.13.1
[atk.git] / atk / atkselection.c
blobf086c288ba897fdc51e2ddbfcb9f667023d01df4
1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
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.
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.
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.
20 #include "config.h"
22 #include "atkselection.h"
24 /**
25 * SECTION:atkselection
26 * @Short_description: The ATK interface implemented by container
27 * objects whose #AtkObject children can be selected.
28 * @Title:AtkSelection
30 * #AtkSelection should be implemented by UI components with children
31 * which are exposed by #atk_object_ref_child and
32 * #atk_object_get_n_children, if the use of the parent UI component
33 * ordinarily involves selection of one or more of the objects
34 * corresponding to those #AtkObject children - for example,
35 * selectable lists.
37 * Note that other types of "selection" (for instance text selection)
38 * are accomplished a other ATK interfaces - #AtkSelection is limited
39 * to the selection/deselection of children.
43 enum {
44 SELECTION_CHANGED,
45 LAST_SIGNAL
48 static void atk_selection_base_init (gpointer *g_class);
50 static guint atk_selection_signals[LAST_SIGNAL] = { 0 };
52 GType
53 atk_selection_get_type (void)
55 static GType type = 0;
57 if (!type) {
58 GTypeInfo tinfo =
60 sizeof (AtkSelectionIface),
61 (GBaseInitFunc)atk_selection_base_init,
62 (GBaseFinalizeFunc) NULL,
66 type = g_type_register_static (G_TYPE_INTERFACE, "AtkSelection", &tinfo, 0);
69 return type;
72 static void
73 atk_selection_base_init (gpointer *g_class)
75 static gboolean initialized = FALSE;
77 if (! initialized)
79 /**
80 * AtkSelection::selection-changed:
81 * @atkselection: the object which received the signal.
83 * The "selection-changed" signal is emitted by an object which
84 * implements AtkSelection interface when the selection changes.
86 atk_selection_signals[SELECTION_CHANGED] =
87 g_signal_new ("selection_changed",
88 ATK_TYPE_SELECTION,
89 G_SIGNAL_RUN_LAST,
90 G_STRUCT_OFFSET (AtkSelectionIface, selection_changed),
91 (GSignalAccumulator) NULL, NULL,
92 g_cclosure_marshal_VOID__VOID,
93 G_TYPE_NONE, 0);
96 initialized = TRUE;
101 * atk_selection_add_selection:
102 * @selection: a #GObject instance that implements AtkSelectionIface
103 * @i: a #gint specifying the child index.
105 * Adds the specified accessible child of the object to the
106 * object's selection.
108 * Returns: TRUE if success, FALSE otherwise.
110 gboolean
111 atk_selection_add_selection (AtkSelection *obj,
112 gint i)
114 AtkSelectionIface *iface;
116 g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
118 iface = ATK_SELECTION_GET_IFACE (obj);
120 if (iface->add_selection)
121 return (iface->add_selection) (obj, i);
122 else
123 return FALSE;
127 * atk_selection_clear_selection:
128 * @selection: a #GObject instance that implements AtkSelectionIface
130 * Clears the selection in the object so that no children in the object
131 * are selected.
133 * Returns: TRUE if success, FALSE otherwise.
135 gboolean
136 atk_selection_clear_selection (AtkSelection *obj)
138 AtkSelectionIface *iface;
140 g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
142 iface = ATK_SELECTION_GET_IFACE (obj);
144 if (iface->clear_selection)
145 return (iface->clear_selection) (obj);
146 else
147 return FALSE;
151 * atk_selection_ref_selection:
152 * @selection: a #GObject instance that implements AtkSelectionIface
153 * @i: a #gint specifying the index in the selection set. (e.g. the
154 * ith selection as opposed to the ith child).
156 * Gets a reference to the accessible object representing the specified
157 * selected child of the object.
158 * Note: callers should not rely on %NULL or on a zero value for
159 * indication of whether AtkSelectionIface is implemented, they should
160 * use type checking/interface checking macros or the
161 * atk_get_accessible_value() convenience method.
163 * Returns: (transfer full): an #AtkObject representing the selected
164 * accessible , or %NULL if @selection does not implement this interface.
166 AtkObject*
167 atk_selection_ref_selection (AtkSelection *obj,
168 gint i)
170 AtkSelectionIface *iface;
172 g_return_val_if_fail (ATK_IS_SELECTION (obj), NULL);
174 iface = ATK_SELECTION_GET_IFACE (obj);
176 if (iface->ref_selection)
177 return (iface->ref_selection) (obj, i);
178 else
179 return NULL;
183 * atk_selection_get_selection_count:
184 * @selection: a #GObject instance that implements AtkSelectionIface
186 * Gets the number of accessible children currently selected.
187 * Note: callers should not rely on %NULL or on a zero value for
188 * indication of whether AtkSelectionIface is implemented, they should
189 * use type checking/interface checking macros or the
190 * atk_get_accessible_value() convenience method.
192 * Returns: a gint representing the number of items selected, or 0
193 * if @selection does not implement this interface.
195 gint
196 atk_selection_get_selection_count (AtkSelection *obj)
198 AtkSelectionIface *iface;
200 g_return_val_if_fail (ATK_IS_SELECTION (obj), 0);
202 iface = ATK_SELECTION_GET_IFACE (obj);
204 if (iface->get_selection_count)
205 return (iface->get_selection_count) (obj);
206 else
207 return 0;
211 * atk_selection_is_child_selected:
212 * @selection: a #GObject instance that implements AtkSelectionIface
213 * @i: a #gint specifying the child index.
215 * Determines if the current child of this object is selected
216 * Note: callers should not rely on %NULL or on a zero value for
217 * indication of whether AtkSelectionIface is implemented, they should
218 * use type checking/interface checking macros or the
219 * atk_get_accessible_value() convenience method.
221 * Returns: a gboolean representing the specified child is selected, or 0
222 * if @selection does not implement this interface.
224 gboolean
225 atk_selection_is_child_selected (AtkSelection *obj,
226 gint i)
228 AtkSelectionIface *iface;
230 g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
232 iface = ATK_SELECTION_GET_IFACE (obj);
234 if (iface->is_child_selected)
235 return (iface->is_child_selected) (obj, i);
236 else
237 return FALSE;
241 * atk_selection_remove_selection:
242 * @selection: a #GObject instance that implements AtkSelectionIface
243 * @i: a #gint specifying the index in the selection set. (e.g. the
244 * ith selection as opposed to the ith child).
246 * Removes the specified child of the object from the object's selection.
248 * Returns: TRUE if success, FALSE otherwise.
250 gboolean
251 atk_selection_remove_selection (AtkSelection *obj,
252 gint i)
254 AtkSelectionIface *iface;
256 g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
258 iface = ATK_SELECTION_GET_IFACE (obj);
260 if (iface->remove_selection)
261 return (iface->remove_selection) (obj, i);
262 else
263 return FALSE;
267 * atk_selection_select_all_selection:
268 * @selection: a #GObject instance that implements AtkSelectionIface
270 * Causes every child of the object to be selected if the object
271 * supports multiple selections.
273 * Returns: TRUE if success, FALSE otherwise.
275 gboolean
276 atk_selection_select_all_selection (AtkSelection *obj)
278 AtkSelectionIface *iface;
280 g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
282 iface = ATK_SELECTION_GET_IFACE (obj);
284 if (iface->select_all_selection)
285 return (iface->select_all_selection) (obj);
286 else
287 return FALSE;