lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxTableCell.cxx
blob53c1a7aa2faa9ed86cbd5ac6c89d7d1d28b1584b
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 <vcl/accessibletableprovider.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
25 namespace accessibility
27 namespace
29 /// @throws css::lang::IndexOutOfBoundsException
30 void checkIndex_Impl( sal_Int32 _nIndex, const OUString& _sText )
32 if ( _nIndex >= _sText.getLength() )
33 throw css::lang::IndexOutOfBoundsException();
36 sal_Int32 getIndex_Impl( sal_Int32 _nRow, sal_uInt16 _nColumn, sal_uInt16 _nColumnCount )
38 return _nRow * _nColumnCount + _nColumn;
41 using namespace ::com::sun::star::lang;
42 using namespace utl;
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 ::svt;
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( vcl::BBTYPE_TABLECELL, nIndex ) );
78 setAccessibleDescription( _rBrowseBox.GetAccessibleObjectDescription( vcl::BBTYPE_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 void AccessibleBrowseBoxTableCell::nameChanged( const OUString& rNewName, const OUString& rOldName )
87 implSetName( rNewName );
88 Any aOldValue, aNewValue;
89 aOldValue <<= rOldName;
90 aNewValue <<= rNewName;
91 commitEvent( AccessibleEventId::NAME_CHANGED, aNewValue, aOldValue );
94 // XInterface -------------------------------------------------------------
96 /** Queries for a new interface. */
97 css::uno::Any SAL_CALL AccessibleBrowseBoxTableCell::queryInterface( const css::uno::Type& rType )
99 Any aRet = AccessibleBrowseBoxCell::queryInterface(rType);
100 if ( !aRet.hasValue() )
101 aRet = AccessibleTextHelper_BASE::queryInterface(rType);
102 return aRet;
105 /** Acquires the object (calls acquire() on base class). */
106 void SAL_CALL AccessibleBrowseBoxTableCell::acquire() throw ()
108 AccessibleBrowseBoxCell::acquire();
111 /** Releases the object (calls release() on base class). */
112 void SAL_CALL AccessibleBrowseBoxTableCell::release() throw ()
114 AccessibleBrowseBoxCell::release();
117 css::awt::Rectangle SAL_CALL AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex )
119 SolarMethodGuard aGuard(getMutex());
120 ensureIsAlive();
122 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
123 throw IndexOutOfBoundsException();
125 css::awt::Rectangle aRect;
127 if ( mpBrowseBox )
129 aRect = AWTRectangle( mpBrowseBox->GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
132 return aRect;
135 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getIndexAtPoint( const css::awt::Point& _aPoint )
137 //! TODO CTL bidi
138 // OSL_FAIL("Need to be done by base class!");
139 SolarMethodGuard aGuard(getMutex());
140 ensureIsAlive();
142 return mpBrowseBox->GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
145 /** @return
146 The name of this class.
148 OUString SAL_CALL AccessibleBrowseBoxTableCell::getImplementationName()
150 return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell" );
153 /** @return The count of visible children. */
154 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleChildCount()
156 return 0;
159 /** @return The XAccessible interface of the specified child. */
160 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
161 AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int32 )
163 throw css::lang::IndexOutOfBoundsException();
166 /** Creates a new AccessibleStateSetHelper and fills it with states of the
167 current object.
168 @return
169 A filled AccessibleStateSetHelper.
171 ::utl::AccessibleStateSetHelper* AccessibleBrowseBoxTableCell::implCreateStateSetHelper()
173 SolarMethodGuard aGuard(getMutex());
175 ::utl::AccessibleStateSetHelper* pStateSetHelper = new ::utl::AccessibleStateSetHelper;
177 if( isAlive() )
179 // SHOWING done with mxParent
180 if( implIsShowing() )
181 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
183 mpBrowseBox->FillAccessibleStateSetForCell( *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
185 else
186 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
188 return pStateSetHelper;
192 // XAccessible ------------------------------------------------------------
194 /** @return The XAccessibleContext interface of this object. */
195 Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleContext()
197 osl::MutexGuard aGuard( getMutex() );
198 ensureIsAlive();
199 return this;
202 // XAccessibleContext -----------------------------------------------------
204 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
206 SolarMethodGuard aGuard(getMutex());
207 ensureIsAlive();
209 return /*vcl::BBINDEX_FIRSTCONTROL*/ m_nOffset + ( getRowPos() * mpBrowseBox->GetColumnCount() ) + getColumnPos();
212 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCaretPosition( )
214 return -1;
217 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex )
219 SolarMethodGuard aGuard(getMutex());
220 ensureIsAlive();
222 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
223 throw IndexOutOfBoundsException();
225 return false;
227 sal_Unicode SAL_CALL AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex )
229 SolarMethodGuard aGuard(getMutex());
230 ensureIsAlive();
232 return OCommonAccessibleText::implGetCharacter( implGetText(), nIndex );
234 css::uno::Sequence< css::beans::PropertyValue > SAL_CALL AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex, const css::uno::Sequence< OUString >& )
236 SolarMethodGuard aGuard(getMutex());
237 ensureIsAlive();
239 OUString sText( implGetText() );
241 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
242 throw IndexOutOfBoundsException();
244 return css::uno::Sequence< css::beans::PropertyValue >();
246 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCharacterCount( )
248 SolarMethodGuard aGuard(getMutex());
249 ensureIsAlive();
251 return implGetText().getLength();
254 OUString SAL_CALL AccessibleBrowseBoxTableCell::getSelectedText( )
256 SolarMethodGuard aGuard(getMutex());
257 ensureIsAlive();
259 return OCommonAccessibleText::getSelectedText( );
261 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionStart( )
263 SolarMethodGuard aGuard(getMutex());
264 ensureIsAlive();
266 return OCommonAccessibleText::getSelectionStart( );
268 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionEnd( )
270 SolarMethodGuard aGuard(getMutex());
271 ensureIsAlive();
273 return OCommonAccessibleText::getSelectionEnd( );
275 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
277 SolarMethodGuard aGuard(getMutex());
278 ensureIsAlive();
280 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
281 throw IndexOutOfBoundsException();
283 return false;
285 OUString SAL_CALL AccessibleBrowseBoxTableCell::getText( )
287 SolarMethodGuard aGuard(getMutex());
288 ensureIsAlive();
290 return implGetText( );
292 OUString SAL_CALL AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
294 SolarMethodGuard aGuard(getMutex());
295 ensureIsAlive();
297 return OCommonAccessibleText::implGetTextRange( implGetText(), nStartIndex, nEndIndex );
299 css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType )
301 SolarMethodGuard aGuard(getMutex());
302 ensureIsAlive();
304 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
306 css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType )
308 SolarMethodGuard aGuard(getMutex());
309 ensureIsAlive();
311 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
313 css::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType )
315 SolarMethodGuard aGuard(getMutex());
316 ensureIsAlive();
318 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
320 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex )
322 SolarMethodGuard aGuard(getMutex());
323 ensureIsAlive();
325 OUString sText = implGetText();
326 checkIndex_Impl( nStartIndex, sText );
327 checkIndex_Impl( nEndIndex, sText );
329 //!!! don't know how to put a string into the clipboard
330 return false;
332 void AccessibleBrowseBoxTableCell::disposing( const EventObject& _rSource )
334 if ( _rSource.Source == mxParent )
336 dispose();
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */