Fixing traverse recurse/restrict documentations
[platform/upstream/at-spi2-core.git] / atspi / atspi-collection.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2007 IBM Corp.
6  * Copyright 2010, 2011 Novell, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include "atspi-private.h"
25
26 /* TODO: Improve documentation and implement some missing functions */
27
28 /**
29  * atspi_collection_is_ancestor_of:
30  *
31  * Not yet implemented.
32  *
33  **/
34 gboolean
35 atspi_collection_is_ancestor_of (AtspiCollection *collection,
36                                  AtspiAccessible *test,
37                                  GError **error)
38 {
39   g_warning ("Atspi: TODO: Implement is_ancestor_of");
40   return FALSE;
41 }
42
43 static DBusMessage *
44 new_message (AtspiCollection *collection, char *method)
45 {
46   AtspiAccessible *accessible;
47
48   if (!collection)
49     return NULL;
50
51   accessible = ATSPI_ACCESSIBLE (collection);
52   return dbus_message_new_method_call (accessible->parent.app->bus_name,
53                                        accessible->parent.path,
54                                        atspi_interface_collection,
55                                        method);
56 }
57
58 static gboolean
59 append_match_rule (DBusMessage *message, AtspiMatchRule *rule)
60 {
61   DBusMessageIter iter;
62
63   dbus_message_iter_init_append (message, &iter);
64   return _atspi_match_rule_marshal (rule, &iter);
65 }
66
67 static gboolean
68 append_accessible (DBusMessage *message, AtspiAccessible *accessible)
69 {
70   DBusMessageIter iter;
71
72   dbus_message_iter_init_append (message, &iter);
73   dbus_message_iter_append_basic (&iter, DBUS_TYPE_OBJECT_PATH,
74                                   &accessible->parent.path);
75   return TRUE;  /* TODO: Check for out-of-memory */
76 }
77
78 static GArray *
79 return_accessibles (DBusMessage *message)
80 {
81   DBusMessageIter iter, iter_array;
82   GArray *ret = g_array_new (TRUE, TRUE, sizeof (AtspiAccessible *));
83
84   _ATSPI_DBUS_CHECK_SIG (message, "a(so)", NULL, NULL);
85
86   dbus_message_iter_init (message, &iter);
87   dbus_message_iter_recurse (&iter, &iter_array);
88
89   while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
90   {
91     AtspiAccessible *accessible;
92     GArray *new_array;
93     accessible = _atspi_dbus_return_accessible_from_iter (&iter_array);
94     new_array = g_array_append_val (ret, accessible);
95     if (new_array)
96       ret = new_array;
97     /* Iter was moved already, so no need to call dbus_message_iter_next */
98   }
99   dbus_message_unref (message);
100   return ret;
101 }
102
103 /**
104  * atspi_collection_get_matches:
105  *
106  * @collection: A pointer to the #AtspiCollection to query.
107  *
108  * @rule: An #AtspiMatchRule describing the match criteria.
109  *
110  * @sortby: An #AtspiCollectionSortOrder specifying the way the results are to
111  *          be sorted.
112  *
113  * @count: The maximum number of results to return, or 0 for no limit.
114  *
115  * @traverse: Not supported.
116  *
117  * Gets all #AtspiAccessible objects from the @collection matching a given
118  * @rule.  
119  *
120  * Returns: (element-type AtspiAccessible*) (transfer full): All 
121  *          #AtspiAccessible objects matching the given match rule.
122  **/
123 GArray *
124 atspi_collection_get_matches (AtspiCollection *collection,
125                               AtspiMatchRule *rule,
126                               AtspiCollectionSortOrder sortby,
127                               gint count,
128                               gboolean traverse,
129                               GError **error)
130 {
131   DBusMessage *message = new_message (collection, "GetMatches");
132   DBusMessage *reply;
133   dbus_int32_t d_sortby = sortby;
134   dbus_int32_t d_count = count;
135   dbus_bool_t d_traverse = traverse;
136
137   if (!message)
138     return NULL;
139
140   if (!append_match_rule (message, rule))
141     return NULL;
142   dbus_message_append_args (message, DBUS_TYPE_UINT32, &d_sortby,
143                             DBUS_TYPE_INT32, &d_count,
144                             DBUS_TYPE_BOOLEAN, &d_traverse,
145                             DBUS_TYPE_INVALID);
146   reply = _atspi_dbus_send_with_reply_and_block (message, error);
147   if (!reply)
148     return NULL;
149   return return_accessibles (reply);
150 }
151
152 /**
153  * atspi_collection_get_matches_to:
154  *
155  * @collection: A pointer to the #AtspiCollection to query.
156  *
157  * @current_object: The object at which to start searching.
158  *
159  * @rule: An #AtspiMatchRule describing the match criteria.
160  *
161  * @sortby: An #AtspiCollectionSortOrder specifying the way the results are to
162  *          be sorted.
163  *
164  * @tree: An #AtspiCollectionTreeTraversalType specifying restrictions on
165  *        the objects to be traversed.
166  *
167  * @restrict: If #TRUE, only descendants of @current_object's parent
168  * will be returned. Otherwise (if #FALSE), any accessible may be returned
169  * if it would preceed @current_object in a flattened hierarchy.
170  *
171  * @count: The maximum number of results to return, or 0 for no limit.
172  *
173  * @traverse: Not supported.
174  *
175  * Gets all #AtspiAccessible objects from the @collection, after 
176  * @current_object, matching a given @rule.  
177  *
178  * Returns: (element-type AtspiAccessible*) (transfer full): All
179  *          #AtspiAccessible objects matching the given match rule after
180  *          @current_object.
181  **/
182 GArray *
183 atspi_collection_get_matches_to (AtspiCollection *collection,
184                               AtspiAccessible *current_object,
185                               AtspiMatchRule *rule,
186                               AtspiCollectionSortOrder sortby,
187                               AtspiCollectionTreeTraversalType tree,
188                               gboolean restrict,
189                               gint count,
190                               gboolean traverse,
191                               GError **error)
192 {
193   DBusMessage *message = new_message (collection, "GetMatchesTo");
194   DBusMessage *reply;
195   dbus_int32_t d_sortby = sortby;
196   dbus_int32_t d_tree = tree;
197   dbus_bool_t d_restrict = restrict;
198   dbus_int32_t d_count = count;
199   dbus_bool_t d_traverse = traverse;
200
201   if (!message)
202     return NULL;
203
204   if (!append_accessible (message, current_object))
205     return NULL;
206   if (!append_match_rule (message, rule))
207     return NULL;
208   dbus_message_append_args (message, DBUS_TYPE_UINT32, &d_sortby,
209                                      DBUS_TYPE_UINT32, &d_tree,
210                             DBUS_TYPE_BOOLEAN, &d_restrict,
211                             DBUS_TYPE_INT32, &d_count,
212                             DBUS_TYPE_BOOLEAN, &d_traverse,
213                             DBUS_TYPE_INVALID);
214   reply = _atspi_dbus_send_with_reply_and_block (message, error);
215   if (!reply)
216     return NULL;
217   return return_accessibles (reply);
218 }
219
220 /**
221  * atspi_collection_get_matches_from:
222  *
223  * @collection: A pointer to the #AtspiCollection to query.
224  *
225  * @current_object: Upon reaching this object, searching should stop.
226  *
227  * @rule: An #AtspiMatchRule describing the match criteria.
228  *
229  * @sortby: An #AtspiCollectionSortOrder specifying the way the results are to
230  *          be sorted.
231  *
232  * @tree: An #AtspiCollectionTreeTraversalType specifying restrictions on
233  *        the objects to be traversed.
234  *
235  * @count: The maximum number of results to return, or 0 for no limit.
236  *
237  * @traverse: Not supported.
238  *
239  * Gets all #AtspiAccessible objects from the @collection, before  
240  * @current_object, matching a given @rule.  
241  *
242  * Returns: (element-type AtspiAccessible*) (transfer full): All 
243  *          #AtspiAccessible objects matching the given match rule that preceed
244  *          @current_object.
245  **/
246 GArray *
247 atspi_collection_get_matches_from (AtspiCollection *collection,
248                               AtspiAccessible *current_object,
249                               AtspiMatchRule *rule,
250                               AtspiCollectionSortOrder sortby,
251                               AtspiCollectionTreeTraversalType tree,
252                               gint count,
253                               gboolean traverse,
254                               GError **error)
255 {
256   DBusMessage *message = new_message (collection, "GetMatchesFrom");
257   DBusMessage *reply;
258   dbus_int32_t d_sortby = sortby;
259   dbus_int32_t d_tree = tree;
260   dbus_int32_t d_count = count;
261   dbus_bool_t d_traverse = traverse;
262
263   if (!message)
264     return NULL;
265
266   if (!append_accessible (message, current_object))
267     return NULL;
268   if (!append_match_rule (message, rule))
269     return NULL;
270   dbus_message_append_args (message, DBUS_TYPE_UINT32, &d_sortby,
271                             DBUS_TYPE_UINT32, &d_tree,
272                             DBUS_TYPE_INT32, &d_count,
273                             DBUS_TYPE_BOOLEAN, &d_traverse,
274                             DBUS_TYPE_INVALID);
275   reply = _atspi_dbus_send_with_reply_and_block (message, error);
276   if (!reply)
277     return NULL;
278   return return_accessibles (reply);
279 }
280
281 /**
282  * atspi_collection_get_active_descendant:
283  *
284  * Not yet implemented.
285  **/
286 AtspiAccessible *
287 atspi_collection_get_active_descendant (AtspiCollection *collection, GError **error)
288 {
289   g_warning ("atspi: TODO: Implement get_active_descendants");
290   return NULL;
291 }
292
293 static void
294 atspi_collection_base_init (AtspiCollection *klass)
295 {
296 }
297
298 GType
299 atspi_collection_get_type (void)
300 {
301   static GType type = 0;
302
303   if (!type) {
304     static const GTypeInfo tinfo =
305     {
306       sizeof (AtspiCollection),
307       (GBaseInitFunc) atspi_collection_base_init,
308       (GBaseFinalizeFunc) NULL,
309     };
310
311     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiCollection", &tinfo, 0);
312
313   }
314   return type;
315 }