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

            
21
#include <atk/atk.h>
22
#include <glib.h>
23
#include <string.h>
24

            
25
#include "my-atk-object.h"
26
#include "my-atk-table-cell.h"
27
#include "my-atk-table.h"
28

            
29
typedef struct _MyAtkTableCellInfo MyAtkTableCellInfo;
30

            
31
static void atk_tablecell_interface_init (AtkTableCellIface *iface);
32

            
33
32
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
384
my_atk_set_table_cell (AtkTableCell *cell, gint x, gint y, gint row_span, gint column_span)
41
{
42
384
  g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (cell), FALSE);
43
384
  MyAtkTableCell *self = MY_ATK_TABLE_CELL (cell);
44

            
45
384
  self->x = x;
46
384
  self->y = y;
47
384
  self->row_span = row_span;
48
384
  self->column_span = column_span;
49

            
50
  /* Default value for span is 1, so that condition is needed */
51
384
  if (row_span == 0)
52
352
    self->row_span = 1;
53
384
  if (column_span == 0)
54
352
    self->column_span = 1;
55

            
56
384
  return TRUE;
57
}
58
gboolean
59
my_atk_set_tablecell (MyAtkTableCell *self, gpointer value, const gchar *row_desc, MyAtkObject *parent_table, gboolean selected, gint *xy)
60
{
61
  self->value = value;
62
  self->row_desc = g_strdup (row_desc);
63
  self->parent_table = parent_table;
64
  self->selected = selected;
65

            
66
  memcpy (self->xy, xy, sizeof (self->xy));
67
  return TRUE;
68
}
69

            
70
static gint
71
3
my_atk_tablecell_get_column_span (AtkTableCell *obj)
72
{
73
3
  g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), -1);
74
3
  MyAtkTableCell *self = MY_ATK_TABLE_CELL (obj);
75
3
  return self->column_span;
76
}
77

            
78
static gboolean
79
1
my_atk_tablecell_get_row_column_span (AtkTableCell *obj, gint *row, gint *col, gint *row_span, gint *col_span)
80
{
81
1
  g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), FALSE);
82
1
  MyAtkTableCell *self = MY_ATK_TABLE_CELL (obj);
83
1
  *col = self->x;
84
1
  *row = self->y;
85
1
  *row_span = self->row_span;
86
1
  *col_span = self->column_span;
87
1
  return TRUE;
88
}
89

            
90
static GPtrArray *
91
my_atk_tablecell_get_column_header_cells (AtkTableCell *obj)
92
{
93
  g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), FALSE);
94
  MyAtkTable *tab = MY_ATK_TABLE (atk_object_get_parent (ATK_OBJECT (obj)));
95

            
96
  gint i, all_child;
97
  all_child = MY_ATK_OBJECT (tab)->children->len;
98
  AtkObject *child = NULL;
99
  GPtrArray *ret = g_ptr_array_new_full (atk_table_get_n_columns ATK_TABLE (tab), g_object_unref);
100

            
101
  for (i = 0; i < all_child; i++)
102
    {
103
      child = atk_object_ref_accessible_child (ATK_OBJECT (tab), i);
104
      if (atk_object_get_role (child) == ATK_ROLE_TABLE_COLUMN_HEADER)
105
        {
106
          g_ptr_array_add (ret, child);
107
        }
108
    }
109

            
110
  return ret;
111
}
112

            
113
static AtkObject *
114
1
my_atk_tablecell_get_table (AtkTableCell *obj)
115
{
116
1
  g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), NULL);
117

            
118
1
  return atk_object_get_parent (ATK_OBJECT (obj));
119
}
120

            
121
static gint
122
1
my_atk_tablecell_get_row_span (AtkTableCell *obj)
123
{
124
1
  g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), -1);
125
1
  MyAtkTableCell *self = MY_ATK_TABLE_CELL (obj);
126
1
  return self->row_span;
127
}
128

            
129
static gboolean
130
1
my_atk_tablecell_get_position (AtkTableCell *obj, gint *row, gint *column)
131
{
132
1
  MyAtkTableCell *self = MY_ATK_TABLE_CELL (obj);
133
1
  g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), FALSE);
134

            
135
1
  *row = self->xy[0];
136
1
  *column = self->xy[1];
137

            
138
1
  return TRUE;
139
}
140

            
141
static GPtrArray *
142
my_atk_tablecell_get_row_header_cells (AtkTableCell *obj)
143
{
144
  g_return_val_if_fail (MY_IS_ATK_TABLE_CELL (obj), FALSE);
145
  MyAtkTable *tab = MY_ATK_TABLE (atk_object_get_parent (ATK_OBJECT (obj)));
146

            
147
  gint i, all_child;
148
  all_child = MY_ATK_OBJECT (tab)->children->len;
149
  AtkObject *child = NULL;
150
  GPtrArray *ret = g_ptr_array_new_full (atk_table_get_n_columns ATK_TABLE (tab), g_object_unref);
151

            
152
  for (i = 0; i < all_child; i++)
153
    {
154
      child = atk_object_ref_accessible_child (ATK_OBJECT (tab), i);
155
      if (atk_object_get_role (child) == ATK_ROLE_TABLE_ROW_HEADER)
156
        {
157
          g_ptr_array_add (ret, child);
158
        }
159
    }
160

            
161
  return ret;
162
}
163

            
164
static void
165
32
atk_tablecell_interface_init (AtkTableCellIface *iface)
166
{
167
32
  if (!iface)
168
    return;
169
32
  iface->get_column_span = my_atk_tablecell_get_column_span;
170
32
  iface->get_column_header_cells = my_atk_tablecell_get_column_header_cells;
171
32
  iface->get_position = my_atk_tablecell_get_position;
172
32
  iface->get_row_span = my_atk_tablecell_get_row_span;
173
32
  iface->get_row_header_cells = my_atk_tablecell_get_row_header_cells;
174
32
  iface->get_row_column_span = my_atk_tablecell_get_row_column_span;
175
32
  iface->get_table = my_atk_tablecell_get_table;
176
}
177

            
178
static void
179
384
my_atk_tablecell_init (MyAtkTableCell *self)
180
{
181
384
  self->value = NULL;
182
384
  self->parent_table = NULL;
183
384
  self->row_desc = NULL;
184
384
  self->selected = FALSE;
185
384
  memset (self->xy, -1, sizeof (self->xy));
186
384
  self->column_span = 1;
187
384
  self->row_span = 1;
188
384
  self->x = -1;
189
384
  self->y = -1;
190
384
  self->column_index = -1;
191
384
}
192

            
193
static void
194
my_atk_tablecell_class_initialize (AtkObject *obj, gpointer data)
195
{
196
}
197

            
198
static void
199
my_atk_tablecell_class_finalize (GObject *obj)
200
{
201
}
202

            
203
static void
204
32
my_atk_tablecell_class_init (MyAtkTableCellClass *my_class)
205
{
206
32
  AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class);
207
32
  GObjectClass *gobject_class = G_OBJECT_CLASS (my_class);
208

            
209
32
  gobject_class->finalize = my_atk_tablecell_class_finalize;
210

            
211
32
  atk_class->initialize = my_atk_tablecell_class_initialize;
212
32
}