build: Use Meson to test for compiler and linker arguments
[atk.git] / atk / atkselection.c
blobd4bd8363ec27dabf3d8bdfb8e828417acbc0f99c
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: (nullable) (transfer full): an #AtkObject representing the
164 * selected accessible, or %NULL if @selection does not implement this
165 * interface.
167 AtkObject*
168 atk_selection_ref_selection (AtkSelection *obj,
169 gint i)
171 AtkSelectionIface *iface;
173 g_return_val_if_fail (ATK_IS_SELECTION (obj), NULL);
175 iface = ATK_SELECTION_GET_IFACE (obj);
177 if (iface->ref_selection)
178 return (iface->ref_selection) (obj, i);
179 else
180 return NULL;
184 * atk_selection_get_selection_count:
185 * @selection: a #GObject instance that implements AtkSelectionIface
187 * Gets the number of accessible children currently selected.
188 * Note: callers should not rely on %NULL or on a zero value for
189 * indication of whether AtkSelectionIface is implemented, they should
190 * use type checking/interface checking macros or the
191 * atk_get_accessible_value() convenience method.
193 * Returns: a gint representing the number of items selected, or 0
194 * if @selection does not implement this interface.
196 gint
197 atk_selection_get_selection_count (AtkSelection *obj)
199 AtkSelectionIface *iface;
201 g_return_val_if_fail (ATK_IS_SELECTION (obj), 0);
203 iface = ATK_SELECTION_GET_IFACE (obj);
205 if (iface->get_selection_count)
206 return (iface->get_selection_count) (obj);
207 else
208 return 0;
212 * atk_selection_is_child_selected:
213 * @selection: a #GObject instance that implements AtkSelectionIface
214 * @i: a #gint specifying the child index.
216 * Determines if the current child of this object is selected
217 * Note: callers should not rely on %NULL or on a zero value for
218 * indication of whether AtkSelectionIface is implemented, they should
219 * use type checking/interface checking macros or the
220 * atk_get_accessible_value() convenience method.
222 * Returns: a gboolean representing the specified child is selected, or 0
223 * if @selection does not implement this interface.
225 gboolean
226 atk_selection_is_child_selected (AtkSelection *obj,
227 gint i)
229 AtkSelectionIface *iface;
231 g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
233 iface = ATK_SELECTION_GET_IFACE (obj);
235 if (iface->is_child_selected)
236 return (iface->is_child_selected) (obj, i);
237 else
238 return FALSE;
242 * atk_selection_remove_selection:
243 * @selection: a #GObject instance that implements AtkSelectionIface
244 * @i: a #gint specifying the index in the selection set. (e.g. the
245 * ith selection as opposed to the ith child).
247 * Removes the specified child of the object from the object's selection.
249 * Returns: TRUE if success, FALSE otherwise.
251 gboolean
252 atk_selection_remove_selection (AtkSelection *obj,
253 gint i)
255 AtkSelectionIface *iface;
257 g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
259 iface = ATK_SELECTION_GET_IFACE (obj);
261 if (iface->remove_selection)
262 return (iface->remove_selection) (obj, i);
263 else
264 return FALSE;
268 * atk_selection_select_all_selection:
269 * @selection: a #GObject instance that implements AtkSelectionIface
271 * Causes every child of the object to be selected if the object
272 * supports multiple selections.
274 * Returns: TRUE if success, FALSE otherwise.
276 gboolean
277 atk_selection_select_all_selection (AtkSelection *obj)
279 AtkSelectionIface *iface;
281 g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
283 iface = ATK_SELECTION_GET_IFACE (obj);
285 if (iface->select_all_selection)
286 return (iface->select_all_selection) (obj);
287 else
288 return FALSE;