| 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 <controls/table/AccessibleGridControlTableCell.hxx> |
| 21 |
#include <vcl/svapp.hxx> |
| 22 |
#include <vcl/unohelp.hxx> |
| 23 |
#include <tools/gen.hxx> |
| 24 |
#include <tools/debug.hxx> |
| 25 |
#include <com/sun/star/accessibility/AccessibleStateType.hpp> |
| 26 |
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
| 27 |
|
| 28 |
namespace accessibility |
| 29 |
{ |
| 30 |
namespace |
| 31 |
{ |
| 32 |
// FIXME this is a copy'n'paste from |
| 33 |
// source/accessibility/AccessibleBrowseBoxTableCell.cxx, get rid of that... |
| 34 |
/// @throws css::lang::IndexOutOfBoundsException |
| 35 |
void checkIndex_Impl(sal_Int32 _nIndex, std::u16string_view _sText) |
| 36 |
{ |
| 37 |
if (_nIndex >= static_cast<sal_Int32>(_sText.size())) |
| 38 |
throw css::lang::IndexOutOfBoundsException(); |
| 39 |
} |
| 40 |
} |
| 41 |
using namespace ::com::sun::star::lang; |
| 42 |
using namespace comphelper; |
| 43 |
using namespace ::com::sun::star::uno; |
| 44 |
using ::com::sun::star::accessibility::XAccessible; |
| 45 |
using namespace ::com::sun::star::accessibility; |
| 46 |
using namespace ::vcl; |
| 47 |
|
| 48 |
// = AccessibleGridControlCell |
| 49 |
|
| 50 |
AccessibleGridControlCell::AccessibleGridControlCell( |
| 51 |
const css::uno::Reference<css::accessibility::XAccessible>& _rxParent, |
| 52 |
svt::table::TableControl& _rTable, sal_Int32 _nRowPos, sal_uInt16 _nColPos, |
| 53 |
AccessibleTableControlObjType _eType) |
| 54 |
: AccessibleGridControlBase(_rxParent, _rTable, _eType) |
| 55 |
, m_nRowPos(_nRowPos) |
| 56 |
, m_nColPos(_nColPos) |
| 57 |
{ |
| 58 |
assert(((m_eObjType == AccessibleTableControlObjType::TABLECELL) |
| 59 |
|| ((m_eObjType == AccessibleTableControlObjType::ROWHEADERCELL) && _nColPos == 0) |
| 60 |
|| ((m_eObjType == AccessibleTableControlObjType::COLUMNHEADERCELL) && _nRowPos == 0)) |
| 61 |
&& "Unhandled table cell type"); |
| 62 |
} |
| 63 |
|
| 64 |
void SAL_CALL AccessibleGridControlCell::grabFocus() |
| 65 |
{ |
| 66 |
SolarMutexGuard aSolarGuard; |
| 67 |
|
| 68 |
m_aTable.GoToCell(m_nColPos, m_nRowPos); |
| 69 |
} |
| 70 |
|
| 71 |
OUString SAL_CALL AccessibleGridControlCell::getAccessibleName() |
| 72 |
{ |
| 73 |
SolarMutexGuard g; |
| 74 |
|
| 75 |
ensureAlive(); |
| 76 |
return m_aTable.GetAccessibleObjectName(m_eObjType, m_nRowPos, m_nColPos); |
| 77 |
} |
| 78 |
|
| 79 |
// implementation of a table cell |
| 80 |
OUString AccessibleGridControlTableCell::implGetText() |
| 81 |
{ |
| 82 |
ensureAlive(); |
| 83 |
return m_aTable.GetAccessibleCellText(getRowPos(), getColumnPos()); |
| 84 |
} |
| 85 |
|
| 86 |
css::lang::Locale AccessibleGridControlTableCell::implGetLocale() |
| 87 |
{ |
| 88 |
ensureAlive(); |
| 89 |
return m_aTable.GetAccessible()->getLocale(); |
| 90 |
} |
| 91 |
|
| 92 |
void AccessibleGridControlTableCell::implGetSelection(sal_Int32& nStartIndex, sal_Int32& nEndIndex) |
| 93 |
{ |
| 94 |
nStartIndex = 0; |
| 95 |
nEndIndex = 0; |
| 96 |
} |
| 97 |
|
| 98 |
AccessibleGridControlTableCell::AccessibleGridControlTableCell( |
| 99 |
const css::uno::Reference<XAccessible>& _rxParent, svt::table::TableControl& _rTable, |
| 100 |
sal_Int32 _nRowPos, sal_uInt16 _nColPos) |
| 101 |
: ImplInheritanceHelper(_rxParent, _rTable, _nRowPos, _nColPos, |
| 102 |
AccessibleTableControlObjType::TABLECELL) |
| 103 |
{ |
| 104 |
} |
| 105 |
|
| 106 |
css::awt::Rectangle SAL_CALL AccessibleGridControlTableCell::getCharacterBounds(sal_Int32 nIndex) |
| 107 |
{ |
| 108 |
SolarMutexGuard aSolarGuard; |
| 109 |
|
| 110 |
ensureAlive(); |
| 111 |
if (!implIsValidIndex(nIndex, implGetText().getLength())) |
| 112 |
throw IndexOutOfBoundsException(); |
| 113 |
|
| 114 |
return vcl::unohelper::ConvertToAWTRect(m_aTable.GetCharacterBounds(nIndex)); |
| 115 |
} |
| 116 |
|
| 117 |
sal_Int32 SAL_CALL AccessibleGridControlTableCell::getIndexAtPoint(const css::awt::Point& _aPoint) |
| 118 |
{ |
| 119 |
SolarMutexGuard aSolarGuard; |
| 120 |
|
| 121 |
ensureAlive(); |
| 122 |
|
| 123 |
return m_aTable.GetIndexForPoint(vcl::unohelper::ConvertToVCLPoint(_aPoint)); |
| 124 |
} |
| 125 |
|
| 126 |
/** @return |
| 127 |
The name of this class. |
| 128 |
*/ |
| 129 |
OUString SAL_CALL AccessibleGridControlTableCell::getImplementationName() |
| 130 |
{ |
| 131 |
return u"com.sun.star.accessibility.AccessibleGridControlTableCell"_ustr; |
| 132 |
} |
| 133 |
|
| 134 |
/** @return The count of visible children. */ |
| 135 |
sal_Int64 SAL_CALL AccessibleGridControlTableCell::getAccessibleChildCount() { return 0; } |
| 136 |
|
| 137 |
/** @return The css::accessibility::XAccessible interface of the specified child. */ |
| 138 |
css::uno::Reference<css::accessibility::XAccessible> |
| 139 |
SAL_CALL AccessibleGridControlTableCell::getAccessibleChild(sal_Int64) |
| 140 |
{ |
| 141 |
throw css::lang::IndexOutOfBoundsException(); |
| 142 |
} |
| 143 |
|
| 144 |
/** Return a bitset of states of the current object. |
| 145 |
*/ |
| 146 |
sal_Int64 AccessibleGridControlTableCell::implCreateStateSet() |
| 147 |
{ |
| 148 |
sal_Int64 nStateSet = 0; |
| 149 |
|
| 150 |
if (isAlive()) |
| 151 |
{ |
| 152 |
// SHOWING done with mxParent |
| 153 |
if (implIsShowing()) |
| 154 |
nStateSet |= AccessibleStateType::SHOWING; |
| 155 |
|
| 156 |
m_aTable.FillAccessibleStateSetForCell(nStateSet, getRowPos(), |
| 157 |
static_cast<sal_uInt16>(getColumnPos())); |
| 158 |
} |
| 159 |
else |
| 160 |
nStateSet |= AccessibleStateType::DEFUNC; |
| 161 |
|
| 162 |
return nStateSet; |
| 163 |
} |
| 164 |
|
| 165 |
// css::accessibility::XAccessibleContext |
| 166 |
|
| 167 |
sal_Int64 SAL_CALL AccessibleGridControlTableCell::getAccessibleIndexInParent() |
| 168 |
{ |
| 169 |
SolarMutexGuard aSolarGuard; |
| 170 |
|
| 171 |
ensureAlive(); |
| 172 |
|
| 173 |
return (static_cast<sal_Int64>(getRowPos()) * static_cast<sal_Int64>(m_aTable.GetColumnCount())) |
| 174 |
+ getColumnPos(); |
| 175 |
} |
| 176 |
|
| 177 |
sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCaretPosition() { return -1; } |
| 178 |
sal_Bool SAL_CALL AccessibleGridControlTableCell::setCaretPosition(sal_Int32 nIndex) |
| 179 |
{ |
| 180 |
SolarMutexGuard aSolarGuard; |
| 181 |
|
| 182 |
if (!implIsValidRange(nIndex, nIndex, implGetText().getLength())) |
| 183 |
throw IndexOutOfBoundsException(); |
| 184 |
|
| 185 |
return false; |
| 186 |
} |
| 187 |
sal_Unicode SAL_CALL AccessibleGridControlTableCell::getCharacter(sal_Int32 nIndex) |
| 188 |
{ |
| 189 |
SolarMutexGuard aSolarGuard; |
| 190 |
|
| 191 |
return OCommonAccessibleText::implGetCharacter(implGetText(), nIndex); |
| 192 |
} |
| 193 |
css::uno::Sequence<css::beans::PropertyValue> SAL_CALL |
| 194 |
AccessibleGridControlTableCell::getCharacterAttributes(sal_Int32 nIndex, |
| 195 |
const css::uno::Sequence<OUString>&) |
| 196 |
{ |
| 197 |
SolarMutexGuard aSolarGuard; |
| 198 |
|
| 199 |
OUString sText(implGetText()); |
| 200 |
|
| 201 |
if (!implIsValidIndex(nIndex, sText.getLength())) |
| 202 |
throw IndexOutOfBoundsException(); |
| 203 |
|
| 204 |
return css::uno::Sequence<css::beans::PropertyValue>(); |
| 205 |
} |
| 206 |
sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCharacterCount() |
| 207 |
{ |
| 208 |
SolarMutexGuard aSolarGuard; |
| 209 |
|
| 210 |
return implGetText().getLength(); |
| 211 |
} |
| 212 |
|
| 213 |
OUString SAL_CALL AccessibleGridControlTableCell::getSelectedText() { return OUString(); } |
| 214 |
sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionStart() { return 0; } |
| 215 |
sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionEnd() { return 0; } |
| 216 |
sal_Bool SAL_CALL AccessibleGridControlTableCell::setSelection(sal_Int32 nStartIndex, |
| 217 |
sal_Int32 nEndIndex) |
| 218 |
{ |
| 219 |
SolarMutexGuard aSolarGuard; |
| 220 |
|
| 221 |
if (!implIsValidRange(nStartIndex, nEndIndex, implGetText().getLength())) |
| 222 |
throw IndexOutOfBoundsException(); |
| 223 |
|
| 224 |
return false; |
| 225 |
} |
| 226 |
OUString SAL_CALL AccessibleGridControlTableCell::getText() |
| 227 |
{ |
| 228 |
SolarMutexGuard aSolarGuard; |
| 229 |
|
| 230 |
return implGetText(); |
| 231 |
} |
| 232 |
OUString SAL_CALL AccessibleGridControlTableCell::getTextRange(sal_Int32 nStartIndex, |
| 233 |
sal_Int32 nEndIndex) |
| 234 |
{ |
| 235 |
SolarMutexGuard aSolarGuard; |
| 236 |
|
| 237 |
return OCommonAccessibleText::implGetTextRange(implGetText(), nStartIndex, nEndIndex); |
| 238 |
} |
| 239 |
css::accessibility::TextSegment SAL_CALL |
| 240 |
AccessibleGridControlTableCell::getTextAtIndex(sal_Int32 nIndex, sal_Int16 aTextType) |
| 241 |
{ |
| 242 |
SolarMutexGuard aSolarGuard; |
| 243 |
|
| 244 |
return OCommonAccessibleText::getTextAtIndex(nIndex, aTextType); |
| 245 |
} |
| 246 |
css::accessibility::TextSegment SAL_CALL |
| 247 |
AccessibleGridControlTableCell::getTextBeforeIndex(sal_Int32 nIndex, sal_Int16 aTextType) |
| 248 |
{ |
| 249 |
SolarMutexGuard aSolarGuard; |
| 250 |
|
| 251 |
return OCommonAccessibleText::getTextBeforeIndex(nIndex, aTextType); |
| 252 |
} |
| 253 |
css::accessibility::TextSegment SAL_CALL |
| 254 |
AccessibleGridControlTableCell::getTextBehindIndex(sal_Int32 nIndex, sal_Int16 aTextType) |
| 255 |
{ |
| 256 |
SolarMutexGuard aSolarGuard; |
| 257 |
|
| 258 |
return OCommonAccessibleText::getTextBehindIndex(nIndex, aTextType); |
| 259 |
} |
| 260 |
sal_Bool SAL_CALL AccessibleGridControlTableCell::copyText(sal_Int32 nStartIndex, |
| 261 |
sal_Int32 nEndIndex) |
| 262 |
{ |
| 263 |
SolarMutexGuard aSolarGuard; |
| 264 |
|
| 265 |
OUString sText = implGetText(); |
| 266 |
checkIndex_Impl(nStartIndex, sText); |
| 267 |
checkIndex_Impl(nEndIndex, sText); |
| 268 |
|
| 269 |
//!!! don't know how to put a string into the clipboard |
| 270 |
return false; |
| 271 |
} |
| 272 |
sal_Bool SAL_CALL AccessibleGridControlTableCell::scrollSubstringTo(sal_Int32, sal_Int32, |
| 273 |
AccessibleScrollType) |
| 274 |
{ |
| 275 |
return false; |
| 276 |
} |
| 277 |
|
| 278 |
AbsoluteScreenPixelRectangle AccessibleGridControlTableCell::implGetBoundingBoxOnScreen() |
| 279 |
{ |
| 280 |
AbsoluteScreenPixelRectangle aGridRect = m_aTable.GetWindowExtentsAbsolute(); |
| 281 |
tools::Rectangle aCellRect = m_aTable.calcCellRect(getRowPos(), getColumnPos()); |
| 282 |
tools::Long nX = aGridRect.Left() + aCellRect.Left(); |
| 283 |
tools::Long nY = aGridRect.Top() + aCellRect.Top(); |
| 284 |
AbsoluteScreenPixelRectangle aCell(AbsoluteScreenPixelPoint(nX, nY), aCellRect.GetSize()); |
| 285 |
return aCell; |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |