Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxTableCell.cxx
blob562ee96e55753ada05998acc3dc00957f7852093
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 "accessibility/extended/AccessibleBrowseBoxTableCell.hxx"
22 #include <svtools/accessibletableprovider.hxx>
23 #include "accessibility/extended/AccessibleBrowseBox.hxx"
24 #include <toolkit/helper/vclunohelper.hxx>
25 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
27 namespace accessibility
29 namespace
31 static void checkIndex_Impl( sal_Int32 _nIndex, const OUString& _sText ) throw (::com::sun::star::lang::IndexOutOfBoundsException)
33 if ( _nIndex >= _sText.getLength() )
34 throw ::com::sun::star::lang::IndexOutOfBoundsException();
37 static sal_Int32 getIndex_Impl( sal_Int32 _nRow, sal_uInt16 _nColumn, sal_uInt16 _nColumnCount )
39 return _nRow * _nColumnCount + _nColumn;
42 using namespace ::com::sun::star::lang;
43 using namespace utl;
44 using namespace comphelper;
45 using ::accessibility::AccessibleBrowseBox;
46 using namespace ::com::sun::star::uno;
47 using ::com::sun::star::accessibility::XAccessible;
48 using namespace ::com::sun::star::accessibility;
49 using namespace ::svt;
52 // implementation of a table cell
53 OUString AccessibleBrowseBoxTableCell::implGetText()
55 ensureIsAlive();
56 return mpBrowseBox->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
59 ::com::sun::star::lang::Locale AccessibleBrowseBoxTableCell::implGetLocale()
61 ensureIsAlive();
62 return mpBrowseBox->GetAccessible()->getAccessibleContext()->getLocale();
65 void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
67 nStartIndex = 0;
68 nEndIndex = 0;
71 AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference<XAccessible >& _rxParent,
72 IAccessibleTableProvider& _rBrowseBox,
73 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
74 sal_Int32 _nRowPos,
75 sal_uInt16 _nColPos,
76 sal_Int32 _nOffset )
77 :AccessibleBrowseBoxCell( _rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos )
79 m_nOffset = ( OFFSET_DEFAULT == _nOffset ) ? (sal_Int32)BBINDEX_FIRSTCONTROL : _nOffset;
80 sal_Int32 nIndex = getIndex_Impl( _nRowPos, _nColPos, _rBrowseBox.GetColumnCount() );
81 setAccessibleName( _rBrowseBox.GetAccessibleObjectName( BBTYPE_TABLECELL, nIndex ) );
82 setAccessibleDescription( _rBrowseBox.GetAccessibleObjectDescription( BBTYPE_TABLECELL, nIndex ) );
83 // Need to register as event listener
84 Reference< XComponent > xComponent(_rxParent, UNO_QUERY);
85 if( xComponent.is() )
86 xComponent->addEventListener(static_cast< XEventListener *> (this));
89 void AccessibleBrowseBoxTableCell::nameChanged( const OUString& rNewName, const OUString& rOldName )
91 implSetName( rNewName );
92 Any aOldValue, aNewValue;
93 aOldValue <<= rOldName;
94 aNewValue <<= rNewName;
95 commitEvent( AccessibleEventId::NAME_CHANGED, aNewValue, aOldValue );
98 // XInterface -------------------------------------------------------------
100 /** Queries for a new interface. */
101 ::com::sun::star::uno::Any SAL_CALL AccessibleBrowseBoxTableCell::queryInterface(
102 const ::com::sun::star::uno::Type& rType )
103 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
105 Any aRet = AccessibleBrowseBoxCell::queryInterface(rType);
106 if ( !aRet.hasValue() )
107 aRet = AccessibleTextHelper_BASE::queryInterface(rType);
108 return aRet;
111 /** Aquires the object (calls acquire() on base class). */
112 void SAL_CALL AccessibleBrowseBoxTableCell::acquire() throw ()
114 AccessibleBrowseBoxCell::acquire();
117 /** Releases the object (calls release() on base class). */
118 void SAL_CALL AccessibleBrowseBoxTableCell::release() throw ()
120 AccessibleBrowseBoxCell::release();
123 ::com::sun::star::awt::Rectangle SAL_CALL AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
125 SolarMutexGuard aSolarGuard;
126 ::osl::MutexGuard aGuard( getOslMutex() );
128 ensureIsAlive();
129 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
130 throw IndexOutOfBoundsException();
132 ::com::sun::star::awt::Rectangle aRect;
134 if ( mpBrowseBox )
136 aRect = AWTRectangle( mpBrowseBox->GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
139 return aRect;
142 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point& _aPoint ) throw (RuntimeException, std::exception)
144 //! TODO CTL bidi
145 // OSL_FAIL("Need to be done by base class!");
146 SolarMutexGuard aSolarGuard;
147 ::osl::MutexGuard aGuard( getOslMutex() );
148 ensureIsAlive();
150 return mpBrowseBox->GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
153 /** @return
154 The name of this class.
156 OUString SAL_CALL AccessibleBrowseBoxTableCell::getImplementationName()
157 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
159 return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell" );
162 /** @return The count of visible children. */
163 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleChildCount()
164 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
166 return 0;
169 /** @return The XAccessible interface of the specified child. */
170 ::com::sun::star::uno::Reference<
171 ::com::sun::star::accessibility::XAccessible > SAL_CALL
172 AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int32 )
173 throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
174 ::com::sun::star::uno::RuntimeException, std::exception )
176 throw ::com::sun::star::lang::IndexOutOfBoundsException();
179 /** Creates a new AccessibleStateSetHelper and fills it with states of the
180 current object.
181 @return
182 A filled AccessibleStateSetHelper.
184 ::utl::AccessibleStateSetHelper* AccessibleBrowseBoxTableCell::implCreateStateSetHelper()
186 SolarMutexGuard aSolarGuard;
187 ::osl::MutexGuard aGuard( getOslMutex() );
189 ::utl::AccessibleStateSetHelper* pStateSetHelper = new ::utl::AccessibleStateSetHelper;
191 if( isAlive() )
193 // SHOWING done with mxParent
194 if( implIsShowing() )
195 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
197 mpBrowseBox->FillAccessibleStateSetForCell( *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
199 else
200 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
202 return pStateSetHelper;
206 // XAccessible ------------------------------------------------------------
208 /** @return The XAccessibleContext interface of this object. */
209 Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleContext() throw ( RuntimeException, std::exception )
211 ensureIsAlive();
212 return this;
215 // XAccessibleContext -----------------------------------------------------
217 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
218 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
220 SolarMutexGuard aSolarGuard;
221 ::osl::MutexGuard aGuard( getOslMutex() );
222 ensureIsAlive();
224 return /*BBINDEX_FIRSTCONTROL*/ m_nOffset + ( getRowPos() * mpBrowseBox->GetColumnCount() ) + getColumnPos();
227 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
229 return -1;
231 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
233 SolarMutexGuard aSolarGuard;
234 ::osl::MutexGuard aGuard( getOslMutex() );
236 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
237 throw IndexOutOfBoundsException();
239 return false;
241 sal_Unicode SAL_CALL AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
243 SolarMutexGuard aSolarGuard;
244 ::osl::MutexGuard aGuard( getOslMutex() );
245 return OCommonAccessibleText::getCharacter( nIndex );
247 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
249 SolarMutexGuard aSolarGuard;
250 ::osl::MutexGuard aGuard( getOslMutex() );
252 OUString sText( implGetText() );
254 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
255 throw IndexOutOfBoundsException();
257 return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
259 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
261 SolarMutexGuard aSolarGuard;
262 ::osl::MutexGuard aGuard( getOslMutex() );
263 return OCommonAccessibleText::getCharacterCount( );
266 OUString SAL_CALL AccessibleBrowseBoxTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
268 SolarMutexGuard aSolarGuard;
269 ::osl::MutexGuard aGuard( getOslMutex() );
270 return OCommonAccessibleText::getSelectedText( );
272 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
274 SolarMutexGuard aSolarGuard;
275 ::osl::MutexGuard aGuard( getOslMutex() );
276 return OCommonAccessibleText::getSelectionStart( );
278 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
280 SolarMutexGuard aSolarGuard;
281 ::osl::MutexGuard aGuard( getOslMutex() );
282 return OCommonAccessibleText::getSelectionEnd( );
284 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
286 SolarMutexGuard aSolarGuard;
287 ::osl::MutexGuard aGuard( getOslMutex() );
288 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
289 throw IndexOutOfBoundsException();
291 return false;
293 OUString SAL_CALL AccessibleBrowseBoxTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
295 SolarMutexGuard aSolarGuard;
296 ::osl::MutexGuard aGuard( getOslMutex() );
297 return OCommonAccessibleText::getText( );
299 OUString SAL_CALL AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
301 SolarMutexGuard aSolarGuard;
302 ::osl::MutexGuard aGuard( getOslMutex() );
303 return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
305 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
307 SolarMutexGuard aSolarGuard;
308 ::osl::MutexGuard aGuard( getOslMutex() );
309 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
311 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
313 SolarMutexGuard aSolarGuard;
314 ::osl::MutexGuard aGuard( getOslMutex() );
315 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
317 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception)
319 SolarMutexGuard aSolarGuard;
320 ::osl::MutexGuard aGuard( getOslMutex() );
321 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
323 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
325 SolarMutexGuard aSolarGuard;
326 ::osl::MutexGuard aGuard( getOslMutex() );
327 OUString sText = implGetText();
328 checkIndex_Impl( nStartIndex, sText );
329 checkIndex_Impl( nEndIndex, sText );
331 //!!! don't know how to put a string into the clipboard
332 return false;
334 void AccessibleBrowseBoxTableCell::disposing( const EventObject& _rSource ) throw (RuntimeException, std::exception)
336 if ( _rSource.Source == mxParent )
338 dispose();
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */