Remove all instances of g_return_if_fail (foo != NULL); that are
[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 the child index.
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 (ATK_IS_SELECTION (obj), FALSE);
59
60   iface = ATK_SELECTION_GET_IFACE (obj);
61
62   if (iface->add_selection)
63     return (iface->add_selection) (obj, i);
64   else
65     return FALSE;
66 }
67
68 /**
69  * atk_selection_clear_selection:
70  * @selection: a #GObject instance that implements AtkSelectionIface
71  *
72  * Clears the selection in the object so that no children in the object
73  * are selected.
74  *
75  * Returns: TRUE if success, FALSE otherwise.
76  **/
77 gboolean
78 atk_selection_clear_selection (AtkSelection *obj)
79 {
80   AtkSelectionIface *iface;
81
82   g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
83
84   iface = ATK_SELECTION_GET_IFACE (obj);
85
86   if (iface->clear_selection)
87     return (iface->clear_selection) (obj);
88   else
89     return FALSE;
90 }
91
92 /**
93  * atk_selection_ref_selection:
94  * @selection: a #GObject instance that implements AtkSelectionIface
95  * @i: a #gint specifying the index in the selection set.  (e.g. the
96  * ith selection as opposed to the ith child).
97  *
98  * Gets a reference to the accessible object representing the specified 
99  * selected child of the object.
100  * Note: callers should not rely on %NULL or on a zero value for
101  * indication of whether AtkSelectionIface is implemented, they should
102  * use type checking/interface checking macros or the
103  * atk_get_accessible_value() convenience method.
104  *
105  * Returns: an #AtkObject representing the selected accessible , or %NULL
106  * if @selection does not implement this interface.
107  **/
108 AtkObject*
109 atk_selection_ref_selection (AtkSelection *obj,
110                              gint         i)
111 {
112   AtkSelectionIface *iface;
113
114   g_return_val_if_fail (ATK_IS_SELECTION (obj), NULL);
115
116   iface = ATK_SELECTION_GET_IFACE (obj);
117
118   if (iface->ref_selection)
119     return (iface->ref_selection) (obj, i);
120   else
121     return NULL;
122 }
123
124 /**
125  * atk_selection_get_selection_count:
126  * @selection: a #GObject instance that implements AtkSelectionIface
127  *
128  * Gets the number of accessible children currently selected.
129  * Note: callers should not rely on %NULL or on a zero value for
130  * indication of whether AtkSelectionIface is implemented, they should
131  * use type checking/interface checking macros or the
132  * atk_get_accessible_value() convenience method.
133  *
134  * Returns: a gint representing the number of items selected, or 0
135  * if @selection does not implement this interface.
136  **/
137 gint
138 atk_selection_get_selection_count (AtkSelection *obj)
139 {
140   AtkSelectionIface *iface;
141
142   g_return_val_if_fail (ATK_IS_SELECTION (obj), 0);
143
144   iface = ATK_SELECTION_GET_IFACE (obj);
145
146   if (iface->get_selection_count)
147     return (iface->get_selection_count) (obj);
148   else
149     return 0;
150 }
151
152 /**
153  * atk_selection_is_child_selected:
154  * @selection: a #GObject instance that implements AtkSelectionIface
155  * @i: a #gint specifying the child index.
156  *
157  * Determines if the current child of this object is selected
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.
162  *
163  * Returns: a gboolean representing the specified child is selected, or 0
164  * if @selection does not implement this interface.
165  **/
166 gboolean
167 atk_selection_is_child_selected (AtkSelection *obj,
168                                  gint         i)
169 {
170   AtkSelectionIface *iface;
171
172   g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
173
174   iface = ATK_SELECTION_GET_IFACE (obj);
175
176   if (iface->is_child_selected)
177     return (iface->is_child_selected) (obj, i);
178   else
179     return FALSE;
180 }
181
182 /**
183  * atk_selection_remove_selection:
184  * @selection: a #GObject instance that implements AtkSelectionIface
185  * @i: a #gint specifying the index in the selection set.  (e.g. the
186  * ith selection as opposed to the ith child).
187  *
188  * Removes the specified child of the object from the object's selection.
189  *
190  * Returns: TRUE if success, FALSE otherwise.
191  **/
192 gboolean
193 atk_selection_remove_selection (AtkSelection *obj,
194                                 gint         i)
195 {
196   AtkSelectionIface *iface;
197
198   g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
199
200   iface = ATK_SELECTION_GET_IFACE (obj);
201
202   if (iface->remove_selection)
203     return (iface->remove_selection) (obj, i);
204   else
205     return FALSE;
206 }
207
208 /**
209  * atk_selection_select_all_selection:
210  * @selection: a #GObject instance that implements AtkSelectionIface
211  *
212  * Causes every child of the object to be selected if the object
213  * supports multiple selections.
214  *
215  * Returns: TRUE if success, FALSE otherwise.
216  **/
217 gboolean
218 atk_selection_select_all_selection (AtkSelection *obj)
219 {
220   AtkSelectionIface *iface;
221
222   g_return_val_if_fail (ATK_IS_SELECTION (obj), FALSE);
223
224   iface = ATK_SELECTION_GET_IFACE (obj);
225
226   if (iface->select_all_selection)
227     return (iface->select_all_selection) (obj);
228   else
229     return FALSE;
230 }