1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/gen.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
28 namespace accessibility
32 static void checkIndex_Impl( sal_Int32 _nIndex
, const OUString
& _sText
) throw (::com::sun::star::lang::IndexOutOfBoundsException
)
34 if ( _nIndex
>= _sText
.getLength() )
35 throw ::com::sun::star::lang::IndexOutOfBoundsException();
38 static sal_Int32
getIndex_Impl( sal_Int32 _nRow
, sal_uInt16 _nColumn
, sal_uInt16 _nColumnCount
)
40 return _nRow
* _nColumnCount
+ _nColumn
;
43 using namespace ::com::sun::star::lang
;
45 using namespace comphelper
;
46 using ::accessibility::AccessibleBrowseBox
;
47 using namespace ::com::sun::star::uno
;
48 using ::com::sun::star::accessibility::XAccessible
;
49 using namespace ::com::sun::star::accessibility
;
50 using namespace ::svt
;
53 // implementation of a table cell
54 OUString
AccessibleBrowseBoxTableCell::implGetText()
57 return mpBrowseBox
->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
60 ::com::sun::star::lang::Locale
AccessibleBrowseBoxTableCell::implGetLocale()
63 return mpBrowseBox
->GetAccessible()->getAccessibleContext()->getLocale();
66 void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32
& nStartIndex
, sal_Int32
& nEndIndex
)
72 AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference
<XAccessible
>& _rxParent
,
73 IAccessibleTableProvider
& _rBrowseBox
,
74 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
>& _xFocusWindow
,
78 :AccessibleBrowseBoxCell( _rxParent
, _rBrowseBox
, _xFocusWindow
, _nRowPos
, _nColPos
)
80 m_nOffset
= ( OFFSET_DEFAULT
== _nOffset
) ? (sal_Int32
)BBINDEX_FIRSTCONTROL
: _nOffset
;
81 sal_Int32 nIndex
= getIndex_Impl( _nRowPos
, _nColPos
, _rBrowseBox
.GetColumnCount() );
82 setAccessibleName( _rBrowseBox
.GetAccessibleObjectName( BBTYPE_TABLECELL
, nIndex
) );
83 setAccessibleDescription( _rBrowseBox
.GetAccessibleObjectDescription( BBTYPE_TABLECELL
, nIndex
) );
84 // Need to register as event listener
85 Reference
< XComponent
> xComponent(_rxParent
, UNO_QUERY
);
87 xComponent
->addEventListener(static_cast< XEventListener
*> (this));
90 void AccessibleBrowseBoxTableCell::nameChanged( const OUString
& rNewName
, const OUString
& rOldName
)
92 implSetName( rNewName
);
93 Any aOldValue
, aNewValue
;
94 aOldValue
<<= rOldName
;
95 aNewValue
<<= rNewName
;
96 commitEvent( AccessibleEventId::NAME_CHANGED
, aOldValue
, aNewValue
);
99 // XInterface -------------------------------------------------------------
101 /** Queries for a new interface. */
102 ::com::sun::star::uno::Any SAL_CALL
AccessibleBrowseBoxTableCell::queryInterface(
103 const ::com::sun::star::uno::Type
& rType
)
104 throw ( ::com::sun::star::uno::RuntimeException
)
106 Any aRet
= AccessibleBrowseBoxCell::queryInterface(rType
);
107 if ( !aRet
.hasValue() )
108 aRet
= AccessibleTextHelper_BASE::queryInterface(rType
);
112 /** Aquires the object (calls acquire() on base class). */
113 void SAL_CALL
AccessibleBrowseBoxTableCell::acquire() throw ()
115 AccessibleBrowseBoxCell::acquire();
118 /** Releases the object (calls release() on base class). */
119 void SAL_CALL
AccessibleBrowseBoxTableCell::release() throw ()
121 AccessibleBrowseBoxCell::release();
124 ::com::sun::star::awt::Rectangle SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
126 SolarMutexGuard aSolarGuard
;
127 ::osl::MutexGuard
aGuard( getOslMutex() );
130 if ( !implIsValidIndex( nIndex
, implGetText().getLength() ) )
131 throw IndexOutOfBoundsException();
133 ::com::sun::star::awt::Rectangle aRect
;
137 aRect
= AWTRectangle( mpBrowseBox
->GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex
) );
143 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point
& _aPoint
) throw (RuntimeException
)
146 // OSL_FAIL("Need to be done by base class!");
147 SolarMutexGuard aSolarGuard
;
148 ::osl::MutexGuard
aGuard( getOslMutex() );
151 return mpBrowseBox
->GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint
) );
155 The name of this class.
157 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getImplementationName()
158 throw ( ::com::sun::star::uno::RuntimeException
)
160 return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell" );
163 /** @return The count of visible children. */
164 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleChildCount()
165 throw ( ::com::sun::star::uno::RuntimeException
)
170 /** @return The XAccessible interface of the specified child. */
171 ::com::sun::star::uno::Reference
<
172 ::com::sun::star::accessibility::XAccessible
> SAL_CALL
173 AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int32
)
174 throw ( ::com::sun::star::lang::IndexOutOfBoundsException
,
175 ::com::sun::star::uno::RuntimeException
)
177 throw ::com::sun::star::lang::IndexOutOfBoundsException();
180 /** Creates a new AccessibleStateSetHelper and fills it with states of the
183 A filled AccessibleStateSetHelper.
185 ::utl::AccessibleStateSetHelper
* AccessibleBrowseBoxTableCell::implCreateStateSetHelper()
187 SolarMutexGuard aSolarGuard
;
188 ::osl::MutexGuard
aGuard( getOslMutex() );
190 ::utl::AccessibleStateSetHelper
* pStateSetHelper
= new ::utl::AccessibleStateSetHelper
;
194 // SHOWING done with mxParent
195 if( implIsShowing() )
196 pStateSetHelper
->AddState( AccessibleStateType::SHOWING
);
198 mpBrowseBox
->FillAccessibleStateSetForCell( *pStateSetHelper
, getRowPos(), static_cast< sal_uInt16
>( getColumnPos() ) );
201 pStateSetHelper
->AddState( AccessibleStateType::DEFUNC
);
203 return pStateSetHelper
;
207 // XAccessible ------------------------------------------------------------
209 /** @return The XAccessibleContext interface of this object. */
210 Reference
< XAccessibleContext
> SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleContext() throw ( RuntimeException
)
216 // XAccessibleContext -----------------------------------------------------
218 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
219 throw ( ::com::sun::star::uno::RuntimeException
)
221 SolarMutexGuard aSolarGuard
;
222 ::osl::MutexGuard
aGuard( getOslMutex() );
225 return /*BBINDEX_FIRSTCONTROL*/ m_nOffset
+ ( getRowPos() * mpBrowseBox
->GetColumnCount() ) + getColumnPos();
228 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException
)
232 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
234 SolarMutexGuard aSolarGuard
;
235 ::osl::MutexGuard
aGuard( getOslMutex() );
237 if ( !implIsValidRange( nIndex
, nIndex
, implGetText().getLength() ) )
238 throw IndexOutOfBoundsException();
242 sal_Unicode SAL_CALL
AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
244 SolarMutexGuard aSolarGuard
;
245 ::osl::MutexGuard
aGuard( getOslMutex() );
246 return OCommonAccessibleText::getCharacter( nIndex
);
248 ::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
)
250 SolarMutexGuard aSolarGuard
;
251 ::osl::MutexGuard
aGuard( getOslMutex() );
253 OUString
sText( implGetText() );
255 if ( !implIsValidIndex( nIndex
, sText
.getLength() ) )
256 throw IndexOutOfBoundsException();
258 return ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>();
260 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException
)
262 SolarMutexGuard aSolarGuard
;
263 ::osl::MutexGuard
aGuard( getOslMutex() );
264 return OCommonAccessibleText::getCharacterCount( );
267 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException
)
269 SolarMutexGuard aSolarGuard
;
270 ::osl::MutexGuard
aGuard( getOslMutex() );
271 return OCommonAccessibleText::getSelectedText( );
273 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException
)
275 SolarMutexGuard aSolarGuard
;
276 ::osl::MutexGuard
aGuard( getOslMutex() );
277 return OCommonAccessibleText::getSelectionStart( );
279 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException
)
281 SolarMutexGuard aSolarGuard
;
282 ::osl::MutexGuard
aGuard( getOslMutex() );
283 return OCommonAccessibleText::getSelectionEnd( );
285 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
287 SolarMutexGuard aSolarGuard
;
288 ::osl::MutexGuard
aGuard( getOslMutex() );
289 if ( !implIsValidRange( nStartIndex
, nEndIndex
, implGetText().getLength() ) )
290 throw IndexOutOfBoundsException();
294 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException
)
296 SolarMutexGuard aSolarGuard
;
297 ::osl::MutexGuard
aGuard( getOslMutex() );
298 return OCommonAccessibleText::getText( );
300 OUString SAL_CALL
AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
302 SolarMutexGuard aSolarGuard
;
303 ::osl::MutexGuard
aGuard( getOslMutex() );
304 return OCommonAccessibleText::getTextRange( nStartIndex
, nEndIndex
);
306 ::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
)
308 SolarMutexGuard aSolarGuard
;
309 ::osl::MutexGuard
aGuard( getOslMutex() );
310 return OCommonAccessibleText::getTextAtIndex( nIndex
,aTextType
);
312 ::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
)
314 SolarMutexGuard aSolarGuard
;
315 ::osl::MutexGuard
aGuard( getOslMutex() );
316 return OCommonAccessibleText::getTextBeforeIndex( nIndex
,aTextType
);
318 ::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
)
320 SolarMutexGuard aSolarGuard
;
321 ::osl::MutexGuard
aGuard( getOslMutex() );
322 return OCommonAccessibleText::getTextBehindIndex( nIndex
,aTextType
);
324 sal_Bool SAL_CALL
AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex
, sal_Int32 nEndIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
326 SolarMutexGuard aSolarGuard
;
327 ::osl::MutexGuard
aGuard( getOslMutex() );
328 OUString sText
= implGetText();
329 checkIndex_Impl( nStartIndex
, sText
);
330 checkIndex_Impl( nEndIndex
, sText
);
332 //!!! don't know how to put a string into the clipboard
335 void AccessibleBrowseBoxTableCell::disposing( const EventObject
& _rSource
) throw (RuntimeException
)
337 if ( _rSource
.Source
== mxParent
)
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */