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