tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxTableCell.cxx
blobf45f6099d6c5a42c400c51b24f2d20c2b8edd1d9
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 .
21 #include <extended/AccessibleBrowseBoxTableCell.hxx>
23 #include <vcl/accessibletableprovider.hxx>
24 #include <vcl/unohelp.hxx>
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28 namespace accessibility
30 namespace
32 /// @throws css::lang::IndexOutOfBoundsException
33 void checkIndex_Impl( sal_Int32 _nIndex, std::u16string_view _sText )
35 if ( _nIndex >= static_cast<sal_Int32>(_sText.size()) )
36 throw css::lang::IndexOutOfBoundsException();
39 sal_Int32 getIndex_Impl( sal_Int32 _nRow, sal_uInt16 _nColumn, sal_uInt16 _nColumnCount )
41 return _nRow * _nColumnCount + _nColumn;
44 using namespace ::com::sun::star::lang;
45 using namespace comphelper;
46 using namespace ::com::sun::star::uno;
47 using ::com::sun::star::accessibility::XAccessible;
48 using namespace ::com::sun::star::accessibility;
51 // implementation of a table cell
52 OUString AccessibleBrowseBoxTableCell::implGetText()
54 return mpBrowseBox->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
57 css::lang::Locale AccessibleBrowseBoxTableCell::implGetLocale()
59 return mpBrowseBox->GetAccessible()->getAccessibleContext()->getLocale();
62 void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
64 nStartIndex = 0;
65 nEndIndex = 0;
68 AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference<XAccessible >& _rxParent,
69 vcl::IAccessibleTableProvider& _rBrowseBox,
70 sal_Int32 _nRowPos,
71 sal_uInt16 _nColPos,
72 sal_Int32 _nOffset )
73 :AccessibleBrowseBoxCell(_rxParent, _rBrowseBox, nullptr, _nRowPos, _nColPos)
75 m_nOffset = ( _nOffset == OFFSET_DEFAULT ) ? sal_Int32(vcl::BBINDEX_FIRSTCONTROL) : _nOffset;
76 sal_Int32 nIndex = getIndex_Impl( _nRowPos, _nColPos, _rBrowseBox.GetColumnCount() );
77 setAccessibleName( _rBrowseBox.GetAccessibleObjectName( AccessibleBrowseBoxObjType::TableCell, nIndex ) );
78 setAccessibleDescription( _rBrowseBox.GetAccessibleObjectDescription( AccessibleBrowseBoxObjType::TableCell, nIndex ) );
79 // Need to register as event listener
80 Reference< XComponent > xComponent(_rxParent, UNO_QUERY);
81 if( xComponent.is() )
82 xComponent->addEventListener(static_cast< XEventListener *> (this));
85 // XInterface -------------------------------------------------------------
87 /** Queries for a new interface. */
88 css::uno::Any SAL_CALL AccessibleBrowseBoxTableCell::queryInterface( const css::uno::Type& rType )
90 Any aRet = AccessibleBrowseBoxCell::queryInterface(rType);
91 if ( !aRet.hasValue() )
92 aRet = AccessibleTextHelper_BASE::queryInterface(rType);
93 return aRet;
96 /** Acquires the object (calls acquire() on base class). */
97 void SAL_CALL AccessibleBrowseBoxTableCell::acquire() noexcept
99 AccessibleBrowseBoxCell::acquire();
102 /** Releases the object (calls release() on base class). */
103 void SAL_CALL AccessibleBrowseBoxTableCell::release() noexcept
105 AccessibleBrowseBoxCell::release();
108 css::awt::Rectangle SAL_CALL AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex )
110 SolarMethodGuard aGuard(getMutex());
111 ensureIsAlive();
113 css::awt::Rectangle aRect;
115 if ( mpBrowseBox )
117 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
118 throw IndexOutOfBoundsException();
120 aRect = vcl::unohelper::ConvertToAWTRect(
121 mpBrowseBox->GetFieldCharacterBounds(getRowPos(), getColumnPos(), nIndex));
124 return aRect;
127 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getIndexAtPoint( const css::awt::Point& _aPoint )
129 //! TODO CTL bidi
130 // OSL_FAIL("Need to be done by base class!");
131 SolarMethodGuard aGuard(getMutex());
132 ensureIsAlive();
134 return mpBrowseBox->GetFieldIndexAtPoint(getRowPos(), getColumnPos(),
135 vcl::unohelper::ConvertToVCLPoint(_aPoint));
138 /** @return
139 The name of this class.
141 OUString SAL_CALL AccessibleBrowseBoxTableCell::getImplementationName()
143 return u"com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell"_ustr;
146 /** @return The count of visible children. */
147 sal_Int64 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleChildCount()
149 return 0;
152 /** @return The XAccessible interface of the specified child. */
153 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
154 AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int64 )
156 throw css::lang::IndexOutOfBoundsException();
159 /** Return a bitset of states of the current object.
161 sal_Int64 AccessibleBrowseBoxTableCell::implCreateStateSet()
163 SolarMethodGuard aGuard(getMutex());
165 sal_Int64 nStateSet = 0;
167 if( isAlive() )
169 // SHOWING done with mxParent
170 if( implIsShowing() )
171 nStateSet |= AccessibleStateType::SHOWING;
173 mpBrowseBox->FillAccessibleStateSetForCell( nStateSet, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
175 else
176 nStateSet |= AccessibleStateType::DEFUNC;
178 return nStateSet;
182 // XAccessible ------------------------------------------------------------
184 /** @return The XAccessibleContext interface of this object. */
185 Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleContext()
187 osl::MutexGuard aGuard( getMutex() );
188 ensureIsAlive();
189 return this;
192 // XAccessibleContext -----------------------------------------------------
194 sal_Int64 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
196 SolarMethodGuard aGuard(getMutex());
197 ensureIsAlive();
199 return /*vcl::BBINDEX_FIRSTCONTROL*/ m_nOffset + (static_cast<sal_Int64>(getRowPos()) * static_cast<sal_Int64>(mpBrowseBox->GetColumnCount())) + getColumnPos();
202 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCaretPosition( )
204 return -1;
207 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex )
209 SolarMethodGuard aGuard(getMutex());
210 ensureIsAlive();
212 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
213 throw IndexOutOfBoundsException();
215 return false;
217 sal_Unicode SAL_CALL AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex )
219 SolarMethodGuard aGuard(getMutex());
220 ensureIsAlive();
222 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex );
224 css::uno::Sequence< css::beans::PropertyValue > SAL_CALL AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& )
226 SolarMethodGuard aGuard(getMutex());
227 ensureIsAlive();
229 OUString sText( implGetText() );
231 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
232 throw IndexOutOfBoundsException();
234 return css::uno::Sequence< css::beans::PropertyValue >();
236 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCharacterCount( )
238 SolarMethodGuard aGuard(getMutex());
239 ensureIsAlive();
241 return implGetText().getLength();
244 OUString SAL_CALL AccessibleBrowseBoxTableCell::getSelectedText( )
246 SolarMethodGuard aGuard(getMutex());
247 ensureIsAlive();
249 return OCommonAccessibleText::getSelectedText( );
251 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionStart( )
253 SolarMethodGuard aGuard(getMutex());
254 ensureIsAlive();
256 return OCommonAccessibleText::getSelectionStart( );
258 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionEnd( )
260 SolarMethodGuard aGuard(getMutex());
261 ensureIsAlive();
263 return OCommonAccessibleText::getSelectionEnd( );
265 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
267 SolarMethodGuard aGuard(getMutex());
268 ensureIsAlive();
270 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
271 throw IndexOutOfBoundsException();
273 return false;
275 OUString SAL_CALL AccessibleBrowseBoxTableCell::getText( )
277 SolarMethodGuard aGuard(getMutex());
278 ensureIsAlive();
280 return implGetText( );
282 OUString SAL_CALL AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
284 SolarMethodGuard aGuard(getMutex());
285 ensureIsAlive();
287 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex );
289 css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
291 SolarMethodGuard aGuard(getMutex());
292 ensureIsAlive();
294 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
296 css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
298 SolarMethodGuard aGuard(getMutex());
299 ensureIsAlive();
301 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
303 css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
305 SolarMethodGuard aGuard(getMutex());
306 ensureIsAlive();
308 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
310 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
312 SolarMethodGuard aGuard(getMutex());
313 ensureIsAlive();
315 OUString sText = implGetText();
316 checkIndex_Impl( nStartIndex, sText );
317 checkIndex_Impl( nEndIndex, sText );
319 //!!! don't know how to put a string into the clipboard
320 return false;
322 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
324 return false;
326 void AccessibleBrowseBoxTableCell::disposing( const EventObject& _rSource )
328 if ( _rSource.Source == mxParent )
330 dispose();
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */