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