1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
31 #include "accessibility/extended/AccessibleGridControlTableCell.hxx"
32 #include <svtools/accessibletable.hxx>
33 #include "accessibility/extended/AccessibleGridControl.hxx"
34 #include <tools/gen.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
38 namespace accessibility
42 void checkIndex_Impl( sal_Int32 _nIndex
, const ::rtl::OUString
& _sText
) throw (::com::sun::star::lang::IndexOutOfBoundsException
)
44 if ( _nIndex
>= _sText
.getLength() )
45 throw ::com::sun::star::lang::IndexOutOfBoundsException();
48 sal_Int32
getIndex_Impl( sal_Int32 _nRow
, sal_uInt16 _nColumn
, sal_uInt16 _nColumnCount
)
50 return _nRow
* _nColumnCount
+ _nColumn
;
53 using namespace ::com::sun::star::lang
;
55 using namespace comphelper
;
56 using ::rtl::OUString
;
57 using ::accessibility::AccessibleGridControl
;
58 using namespace ::com::sun::star::uno
;
59 using ::com::sun::star::accessibility::XAccessible
;
60 using namespace ::com::sun::star::accessibility
;
61 using namespace ::svt
;
62 using namespace ::svt::table
;
65 // =============================================================================
66 // = AccessibleGridControlCell
67 // =============================================================================
68 // -----------------------------------------------------------------------------
69 AccessibleGridControlCell::AccessibleGridControlCell(
70 const Reference
< XAccessible
>& _rxParent
, IAccessibleTable
& _rTable
,
71 sal_Int32 _nRowPos
, sal_uInt16 _nColPos
, AccessibleTableControlObjType _eType
)
72 :AccessibleGridControlBase( _rxParent
, _rTable
, _eType
)
73 ,m_nRowPos( _nRowPos
)
74 ,m_nColPos( _nColPos
)
76 // set accessible name here, because for that we need the position of the cell
77 // and so the base class isn't capable of doing this
78 ::rtl::OUString aAccName
;
79 if(_eType
== TCTYPE_TABLECELL
)
80 aAccName
= _rTable
.GetAccessibleObjectName( TCTYPE_TABLECELL
, _nRowPos
, _nColPos
);
81 else if(_eType
== TCTYPE_ROWHEADERCELL
)
82 aAccName
= _rTable
.GetAccessibleObjectName( TCTYPE_ROWHEADERCELL
, _nRowPos
, 0 );
83 else if(_eType
== TCTYPE_COLUMNHEADERCELL
)
84 aAccName
= _rTable
.GetAccessibleObjectName( TCTYPE_COLUMNHEADERCELL
, 0, _nRowPos
);
85 implSetName( aAccName
);
88 // -----------------------------------------------------------------------------
89 AccessibleGridControlCell::~AccessibleGridControlCell()
93 // -----------------------------------------------------------------------------
94 void SAL_CALL
AccessibleGridControlCell::grabFocus() throw ( RuntimeException
)
96 TCSolarGuard aSolarGuard
;
97 ::osl::MutexGuard
aGuard( getOslMutex() );
98 m_aTable
.GoToCell( m_nColPos
, m_nRowPos
);
100 //// -----------------------------------------------------------------------------
101 // implementation of a table cell
102 ::rtl::OUString
AccessibleGridControlTableCell::implGetText()
105 return m_aTable
.GetAccessibleCellText( getRowPos(), getColumnPos() );
108 ::com::sun::star::lang::Locale
AccessibleGridControlTableCell::implGetLocale()
111 return m_aTable
.GetAccessible()->getAccessibleContext()->getLocale();
114 void AccessibleGridControlTableCell::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
120 AccessibleGridControlTableCell::AccessibleGridControlTableCell(const Reference
<XAccessible
>& _rxParent
,
121 IAccessibleTable
& _rTable
,
124 AccessibleTableControlObjType eObjType
)
125 :AccessibleGridControlCell( _rxParent
, _rTable
, _nRowPos
, _nColPos
, eObjType
)
129 // XInterface -------------------------------------------------------------
131 /** Queries for a new interface. */
132 ::com::sun::star::uno::Any SAL_CALL
AccessibleGridControlTableCell::queryInterface(
133 const ::com::sun::star::uno::Type
& rType
)
134 throw ( ::com::sun::star::uno::RuntimeException
)
136 Any aRet
= AccessibleGridControlCell::queryInterface(rType
);
137 if ( !aRet
.hasValue() )
138 aRet
= AccessibleTextHelper_BASE::queryInterface(rType
);
142 /** Aquires the object (calls acquire() on base class). */
143 void SAL_CALL
AccessibleGridControlTableCell::acquire() throw ()
145 AccessibleGridControlCell::acquire();
148 /** Releases the object (calls release() on base class). */
149 void SAL_CALL
AccessibleGridControlTableCell::release() throw ()
151 AccessibleGridControlCell::release();
154 ::com::sun::star::awt::Rectangle SAL_CALL
AccessibleGridControlTableCell::getCharacterBounds( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
156 TCSolarGuard aSolarGuard
;
157 ::osl::MutexGuard
aGuard( getOslMutex() );
160 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
161 throw IndexOutOfBoundsException();
163 ::com::sun::star::awt::Rectangle aRect
;
166 aRect
= AWTRectangle( m_aTable
.GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex
) );
170 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point
& _aPoint
) throw (RuntimeException
)
172 TCSolarGuard aSolarGuard
;
173 ::osl::MutexGuard
aGuard( getOslMutex() );
176 return m_aTable
.GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint
) );
180 The name of this class.
182 ::rtl::OUString SAL_CALL
AccessibleGridControlTableCell::getImplementationName()
183 throw ( ::com::sun::star::uno::RuntimeException
)
185 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleGridControlTableCell" ) );
188 /** @return The count of visible children. */
189 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getAccessibleChildCount()
190 throw ( ::com::sun::star::uno::RuntimeException
)
195 /** @return The XAccessible interface of the specified child. */
196 ::com::sun::star::uno::Reference
<
197 ::com::sun::star::accessibility::XAccessible
> SAL_CALL
198 AccessibleGridControlTableCell::getAccessibleChild( sal_Int32
)
199 throw ( ::com::sun::star::lang::IndexOutOfBoundsException
,
200 ::com::sun::star::uno::RuntimeException
)
202 throw ::com::sun::star::lang::IndexOutOfBoundsException();
205 /** Creates a new AccessibleStateSetHelper and fills it with states of the
208 A filled AccessibleStateSetHelper.
210 ::utl::AccessibleStateSetHelper
* AccessibleGridControlTableCell::implCreateStateSetHelper()
212 TCSolarGuard aSolarGuard
;
213 ::osl::MutexGuard
aGuard( getOslMutex() );
215 ::utl::AccessibleStateSetHelper
* pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
219 // SHOWING done with mxParent
220 if( implIsShowing() )
221 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
223 m_aTable
.FillAccessibleStateSetForCell( *pStateSetHelper
, getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
226 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
228 return pStateSetHelper
;
232 // XAccessible ------------------------------------------------------------
234 /** @return The XAccessibleContext interface of this object. */
235 Reference
< XAccessibleContext
> SAL_CALL
AccessibleGridControlTableCell::getAccessibleContext() throw ( RuntimeException
)
241 // XAccessibleContext -----------------------------------------------------
243 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getAccessibleIndexInParent()
244 throw ( ::com::sun::star::uno::RuntimeException
)
246 TCSolarGuard aSolarGuard
;
247 ::osl::MutexGuard
aGuard( getOslMutex() );
250 return ( getRowPos() * m_aTable
.GetColumnCount() ) + getColumnPos();
253 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException
)
257 sal_Bool SAL_CALL
AccessibleGridControlTableCell::setCaretPosition ( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
259 TCSolarGuard aSolarGuard
;
260 ::osl::MutexGuard
aGuard( getOslMutex() );
262 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
263 throw IndexOutOfBoundsException();
267 sal_Unicode SAL_CALL
AccessibleGridControlTableCell::getCharacter( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
269 TCSolarGuard aSolarGuard
;
270 ::osl::MutexGuard
aGuard( getOslMutex() );
271 return OCommonAccessibleText::getCharacter( nIndex
);
273 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> SAL_CALL
AccessibleGridControlTableCell::getCharacterAttributes( sal_Int32 nIndex
, const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& ) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
275 TCSolarGuard aSolarGuard
;
276 ::osl::MutexGuard
aGuard( getOslMutex() );
278 ::rtl::OUString
sText( implGetText() );
280 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
281 throw IndexOutOfBoundsException();
283 return ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>();
285 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException
)
287 TCSolarGuard aSolarGuard
;
288 ::osl::MutexGuard
aGuard( getOslMutex() );
289 return OCommonAccessibleText::getCharacterCount( );
292 ::rtl::OUString SAL_CALL
AccessibleGridControlTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException
)
294 TCSolarGuard aSolarGuard
;
295 ::osl::MutexGuard
aGuard( getOslMutex() );
296 return OCommonAccessibleText::getSelectedText( );
298 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException
)
300 TCSolarGuard aSolarGuard
;
301 ::osl::MutexGuard
aGuard( getOslMutex() );
302 return OCommonAccessibleText::getSelectionStart( );
304 sal_Int32 SAL_CALL
AccessibleGridControlTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException
)
306 TCSolarGuard aSolarGuard
;
307 ::osl::MutexGuard
aGuard( getOslMutex() );
308 return OCommonAccessibleText::getSelectionEnd( );
310 sal_Bool SAL_CALL
AccessibleGridControlTableCell::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
312 TCSolarGuard aSolarGuard
;
313 ::osl::MutexGuard
aGuard( getOslMutex() );
314 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
315 throw IndexOutOfBoundsException();
319 ::rtl::OUString SAL_CALL
AccessibleGridControlTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException
)
321 TCSolarGuard aSolarGuard
;
322 ::osl::MutexGuard
aGuard( getOslMutex() );
323 return OCommonAccessibleText::getText( );
325 ::rtl::OUString SAL_CALL
AccessibleGridControlTableCell::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
327 TCSolarGuard aSolarGuard
;
328 ::osl::MutexGuard
aGuard( getOslMutex() );
329 return OCommonAccessibleText::getTextRange( nStartIndex
, nEndIndex
);
331 ::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
)
333 TCSolarGuard aSolarGuard
;
334 ::osl::MutexGuard
aGuard( getOslMutex() );
335 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
337 ::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
)
339 TCSolarGuard aSolarGuard
;
340 ::osl::MutexGuard
aGuard( getOslMutex() );
341 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
343 ::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
)
345 TCSolarGuard aSolarGuard
;
346 ::osl::MutexGuard
aGuard( getOslMutex() );
347 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
349 sal_Bool SAL_CALL
AccessibleGridControlTableCell::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
351 TCSolarGuard aSolarGuard
;
352 ::osl::MutexGuard
aGuard( getOslMutex() );
353 ::rtl::OUString sText
= implGetText();
354 checkIndex_Impl( nStartIndex
, sText
);
355 checkIndex_Impl( nEndIndex
, sText
);
357 //!!! don't know how to put a string into the clipboard
361 Rectangle
AccessibleGridControlTableCell::implGetBoundingBox()
363 return Rectangle(Point(0,0),Point(0,0));//To Do - return headercell rectangle
365 // -----------------------------------------------------------------------------
366 Rectangle
AccessibleGridControlTableCell::implGetBoundingBoxOnScreen()
368 return Rectangle(Point(0,0),Point(0,0));//To Do - return headercell rectangle