xref: /AOO41X/main/accessibility/source/standard/vclxaccessiblelistitem.cxx (revision 4d7c9de063a797b8b4f3d45e3561e82ad1f8ef1f)
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 {
checkIndex_Impl(sal_Int32 _nIndex,const::rtl::OUString & _sText)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 
DBG_NAME(VCLXAccessibleListItem)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 // -----------------------------------------------------------------------------
~VCLXAccessibleListItem()92 VCLXAccessibleListItem::~VCLXAccessibleListItem()
93 {
94     DBG_DTOR( VCLXAccessibleListItem, NULL );
95 }
96 // -----------------------------------------------------------------------------
SetSelected(sal_Bool _bSelected)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 // -----------------------------------------------------------------------------
SetVisible(sal_Bool _bVisible)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 // -----------------------------------------------------------------------------
NotifyAccessibleEvent(sal_Int16 _nEventId,const::com::sun::star::uno::Any & _aOldValue,const::com::sun::star::uno::Any & _aNewValue)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 // -----------------------------------------------------------------------------
implGetText()141 ::rtl::OUString VCLXAccessibleListItem::implGetText()
142 {
143     return m_sEntryText;
144 }
145 // -----------------------------------------------------------------------------
implGetLocale()146 Locale VCLXAccessibleListItem::implGetLocale()
147 {
148     return Application::GetSettings().GetLocale();
149 }
150 // -----------------------------------------------------------------------------
implGetSelection(sal_Int32 & nStartIndex,sal_Int32 & nEndIndex)151 void VCLXAccessibleListItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
152 {
153     nStartIndex = 0;
154     nEndIndex = 0;
155 }
156 // -----------------------------------------------------------------------------
157 // XInterface
158 // -----------------------------------------------------------------------------
queryInterface(Type const & rType)159 Any SAL_CALL VCLXAccessibleListItem::queryInterface( Type const & rType ) throw (RuntimeException)
160 {
161     return VCLXAccessibleListItem_BASE::queryInterface( rType );
162 }
163 // -----------------------------------------------------------------------------
acquire()164 void SAL_CALL VCLXAccessibleListItem::acquire() throw ()
165 {
166     VCLXAccessibleListItem_BASE::acquire();
167 }
168 // -----------------------------------------------------------------------------
release()169 void SAL_CALL VCLXAccessibleListItem::release() throw ()
170 {
171     VCLXAccessibleListItem_BASE::release();
172 }
173 // -----------------------------------------------------------------------------
174 // XTypeProvider
175 // -----------------------------------------------------------------------------
getTypes()176 Sequence< Type > SAL_CALL VCLXAccessibleListItem::getTypes(  ) throw (RuntimeException)
177 {
178     return VCLXAccessibleListItem_BASE::getTypes();
179 }
180 // -----------------------------------------------------------------------------
getImplementationId()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 // -----------------------------------------------------------------------------
disposing()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 // -----------------------------------------------------------------------------
getImplementationName()226 ::rtl::OUString VCLXAccessibleListItem::getImplementationName() throw (RuntimeException)
227 {
228     return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleListItem" );
229 }
230 // -----------------------------------------------------------------------------
supportsService(const::rtl::OUString & rServiceName)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 // -----------------------------------------------------------------------------
getSupportedServiceNames()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 // -----------------------------------------------------------------------------
getAccessibleContext()253 Reference< XAccessibleContext > SAL_CALL VCLXAccessibleListItem::getAccessibleContext(  ) throw (RuntimeException)
254 {
255     return this;
256 }
257 // -----------------------------------------------------------------------------
258 // XAccessibleContext
259 // -----------------------------------------------------------------------------
getAccessibleChildCount()260 sal_Int32 SAL_CALL VCLXAccessibleListItem::getAccessibleChildCount(  ) throw (RuntimeException)
261 {
262     return 0;
263 }
264 // -----------------------------------------------------------------------------
getAccessibleChild(sal_Int32)265 Reference< XAccessible > SAL_CALL VCLXAccessibleListItem::getAccessibleChild( sal_Int32 ) throw (RuntimeException)
266 {
267     return Reference< XAccessible >();
268 }
269 // -----------------------------------------------------------------------------
getAccessibleParent()270 Reference< XAccessible > SAL_CALL VCLXAccessibleListItem::getAccessibleParent(  ) throw (RuntimeException)
271 {
272     ::osl::MutexGuard aGuard( m_aMutex );
273 
274     return m_xParent;
275 }
276 // -----------------------------------------------------------------------------
getAccessibleIndexInParent()277 sal_Int32 SAL_CALL VCLXAccessibleListItem::getAccessibleIndexInParent(  ) throw (RuntimeException)
278 {
279     ::osl::MutexGuard aGuard( m_aMutex );
280     return m_nIndexInParent;
281 }
282 // -----------------------------------------------------------------------------
getAccessibleRole()283 sal_Int16 SAL_CALL VCLXAccessibleListItem::getAccessibleRole(  ) throw (RuntimeException)
284 {
285     return AccessibleRole::LIST_ITEM;
286     //  return AccessibleRole::LABEL;
287 }
288 // -----------------------------------------------------------------------------
getAccessibleDescription()289 ::rtl::OUString SAL_CALL VCLXAccessibleListItem::getAccessibleDescription(  ) throw (RuntimeException)
290 {
291     // no description for every item
292     return ::rtl::OUString();
293 }
294 // -----------------------------------------------------------------------------
getAccessibleName()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 // -----------------------------------------------------------------------------
getAccessibleRelationSet()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 // -----------------------------------------------------------------------------
getAccessibleStateSet()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         if(m_pListBoxHelper->IsEnabled())
322         {
323             pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
324             pStateSetHelper->AddState( AccessibleStateType::ENABLED );
325             pStateSetHelper->AddState( AccessibleStateType::SENSITIVE );
326         }
327 
328         if ( m_bSelected )
329             pStateSetHelper->AddState( AccessibleStateType::SELECTED );
330         if ( m_bVisible )
331         {
332             pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
333             pStateSetHelper->AddState( AccessibleStateType::SHOWING );
334         }
335     }
336     else
337         pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
338 
339     return xStateSet;
340 }
341 // -----------------------------------------------------------------------------
getLocale()342 Locale SAL_CALL VCLXAccessibleListItem::getLocale(  ) throw (IllegalAccessibleComponentStateException, RuntimeException)
343 {
344     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
345     ::osl::MutexGuard aGuard( m_aMutex );
346 
347     return implGetLocale();
348 }
349 // -----------------------------------------------------------------------------
350 // XAccessibleComponent
351 // -----------------------------------------------------------------------------
containsPoint(const awt::Point & _aPoint)352 sal_Bool SAL_CALL VCLXAccessibleListItem::containsPoint( const awt::Point& _aPoint ) throw (RuntimeException)
353 {
354     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
355     ::osl::MutexGuard aGuard( m_aMutex );
356 
357     sal_Bool bInside = sal_False;
358     if ( m_pListBoxHelper )
359     {
360         Rectangle aRect( m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent ) );
361         aRect.Move(-aRect.TopLeft().X(),-aRect.TopLeft().Y());
362         bInside = aRect.IsInside( VCLPoint( _aPoint ) );
363     }
364     return bInside;
365 }
366 // -----------------------------------------------------------------------------
getAccessibleAtPoint(const awt::Point &)367 Reference< XAccessible > SAL_CALL VCLXAccessibleListItem::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
368 {
369     return Reference< XAccessible >();
370 }
371 // -----------------------------------------------------------------------------
getBounds()372 awt::Rectangle SAL_CALL VCLXAccessibleListItem::getBounds(  ) throw (RuntimeException)
373 {
374     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
375     ::osl::MutexGuard aGuard( m_aMutex );
376 
377     awt::Rectangle aRect;
378     if ( m_pListBoxHelper )
379         aRect = AWTRectangle( m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent ) );
380 
381     return aRect;
382 }
383 // -----------------------------------------------------------------------------
getLocation()384 awt::Point SAL_CALL VCLXAccessibleListItem::getLocation(  ) throw (RuntimeException)
385 {
386     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
387     ::osl::MutexGuard aGuard( m_aMutex );
388 
389     Point aPoint(0,0);
390     if ( m_pListBoxHelper )
391     {
392         Rectangle aRect = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent );
393         aPoint = aRect.TopLeft();
394     }
395     return AWTPoint( aPoint );
396 }
397 // -----------------------------------------------------------------------------
getLocationOnScreen()398 awt::Point SAL_CALL VCLXAccessibleListItem::getLocationOnScreen(  ) throw (RuntimeException)
399 {
400     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
401     ::osl::MutexGuard aGuard( m_aMutex );
402 
403     Point aPoint(0,0);
404     if ( m_pListBoxHelper )
405     {
406         Rectangle aRect = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent );
407         aPoint = aRect.TopLeft();
408         aPoint += m_pListBoxHelper->GetWindowExtentsRelative( NULL ).TopLeft();
409     }
410     return AWTPoint( aPoint );
411 }
412 // -----------------------------------------------------------------------------
getSize()413 awt::Size SAL_CALL VCLXAccessibleListItem::getSize(  ) throw (RuntimeException)
414 {
415     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
416     ::osl::MutexGuard aGuard( m_aMutex );
417 
418     Size aSize;
419     if ( m_pListBoxHelper )
420         aSize = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent ).GetSize();
421 
422     return AWTSize( aSize );
423 }
424 // -----------------------------------------------------------------------------
grabFocus()425 void SAL_CALL VCLXAccessibleListItem::grabFocus(  ) throw (RuntimeException)
426 {
427     // no focus for each item
428 }
429 // -----------------------------------------------------------------------------
430 // XAccessibleText
431 // -----------------------------------------------------------------------------
getCaretPosition()432 sal_Int32 SAL_CALL VCLXAccessibleListItem::getCaretPosition() throw (RuntimeException)
433 {
434     return -1;
435 }
436 // -----------------------------------------------------------------------------
setCaretPosition(sal_Int32 nIndex)437 sal_Bool SAL_CALL VCLXAccessibleListItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
438 {
439     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
440     ::osl::MutexGuard aGuard( m_aMutex );
441 
442     if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
443         throw IndexOutOfBoundsException();
444 
445     return sal_False;
446 }
447 // -----------------------------------------------------------------------------
getCharacter(sal_Int32 nIndex)448 sal_Unicode SAL_CALL VCLXAccessibleListItem::getCharacter( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
449 {
450     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
451     ::osl::MutexGuard aGuard( m_aMutex );
452 
453     return OCommonAccessibleText::getCharacter( nIndex );
454 }
455 // -----------------------------------------------------------------------------
getCharacterAttributes(sal_Int32 nIndex,const Sequence<::rtl::OUString> &)456 Sequence< PropertyValue > SAL_CALL VCLXAccessibleListItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& ) throw (IndexOutOfBoundsException, RuntimeException)
457 {
458     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
459     ::osl::MutexGuard aGuard( m_aMutex );
460 
461     ::rtl::OUString sText( implGetText() );
462     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
463         throw IndexOutOfBoundsException();
464 
465     return Sequence< PropertyValue >();
466 }
467 // -----------------------------------------------------------------------------
getCharacterBounds(sal_Int32 nIndex)468 awt::Rectangle SAL_CALL VCLXAccessibleListItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
469 {
470     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
471     ::osl::MutexGuard aGuard( m_aMutex );
472 
473     ::rtl::OUString sText( implGetText() );
474     if ( !implIsValidIndex( nIndex, sText.getLength() ) )
475         throw IndexOutOfBoundsException();
476 
477     awt::Rectangle aBounds( 0, 0, 0, 0 );
478     if ( m_pListBoxHelper )
479     {
480         Rectangle aCharRect = m_pListBoxHelper->GetEntryCharacterBounds( m_nIndexInParent, nIndex );
481         Rectangle aItemRect = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent );
482         aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
483         aBounds = AWTRectangle( aCharRect );
484     }
485 
486     return aBounds;
487 }
488 // -----------------------------------------------------------------------------
getCharacterCount()489 sal_Int32 SAL_CALL VCLXAccessibleListItem::getCharacterCount() throw (RuntimeException)
490 {
491     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
492     ::osl::MutexGuard aGuard( m_aMutex );
493 
494     return OCommonAccessibleText::getCharacterCount();
495 }
496 // -----------------------------------------------------------------------------
getIndexAtPoint(const awt::Point & aPoint)497 sal_Int32 SAL_CALL VCLXAccessibleListItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
498 {
499     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
500     ::osl::MutexGuard aGuard( m_aMutex );
501 
502     sal_Int32 nIndex = -1;
503     if ( m_pListBoxHelper )
504     {
505         sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
506         Rectangle aItemRect = m_pListBoxHelper->GetBoundingRectangle( (sal_uInt16)m_nIndexInParent );
507         Point aPnt( VCLPoint( aPoint ) );
508         aPnt += aItemRect.TopLeft();
509         sal_Int32 nI = m_pListBoxHelper->GetIndexForPoint( aPnt, nPos );
510         if ( nI != -1 && (sal_uInt16)m_nIndexInParent == nPos )
511             nIndex = nI;
512     }
513     return nIndex;
514 }
515 // -----------------------------------------------------------------------------
getSelectedText()516 ::rtl::OUString SAL_CALL VCLXAccessibleListItem::getSelectedText() throw (RuntimeException)
517 {
518     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
519     ::osl::MutexGuard aGuard( m_aMutex );
520 
521     return OCommonAccessibleText::getSelectedText();
522 }
523 // -----------------------------------------------------------------------------
getSelectionStart()524 sal_Int32 SAL_CALL VCLXAccessibleListItem::getSelectionStart() throw (RuntimeException)
525 {
526     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
527     ::osl::MutexGuard aGuard( m_aMutex );
528 
529     return OCommonAccessibleText::getSelectionStart();
530 }
531 // -----------------------------------------------------------------------------
getSelectionEnd()532 sal_Int32 SAL_CALL VCLXAccessibleListItem::getSelectionEnd() throw (RuntimeException)
533 {
534     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
535     ::osl::MutexGuard aGuard( m_aMutex );
536 
537     return OCommonAccessibleText::getSelectionEnd();
538 }
539 // -----------------------------------------------------------------------------
setSelection(sal_Int32 nStartIndex,sal_Int32 nEndIndex)540 sal_Bool SAL_CALL VCLXAccessibleListItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
541 {
542     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
543     ::osl::MutexGuard aGuard( m_aMutex );
544 
545     if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
546         throw IndexOutOfBoundsException();
547 
548     return sal_False;
549 }
550 // -----------------------------------------------------------------------------
getText()551 ::rtl::OUString SAL_CALL VCLXAccessibleListItem::getText() throw (RuntimeException)
552 {
553     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
554     ::osl::MutexGuard aGuard( m_aMutex );
555 
556     return OCommonAccessibleText::getText();
557 }
558 // -----------------------------------------------------------------------------
getTextRange(sal_Int32 nStartIndex,sal_Int32 nEndIndex)559 ::rtl::OUString SAL_CALL VCLXAccessibleListItem::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
560 {
561     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
562     ::osl::MutexGuard aGuard( m_aMutex );
563 
564     return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex );
565 }
566 // -----------------------------------------------------------------------------
getTextAtIndex(sal_Int32 nIndex,sal_Int16 aTextType)567 ::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)
568 {
569     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
570     ::osl::MutexGuard aGuard( m_aMutex );
571 
572     return OCommonAccessibleText::getTextAtIndex( nIndex, aTextType );
573 }
574 // -----------------------------------------------------------------------------
getTextBeforeIndex(sal_Int32 nIndex,sal_Int16 aTextType)575 ::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)
576 {
577     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
578     ::osl::MutexGuard aGuard( m_aMutex );
579 
580     return OCommonAccessibleText::getTextBeforeIndex( nIndex, aTextType );
581 }
582 // -----------------------------------------------------------------------------
getTextBehindIndex(sal_Int32 nIndex,sal_Int16 aTextType)583 ::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)
584 {
585     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
586     ::osl::MutexGuard aGuard( m_aMutex );
587 
588     return OCommonAccessibleText::getTextBehindIndex( nIndex, aTextType );
589 }
590 // -----------------------------------------------------------------------------
copyText(sal_Int32 nStartIndex,sal_Int32 nEndIndex)591 sal_Bool SAL_CALL VCLXAccessibleListItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
592 {
593     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
594     ::osl::MutexGuard aGuard( m_aMutex );
595 
596     checkIndex_Impl( nStartIndex, m_sEntryText );
597     checkIndex_Impl( nEndIndex, m_sEntryText );
598 
599     sal_Bool bRet = sal_False;
600     if ( m_pListBoxHelper )
601     {
602         Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pListBoxHelper->GetClipboard();
603         if ( xClipboard.is() )
604         {
605             ::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) );
606             ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
607 
608             const sal_uInt32 nRef = Application::ReleaseSolarMutex();
609             xClipboard->setContents( pDataObj, NULL );
610             Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
611             if( xFlushableClipboard.is() )
612                 xFlushableClipboard->flushClipboard();
613             Application::AcquireSolarMutex( nRef );
614 
615             bRet = sal_True;
616         }
617     }
618 
619     return bRet;
620 }
621 // -----------------------------------------------------------------------------
622 // XAccessibleEventBroadcaster
623 // -----------------------------------------------------------------------------
addEventListener(const Reference<XAccessibleEventListener> & xListener)624 void SAL_CALL VCLXAccessibleListItem::addEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
625 {
626     if (xListener.is())
627     {
628         if (!m_nClientId)
629             m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
630         comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener );
631     }
632 }
633 // -----------------------------------------------------------------------------
removeEventListener(const Reference<XAccessibleEventListener> & xListener)634 void SAL_CALL VCLXAccessibleListItem::removeEventListener( const Reference< XAccessibleEventListener >& xListener ) throw (RuntimeException)
635 {
636     if ( xListener.is() && m_nClientId )
637     {
638         sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener );
639         if ( !nListenerCount )
640         {
641             // no listeners anymore
642             // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
643             // and at least to us not firing any events anymore, in case somebody calls
644             // NotifyAccessibleEvent, again
645             if ( m_nClientId )
646             {
647                 comphelper::AccessibleEventNotifier::TClientId nId( m_nClientId );
648                 m_nClientId = 0;
649                 comphelper::AccessibleEventNotifier::revokeClient( nId );
650             }
651         }
652     }
653 }
654 // -----------------------------------------------------------------------------
655 
656 
657 
658 // AF (Oct. 29 2002): Return black as constant foreground color.  This is an
659 // initial implementation and has to be substituted by code that determines
660 // the color that is actually used.
getForeground(void)661 sal_Int32 SAL_CALL VCLXAccessibleListItem::getForeground (void)
662     throw (::com::sun::star::uno::RuntimeException)
663 {
664     return COL_BLACK;
665 }
666 
667 // AF (Oct. 29 2002): Return white as constant background color.  This is an
668 // initial implementation and has to be substituted by code that determines
669 // the color that is actually used.
getBackground(void)670 sal_Int32 SAL_CALL VCLXAccessibleListItem::getBackground (void)
671     throw (::com::sun::star::uno::RuntimeException)
672 {
673     return COL_WHITE;
674 }
675 // -----------------------------------------------------------------------------
676