| 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 <com/sun/star/accessibility/AccessibleEventId.hpp> |
| 21 |
#include <com/sun/star/accessibility/AccessibleTableModelChange.hpp> |
| 22 |
#include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp> |
| 23 |
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
| 24 |
#include <controls/table/AccessibleGridControlTable.hxx> |
| 25 |
#include <controls/table/AccessibleGridControlTableCell.hxx> |
| 26 |
#include <vcl/svapp.hxx> |
| 27 |
#include <vcl/unohelp.hxx> |
| 28 |
#include <tools/debug.hxx> |
| 29 |
|
| 30 |
using ::com::sun::star::uno::Reference; |
| 31 |
using ::com::sun::star::uno::Sequence; |
| 32 |
using ::com::sun::star::uno::Any; |
| 33 |
|
| 34 |
using namespace ::com::sun::star; |
| 35 |
using namespace ::com::sun::star::accessibility; |
| 36 |
using namespace ::vcl; |
| 37 |
|
| 38 |
|
| 39 |
namespace accessibility { |
| 40 |
|
| 41 |
AccessibleGridControlTable::AccessibleGridControlTable(const Reference<XAccessible>& rxParent, |
| 42 |
svt::table::TableControl& rTable) |
| 43 |
: ImplInheritanceHelper(rxParent, rTable, AccessibleTableControlObjType::TABLE) |
| 44 |
{ |
| 45 |
} |
| 46 |
|
| 47 |
// XAccessibleContext --------------------------------------------------------- |
| 48 |
|
| 49 |
Reference< XAccessible > SAL_CALL |
| 50 |
AccessibleGridControlTable::getAccessibleChild( sal_Int64 nChildIndex ) |
| 51 |
{ |
| 52 |
SolarMutexGuard aSolarGuard; |
| 53 |
|
| 54 |
ensureAlive(); |
| 55 |
ensureIsValidIndex( nChildIndex ); |
| 56 |
sal_Int64 nCount = getAccessibleChildCount(); |
| 57 |
if(m_aCellVector.empty() || m_aCellVector.size() != static_cast<unsigned>(nCount)) |
| 58 |
{ |
| 59 |
assert(o3tl::make_unsigned(nCount) < m_aCellVector.max_size()); |
| 60 |
m_aCellVector.resize(nCount); |
| 61 |
} |
| 62 |
if(!m_aCellVector[nChildIndex].is()) |
| 63 |
{ |
| 64 |
m_aCellVector[nChildIndex].set(new AccessibleGridControlTableCell(this, m_aTable, nChildIndex/m_aTable.GetColumnCount(), nChildIndex%m_aTable.GetColumnCount())); |
| 65 |
} |
| 66 |
return m_aCellVector[nChildIndex]; |
| 67 |
} |
| 68 |
|
| 69 |
sal_Int64 SAL_CALL AccessibleGridControlTable::getAccessibleIndexInParent() |
| 70 |
{ |
| 71 |
SolarMutexGuard aSolarGuard; |
| 72 |
|
| 73 |
ensureAlive(); |
| 74 |
if(m_aTable.HasRowHeader() && m_aTable.HasColHeader()) |
| 75 |
return 0; |
| 76 |
else if(m_aTable.HasRowHeader() != m_aTable.HasColHeader()) |
| 77 |
return 1; |
| 78 |
else |
| 79 |
return 2; |
| 80 |
} |
| 81 |
|
| 82 |
// XAccessibleComponent ------------------------------------------------------- |
| 83 |
|
| 84 |
Reference< XAccessible > SAL_CALL |
| 85 |
AccessibleGridControlTable::getAccessibleAtPoint( const awt::Point& rPoint ) |
| 86 |
{ |
| 87 |
SolarMutexGuard aSolarGuard; |
| 88 |
|
| 89 |
ensureAlive(); |
| 90 |
|
| 91 |
// convert position relative to this AccessibleGridControlTable to position relative to |
| 92 |
// the parent TableControl by adding own relative position within the TableControl parent |
| 93 |
Point aPosInTableControl = vcl::unohelper::ConvertToVCLPoint(rPoint) + implGetBoundingBox().TopLeft(); |
| 94 |
sal_Int32 nRow = 0; |
| 95 |
sal_Int32 nColumnPos = 0; |
| 96 |
if (m_aTable.ConvertPointToCellAddress(nRow, nColumnPos, aPosInTableControl)) |
| 97 |
return getAccessibleCellAt(nRow, nColumnPos); |
| 98 |
return nullptr; |
| 99 |
} |
| 100 |
|
| 101 |
void SAL_CALL AccessibleGridControlTable::grabFocus() |
| 102 |
{ |
| 103 |
SolarMutexGuard aSolarGuard; |
| 104 |
|
| 105 |
ensureAlive(); |
| 106 |
m_aTable.GrabFocus(); |
| 107 |
} |
| 108 |
|
| 109 |
// XAccessibleTable ----------------------------------------------------------- |
| 110 |
|
| 111 |
OUString SAL_CALL AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow ) |
| 112 |
{ |
| 113 |
SolarMutexGuard aSolarGuard; |
| 114 |
|
| 115 |
ensureAlive(); |
| 116 |
ensureIsValidRow( nRow ); |
| 117 |
return u"row description"_ustr; |
| 118 |
} |
| 119 |
|
| 120 |
OUString SAL_CALL AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn ) |
| 121 |
{ |
| 122 |
SolarMutexGuard aSolarGuard; |
| 123 |
|
| 124 |
ensureAlive(); |
| 125 |
ensureIsValidColumn( nColumn ); |
| 126 |
return u"col description"_ustr; |
| 127 |
} |
| 128 |
|
| 129 |
Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleRowHeaders() |
| 130 |
{ |
| 131 |
SolarMutexGuard g; |
| 132 |
|
| 133 |
ensureAlive(); |
| 134 |
if(m_aTable.HasColHeader()) |
| 135 |
return implGetHeaderBar( 1 ); |
| 136 |
else |
| 137 |
return implGetHeaderBar( 0 ); |
| 138 |
} |
| 139 |
|
| 140 |
Reference< XAccessibleTable > SAL_CALL AccessibleGridControlTable::getAccessibleColumnHeaders() |
| 141 |
{ |
| 142 |
SolarMutexGuard g; |
| 143 |
|
| 144 |
ensureAlive(); |
| 145 |
return implGetHeaderBar( 0 ); |
| 146 |
} |
| 147 |
|
| 148 |
Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleRows() |
| 149 |
{ |
| 150 |
SolarMutexGuard aSolarGuard; |
| 151 |
|
| 152 |
ensureAlive(); |
| 153 |
Sequence< sal_Int32 > aSelSeq; |
| 154 |
implGetSelectedRows( aSelSeq ); |
| 155 |
return aSelSeq; |
| 156 |
} |
| 157 |
|
| 158 |
//columns aren't selectable |
| 159 |
Sequence< sal_Int32 > SAL_CALL AccessibleGridControlTable::getSelectedAccessibleColumns() |
| 160 |
{ |
| 161 |
return {}; |
| 162 |
} |
| 163 |
|
| 164 |
sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow ) |
| 165 |
{ |
| 166 |
SolarMutexGuard aSolarGuard; |
| 167 |
|
| 168 |
ensureAlive(); |
| 169 |
ensureIsValidRow( nRow ); |
| 170 |
Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows(); |
| 171 |
return comphelper::findValue(selectedRows, nRow) != -1; |
| 172 |
} |
| 173 |
|
| 174 |
//columns aren't selectable |
| 175 |
sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32 ) |
| 176 |
{ |
| 177 |
return false; |
| 178 |
} |
| 179 |
|
| 180 |
Reference< XAccessible > SAL_CALL AccessibleGridControlTable::getAccessibleCellAt( |
| 181 |
sal_Int32 nRow, sal_Int32 nColumn ) |
| 182 |
{ |
| 183 |
SolarMutexGuard aSolarGuard; |
| 184 |
|
| 185 |
ensureAlive(); |
| 186 |
ensureIsValidAddress( nRow, nColumn ); |
| 187 |
sal_Int64 nChildIndex = static_cast<sal_Int64>(nRow) * static_cast<sal_Int64>(m_aTable.GetColumnCount()) + nColumn; |
| 188 |
return getAccessibleChild(nChildIndex); |
| 189 |
} |
| 190 |
|
| 191 |
sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleSelected( |
| 192 |
sal_Int32 nRow, sal_Int32 nColumn ) |
| 193 |
{ |
| 194 |
SolarMutexGuard aSolarGuard; |
| 195 |
|
| 196 |
ensureAlive(); |
| 197 |
ensureIsValidAddress( nRow, nColumn ); |
| 198 |
//selection of single cells not possible, so if row is selected, the cell will be selected too |
| 199 |
return isAccessibleRowSelected(nRow); |
| 200 |
} |
| 201 |
void SAL_CALL AccessibleGridControlTable::selectAccessibleChild( sal_Int64 nChildIndex ) |
| 202 |
{ |
| 203 |
SolarMutexGuard aSolarGuard; |
| 204 |
|
| 205 |
ensureAlive(); |
| 206 |
ensureIsValidIndex( nChildIndex ); |
| 207 |
sal_Int32 nColumns = m_aTable.GetColumnCount(); |
| 208 |
sal_Int32 nRow = nChildIndex / nColumns; |
| 209 |
m_aTable.SelectRow( nRow, true ); |
| 210 |
} |
| 211 |
sal_Bool SAL_CALL AccessibleGridControlTable::isAccessibleChildSelected( sal_Int64 nChildIndex ) |
| 212 |
{ |
| 213 |
SolarMutexGuard aSolarGuard; |
| 214 |
|
| 215 |
ensureAlive(); |
| 216 |
ensureIsValidIndex( nChildIndex ); |
| 217 |
sal_Int32 nColumns = m_aTable.GetColumnCount(); |
| 218 |
sal_Int32 nRow = nChildIndex / nColumns; |
| 219 |
return isAccessibleRowSelected(nRow); |
| 220 |
} |
| 221 |
void SAL_CALL AccessibleGridControlTable::clearAccessibleSelection() |
| 222 |
{ |
| 223 |
SolarMutexGuard aSolarGuard; |
| 224 |
|
| 225 |
ensureAlive(); |
| 226 |
m_aTable.SelectAllRows( false ); |
| 227 |
} |
| 228 |
void SAL_CALL AccessibleGridControlTable::selectAllAccessibleChildren() |
| 229 |
{ |
| 230 |
SolarMutexGuard aSolarGuard; |
| 231 |
|
| 232 |
ensureAlive(); |
| 233 |
Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows(); |
| 234 |
auto selectedRowsRange = asNonConstRange(selectedRows); |
| 235 |
for(tools::Long i=0; i<m_aTable.GetRowCount(); i++) |
| 236 |
selectedRowsRange[i]=i; |
| 237 |
} |
| 238 |
sal_Int64 SAL_CALL AccessibleGridControlTable::getSelectedAccessibleChildCount() |
| 239 |
{ |
| 240 |
SolarMutexGuard aSolarGuard; |
| 241 |
|
| 242 |
ensureAlive(); |
| 243 |
Sequence< sal_Int32 > selectedRows = getSelectedAccessibleRows(); |
| 244 |
sal_Int32 nColumns = m_aTable.GetColumnCount(); |
| 245 |
return static_cast<sal_Int64>(selectedRows.getLength()) * static_cast<sal_Int64>(nColumns); |
| 246 |
} |
| 247 |
Reference< XAccessible > SAL_CALL |
| 248 |
AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex ) |
| 249 |
{ |
| 250 |
SolarMutexGuard aSolarGuard; |
| 251 |
|
| 252 |
ensureAlive(); |
| 253 |
if (nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount()) |
| 254 |
throw lang::IndexOutOfBoundsException(u"Invalid index into selection"_ustr, *this); |
| 255 |
|
| 256 |
const sal_Int32 nColCount = getAccessibleColumnCount(); |
| 257 |
assert(nColCount > 0 && "Column count non-positive, but child count > 0"); |
| 258 |
const sal_Int32 nIndexInSelectedRowsSequence = nSelectedChildIndex / nColCount; |
| 259 |
const Sequence<sal_Int32> aSelectedRows = getSelectedAccessibleRows(); |
| 260 |
const sal_Int32 nRowIndex = aSelectedRows[nIndexInSelectedRowsSequence]; |
| 261 |
const sal_Int32 nColIndex = nSelectedChildIndex % nColCount; |
| 262 |
return getAccessibleCellAt(nRowIndex, nColIndex); |
| 263 |
} |
| 264 |
//not implemented yet, because only row selection possible |
| 265 |
void SAL_CALL AccessibleGridControlTable::deselectAccessibleChild( |
| 266 |
sal_Int64 ) |
| 267 |
{ |
| 268 |
SolarMutexGuard aSolarGuard; |
| 269 |
|
| 270 |
ensureAlive(); |
| 271 |
} |
| 272 |
|
| 273 |
// XServiceInfo --------------------------------------------------------------- |
| 274 |
|
| 275 |
OUString SAL_CALL AccessibleGridControlTable::getImplementationName() |
| 276 |
{ |
| 277 |
return u"com.sun.star.accessibility.AccessibleGridControlTable"_ustr; |
| 278 |
} |
| 279 |
|
| 280 |
void AccessibleGridControlTable::dispose() |
| 281 |
{ |
| 282 |
for (rtl::Reference<AccessibleGridControlTableCell>& rxCell : m_aCellVector) |
| 283 |
{ |
| 284 |
if (rxCell.is()) |
| 285 |
{ |
| 286 |
rxCell->dispose(); |
| 287 |
rxCell.clear(); |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
AccessibleGridControlTableBase::dispose(); |
| 292 |
} |
| 293 |
|
| 294 |
void AccessibleGridControlTable::commitEvent(sal_Int16 nEventId, const css::uno::Any& rNewValue, |
| 295 |
const css::uno::Any& rOldValue) |
| 296 |
{ |
| 297 |
if (nEventId == AccessibleEventId::TABLE_MODEL_CHANGED) |
| 298 |
{ |
| 299 |
AccessibleTableModelChange aChange; |
| 300 |
if (rNewValue >>= aChange) |
| 301 |
{ |
| 302 |
assert(aChange.Type != AccessibleTableModelChangeType::COLUMNS_REMOVED); |
| 303 |
|
| 304 |
if (aChange.Type == AccessibleTableModelChangeType::ROWS_REMOVED) |
| 305 |
{ |
| 306 |
int nColCount = m_aTable.GetColumnCount(); |
| 307 |
// check valid index - entries are inserted lazily |
| 308 |
size_t const nStart = nColCount * aChange.FirstRow; |
| 309 |
size_t const nEnd = nColCount * aChange.LastRow; |
| 310 |
if (nStart < m_aCellVector.size()) |
| 311 |
{ |
| 312 |
m_aCellVector.erase( |
| 313 |
m_aCellVector.begin() + nStart, |
| 314 |
m_aCellVector.begin() + std::min(m_aCellVector.size(), nEnd)); |
| 315 |
} |
| 316 |
} |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
AccessibleGridControlBase::commitEvent(nEventId, rNewValue, rOldValue); |
| 321 |
} |
| 322 |
|
| 323 |
// internal virtual methods --------------------------------------------------- |
| 324 |
|
| 325 |
AbsoluteScreenPixelRectangle AccessibleGridControlTable::implGetBoundingBoxOnScreen() |
| 326 |
{ |
| 327 |
tools::Rectangle aGridRect( m_aTable.GetWindowExtentsAbsolute()); |
| 328 |
tools::Rectangle aTableRect( m_aTable.calcTableRect() ); |
| 329 |
tools::Long nX = aGridRect.Left() + aTableRect.Left(); |
| 330 |
tools::Long nY = aGridRect.Top() + aTableRect.Top(); |
| 331 |
tools::Long nWidth = aGridRect.GetSize().Width()-aTableRect.Left(); |
| 332 |
tools::Long nHeight = aGridRect.GetSize().Height()-aTableRect.Top(); |
| 333 |
AbsoluteScreenPixelRectangle aTable( AbsoluteScreenPixelPoint( nX, nY ), AbsoluteScreenPixelSize( nWidth, nHeight )); |
| 334 |
return aTable; |
| 335 |
} |
| 336 |
|
| 337 |
// internal helper methods ---------------------------------------------------- |
| 338 |
Reference< XAccessibleTable > AccessibleGridControlTable::implGetHeaderBar( |
| 339 |
sal_Int32 nChildIndex ) |
| 340 |
{ |
| 341 |
Reference< XAccessible > xRet; |
| 342 |
|
| 343 |
if (!m_xParent.is()) |
| 344 |
return nullptr; |
| 345 |
|
| 346 |
Reference<XAccessibleContext> xContext = m_xParent->getAccessibleContext(); |
| 347 |
if( xContext.is() ) |
| 348 |
{ |
| 349 |
try |
| 350 |
{ |
| 351 |
xRet = xContext->getAccessibleChild( nChildIndex ); |
| 352 |
} |
| 353 |
catch (const lang::IndexOutOfBoundsException&) |
| 354 |
{ |
| 355 |
OSL_FAIL( "implGetHeaderBar - wrong child index" ); |
| 356 |
} |
| 357 |
// RuntimeException goes to caller |
| 358 |
} |
| 359 |
return Reference< XAccessibleTable >( xRet, uno::UNO_QUERY ); |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
} // namespace accessibility |
| 364 |
|
| 365 |
|
| 366 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |