bump product version to 7.6.3.2-android
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTableCell.cxx
blob91d84902bdee86f586218b6d41500243addb4e4d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <extended/AccessibleGridControlTableCell.hxx>
21 #include <toolkit/helper/convert.hxx>
22 #include <vcl/accessibletable.hxx>
23 #include <vcl/svapp.hxx>
24 #include <tools/gen.hxx>
25 #include <tools/debug.hxx>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 namespace accessibility
31 namespace
33 // FIXME this is a copy'n'paste from
34 // source/extended/AccessibleBrowseBoxTableCell.cxx, get rid of that...
35 /// @throws css::lang::IndexOutOfBoundsException
36 void checkIndex_Impl( sal_Int32 _nIndex, std::u16string_view _sText )
38 if ( _nIndex >= static_cast<sal_Int32>(_sText.size()) )
39 throw css::lang::IndexOutOfBoundsException();
42 using namespace ::com::sun::star::lang;
43 using namespace comphelper;
44 using namespace ::com::sun::star::uno;
45 using ::com::sun::star::accessibility::XAccessible;
46 using namespace ::com::sun::star::accessibility;
47 using namespace ::vcl;
48 using namespace ::vcl::table;
51 // = AccessibleGridControlCell
54 AccessibleGridControlCell::AccessibleGridControlCell(
55 const css::uno::Reference< css::accessibility::XAccessible >& _rxParent, ::vcl::table::IAccessibleTable& _rTable,
56 sal_Int32 _nRowPos, sal_uInt16 _nColPos, ::vcl::table::AccessibleTableControlObjType _eType )
57 :AccessibleGridControlBase( _rxParent, _rTable, _eType )
58 ,m_nRowPos( _nRowPos )
59 ,m_nColPos( _nColPos )
63 void SAL_CALL AccessibleGridControlCell::grabFocus()
65 SolarMutexGuard aSolarGuard;
67 m_aTable.GoToCell( m_nColPos, m_nRowPos );
70 OUString SAL_CALL AccessibleGridControlCell::getAccessibleName()
72 SolarMutexGuard g;
74 ensureIsAlive();
76 OUString sAccName;
77 if (m_eObjType == TCTYPE_TABLECELL)
78 sAccName = m_aTable.GetAccessibleObjectName(TCTYPE_TABLECELL, m_nRowPos, m_nColPos);
79 else if (m_eObjType == TCTYPE_ROWHEADERCELL)
80 sAccName = m_aTable.GetAccessibleObjectName(TCTYPE_ROWHEADERCELL, m_nRowPos, 0);
81 else if (m_eObjType == TCTYPE_COLUMNHEADERCELL)
82 sAccName = m_aTable.GetAccessibleObjectName(TCTYPE_COLUMNHEADERCELL, 0, m_nRowPos);
83 else
84 assert(false && "Unhandled table cell type");
85 return sAccName;
88 // implementation of a table cell
89 OUString AccessibleGridControlTableCell::implGetText()
91 ensureIsAlive();
92 return m_aTable.GetAccessibleCellText( getRowPos(), getColumnPos() );
95 css::lang::Locale AccessibleGridControlTableCell::implGetLocale()
97 ensureIsAlive();
98 return m_aTable.GetAccessible()->getAccessibleContext()->getLocale();
101 void AccessibleGridControlTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
103 nStartIndex = 0;
104 nEndIndex = 0;
107 AccessibleGridControlTableCell::AccessibleGridControlTableCell(const css::uno::Reference<XAccessible >& _rxParent,
108 ::vcl::table::IAccessibleTable& _rTable,
109 sal_Int32 _nRowPos,
110 sal_uInt16 _nColPos)
111 :AccessibleGridControlCell( _rxParent, _rTable, _nRowPos, _nColPos, TCTYPE_TABLECELL )
115 // XInterface
117 /** Queries for a new interface. */
118 css::uno::Any SAL_CALL AccessibleGridControlTableCell::queryInterface(
119 const css::uno::Type& rType )
121 Any aRet = AccessibleGridControlCell::queryInterface(rType);
122 if ( !aRet.hasValue() )
123 aRet = AccessibleTextHelper_BASE::queryInterface(rType);
124 return aRet;
127 /** Acquires the object (calls acquire() on base class). */
128 void SAL_CALL AccessibleGridControlTableCell::acquire() noexcept
130 AccessibleGridControlCell::acquire();
133 /** Releases the object (calls release() on base class). */
134 void SAL_CALL AccessibleGridControlTableCell::release() noexcept
136 AccessibleGridControlCell::release();
139 css::awt::Rectangle SAL_CALL AccessibleGridControlTableCell::getCharacterBounds( sal_Int32 nIndex )
141 SolarMutexGuard aSolarGuard;
143 ensureIsAlive();
144 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
145 throw IndexOutOfBoundsException();
147 return AWTRectangle( m_aTable.GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
150 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getIndexAtPoint( const css::awt::Point& _aPoint )
152 SolarMutexGuard aSolarGuard;
154 ensureIsAlive();
156 return m_aTable.GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
159 /** @return
160 The name of this class.
162 OUString SAL_CALL AccessibleGridControlTableCell::getImplementationName()
164 return "com.sun.star.accessibility.AccessibleGridControlTableCell";
167 /** @return The count of visible children. */
168 sal_Int64 SAL_CALL AccessibleGridControlTableCell::getAccessibleChildCount()
170 return 0;
173 /** @return The css::accessibility::XAccessible interface of the specified child. */
174 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL AccessibleGridControlTableCell::getAccessibleChild( sal_Int64 )
176 throw css::lang::IndexOutOfBoundsException();
179 /** Return a bitset of states of the current object.
181 sal_Int64 AccessibleGridControlTableCell::implCreateStateSet()
183 sal_Int64 nStateSet = 0;
185 if( isAlive() )
187 // SHOWING done with mxParent
188 if( implIsShowing() )
189 nStateSet |= AccessibleStateType::SHOWING;
191 m_aTable.FillAccessibleStateSetForCell( nStateSet, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
193 else
194 nStateSet |= AccessibleStateType::DEFUNC;
196 return nStateSet;
200 // css::accessibility::XAccessible
202 /** @return The css::accessibility::XAccessibleContext interface of this object. */
203 css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL AccessibleGridControlTableCell::getAccessibleContext()
205 SolarMutexGuard g;
207 ensureIsAlive();
208 return this;
211 // css::accessibility::XAccessibleContext
213 sal_Int64 SAL_CALL AccessibleGridControlTableCell::getAccessibleIndexInParent()
215 SolarMutexGuard aSolarGuard;
217 ensureIsAlive();
219 return (static_cast<sal_Int64>(getRowPos()) * static_cast<sal_Int64>(m_aTable.GetColumnCount())) + getColumnPos();
222 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCaretPosition( )
224 return -1;
226 sal_Bool SAL_CALL AccessibleGridControlTableCell::setCaretPosition ( sal_Int32 nIndex )
228 SolarMutexGuard aSolarGuard;
230 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
231 throw IndexOutOfBoundsException();
233 return false;
235 sal_Unicode SAL_CALL AccessibleGridControlTableCell::getCharacter( sal_Int32 nIndex )
237 SolarMutexGuard aSolarGuard;
239 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex );
241 css::uno::Sequence< css::beans::PropertyValue > SAL_CALL AccessibleGridControlTableCell::getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& )
243 SolarMutexGuard aSolarGuard;
245 OUString sText( implGetText() );
247 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
248 throw IndexOutOfBoundsException();
250 return css::uno::Sequence< css::beans::PropertyValue >();
252 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCharacterCount( )
254 SolarMutexGuard aSolarGuard;
256 return implGetText().getLength();
259 OUString SAL_CALL AccessibleGridControlTableCell::getSelectedText( )
261 return OUString();
263 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionStart( )
265 return 0;
267 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionEnd( )
269 return 0;
271 sal_Bool SAL_CALL AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
273 SolarMutexGuard aSolarGuard;
275 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
276 throw IndexOutOfBoundsException();
278 return false;
280 OUString SAL_CALL AccessibleGridControlTableCell::getText( )
282 SolarMutexGuard aSolarGuard;
284 return implGetText( );
286 OUString SAL_CALL AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
288 SolarMutexGuard aSolarGuard;
290 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex );
292 css::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
294 SolarMutexGuard aSolarGuard;
296 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
298 css::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
300 SolarMutexGuard aSolarGuard;
302 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
304 css::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
306 SolarMutexGuard aSolarGuard;
308 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
310 sal_Bool SAL_CALL AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
312 SolarMutexGuard aSolarGuard;
314 OUString sText = implGetText();
315 checkIndex_Impl( nStartIndex, sText );
316 checkIndex_Impl( nEndIndex, sText );
318 //!!! don't know how to put a string into the clipboard
319 return false;
321 sal_Bool SAL_CALL AccessibleGridControlTableCell::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
323 return false;
326 tools::Rectangle AccessibleGridControlTableCell::implGetBoundingBox()
328 vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
329 DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
330 tools::Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( pParent );
331 sal_Int64 nIndex = getAccessibleIndexInParent();
332 tools::Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
333 tools::Long nX = aGridRect.Left() + aCellRect.Left();
334 tools::Long nY = aGridRect.Top() + aCellRect.Top();
335 tools::Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
336 return aCell;
339 tools::Rectangle AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
341 tools::Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( nullptr );
342 sal_Int64 nIndex = getAccessibleIndexInParent();
343 tools::Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
344 tools::Long nX = aGridRect.Left() + aCellRect.Left();
345 tools::Long nY = aGridRect.Top() + aCellRect.Top();
346 tools::Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
347 return aCell;
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */