office-gobmx/winaccessibility/source/UAccCOM/AccTableCell.cxx
Michael Weghorn 97a88e30e2 tdf#100086 tdf#124832 wina11y: Implement IAccessibleTableCell
Add a new class 'AccTableCell' that implements the
IAccessibleTableCell interface from the IAccessible2 spec
and add what's needed to expose it to accessibility tools
via COM.

Since there's no specific XInterface for table cells
that an XAccessible's context could be queried for,
make use of the fact that a table cell's
parent is a table, i.e. its accessible context implements
XAccessibleTable.

AccTableCell keeps a reference to that table and remembers the
cell's index in the parent to retrieve information
on the cell from there.

This addresses the

> At least for LibreOffice Table Cells don't implement
> IAccessibleTableCell, and therefore there's no way to get the row and
> column span. LibreOffice itself also does not expose the merged state in
> the accessible name of the cell.

comment from [1] (which is the NVDA counterpart for LO's
tdf#124832) and may also help for tdf#100086,
though more work will be needed on LibreOffice and/or NVDA
side for both issues.

[1] https://github.com/nvaccess/nvda/issues/9310

Change-Id: I0f53212d14ee17c760b9e6c91be2154a1b25d862
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121821
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
2021-09-08 20:06:00 +02:00

168 lines
4.1 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "AccTableCell.h"
#include <vcl/svapp.hxx>
#include <com/sun/star/accessibility/XAccessible.hpp>
using namespace com::sun::star::accessibility;
using namespace com::sun::star::uno;
CAccTableCell::CAccTableCell()
: m_nIndexInParent(0)
{
}
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::put_XInterface(hyper pXInterface)
{
// internal IUNOXWrapper - no mutex meeded
ENTER_PROTECTED_BLOCK
CUNOXWrapper::put_XInterface(pXInterface);
if (pUNOInterface == nullptr)
return E_INVALIDARG;
Reference<XAccessibleContext> xContext = pUNOInterface->getAccessibleContext();
if (!xContext.is())
return E_FAIL;
// retrieve reference to table (parent of the cell)
Reference<XAccessibleContext> xParentContext
= xContext->getAccessibleParent()->getAccessibleContext();
Reference<XAccessibleTable> xTable(xParentContext, UNO_QUERY);
if (!xTable.is())
{
m_xTable.clear();
return E_FAIL;
}
m_xTable = xTable;
m_nIndexInParent = xContext->getAccessibleIndexInParent();
return S_OK;
LEAVE_PROTECTED_BLOCK
}
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_columnExtent(long* pColumnsSpanned)
{
SolarMutexGuard g;
ENTER_PROTECTED_BLOCK
if (pColumnsSpanned == nullptr)
return E_INVALIDARG;
if (!m_xTable.is())
return E_FAIL;
long nRow = 0, nColumn = 0;
get_rowIndex(&nRow);
get_columnIndex(&nColumn);
*pColumnsSpanned = m_xTable->getAccessibleColumnExtentAt(nRow, nColumn);
return S_OK;
LEAVE_PROTECTED_BLOCK
}
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_columnIndex(long* pColumnIndex)
{
SolarMutexGuard g;
ENTER_PROTECTED_BLOCK
if (pColumnIndex == nullptr)
return E_INVALIDARG;
if (!m_xTable.is())
return E_FAIL;
*pColumnIndex = m_xTable->getAccessibleColumn(m_nIndexInParent);
return S_OK;
LEAVE_PROTECTED_BLOCK
}
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_rowExtent(long* pRowsSpanned)
{
SolarMutexGuard g;
ENTER_PROTECTED_BLOCK
if (pRowsSpanned == nullptr)
return E_INVALIDARG;
if (!m_xTable.is())
return E_FAIL;
long nRow = 0, nColumn = 0;
get_rowIndex(&nRow);
get_columnIndex(&nColumn);
*pRowsSpanned = m_xTable->getAccessibleRowExtentAt(nRow, nColumn);
return S_OK;
LEAVE_PROTECTED_BLOCK
}
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_rowIndex(long* pRowIndex)
{
SolarMutexGuard g;
ENTER_PROTECTED_BLOCK
if (pRowIndex == nullptr)
return E_INVALIDARG;
if (!m_xTable.is())
return E_FAIL;
*pRowIndex = m_xTable->getAccessibleRow(m_nIndexInParent);
return S_OK;
LEAVE_PROTECTED_BLOCK
}
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTableCell::get_isSelected(boolean* pIsSelected)
{
SolarMutexGuard g;
ENTER_PROTECTED_BLOCK
if (pIsSelected == nullptr)
return E_INVALIDARG;
if (!m_xTable.is())
return E_FAIL;
long nRow = 0, nColumn = 0;
get_rowIndex(&nRow);
get_columnIndex(&nColumn);
*pIsSelected = m_xTable->isAccessibleSelected(nRow, nColumn);
return S_OK;
LEAVE_PROTECTED_BLOCK
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */