2d1c5688342a9bd01d34c1b038ce31c2b38920a2
[platform/upstream/at-spi2-atk.git] / tests / dummyatk / my-atk-table-cell.c
1 /*
2  * Copyright 2008 Codethink Ltd.
3  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <glib.h>
22 #include <string.h>
23 #include <atk/atk.h>
24
25 #include "my-atk-object.h"
26 #include "my-atk-table.h"
27 #include "my-atk-table-cell.h"
28
29 typedef struct _MyAtkTableCellInfo MyAtkTableCellInfo;
30
31 static void atk_tablecell_interface_init (AtkTableCellIface *iface);
32
33 G_DEFINE_TYPE_WITH_CODE (MyAtkTableCell,
34                          my_atk_tablecell,
35                          MY_TYPE_ATK_OBJECT,
36                          G_IMPLEMENT_INTERFACE (ATK_TYPE_TABLE_CELL,
37                              atk_tablecell_interface_init));
38
39 gboolean
40 my_atk_set_table_cell (AtkTableCell *cell, gint x, gint y, gint row_span, gint column_span)
41 {
42   g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (cell), FALSE);
43   MyAtkTableCell *self = MY_ATK_TABLE_CELL (cell);
44
45   self->x = x;
46   self->y = y;
47   self->row_span = row_span;
48   self->column_span = column_span;
49
50   /* Default value for span is 1, so that condition is needed */
51   if (row_span == 0)
52     self->row_span = 1;
53   if (column_span == 0)
54     self->column_span = 1;
55
56   return TRUE;
57
58 }
59 gboolean
60 my_atk_set_tablecell (MyAtkTableCell *self, gpointer value, const gchar *row_desc, MyAtkObject *parent_table, gboolean selected, gint *xy)
61 {
62   self->value = value;
63   self->row_desc = g_strdup (row_desc);
64   self->parent_table = parent_table;
65   self->selected = selected;
66
67   memcpy (self->xy, xy, sizeof (self->xy));
68   return TRUE;
69 }
70
71 static gint
72 my_atk_tablecell_get_column_span (AtkTableCell *obj)
73 {
74   g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), -1);
75   MyAtkTableCell *self = MY_ATK_TABLE_CELL (obj);
76   return self->column_span;
77 }
78
79 static gboolean
80 my_atk_tablecell_get_row_column_span (AtkTableCell *obj, gint *row, gint *col, gint *row_span, gint *col_span)
81 {
82   g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), FALSE);
83   MyAtkTableCell *self = MY_ATK_TABLE_CELL (obj);
84   *col = self->x;
85   *row = self->y;
86   *row_span = self->row_span;
87   *col_span = self->column_span;
88   return TRUE;
89 }
90
91 static GPtrArray *
92 my_atk_tablecell_get_column_header_cells (AtkTableCell *obj)
93 {
94   g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), FALSE);
95   MyAtkTable *tab = MY_ATK_TABLE (atk_object_get_parent (ATK_OBJECT (obj)));
96
97   gint i, all_child;
98   all_child = MY_ATK_OBJECT (tab)->children->len;
99   AtkObject *child = NULL;
100   GPtrArray *ret = g_ptr_array_new_full (atk_table_get_n_columns ATK_TABLE (tab), g_object_unref);
101
102   for (i = 0; i < all_child; i++) {
103     child = atk_object_ref_accessible_child (ATK_OBJECT (tab), i);
104     if (atk_object_get_role (child) == ATK_ROLE_TABLE_COLUMN_HEADER) {
105       g_ptr_array_add (ret, child);
106     }
107   }
108
109   return ret;
110 }
111
112 static AtkObject *
113 my_atk_tablecell_get_table (AtkTableCell *obj)
114 {
115   g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), NULL);
116
117   return atk_object_get_parent (ATK_OBJECT (obj));
118 }
119
120 static gint
121 my_atk_tablecell_get_row_span (AtkTableCell *obj)
122 {
123   g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), -1);
124   MyAtkTableCell *self = MY_ATK_TABLE_CELL (obj);
125   return self->row_span;
126 }
127
128 static gboolean
129 my_atk_tablecell_get_position (AtkTableCell *obj, gint *row , gint *column)
130 {
131   MyAtkTableCell *self = MY_ATK_TABLE_CELL (obj);
132   g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), FALSE);
133
134   *row = self->xy[0];
135   *column = self->xy[1];
136
137   return FALSE;
138 }
139
140 static GPtrArray *
141 my_atk_tablecell_get_row_header_cells (AtkTableCell *obj)
142 {
143   g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), FALSE);
144   MyAtkTable *tab = MY_ATK_TABLE (atk_object_get_parent (ATK_OBJECT (obj)));
145
146   gint i, all_child;
147   all_child = MY_ATK_OBJECT (tab)->children->len;
148   AtkObject *child = NULL;
149   GPtrArray *ret = g_ptr_array_new_full (atk_table_get_n_columns ATK_TABLE (tab), g_object_unref);
150
151   for (i = 0; i < all_child; i++) {
152     child = atk_object_ref_accessible_child (ATK_OBJECT (tab), i);
153     if (atk_object_get_role (child) == ATK_ROLE_TABLE_ROW_HEADER) {
154       g_ptr_array_add (ret, child);
155     }
156   }
157
158   return ret;
159 }
160
161 static void
162 atk_tablecell_interface_init (AtkTableCellIface *iface)
163 {
164   if (!iface) return;
165   iface->get_column_span = my_atk_tablecell_get_column_span;
166   iface->get_column_header_cells = my_atk_tablecell_get_column_header_cells;
167   iface->get_position = my_atk_tablecell_get_position;
168   iface->get_row_span = my_atk_tablecell_get_row_span;
169   iface->get_row_header_cells = my_atk_tablecell_get_row_header_cells;
170   iface->get_row_column_span = my_atk_tablecell_get_row_column_span;
171   iface->get_table = my_atk_tablecell_get_table;
172 }
173
174 static void
175 my_atk_tablecell_init (MyAtkTableCell *self)
176 {
177   self->value = NULL;
178   self->parent_table = NULL;
179   self->row_desc = NULL;
180   self->selected = FALSE;
181   memset (self->xy, -1, sizeof (self->xy));
182   self->column_span = 1;
183   self->row_span = 1;
184   self->x = -1;
185   self->y = -1;
186   self->column_index = -1;
187 }
188
189 static void
190 my_atk_tablecell_class_initialize (AtkObject *obj, gpointer data)
191 {
192 }
193
194 static void
195 my_atk_tablecell_class_finalize (GObject *obj)
196 {
197 }
198
199 static void
200 my_atk_tablecell_class_init (MyAtkTableCellClass *my_class)
201 {
202   AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class);
203   GObjectClass *gobject_class = G_OBJECT_CLASS (my_class);
204
205   gobject_class->finalize = my_atk_tablecell_class_finalize;
206
207   atk_class->initialize = my_atk_tablecell_class_initialize;
208 }