Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTableCell.cxx
blob85f10f7c7e0b974dd802b2e555b4e6c70ca16b84
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;
52 // = AccessibleGridControlCell
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 );
75 AccessibleGridControlCell::~AccessibleGridControlCell()
80 void SAL_CALL AccessibleGridControlCell::grabFocus() throw ( RuntimeException, std::exception )
82 SolarMutexGuard aSolarGuard;
84 m_aTable.GoToCell( m_nColPos, m_nRowPos );
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, std::exception )
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, std::exception)
142 SolarMutexGuard aSolarGuard;
144 ensureIsAlive();
145 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
146 throw IndexOutOfBoundsException();
148 return AWTRectangle( m_aTable.GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
151 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point& _aPoint ) throw (RuntimeException, std::exception)
153 SolarMutexGuard aSolarGuard;
155 ensureIsAlive();
157 return m_aTable.GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
160 /** @return
161 The name of this class.
163 OUString SAL_CALL AccessibleGridControlTableCell::getImplementationName()
164 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
166 return OUString( "com.sun.star.accessibility.AccessibleGridControlTableCell" );
169 /** @return The count of visible children. */
170 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getAccessibleChildCount()
171 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
173 return 0;
176 /** @return The XAccessible interface of the specified child. */
177 ::com::sun::star::uno::Reference<
178 ::com::sun::star::accessibility::XAccessible > SAL_CALL
179 AccessibleGridControlTableCell::getAccessibleChild( sal_Int32 )
180 throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
181 ::com::sun::star::uno::RuntimeException, std::exception )
183 throw ::com::sun::star::lang::IndexOutOfBoundsException();
186 /** Creates a new AccessibleStateSetHelper and fills it with states of the
187 current object.
188 @return
189 A filled AccessibleStateSetHelper.
191 ::utl::AccessibleStateSetHelper* AccessibleGridControlTableCell::implCreateStateSetHelper()
193 ::utl::AccessibleStateSetHelper* pStateSetHelper = new ::utl::AccessibleStateSetHelper;
195 if( isAlive() )
197 // SHOWING done with mxParent
198 if( implIsShowing() )
199 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
201 m_aTable.FillAccessibleStateSetForCell( *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
203 else
204 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
206 return pStateSetHelper;
210 // XAccessible ------------------------------------------------------------
212 /** @return The XAccessibleContext interface of this object. */
213 Reference< XAccessibleContext > SAL_CALL AccessibleGridControlTableCell::getAccessibleContext() throw ( RuntimeException, std::exception )
215 SolarMutexGuard g;
217 ensureIsAlive();
218 return this;
221 // XAccessibleContext -----------------------------------------------------
223 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getAccessibleIndexInParent()
224 throw ( ::com::sun::star::uno::RuntimeException, std::exception )
226 SolarMutexGuard aSolarGuard;
228 ensureIsAlive();
230 return ( getRowPos() * m_aTable.GetColumnCount() ) + getColumnPos();
233 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
235 return -1;
237 sal_Bool SAL_CALL AccessibleGridControlTableCell::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
239 SolarMutexGuard aSolarGuard;
241 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
242 throw IndexOutOfBoundsException();
244 return false;
246 sal_Unicode SAL_CALL AccessibleGridControlTableCell::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
248 SolarMutexGuard aSolarGuard;
250 return OCommonAccessibleText::getCharacter( nIndex );
252 ::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, std::exception)
254 SolarMutexGuard aSolarGuard;
256 OUString sText( implGetText() );
258 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
259 throw IndexOutOfBoundsException();
261 return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
263 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
265 SolarMutexGuard aSolarGuard;
267 return OCommonAccessibleText::getCharacterCount( );
270 OUString SAL_CALL AccessibleGridControlTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
272 SolarMutexGuard aSolarGuard;
274 return OCommonAccessibleText::getSelectedText( );
276 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
278 SolarMutexGuard aSolarGuard;
280 return OCommonAccessibleText::getSelectionStart( );
282 sal_Int32 SAL_CALL AccessibleGridControlTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
284 SolarMutexGuard aSolarGuard;
286 return OCommonAccessibleText::getSelectionEnd( );
288 sal_Bool SAL_CALL AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
290 SolarMutexGuard aSolarGuard;
292 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
293 throw IndexOutOfBoundsException();
295 return false;
297 OUString SAL_CALL AccessibleGridControlTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
299 SolarMutexGuard aSolarGuard;
301 return OCommonAccessibleText::getText( );
303 OUString SAL_CALL AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
305 SolarMutexGuard aSolarGuard;
307 return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
309 ::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, std::exception)
311 SolarMutexGuard aSolarGuard;
313 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
315 ::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, std::exception)
317 SolarMutexGuard aSolarGuard;
319 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
321 ::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, std::exception)
323 SolarMutexGuard aSolarGuard;
325 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
327 sal_Bool SAL_CALL AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception)
329 SolarMutexGuard aSolarGuard;
331 OUString sText = implGetText();
332 checkIndex_Impl( nStartIndex, sText );
333 checkIndex_Impl( nEndIndex, sText );
335 //!!! don't know how to put a string into the clipboard
336 return false;
339 Rectangle AccessibleGridControlTableCell::implGetBoundingBox()
341 vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
342 DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
343 Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( pParent );
344 sal_Int32 nIndex = getAccessibleIndexInParent();
345 Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
346 long nX = aGridRect.Left() + aCellRect.Left();
347 long nY = aGridRect.Top() + aCellRect.Top();
348 Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
349 return aCell;
352 Rectangle AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
354 Rectangle aGridRect = m_aTable.GetWindowExtentsRelative( NULL );
355 sal_Int32 nIndex = getAccessibleIndexInParent();
356 Rectangle aCellRect = m_aTable.calcCellRect(nIndex%m_aTable.GetColumnCount(), nIndex/m_aTable.GetColumnCount());
357 long nX = aGridRect.Left() + aCellRect.Left();
358 long nY = aGridRect.Top() + aCellRect.Top();
359 Rectangle aCell( Point( nX, nY ), aCellRect.GetSize());
360 return aCell;
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */