Now atkselection returns a boolean for add_selection, clear_selection
[platform/upstream/atk.git] / atk / atkselection.c
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 "atkselection.h"
21
22 GType
23 atk_selection_get_type ()
24 {
25   static GType type = 0;
26
27   if (!type) {
28     GTypeInfo tinfo =
29     {
30       sizeof (AtkSelectionIface),
31       (GBaseInitFunc) NULL,
32       (GBaseFinalizeFunc) NULL,
33
34     };
35
36     type = g_type_register_static (G_TYPE_INTERFACE, "AtkSelection", &tinfo, 0);
37   }
38
39   return type;
40 }
41
42 /**
43  * atk_selection_add_selection:
44  * @selection: a #GObject instance that implements AtkSelectionIface
45  * @i: a #gint specifying an accessible child of @selection 
46  *
47  * Adds the specified accessible child of the object to the
48  * object's selection.
49  *
50  * Returns: TRUE if success, FALSE otherwise.
51  **/
52 gboolean
53 atk_selection_add_selection (AtkSelection *obj,
54                              gint         i)
55 {
56   AtkSelectionIface *iface;
57
58   g_return_val_if_fail (obj != NULL, FALSE);
59   g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
60
61   iface = ATK_SELECTION_GET_IFACE (obj);
62
63   if (iface->add_selection)
64     return (iface->add_selection) (obj, i);
65   else
66     return FALSE;
67 }
68
69 /**
70  * atk_selection_clear_selection:
71  * @selection: a #GObject instance that implements AtkSelectionIface
72  *
73  * Clears the selection in the object so that no children in the object
74  * are selected.
75  *
76  * Returns: TRUE if success, FALSE otherwise.
77  **/
78 gboolean
79 atk_selection_clear_selection (AtkSelection *obj)
80 {
81   AtkSelectionIface *iface;
82
83   g_return_val_if_fail (obj != NULL, FALSE);
84   g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
85
86   iface = ATK_SELECTION_GET_IFACE (obj);
87
88   if (iface->clear_selection)
89     return (iface->clear_selection) (obj);
90   else
91     return FALSE;
92 }
93
94 /**
95  * atk_selection_ref_selection:
96  * @selection: a #GObject instance that implements AtkSelectionIface
97  * @i: a #gint specifying an accessible child of @selection 
98  *
99  * Gets a reference to the accessible object representing the specified 
100  * selected child of the object.
101  * Note: callers should not rely on %NULL or on a zero value for
102  * indication of whether AtkSelectionIface is implemented, they should
103  * use type checking/interface checking macros or the
104  * atk_get_accessible_value() convenience method.
105  *
106  * Returns: an #AtkObject representing the selected accessible , or %NULL
107  * if @selection does not implement this interface.
108  **/
109 AtkObject*
110 atk_selection_ref_selection (AtkSelection *obj,
111                              gint         i)
112 {
113   AtkSelectionIface *iface;
114
115   g_return_val_if_fail (obj != NULL, NULL);
116   g_return_val_if_fail (ATK_IS_SELECTION (obj), NULL);
117
118   iface = ATK_SELECTION_GET_IFACE (obj);
119
120   if (iface->ref_selection)
121     return (iface->ref_selection) (obj, i);
122   else
123     return NULL;
124 }
125
126 /**
127  * atk_selection_get_selection_count:
128  * @selection: a #GObject instance that implements AtkSelectionIface
129  *
130  * Gets the number of accessible children currently selected.
131  * Note: callers should not rely on %NULL or on a zero value for
132  * indication of whether AtkSelectionIface is implemented, they should
133  * use type checking/interface checking macros or the
134  * atk_get_accessible_value() convenience method.
135  *
136  * Returns: a gint representing the number of items selected, or 0
137  * if @selection does not implement this interface.
138  **/
139 gint
140 atk_selection_get_selection_count (AtkSelection *obj)
141 {
142   AtkSelectionIface *iface;
143
144   g_return_val_if_fail (obj != NULL, 0);
145   g_return_val_if_fail (ATK_IS_SELECTION (obj), 0);
146
147   iface = ATK_SELECTION_GET_IFACE (obj);
148
149   if (iface->get_selection_count)
150     return (iface->get_selection_count) (obj);
151   else
152     return 0;
153 }
154
155 /**
156  * atk_selection_is_child_selected:
157  * @selection: a #GObject instance that implements AtkSelectionIface
158  * @i: a #gint specifying an accessible child of @selection 
159  *
160  * Determines if the current child of this object is selected
161  * Note: callers should not rely on %NULL or on a zero value for
162  * indication of whether AtkSelectionIface is implemented, they should
163  * use type checking/interface checking macros or the
164  * atk_get_accessible_value() convenience method.
165  *
166  * Returns: a gboolean representing the specified child is selected, or 0
167  * if @selection does not implement this interface.
168  **/
169 gboolean
170 atk_selection_is_child_selected (AtkSelection *obj,
171                                  gint         i)
172 {
173   AtkSelectionIface *iface;
174
175   g_return_val_if_fail (obj != NULL, FALSE);
176   g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
177
178   iface = ATK_SELECTION_GET_IFACE (obj);
179
180   if (iface->is_child_selected)
181     return (iface->is_child_selected) (obj, i);
182   else
183     return FALSE;
184 }
185
186 /**
187  * atk_selection_remove_selection:
188  * @selection: a #GObject instance that implements AtkSelectionIface
189  * @i: a #gint specifying an accessible child of @selection 
190  *
191  * Removes the specified child of the object from the object's selection.
192  *
193  * Returns: TRUE if success, FALSE otherwise.
194  **/
195 gboolean
196 atk_selection_remove_selection (AtkSelection *obj,
197                                 gint         i)
198 {
199   AtkSelectionIface *iface;
200
201   g_return_val_if_fail (obj != NULL, FALSE);
202   g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
203
204   iface = ATK_SELECTION_GET_IFACE (obj);
205
206   if (iface->remove_selection)
207     return (iface->remove_selection) (obj, i);
208   else
209     return FALSE;
210 }
211
212 /**
213  * atk_selection_select_all_selection:
214  * @selection: a #GObject instance that implements AtkSelectionIface
215  *
216  * Causes every child of the object to be selected if the object
217  * supports multiple selections.
218  **/
219 void
220 atk_selection_select_all_selection (AtkSelection *obj)
221 {
222   AtkSelectionIface *iface;
223
224   g_return_if_fail (obj != NULL);
225   g_return_if_fail (ATK_IS_SELECTION (obj));
226
227   iface = ATK_SELECTION_GET_IFACE (obj);
228
229   if (iface->select_all_selection)
230     (iface->select_all_selection) (obj);
231 }