Imported version 2.7.91
[platform/core/uifw/at-spi2-core.git] / atspi / atspi-selection.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2001, 2002 Sun Microsystems Inc.,
6  * Copyright 2001, 2002 Ximian, Inc.
7  * Copyright 2010, 2011 Novell, Inc.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include "atspi-private.h"
26
27 /**
28  * atspi_selection_get_n_selected_children:
29  * @obj: a pointer to the #AtspiSelection implementor on which to operate.
30  *
31  * Gets the number of children of an #AtspiSelection implementor which are
32  *        currently selected.
33  *
34  * Returns: a #gint indicating the number of #Accessible children
35  *        of the #AtspiSelection implementor which are currently selected.
36  *
37  **/
38 gint
39 atspi_selection_get_n_selected_children (AtspiSelection *obj, GError **error)
40 {
41   dbus_int32_t retval = -1;
42
43   g_return_val_if_fail (obj != NULL, -1);
44
45   _atspi_dbus_get_property (obj, atspi_interface_selection, "NSelectedChildren", error, "i", &retval);
46
47   return retval;
48 }
49
50 /**
51  * atspi_selection_get_selected_child:
52  * @obj: a pointer to the #AtspiSelection on which to operate.
53  * @selected_child_index: a #gint indicating which of the selected
54  *      children is specified.
55  *
56  * Gets the i-th selected #AtspiAccessible child of an #AtspiSelection.
57  *      Note that @selected_child_index refers to the index in the list 
58  *      of 'selected'
59  *      children and generally differs from that used in
60  *      #atspi_accessible_get_child_at_index or returned by
61  *      #atspi_accessible_get_index_in_parent.
62  *      @selected_child_index must lie between 0
63  *      and #atspi_selection_get_n_selected_children - 1, inclusive.
64  *
65  * Returns: (transfer full): a pointer to a selected #AtspiAccessible child
66  *          object, specified by @selected_child_index.
67  *
68  **/
69 AtspiAccessible *
70 atspi_selection_get_selected_child (AtspiSelection *obj,
71                                       gint selected_child_index, GError **error)
72 {
73   dbus_int32_t d_selected_child_index = selected_child_index;
74   DBusMessage *reply;
75
76   g_return_val_if_fail (obj != NULL, NULL);
77   
78   reply = _atspi_dbus_call_partial (obj, atspi_interface_selection,
79                                     "GetSelectedChild", error, "i",
80                                     d_selected_child_index);
81
82   return _atspi_dbus_return_accessible_from_message (reply);
83 }
84
85 /**
86  * atspi_selection_select_child:
87  * @obj: a pointer to the #AtspiSelection on which to operate.
88  * @child_index: a #gint indicating which child of the #Accessible
89  *              is to be selected.
90  *
91  * Adds a child to the selected children list of an #AtspiSelection.
92  *         For #AtspiSelection implementors that only allow
93  *         single selections, this may replace the (single) current
94  *         selection.
95  *
96  * Returns: #TRUE if the child was successfully selected, #FALSE otherwise.
97  **/
98 gboolean
99 atspi_selection_select_child (AtspiSelection *obj,
100                               gint child_index,
101                               GError **error)
102 {
103   dbus_int32_t d_child_index = child_index;
104   dbus_bool_t retval = FALSE;
105
106   g_return_val_if_fail (obj != NULL, FALSE);
107
108   _atspi_dbus_call (obj, atspi_interface_selection, "SelectChild", error, "i=>b", d_child_index, &retval);
109
110   return retval;
111 }
112
113 /**
114  * atspi_selection_deselect_selected_child:
115  * @obj: a pointer to the #AtspiSelection on which to operate.
116  * @selected_child_index: a #gint indicating which of the selected children
117  *              of the #Accessible is to be selected.
118  *
119  * Removes a child from the selected children list of an #AtspiSelection.
120  *          Note that @child_index is the index in the selected-children list,
121  *          not the index in the parent container.  @selectedChildIndex in this
122  *          method, and @child_index in #atspi_selection_select_child
123  *          are asymmetric.
124  *
125  * Returns: #TRUE if the child was successfully deselected, #FALSE otherwise.
126  **/
127 gboolean
128 atspi_selection_deselect_selected_child (AtspiSelection *obj,
129                                          gint selected_child_index,
130                                          GError **error)
131 {
132   dbus_int32_t d_selected_child_index = selected_child_index;
133   dbus_bool_t retval = FALSE;
134
135   g_return_val_if_fail (obj != NULL, FALSE);
136
137   _atspi_dbus_call (obj, atspi_interface_selection, "DeselectSelectedChild", error, "i=>b", d_selected_child_index, &retval);
138
139   return retval;
140 }
141
142 /**
143  * atspi_selection_deselect_child:
144  * @obj: a pointer to the #AtspiSelection on which to operate.
145  * @child_index: a #gint indicating which of the children
146  *              of the #AtspiAccessible is to be de-selected.
147  *
148  * Deselects a specific child of an #AtspiSelection.
149  *          Note that @child_index is the index of the child
150  *          in the parent container.
151  * 
152  * See #atspi_selection_deselect_selected_child
153  * 
154  * Returns: #TRUE if the child was successfully deselected, #FALSE otherwise.
155  **/
156 gboolean
157 atspi_selection_deselect_child (AtspiSelection *obj,
158                                 gint child_index,
159                                 GError **error)
160 {
161   dbus_int32_t d_child_index = child_index;
162   dbus_bool_t retval = FALSE;
163
164   g_return_val_if_fail (obj != NULL, FALSE);
165
166   _atspi_dbus_call (obj, atspi_interface_selection, "DeselectChild", error, "i=>b", d_child_index, &retval);
167
168   return retval;
169 }
170
171 /**
172  * atspi_selection_is_child_selected:
173  * @obj: a pointer to the #AtspiSelection implementor on which to operate.
174  * @child_index: an index into the #AtspiSelection's list of children.
175  *
176  * Determines whether a particular child of an #AtspiSelection implementor
177  *        is currently selected.  Note that @child_index is the index into the
178  *        standard #AtspiAccessible container's list of children.
179  *
180  * Returns: #TRUE if the specified child is currently selected,
181  *          #FALSE otherwise.
182  **/
183 gboolean
184 atspi_selection_is_child_selected (AtspiSelection *obj,
185                                    gint child_index,
186                                    GError **error)
187 {
188   dbus_int32_t d_child_index = child_index;
189   dbus_bool_t retval = FALSE;
190
191   g_return_val_if_fail (obj != NULL, FALSE);
192
193   _atspi_dbus_call (obj, atspi_interface_selection, "IsChildSelected", error, "i=>b", d_child_index, &retval);
194
195   return retval;
196 }
197
198 /**
199  * atspi_selection_select_all:
200  * @obj: a pointer to the #AtspiSelection implementor on which to operate.
201  *
202  * Attempts to select all of the children of an #AtspiSelection implementor.
203  * Not all #AtspiSelection implementors support this operation.
204  *
205  * Returns: #TRUE if successful, #FALSE otherwise.
206  *
207  **/
208 gboolean
209 atspi_selection_select_all (AtspiSelection *obj, GError **error)
210 {
211   dbus_bool_t retval = FALSE;
212   
213   g_return_val_if_fail (obj != NULL, FALSE);
214
215   _atspi_dbus_call (obj, atspi_interface_selection, "SelectAll", error, "=>b", &retval);
216
217   return retval;
218 }
219
220 /**
221  * atspi_selection_clear_selection:
222  * @obj: a pointer to the #AtspiSelection implementor on which to operate.
223  *
224  * Clears the current selection, removing all selected children from the
225  *       specified #AtspiSelection implementor's selection list.
226  *
227  * Returns: #TRUE if successful, #FALSE otherwise.
228  *
229  **/
230 gboolean
231 atspi_selection_clear_selection (AtspiSelection *obj, GError **error)
232 {
233   dbus_bool_t retval = FALSE;
234   
235   g_return_val_if_fail (obj != NULL, FALSE);
236
237   _atspi_dbus_call (obj, atspi_interface_selection, "ClearSelection", error, "=>b", &retval);
238
239   return retval;
240 }
241
242 static void
243 atspi_selection_base_init (AtspiSelection *klass)
244 {
245 }
246
247 GType
248 atspi_selection_get_type (void)
249 {
250   static GType type = 0;
251
252   if (!type) {
253     static const GTypeInfo tinfo =
254     {
255       sizeof (AtspiSelection),
256       (GBaseInitFunc) atspi_selection_base_init,
257       (GBaseFinalizeFunc) NULL,
258     };
259
260     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiSelection", &tinfo, 0);
261
262   }
263   return type;
264 }