1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleBrowseBoxTableCell.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
34 #include "accessibility/extended/AccessibleBrowseBoxTableCell.hxx"
35 #include <svtools/accessibletableprovider.hxx>
36 #include "accessibility/extended/AccessibleBrowseBox.hxx"
37 #include <tools/gen.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
39 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
41 namespace accessibility
45 void checkIndex_Impl( sal_Int32 _nIndex
, const ::rtl::OUString
& _sText
) throw (::com::sun::star::lang::IndexOutOfBoundsException
)
47 if ( _nIndex
>= _sText
.getLength() )
48 throw ::com::sun::star::lang::IndexOutOfBoundsException();
51 sal_Int32
getIndex_Impl( sal_Int32 _nRow
, sal_uInt16 _nColumn
, sal_uInt16 _nColumnCount
)
53 return _nRow
* _nColumnCount
+ _nColumn
;
56 using namespace ::com::sun::star::lang
;
58 using namespace comphelper
;
59 using ::rtl::OUString
;
60 using ::accessibility::AccessibleBrowseBox
;
61 using namespace ::com::sun::star::uno
;
62 using ::com::sun::star::accessibility::XAccessible
;
63 using namespace ::com::sun::star::accessibility
;
64 using namespace ::svt
;
67 // implementation of a table cell
68 ::rtl::OUString
AccessibleBrowseBoxTableCell::implGetText()
71 return mpBrowseBox
->GetAccessibleCellText( getRowPos(), static_cast< USHORT
>( getColumnPos() ) );
74 ::com::sun::star::lang::Locale
AccessibleBrowseBoxTableCell::implGetLocale()
77 return mpBrowseBox
->GetAccessible()->getAccessibleContext()->getLocale();
80 void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
86 AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference
<XAccessible
>& _rxParent
,
87 IAccessibleTableProvider
& _rBrowseBox
,
88 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& _xFocusWindow
,
92 :AccessibleBrowseBoxCell( _rxParent
, _rBrowseBox
, _xFocusWindow
, _nRowPos
, _nColPos
)
94 m_nOffset
= ( OFFSET_DEFAULT
== _nOffset
) ? (sal_Int32
)BBINDEX_FIRSTCONTROL
: _nOffset
;
95 sal_Int32 nIndex
= getIndex_Impl( _nRowPos
, _nColPos
, _rBrowseBox
.GetColumnCount() );
96 setAccessibleName( _rBrowseBox
.GetAccessibleObjectName( BBTYPE_TABLECELL
, nIndex
) );
97 setAccessibleDescription( _rBrowseBox
.GetAccessibleObjectDescription( BBTYPE_TABLECELL
, nIndex
) );
98 // Need to register as event listener
99 Reference
< XComponent
> xComponent(_rxParent
, UNO_QUERY
);
100 if( xComponent
.is() )
101 xComponent
->addEventListener(static_cast< XEventListener
*> (this));
104 void AccessibleBrowseBoxTableCell::nameChanged( const ::rtl::OUString
& rNewName
, const ::rtl::OUString
& rOldName
)
106 implSetName( rNewName
);
107 Any aOldValue
, aNewValue
;
108 aOldValue
<<= rOldName
;
109 aNewValue
<<= rNewName
;
110 commitEvent( AccessibleEventId::NAME_CHANGED
, aOldValue
, aNewValue
);
113 // XInterface -------------------------------------------------------------
115 /** Queries for a new interface. */
116 ::com::sun::star::uno::Any SAL_CALL
AccessibleBrowseBoxTableCell::queryInterface(
117 const ::com::sun::star::uno::Type
& rType
)
118 throw ( ::com::sun::star::uno::RuntimeException
)
120 Any aRet
= AccessibleBrowseBoxCell::queryInterface(rType
);
121 if ( !aRet
.hasValue() )
122 aRet
= AccessibleTextHelper_BASE::queryInterface(rType
);
126 /** Aquires the object (calls acquire() on base class). */
127 void SAL_CALL
AccessibleBrowseBoxTableCell::acquire() throw ()
129 AccessibleBrowseBoxCell::acquire();
132 /** Releases the object (calls release() on base class). */
133 void SAL_CALL
AccessibleBrowseBoxTableCell::release() throw ()
135 AccessibleBrowseBoxCell::release();
138 ::com::sun::star::awt::Rectangle SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
140 BBSolarGuard aSolarGuard
;
141 ::osl::MutexGuard
aGuard( getOslMutex() );
144 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
145 throw IndexOutOfBoundsException();
147 ::com::sun::star::awt::Rectangle aRect
;
151 aRect
= AWTRectangle( mpBrowseBox
->GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex
) );
157 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point
& _aPoint
) throw (RuntimeException
)
160 // DBG_ASSERT(0,"Need to be done by base class!");
161 BBSolarGuard aSolarGuard
;
162 ::osl::MutexGuard
aGuard( getOslMutex() );
165 return mpBrowseBox
->GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint
) );
169 The name of this class.
171 ::rtl::OUString SAL_CALL
AccessibleBrowseBoxTableCell::getImplementationName()
172 throw ( ::com::sun::star::uno::RuntimeException
)
174 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell" ) );
177 /** @return The count of visible children. */
178 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleChildCount()
179 throw ( ::com::sun::star::uno::RuntimeException
)
184 /** @return The XAccessible interface of the specified child. */
185 ::com::sun::star::uno::Reference
<
186 ::com::sun::star::accessibility::XAccessible
> SAL_CALL
187 AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int32
)
188 throw ( ::com::sun::star::lang::IndexOutOfBoundsException
,
189 ::com::sun::star::uno::RuntimeException
)
191 throw ::com::sun::star::lang::IndexOutOfBoundsException();
194 /** Creates a new AccessibleStateSetHelper and fills it with states of the
197 A filled AccessibleStateSetHelper.
199 ::utl::AccessibleStateSetHelper
* AccessibleBrowseBoxTableCell::implCreateStateSetHelper()
201 BBSolarGuard aSolarGuard
;
202 ::osl::MutexGuard
aGuard( getOslMutex() );
204 ::utl::AccessibleStateSetHelper
* pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
208 // SHOWING done with mxParent
209 if( implIsShowing() )
210 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
212 mpBrowseBox
->FillAccessibleStateSetForCell( *pStateSetHelper
, getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
215 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
217 return pStateSetHelper
;
221 // XAccessible ------------------------------------------------------------
223 /** @return The XAccessibleContext interface of this object. */
224 Reference
< XAccessibleContext
> SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleContext() throw ( RuntimeException
)
230 // XAccessibleContext -----------------------------------------------------
232 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
233 throw ( ::com::sun::star::uno::RuntimeException
)
235 BBSolarGuard aSolarGuard
;
236 ::osl::MutexGuard
aGuard( getOslMutex() );
239 return /*BBINDEX_FIRSTCONTROL*/ m_nOffset
+ ( getRowPos() * mpBrowseBox
->GetColumnCount() ) + getColumnPos();
242 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException
)
246 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
248 BBSolarGuard aSolarGuard
;
249 ::osl::MutexGuard
aGuard( getOslMutex() );
251 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
252 throw IndexOutOfBoundsException();
256 sal_Unicode SAL_CALL
AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
258 BBSolarGuard aSolarGuard
;
259 ::osl::MutexGuard
aGuard( getOslMutex() );
260 return OCommonAccessibleText::getCharacter( nIndex
);
262 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex
, const ::com::sun::star::uno::Sequence
< ::rtl::OUString
>& ) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
264 BBSolarGuard aSolarGuard
;
265 ::osl::MutexGuard
aGuard( getOslMutex() );
267 ::rtl::OUString
sText( implGetText() );
269 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
270 throw IndexOutOfBoundsException();
272 return ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>();
274 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException
)
276 BBSolarGuard aSolarGuard
;
277 ::osl::MutexGuard
aGuard( getOslMutex() );
278 return OCommonAccessibleText::getCharacterCount( );
281 ::rtl::OUString SAL_CALL
AccessibleBrowseBoxTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException
)
283 BBSolarGuard aSolarGuard
;
284 ::osl::MutexGuard
aGuard( getOslMutex() );
285 return OCommonAccessibleText::getSelectedText( );
287 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException
)
289 BBSolarGuard aSolarGuard
;
290 ::osl::MutexGuard
aGuard( getOslMutex() );
291 return OCommonAccessibleText::getSelectionStart( );
293 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException
)
295 BBSolarGuard aSolarGuard
;
296 ::osl::MutexGuard
aGuard( getOslMutex() );
297 return OCommonAccessibleText::getSelectionEnd( );
299 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
301 BBSolarGuard aSolarGuard
;
302 ::osl::MutexGuard
aGuard( getOslMutex() );
303 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
304 throw IndexOutOfBoundsException();
308 ::rtl::OUString SAL_CALL
AccessibleBrowseBoxTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException
)
310 BBSolarGuard aSolarGuard
;
311 ::osl::MutexGuard
aGuard( getOslMutex() );
312 return OCommonAccessibleText::getText( );
314 ::rtl::OUString SAL_CALL
AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
316 BBSolarGuard aSolarGuard
;
317 ::osl::MutexGuard
aGuard( getOslMutex() );
318 return OCommonAccessibleText::getTextRange( nStartIndex
, nEndIndex
);
320 ::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
)
322 BBSolarGuard aSolarGuard
;
323 ::osl::MutexGuard
aGuard( getOslMutex() );
324 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
326 ::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
)
328 BBSolarGuard aSolarGuard
;
329 ::osl::MutexGuard
aGuard( getOslMutex() );
330 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
332 ::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
)
334 BBSolarGuard aSolarGuard
;
335 ::osl::MutexGuard
aGuard( getOslMutex() );
336 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
338 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
340 BBSolarGuard aSolarGuard
;
341 ::osl::MutexGuard
aGuard( getOslMutex() );
342 ::rtl::OUString sText
= implGetText();
343 checkIndex_Impl( nStartIndex
, sText
);
344 checkIndex_Impl( nEndIndex
, sText
);
346 //!!! don't know how to put a string into the clipboard
349 void AccessibleBrowseBoxTableCell::disposing( const EventObject
& _rSource
) throw (RuntimeException
)
351 if ( _rSource
.Source
== mxParent
)