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