Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTableCell.cxx
blob1f700880b1f053e45e8b82d03af40c05252a221b
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/AccessibleGridControlTableCell.hxx"
22 #include <svtools/accessibletable.hxx>
23 #include "accessibility/extended/AccessibleGridControl.hxx"
24 #include <tools/gen.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
28 namespace accessibility
30 namespace
32 // FIXME this is a copy'n'paste from
33 // source/extended/AccessibleBrowseBoxTableCell.cxx, get rid of that...
34 static void checkIndex_Impl( sal_Int32 _nIndex, const OUString& _sText ) throw (::com::sun::star::lang::IndexOutOfBoundsException)
36 if ( _nIndex >= _sText.getLength() )
37 throw ::com::sun::star::lang::IndexOutOfBoundsException();
40 using namespace ::com::sun::star::lang;
41 using namespace utl;
42 using namespace comphelper;
43 using ::accessibility::AccessibleGridControl;
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;
48 using namespace ::svt::table;
51 // =============================================================================
52 // = AccessibleGridControlCell
53 // =============================================================================
54 // -----------------------------------------------------------------------------
55 AccessibleGridControlCell::AccessibleGridControlCell(
56 const Reference< XAccessible >& _rxParent, IAccessibleTable& _rTable,
57 sal_Int32 _nRowPos, sal_uInt16 _nColPos, AccessibleTableControlObjType _eType )
58 :AccessibleGridControlBase( _rxParent, _rTable, _eType )
59 ,m_nRowPos( _nRowPos )
60 ,m_nColPos( _nColPos )
62 // set accessible name here, because for that we need the position of the cell
63 // and so the base class isn't capable of doing this
64 OUString aAccName;
65 if(_eType == TCTYPE_TABLECELL)
66 aAccName = _rTable.GetAccessibleObjectName( TCTYPE_TABLECELL, _nRowPos, _nColPos );
67 else if(_eType == TCTYPE_ROWHEADERCELL)
68 aAccName = _rTable.GetAccessibleObjectName( TCTYPE_ROWHEADERCELL, _nRowPos, 0 );
69 else if(_eType == TCTYPE_COLUMNHEADERCELL)
70 aAccName = _rTable.GetAccessibleObjectName( TCTYPE_COLUMNHEADERCELL, 0, _nRowPos );
71 implSetName( aAccName );
74 // -----------------------------------------------------------------------------
75 AccessibleGridControlCell::~AccessibleGridControlCell()
79 // -----------------------------------------------------------------------------
80 void SAL_CALL AccessibleGridControlCell::grabFocus() throw ( RuntimeException )
82 SolarMutexGuard aSolarGuard;
83 ::osl::MutexGuard aGuard( getOslMutex() );
84 m_aTable.GoToCell( m_nColPos, m_nRowPos );
86 //// -----------------------------------------------------------------------------
87 // implementation of a table cell
88 OUString AccessibleGridControlTableCell::implGetText()
90 ensureIsAlive();
91 return m_aTable.GetAccessibleCellText( getRowPos(), getColumnPos() );
94 ::com::sun::star::lang::Locale AccessibleGridControlTableCell::implGetLocale()
96 ensureIsAlive();
97 return m_aTable.GetAccessible()->getAccessibleContext()->getLocale();
100 void AccessibleGridControlTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
102 nStartIndex = 0;
103 nEndIndex = 0;
106 AccessibleGridControlTableCell::AccessibleGridControlTableCell(const Reference<XAccessible >& _rxParent,
107 IAccessibleTable& _rTable,
108 sal_Int32 _nRowPos,
109 sal_uInt16 _nColPos,
110 AccessibleTableControlObjType eObjType)
111 :AccessibleGridControlCell( _rxParent, _rTable, _nRowPos, _nColPos, eObjType )
115 // XInterface -------------------------------------------------------------
117 /** Queries for a new interface. */
118 ::com::sun::star::uno::Any SAL_CALL AccessibleGridControlTableCell::queryInterface(
119 const ::com::sun::star::uno::Type& rType )
120 throw ( ::com::sun::star::uno::RuntimeException )
122 Any aRet = AccessibleGridControlCell::queryInterface(rType);
123 if ( !aRet.hasValue() )
124 aRet = AccessibleTextHelper_BASE::queryInterface(rType);
125 return aRet;
128 /** Aquires the object (calls acquire() on base class). */
129 void SAL_CALL AccessibleGridControlTableCell::acquire() throw ()
131 AccessibleGridControlCell::acquire();
134 /** Releases the object (calls release() on base class). */
135 void SAL_CALL AccessibleGridControlTableCell::release() throw ()
137 AccessibleGridControlCell::release();
140 ::com::sun::star::awt::Rectangle SAL_CALL AccessibleGridControlTableCell::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
142 SolarMutexGuard aSolarGuard;
143 ::osl::MutexGuard aGuard( getOslMutex() );
145 ensureIsAlive();
146 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
147 throw IndexOutOfBoundsException();
149 ::com::sun::star::awt::Rectangle aRect;
151 if ( &m_aTable )
152 aRect = AWTRectangle( m_aTable.GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
153 return aRect;
156 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point& _aPoint ) throw (RuntimeException)
158 SolarMutexGuard aSolarGuard;
159 ::osl::MutexGuard aGuard( getOslMutex() );
160 ensureIsAlive();
162 return m_aTable.GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
165 /** @return
166 The name of this class.
168 OUString SAL_CALL AccessibleGridControlTableCell::getImplementationName()
169 throw ( ::com::sun::star::uno::RuntimeException )
171 return OUString( "com.sun.star.accessibility.AccessibleGridControlTableCell" );
174 /** @return The count of visible children. */
175 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getAccessibleChildCount()
176 throw ( ::com::sun::star::uno::RuntimeException )
178 return 0;
181 /** @return The XAccessible interface of the specified child. */
182 ::com::sun::star::uno::Reference<
183 ::com::sun::star::accessibility::XAccessible > SAL_CALL
184 AccessibleGridControlTableCell::getAccessibleChild( sal_Int32 )
185 throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
186 ::com::sun::star::uno::RuntimeException )
188 throw ::com::sun::star::lang::IndexOutOfBoundsException();
191 /** Creates a new AccessibleStateSetHelper and fills it with states of the
192 current object.
193 @return
194 A filled AccessibleStateSetHelper.
196 ::utl::AccessibleStateSetHelper* AccessibleGridControlTableCell::implCreateStateSetHelper()
198 SolarMutexGuard aSolarGuard;
199 ::osl::MutexGuard aGuard( getOslMutex() );
201 ::utl::AccessibleStateSetHelper* pStateSetHelper = new ::utl::AccessibleStateSetHelper;
203 if( isAlive() )
205 // SHOWING done with mxParent
206 if( implIsShowing() )
207 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
209 m_aTable.FillAccessibleStateSetForCell( *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
211 else
212 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
214 return pStateSetHelper;
218 // XAccessible ------------------------------------------------------------
220 /** @return The XAccessibleContext interface of this object. */
221 Reference< XAccessibleContext > SAL_CALL AccessibleGridControlTableCell::getAccessibleContext() throw ( RuntimeException )
223 ensureIsAlive();
224 return this;
227 // XAccessibleContext -----------------------------------------------------
229 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getAccessibleIndexInParent()
230 throw ( ::com::sun::star::uno::RuntimeException )
232 SolarMutexGuard aSolarGuard;
233 ::osl::MutexGuard aGuard( getOslMutex() );
234 ensureIsAlive();
236 return ( getRowPos() * m_aTable.GetColumnCount() ) + getColumnPos();
239 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException)
241 return -1;
243 sal_Bool SAL_CALL AccessibleGridControlTableCell::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
245 SolarMutexGuard aSolarGuard;
246 ::osl::MutexGuard aGuard( getOslMutex() );
248 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
249 throw IndexOutOfBoundsException();
251 return sal_False;
253 sal_Unicode SAL_CALL AccessibleGridControlTableCell::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
255 SolarMutexGuard aSolarGuard;
256 ::osl::MutexGuard aGuard( getOslMutex() );
257 return OCommonAccessibleText::getCharacter( nIndex );
259 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL AccessibleGridControlTableCell::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
261 SolarMutexGuard aSolarGuard;
262 ::osl::MutexGuard aGuard( getOslMutex() );
264 OUString sText( implGetText() );
266 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
267 throw IndexOutOfBoundsException();
269 return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
271 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException)
273 SolarMutexGuard aSolarGuard;
274 ::osl::MutexGuard aGuard( getOslMutex() );
275 return OCommonAccessibleText::getCharacterCount( );
278 OUString SAL_CALL AccessibleGridControlTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException)
280 SolarMutexGuard aSolarGuard;
281 ::osl::MutexGuard aGuard( getOslMutex() );
282 return OCommonAccessibleText::getSelectedText( );
284 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException)
286 SolarMutexGuard aSolarGuard;
287 ::osl::MutexGuard aGuard( getOslMutex() );
288 return OCommonAccessibleText::getSelectionStart( );
290 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException)
292 SolarMutexGuard aSolarGuard;
293 ::osl::MutexGuard aGuard( getOslMutex() );
294 return OCommonAccessibleText::getSelectionEnd( );
296 sal_Bool SAL_CALL AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
298 SolarMutexGuard aSolarGuard;
299 ::osl::MutexGuard aGuard( getOslMutex() );
300 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
301 throw IndexOutOfBoundsException();
303 return sal_False;
305 OUString SAL_CALL AccessibleGridControlTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException)
307 SolarMutexGuard aSolarGuard;
308 ::osl::MutexGuard aGuard( getOslMutex() );
309 return OCommonAccessibleText::getText( );
311 OUString SAL_CALL AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
313 SolarMutexGuard aSolarGuard;
314 ::osl::MutexGuard aGuard( getOslMutex() );
315 return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
317 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
319 SolarMutexGuard aSolarGuard;
320 ::osl::MutexGuard aGuard( getOslMutex() );
321 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
323 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
325 SolarMutexGuard aSolarGuard;
326 ::osl::MutexGuard aGuard( getOslMutex() );
327 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
329 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleGridControlTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
331 SolarMutexGuard aSolarGuard;
332 ::osl::MutexGuard aGuard( getOslMutex() );
333 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
335 sal_Bool SAL_CALL AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
337 SolarMutexGuard aSolarGuard;
338 ::osl::MutexGuard aGuard( getOslMutex() );
339 OUString sText = implGetText();
340 checkIndex_Impl( nStartIndex, sText );
341 checkIndex_Impl( nEndIndex, sText );
343 //!!! don't know how to put a string into the clipboard
344 return sal_False;
347 Rectangle AccessibleGridControlTableCell::implGetBoundingBox()
349 Window* pParent = m_aTable.GetAccessibleParentWindow();
350 DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
351 Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( pParent );
352 sal_Int32 nIndex = getAccessibleIndexInParent();
353 Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
354 long nX = aGridRect.Left() + aCellRect.Left();
355 long nY = aGridRect.Top() + aCellRect.Top();
356 Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
357 return aCell;
359 // -----------------------------------------------------------------------------
360 Rectangle AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
362 Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( NULL );
363 sal_Int32 nIndex = getAccessibleIndexInParent();
364 Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
365 long nX = aGridRect.Left() + aCellRect.Left();
366 long nY = aGridRect.Top() + aCellRect.Top();
367 Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
368 return aCell;
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */