Remove dependency on libxkbcommon
[platform/upstream/at-spi2-core.git] / atspi / atspi-table-cell.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 2013 SUSE LLC.
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 <stdlib.h> /* for malloc */
26 #include "atspi-private.h"
27
28 static GPtrArray *
29 get_object_array_and_unref (DBusMessage *reply)
30 {
31   DBusMessageIter iter, iter_array;
32   GPtrArray *array;
33
34   if (!reply)
35     return NULL;
36
37   if (strcmp (dbus_message_get_signature (reply), "(so)") != 0)
38   {
39     dbus_message_unref (reply);
40     return NULL;
41   }
42
43   array = g_ptr_array_new ();
44
45   dbus_message_iter_init (reply, &iter);
46   dbus_message_iter_recurse (&iter, &iter_array);
47   while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
48   {
49     AtspiAccessible *accessible = _atspi_dbus_return_accessible_from_iter (&iter_array);
50     g_ptr_array_add (array, accessible);
51   }
52   dbus_message_unref (reply);
53   return array;
54 }
55
56 /**
57  * atspi_table_cell_get_column_span:
58  * @obj: a GObject instance that implements AtspiTableCellIface
59  *
60  * Returns the number of columns occupied by this cell accessible.
61  *
62  * Returns: a gint representing the number of columns occupied by this cell,
63  * or 0 if the cell does not implement this method.
64  */
65 gint
66 atspi_table_cell_get_column_span (AtspiTableCell *obj, GError **error)
67 {
68   dbus_int32_t retval = -1;
69
70   g_return_val_if_fail (obj != NULL, -1);
71
72   _atspi_dbus_get_property (obj, atspi_interface_table_cell, "ColumnSpan",
73                             error, "i", &retval);
74           
75   return retval;
76 }
77
78 /**
79  * atspi_table_cell_get_column_header_cells:
80  * @obj: a GObject instance that implements AtspiTableCellIface
81  *
82  * Returns the column headers as an array of cell accessibles.
83  *
84  * Returns: (element-type AtspiAccessible) (transfer full): a GPtrArray of
85  * AtspiAccessibles representing the column header cells.
86   */
87 GPtrArray *
88 atspi_table_cell_get_column_header_cells (AtspiTableCell *obj, GError **error)
89 {
90   DBusMessage *reply;
91
92   g_return_val_if_fail (obj != NULL, NULL);
93
94   reply = _atspi_dbus_call_partial (obj, atspi_interface_table_cell, "GetColumnHeaderCells", error, "");
95           
96   return get_object_array_and_unref (reply);
97 }
98
99 /**
100  * atspi_table_cell_get_row_span:
101  * @obj: a GObject instance that implements AtspiTableCellIface
102  *
103  * Returns the number of rows occupied by this cell accessible.
104  *
105  * Returns: a gint representing the number of rows occupied by this cell,
106  * or 0 if the cell does not implement this method.
107  */
108 gint
109 atspi_table_cell_get_row_span (AtspiTableCell *obj, GError **error)
110 {
111   dbus_int32_t retval = -1;
112
113   g_return_val_if_fail (obj != NULL, -1);
114
115   _atspi_dbus_get_property (obj, atspi_interface_table_cell, "RowSpan",
116                             error, "i", &retval);
117           
118   return retval;
119 }
120
121 /**
122  * atspi_table_cell_get_row_header_cells:
123  * @obj: a GObject instance that implements AtspiTableCellIface
124  *
125  * Returns the row headers as an array of cell accessibles.
126  *
127  * Returns: (element-type AtspiAccessible) (transfer full): a GPtrArray of
128  * AtspiAccessibles representing the row header cells.
129  */
130 GPtrArray *
131 atspi_table_cell_get_row_header_cells (AtspiTableCell *obj, GError **error)
132 {
133   DBusMessage *reply;
134
135   g_return_val_if_fail (obj != NULL, NULL);
136
137   reply = _atspi_dbus_call_partial (obj, atspi_interface_table_cell, "GetRowHeaderCells", error, "");
138           
139   return get_object_array_and_unref (reply);
140 }
141
142 /**
143  * atspi_table_cell_get_position:
144  * @obj: a GObject instance that implements AtspiTableCellIface
145  * @row: (out): the row of the given cell.
146  * @column: (out): the column of the given cell.
147  *
148  * Retrieves the tabular position of this cell.
149  *
150  * Returns: TRUE if successful, FALSE otherwise.
151  */
152 gint
153 atspi_table_cell_get_position (AtspiTableCell *obj,
154                                gint *row,
155                                gint *column,
156                                GError **error)
157 {
158   DBusMessage *reply;
159   DBusMessageIter iter, iter_struct, iter_variant;
160   dbus_int32_t d_row = -1, d_column = -1;
161   char *iter_sig;
162
163   g_return_val_if_fail (obj != NULL, -1);
164
165   reply = _atspi_dbus_call_partial (obj, "org.freedesktop.DBus.Properties",
166                                     "Get", error, "ss",
167                                     atspi_interface_table_cell, "Position");
168           
169   if (!reply)
170     return -1;
171
172   dbus_message_iter_init (reply, &iter);
173
174   /* TODO: Return error here */
175   if (dbus_message_iter_get_arg_type (&iter) != 'v')
176     return FALSE;
177
178   dbus_message_iter_recurse (&iter, &iter_variant);
179   iter_sig = dbus_message_iter_get_signature (&iter_variant);
180   /* TODO: Also report error here */
181   if (strcmp (iter_sig, "(ii)") != 0)
182   {
183     dbus_free (iter_sig);
184     return FALSE;
185   }
186   dbus_free (iter_sig);
187
188   dbus_message_iter_recurse (&iter_variant, &iter_struct);
189   dbus_message_iter_get_basic (&iter_struct, &d_row);
190   if (row)
191     *row = d_row;
192   dbus_message_iter_next (&iter_struct);
193   dbus_message_iter_get_basic (&iter_struct, &d_column);
194   if (column)
195     *column = d_column;
196   dbus_message_unref (reply);
197   return TRUE;
198 }
199
200 /**
201  * atspi_table_cell_get_row_column_span:
202  * @obj: a GObject instance that implements AtspiTableCellIface
203  * @row: (out): the row index of the given cell.
204  * @column: (out): the column index of the given cell.
205  * @row_span: (out): the number of rows occupied by this cell.
206  * @column_span: (out): the number of columns occupied by this cell.
207  *
208  * Gets the row and column indexes and extents of this cell accessible.
209  */
210 void
211 atspi_table_cell_get_row_column_span (AtspiTableCell *obj,
212                                        gint *row,
213                                        gint *column,
214                                        gint *row_span,
215                                        gint *column_span,
216                                        GError **error)
217 {
218   dbus_int32_t d_row = 0,  d_column = 0, d_row_span = 0, d_column_span = 0;
219
220   if (row)
221     *row = -1;
222   if (column)
223     *column = -1;
224   if (row_span)
225     *row_span = -1;
226   if (column_span)
227     *column_span = -1;
228
229   g_return_if_fail (obj != NULL);
230
231   _atspi_dbus_call (obj, atspi_interface_table_cell, "GetRowColumnSpan",
232                     error, "=>iiii", &d_row, &d_column,
233                     &d_row_span, &d_column_span);
234
235   if (row)
236     *row = d_row;
237   if (column)
238     *column = d_column;
239   if (row_span)
240     *row_span = d_row_span;
241   if (column_span)
242     *column_span = d_column_span;
243 }
244
245 /**
246  * atspi_table_cell_get_table:
247  * @obj: a GObject instance that implements AtspiTableCellIface
248  *
249  * Returns a reference to the accessible of the containing table.
250  *
251  * Returns: (transfer full): the AtspiAccessible for the containing table.
252  */
253 AtspiAccessible *
254 atspi_table_cell_get_table (AtspiTableCell *obj, GError **error)
255 {
256   AtspiAccessible *retval = NULL;
257
258   g_return_val_if_fail (obj != NULL, NULL);
259
260   _atspi_dbus_get_property (obj, atspi_interface_table_cell, "Table",
261                             error, "(so)", &retval);
262           
263   return retval;
264 }
265
266 static void
267 atspi_table_cell_base_init (AtspiTableCell *klass)
268 {
269 }
270
271 GType
272 atspi_table_cell_get_type (void)
273 {
274   static GType type = 0;
275
276   if (!type) {
277     static const GTypeInfo tinfo =
278     {
279       sizeof (AtspiTableCell),
280       (GBaseInitFunc) atspi_table_cell_base_init,
281       (GBaseFinalizeFunc) NULL,
282     };
283
284     type = g_type_register_static (G_TYPE_INTERFACE, "AtspiTableCell", &tinfo, 0);
285
286   }
287   return type;
288 }