doc: documentation for AtkTableCell, AtkTable, deprecations and padding
[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 gint
61 atk_table_cell_get_column_span (AtkTableCell *cell)
62 {
63   AtkTableCellIface *iface;
64
65   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), 0);
66
67   iface = ATK_TABLE_CELL_GET_IFACE (cell);
68
69   if (iface->get_column_span)
70     return (iface->get_column_span) (cell);
71   else
72     return 0;
73 }
74
75 /**
76  * atk_table_cell_get_column_header_cells:
77  * @cell: a GObject instance that implements AtkTableCellIface
78  *
79  * Returns the column headers as an array of cell accessibles.
80  *
81  * Returns: (element-type AtkObject) (transfer full): a GPtrArray of AtkObjects
82  * representing the column header cells.
83  */
84 GPtrArray *
85 atk_table_cell_get_column_header_cells (AtkTableCell *cell)
86 {
87   AtkTableCellIface *iface;
88
89   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), NULL);
90
91   iface = ATK_TABLE_CELL_GET_IFACE (cell);
92
93   if (iface->get_column_header_cells)
94     return (iface->get_column_header_cells) (cell);
95   else
96     return NULL;
97 }
98
99 /**
100  * atk_table_cell_get_position:
101  * @cell: a GObject instance that implements AtkTableCellIface
102  * @row: (out): the row of the given cell.
103  * @column: (out): the column of the given cell.
104  *
105  * Retrieves the tabular position of this cell.
106  *
107  * Returns: TRUE if successful; FALSE otherwise.
108  */
109 gboolean
110 atk_table_cell_get_position (AtkTableCell *cell,
111                              gint         *row,
112                              gint         *column)
113 {
114   AtkTableCellIface *iface;
115   gint tmp_row, tmp_column;
116   gint *real_row = (row ? row : &tmp_row);
117   gint *real_column = (column ? column : &tmp_column);
118
119   *real_row = -1;
120   *real_column = -1;
121
122   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), FALSE);
123
124   iface = ATK_TABLE_CELL_GET_IFACE (cell);
125
126   if (iface->get_position)
127     return (iface->get_position) (cell, real_row, real_column);
128   else
129     return FALSE;
130 }
131
132 /**
133  * atk_table_cell_get_row_span:
134  * @cell: a GObject instance that implements AtkTableCellIface
135  *
136  * Returns the number of rows occupied by this cell accessible.
137  *
138  * Returns: a gint representing the number of rows occupied by this cell,
139  * or 0 if the cell does not implement this method.
140  */
141 gint
142 atk_table_cell_get_row_span (AtkTableCell *cell)
143 {
144   AtkTableCellIface *iface;
145
146   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), 0);
147
148   iface = ATK_TABLE_CELL_GET_IFACE (cell);
149
150   if (iface->get_row_span)
151     return (iface->get_row_span) (cell);
152   else
153     return 0;
154 }
155
156 /**
157  * atk_table_cell_get_row_header_cells:
158  * @cell: a GObject instance that implements AtkTableCellIface
159  *
160  * Returns the row headers as an array of cell accessibles.
161  *
162  * Returns: (element-type AtkObject) (transfer full): a GPtrArray of AtkObjects
163  * representing the row header cells.
164  */
165 GPtrArray *
166 atk_table_cell_get_row_header_cells (AtkTableCell *cell)
167 {
168   AtkTableCellIface *iface;
169
170   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), NULL);
171
172   iface = ATK_TABLE_CELL_GET_IFACE (cell);
173
174   if (iface->get_row_header_cells)
175     return (iface->get_row_header_cells) (cell);
176   else
177     return NULL;
178 }
179
180 /**
181  * atk_table_cell_get_row_column_span:
182  * @cell: a GObject instance that implements AtkTableCellIface
183  * @row: (out): the row index of the given cell.
184  * @column: (out): the column index of the given cell.
185  * @row_span: (out): the number of rows occupied by this cell.
186  * @column_span: (out): the number of columns occupied by this cell.
187  *
188  * Gets the row and column indexes and span of this cell accessible.
189  *
190  * Note: If the object does not implement this function, then, by default, atk
191  * will implement this function by calling get_row_span and get_column_span
192  * on the object.
193  *
194  * Returns: TRUE if successful; FALSE otherwise.
195  */
196 gboolean
197 atk_table_cell_get_row_column_span (AtkTableCell *cell,
198                                     gint         *row,
199                                     gint         *column,
200                                     gint         *row_span,
201                                     gint         *column_span)
202 {
203   AtkTableCellIface *iface;
204   gint local_row = 0, local_column = 0;
205   gint local_row_span = 0, local_column_span = 0;
206   gint *real_row, *real_column;
207   gint *real_row_span, *real_column_span;
208
209   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), FALSE);
210
211   real_row = (row ? row : &local_row);
212   real_column = (column ? column : &local_column);
213   real_row_span = (row_span ? row_span : &local_row_span);
214   real_column_span = (column_span ? column_span : &local_column_span);
215
216   iface = ATK_TABLE_CELL_GET_IFACE (cell);
217
218   if (iface->get_row_column_span)
219     return (iface->get_row_column_span) (cell, real_row, real_column,
220                                            real_row_span,
221                                            real_column_span);
222   else
223     return FALSE;
224 }
225
226 /**
227  * atk_table_cell_get_table:
228  * @cell: a GObject instance that implements AtkTableCellIface
229  *
230  * Returns a reference to the accessible of the containing table.
231  *
232  * Returns: (transfer full): the atk object for the containing table.
233  */
234 AtkObject *
235 atk_table_cell_get_table (AtkTableCell *cell)
236 {
237   AtkTableCellIface *iface;
238
239   g_return_val_if_fail (ATK_IS_TABLE_CELL (cell), FALSE);
240
241   iface = ATK_TABLE_CELL_GET_IFACE (cell);
242
243   if (iface->get_table)
244     return (iface->get_table) (cell);
245   else
246     return NULL;
247 }
248
249 static gboolean
250 atk_table_cell_real_get_row_column_span (AtkTableCell *cell,
251                                          gint         *row,
252                                          gint         *column,
253                                          gint         *row_span,
254                                          gint         *column_span)
255 {
256   atk_table_cell_get_position (cell, row, column);
257   *row_span = atk_table_cell_get_row_span (cell);
258   *column_span = atk_table_cell_get_column_span (cell);
259   return (row != 0 && column != 0 && row_span > 0 && column_span > 0);
260 }