1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessiblelist.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
33 #include <accessibility/standard/vclxaccessiblelist.hxx>
34 #include <accessibility/standard/vclxaccessiblelistitem.hxx>
35 #include <accessibility/helper/listboxhelper.hxx>
37 #include <unotools/accessiblestatesethelper.hxx>
38 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
40 #include <com/sun/star/accessibility/AccessibleRole.hpp>
41 #include <vcl/svapp.hxx>
42 #include <vcl/combobox.hxx>
43 #include <vcl/lstbox.hxx>
44 #include <toolkit/helper/convert.hxx>
46 using namespace ::com::sun::star
;
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::lang
;
49 using namespace ::com::sun::star::beans
;
50 using namespace ::com::sun::star::accessibility
;
51 using namespace ::accessibility
;
55 void checkSelection_Impl( sal_Int32 _nIndex
, const IComboListBoxHelper
& _rListBox
, sal_Bool bSelected
)
56 throw (::com::sun::star::lang::IndexOutOfBoundsException
)
58 sal_Int32 nCount
= bSelected
? (sal_Int32
)_rListBox
.GetSelectEntryCount()
59 : (sal_Int32
)_rListBox
.GetEntryCount();
60 if ( _nIndex
< 0 || _nIndex
>= nCount
)
61 throw ::com::sun::star::lang::IndexOutOfBoundsException();
65 VCLXAccessibleList::VCLXAccessibleList (VCLXWindow
* pVCLWindow
, BoxType aBoxType
,
66 const Reference
< XAccessible
>& _xParent
)
67 : VCLXAccessibleComponent (pVCLWindow
),
68 m_aBoxType (aBoxType
),
69 m_nVisibleLineCount (0),
70 m_nIndexInParent (DEFAULT_INDEX_IN_PARENT
),
71 m_nLastTopEntry ( 0 ),
72 m_nLastSelectedPos ( LISTBOX_ENTRY_NOTFOUND
),
73 m_bDisableProcessEvent ( false ),
75 m_xParent ( _xParent
)
77 // Because combo boxes and list boxes have the no common interface for
78 // methods with identical signature we have to write down twice the
84 ComboBox
* pBox
= static_cast<ComboBox
*>(GetWindow());
86 m_pListBoxHelper
= new VCLListBoxHelper
<ComboBox
> (*pBox
);
92 ListBox
* pBox
= static_cast<ListBox
*>(GetWindow());
94 m_pListBoxHelper
= new VCLListBoxHelper
<ListBox
> (*pBox
);
98 UpdateVisibleLineCount();
100 USHORT nCount
= static_cast<USHORT
>(getAccessibleChildCount());
101 m_aAccessibleChildren
.reserve(nCount
);
103 // -----------------------------------------------------------------------------
105 VCLXAccessibleList::~VCLXAccessibleList (void)
107 delete m_pListBoxHelper
;
109 // -----------------------------------------------------------------------------
111 void VCLXAccessibleList::SetIndexInParent (sal_Int32 nIndex
)
113 m_nIndexInParent
= nIndex
;
115 // -----------------------------------------------------------------------------
117 void SAL_CALL
VCLXAccessibleList::disposing (void)
119 VCLXAccessibleComponent::disposing();
121 // Dispose all items in the list.
124 delete m_pListBoxHelper
;
125 m_pListBoxHelper
= NULL
;
127 // -----------------------------------------------------------------------------
129 void VCLXAccessibleList::clearItems()
131 // ListItems::iterator aEnd = m_aAccessibleChildren.end();
132 // for (ListItems::iterator aIter = m_aAccessibleChildren.begin(); aIter != aEnd; ++aIter)
133 // ::comphelper::disposeComponent(*aIter);
135 // Clear the list itself and delete all the rest.
136 ListItems().swap(m_aAccessibleChildren
); // clear and minimize
138 // -----------------------------------------------------------------------------
140 void VCLXAccessibleList::FillAccessibleStateSet (utl::AccessibleStateSetHelper
& rStateSet
)
142 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
144 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
145 // check if our list should be visible
146 if ( m_pListBoxHelper
147 && (m_pListBoxHelper
->GetStyle() & WB_DROPDOWN
) == WB_DROPDOWN
148 && !m_pListBoxHelper
->IsInDropDown() )
150 rStateSet
.RemoveState (AccessibleStateType::VISIBLE
);
151 rStateSet
.RemoveState (AccessibleStateType::SHOWING
);
155 // Both the combo box and list box are handled identical in the
156 // following but for some reason they don't have a common interface for
158 if ( m_pListBoxHelper
)
160 if ( m_pListBoxHelper
->IsMultiSelectionEnabled() )
161 rStateSet
.AddState( AccessibleStateType::MULTI_SELECTABLE
);
162 rStateSet
.AddState (AccessibleStateType::FOCUSABLE
);
163 // All children are transient.
164 rStateSet
.AddState (AccessibleStateType::MANAGES_DESCENDANTS
);
167 // -----------------------------------------------------------------------------
168 void VCLXAccessibleList::notifyVisibleStates(sal_Bool _bSetNew
)
170 m_bVisible
= _bSetNew
? true : false;
171 Any aOldValue
, aNewValue
;
172 (_bSetNew
? aNewValue
: aOldValue
) <<= AccessibleStateType::VISIBLE
;
173 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
174 (_bSetNew
? aNewValue
: aOldValue
) <<= AccessibleStateType::SHOWING
;
175 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED
, aOldValue
, aNewValue
);
177 ListItems::iterator aIter
= m_aAccessibleChildren
.begin();
178 ListItems::iterator aEnd
= m_aAccessibleChildren
.end();
179 UpdateVisibleLineCount();
180 // adjust the index inside the VCLXAccessibleListItem
181 for (;aIter
!= aEnd
; ++aIter
)
183 Reference
< XAccessible
> xHold
= *aIter
;
184 VCLXAccessibleListItem
* pItem
= static_cast<VCLXAccessibleListItem
*>(xHold
.get());
187 USHORT nTopEntry
= 0;
188 if ( m_pListBoxHelper
)
189 nTopEntry
= m_pListBoxHelper
->GetTopEntry();
190 USHORT nPos
= (USHORT
)(aIter
- m_aAccessibleChildren
.begin());
191 sal_Bool bVisible
= ( nPos
>=nTopEntry
&& nPos
<( nTopEntry
+ m_nVisibleLineCount
) );
192 pItem
->SetVisible( m_bVisible
&& bVisible
);
197 // -----------------------------------------------------------------------------
198 void VCLXAccessibleList::ProcessWindowEvent (const VclWindowEvent
& rVclWindowEvent
)
200 // Create a reference to this object to prevent an early release of the
201 // listbox (VCLEVENT_OBJECT_DYING).
202 Reference
< XAccessible
> xTemp
= this;
204 switch ( rVclWindowEvent
.GetId() )
206 case VCLEVENT_DROPDOWN_OPEN
:
207 notifyVisibleStates(sal_True
);
209 case VCLEVENT_DROPDOWN_CLOSE
:
210 notifyVisibleStates(sal_False
);
212 case VCLEVENT_LISTBOX_SCROLLED
:
213 case VCLEVENT_COMBOBOX_SCROLLED
:
214 UpdateEntryRange_Impl();
217 case VCLEVENT_LISTBOX_SELECT
:
218 if ( !m_bDisableProcessEvent
)
219 UpdateSelection_Impl();
221 // The selection events VCLEVENT_COMBOBOX_SELECT and
222 // VCLEVENT_COMBOBOX_DESELECT are not handled here because here we
223 // have no access to the edit field. Its text is necessary to
224 // identify the currently selected item.
226 case VCLEVENT_OBJECT_DYING
:
230 VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent
);
234 case VCLEVENT_LISTBOX_ITEMREMOVED
:
235 case VCLEVENT_COMBOBOX_ITEMREMOVED
:
236 HandleChangedItemList (false, reinterpret_cast<sal_IntPtr
>(
237 rVclWindowEvent
.GetData()));
240 case VCLEVENT_LISTBOX_ITEMADDED
:
241 case VCLEVENT_COMBOBOX_ITEMADDED
:
242 HandleChangedItemList (true, reinterpret_cast<sal_IntPtr
>(
243 rVclWindowEvent
.GetData()));
245 case VCLEVENT_CONTROL_GETFOCUS
:
246 VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent
);
247 if ( m_pListBoxHelper
)
251 USHORT nPos
= m_pListBoxHelper
->GetSelectEntryPos();
252 if ( nPos
== LISTBOX_ENTRY_NOTFOUND
)
253 nPos
= m_pListBoxHelper
->GetTopEntry();
254 if ( nPos
!= LISTBOX_ENTRY_NOTFOUND
)
255 aNewValue
<<= CreateChild(nPos
);
257 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
,
264 VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent
);
267 // -----------------------------------------------------------------------------
269 /** To find out which item is currently selected and to update the SELECTED
270 state of the associated accessibility objects accordingly we exploit the
273 void VCLXAccessibleList::UpdateSelection (::rtl::OUString sTextOfSelectedItem
)
275 if ( m_aBoxType
== COMBOBOX
)
277 ComboBox
* pBox
= static_cast<ComboBox
*>(GetWindow());
280 // Find the index of the selected item inside the VCL control...
281 USHORT nIndex
= pBox
->GetEntryPos (XubString(sTextOfSelectedItem
));
282 // ...and then find the associated accessibility object.
283 if ( nIndex
== LISTBOX_ENTRY_NOTFOUND
)
285 UpdateSelection_Impl(nIndex
);
289 // -----------------------------------------------------------------------------
291 void VCLXAccessibleList::adjustEntriesIndexInParent(ListItems::iterator
& _aBegin
,::std::mem_fun_t
<bool,VCLXAccessibleListItem
>& _rMemFun
)
293 ListItems::iterator aIter
= _aBegin
;
294 ListItems::iterator aEnd
= m_aAccessibleChildren
.end();
295 // adjust the index inside the VCLXAccessibleListItem
296 for (;aIter
!= aEnd
; ++aIter
)
298 Reference
< XAccessible
> xHold
= *aIter
;
299 VCLXAccessibleListItem
* pItem
= static_cast<VCLXAccessibleListItem
*>(xHold
.get());
304 // -----------------------------------------------------------------------------
306 Reference
<XAccessible
> VCLXAccessibleList::CreateChild (sal_Int32 i
)
308 Reference
<XAccessible
> xChild
;
310 USHORT nPos
= static_cast<USHORT
>(i
);
311 if ( nPos
>= m_aAccessibleChildren
.size() )
313 m_aAccessibleChildren
.resize(nPos
+ 1);
315 // insert into the container
316 xChild
= new VCLXAccessibleListItem(m_pListBoxHelper
, i
, this);
317 m_aAccessibleChildren
[nPos
] = xChild
;
321 xChild
= m_aAccessibleChildren
[nPos
];
322 // check if position is empty and can be used else we have to adjust all entries behind this
325 ListItems::iterator aIter
= m_aAccessibleChildren
.begin() + nPos
;
326 ::std::mem_fun_t
<bool, VCLXAccessibleListItem
> aTemp(&VCLXAccessibleListItem::IncrementIndexInParent
);
327 adjustEntriesIndexInParent( aIter
, aTemp
);
331 xChild
= new VCLXAccessibleListItem(m_pListBoxHelper
, i
, this);
332 m_aAccessibleChildren
[nPos
] = xChild
;
338 // Just add the SELECTED state.
339 BOOL bNowSelected
= FALSE
;
340 if ( m_pListBoxHelper
)
341 bNowSelected
= m_pListBoxHelper
->IsEntryPosSelected ((USHORT
)i
);
342 VCLXAccessibleListItem
* pItem
= static_cast< VCLXAccessibleListItem
* >(xChild
.get());
343 pItem
->SetSelected( bNowSelected
);
345 // Set the child's VISIBLE state.
346 UpdateVisibleLineCount();
347 USHORT nTopEntry
= 0;
348 if ( m_pListBoxHelper
)
349 nTopEntry
= m_pListBoxHelper
->GetTopEntry();
350 sal_Bool bVisible
= ( nPos
>=nTopEntry
&& nPos
<( nTopEntry
+ m_nVisibleLineCount
) );
351 pItem
->SetVisible( m_bVisible
&& bVisible
);
356 // -----------------------------------------------------------------------------
358 void VCLXAccessibleList::HandleChangedItemList (bool bItemInserted
, sal_Int32 nIndex
)
360 if ( !bItemInserted
)
362 if ( nIndex
== -1 ) // special handling here
368 if ( nIndex
>= 0 && static_cast<USHORT
>(nIndex
) < m_aAccessibleChildren
.size() )
370 ListItems::iterator aIter
= m_aAccessibleChildren
.erase(m_aAccessibleChildren
.begin()+nIndex
);
371 ::std::mem_fun_t
<bool, VCLXAccessibleListItem
> aTemp(&VCLXAccessibleListItem::DecrementIndexInParent
);
372 adjustEntriesIndexInParent( aIter
, aTemp
);
377 getAccessibleChild(nIndex
);
379 NotifyAccessibleEvent (
380 AccessibleEventId::INVALIDATE_ALL_CHILDREN
,
383 // -----------------------------------------------------------------------------
385 IMPLEMENT_FORWARD_XINTERFACE2(VCLXAccessibleList
, VCLXAccessibleComponent
, VCLXAccessibleList_BASE
)
386 IMPLEMENT_FORWARD_XTYPEPROVIDER2(VCLXAccessibleList
, VCLXAccessibleComponent
, VCLXAccessibleList_BASE
)
388 //===== XAccessible =========================================================
390 Reference
<XAccessibleContext
> SAL_CALL
391 VCLXAccessibleList::getAccessibleContext (void)
392 throw (RuntimeException
)
396 // -----------------------------------------------------------------------------
398 //===== XAccessibleContext ==================================================
400 sal_Int32 SAL_CALL
VCLXAccessibleList::getAccessibleChildCount (void)
401 throw (RuntimeException
)
403 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
404 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
406 sal_Int32 nCount
= 0;
407 if ( m_pListBoxHelper
)
408 nCount
= m_pListBoxHelper
->GetEntryCount();
412 // -----------------------------------------------------------------------------
414 Reference
<XAccessible
> SAL_CALL
VCLXAccessibleList::getAccessibleChild (sal_Int32 i
)
415 throw (IndexOutOfBoundsException
, RuntimeException
)
417 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
418 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
420 if ( i
< 0 || i
>= getAccessibleChildCount() )
421 throw IndexOutOfBoundsException();
423 Reference
< XAccessible
> xChild
;
424 // search for the child
425 if ( static_cast<USHORT
>(i
) >= m_aAccessibleChildren
.size() )
426 xChild
= CreateChild (i
);
429 xChild
= m_aAccessibleChildren
[i
];
431 xChild
= CreateChild (i
);
433 OSL_ENSURE( xChild
.is(), "VCLXAccessibleList::getAccessibleChild: returning empty child!" );
436 // -----------------------------------------------------------------------------
438 Reference
< XAccessible
> SAL_CALL
VCLXAccessibleList::getAccessibleParent( )
439 throw (RuntimeException
)
441 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
445 // -----------------------------------------------------------------------------
447 sal_Int32 SAL_CALL
VCLXAccessibleList::getAccessibleIndexInParent (void)
448 throw (::com::sun::star::uno::RuntimeException
)
450 if (m_nIndexInParent
!= DEFAULT_INDEX_IN_PARENT
)
451 return m_nIndexInParent
;
453 return VCLXAccessibleComponent::getAccessibleIndexInParent();
455 // -----------------------------------------------------------------------------
457 sal_Int16 SAL_CALL
VCLXAccessibleList::getAccessibleRole (void)
458 throw (RuntimeException
)
460 return AccessibleRole::LIST
;
462 // -----------------------------------------------------------------------------
464 //===== XAccessibleComponent ================================================
466 sal_Bool SAL_CALL
VCLXAccessibleList::contains( const awt::Point
& rPoint
) throw (RuntimeException
)
468 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
469 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
471 sal_Bool bInside
= sal_False
;
473 Window
* pListBox
= GetWindow();
476 Rectangle
aRect( Point(0,0), pListBox
->GetSizePixel() );
477 bInside
= aRect
.IsInside( VCLPoint( rPoint
) );
482 // -----------------------------------------------------------------------------
484 Reference
< XAccessible
> SAL_CALL
VCLXAccessibleList::getAccessibleAt( const awt::Point
& rPoint
)
485 throw (RuntimeException
)
487 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
488 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
490 Reference
< XAccessible
> xChild
;
491 if ( m_pListBoxHelper
)
493 UpdateVisibleLineCount();
494 if ( contains( rPoint
) && m_nVisibleLineCount
> 0 )
496 Point aPos
= VCLPoint( rPoint
);
497 USHORT nEndPos
= m_pListBoxHelper
->GetTopEntry() + (USHORT
)m_nVisibleLineCount
;
498 for ( USHORT i
= m_pListBoxHelper
->GetTopEntry(); i
< nEndPos
; ++i
)
500 if ( m_pListBoxHelper
->GetBoundingRectangle(i
).IsInside( aPos
) )
502 xChild
= getAccessibleChild(i
);
511 // -----------------------------------------------------------------------------
513 //===== XServiceInfo ==========================================================
515 ::rtl::OUString
VCLXAccessibleList::getImplementationName (void)
516 throw (RuntimeException
)
518 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.toolkit.AccessibleList"));
520 // -----------------------------------------------------------------------------
522 Sequence
< ::rtl::OUString
> VCLXAccessibleList::getSupportedServiceNames (void)
523 throw (RuntimeException
)
525 Sequence
< ::rtl::OUString
> aNames
= VCLXAccessibleComponent::getSupportedServiceNames();
526 sal_Int32 nLength
= aNames
.getLength();
527 aNames
.realloc( nLength
+ 1 );
528 aNames
[nLength
] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleList"));
531 // -----------------------------------------------------------------------------
533 void VCLXAccessibleList::UpdateVisibleLineCount()
535 if ( m_pListBoxHelper
)
537 if ( (m_pListBoxHelper
->GetStyle() & WB_DROPDOWN
) == WB_DROPDOWN
)
538 m_nVisibleLineCount
= m_pListBoxHelper
->GetDisplayLineCount();
543 m_pListBoxHelper
->GetMaxVisColumnsAndLines (nCols
, nLines
);
544 m_nVisibleLineCount
= nLines
;
549 // -----------------------------------------------------------------------------
550 void VCLXAccessibleList::UpdateEntryRange_Impl()
552 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
553 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
555 sal_Int32 nTop
= m_nLastTopEntry
;
557 if ( m_pListBoxHelper
)
558 nTop
= m_pListBoxHelper
->GetTopEntry();
559 if ( nTop
!= m_nLastTopEntry
)
561 UpdateVisibleLineCount();
562 sal_Int32 nBegin
= Min( m_nLastTopEntry
, nTop
);
563 sal_Int32 nEnd
= Max( m_nLastTopEntry
+ m_nVisibleLineCount
, nTop
+ m_nVisibleLineCount
);
564 for (USHORT i
= static_cast<USHORT
>(nBegin
); (i
<= static_cast<USHORT
>(nEnd
)); ++i
)
566 sal_Bool bVisible
= ( i
>= nTop
&& i
< ( nTop
+ m_nVisibleLineCount
) );
567 Reference
< XAccessible
> xHold
;
568 if ( i
< m_aAccessibleChildren
.size() )
569 xHold
= m_aAccessibleChildren
[i
];
571 xHold
= CreateChild(i
);
574 static_cast< VCLXAccessibleListItem
* >( xHold
.get() )->SetVisible( m_bVisible
&& bVisible
);
578 m_nLastTopEntry
= nTop
;
580 // -----------------------------------------------------------------------------
581 BOOL
VCLXAccessibleList::checkEntrySelected(USHORT _nPos
,Any
& _rNewValue
,Reference
< XAccessible
>& _rxNewAcc
)
583 OSL_ENSURE(m_pListBoxHelper
,"Helper is not valid!");
584 BOOL bNowSelected
= FALSE
;
585 if ( m_pListBoxHelper
)
587 bNowSelected
= m_pListBoxHelper
->IsEntryPosSelected (_nPos
);
590 _rxNewAcc
= CreateChild(_nPos
);
591 _rNewValue
<<= _rxNewAcc
;
596 // -----------------------------------------------------------------------------
598 void VCLXAccessibleList::UpdateSelection_Impl(USHORT
)
600 uno::Any aOldValue
, aNewValue
;
603 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
604 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
605 Reference
< XAccessible
> xNewAcc
;
607 if ( m_pListBoxHelper
)
610 for ( ListItems::iterator aIter
= m_aAccessibleChildren
.begin();
611 aIter
!= m_aAccessibleChildren
.end(); ++aIter
,++i
)
613 Reference
< XAccessible
> xHold
= *aIter
;
616 VCLXAccessibleListItem
* pItem
= static_cast< VCLXAccessibleListItem
* >( xHold
.get() );
617 // Retrieve the item's index from the list entry.
618 BOOL bNowSelected
= m_pListBoxHelper
->IsEntryPosSelected (i
);
620 if ( bNowSelected
&& !pItem
->IsSelected() )
623 aNewValue
<<= xNewAcc
;
625 else if ( pItem
->IsSelected() )
626 m_nLastSelectedPos
= i
;
628 pItem
->SetSelected( bNowSelected
);
631 { // it could happen that a child was not created before
632 checkEntrySelected(i
,aNewValue
,xNewAcc
);
635 USHORT nCount
= m_pListBoxHelper
->GetEntryCount();
636 if ( i
< nCount
) // here we have to check the if any other listbox entry is selected
638 for (; i
< nCount
&& !checkEntrySelected(i
,aNewValue
,xNewAcc
) ;++i
)
641 if ( xNewAcc
.is() && GetWindow()->HasFocus() )
643 if ( m_nLastSelectedPos
!= LISTBOX_ENTRY_NOTFOUND
)
644 aOldValue
<<= getAccessibleChild( (sal_Int32
)m_nLastSelectedPos
);
645 aNewValue
<<= xNewAcc
;
650 if ( aNewValue
.hasValue() || aOldValue
.hasValue() )
651 NotifyAccessibleEvent(
652 AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
,
656 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, Any(), Any() );
659 // -----------------------------------------------------------------------------
660 // XAccessibleSelection
661 // -----------------------------------------------------------------------------
662 void SAL_CALL
VCLXAccessibleList::selectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
664 sal_Bool bNotify
= sal_False
;
667 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
668 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
670 if ( m_pListBoxHelper
)
672 checkSelection_Impl(nChildIndex
,*m_pListBoxHelper
,sal_False
);
674 m_pListBoxHelper
->SelectEntryPos( (USHORT
)nChildIndex
, TRUE
);
675 // call the select handler, don't handle events in this time
676 m_bDisableProcessEvent
= true;
677 m_pListBoxHelper
->Select();
678 m_bDisableProcessEvent
= false;
684 UpdateSelection_Impl();
686 // -----------------------------------------------------------------------------
687 sal_Bool SAL_CALL
VCLXAccessibleList::isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
689 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
690 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
692 sal_Bool bRet
= sal_False
;
693 if ( m_pListBoxHelper
)
695 checkSelection_Impl(nChildIndex
,*m_pListBoxHelper
,sal_False
);
697 bRet
= m_pListBoxHelper
->IsEntryPosSelected( (USHORT
)nChildIndex
);
701 // -----------------------------------------------------------------------------
702 void SAL_CALL
VCLXAccessibleList::clearAccessibleSelection( ) throw (RuntimeException
)
704 sal_Bool bNotify
= sal_False
;
707 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
708 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
710 if ( m_pListBoxHelper
)
712 m_pListBoxHelper
->SetNoSelection();
718 UpdateSelection_Impl();
720 // -----------------------------------------------------------------------------
721 void SAL_CALL
VCLXAccessibleList::selectAllAccessibleChildren( ) throw (RuntimeException
)
723 sal_Bool bNotify
= sal_False
;
726 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
727 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
729 if ( m_pListBoxHelper
)
731 USHORT nCount
= m_pListBoxHelper
->GetEntryCount();
732 for ( USHORT i
= 0; i
< nCount
; ++i
)
733 m_pListBoxHelper
->SelectEntryPos( i
, TRUE
);
734 // call the select handler, don't handle events in this time
735 m_bDisableProcessEvent
= true;
736 m_pListBoxHelper
->Select();
737 m_bDisableProcessEvent
= false;
743 UpdateSelection_Impl();
745 // -----------------------------------------------------------------------------
746 sal_Int32 SAL_CALL
VCLXAccessibleList::getSelectedAccessibleChildCount( ) throw (RuntimeException
)
748 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
749 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
751 sal_Int32 nCount
= 0;
752 if ( m_pListBoxHelper
)
753 nCount
= m_pListBoxHelper
->GetSelectEntryCount();
756 // -----------------------------------------------------------------------------
757 Reference
< XAccessible
> SAL_CALL
VCLXAccessibleList::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
759 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
760 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
762 if ( m_pListBoxHelper
)
764 checkSelection_Impl(nSelectedChildIndex
,*m_pListBoxHelper
,sal_True
);
765 return getAccessibleChild( (sal_Int32
)m_pListBoxHelper
->GetSelectEntryPos( (USHORT
)nSelectedChildIndex
) );
770 // -----------------------------------------------------------------------------
771 void SAL_CALL
VCLXAccessibleList::deselectAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
773 sal_Bool bNotify
= sal_False
;
776 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
777 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
779 if ( m_pListBoxHelper
)
781 checkSelection_Impl(nSelectedChildIndex
,*m_pListBoxHelper
,sal_False
);
783 m_pListBoxHelper
->SelectEntryPos( (USHORT
)nSelectedChildIndex
, FALSE
);
784 // call the select handler, don't handle events in this time
785 m_bDisableProcessEvent
= true;
786 m_pListBoxHelper
->Select();
787 m_bDisableProcessEvent
= false;
793 UpdateSelection_Impl();
795 // -----------------------------------------------------------------------------
796 // accessibility::XAccessibleComponent
797 awt::Rectangle
VCLXAccessibleList::implGetBounds() throw (uno::RuntimeException
)
799 awt::Rectangle
aBounds ( 0, 0, 0, 0 );
800 if ( m_pListBoxHelper
801 && (m_pListBoxHelper
->GetStyle() & WB_DROPDOWN
) == WB_DROPDOWN
)
803 if ( m_pListBoxHelper
->IsInDropDown() )
804 aBounds
= AWTRectangle(m_pListBoxHelper
->GetDropDownPosSizePixel());
808 // a list has the same bounds as his parent but starts at (0,0)
809 aBounds
= VCLXAccessibleComponent::implGetBounds();
812 if ( m_aBoxType
== COMBOBOX
)
814 ComboBox
* pBox
= static_cast<ComboBox
*>(GetWindow());
817 Size aSize
= pBox
->GetSubEdit()->GetSizePixel();
818 aBounds
.X
+= aSize
.Height();
819 aBounds
.Y
+= aSize
.Width();
820 aBounds
.Height
-= aSize
.Height();
821 aBounds
.Width
-= aSize
.Width();
827 // -----------------------------------------------------------------------------
829 awt::Point
VCLXAccessibleList::getLocationOnScreen( ) throw (uno::RuntimeException
)
831 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
832 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
835 if ( m_pListBoxHelper
836 && (m_pListBoxHelper
->GetStyle() & WB_DROPDOWN
) == WB_DROPDOWN
)
838 if ( m_pListBoxHelper
->IsInDropDown() )
839 aPos
= AWTPoint(m_pListBoxHelper
->GetDropDownPosSizePixel().TopLeft());
843 aPos
= VCLXAccessibleComponent::getLocationOnScreen();
844 if ( m_aBoxType
== COMBOBOX
)
846 ComboBox
* pBox
= static_cast<ComboBox
*>(GetWindow());
849 aPos
.X
+= pBox
->GetSubEdit()->GetSizePixel().Height();
850 aPos
.Y
+= pBox
->GetSubEdit()->GetSizePixel().Width();
856 // -----------------------------------------------------------------------------