1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_accessibility.hxx"
26 
27 #include "accessibility/extended/AccessibleBrowseBoxTableCell.hxx"
28 #include <svtools/accessibletableprovider.hxx>
29 #include "accessibility/extended/AccessibleBrowseBox.hxx"
30 #include <tools/gen.hxx>
31 #include <toolkit/helper/vclunohelper.hxx>
32 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
33 
34 namespace accessibility
35 {
36 	namespace
37 	{
checkIndex_Impl(sal_Int32 _nIndex,const::rtl::OUString & _sText)38 		void checkIndex_Impl( sal_Int32 _nIndex, const ::rtl::OUString& _sText ) throw (::com::sun::star::lang::IndexOutOfBoundsException)
39 		{
40 			if ( _nIndex >= _sText.getLength() )
41 				throw ::com::sun::star::lang::IndexOutOfBoundsException();
42 		}
43 
getIndex_Impl(sal_Int32 _nRow,sal_uInt16 _nColumn,sal_uInt16 _nColumnCount)44 		sal_Int32 getIndex_Impl( sal_Int32 _nRow, sal_uInt16 _nColumn, sal_uInt16 _nColumnCount )
45 		{
46 			return _nRow * _nColumnCount + _nColumn;
47 		}
48 	}
49 	using namespace ::com::sun::star::lang;
50 	using namespace utl;
51 	using namespace comphelper;
52 	using ::rtl::OUString;
53 	using ::accessibility::AccessibleBrowseBox;
54 	using namespace ::com::sun::star::uno;
55 	using ::com::sun::star::accessibility::XAccessible;
56 	using namespace ::com::sun::star::accessibility;
57     using namespace ::svt;
58 
59 
60 	// implementation of a table cell
implGetText()61 	::rtl::OUString AccessibleBrowseBoxTableCell::implGetText()
62 	{
63 		ensureIsAlive();
64         return mpBrowseBox->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
65 	}
66 
implGetLocale()67 	::com::sun::star::lang::Locale AccessibleBrowseBoxTableCell::implGetLocale()
68 	{
69 		ensureIsAlive();
70 		return mpBrowseBox->GetAccessible()->getAccessibleContext()->getLocale();
71 	}
72 
implGetSelection(sal_Int32 & nStartIndex,sal_Int32 & nEndIndex)73 	void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
74 	{
75 		nStartIndex = 0;
76 		nEndIndex = 0;
77 	}
78 
AccessibleBrowseBoxTableCell(const Reference<XAccessible> & _rxParent,IAccessibleTableProvider & _rBrowseBox,const::com::sun::star::uno::Reference<::com::sun::star::awt::XWindow> & _xFocusWindow,sal_Int32 _nRowPos,sal_uInt16 _nColPos,sal_Int32 _nOffset)79 	AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference<XAccessible >& _rxParent,
80 								IAccessibleTableProvider& _rBrowseBox,
81 								const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow,
82 								sal_Int32 _nRowPos,
83                                 sal_uInt16 _nColPos,
84                                 sal_Int32 _nOffset )
85 		:AccessibleBrowseBoxCell( _rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos )
86 	{
87         m_nOffset = ( OFFSET_DEFAULT == _nOffset ) ? (sal_Int32)BBINDEX_FIRSTCONTROL : _nOffset;
88 		sal_Int32 nIndex = getIndex_Impl( _nRowPos, _nColPos, _rBrowseBox.GetColumnCount() );
89        setAccessibleName( _rBrowseBox.GetAccessibleObjectName( BBTYPE_TABLECELL, nIndex ) );
90        setAccessibleDescription( _rBrowseBox.GetAccessibleObjectDescription( BBTYPE_TABLECELL, nIndex ) );
91         // Need to register as event listener
92         Reference< XComponent > xComponent(_rxParent, UNO_QUERY);
93         if( xComponent.is() )
94             xComponent->addEventListener(static_cast< XEventListener *> (this));
95 	}
96 
nameChanged(const::rtl::OUString & rNewName,const::rtl::OUString & rOldName)97     void AccessibleBrowseBoxTableCell::nameChanged( const ::rtl::OUString& rNewName, const ::rtl::OUString& rOldName )
98     {
99         implSetName( rNewName );
100         Any aOldValue, aNewValue;
101         aOldValue <<= rOldName;
102         aNewValue <<= rNewName;
103         commitEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
104     }
105 
106 	// XInterface -------------------------------------------------------------
107 
108 	/** Queries for a new interface. */
queryInterface(const::com::sun::star::uno::Type & rType)109 	::com::sun::star::uno::Any SAL_CALL AccessibleBrowseBoxTableCell::queryInterface(
110 			const ::com::sun::star::uno::Type& rType )
111 		throw ( ::com::sun::star::uno::RuntimeException )
112 	{
113 		Any aRet = AccessibleBrowseBoxCell::queryInterface(rType);
114 		if ( !aRet.hasValue() )
115 			aRet = AccessibleTextHelper_BASE::queryInterface(rType);
116 		return aRet;
117 	}
118 
119 	/** Aquires the object (calls acquire() on base class). */
acquire()120 	void SAL_CALL AccessibleBrowseBoxTableCell::acquire() throw ()
121 	{
122 		AccessibleBrowseBoxCell::acquire();
123 	}
124 
125 	/** Releases the object (calls release() on base class). */
release()126 	void SAL_CALL AccessibleBrowseBoxTableCell::release() throw ()
127 	{
128 		AccessibleBrowseBoxCell::release();
129 	}
130 
getCharacterBounds(sal_Int32 nIndex)131 	::com::sun::star::awt::Rectangle SAL_CALL AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
132 	{
133 		BBSolarGuard aSolarGuard;
134 		::osl::MutexGuard aGuard( getOslMutex() );
135 
136 		ensureIsAlive();
137 		if ( !implIsValidIndex( nIndex, implGetText().getLength() ) )
138 			throw IndexOutOfBoundsException();
139 
140 		::com::sun::star::awt::Rectangle aRect;
141 
142 		if ( mpBrowseBox )
143 		{
144 			aRect = AWTRectangle( mpBrowseBox->GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) );
145 		}
146 
147 		return aRect;
148 	}
149 
getIndexAtPoint(const::com::sun::star::awt::Point & _aPoint)150 	sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point& _aPoint ) throw (RuntimeException)
151 	{
152 		//! TODO CTL bidi
153 		// DBG_ASSERT(0,"Need to be done by base class!");
154 		BBSolarGuard aSolarGuard;
155 		::osl::MutexGuard aGuard( getOslMutex() );
156 		ensureIsAlive();
157 
158 		return mpBrowseBox->GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) );
159 	}
160 
161 	/** @return
162 			The name of this class.
163 	*/
getImplementationName()164 	::rtl::OUString SAL_CALL AccessibleBrowseBoxTableCell::getImplementationName()
165 		throw ( ::com::sun::star::uno::RuntimeException )
166 	{
167 		return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell" ) );
168 	}
169 
170 	/** @return  The count of visible children. */
getAccessibleChildCount()171 	sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleChildCount()
172 		throw ( ::com::sun::star::uno::RuntimeException )
173 	{
174 		return 0;
175 	}
176 
177 	/** @return  The XAccessible interface of the specified child. */
178 	::com::sun::star::uno::Reference<
179 		::com::sun::star::accessibility::XAccessible > SAL_CALL
getAccessibleChild(sal_Int32)180 		AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int32 )
181 			throw ( ::com::sun::star::lang::IndexOutOfBoundsException,
182 					::com::sun::star::uno::RuntimeException )
183 	{
184 		throw ::com::sun::star::lang::IndexOutOfBoundsException();
185 	}
186 
187 	/** Creates a new AccessibleStateSetHelper and fills it with states of the
188 		current object.
189 		@return
190 			A filled AccessibleStateSetHelper.
191 	*/
implCreateStateSetHelper()192 	::utl::AccessibleStateSetHelper* AccessibleBrowseBoxTableCell::implCreateStateSetHelper()
193 	{
194 		BBSolarGuard aSolarGuard;
195 		::osl::MutexGuard aGuard( getOslMutex() );
196 
197 		::utl::AccessibleStateSetHelper* pStateSetHelper = new ::utl::AccessibleStateSetHelper;
198 
199 		if( isAlive() )
200 		{
201 			// SHOWING done with mxParent
202 			if( implIsShowing() )
203 				pStateSetHelper->AddState( AccessibleStateType::SHOWING );
204 
205             mpBrowseBox->FillAccessibleStateSetForCell( *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) );
206 		}
207 		else
208 			pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
209 
210 		return pStateSetHelper;
211 	}
212 
213 
214 	// XAccessible ------------------------------------------------------------
215 
216 	/** @return  The XAccessibleContext interface of this object. */
getAccessibleContext()217 	Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleContext() throw ( RuntimeException )
218 	{
219 		ensureIsAlive();
220 		return this;
221 	}
222 
223 	// XAccessibleContext -----------------------------------------------------
224 
getAccessibleIndexInParent()225 	sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleIndexInParent()
226 			throw ( ::com::sun::star::uno::RuntimeException )
227 	{
228 		BBSolarGuard aSolarGuard;
229 		::osl::MutexGuard aGuard( getOslMutex() );
230 		ensureIsAlive();
231 
232         return /*BBINDEX_FIRSTCONTROL*/ m_nOffset + ( getRowPos() * mpBrowseBox->GetColumnCount() ) + getColumnPos();
233 	}
234 
getCaretPosition()235 	sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCaretPosition(  ) throw (::com::sun::star::uno::RuntimeException)
236 	{
237 		return -1;
238 	}
setCaretPosition(sal_Int32 nIndex)239 	sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
240 	{
241 		BBSolarGuard aSolarGuard;
242 		::osl::MutexGuard aGuard( getOslMutex() );
243 
244 		if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
245 			throw IndexOutOfBoundsException();
246 
247 		return sal_False;
248 	}
getCharacter(sal_Int32 nIndex)249 	sal_Unicode SAL_CALL AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
250 	{
251 		BBSolarGuard aSolarGuard;
252 		::osl::MutexGuard aGuard( getOslMutex() );
253 		return OCommonAccessibleText::getCharacter( nIndex );
254 	}
getCharacterAttributes(sal_Int32 nIndex,const::com::sun::star::uno::Sequence<::rtl::OUString> &)255 	::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)
256 	{
257 		BBSolarGuard aSolarGuard;
258 		::osl::MutexGuard aGuard( getOslMutex() );
259 
260 		::rtl::OUString sText( implGetText() );
261 
262 		if ( !implIsValidIndex( nIndex, sText.getLength() ) )
263 			throw IndexOutOfBoundsException();
264 
265 		return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >();
266 	}
getCharacterCount()267 	sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCharacterCount(  ) throw (::com::sun::star::uno::RuntimeException)
268 	{
269 		BBSolarGuard aSolarGuard;
270 		::osl::MutexGuard aGuard( getOslMutex() );
271 		return OCommonAccessibleText::getCharacterCount(  );
272 	}
273 
getSelectedText()274 	::rtl::OUString SAL_CALL AccessibleBrowseBoxTableCell::getSelectedText(  ) throw (::com::sun::star::uno::RuntimeException)
275 	{
276 		BBSolarGuard aSolarGuard;
277 		::osl::MutexGuard aGuard( getOslMutex() );
278 		return OCommonAccessibleText::getSelectedText(  );
279 	}
getSelectionStart()280 	sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionStart(  ) throw (::com::sun::star::uno::RuntimeException)
281 	{
282 		BBSolarGuard aSolarGuard;
283 		::osl::MutexGuard aGuard( getOslMutex() );
284 		return OCommonAccessibleText::getSelectionStart(  );
285 	}
getSelectionEnd()286 	sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionEnd(  ) throw (::com::sun::star::uno::RuntimeException)
287 	{
288 		BBSolarGuard aSolarGuard;
289 		::osl::MutexGuard aGuard( getOslMutex() );
290 		return OCommonAccessibleText::getSelectionEnd(  );
291 	}
setSelection(sal_Int32 nStartIndex,sal_Int32 nEndIndex)292 	sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
293 	{
294 		BBSolarGuard aSolarGuard;
295 		::osl::MutexGuard aGuard( getOslMutex() );
296 		if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
297 			throw IndexOutOfBoundsException();
298 
299 		return sal_False;
300 	}
getText()301 	::rtl::OUString SAL_CALL AccessibleBrowseBoxTableCell::getText(  ) throw (::com::sun::star::uno::RuntimeException)
302 	{
303 		BBSolarGuard aSolarGuard;
304 		::osl::MutexGuard aGuard( getOslMutex() );
305 		return OCommonAccessibleText::getText(  );
306 	}
getTextRange(sal_Int32 nStartIndex,sal_Int32 nEndIndex)307 	::rtl::OUString SAL_CALL AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
308 	{
309 		BBSolarGuard aSolarGuard;
310 		::osl::MutexGuard aGuard( getOslMutex() );
311 		return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
312 	}
getTextAtIndex(sal_Int32 nIndex,sal_Int16 aTextType)313     ::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)
314 	{
315 		BBSolarGuard aSolarGuard;
316 		::osl::MutexGuard aGuard( getOslMutex() );
317 		return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType);
318 	}
getTextBeforeIndex(sal_Int32 nIndex,sal_Int16 aTextType)319     ::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)
320 	{
321 		BBSolarGuard aSolarGuard;
322 		::osl::MutexGuard aGuard( getOslMutex() );
323 		return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType);
324 	}
getTextBehindIndex(sal_Int32 nIndex,sal_Int16 aTextType)325     ::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)
326 	{
327 		BBSolarGuard aSolarGuard;
328 		::osl::MutexGuard aGuard( getOslMutex() );
329 		return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType);
330 	}
copyText(sal_Int32 nStartIndex,sal_Int32 nEndIndex)331 	sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException)
332 	{
333 		BBSolarGuard aSolarGuard;
334 		::osl::MutexGuard aGuard( getOslMutex() );
335 		::rtl::OUString sText = implGetText();
336 		checkIndex_Impl( nStartIndex, sText );
337 		checkIndex_Impl( nEndIndex, sText );
338 
339 		//!!! don't know how to put a string into the clipboard
340 		return sal_False;
341 	}
disposing(const EventObject & _rSource)342 	void AccessibleBrowseBoxTableCell::disposing( const EventObject& _rSource ) throw (RuntimeException)
343 	{
344         	if ( _rSource.Source == mxParent )
345         	{
346                 	dispose();
347         	}
348 	}
349 
350 }
351