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 #include <accessibility/standard/vclxaccessiblelistitem.hxx>
27 #include <toolkit/helper/convert.hxx>
28 #include <accessibility/helper/listboxhelper.hxx>
29 #include <com/sun/star/awt/Point.hpp>
30 #include <com/sun/star/awt/Rectangle.hpp>
31 #include <com/sun/star/awt/Size.hpp>
32 
33 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
34 #include <com/sun/star/accessibility/AccessibleRole.hpp>
35 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
37 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
38 #include <tools/debug.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/controllayout.hxx>
41 #include <vcl/unohelp2.hxx>
42 #include <toolkit/awt/vclxwindow.hxx>
43 #include <unotools/accessiblestatesethelper.hxx>
44 #include <unotools/accessiblerelationsethelper.hxx>
45 #include <cppuhelper/typeprovider.hxx>
46 #include <comphelper/sequence.hxx>
47 #include <comphelper/accessibleeventnotifier.hxx>
48 
49 namespace
50 {
51 	void checkIndex_Impl( sal_Int32 _nIndex, const ::rtl::OUString& _sText ) throw (::com::sun::star::lang::IndexOutOfBoundsException)
52 	{
53 		if ( _nIndex < 0 || _nIndex > _sText.getLength() )
54 			throw ::com::sun::star::lang::IndexOutOfBoundsException();
55 	}
56 }
57 
58 // class VCLXAccessibleListItem ------------------------------------------
59 
60 using namespace ::com::sun::star::accessibility;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::beans;
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star;
65 
66 DBG_NAME(VCLXAccessibleListItem)
67 
68 // -----------------------------------------------------------------------------
69 // Ctor() and Dtor()
70 // -----------------------------------------------------------------------------
71 VCLXAccessibleListItem::VCLXAccessibleListItem( ::accessibility::IComboListBoxHelper* _pListBoxHelper, sal_Int32 _nIndexInParent, const Reference< XAccessible >& _xParent ) :
72 
73 	VCLXAccessibleListItem_BASE	( m_aMutex ),
74 
75 	m_nIndexInParent( _nIndexInParent ),
76 	m_bSelected		( sal_False ),
77 	m_bVisible		( sal_False ),
78     m_nClientId     ( 0 ),
79 	m_pListBoxHelper( _pListBoxHelper ),
80 	m_xParent		( _xParent )
81 
82 {
83 	DBG_CTOR( VCLXAccessibleListItem, NULL );
84 
85 	if ( m_xParent.is() )
86 		m_xParentContext = m_xParent->getAccessibleContext();
87 
88 	if ( m_pListBoxHelper )
89 		m_sEntryText = m_pListBoxHelper->GetEntry( (sal_uInt16)_nIndexInParent );
90 }
91 // -----------------------------------------------------------------------------
92 VCLXAccessibleListItem::~VCLXAccessibleListItem()
93 {
94 	DBG_DTOR( VCLXAccessibleListItem, NULL );
95 }
96 // -----------------------------------------------------------------------------
97 void VCLXAccessibleListItem::SetSelected( sal_Bool _bSelected )
98 {
99 	if ( m_bSelected != _bSelected )
100 	{
101 		Any aOldValue;
102 		Any aNewValue;
103 		if ( m_bSelected )
104 			aOldValue <<= AccessibleStateType::SELECTED;
105 		else
106 			aNewValue <<= AccessibleStateType::SELECTED;
107 		m_bSelected = _bSelected;
108         NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
109 	}
110 }
111 // -----------------------------------------------------------------------------
112 void VCLXAccessibleListItem::SetVisible( sal_Bool _bVisible )
113 {
114 	if ( m_bVisible != _bVisible )
115 	{
116 		Any aOldValue, aNewValue;
117 		m_bVisible = _bVisible;
118 		(_bVisible ? aNewValue : aOldValue ) <<= AccessibleStateType::VISIBLE;
119 		NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
120 		(_bVisible ? aNewValue : aOldValue ) <<= AccessibleStateType::SHOWING;
121 		NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
122 	}
123 }
124 // -----------------------------------------------------------------------------
125 void VCLXAccessibleListItem::NotifyAccessibleEvent( sal_Int16 _nEventId,
126 													const ::com::sun::star::uno::Any& _aOldValue,
127 													const ::com::sun::star::uno::Any& _aNewValue )
128 {
129 	AccessibleEventObject aEvt;
130 	aEvt.Source = *this;
131 	aEvt.EventId = _nEventId;
132     aEvt.OldValue = _aOldValue;
133     aEvt.NewValue = _aNewValue;
134 
135 	if (m_nClientId)
136 		comphelper::AccessibleEventNotifier::addEvent( m_nClientId, aEvt );
137 }
138 // -----------------------------------------------------------------------------
139 // OCommonAccessibleText
140 // -----------------------------------------------------------------------------
141 ::rtl::OUString VCLXAccessibleListItem::implGetText()
142 {
143 	return m_sEntryText;
144 }
145 // -----------------------------------------------------------------------------
146 Locale VCLXAccessibleListItem::implGetLocale()
147 {
148 	return Application::GetSettings().GetLocale();
149 }
150 // -----------------------------------------------------------------------------
151 void VCLXAccessibleListItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
152 {
153 	nStartIndex = 0;
154 	nEndIndex = 0;
155 }
156 // -----------------------------------------------------------------------------
157 // XInterface
158 // -----------------------------------------------------------------------------
159 Any SAL_CALL VCLXAccessibleListItem::queryInterface( Type const & rType ) throw (RuntimeException)
160 {
161 	return VCLXAccessibleListItem_BASE::queryInterface( rType );
162 }
163 // -----------------------------------------------------------------------------
164 void SAL_CALL VCLXAccessibleListItem::acquire() throw ()
165 {
166 	VCLXAccessibleListItem_BASE::acquire();
167 }
168 // -----------------------------------------------------------------------------
169 void SAL_CALL VCLXAccessibleListItem::release() throw ()
170 {
171 	VCLXAccessibleListItem_BASE::release();
172 }
173 // -----------------------------------------------------------------------------
174 // XTypeProvider
175 // -----------------------------------------------------------------------------
176 Sequence< Type > SAL_CALL VCLXAccessibleListItem::getTypes(  ) throw (RuntimeException)
177 {
178 	return VCLXAccessibleListItem_BASE::getTypes();
179 }
180 // -----------------------------------------------------------------------------
181 Sequence< sal_Int8 > VCLXAccessibleListItem::getImplementationId() throw (RuntimeException)
182 {
183 	static ::cppu::OImplementationId* pId = NULL;
184 
185 	if ( !pId )
186 	{
187 		::osl::Guard< ::osl::Mutex > aGuard( m_aMutex );
188 
189 		if ( !pId )
190 		{
191 			static ::cppu::OImplementationId aId;
192 			pId = &aId;
193 		}
194 	}
195 	return pId->getImplementationId();
196 }
197 // -----------------------------------------------------------------------------
198 // XComponent
199 // -----------------------------------------------------------------------------
200 void SAL_CALL VCLXAccessibleListItem::disposing()
201 {
202 	comphelper::AccessibleEventNotifier::TClientId nId( 0 );
203 	Reference< XInterface > xEventSource;
204 	{
205 		::osl::MutexGuard aGuard( m_aMutex );
206 
207 		VCLXAccessibleListItem_BASE::disposing();
208 		m_sEntryText		= ::rtl::OUString();
209 		m_pListBoxHelper	= NULL;
210 		m_xParent			= NULL;
211 		m_xParentContext	= NULL;
212 
213 		nId = m_nClientId;
214 		m_nClientId =  0;
215 		if ( nId )
216 			xEventSource = *this;
217 	}
218 
219     // Send a disposing to all listeners.
220 	if ( nId )
221         	comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( nId, *this );
222 }
223 // -----------------------------------------------------------------------------
224 // XServiceInfo
225 // -----------------------------------------------------------------------------
226 ::rtl::OUString VCLXAccessibleListItem::getImplementationName() throw (RuntimeException)
227 {
228 	return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleListItem" );
229 }
230 // -----------------------------------------------------------------------------
231 sal_Bool VCLXAccessibleListItem::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
232 {
233 	Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
234 	const ::rtl::OUString* pNames = aNames.getConstArray();
235 	const ::rtl::OUString* pEnd = pNames + aNames.getLength();
236 	for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
237 		;
238 
239 	return pNames != pEnd;
240 }
241 // -----------------------------------------------------------------------------
242 Sequence< ::rtl::OUString > VCLXAccessibleListItem::getSupportedServiceNames() throw (RuntimeException)
243 {
244 	Sequence< ::rtl::OUString > aNames(3);
245 	aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleContext" );
246 	aNames[1] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleComponent" );
247 	aNames[2] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleListItem" );
248 	return aNames;
249 }
250 // -----------------------------------------------------------------------------
251 // XAccessible
252 // -----------------------------------------------------------------------------
253 Reference< XAccessibleContext > SAL_CALL VCLXAccessibleListItem::getAccessibleContext(  ) throw (RuntimeException)
254 {
255 	return this;
256 }
257 // -----------------------------------------------------------------------------
258 // XAccessibleContext
259 // -----------------------------------------------------------------------------
260 sal_Int32 SAL_CALL VCLXAccessibleListItem::getAccessibleChildCount(  ) throw (RuntimeException)
261 {
262 	return 0;
263 }
264 // -----------------------------------------------------------------------------
265 Reference< XAccessible > SAL_CALL VCLXAccessibleListItem::getAccessibleChild( sal_Int32 ) throw (RuntimeException)
266 {
267 	return Reference< XAccessible >();
268 }
269 // -----------------------------------------------------------------------------
270 Reference< XAccessible > SAL_CALL VCLXAccessibleListItem::getAccessibleParent(  ) throw (RuntimeException)
271 {
272 	::osl::MutexGuard aGuard( m_aMutex );
273 
274 	return m_xParent;
275 }
276 // -----------------------------------------------------------------------------
277 sal_Int32 SAL_CALL VCLXAccessibleListItem::getAccessibleIndexInParent(  ) throw (RuntimeException)
278 {
279 	::osl::MutexGuard aGuard( m_aMutex );
280 	return m_nIndexInParent;
281 }
282 // -----------------------------------------------------------------------------
283 sal_Int16 SAL_CALL VCLXAccessibleListItem::getAccessibleRole(  ) throw (RuntimeException)
284 {
285 	return AccessibleRole::LIST_ITEM;
286     //	return AccessibleRole::LABEL;
287 }
288 // -----------------------------------------------------------------------------
289 ::rtl::OUString SAL_CALL VCLXAccessibleListItem::getAccessibleDescription(  ) throw (RuntimeException)
290 {
291 	// no description for every item
292 	return ::rtl::OUString();
293 }
294 // -----------------------------------------------------------------------------
295 ::rtl::OUString SAL_CALL VCLXAccessibleListItem::getAccessibleName(  ) throw (RuntimeException)
296 {
297 	::osl::MutexGuard aGuard( m_aMutex );
298 
299 	// entry text == accessible name
300 	return implGetText();
301 }
302 // -----------------------------------------------------------------------------
303 Reference< XAccessibleRelationSet > SAL_CALL VCLXAccessibleListItem::getAccessibleRelationSet(  ) throw (RuntimeException)
304 {
305     utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
306 	Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
307     return xSet;
308 }
309 // -----------------------------------------------------------------------------
310 Reference< XAccessibleStateSet > SAL_CALL VCLXAccessibleListItem::getAccessibleStateSet(  ) throw (RuntimeException)
311 {
312 	::osl::MutexGuard aGuard( m_aMutex );
313 
314     utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
315 	Reference< XAccessibleStateSet > xStateSet = pStateSetHelper;
316 
317 	if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
318 	{
319         pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
320 
321 		// IAccessible2 implementation, 2009
322 		if(m_pListBoxHelper->IsEnabled())
323 		{
324 	    	pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
325 	    	pStateSetHelper->AddState( AccessibleStateType::ENABLED );
326 	    	pStateSetHelper->AddState( AccessibleStateType::SENSITIVE );
327 		}
328 
329         if ( m_bSelected )
330 			pStateSetHelper->AddState( AccessibleStateType::SELECTED );
331 		if ( m_bVisible )
332 		{
333 			pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
334 			pStateSetHelper->AddState( AccessibleStateType::SHOWING );
335 		}
336 	}
337 	else
338         pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
339 
340     return xStateSet;
341 }
342 // -----------------------------------------------------------------------------
343 Locale SAL_CALL VCLXAccessibleListItem::getLocale(  ) throw (IllegalAccessibleComponentStateException, RuntimeException)
344 {
345 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
346 	::osl::MutexGuard aGuard( m_aMutex );
347 
348     return implGetLocale();
349 }
350 // -----------------------------------------------------------------------------
351 // XAccessibleComponent
352 // -----------------------------------------------------------------------------
353 sal_Bool SAL_CALL VCLXAccessibleListItem::containsPoint( const awt::Point& _aPoint ) throw (RuntimeException)
354 {
355 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
356 	::osl::MutexGuard aGuard( m_aMutex );
357 
358 	sal_Bool bInside = sal_False;
359 	if ( m_pListBoxHelper )
360 	{
361 		Rectangle aRect( m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent ) );
362 		aRect.Move(-aRect.TopLeft().X(),-aRect.TopLeft().Y());
363 		bInside = aRect.IsInside( VCLPoint( _aPoint ) );
364 	}
365 	return bInside;
366 }
367 // -----------------------------------------------------------------------------
368 Reference< XAccessible > SAL_CALL VCLXAccessibleListItem::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
369 {
370 	return Reference< XAccessible >();
371 }
372 // -----------------------------------------------------------------------------
373 awt::Rectangle SAL_CALL VCLXAccessibleListItem::getBounds(  ) throw (RuntimeException)
374 {
375 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
376 	::osl::MutexGuard aGuard( m_aMutex );
377 
378 	awt::Rectangle aRect;
379 	if ( m_pListBoxHelper )
380 		aRect = AWTRectangle( m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent ) );
381 
382 	return aRect;
383 }
384 // -----------------------------------------------------------------------------
385 awt::Point SAL_CALL VCLXAccessibleListItem::getLocation(  ) throw (RuntimeException)
386 {
387 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
388 	::osl::MutexGuard aGuard( m_aMutex );
389 
390 	Point aPoint(0,0);
391 	if ( m_pListBoxHelper )
392 	{
393 		Rectangle aRect = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent );
394 		aPoint = aRect.TopLeft();
395 	}
396 	return AWTPoint( aPoint );
397 }
398 // -----------------------------------------------------------------------------
399 awt::Point SAL_CALL VCLXAccessibleListItem::getLocationOnScreen(  ) throw (RuntimeException)
400 {
401 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
402 	::osl::MutexGuard aGuard( m_aMutex );
403 
404 	Point aPoint(0,0);
405 	if ( m_pListBoxHelper )
406 	{
407 		Rectangle aRect = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent );
408 		aPoint = aRect.TopLeft();
409 		aPoint += m_pListBoxHelper->GetWindowExtentsRelative( NULL ).TopLeft();
410 	}
411 	return AWTPoint( aPoint );
412 }
413 // -----------------------------------------------------------------------------
414 awt::Size SAL_CALL VCLXAccessibleListItem::getSize(  ) throw (RuntimeException)
415 {
416 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
417 	::osl::MutexGuard aGuard( m_aMutex );
418 
419 	Size aSize;
420 	if ( m_pListBoxHelper )
421 		aSize = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent ).GetSize();
422 
423 	return AWTSize( aSize );
424 }
425 // -----------------------------------------------------------------------------
426 void SAL_CALL VCLXAccessibleListItem::grabFocus(  ) throw (RuntimeException)
427 {
428 	// no focus for each item
429 }
430 // -----------------------------------------------------------------------------
431 // XAccessibleText
432 // -----------------------------------------------------------------------------
433 sal_Int32 SAL_CALL VCLXAccessibleListItem::getCaretPosition() throw (RuntimeException)
434 {
435 	return -1;
436 }
437 // -----------------------------------------------------------------------------
438 sal_Bool SAL_CALL VCLXAccessibleListItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
439 {
440 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
441 	::osl::MutexGuard aGuard( m_aMutex );
442 
443     if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
444         throw IndexOutOfBoundsException();
445 
446 	return sal_False;
447 }
448 // -----------------------------------------------------------------------------
449 sal_Unicode SAL_CALL VCLXAccessibleListItem::getCharacter( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
450 {
451 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
452 	::osl::MutexGuard aGuard( m_aMutex );
453 
454 	return OCommonAccessibleText::getCharacter( nIndex );
455 }
456 // -----------------------------------------------------------------------------
457 Sequence< PropertyValue > SAL_CALL VCLXAccessibleListItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& ) throw (IndexOutOfBoundsException, RuntimeException)
458 {
459 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
460 	::osl::MutexGuard aGuard( m_aMutex );
461 
462 	::rtl::OUString sText( implGetText() );
463     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
464         throw IndexOutOfBoundsException();
465 
466 	return Sequence< PropertyValue >();
467 }
468 // -----------------------------------------------------------------------------
469 awt::Rectangle SAL_CALL VCLXAccessibleListItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
470 {
471 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
472 	::osl::MutexGuard aGuard( m_aMutex );
473 
474 	::rtl::OUString sText( implGetText() );
475     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
476         throw IndexOutOfBoundsException();
477 
478 	awt::Rectangle aBounds( 0, 0, 0, 0 );
479 	if ( m_pListBoxHelper )
480 	{
481 		Rectangle aCharRect = m_pListBoxHelper->GetEntryCharacterBounds( m_nIndexInParent, nIndex );
482 		Rectangle aItemRect = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent );
483 		aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
484 		aBounds = AWTRectangle( aCharRect );
485 	}
486 
487 	return aBounds;
488 }
489 // -----------------------------------------------------------------------------
490 sal_Int32 SAL_CALL VCLXAccessibleListItem::getCharacterCount() throw (RuntimeException)
491 {
492 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
493 	::osl::MutexGuard aGuard( m_aMutex );
494 
495 	return OCommonAccessibleText::getCharacterCount();
496 }
497 // -----------------------------------------------------------------------------
498 sal_Int32 SAL_CALL VCLXAccessibleListItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
499 {
500 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
501 	::osl::MutexGuard aGuard( m_aMutex );
502 
503 	sal_Int32 nIndex = -1;
504 	if ( m_pListBoxHelper )
505 	{
506         sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
507         Rectangle aItemRect = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent );
508 		Point aPnt( VCLPoint( aPoint ) );
509 		aPnt += aItemRect.TopLeft();
510         sal_Int32 nI = m_pListBoxHelper->GetIndexForPoint( aPnt, nPos );
511         if ( nI != -1 && (sal_uInt16)m_nIndexInParent == nPos )
512             nIndex = nI;
513 	}
514     return nIndex;
515 }
516 // -----------------------------------------------------------------------------
517 ::rtl::OUString SAL_CALL VCLXAccessibleListItem::getSelectedText() throw (RuntimeException)
518 {
519 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
520 	::osl::MutexGuard aGuard( m_aMutex );
521 
522 	return OCommonAccessibleText::getSelectedText();
523 }
524 // -----------------------------------------------------------------------------
525 sal_Int32 SAL_CALL VCLXAccessibleListItem::getSelectionStart() throw (RuntimeException)
526 {
527 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
528 	::osl::MutexGuard aGuard( m_aMutex );
529 
530 	return OCommonAccessibleText::getSelectionStart();
531 }
532 // -----------------------------------------------------------------------------
533 sal_Int32 SAL_CALL VCLXAccessibleListItem::getSelectionEnd() throw (RuntimeException)
534 {
535 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
536 	::osl::MutexGuard aGuard( m_aMutex );
537 
538 	return OCommonAccessibleText::getSelectionEnd();
539 }
540 // -----------------------------------------------------------------------------
541 sal_Bool SAL_CALL VCLXAccessibleListItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
542 {
543 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
544 	::osl::MutexGuard aGuard( m_aMutex );
545 
546     if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
547         throw IndexOutOfBoundsException();
548 
549 	return sal_False;
550 }
551 // -----------------------------------------------------------------------------
552 ::rtl::OUString SAL_CALL VCLXAccessibleListItem::getText() throw (RuntimeException)
553 {
554 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
555 	::osl::MutexGuard aGuard( m_aMutex );
556 
557 	return OCommonAccessibleText::getText();
558 }
559 // -----------------------------------------------------------------------------
560 ::rtl::OUString SAL_CALL VCLXAccessibleListItem::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
561 {
562 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
563 	::osl::MutexGuard aGuard( m_aMutex );
564 
565 	return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
566 }
567 // -----------------------------------------------------------------------------
568 ::com::sun::star::accessibility::TextSegment SAL_CALL VCLXAccessibleListItem::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
569 {
570 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
571 	::osl::MutexGuard aGuard( m_aMutex );
572 
573 	return OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
574 }
575 // -----------------------------------------------------------------------------
576 ::com::sun::star::accessibility::TextSegment SAL_CALL VCLXAccessibleListItem::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
577 {
578 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
579 	::osl::MutexGuard aGuard( m_aMutex );
580 
581 	return OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
582 }
583 // -----------------------------------------------------------------------------
584 ::com::sun::star::accessibility::TextSegment SAL_CALL VCLXAccessibleListItem::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
585 {
586 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
587 	::osl::MutexGuard aGuard( m_aMutex );
588 
589 	return OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
590 }
591 // -----------------------------------------------------------------------------
592 sal_Bool SAL_CALL VCLXAccessibleListItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
593 {
594 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
595 	::osl::MutexGuard aGuard( m_aMutex );
596 
597 	checkIndex_Impl( nStartIndex, m_sEntryText );
598 	checkIndex_Impl( nEndIndex, m_sEntryText );
599 
600 	sal_Bool bRet = sal_False;
601 	if ( m_pListBoxHelper )
602 	{
603 		Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pListBoxHelper->GetClipboard();
604 		if ( xClipboard.is() )
605 		{
606 			::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) );
607 			::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
608 
609 			const sal_uInt32 nRef = Application::ReleaseSolarMutex();
610 			xClipboard->setContents( pDataObj, NULL );
611 			Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
612 			if( xFlushableClipboard.is() )
613 				xFlushableClipboard->flushClipboard();
614 			Application::AcquireSolarMutex( nRef );
615 
616 			bRet = sal_True;
617 		}
618 	}
619 
620     return bRet;
621 }
622 // -----------------------------------------------------------------------------
623 // XAccessibleEventBroadcaster
624 // -----------------------------------------------------------------------------
625 void SAL_CALL VCLXAccessibleListItem::addEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
626 {
627 	if (xListener.is())
628     {
629 		if (!m_nClientId)
630             m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
631 		comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener );
632     }
633 }
634 // -----------------------------------------------------------------------------
635 void SAL_CALL VCLXAccessibleListItem::removeEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
636 {
637 	if ( xListener.is() && m_nClientId )
638 	{
639         sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener );
640 		if ( !nListenerCount )
641 		{
642 			// no listeners anymore
643 			// -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
644 			// and at least to us not firing any events anymore, in case somebody calls
645 			// NotifyAccessibleEvent, again
646 			if ( m_nClientId )
647 			{
648 				comphelper::AccessibleEventNotifier::TClientId nId( m_nClientId );
649 				m_nClientId = 0;
650 				comphelper::AccessibleEventNotifier::revokeClient( nId );
651 			}
652 		}
653 	}
654 }
655 // -----------------------------------------------------------------------------
656 
657 
658 
659 // AF (Oct. 29 2002): Return black as constant foreground color.  This is an
660 // initial implementation and has to be substituted by code that determines
661 // the color that is actually used.
662 sal_Int32 SAL_CALL VCLXAccessibleListItem::getForeground (void)
663     throw (::com::sun::star::uno::RuntimeException)
664 {
665     return COL_BLACK;
666 }
667 
668 // AF (Oct. 29 2002): Return white as constant background color.  This is an
669 // initial implementation and has to be substituted by code that determines
670 // the color that is actually used.
671 sal_Int32 SAL_CALL VCLXAccessibleListItem::getBackground (void)
672     throw (::com::sun::star::uno::RuntimeException)
673 {
674     return COL_WHITE;
675 }
676 // -----------------------------------------------------------------------------
677