tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTableCell.cxx
bloba1a1af5fe64173b21eeaea10c5cd194a3fb6f9ba
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 <vcl/accessibletable.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/unohelp.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 )
61 assert(((m_eObjType == AccessibleTableControlObjType::TABLECELL)
62 || ((m_eObjType == AccessibleTableControlObjType::ROWHEADERCELL) && _nColPos == 0)
63 || ((m_eObjType == AccessibleTableControlObjType::COLUMNHEADERCELL) && _nRowPos == 0))
64 && "Unhandled table cell type");
67 void SAL_CALL AccessibleGridControlCell::grabFocus()
69 SolarMutexGuard aSolarGuard;
71 m_aTable.GoToCell( m_nColPos, m_nRowPos );
74 OUString SAL_CALL AccessibleGridControlCell::getAccessibleName()
76 SolarMutexGuard g;
78 ensureIsAlive();
79 return m_aTable.GetAccessibleObjectName(m_eObjType, m_nRowPos, m_nColPos);
82 // implementation of a table cell
83 OUString AccessibleGridControlTableCell::implGetText()
85 ensureIsAlive();
86 return m_aTable.GetAccessibleCellText( getRowPos(), getColumnPos() );
89 css::lang::Locale AccessibleGridControlTableCell::implGetLocale()
91 ensureIsAlive();
92 return m_aTable.GetAccessible()->getAccessibleContext()->getLocale();
95 void AccessibleGridControlTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
97 nStartIndex = 0;
98 nEndIndex = 0;
101 AccessibleGridControlTableCell::AccessibleGridControlTableCell(const css::uno::Reference<XAccessible >& _rxParent,
102 ::vcl::table::IAccessibleTable& _rTable,
103 sal_Int32 _nRowPos,
104 sal_uInt16 _nColPos)
105 :AccessibleGridControlCell(_rxParent, _rTable, _nRowPos, _nColPos, AccessibleTableControlObjType::TABLECELL)
109 // XInterface
111 /** Queries for a new interface. */
112 css::uno::Any SAL_CALL AccessibleGridControlTableCell::queryInterface(
113 const css::uno::Type& rType )
115 Any aRet = AccessibleGridControlCell::queryInterface(rType);
116 if ( !aRet.hasValue() )
117 aRet = AccessibleTextHelper_BASE::queryInterface(rType);
118 return aRet;
121 /** Acquires the object (calls acquire() on base class). */
122 void SAL_CALL AccessibleGridControlTableCell::acquire() noexcept
124 AccessibleGridControlCell::acquire();
127 /** Releases the object (calls release() on base class). */
128 void SAL_CALL AccessibleGridControlTableCell::release() noexcept
130 AccessibleGridControlCell::release();
133 css::awt::Rectangle SAL_CALL AccessibleGridControlTableCell::getCharacterBounds( sal_Int32 nIndex )
135 SolarMutexGuard aSolarGuard;
137 ensureIsAlive();
138 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
139 throw IndexOutOfBoundsException();
141 return vcl::unohelper::ConvertToAWTRect(
142 m_aTable.GetFieldCharacterBounds(getRowPos(), getColumnPos(), nIndex));
145 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getIndexAtPoint( const css::awt::Point& _aPoint )
147 SolarMutexGuard aSolarGuard;
149 ensureIsAlive();
151 return m_aTable.GetFieldIndexAtPoint(getRowPos(), getColumnPos(),
152 vcl::unohelper::ConvertToVCLPoint(_aPoint));
155 /** @return
156 The name of this class.
158 OUString SAL_CALL AccessibleGridControlTableCell::getImplementationName()
160 return u"com.sun.star.accessibility.AccessibleGridControlTableCell"_ustr;
163 /** @return The count of visible children. */
164 sal_Int64 SAL_CALL AccessibleGridControlTableCell::getAccessibleChildCount()
166 return 0;
169 /** @return The css::accessibility::XAccessible interface of the specified child. */
170 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL AccessibleGridControlTableCell::getAccessibleChild( sal_Int64 )
172 throw css::lang::IndexOutOfBoundsException();
175 /** Return a bitset of states of the current object.
177 sal_Int64 AccessibleGridControlTableCell::implCreateStateSet()
179 sal_Int64 nStateSet = 0;
181 if( isAlive() )
183 // SHOWING done with mxParent
184 if( implIsShowing() )
185 nStateSet |= AccessibleStateType::SHOWING;
187 m_aTable.FillAccessibleStateSetForCell( nStateSet, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
189 else
190 nStateSet |= AccessibleStateType::DEFUNC;
192 return nStateSet;
196 // css::accessibility::XAccessible
198 /** @return The css::accessibility::XAccessibleContext interface of this object. */
199 css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL AccessibleGridControlTableCell::getAccessibleContext()
201 SolarMutexGuard g;
203 ensureIsAlive();
204 return this;
207 // css::accessibility::XAccessibleContext
209 sal_Int64 SAL_CALL AccessibleGridControlTableCell::getAccessibleIndexInParent()
211 SolarMutexGuard aSolarGuard;
213 ensureIsAlive();
215 return (static_cast<sal_Int64>(getRowPos()) * static_cast<sal_Int64>(m_aTable.GetColumnCount())) + getColumnPos();
218 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCaretPosition( )
220 return -1;
222 sal_Bool SAL_CALL AccessibleGridControlTableCell::setCaretPosition ( sal_Int32 nIndex )
224 SolarMutexGuard aSolarGuard;
226 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
227 throw IndexOutOfBoundsException();
229 return false;
231 sal_Unicode SAL_CALL AccessibleGridControlTableCell::getCharacter( sal_Int32 nIndex )
233 SolarMutexGuard aSolarGuard;
235 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex );
237 css::uno::Sequence< css::beans::PropertyValue > SAL_CALL AccessibleGridControlTableCell::getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& )
239 SolarMutexGuard aSolarGuard;
241 OUString sText( implGetText() );
243 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
244 throw IndexOutOfBoundsException();
246 return css::uno::Sequence< css::beans::PropertyValue >();
248 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCharacterCount( )
250 SolarMutexGuard aSolarGuard;
252 return implGetText().getLength();
255 OUString SAL_CALL AccessibleGridControlTableCell::getSelectedText( )
257 return OUString();
259 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionStart( )
261 return 0;
263 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionEnd( )
265 return 0;
267 sal_Bool SAL_CALL AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
269 SolarMutexGuard aSolarGuard;
271 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
272 throw IndexOutOfBoundsException();
274 return false;
276 OUString SAL_CALL AccessibleGridControlTableCell::getText( )
278 SolarMutexGuard aSolarGuard;
280 return implGetText( );
282 OUString SAL_CALL AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
284 SolarMutexGuard aSolarGuard;
286 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex );
288 css::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
290 SolarMutexGuard aSolarGuard;
292 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
294 css::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
296 SolarMutexGuard aSolarGuard;
298 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
300 css::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
302 SolarMutexGuard aSolarGuard;
304 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
306 sal_Bool SAL_CALL AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
308 SolarMutexGuard aSolarGuard;
310 OUString sText = implGetText();
311 checkIndex_Impl( nStartIndex, sText );
312 checkIndex_Impl( nEndIndex, sText );
314 //!!! don't know how to put a string into the clipboard
315 return false;
317 sal_Bool SAL_CALL AccessibleGridControlTableCell::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
319 return false;
322 tools::Rectangle AccessibleGridControlTableCell::implGetBoundingBox()
324 vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
325 assert(pParent && "implGetBoundingBox - missing parent window");
326 tools::Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( *pParent );
327 sal_Int64 nIndex = getAccessibleIndexInParent();
328 tools::Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
329 tools::Long nX = aGridRect.Left() + aCellRect.Left();
330 tools::Long nY = aGridRect.Top() + aCellRect.Top();
331 tools::Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
332 return aCell;
335 AbsoluteScreenPixelRectangle AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
337 AbsoluteScreenPixelRectangle aGridRect = m_aTable.GetWindowExtentsAbsolute();
338 sal_Int64 nIndex = getAccessibleIndexInParent();
339 tools::Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
340 tools::Long nX = aGridRect.Left() + aCellRect.Left();
341 tools::Long nY = aGridRect.Top() + aCellRect.Top();
342 AbsoluteScreenPixelRectangle aCell( AbsoluteScreenPixelPoint( nX, nY ), aCellRect.GetSize());
343 return aCell;
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */