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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "AccTableCell.h"
21 #include "MAccessible.h"
23 #include <vcl/svapp.hxx>
24 #include <com/sun/star/accessibility/XAccessible.hpp>
26 using namespace com::sun::star::accessibility
;
27 using namespace com::sun::star::uno
;
29 CAccTableCell::CAccTableCell()
34 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::put_XInterface(hyper pXInterface
)
36 // internal IUNOXWrapper - no mutex meeded
40 CUNOXWrapper::put_XInterface(pXInterface
);
41 if (pUNOInterface
== nullptr)
44 Reference
<XAccessibleContext
> xContext
= pUNOInterface
->getAccessibleContext();
48 // retrieve reference to table (parent of the cell)
49 Reference
<XAccessibleContext
> xParentContext
50 = xContext
->getAccessibleParent()->getAccessibleContext();
51 Reference
<XAccessibleTable
> xTable(xParentContext
, UNO_QUERY
);
60 m_nIndexInParent
= xContext
->getAccessibleIndexInParent();
69 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::get_columnExtent(long* pColumnsSpanned
)
75 if (pColumnsSpanned
== nullptr)
81 long nRow
= 0, nColumn
= 0;
83 get_columnIndex(&nColumn
);
85 *pColumnsSpanned
= m_xTable
->getAccessibleColumnExtentAt(nRow
, nColumn
);
94 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::get_columnHeaderCells(IUnknown
*** cellAccessibles
,
95 long* pColumnHeaderCellCount
)
99 if (!cellAccessibles
|| !pColumnHeaderCellCount
)
105 Reference
<XAccessibleTable
> xHeaders
= m_xTable
->getAccessibleColumnHeaders();
109 const sal_Int32 nCount
= xHeaders
->getAccessibleRowCount();
110 *pColumnHeaderCellCount
= nCount
;
111 *cellAccessibles
= static_cast<IUnknown
**>(CoTaskMemAlloc(nCount
* sizeof(IUnknown
*)));
113 get_columnIndex(&nCol
);
114 for (sal_Int32 nRow
= 0; nRow
< nCount
; nRow
++)
116 Reference
<XAccessible
> xCell
= xHeaders
->getAccessibleCellAt(nRow
, nCol
);
119 IAccessible
* pIAccessible
= CMAccessible::get_IAccessibleFromXAccessible(xCell
.get());
122 Reference
<XAccessible
> xTableAcc(m_xTable
, UNO_QUERY
);
123 CMAccessible::g_pAccObjectManager
->InsertAccObj(xCell
.get(), xTableAcc
.get());
124 pIAccessible
= CMAccessible::get_IAccessibleFromXAccessible(xCell
.get());
126 assert(pIAccessible
&& "Couldn't retrieve IAccessible object for cell.");
128 pIAccessible
->AddRef();
129 (*cellAccessibles
)[nRow
] = pIAccessible
;
134 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::get_columnIndex(long* pColumnIndex
)
140 if (pColumnIndex
== nullptr)
146 *pColumnIndex
= m_xTable
->getAccessibleColumn(m_nIndexInParent
);
155 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::get_rowExtent(long* pRowsSpanned
)
161 if (pRowsSpanned
== nullptr)
167 long nRow
= 0, nColumn
= 0;
169 get_columnIndex(&nColumn
);
171 *pRowsSpanned
= m_xTable
->getAccessibleRowExtentAt(nRow
, nColumn
);
181 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::get_rowHeaderCells(IUnknown
*** cellAccessibles
,
182 long* pRowHeaderCellCount
)
186 if (!cellAccessibles
|| !pRowHeaderCellCount
)
192 Reference
<XAccessibleTable
> xHeaders
= m_xTable
->getAccessibleRowHeaders();
196 const sal_Int32 nCount
= xHeaders
->getAccessibleColumnCount();
197 *pRowHeaderCellCount
= nCount
;
198 *cellAccessibles
= static_cast<IUnknown
**>(CoTaskMemAlloc(nCount
* sizeof(IUnknown
*)));
201 for (sal_Int32 nCol
= 0; nCol
< nCount
; nCol
++)
203 Reference
<XAccessible
> xCell
= xHeaders
->getAccessibleCellAt(nRow
, nCol
);
206 IAccessible
* pIAccessible
= CMAccessible::get_IAccessibleFromXAccessible(xCell
.get());
209 Reference
<XAccessible
> xTableAcc(m_xTable
, UNO_QUERY
);
210 CMAccessible::g_pAccObjectManager
->InsertAccObj(xCell
.get(), xTableAcc
.get());
211 pIAccessible
= CMAccessible::get_IAccessibleFromXAccessible(xCell
.get());
213 assert(pIAccessible
&& "Couldn't retrieve IAccessible object for cell.");
215 pIAccessible
->AddRef();
216 (*cellAccessibles
)[nCol
] = pIAccessible
;
221 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::get_rowIndex(long* pRowIndex
)
227 if (pRowIndex
== nullptr)
233 *pRowIndex
= m_xTable
->getAccessibleRow(m_nIndexInParent
);
242 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::get_isSelected(boolean
* pIsSelected
)
248 if (pIsSelected
== nullptr)
254 long nRow
= 0, nColumn
= 0;
256 get_columnIndex(&nColumn
);
258 *pIsSelected
= m_xTable
->isAccessibleSelected(nRow
, nColumn
);
267 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::get_rowColumnExtents(long* pRow
, long* pColumn
,
269 long* pColumnExtents
,
270 boolean
* pIsSelected
)
274 if (!pRow
|| !pColumn
|| !pRowExtents
|| !pColumnExtents
|| !pIsSelected
)
277 if (get_rowIndex(pRow
) != S_OK
)
279 if (get_columnIndex(pColumn
) != S_OK
)
281 if (get_rowExtent(pRowExtents
) != S_OK
)
283 if (get_columnExtent(pColumnExtents
) != S_OK
)
285 if (get_isSelected(pIsSelected
) != S_OK
)
290 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccTableCell::get_table(IUnknown
** ppTable
)
298 Reference
<XAccessible
> xAcc(m_xTable
, UNO_QUERY
);
302 IAccessible
* pRet
= CMAccessible::get_IAccessibleFromXAccessible(xAcc
.get());
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */