Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxTableCell.cxx
blob12571484e69d3a0e3eccc5378b6401baab3f2444
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>
22 #include <toolkit/helper/convert.hxx>
23 #include <vcl/accessibletableprovider.hxx>
24 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27 namespace accessibility
29 namespace
31 /// @throws css::lang::IndexOutOfBoundsException
32 void checkIndex_Impl( sal_Int32 _nIndex, std::u16string_view _sText )
34 if ( _nIndex >= static_cast<sal_Int32>(_sText.size()) )
35 throw css::lang::IndexOutOfBoundsException();
38 sal_Int32 getIndex_Impl( sal_Int32 _nRow, sal_uInt16 _nColumn, sal_uInt16 _nColumnCount )
40 return _nRow * _nColumnCount + _nColumn;
43 using namespace ::com::sun::star::lang;
44 using namespace comphelper;
45 using namespace ::com::sun::star::uno;
46 using ::com::sun::star::accessibility::XAccessible;
47 using namespace ::com::sun::star::accessibility;
50 // implementation of a table cell
51 OUString AccessibleBrowseBoxTableCell::implGetText()
53 return mpBrowseBox->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
56 css::lang::Locale AccessibleBrowseBoxTableCell::implGetLocale()
58 return mpBrowseBox->GetAccessible()->getAccessibleContext()->getLocale();
61 void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
63 nStartIndex = 0;
64 nEndIndex = 0;
67 AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference<XAccessible >& _rxParent,
68 vcl::IAccessibleTableProvider& _rBrowseBox,
69 const css::uno::Reference< css::awt::XWindow >& _xFocusWindow,
70 sal_Int32 _nRowPos,
71 sal_uInt16 _nColPos,
72 sal_Int32 _nOffset )
73 :AccessibleBrowseBoxCell( _rxParent, _rBrowseBox, _xFocusWindow, _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 = AWTRectangle( mpBrowseBox->GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
123 return aRect;
126 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getIndexAtPoint( const css::awt::Point& _aPoint )
128 //! TODO CTL bidi
129 // OSL_FAIL("Need to be done by base class!");
130 SolarMethodGuard aGuard(getMutex());
131 ensureIsAlive();
133 return mpBrowseBox->GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
136 /** @return
137 The name of this class.
139 OUString SAL_CALL AccessibleBrowseBoxTableCell::getImplementationName()
141 return "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell";
144 /** @return The count of visible children. */
145 sal_Int64 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleChildCount()
147 return 0;
150 /** @return The XAccessible interface of the specified child. */
151 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
152 AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int64 )
154 throw css::lang::IndexOutOfBoundsException();
157 /** Return a bitset of states of the current object.
159 sal_Int64 AccessibleBrowseBoxTableCell::implCreateStateSet()
161 SolarMethodGuard aGuard(getMutex());
163 sal_Int64 nStateSet = 0;
165 if( isAlive() )
167 // SHOWING done with mxParent
168 if( implIsShowing() )
169 nStateSet |= AccessibleStateType::SHOWING;
171 mpBrowseBox->FillAccessibleStateSetForCell( nStateSet, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
173 else
174 nStateSet |= AccessibleStateType::DEFUNC;
176 return nStateSet;
180 // XAccessible ------------------------------------------------------------
182 /** @return The XAccessibleContext interface of this object. */
183 Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleContext()
185 osl::MutexGuard aGuard( getMutex() );
186 ensureIsAlive();
187 return this;
190 // XAccessibleContext -----------------------------------------------------
192 sal_Int64 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
194 SolarMethodGuard aGuard(getMutex());
195 ensureIsAlive();
197 return /*vcl::BBINDEX_FIRSTCONTROL*/ m_nOffset + (static_cast<sal_Int64>(getRowPos()) * static_cast<sal_Int64>(mpBrowseBox->GetColumnCount())) + getColumnPos();
200 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCaretPosition( )
202 return -1;
205 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex )
207 SolarMethodGuard aGuard(getMutex());
208 ensureIsAlive();
210 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
211 throw IndexOutOfBoundsException();
213 return false;
215 sal_Unicode SAL_CALL AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex )
217 SolarMethodGuard aGuard(getMutex());
218 ensureIsAlive();
220 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex );
222 css::uno::Sequence< css::beans::PropertyValue > SAL_CALL AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& )
224 SolarMethodGuard aGuard(getMutex());
225 ensureIsAlive();
227 OUString sText( implGetText() );
229 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
230 throw IndexOutOfBoundsException();
232 return css::uno::Sequence< css::beans::PropertyValue >();
234 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCharacterCount( )
236 SolarMethodGuard aGuard(getMutex());
237 ensureIsAlive();
239 return implGetText().getLength();
242 OUString SAL_CALL AccessibleBrowseBoxTableCell::getSelectedText( )
244 SolarMethodGuard aGuard(getMutex());
245 ensureIsAlive();
247 return OCommonAccessibleText::getSelectedText( );
249 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionStart( )
251 SolarMethodGuard aGuard(getMutex());
252 ensureIsAlive();
254 return OCommonAccessibleText::getSelectionStart( );
256 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionEnd( )
258 SolarMethodGuard aGuard(getMutex());
259 ensureIsAlive();
261 return OCommonAccessibleText::getSelectionEnd( );
263 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
265 SolarMethodGuard aGuard(getMutex());
266 ensureIsAlive();
268 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
269 throw IndexOutOfBoundsException();
271 return false;
273 OUString SAL_CALL AccessibleBrowseBoxTableCell::getText( )
275 SolarMethodGuard aGuard(getMutex());
276 ensureIsAlive();
278 return implGetText( );
280 OUString SAL_CALL AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
282 SolarMethodGuard aGuard(getMutex());
283 ensureIsAlive();
285 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex );
287 css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
289 SolarMethodGuard aGuard(getMutex());
290 ensureIsAlive();
292 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
294 css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
296 SolarMethodGuard aGuard(getMutex());
297 ensureIsAlive();
299 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
301 css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
303 SolarMethodGuard aGuard(getMutex());
304 ensureIsAlive();
306 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
308 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
310 SolarMethodGuard aGuard(getMutex());
311 ensureIsAlive();
313 OUString sText = implGetText();
314 checkIndex_Impl( nStartIndex, sText );
315 checkIndex_Impl( nEndIndex, sText );
317 //!!! don't know how to put a string into the clipboard
318 return false;
320 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::scrollSubstringTo( sal_Int32, sal_Int32, AccessibleScrollType )
322 return false;
324 void AccessibleBrowseBoxTableCell::disposing( const EventObject& _rSource )
326 if ( _rSource.Source == mxParent )
328 dispose();
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */