Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / vcl / unx / gtk3 / a11y / atktablecell.cxx
blobacdb64ef9031309ad4efd5a5aef3f5674589a61b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "atkwrapper.hxx"
12 #include <com/sun/star/accessibility/XAccessibleTable.hpp>
13 #include <com/sun/star/accessibility/XAccessibleTableSelection.hpp>
14 #include <sal/log.hxx>
16 static css::uno::Reference<css::accessibility::XAccessibleContext>
17 getContext(AtkTableCell* pTableCell)
19 AtkObjectWrapper* pWrap = ATK_OBJECT_WRAPPER(pTableCell);
20 if (pWrap)
22 return pWrap->mpContext;
25 return css::uno::Reference<css::accessibility::XAccessibleContext>();
28 static css::uno::Reference<css::accessibility::XAccessibleTable>
29 getTableParent(AtkTableCell* pTableCell)
31 AtkObject* pParent = atk_object_get_parent(ATK_OBJECT(pTableCell));
32 if (!pParent)
33 return css::uno::Reference<css::accessibility::XAccessibleTable>();
35 AtkObjectWrapper* pWrap = ATK_OBJECT_WRAPPER(pParent);
36 if (pWrap)
38 if (!pWrap->mpTable.is())
40 pWrap->mpTable.set(pWrap->mpContext, css::uno::UNO_QUERY);
43 return pWrap->mpTable;
46 return css::uno::Reference<css::accessibility::XAccessibleTable>();
49 extern "C" {
51 static int tablecell_wrapper_get_column_span(AtkTableCell* cell)
53 int nColumnExtent = -1;
54 try
56 css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell);
57 if (!xContext.is())
58 return -1;
60 css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell);
61 if (xTable.is())
63 const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent();
64 const sal_Int32 nRow = xTable->getAccessibleRow(nChildIndex);
65 const sal_Int32 nColumn = xTable->getAccessibleColumn(nChildIndex);
66 nColumnExtent = xTable->getAccessibleColumnExtentAt(nRow, nColumn);
69 catch (const css::uno::Exception&)
71 g_warning("Exception in tablecell_wrapper_get_column_span");
74 return nColumnExtent;
77 static GPtrArray* tablecell_wrapper_get_column_header_cells(AtkTableCell* cell)
79 GPtrArray* pHeaderCells = g_ptr_array_new();
80 try
82 css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell);
83 if (!xContext.is())
84 return pHeaderCells;
86 css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell);
87 if (xTable.is())
89 const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent();
90 const sal_Int32 nCol = xTable->getAccessibleColumn(nChildIndex);
91 css::uno::Reference<css::accessibility::XAccessibleTable> xHeaders
92 = xTable->getAccessibleColumnHeaders();
93 if (!xHeaders.is())
94 return pHeaderCells;
96 for (sal_Int32 nRow = 0; nRow < xHeaders->getAccessibleRowCount(); nRow++)
98 css::uno::Reference<css::accessibility::XAccessible> xCell
99 = xHeaders->getAccessibleCellAt(nRow, nCol);
100 AtkObject* pCell = atk_object_wrapper_ref(xCell);
101 g_ptr_array_add(pHeaderCells, pCell);
105 catch (const css::uno::Exception&)
107 g_warning("Exception in tablecell_wrapper_get_column_header_cells");
110 return pHeaderCells;
113 static gboolean tablecell_wrapper_get_position(AtkTableCell* cell, gint* row, gint* column)
117 css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell);
118 if (!xContext.is())
119 return false;
121 css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell);
122 if (xTable.is())
124 const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent();
125 *row = xTable->getAccessibleRow(nChildIndex);
126 *column = xTable->getAccessibleColumn(nChildIndex);
127 return true;
130 catch (const css::uno::Exception&)
132 g_warning("Exception in tablecell_wrapper_get_position()");
135 return false;
138 static gint tablecell_wrapper_get_row_span(AtkTableCell* cell)
140 int nRowExtent = -1;
143 css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell);
144 if (!xContext.is())
145 return -1;
147 css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell);
148 if (xTable.is())
150 const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent();
151 const sal_Int32 nRow = xTable->getAccessibleRow(nChildIndex);
152 const sal_Int32 nColumn = xTable->getAccessibleColumn(nChildIndex);
153 nRowExtent = xTable->getAccessibleRowExtentAt(nRow, nColumn);
156 catch (const css::uno::Exception&)
158 g_warning("Exception in tablecell_wrapper_get_row_span");
161 return nRowExtent;
164 static GPtrArray* tablecell_wrapper_get_row_header_cells(AtkTableCell* cell)
166 GPtrArray* pHeaderCells = g_ptr_array_new();
169 css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell);
170 if (!xContext.is())
171 return pHeaderCells;
173 css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell);
174 if (xTable.is())
176 const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent();
177 const sal_Int32 nRow = xTable->getAccessibleRow(nChildIndex);
178 css::uno::Reference<css::accessibility::XAccessibleTable> xHeaders
179 = xTable->getAccessibleRowHeaders();
180 if (!xHeaders.is())
181 return pHeaderCells;
183 for (sal_Int32 nCol = 0; nCol < xHeaders->getAccessibleColumnCount(); nCol++)
185 css::uno::Reference<css::accessibility::XAccessible> xCell
186 = xHeaders->getAccessibleCellAt(nRow, nCol);
187 AtkObject* pCell = atk_object_wrapper_ref(xCell);
188 g_ptr_array_add(pHeaderCells, pCell);
192 catch (const css::uno::Exception&)
194 g_warning("Exception in tablecell_wrapper_get_row_header_cells");
197 return pHeaderCells;
200 static gboolean tablecell_wrapper_get_row_column_span(AtkTableCell* cell, gint* row, gint* column,
201 gint* row_span, gint* column_span)
205 css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell);
206 if (!xContext.is())
207 return -1;
209 css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell);
210 if (xTable.is())
212 const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent();
213 const sal_Int32 nRow = xTable->getAccessibleRow(nChildIndex);
214 const sal_Int32 nColumn = xTable->getAccessibleColumn(nChildIndex);
215 *row = nRow;
216 *column = nColumn;
217 *row_span = xTable->getAccessibleRowExtentAt(nRow, nColumn);
218 *column_span = xTable->getAccessibleColumnExtentAt(nRow, nColumn);
219 return true;
222 catch (const css::uno::Exception&)
224 g_warning("Exception in tablecell_wrapper_get_row_column_span");
227 return false;
230 static AtkObject* tablecell_wrapper_get_table(AtkTableCell* cell)
234 css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell);
235 if (!xContext.is())
236 return nullptr;
238 css::uno::Reference<css::accessibility::XAccessible> xParent
239 = getContext(cell)->getAccessibleParent();
240 if (!xParent.is())
241 return nullptr;
243 return atk_object_wrapper_ref(xParent);
246 catch (const css::uno::Exception&)
248 g_warning("Exception in tablecell_wrapper_get_table()");
251 return nullptr;
254 } // extern "C"
256 void tablecellIfaceInit(gpointer iface_, gpointer)
258 auto const iface = static_cast<AtkTableCellIface*>(iface_);
259 g_return_if_fail(iface != nullptr);
261 iface->get_column_span = tablecell_wrapper_get_column_span;
262 iface->get_column_header_cells = tablecell_wrapper_get_column_header_cells;
263 iface->get_position = tablecell_wrapper_get_position;
264 iface->get_row_span = tablecell_wrapper_get_row_span;
265 iface->get_row_header_cells = tablecell_wrapper_get_row_header_cells;
266 iface->get_row_column_span = tablecell_wrapper_get_row_column_span;
267 iface->get_table = tablecell_wrapper_get_table;
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */