| 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/AccessibleRole.hpp> |
| 21 |
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
| 22 |
#include <controls/table/AccessibleGridControlTableBase.hxx> |
| 23 |
#include <vcl/svapp.hxx> |
| 24 |
#include <comphelper/sequence.hxx> |
| 25 |
|
| 26 |
using css::uno::Reference; |
| 27 |
using css::uno::Sequence; |
| 28 |
using css::uno::Any; |
| 29 |
|
| 30 |
using namespace ::com::sun::star; |
| 31 |
using namespace ::com::sun::star::accessibility; |
| 32 |
using namespace ::vcl; |
| 33 |
|
| 34 |
|
| 35 |
namespace accessibility { |
| 36 |
|
| 37 |
|
| 38 |
AccessibleGridControlTableBase::AccessibleGridControlTableBase( |
| 39 |
const Reference< XAccessible >& rxParent, |
| 40 |
svt::table::TableControl& rTable, |
| 41 |
AccessibleTableControlObjType eObjType ) : |
| 42 |
AccessibleGridControlTableImplHelper( rxParent, rTable, eObjType ) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
// XAccessibleContext --------------------------------------------------------- |
| 47 |
|
| 48 |
sal_Int64 SAL_CALL AccessibleGridControlTableBase::getAccessibleChildCount() |
| 49 |
{ |
| 50 |
SolarMutexGuard aSolarGuard; |
| 51 |
|
| 52 |
ensureAlive(); |
| 53 |
sal_Int64 nChildren = 0; |
| 54 |
if (m_eObjType == AccessibleTableControlObjType::ROWHEADERBAR) |
| 55 |
nChildren = m_aTable.GetRowCount(); |
| 56 |
else if (m_eObjType == AccessibleTableControlObjType::TABLE) |
| 57 |
nChildren = static_cast<sal_Int64>(m_aTable.GetRowCount()) * static_cast<sal_Int64>(m_aTable.GetColumnCount()); |
| 58 |
else if (m_eObjType == AccessibleTableControlObjType::COLUMNHEADERBAR) |
| 59 |
nChildren = m_aTable.GetColumnCount(); |
| 60 |
return nChildren; |
| 61 |
} |
| 62 |
|
| 63 |
sal_Int16 SAL_CALL AccessibleGridControlTableBase::getAccessibleRole() |
| 64 |
{ |
| 65 |
SolarMutexGuard g; |
| 66 |
|
| 67 |
ensureAlive(); |
| 68 |
return AccessibleRole::TABLE; |
| 69 |
} |
| 70 |
|
| 71 |
// XAccessibleTable ----------------------------------------------------------- |
| 72 |
|
| 73 |
sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowCount() |
| 74 |
{ |
| 75 |
SolarMutexGuard aSolarGuard; |
| 76 |
|
| 77 |
ensureAlive(); |
| 78 |
|
| 79 |
if (m_eObjType == AccessibleTableControlObjType::COLUMNHEADERBAR) |
| 80 |
return 1; |
| 81 |
return m_aTable.GetRowCount(); |
| 82 |
} |
| 83 |
|
| 84 |
sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnCount() |
| 85 |
{ |
| 86 |
SolarMutexGuard aSolarGuard; |
| 87 |
|
| 88 |
ensureAlive(); |
| 89 |
|
| 90 |
if (m_eObjType == AccessibleTableControlObjType::ROWHEADERBAR) |
| 91 |
return 1; |
| 92 |
return m_aTable.GetColumnCount(); |
| 93 |
} |
| 94 |
|
| 95 |
sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowExtentAt( |
| 96 |
sal_Int32 nRow, sal_Int32 nColumn ) |
| 97 |
{ |
| 98 |
SolarMutexGuard aSolarGuard; |
| 99 |
|
| 100 |
ensureAlive(); |
| 101 |
ensureIsValidAddress( nRow, nColumn ); |
| 102 |
return 1; // merged cells not supported |
| 103 |
} |
| 104 |
|
| 105 |
sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnExtentAt( |
| 106 |
sal_Int32 nRow, sal_Int32 nColumn ) |
| 107 |
{ |
| 108 |
SolarMutexGuard aSolarGuard; |
| 109 |
|
| 110 |
ensureAlive(); |
| 111 |
ensureIsValidAddress( nRow, nColumn ); |
| 112 |
return 1; // merged cells not supported |
| 113 |
} |
| 114 |
|
| 115 |
Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleCaption() |
| 116 |
{ |
| 117 |
SolarMutexGuard g; |
| 118 |
|
| 119 |
ensureAlive(); |
| 120 |
return nullptr; // not supported |
| 121 |
} |
| 122 |
|
| 123 |
Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleSummary() |
| 124 |
{ |
| 125 |
SolarMutexGuard g; |
| 126 |
|
| 127 |
ensureAlive(); |
| 128 |
return nullptr; // not supported |
| 129 |
} |
| 130 |
|
| 131 |
sal_Int64 SAL_CALL AccessibleGridControlTableBase::getAccessibleIndex( |
| 132 |
sal_Int32 nRow, sal_Int32 nColumn ) |
| 133 |
{ |
| 134 |
SolarMutexGuard aSolarGuard; |
| 135 |
|
| 136 |
ensureAlive(); |
| 137 |
ensureIsValidAddress( nRow, nColumn ); |
| 138 |
return static_cast<sal_Int64>(nRow) * static_cast<sal_Int64>(m_aTable.GetColumnCount()) + nColumn; |
| 139 |
} |
| 140 |
|
| 141 |
sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRow( sal_Int64 nChildIndex ) |
| 142 |
{ |
| 143 |
SolarMutexGuard aSolarGuard; |
| 144 |
|
| 145 |
ensureAlive(); |
| 146 |
ensureIsValidIndex( nChildIndex ); |
| 147 |
return implGetRow( nChildIndex ); |
| 148 |
} |
| 149 |
|
| 150 |
sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumn( sal_Int64 nChildIndex ) |
| 151 |
{ |
| 152 |
SolarMutexGuard aSolarGuard; |
| 153 |
|
| 154 |
ensureAlive(); |
| 155 |
ensureIsValidIndex( nChildIndex ); |
| 156 |
return implGetColumn( nChildIndex ); |
| 157 |
} |
| 158 |
|
| 159 |
// internal helper methods ---------------------------------------------------- |
| 160 |
|
| 161 |
sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int64 nChildIndex ) |
| 162 |
{ |
| 163 |
sal_Int32 nColumns = getAccessibleColumnCount(); |
| 164 |
return nColumns ? (nChildIndex / nColumns) : 0; |
| 165 |
} |
| 166 |
|
| 167 |
sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int64 nChildIndex ) |
| 168 |
{ |
| 169 |
sal_Int32 nColumns = getAccessibleColumnCount(); |
| 170 |
return nColumns ? (nChildIndex % nColumns) : 0; |
| 171 |
} |
| 172 |
|
| 173 |
void AccessibleGridControlTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq ) |
| 174 |
{ |
| 175 |
sal_Int32 const selectionCount( m_aTable.GetSelectedRowCount() ); |
| 176 |
rSeq.realloc( selectionCount ); |
| 177 |
auto pSeq = rSeq.getArray(); |
| 178 |
for ( sal_Int32 i=0; i<selectionCount; ++i ) |
| 179 |
pSeq[i] = m_aTable.GetSelectedRowIndex(i); |
| 180 |
} |
| 181 |
|
| 182 |
void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow ) |
| 183 |
{ |
| 184 |
if (nRow < 0 || nRow >= getAccessibleRowCount()) |
| 185 |
throw lang::IndexOutOfBoundsException( u"row index is invalid"_ustr, *this ); |
| 186 |
} |
| 187 |
|
| 188 |
void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn ) |
| 189 |
{ |
| 190 |
if (nColumn < 0 || nColumn >= getAccessibleColumnCount()) |
| 191 |
throw lang::IndexOutOfBoundsException( u"column index is invalid"_ustr, *this ); |
| 192 |
} |
| 193 |
|
| 194 |
void AccessibleGridControlTableBase::ensureIsValidAddress( |
| 195 |
sal_Int32 nRow, sal_Int32 nColumn ) |
| 196 |
{ |
| 197 |
ensureIsValidRow( nRow ); |
| 198 |
ensureIsValidColumn( nColumn ); |
| 199 |
} |
| 200 |
|
| 201 |
void AccessibleGridControlTableBase::ensureIsValidIndex( sal_Int64 nChildIndex ) |
| 202 |
{ |
| 203 |
if (nChildIndex < 0 || nChildIndex >= static_cast<sal_Int64>(m_aTable.GetRowCount()) * static_cast<sal_Int64>(m_aTable.GetColumnCount())) |
| 204 |
throw lang::IndexOutOfBoundsException( u"child index is invalid"_ustr, *this ); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
} // namespace accessibility |
| 209 |
|
| 210 |
|
| 211 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |