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 Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 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
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the
21
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
 * Boston, MA 02110-1301, USA.
23
 */
24

            
25
#include <atk/atk.h>
26
#include <droute/droute.h>
27

            
28
#include "spi-dbus.h"
29

            
30
#include "introspection.h"
31
#include "object.h"
32

            
33
static dbus_bool_t
34
impl_get_Version (DBusMessageIter *iter, void *user_data)
35
{
36
  return droute_return_v_uint32 (iter, SPI_DBUS_TABLE_CELL_VERSION);
37
}
38

            
39
static dbus_bool_t
40
3
impl_get_ColumnSpan (DBusMessageIter *iter, void *user_data)
41
{
42
3
  AtkTableCell *cell = (AtkTableCell *) user_data;
43
3
  g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data), FALSE);
44
3
  return droute_return_v_int32 (iter, atk_table_cell_get_column_span (cell));
45
}
46

            
47
static DBusMessage *
48
message_from_object_array (DBusMessage *message, GPtrArray *array)
49
{
50
  DBusMessage *reply;
51
  DBusMessageIter iter, iter_array;
52
  gint len;
53
  gint i;
54

            
55
  reply = dbus_message_new_method_return (message);
56
  if (!reply)
57
    return NULL;
58

            
59
  dbus_message_iter_init_append (reply, &iter);
60

            
61
  if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(so)", &iter_array))
62
    return reply; /* TODO: handle out of memory */
63
  len = (array ? array->len : 0);
64
  for (i = 0; i < len; i++)
65
    {
66
      spi_object_append_reference (&iter_array, g_ptr_array_index (array, i));
67
    }
68
  dbus_message_iter_close_container (&iter, &iter_array);
69
  if (array)
70
    g_ptr_array_unref (array);
71
  return reply;
72
}
73

            
74
static DBusMessage *
75
impl_GetColumnHeaderCells (DBusConnection *bus, DBusMessage *message, void *user_data)
76
{
77
  AtkTableCell *cell = user_data;
78
  GPtrArray *array;
79

            
80
  g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data),
81
                        droute_not_yet_handled_error (message));
82

            
83
  array = atk_table_cell_get_column_header_cells (cell);
84
  return message_from_object_array (message, array);
85
}
86

            
87
static dbus_bool_t
88
1
impl_get_RowSpan (DBusMessageIter *iter, void *user_data)
89
{
90
1
  AtkTableCell *cell = (AtkTableCell *) user_data;
91
1
  g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data), FALSE);
92
1
  return droute_return_v_int32 (iter, atk_table_cell_get_row_span (cell));
93
}
94

            
95
static DBusMessage *
96
impl_GetRowHeaderCells (DBusConnection *bus, DBusMessage *message, void *user_data)
97
{
98
  AtkTableCell *cell = user_data;
99
  GPtrArray *array;
100

            
101
  g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data),
102
                        droute_not_yet_handled_error (message));
103

            
104
  array = atk_table_cell_get_row_header_cells (cell);
105
  return message_from_object_array (message, array);
106
}
107

            
108
static dbus_bool_t
109
1
impl_get_Position (DBusMessageIter *iter, void *user_data)
110
{
111
1
  AtkTableCell *cell = (AtkTableCell *) user_data;
112
1
  gint row = -1, column = -1;
113
  DBusMessageIter iter_struct, iter_variant;
114

            
115
1
  g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data), FALSE);
116
1
  if (!atk_table_cell_get_position (cell, &row, &column))
117
    return FALSE;
118

            
119
1
  dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(ii)", &iter_variant);
120
1
  dbus_message_iter_open_container (&iter_variant, DBUS_TYPE_STRUCT, NULL, &iter_struct);
121
1
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, (dbus_int32_t *) &row);
122
1
  dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, (dbus_int32_t *) &column);
123
1
  dbus_message_iter_close_container (&iter_variant, &iter_struct);
124
1
  dbus_message_iter_close_container (iter, &iter_variant);
125
1
  return TRUE;
126
}
127

            
128
static dbus_bool_t
129
1
impl_get_Table (DBusMessageIter *iter, void *user_data)
130
{
131
1
  AtkTableCell *cell = (AtkTableCell *) user_data;
132
  AtkObject *table;
133
  DBusMessageIter iter_variant;
134

            
135
1
  g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data), FALSE);
136

            
137
1
  table = atk_table_cell_get_table (cell);
138
1
  if (!table)
139
    return FALSE;
140
1
  dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(so)", &iter_variant);
141
1
  spi_object_append_reference (&iter_variant, table);
142
1
  dbus_message_iter_close_container (iter, &iter_variant);
143
1
  return TRUE;
144
}
145

            
146
static DBusMessage *
147
1
impl_GetRowColumnSpan (DBusConnection *bus, DBusMessage *message, void *user_data)
148
{
149
1
  AtkTableCell *cell = (AtkTableCell *) user_data;
150
  gint row, column, row_span, column_span;
151
  dbus_int32_t d_row, d_column, d_row_span, d_column_span;
152
  DBusMessage *reply;
153

            
154
1
  g_return_val_if_fail (ATK_IS_TABLE_CELL (user_data),
155
                        droute_not_yet_handled_error (message));
156
1
  atk_table_cell_get_row_column_span (cell, &row, &column, &row_span,
157
                                      &column_span);
158
1
  d_row = row;
159
1
  d_column = column;
160
1
  d_row_span = row_span;
161
1
  d_column_span = column_span;
162
1
  reply = dbus_message_new_method_return (message);
163
1
  if (reply)
164
    {
165
1
      dbus_message_append_args (reply, DBUS_TYPE_INT32, &d_row, DBUS_TYPE_INT32,
166
                                &d_column, DBUS_TYPE_INT32, &d_row_span,
167
                                DBUS_TYPE_INT32, &d_column_span,
168
                                DBUS_TYPE_INVALID);
169
    }
170
1
  return reply;
171
}
172

            
173
static DRouteMethod methods[] = {
174
  { impl_GetRowHeaderCells, "GetRowHeaderCells" },
175
  { impl_GetColumnHeaderCells, "GetColumnHeaderCells" },
176
  { impl_GetRowColumnSpan, "GetRowColumnSpan" },
177
  { NULL, NULL }
178
};
179

            
180
static DRouteProperty properties[] = {
181
  { impl_get_ColumnSpan, NULL, "ColumnSpan" },
182
  { impl_get_Position, NULL, "Position" },
183
  { impl_get_RowSpan, NULL, "RowSpan" },
184
  { impl_get_Table, NULL, "Table" },
185
  { impl_get_Version, NULL, "version" },
186
  { NULL, NULL, NULL }
187
};
188

            
189
void
190
161
spi_initialize_table_cell (DRoutePath *path)
191
{
192
161
  droute_path_add_interface (path,
193
                             ATSPI_DBUS_INTERFACE_TABLE_CELL,
194
                             spi_org_a11y_atspi_TableCell,
195
                             methods, properties);
196
161
};