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