1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
);
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
));
33 return css::uno::Reference
<css::accessibility::XAccessibleTable
>();
35 AtkObjectWrapper
* pWrap
= ATK_OBJECT_WRAPPER(pParent
);
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
>();
51 static int tablecell_wrapper_get_column_span(AtkTableCell
* cell
)
53 int nColumnExtent
= -1;
56 css::uno::Reference
<css::accessibility::XAccessibleContext
> xContext
= getContext(cell
);
60 css::uno::Reference
<css::accessibility::XAccessibleTable
> xTable
= getTableParent(cell
);
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");
77 static GPtrArray
* tablecell_wrapper_get_column_header_cells(AtkTableCell
* cell
)
79 GPtrArray
* pHeaderCells
= g_ptr_array_new();
82 css::uno::Reference
<css::accessibility::XAccessibleContext
> xContext
= getContext(cell
);
86 css::uno::Reference
<css::accessibility::XAccessibleTable
> xTable
= getTableParent(cell
);
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();
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");
113 static gboolean
tablecell_wrapper_get_position(AtkTableCell
* cell
, gint
* row
, gint
* column
)
117 css::uno::Reference
<css::accessibility::XAccessibleContext
> xContext
= getContext(cell
);
121 css::uno::Reference
<css::accessibility::XAccessibleTable
> xTable
= getTableParent(cell
);
124 const sal_Int64 nChildIndex
= xContext
->getAccessibleIndexInParent();
125 *row
= xTable
->getAccessibleRow(nChildIndex
);
126 *column
= xTable
->getAccessibleColumn(nChildIndex
);
130 catch (const css::uno::Exception
&)
132 g_warning("Exception in tablecell_wrapper_get_position()");
138 static gint
tablecell_wrapper_get_row_span(AtkTableCell
* cell
)
143 css::uno::Reference
<css::accessibility::XAccessibleContext
> xContext
= getContext(cell
);
147 css::uno::Reference
<css::accessibility::XAccessibleTable
> xTable
= getTableParent(cell
);
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");
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
);
173 css::uno::Reference
<css::accessibility::XAccessibleTable
> xTable
= getTableParent(cell
);
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();
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");
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
);
209 css::uno::Reference
<css::accessibility::XAccessibleTable
> xTable
= getTableParent(cell
);
212 const sal_Int64 nChildIndex
= xContext
->getAccessibleIndexInParent();
213 const sal_Int32 nRow
= xTable
->getAccessibleRow(nChildIndex
);
214 const sal_Int32 nColumn
= xTable
->getAccessibleColumn(nChildIndex
);
217 *row_span
= xTable
->getAccessibleRowExtentAt(nRow
, nColumn
);
218 *column_span
= xTable
->getAccessibleColumnExtentAt(nRow
, nColumn
);
222 catch (const css::uno::Exception
&)
224 g_warning("Exception in tablecell_wrapper_get_row_column_span");
230 static AtkObject
* tablecell_wrapper_get_table(AtkTableCell
* cell
)
234 css::uno::Reference
<css::accessibility::XAccessibleContext
> xContext
= getContext(cell
);
238 css::uno::Reference
<css::accessibility::XAccessible
> xParent
239 = getContext(cell
)->getAccessibleParent();
243 return atk_object_wrapper_ref(xParent
);
246 catch (const css::uno::Exception
&)
248 g_warning("Exception in tablecell_wrapper_get_table()");
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: */