Add AtspitableCell, tracking the new atk interface
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / table-cell-adaptor.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2013 SUSE LLC.
6  * Copyright 2001, 2002 Sun Microsystems Inc.,
7  * Copyright 2001, 2002 Ximian, 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 <atk/atk.h>
26 #include <droute/droute.h>
27
28 #include "spi-dbus.h"
29 #include "object.h"
30 #include "introspection.h"
31
32 static dbus_bool_t
33 impl_get_ColumnSpan (DBusMessageIter * iter, void *user_data)
34 {
35   AtkTableCell *cell = (AtkTableCell *) user_data;
36   g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data), FALSE);
37   return droute_return_v_int32 (iter, atk_table_cell_get_column_span (cell));
38 }
39
40 static DBusMessage *
41 message_from_object_array (DBusMessage *message, GPtrArray *array)
42 {
43   DBusMessage *reply;
44   DBusMessageIter iter, iter_array;
45   gint len;
46   gint i;
47
48   reply = dbus_message_new_method_return (message);
49   if (!reply)
50     return NULL;
51
52   dbus_message_iter_init_append (reply, &iter);
53
54   if (!dbus_message_iter_open_container
55       (&iter, DBUS_TYPE_ARRAY, "(so)", &iter_array))
56     return reply; /* TODO: handle out of memory */
57   len = (array? array->len: 0);
58   for (i = 0; i < len; i++)
59   {
60     spi_object_append_reference (&iter_array, g_ptr_array_index (array, i));
61   }
62   dbus_message_iter_close_container (&iter, &iter_array);
63   g_ptr_array_unref (array);
64   return message;
65 }
66
67 static DBusMessage *
68 impl_GetColumnHeaderCells (DBusConnection * bus, DBusMessage * message,
69                         void *user_data)
70 {
71   AtkTableCell *cell = user_data;
72   GPtrArray *array;
73
74   g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data),
75                         droute_not_yet_handled_error (message));
76
77   array = atk_table_cell_get_column_header_cells (cell);
78   return message_from_object_array (message, array);
79 }
80
81 static dbus_bool_t
82 impl_get_RowSpan (DBusMessageIter * iter, void *user_data)
83 {
84   AtkTableCell *cell = (AtkTableCell *) user_data;
85   g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data), FALSE);
86   return droute_return_v_int32 (iter, atk_table_cell_get_row_span (cell));
87 }
88
89 static DBusMessage *
90 impl_GetRowHeaderCells (DBusConnection * bus, DBusMessage * message,
91                         void *user_data)
92 {
93   AtkTableCell *cell = user_data;
94   GPtrArray *array;
95
96   g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data),
97                         droute_not_yet_handled_error (message));
98
99   array = atk_table_cell_get_row_header_cells (cell);
100   return message_from_object_array (message, array);
101 }
102
103 static dbus_bool_t
104 impl_get_Position (DBusMessageIter * iter, void *user_data)
105 {
106   AtkTableCell *cell = (AtkTableCell *) user_data;
107   gint row = -1, column = -1;
108   dbus_int32_t d_row, d_column;
109   DBusMessageIter iter_struct, iter_variant;
110
111   g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data), FALSE);
112   if (!atk_table_cell_get_position (cell, &row, &column))
113     return FALSE;
114
115   d_row = row;
116   d_column = column;
117   dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, "(ii)", &iter_variant);
118   dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_STRUCT, NULL, &iter_struct);
119   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &row);
120   dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &column);
121   dbus_message_iter_close_container (&iter_variant, &iter_struct);
122   dbus_message_iter_close_container (iter, &iter_variant);
123   return TRUE;
124 }
125
126 static dbus_bool_t
127 impl_get_Table (DBusMessageIter * iter, void *user_data)
128 {
129   AtkTableCell *cell = (AtkTableCell *) user_data;
130   AtkObject *table;
131
132   g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data), FALSE);
133
134   table = atk_table_cell_get_table (cell);
135   if (!table)
136     return FALSE;
137   spi_object_append_reference (iter, table);
138   return TRUE;
139 }
140
141 static DBusMessage *
142 impl_GetRowColumnSpan (DBusConnection * bus, DBusMessage * message,
143                           void *user_data)
144 {
145   AtkTableCell *cell = (AtkTableCell *) user_data;
146   gint row, column, row_span, column_span;
147   dbus_int32_t d_row, d_column, d_row_span, d_column_span;
148   DBusMessage *reply;
149
150   g_return_val_if_fail (ATK_IS_TABLE (user_data),
151                         droute_not_yet_handled_error (message));
152   atk_table_cell_get_row_column_span (cell, &row, &column, &row_span,
153                                          &column_span);
154   d_row = row;
155   d_column = column;
156   d_row_span = row_span;
157   d_column_span = column_span;
158   reply = dbus_message_new_method_return (message);
159   if (reply)
160     {
161       dbus_message_append_args (reply, DBUS_TYPE_INT32, &d_row, DBUS_TYPE_INT32,
162                                 &d_column, DBUS_TYPE_INT32, &d_row_span,
163                                 DBUS_TYPE_INT32, &d_column_span,
164                                 DBUS_TYPE_INVALID);
165     }
166   return reply;
167 }
168
169 static DRouteMethod methods[] = {
170   {impl_GetRowHeaderCells, "GetRowHeaderCells"},
171   {impl_GetColumnHeaderCells, "GetColumnHeaderCells"},
172   {impl_GetRowColumnSpan, "GetRowColumnSpan"},
173   {NULL, NULL}
174 };
175
176 static DRouteProperty properties[] = {
177   {impl_get_ColumnSpan, NULL, "ColumnSpan"},
178   {impl_get_Position, NULL, "Position"},
179   {impl_get_RowSpan, NULL, "RowSpan"},
180   {impl_get_Table, NULL, "Table"},
181   {NULL, NULL, NULL}
182 };
183
184 void
185 spi_initialize_table_cell (DRoutePath * path)
186 {
187   droute_path_add_interface (path,
188                              ATSPI_DBUS_INTERFACE_TABLE_CELL,
189                              spi_org_a11y_atspi_TableCell,
190                              methods, properties);
191 };