Revert "Merge remote-tracking branch 'origin/sandbox/mniesluchow/upstream_2_16' into...
[platform/upstream/atk.git] / atk / atktablecell.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2014 SUSE LLC.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "atktablecell.h"
21
22
23 /**
24  * SECTION:atktablecell
25  * @Short_description: The ATK interface implemented for a cell inside
26  * a two-dimentional #AtkTable
27  * @Title:AtkTableCell
28  *
29  * Being #AtkTable a component which present elements ordered via rows
30  * and columns, an #AtkTableCell is the interface which each of those
31  * elements, so "cells" should implement.
32  *
33  * See also #AtkTable.
34  */
35
36 typedef AtkTableCellIface AtkTableCellInterface;
37 G_DEFINE_INTERFACE (AtkTableCell, atk_table_cell, ATK_TYPE_OBJECT)
38
39 static gboolean atk_table_cell_real_get_row_column_span (AtkTableCell *cell,
40                                                          gint         *row,
41                                                          gint         *column,
42                                                          gint         *row_span,
43                                                          gint         *column_span);
44
45 static void
46 atk_table_cell_default_init (AtkTableCellInterface *iface)
47 {
48   iface->get_row_column_span = atk_table_cell_real_get_row_column_span;
49 }
50
51 /**
52  * atk_table_cell_get_column_span:
53  * @cell: a GObject instance that implements AtkTableCellIface
54  *
55  * Returns the number of columns occupied by this cell accessible.
56  *
57  * Returns: a gint representing the number of columns occupied by this cell,
58  * or 0 if the cell does not implement this method.
59  *
60  * Since: 2.12
61  */
62 gint
63 atk_table_cell_get_column_span (AtkTableCell *cell)
64 {
65   AtkTableCellIface *iface;
66
67   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), 0);
68
69   iface = ATK_TABLE_CELL_GET_IFACE (cell);
70
71   if (iface->get_column_span)
72     return (iface->get_column_span) (cell);
73   else
74     return 0;
75 }
76
77 /**
78  * atk_table_cell_get_column_header_cells:
79  * @cell: a GObject instance that implements AtkTableCellIface
80  *
81  * Returns the column headers as an array of cell accessibles.
82  *
83  * Returns: (element-type AtkObject) (transfer full): a GPtrArray of AtkObjects
84  * representing the column header cells.
85  *
86  * Since: 2.12
87  */
88 GPtrArray *
89 atk_table_cell_get_column_header_cells (AtkTableCell *cell)
90 {
91   AtkTableCellIface *iface;
92
93   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), NULL);
94
95   iface = ATK_TABLE_CELL_GET_IFACE (cell);
96
97   if (iface->get_column_header_cells)
98     return (iface->get_column_header_cells) (cell);
99   else
100     return NULL;
101 }
102
103 /**
104  * atk_table_cell_get_position:
105  * @cell: a GObject instance that implements AtkTableCellIface
106  * @row: (out): the row of the given cell.
107  * @column: (out): the column of the given cell.
108  *
109  * Retrieves the tabular position of this cell.
110  *
111  * Returns: TRUE if successful; FALSE otherwise.
112  *
113  * Since: 2.12
114  */
115 gboolean
116 atk_table_cell_get_position (AtkTableCell *cell,
117                              gint         *row,
118                              gint         *column)
119 {
120   AtkTableCellIface *iface;
121   gint tmp_row, tmp_column;
122   gint *real_row = (row ? row : &tmp_row);
123   gint *real_column = (column ? column : &tmp_column);
124
125   *real_row = -1;
126   *real_column = -1;
127
128   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), FALSE);
129
130   iface = ATK_TABLE_CELL_GET_IFACE (cell);
131
132   if (iface->get_position)
133     return (iface->get_position) (cell, real_row, real_column);
134   else
135     return FALSE;
136 }
137
138 /**
139  * atk_table_cell_get_row_span:
140  * @cell: a GObject instance that implements AtkTableCellIface
141  *
142  * Returns the number of rows occupied by this cell accessible.
143  *
144  * Returns: a gint representing the number of rows occupied by this cell,
145  * or 0 if the cell does not implement this method.
146  *
147  * Since: 2.12
148  */
149 gint
150 atk_table_cell_get_row_span (AtkTableCell *cell)
151 {
152   AtkTableCellIface *iface;
153
154   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), 0);
155
156   iface = ATK_TABLE_CELL_GET_IFACE (cell);
157
158   if (iface->get_row_span)
159     return (iface->get_row_span) (cell);
160   else
161     return 0;
162 }
163
164 /**
165  * atk_table_cell_get_row_header_cells:
166  * @cell: a GObject instance that implements AtkTableCellIface
167  *
168  * Returns the row headers as an array of cell accessibles.
169  *
170  * Returns: (element-type AtkObject) (transfer full): a GPtrArray of AtkObjects
171  * representing the row header cells.
172  *
173  * Since: 2.12
174  */
175 GPtrArray *
176 atk_table_cell_get_row_header_cells (AtkTableCell *cell)
177 {
178   AtkTableCellIface *iface;
179
180   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), NULL);
181
182   iface = ATK_TABLE_CELL_GET_IFACE (cell);
183
184   if (iface->get_row_header_cells)
185     return (iface->get_row_header_cells) (cell);
186   else
187     return NULL;
188 }
189
190 /**
191  * atk_table_cell_get_row_column_span:
192  * @cell: a GObject instance that implements AtkTableCellIface
193  * @row: (out): the row index of the given cell.
194  * @column: (out): the column index of the given cell.
195  * @row_span: (out): the number of rows occupied by this cell.
196  * @column_span: (out): the number of columns occupied by this cell.
197  *
198  * Gets the row and column indexes and span of this cell accessible.
199  *
200  * Note: If the object does not implement this function, then, by default, atk
201  * will implement this function by calling get_row_span and get_column_span
202  * on the object.
203  *
204  * Returns: TRUE if successful; FALSE otherwise.
205  *
206  * Since: 2.12
207  */
208 gboolean
209 atk_table_cell_get_row_column_span (AtkTableCell *cell,
210                                     gint         *row,
211                                     gint         *column,
212                                     gint         *row_span,
213                                     gint         *column_span)
214 {
215   AtkTableCellIface *iface;
216   gint local_row = 0, local_column = 0;
217   gint local_row_span = 0, local_column_span = 0;
218   gint *real_row, *real_column;
219   gint *real_row_span, *real_column_span;
220
221   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), FALSE);
222
223   real_row = (row ? row : &local_row);
224   real_column = (column ? column : &local_column);
225   real_row_span = (row_span ? row_span : &local_row_span);
226   real_column_span = (column_span ? column_span : &local_column_span);
227
228   iface = ATK_TABLE_CELL_GET_IFACE (cell);
229
230   if (iface->get_row_column_span)
231     return (iface->get_row_column_span) (cell, real_row, real_column,
232                                            real_row_span,
233                                            real_column_span);
234   else
235     return FALSE;
236 }
237
238 /**
239  * atk_table_cell_get_table:
240  * @cell: a GObject instance that implements AtkTableCellIface
241  *
242  * Returns a reference to the accessible of the containing table.
243  *
244  * Returns: (transfer full): the atk object for the containing table.
245  *
246  * Since: 2.12
247  */
248 AtkObject *
249 atk_table_cell_get_table (AtkTableCell *cell)
250 {
251   AtkTableCellIface *iface;
252
253   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), FALSE);
254
255   iface = ATK_TABLE_CELL_GET_IFACE (cell);
256
257   if (iface->get_table)
258     return (iface->get_table) (cell);
259   else
260     return NULL;
261 }
262
263 static gboolean
264 atk_table_cell_real_get_row_column_span (AtkTableCell *cell,
265                                          gint         *row,
266                                          gint         *column,
267                                          gint         *row_span,
268                                          gint         *column_span)
269 {
270   atk_table_cell_get_position (cell, row, column);
271   *row_span = atk_table_cell_get_row_span (cell);
272   *column_span = atk_table_cell_get_column_span (cell);
273   return (row != 0 && column != 0 && row_span > 0 && column_span > 0);
274 }