| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | /* |
| 3 | * This file is part of the LibreOffice project. |
| 4 | * |
| 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 | */ |
| 9 | |
| 10 | #include "atkwrapper.hxx" |
| 11 | |
| 12 | #include <com/sun/star/accessibility/XAccessibleTable.hpp> |
| 13 | #include <com/sun/star/accessibility/XAccessibleTableSelection.hpp> |
| 14 | #include <sal/log.hxx> |
| 15 | |
| 16 | static css::uno::Reference<css::accessibility::XAccessibleContext> |
| 17 | getContext(AtkTableCell* pTableCell) |
| 18 | { |
| 19 | AtkObjectWrapper* pWrap = ATK_OBJECT_WRAPPER(pTableCell); |
| 20 | if (pWrap) |
| 21 | { |
| 22 | return pWrap->mpContext; |
| 23 | } |
| 24 | |
| 25 | return css::uno::Reference<css::accessibility::XAccessibleContext>(); |
| 26 | } |
| 27 | |
| 28 | static css::uno::Reference<css::accessibility::XAccessibleTable> |
| 29 | getTableParent(AtkTableCell* pTableCell) |
| 30 | { |
| 31 | AtkObject* pParent = atk_object_get_parent(ATK_OBJECT(pTableCell)); |
| 32 | AtkObjectWrapper* pWrap = ATK_OBJECT_WRAPPER(pParent); |
| 33 | if (pWrap) |
| 34 | { |
| 35 | if (!pWrap->mpTable.is()) |
| 36 | { |
| 37 | pWrap->mpTable.set(pWrap->mpContext, css::uno::UNO_QUERY); |
| 38 | } |
| 39 | |
| 40 | return pWrap->mpTable; |
| 41 | } |
| 42 | |
| 43 | return css::uno::Reference<css::accessibility::XAccessibleTable>(); |
| 44 | } |
| 45 | |
| 46 | extern "C" { |
| 47 | |
| 48 | static int tablecell_wrapper_get_column_span(AtkTableCell* cell) |
| 49 | { |
| 50 | int nColumnExtent = -1; |
| 51 | try |
| 52 | { |
| 53 | css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell); |
| 54 | if (!xContext.is()) |
| 55 | return -1; |
| 56 | |
| 57 | css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell); |
| 58 | if (xTable.is()) |
| 59 | { |
| 60 | const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent(); |
| 61 | const sal_Int32 nRow = xTable->getAccessibleRow(nChildIndex); |
| 62 | const sal_Int32 nColumn = xTable->getAccessibleColumn(nChildIndex); |
| 63 | nColumnExtent = xTable->getAccessibleColumnExtentAt(nRow, nColumn); |
| 64 | } |
| 65 | } |
| 66 | catch (const css::uno::Exception&) |
| 67 | { |
| 68 | g_warning("Exception in tablecell_wrapper_get_column_span"); |
| 69 | } |
| 70 | |
| 71 | return nColumnExtent; |
| 72 | } |
| 73 | |
| 74 | static GPtrArray* tablecell_wrapper_get_column_header_cells(AtkTableCell* cell) |
| 75 | { |
| 76 | GPtrArray* pHeaderCells = g_ptr_array_new(); |
| 77 | try |
| 78 | { |
| 79 | css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell); |
| 80 | if (!xContext.is()) |
| 81 | return pHeaderCells; |
| 82 | |
| 83 | css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell); |
| 84 | if (xTable.is()) |
| 85 | { |
| 86 | const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent(); |
| 87 | const sal_Int32 nCol = xTable->getAccessibleColumn(nChildIndex); |
| 88 | css::uno::Reference<css::accessibility::XAccessibleTable> xHeaders |
| 89 | = xTable->getAccessibleColumnHeaders(); |
| 90 | if (!xHeaders.is()) |
| 91 | return pHeaderCells; |
| 92 | |
| 93 | for (sal_Int32 nRow = 0; nRow < xHeaders->getAccessibleRowCount(); nRow++) |
| 94 | { |
| 95 | css::uno::Reference<css::accessibility::XAccessible> xCell |
| 96 | = xHeaders->getAccessibleCellAt(nRow, nCol); |
| 97 | AtkObject* pCell = atk_object_wrapper_ref(xCell); |
| 98 | g_ptr_array_add(pHeaderCells, pCell); |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | catch (const css::uno::Exception&) |
| 103 | { |
| 104 | g_warning("Exception in tablecell_wrapper_get_column_header_cells"); |
| 105 | } |
| 106 | |
| 107 | return pHeaderCells; |
| 108 | } |
| 109 | |
| 110 | static gboolean tablecell_wrapper_get_position(AtkTableCell* cell, gint* row, gint* column) |
| 111 | { |
| 112 | try |
| 113 | { |
| 114 | css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell); |
| 115 | if (!xContext.is()) |
| 116 | return false; |
| 117 | |
| 118 | css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell); |
| 119 | if (xTable.is()) |
| 120 | { |
| 121 | const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent(); |
| 122 | *row = xTable->getAccessibleRow(nChildIndex); |
| 123 | *column = xTable->getAccessibleColumn(nChildIndex); |
| 124 | return true; |
| 125 | } |
| 126 | } |
| 127 | catch (const css::uno::Exception&) |
| 128 | { |
| 129 | g_warning("Exception in tablecell_wrapper_get_position()"); |
| 130 | } |
| 131 | |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | static gint tablecell_wrapper_get_row_span(AtkTableCell* cell) |
| 136 | { |
| 137 | int nRowExtent = -1; |
| 138 | try |
| 139 | { |
| 140 | css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell); |
| 141 | if (!xContext.is()) |
| 142 | return -1; |
| 143 | |
| 144 | css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell); |
| 145 | if (xTable.is()) |
| 146 | { |
| 147 | const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent(); |
| 148 | const sal_Int32 nRow = xTable->getAccessibleRow(nChildIndex); |
| 149 | const sal_Int32 nColumn = xTable->getAccessibleColumn(nChildIndex); |
| 150 | nRowExtent = xTable->getAccessibleRowExtentAt(nRow, nColumn); |
| 151 | } |
| 152 | } |
| 153 | catch (const css::uno::Exception&) |
| 154 | { |
| 155 | g_warning("Exception in tablecell_wrapper_get_row_span"); |
| 156 | } |
| 157 | |
| 158 | return nRowExtent; |
| 159 | } |
| 160 | |
| 161 | static GPtrArray* tablecell_wrapper_get_row_header_cells(AtkTableCell* cell) |
| 162 | { |
| 163 | GPtrArray* pHeaderCells = g_ptr_array_new(); |
| 164 | try |
| 165 | { |
| 166 | css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell); |
| 167 | if (!xContext.is()) |
| 168 | return pHeaderCells; |
| 169 | |
| 170 | css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell); |
| 171 | if (xTable.is()) |
| 172 | { |
| 173 | const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent(); |
| 174 | const sal_Int32 nRow = xTable->getAccessibleRow(nChildIndex); |
| 175 | css::uno::Reference<css::accessibility::XAccessibleTable> xHeaders |
| 176 | = xTable->getAccessibleRowHeaders(); |
| 177 | if (!xHeaders.is()) |
| 178 | return pHeaderCells; |
| 179 | |
| 180 | for (sal_Int32 nCol = 0; nCol < xHeaders->getAccessibleColumnCount(); nCol++) |
| 181 | { |
| 182 | css::uno::Reference<css::accessibility::XAccessible> xCell |
| 183 | = xHeaders->getAccessibleCellAt(nRow, nCol); |
| 184 | AtkObject* pCell = atk_object_wrapper_ref(xCell); |
| 185 | g_ptr_array_add(pHeaderCells, pCell); |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | catch (const css::uno::Exception&) |
| 190 | { |
| 191 | g_warning("Exception in tablecell_wrapper_get_row_header_cells"); |
| 192 | } |
| 193 | |
| 194 | return pHeaderCells; |
| 195 | } |
| 196 | |
| 197 | static gboolean tablecell_wrapper_get_row_column_span(AtkTableCell* cell, gint* row, gint* column, |
| 198 | gint* row_span, gint* column_span) |
| 199 | { |
| 200 | try |
| 201 | { |
| 202 | css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell); |
| 203 | if (!xContext.is()) |
| 204 | return -1; |
| 205 | |
| 206 | css::uno::Reference<css::accessibility::XAccessibleTable> xTable = getTableParent(cell); |
| 207 | if (xTable.is()) |
| 208 | { |
| 209 | const sal_Int64 nChildIndex = xContext->getAccessibleIndexInParent(); |
| 210 | const sal_Int32 nRow = xTable->getAccessibleRow(nChildIndex); |
| 211 | const sal_Int32 nColumn = xTable->getAccessibleColumn(nChildIndex); |
| 212 | *row = nRow; |
| 213 | *column = nColumn; |
| 214 | *row_span = xTable->getAccessibleRowExtentAt(nRow, nColumn); |
| 215 | *column_span = xTable->getAccessibleColumnExtentAt(nRow, nColumn); |
| 216 | return true; |
| 217 | } |
| 218 | } |
| 219 | catch (const css::uno::Exception&) |
| 220 | { |
| 221 | g_warning("Exception in tablecell_wrapper_get_row_column_span"); |
| 222 | } |
| 223 | |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | static AtkObject* tablecell_wrapper_get_table(AtkTableCell* cell) |
| 228 | { |
| 229 | try |
| 230 | { |
| 231 | css::uno::Reference<css::accessibility::XAccessibleContext> xContext = getContext(cell); |
| 232 | if (!xContext.is()) |
| 233 | return nullptr; |
| 234 | |
| 235 | css::uno::Reference<css::accessibility::XAccessible> xParent |
| 236 | = getContext(cell)->getAccessibleParent(); |
| 237 | if (!xParent.is()) |
| 238 | return nullptr; |
| 239 | |
| 240 | return atk_object_wrapper_ref(xParent); |
| 241 | } |
| 242 | |
| 243 | catch (const css::uno::Exception&) |
| 244 | { |
| 245 | g_warning("Exception in tablecell_wrapper_get_table()"); |
| 246 | } |
| 247 | |
| 248 | return nullptr; |
| 249 | } |
| 250 | |
| 251 | } // extern "C" |
| 252 | |
| 253 | void tablecellIfaceInit(gpointer iface_, gpointer) |
| 254 | { |
| 255 | auto const iface = static_cast<AtkTableCellIface*>(iface_); |
| 256 | g_return_if_fail(iface != nullptr); |
| 257 | |
| 258 | iface->get_column_span = tablecell_wrapper_get_column_span; |
| 259 | iface->get_column_header_cells = tablecell_wrapper_get_column_header_cells; |
| 260 | iface->get_position = tablecell_wrapper_get_position; |
| 261 | iface->get_row_span = tablecell_wrapper_get_row_span; |
| 262 | iface->get_row_header_cells = tablecell_wrapper_get_row_header_cells; |
| 263 | iface->get_row_column_span = tablecell_wrapper_get_row_column_span; |
| 264 | iface->get_table = tablecell_wrapper_get_table; |
| 265 | } |
| 266 | |
| 267 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |