LibreOffice Module winaccessibility (master) 1
AccTableCell.cxx
Go to the documentation of this file.
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "AccTableCell.h"
21#include "MAccessible.h"
22
23#include <vcl/svapp.hxx>
24#include <com/sun/star/accessibility/XAccessible.hpp>
25
26using namespace com::sun::star::accessibility;
27using namespace com::sun::star::uno;
28
30 : m_nIndexInParent(0)
31{
32}
33
34COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::put_XInterface(hyper pXInterface)
35{
36 // internal IUNOXWrapper - no mutex meeded
37
38 try
39 {
41 if (pUNOInterface == nullptr)
42 return E_INVALIDARG;
43
44 Reference<XAccessibleContext> xContext = pUNOInterface->getAccessibleContext();
45 if (!xContext.is())
46 return E_FAIL;
47
48 // retrieve reference to table (parent of the cell)
50 = xContext->getAccessibleParent()->getAccessibleContext();
51 Reference<XAccessibleTable> xTable(xParentContext, UNO_QUERY);
52
53 if (!xTable.is())
54 {
55 m_xTable.clear();
56 return E_FAIL;
57 }
58
59 m_xTable = xTable;
60 m_nIndexInParent = xContext->getAccessibleIndexInParent();
61 return S_OK;
62 }
63 catch (...)
64 {
65 return E_FAIL;
66 }
67}
68
69COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_columnExtent(long* pColumnsSpanned)
70{
72
73 try
74 {
75 if (pColumnsSpanned == nullptr)
76 return E_INVALIDARG;
77
78 if (!m_xTable.is())
79 return E_FAIL;
80
81 long nRow = 0, nColumn = 0;
82 get_rowIndex(&nRow);
83 get_columnIndex(&nColumn);
84
85 *pColumnsSpanned = m_xTable->getAccessibleColumnExtentAt(nRow, nColumn);
86 return S_OK;
87 }
88 catch (...)
89 {
90 return E_FAIL;
91 }
92}
93
94COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_columnHeaderCells(IUnknown*** cellAccessibles,
95 long* pColumnHeaderCellCount)
96{
98
99 if (!cellAccessibles || !pColumnHeaderCellCount)
100 return E_INVALIDARG;
101
102 if (!m_xTable.is())
103 return E_FAIL;
104
105 Reference<XAccessibleTable> xHeaders = m_xTable->getAccessibleColumnHeaders();
106 if (!xHeaders.is())
107 return E_FAIL;
108
109 const sal_Int32 nCount = xHeaders->getAccessibleRowCount();
110 *pColumnHeaderCellCount = nCount;
111 *cellAccessibles = static_cast<IUnknown**>(CoTaskMemAlloc(nCount * sizeof(IUnknown*)));
112 sal_Int32 nCol = 0;
113 get_columnIndex(&nCol);
114 for (sal_Int32 nRow = 0; nRow < nCount; nRow++)
115 {
116 Reference<XAccessible> xCell = xHeaders->getAccessibleCellAt(nRow, nCol);
117 assert(xCell.is());
118
119 IAccessible* pIAccessible;
120 bool bOK = CMAccessible::get_IAccessibleFromXAccessible(xCell.get(), &pIAccessible);
121 if (!bOK)
122 {
123 Reference<XAccessible> xTableAcc(m_xTable, UNO_QUERY);
124 CMAccessible::g_pAgent->InsertAccObj(xCell.get(), xTableAcc.get());
125 bOK = CMAccessible::get_IAccessibleFromXAccessible(xCell.get(), &pIAccessible);
126 }
127 assert(bOK && "Couldn't retrieve IAccessible object for cell.");
128
129 pIAccessible->AddRef();
130 (*cellAccessibles)[nRow] = pIAccessible;
131 }
132 return S_OK;
133}
134
135COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_columnIndex(long* pColumnIndex)
136{
138
139 try
140 {
141 if (pColumnIndex == nullptr)
142 return E_INVALIDARG;
143
144 if (!m_xTable.is())
145 return E_FAIL;
146
147 *pColumnIndex = m_xTable->getAccessibleColumn(m_nIndexInParent);
148 return S_OK;
149 }
150 catch (...)
151 {
152 return E_FAIL;
153 }
154}
155
156COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_rowExtent(long* pRowsSpanned)
157{
159
160 try
161 {
162 if (pRowsSpanned == nullptr)
163 return E_INVALIDARG;
164
165 if (!m_xTable.is())
166 return E_FAIL;
167
168 long nRow = 0, nColumn = 0;
169 get_rowIndex(&nRow);
170 get_columnIndex(&nColumn);
171
172 *pRowsSpanned = m_xTable->getAccessibleRowExtentAt(nRow, nColumn);
173
174 return S_OK;
175 }
176 catch (...)
177 {
178 return E_FAIL;
179 }
180}
181
182COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_rowHeaderCells(IUnknown*** cellAccessibles,
183 long* pRowHeaderCellCount)
184{
186
187 if (!cellAccessibles || !pRowHeaderCellCount)
188 return E_INVALIDARG;
189
190 if (!m_xTable.is())
191 return E_FAIL;
192
193 Reference<XAccessibleTable> xHeaders = m_xTable->getAccessibleRowHeaders();
194 if (!xHeaders.is())
195 return E_FAIL;
196
197 const sal_Int32 nCount = xHeaders->getAccessibleColumnCount();
198 *pRowHeaderCellCount = nCount;
199 *cellAccessibles = static_cast<IUnknown**>(CoTaskMemAlloc(nCount * sizeof(IUnknown*)));
200 sal_Int32 nRow = 0;
201 get_rowIndex(&nRow);
202 for (sal_Int32 nCol = 0; nCol < nCount; nCol++)
203 {
204 Reference<XAccessible> xCell = xHeaders->getAccessibleCellAt(nRow, nCol);
205 assert(xCell.is());
206
207 IAccessible* pIAccessible;
208 bool bOK = CMAccessible::get_IAccessibleFromXAccessible(xCell.get(), &pIAccessible);
209 if (!bOK)
210 {
211 Reference<XAccessible> xTableAcc(m_xTable, UNO_QUERY);
212 CMAccessible::g_pAgent->InsertAccObj(xCell.get(), xTableAcc.get());
213 bOK = CMAccessible::get_IAccessibleFromXAccessible(xCell.get(), &pIAccessible);
214 }
215 assert(bOK && "Couldn't retrieve IAccessible object for cell.");
216
217 pIAccessible->AddRef();
218 (*cellAccessibles)[nRow] = pIAccessible;
219 }
220 return S_OK;
221}
222
223COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_rowIndex(long* pRowIndex)
224{
226
227 try
228 {
229 if (pRowIndex == nullptr)
230 return E_INVALIDARG;
231
232 if (!m_xTable.is())
233 return E_FAIL;
234
235 *pRowIndex = m_xTable->getAccessibleRow(m_nIndexInParent);
236 return S_OK;
237 }
238 catch (...)
239 {
240 return E_FAIL;
241 }
242}
243
244COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_isSelected(boolean* pIsSelected)
245{
247
248 try
249 {
250 if (pIsSelected == nullptr)
251 return E_INVALIDARG;
252
253 if (!m_xTable.is())
254 return E_FAIL;
255
256 long nRow = 0, nColumn = 0;
257 get_rowIndex(&nRow);
258 get_columnIndex(&nColumn);
259
260 *pIsSelected = m_xTable->isAccessibleSelected(nRow, nColumn);
261 return S_OK;
262 }
263 catch (...)
264 {
265 return E_FAIL;
266 }
267}
268
269COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_rowColumnExtents(long* pRow, long* pColumn,
270 long* pRowExtents,
271 long* pColumnExtents,
272 boolean* pIsSelected)
273{
275
276 if (!pRow || !pColumn || !pRowExtents || !pColumnExtents || !pIsSelected)
277 return E_INVALIDARG;
278
279 if (get_rowIndex(pRow) != S_OK)
280 return E_FAIL;
281 if (get_columnIndex(pColumn) != S_OK)
282 return E_FAIL;
283 if (get_rowExtent(pRowExtents) != S_OK)
284 return E_FAIL;
285 if (get_columnExtent(pColumnExtents) != S_OK)
286 return E_FAIL;
287 if (get_isSelected(pIsSelected) != S_OK)
288 return E_FAIL;
289 return S_OK;
290}
291
292COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_table(IUnknown** ppTable)
293{
294 if (!ppTable)
295 return E_INVALIDARG;
296
297 if (!m_xTable.is())
298 return E_FAIL;
299
300 Reference<XAccessible> xAcc(m_xTable, UNO_QUERY);
301 if (!xAcc.is())
302 return E_FAIL;
303
304 IAccessible* pRet = nullptr;
305 bool bOK = CMAccessible::get_IAccessibleFromXAccessible(xAcc.get(), &pRet);
306 if (!bOK)
307 return E_FAIL;
308
309 *ppTable = pRet;
310 pRet->AddRef();
311 return S_OK;
312}
313
314/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool InsertAccObj(css::accessibility::XAccessible *pXAcc, css::accessibility::XAccessible *pParentXAcc, HWND hWnd=nullptr)
When a new UNO XAccessible object is found by listener, we create a corresponding com object and inse...
STDMETHOD() get_columnHeaderCells(IUnknown ***, long *) override
sal_Int64 m_nIndexInParent
Definition: AccTableCell.h:84
STDMETHOD() get_rowColumnExtents(long *, long *, long *, long *, boolean *) override
STDMETHOD() get_rowIndex(long *) override
STDMETHOD() get_rowHeaderCells(IUnknown ***, long *) override
css::uno::Reference< css::accessibility::XAccessibleTable > m_xTable
Definition: AccTableCell.h:83
STDMETHOD() get_table(IUnknown **) override
STDMETHOD() get_isSelected(boolean *) override
STDMETHOD() get_rowExtent(long *) override
STDMETHOD() get_columnIndex(long *) override
STDMETHOD() put_XInterface(hyper pXInterface) override
STDMETHOD() get_columnExtent(long *) override
static bool get_IAccessibleFromXAccessible(css::accessibility::XAccessible *pXAcc, IAccessible **ppIA)
static AccObjectManagerAgent * g_pAgent
Definition: MAccessible.h:207
STDMETHOD() put_XInterface(hyper pXInterface) override
Definition: UNOXWrapper.cxx:27
css::accessibility::XAccessible * pUNOInterface
Definition: UNOXWrapper.h:34
int nCount