xref: /AOO41X/main/accessibility/source/standard/vclxaccessiblelist.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
30*cdf0e10cSrcweir #include <accessibility/standard/vclxaccessiblelist.hxx>
31*cdf0e10cSrcweir #include <accessibility/standard/vclxaccessiblelistitem.hxx>
32*cdf0e10cSrcweir #include <accessibility/helper/listboxhelper.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
35*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
38*cdf0e10cSrcweir #include <vcl/svapp.hxx>
39*cdf0e10cSrcweir #include <vcl/combobox.hxx>
40*cdf0e10cSrcweir #include <vcl/lstbox.hxx>
41*cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir using namespace ::com::sun::star;
44*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
45*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
46*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
47*cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
48*cdf0e10cSrcweir using namespace ::accessibility;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir 	void checkSelection_Impl( sal_Int32 _nIndex, const IComboListBoxHelper& _rListBox, sal_Bool bSelected )
53*cdf0e10cSrcweir         throw (::com::sun::star::lang::IndexOutOfBoundsException)
54*cdf0e10cSrcweir 	{
55*cdf0e10cSrcweir 		sal_Int32 nCount = bSelected ? (sal_Int32)_rListBox.GetSelectEntryCount()
56*cdf0e10cSrcweir 									 : (sal_Int32)_rListBox.GetEntryCount();
57*cdf0e10cSrcweir 		if ( _nIndex < 0 || _nIndex >= nCount )
58*cdf0e10cSrcweir 			throw ::com::sun::star::lang::IndexOutOfBoundsException();
59*cdf0e10cSrcweir 	}
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir VCLXAccessibleList::VCLXAccessibleList (VCLXWindow* pVCLWindow, BoxType aBoxType,
63*cdf0e10cSrcweir 										const Reference< XAccessible >& _xParent)
64*cdf0e10cSrcweir     : VCLXAccessibleComponent	(pVCLWindow),
65*cdf0e10cSrcweir       m_aBoxType				(aBoxType),
66*cdf0e10cSrcweir       m_nVisibleLineCount		(0),
67*cdf0e10cSrcweir       m_nIndexInParent			(DEFAULT_INDEX_IN_PARENT),
68*cdf0e10cSrcweir 	  m_nLastTopEntry			( 0 ),
69*cdf0e10cSrcweir 	  m_nLastSelectedPos		( LISTBOX_ENTRY_NOTFOUND ),
70*cdf0e10cSrcweir 	  m_bDisableProcessEvent	( false ),
71*cdf0e10cSrcweir 	  m_bVisible				( true ),
72*cdf0e10cSrcweir       m_xParent                 ( _xParent )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir     // Because combo boxes and list boxes have the no common interface for
75*cdf0e10cSrcweir     // methods with identical signature we have to write down twice the
76*cdf0e10cSrcweir     // same code.
77*cdf0e10cSrcweir     switch (m_aBoxType)
78*cdf0e10cSrcweir     {
79*cdf0e10cSrcweir         case COMBOBOX:
80*cdf0e10cSrcweir         {
81*cdf0e10cSrcweir             ComboBox* pBox = static_cast<ComboBox*>(GetWindow());
82*cdf0e10cSrcweir             if ( pBox != NULL )
83*cdf0e10cSrcweir                 m_pListBoxHelper = new VCLListBoxHelper<ComboBox> (*pBox);
84*cdf0e10cSrcweir             break;
85*cdf0e10cSrcweir         }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir         case LISTBOX:
88*cdf0e10cSrcweir         {
89*cdf0e10cSrcweir             ListBox* pBox = static_cast<ListBox*>(GetWindow());
90*cdf0e10cSrcweir             if ( pBox != NULL )
91*cdf0e10cSrcweir                 m_pListBoxHelper = new VCLListBoxHelper<ListBox> (*pBox);
92*cdf0e10cSrcweir             break;
93*cdf0e10cSrcweir         }
94*cdf0e10cSrcweir     }
95*cdf0e10cSrcweir     UpdateVisibleLineCount();
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	sal_uInt16 nCount = static_cast<sal_uInt16>(getAccessibleChildCount());
98*cdf0e10cSrcweir 	m_aAccessibleChildren.reserve(nCount);
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir // -----------------------------------------------------------------------------
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir VCLXAccessibleList::~VCLXAccessibleList (void)
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir     delete m_pListBoxHelper;
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir // -----------------------------------------------------------------------------
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir void VCLXAccessibleList::SetIndexInParent (sal_Int32 nIndex)
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     m_nIndexInParent = nIndex;
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir // -----------------------------------------------------------------------------
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir void SAL_CALL VCLXAccessibleList::disposing (void)
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir 	VCLXAccessibleComponent::disposing();
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     // Dispose all items in the list.
119*cdf0e10cSrcweir 	clearItems();
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	delete m_pListBoxHelper;
122*cdf0e10cSrcweir 	m_pListBoxHelper = NULL;
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir // -----------------------------------------------------------------------------
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir void VCLXAccessibleList::clearItems()
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir //	ListItems::iterator aEnd = m_aAccessibleChildren.end();
129*cdf0e10cSrcweir //	for (ListItems::iterator aIter = m_aAccessibleChildren.begin(); aIter != aEnd; ++aIter)
130*cdf0e10cSrcweir //		::comphelper::disposeComponent(*aIter);
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     // Clear the list itself and delete all the rest.
133*cdf0e10cSrcweir 	ListItems().swap(m_aAccessibleChildren); // clear and minimize
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir // -----------------------------------------------------------------------------
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir void VCLXAccessibleList::FillAccessibleStateSet (utl::AccessibleStateSetHelper& rStateSet)
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
142*cdf0e10cSrcweir 	// check if our list should be visible
143*cdf0e10cSrcweir 	if (	m_pListBoxHelper
144*cdf0e10cSrcweir 		&& (m_pListBoxHelper->GetStyle() & WB_DROPDOWN ) == WB_DROPDOWN
145*cdf0e10cSrcweir 		&& !m_pListBoxHelper->IsInDropDown() )
146*cdf0e10cSrcweir 	{
147*cdf0e10cSrcweir 		rStateSet.RemoveState (AccessibleStateType::VISIBLE);
148*cdf0e10cSrcweir 		rStateSet.RemoveState (AccessibleStateType::SHOWING);
149*cdf0e10cSrcweir 		m_bVisible = false;
150*cdf0e10cSrcweir 	}
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     // Both the combo box and list box are handled identical in the
153*cdf0e10cSrcweir     // following but for some reason they don't have a common interface for
154*cdf0e10cSrcweir     // the methods used.
155*cdf0e10cSrcweir 	if ( m_pListBoxHelper )
156*cdf0e10cSrcweir 	{
157*cdf0e10cSrcweir         if ( m_pListBoxHelper->IsMultiSelectionEnabled() )
158*cdf0e10cSrcweir             rStateSet.AddState( AccessibleStateType::MULTI_SELECTABLE);
159*cdf0e10cSrcweir 		rStateSet.AddState (AccessibleStateType::FOCUSABLE);
160*cdf0e10cSrcweir         // All children are transient.
161*cdf0e10cSrcweir         rStateSet.AddState (AccessibleStateType::MANAGES_DESCENDANTS);
162*cdf0e10cSrcweir 	}
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir // -----------------------------------------------------------------------------
165*cdf0e10cSrcweir void VCLXAccessibleList::notifyVisibleStates(sal_Bool _bSetNew )
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir 	m_bVisible = _bSetNew ? true : false;
168*cdf0e10cSrcweir 	Any aOldValue, aNewValue;
169*cdf0e10cSrcweir 	(_bSetNew ? aNewValue : aOldValue ) <<= AccessibleStateType::VISIBLE;
170*cdf0e10cSrcweir 	NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
171*cdf0e10cSrcweir 	(_bSetNew ? aNewValue : aOldValue ) <<= AccessibleStateType::SHOWING;
172*cdf0e10cSrcweir 	NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 	ListItems::iterator aIter = m_aAccessibleChildren.begin();
175*cdf0e10cSrcweir 	ListItems::iterator aEnd = m_aAccessibleChildren.end();
176*cdf0e10cSrcweir     UpdateVisibleLineCount();
177*cdf0e10cSrcweir 	// adjust the index inside the VCLXAccessibleListItem
178*cdf0e10cSrcweir 	for (;aIter != aEnd ; ++aIter)
179*cdf0e10cSrcweir 	{
180*cdf0e10cSrcweir 		Reference< XAccessible > xHold = *aIter;
181*cdf0e10cSrcweir 		VCLXAccessibleListItem* pItem = static_cast<VCLXAccessibleListItem*>(xHold.get());
182*cdf0e10cSrcweir 		if ( pItem )
183*cdf0e10cSrcweir 		{
184*cdf0e10cSrcweir 			sal_uInt16 nTopEntry = 0;
185*cdf0e10cSrcweir 			if ( m_pListBoxHelper )
186*cdf0e10cSrcweir 				nTopEntry = m_pListBoxHelper->GetTopEntry();
187*cdf0e10cSrcweir             sal_uInt16 nPos = (sal_uInt16)(aIter - m_aAccessibleChildren.begin());
188*cdf0e10cSrcweir 			sal_Bool bVisible = ( nPos>=nTopEntry && nPos<( nTopEntry + m_nVisibleLineCount ) );
189*cdf0e10cSrcweir 			pItem->SetVisible( m_bVisible && bVisible );
190*cdf0e10cSrcweir 		}
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 	}
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir // -----------------------------------------------------------------------------
195*cdf0e10cSrcweir void VCLXAccessibleList::ProcessWindowEvent (const VclWindowEvent& rVclWindowEvent)
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir     // Create a reference to this object to prevent an early release of the
198*cdf0e10cSrcweir     // listbox (VCLEVENT_OBJECT_DYING).
199*cdf0e10cSrcweir 	Reference< XAccessible > xTemp = this;
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 	switch ( rVclWindowEvent.GetId() )
202*cdf0e10cSrcweir     {
203*cdf0e10cSrcweir 		case VCLEVENT_DROPDOWN_OPEN:
204*cdf0e10cSrcweir 			notifyVisibleStates(sal_True);
205*cdf0e10cSrcweir 			break;
206*cdf0e10cSrcweir 		case VCLEVENT_DROPDOWN_CLOSE:
207*cdf0e10cSrcweir 			notifyVisibleStates(sal_False);
208*cdf0e10cSrcweir 			break;
209*cdf0e10cSrcweir 		case VCLEVENT_LISTBOX_SCROLLED:
210*cdf0e10cSrcweir 		case VCLEVENT_COMBOBOX_SCROLLED:
211*cdf0e10cSrcweir 			UpdateEntryRange_Impl();
212*cdf0e10cSrcweir 			break;
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 		case VCLEVENT_LISTBOX_SELECT:
215*cdf0e10cSrcweir 			if ( !m_bDisableProcessEvent )
216*cdf0e10cSrcweir 				UpdateSelection_Impl();
217*cdf0e10cSrcweir 			break;
218*cdf0e10cSrcweir 		// The selection events VCLEVENT_COMBOBOX_SELECT and
219*cdf0e10cSrcweir 		// VCLEVENT_COMBOBOX_DESELECT are not handled here because here we
220*cdf0e10cSrcweir 		// have no access to the edit field.  Its text is necessary to
221*cdf0e10cSrcweir 		// identify the currently selected item.
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 		case VCLEVENT_OBJECT_DYING:
224*cdf0e10cSrcweir 		{
225*cdf0e10cSrcweir             dispose();
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir             VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent);
228*cdf0e10cSrcweir             break;
229*cdf0e10cSrcweir 		}
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir         case VCLEVENT_LISTBOX_ITEMREMOVED:
232*cdf0e10cSrcweir         case VCLEVENT_COMBOBOX_ITEMREMOVED:
233*cdf0e10cSrcweir             HandleChangedItemList (false, reinterpret_cast<sal_IntPtr>(
234*cdf0e10cSrcweir                 rVclWindowEvent.GetData()));
235*cdf0e10cSrcweir             break;
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir         case VCLEVENT_LISTBOX_ITEMADDED:
238*cdf0e10cSrcweir         case VCLEVENT_COMBOBOX_ITEMADDED:
239*cdf0e10cSrcweir             HandleChangedItemList (true, reinterpret_cast<sal_IntPtr>(
240*cdf0e10cSrcweir                 rVclWindowEvent.GetData()));
241*cdf0e10cSrcweir             break;
242*cdf0e10cSrcweir 		case VCLEVENT_CONTROL_GETFOCUS:
243*cdf0e10cSrcweir             VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent);
244*cdf0e10cSrcweir 			if ( m_pListBoxHelper )
245*cdf0e10cSrcweir 			{
246*cdf0e10cSrcweir 				uno::Any	aOldValue,
247*cdf0e10cSrcweir 							aNewValue;
248*cdf0e10cSrcweir 				sal_uInt16 nPos = m_pListBoxHelper->GetSelectEntryPos();
249*cdf0e10cSrcweir 				if ( nPos == LISTBOX_ENTRY_NOTFOUND )
250*cdf0e10cSrcweir 					nPos = m_pListBoxHelper->GetTopEntry();
251*cdf0e10cSrcweir 				if ( nPos != LISTBOX_ENTRY_NOTFOUND )
252*cdf0e10cSrcweir 					aNewValue <<= CreateChild(nPos);
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 				NotifyAccessibleEvent(	AccessibleEventId::ACTIVE_DESCENDANT_CHANGED,
255*cdf0e10cSrcweir 										aOldValue,
256*cdf0e10cSrcweir 										aNewValue );
257*cdf0e10cSrcweir 			}
258*cdf0e10cSrcweir 			break;
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir         default:
261*cdf0e10cSrcweir             VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent);
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir // -----------------------------------------------------------------------------
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir /** To find out which item is currently selected and to update the SELECTED
267*cdf0e10cSrcweir     state of the associated accessibility objects accordingly we exploit the
268*cdf0e10cSrcweir     fact that the
269*cdf0e10cSrcweir */
270*cdf0e10cSrcweir void VCLXAccessibleList::UpdateSelection (::rtl::OUString sTextOfSelectedItem)
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir     if ( m_aBoxType == COMBOBOX )
273*cdf0e10cSrcweir     {
274*cdf0e10cSrcweir         ComboBox* pBox = static_cast<ComboBox*>(GetWindow());
275*cdf0e10cSrcweir         if ( pBox != NULL )
276*cdf0e10cSrcweir         {
277*cdf0e10cSrcweir             // Find the index of the selected item inside the VCL control...
278*cdf0e10cSrcweir             sal_uInt16 nIndex = pBox->GetEntryPos (XubString(sTextOfSelectedItem));
279*cdf0e10cSrcweir             // ...and then find the associated accessibility object.
280*cdf0e10cSrcweir 			if ( nIndex == LISTBOX_ENTRY_NOTFOUND )
281*cdf0e10cSrcweir 				nIndex = 0;
282*cdf0e10cSrcweir 			UpdateSelection_Impl(nIndex);
283*cdf0e10cSrcweir         }
284*cdf0e10cSrcweir     }
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir // -----------------------------------------------------------------------------
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir void VCLXAccessibleList::adjustEntriesIndexInParent(ListItems::iterator& _aBegin,::std::mem_fun_t<bool,VCLXAccessibleListItem>& _rMemFun)
289*cdf0e10cSrcweir {
290*cdf0e10cSrcweir 	ListItems::iterator aIter = _aBegin;
291*cdf0e10cSrcweir 	ListItems::iterator aEnd = m_aAccessibleChildren.end();
292*cdf0e10cSrcweir 	// adjust the index inside the VCLXAccessibleListItem
293*cdf0e10cSrcweir 	for (;aIter != aEnd ; ++aIter)
294*cdf0e10cSrcweir 	{
295*cdf0e10cSrcweir 		Reference< XAccessible > xHold = *aIter;
296*cdf0e10cSrcweir 		VCLXAccessibleListItem* pItem = static_cast<VCLXAccessibleListItem*>(xHold.get());
297*cdf0e10cSrcweir 		if ( pItem )
298*cdf0e10cSrcweir 			_rMemFun(pItem);
299*cdf0e10cSrcweir 	}
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir // -----------------------------------------------------------------------------
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir Reference<XAccessible> VCLXAccessibleList::CreateChild (sal_Int32 i)
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir     Reference<XAccessible> xChild;
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	sal_uInt16 nPos = static_cast<sal_uInt16>(i);
308*cdf0e10cSrcweir 	if ( nPos >= m_aAccessibleChildren.size() )
309*cdf0e10cSrcweir 	{
310*cdf0e10cSrcweir 		m_aAccessibleChildren.resize(nPos + 1);
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 		// insert into the container
313*cdf0e10cSrcweir 		xChild = new VCLXAccessibleListItem(m_pListBoxHelper, i, this);
314*cdf0e10cSrcweir 		m_aAccessibleChildren[nPos] = xChild;
315*cdf0e10cSrcweir 	}
316*cdf0e10cSrcweir 	else
317*cdf0e10cSrcweir 	{
318*cdf0e10cSrcweir 		xChild = m_aAccessibleChildren[nPos];
319*cdf0e10cSrcweir 		// check if position is empty and can be used else we have to adjust all entries behind this
320*cdf0e10cSrcweir 		if ( xChild.is() )
321*cdf0e10cSrcweir 		{
322*cdf0e10cSrcweir 			ListItems::iterator aIter = m_aAccessibleChildren.begin() + nPos;
323*cdf0e10cSrcweir             ::std::mem_fun_t<bool, VCLXAccessibleListItem> aTemp(&VCLXAccessibleListItem::IncrementIndexInParent);
324*cdf0e10cSrcweir 			adjustEntriesIndexInParent(	aIter, aTemp);
325*cdf0e10cSrcweir 		}
326*cdf0e10cSrcweir 		else
327*cdf0e10cSrcweir 		{
328*cdf0e10cSrcweir 			xChild = new VCLXAccessibleListItem(m_pListBoxHelper, i, this);
329*cdf0e10cSrcweir 			m_aAccessibleChildren[nPos] = xChild;
330*cdf0e10cSrcweir 		}
331*cdf0e10cSrcweir 	}
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir     if ( xChild.is() )
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir 		// Just add the SELECTED state.
336*cdf0e10cSrcweir 		sal_Bool bNowSelected = sal_False;
337*cdf0e10cSrcweir 		if ( m_pListBoxHelper )
338*cdf0e10cSrcweir 			bNowSelected = m_pListBoxHelper->IsEntryPosSelected ((sal_uInt16)i);
339*cdf0e10cSrcweir         VCLXAccessibleListItem* pItem = static_cast< VCLXAccessibleListItem* >(xChild.get());
340*cdf0e10cSrcweir         pItem->SetSelected( bNowSelected );
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 		// Set the child's VISIBLE state.
343*cdf0e10cSrcweir         UpdateVisibleLineCount();
344*cdf0e10cSrcweir 		sal_uInt16 nTopEntry = 0;
345*cdf0e10cSrcweir 		if ( m_pListBoxHelper )
346*cdf0e10cSrcweir 			nTopEntry = m_pListBoxHelper->GetTopEntry();
347*cdf0e10cSrcweir 		sal_Bool bVisible = ( nPos>=nTopEntry && nPos<( nTopEntry + m_nVisibleLineCount ) );
348*cdf0e10cSrcweir 		pItem->SetVisible( m_bVisible && bVisible );
349*cdf0e10cSrcweir     }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir     return xChild;
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir // -----------------------------------------------------------------------------
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir void VCLXAccessibleList::HandleChangedItemList (bool bItemInserted, sal_Int32 nIndex)
356*cdf0e10cSrcweir {
357*cdf0e10cSrcweir     if ( !bItemInserted )
358*cdf0e10cSrcweir 	{
359*cdf0e10cSrcweir 		if ( nIndex == -1 ) // special handling here
360*cdf0e10cSrcweir 		{
361*cdf0e10cSrcweir 			clearItems();
362*cdf0e10cSrcweir 		}
363*cdf0e10cSrcweir 		else
364*cdf0e10cSrcweir 		{
365*cdf0e10cSrcweir 			if ( nIndex >= 0 && static_cast<sal_uInt16>(nIndex) < m_aAccessibleChildren.size() )
366*cdf0e10cSrcweir 			{
367*cdf0e10cSrcweir 				ListItems::iterator aIter = m_aAccessibleChildren.erase(m_aAccessibleChildren.begin()+nIndex);
368*cdf0e10cSrcweir             ::std::mem_fun_t<bool, VCLXAccessibleListItem> aTemp(&VCLXAccessibleListItem::DecrementIndexInParent);
369*cdf0e10cSrcweir 				adjustEntriesIndexInParent(	aIter, aTemp );
370*cdf0e10cSrcweir 			}
371*cdf0e10cSrcweir 		}
372*cdf0e10cSrcweir 	}
373*cdf0e10cSrcweir 	else
374*cdf0e10cSrcweir 		getAccessibleChild(nIndex);
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir     NotifyAccessibleEvent (
377*cdf0e10cSrcweir         AccessibleEventId::INVALIDATE_ALL_CHILDREN,
378*cdf0e10cSrcweir         Any(), Any());
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir // -----------------------------------------------------------------------------
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2(VCLXAccessibleList, VCLXAccessibleComponent, VCLXAccessibleList_BASE)
383*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2(VCLXAccessibleList, VCLXAccessibleComponent, VCLXAccessibleList_BASE)
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir //=====  XAccessible  =========================================================
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir Reference<XAccessibleContext> SAL_CALL
388*cdf0e10cSrcweir     VCLXAccessibleList::getAccessibleContext (void)
389*cdf0e10cSrcweir     throw (RuntimeException)
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir 	return this;
392*cdf0e10cSrcweir }
393*cdf0e10cSrcweir // -----------------------------------------------------------------------------
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir //=====  XAccessibleContext  ==================================================
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXAccessibleList::getAccessibleChildCount (void)
398*cdf0e10cSrcweir     throw (RuntimeException)
399*cdf0e10cSrcweir {
400*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
401*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 	sal_Int32 nCount = 0;
404*cdf0e10cSrcweir 	if ( m_pListBoxHelper )
405*cdf0e10cSrcweir 		nCount = m_pListBoxHelper->GetEntryCount();
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir     return nCount;
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir // -----------------------------------------------------------------------------
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir Reference<XAccessible> SAL_CALL VCLXAccessibleList::getAccessibleChild (sal_Int32 i)
412*cdf0e10cSrcweir     throw (IndexOutOfBoundsException, RuntimeException)
413*cdf0e10cSrcweir {
414*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
415*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 	if ( i < 0 || i >= getAccessibleChildCount() )
418*cdf0e10cSrcweir 		throw IndexOutOfBoundsException();
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     Reference< XAccessible > xChild;
421*cdf0e10cSrcweir     // search for the child
422*cdf0e10cSrcweir 	if ( static_cast<sal_uInt16>(i) >= m_aAccessibleChildren.size() )
423*cdf0e10cSrcweir 		xChild = CreateChild (i);
424*cdf0e10cSrcweir 	else
425*cdf0e10cSrcweir 	{
426*cdf0e10cSrcweir 		xChild = m_aAccessibleChildren[i];
427*cdf0e10cSrcweir 		if ( !xChild.is() )
428*cdf0e10cSrcweir 			xChild = CreateChild (i);
429*cdf0e10cSrcweir 	}
430*cdf0e10cSrcweir 	OSL_ENSURE( xChild.is(), "VCLXAccessibleList::getAccessibleChild: returning empty child!" );
431*cdf0e10cSrcweir     return xChild;
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir // -----------------------------------------------------------------------------
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir Reference< XAccessible > SAL_CALL VCLXAccessibleList::getAccessibleParent(  )
436*cdf0e10cSrcweir 	throw (RuntimeException)
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 	return m_xParent;
441*cdf0e10cSrcweir }
442*cdf0e10cSrcweir // -----------------------------------------------------------------------------
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXAccessibleList::getAccessibleIndexInParent (void)
445*cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
446*cdf0e10cSrcweir {
447*cdf0e10cSrcweir     if (m_nIndexInParent != DEFAULT_INDEX_IN_PARENT)
448*cdf0e10cSrcweir         return m_nIndexInParent;
449*cdf0e10cSrcweir     else
450*cdf0e10cSrcweir         return VCLXAccessibleComponent::getAccessibleIndexInParent();
451*cdf0e10cSrcweir }
452*cdf0e10cSrcweir // -----------------------------------------------------------------------------
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir sal_Int16 SAL_CALL VCLXAccessibleList::getAccessibleRole (void)
455*cdf0e10cSrcweir     throw (RuntimeException)
456*cdf0e10cSrcweir {
457*cdf0e10cSrcweir     return AccessibleRole::LIST;
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir // -----------------------------------------------------------------------------
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir //=====  XAccessibleComponent  ================================================
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir sal_Bool SAL_CALL VCLXAccessibleList::contains( const awt::Point& rPoint ) throw (RuntimeException)
464*cdf0e10cSrcweir {
465*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
466*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir 	sal_Bool bInside = sal_False;
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir     Window* pListBox = GetWindow();
471*cdf0e10cSrcweir     if ( pListBox )
472*cdf0e10cSrcweir 	{
473*cdf0e10cSrcweir 		Rectangle aRect( Point(0,0), pListBox->GetSizePixel() );
474*cdf0e10cSrcweir 		bInside = aRect.IsInside( VCLPoint( rPoint ) );
475*cdf0e10cSrcweir 	}
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 	return bInside;
478*cdf0e10cSrcweir }
479*cdf0e10cSrcweir // -----------------------------------------------------------------------------
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir Reference< XAccessible > SAL_CALL VCLXAccessibleList::getAccessibleAt( const awt::Point& rPoint )
482*cdf0e10cSrcweir     throw (RuntimeException)
483*cdf0e10cSrcweir {
484*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
485*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 	Reference< XAccessible > xChild;
488*cdf0e10cSrcweir 	if ( m_pListBoxHelper )
489*cdf0e10cSrcweir 	{
490*cdf0e10cSrcweir         UpdateVisibleLineCount();
491*cdf0e10cSrcweir 		if ( contains( rPoint ) && m_nVisibleLineCount > 0 )
492*cdf0e10cSrcweir 		{
493*cdf0e10cSrcweir 			Point aPos = VCLPoint( rPoint );
494*cdf0e10cSrcweir 			sal_uInt16 nEndPos = m_pListBoxHelper->GetTopEntry() + (sal_uInt16)m_nVisibleLineCount;
495*cdf0e10cSrcweir 			for ( sal_uInt16 i = m_pListBoxHelper->GetTopEntry(); i < nEndPos; ++i )
496*cdf0e10cSrcweir 			{
497*cdf0e10cSrcweir 				if ( m_pListBoxHelper->GetBoundingRectangle(i).IsInside( aPos ) )
498*cdf0e10cSrcweir 				{
499*cdf0e10cSrcweir 					xChild = getAccessibleChild(i);
500*cdf0e10cSrcweir 					break;
501*cdf0e10cSrcweir 				}
502*cdf0e10cSrcweir 			}
503*cdf0e10cSrcweir 		}
504*cdf0e10cSrcweir 	}
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir     return xChild;
507*cdf0e10cSrcweir }
508*cdf0e10cSrcweir // -----------------------------------------------------------------------------
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir //===== XServiceInfo ==========================================================
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleList::getImplementationName (void)
513*cdf0e10cSrcweir     throw (RuntimeException)
514*cdf0e10cSrcweir {
515*cdf0e10cSrcweir 	return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.toolkit.AccessibleList"));
516*cdf0e10cSrcweir }
517*cdf0e10cSrcweir // -----------------------------------------------------------------------------
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleList::getSupportedServiceNames (void)
520*cdf0e10cSrcweir     throw (RuntimeException)
521*cdf0e10cSrcweir {
522*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aNames = VCLXAccessibleComponent::getSupportedServiceNames();
523*cdf0e10cSrcweir 	sal_Int32 nLength = aNames.getLength();
524*cdf0e10cSrcweir 	aNames.realloc( nLength + 1 );
525*cdf0e10cSrcweir 	aNames[nLength] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleList"));
526*cdf0e10cSrcweir 	return aNames;
527*cdf0e10cSrcweir }
528*cdf0e10cSrcweir // -----------------------------------------------------------------------------
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir void VCLXAccessibleList::UpdateVisibleLineCount()
531*cdf0e10cSrcweir {
532*cdf0e10cSrcweir 	if ( m_pListBoxHelper )
533*cdf0e10cSrcweir 	{
534*cdf0e10cSrcweir 		if ( (m_pListBoxHelper->GetStyle() & WB_DROPDOWN ) == WB_DROPDOWN )
535*cdf0e10cSrcweir 			m_nVisibleLineCount = m_pListBoxHelper->GetDisplayLineCount();
536*cdf0e10cSrcweir 		else
537*cdf0e10cSrcweir 		{
538*cdf0e10cSrcweir 			sal_uInt16 nCols = 0,
539*cdf0e10cSrcweir 				nLines = 0;
540*cdf0e10cSrcweir 			m_pListBoxHelper->GetMaxVisColumnsAndLines (nCols, nLines);
541*cdf0e10cSrcweir 			m_nVisibleLineCount = nLines;
542*cdf0e10cSrcweir 		}
543*cdf0e10cSrcweir 	}
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir // -----------------------------------------------------------------------------
547*cdf0e10cSrcweir void VCLXAccessibleList::UpdateEntryRange_Impl()
548*cdf0e10cSrcweir {
549*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
550*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir 	sal_Int32 nTop = m_nLastTopEntry;
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 	if ( m_pListBoxHelper )
555*cdf0e10cSrcweir 		nTop = m_pListBoxHelper->GetTopEntry();
556*cdf0e10cSrcweir 	if ( nTop != m_nLastTopEntry )
557*cdf0e10cSrcweir 	{
558*cdf0e10cSrcweir         UpdateVisibleLineCount();
559*cdf0e10cSrcweir 		sal_Int32 nBegin = Min( m_nLastTopEntry, nTop );
560*cdf0e10cSrcweir 		sal_Int32 nEnd = Max( m_nLastTopEntry + m_nVisibleLineCount, nTop + m_nVisibleLineCount );
561*cdf0e10cSrcweir 		for (sal_uInt16 i = static_cast<sal_uInt16>(nBegin); (i <= static_cast<sal_uInt16>(nEnd)); ++i)
562*cdf0e10cSrcweir 		{
563*cdf0e10cSrcweir 			sal_Bool bVisible = ( i >= nTop && i < ( nTop + m_nVisibleLineCount ) );
564*cdf0e10cSrcweir 			Reference< XAccessible > xHold;
565*cdf0e10cSrcweir 			if ( i < m_aAccessibleChildren.size() )
566*cdf0e10cSrcweir 				xHold = m_aAccessibleChildren[i];
567*cdf0e10cSrcweir 			else if ( bVisible )
568*cdf0e10cSrcweir 				xHold = CreateChild(i);
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir 			if ( xHold.is() )
571*cdf0e10cSrcweir 				static_cast< VCLXAccessibleListItem* >( xHold.get() )->SetVisible( m_bVisible && bVisible );
572*cdf0e10cSrcweir 		}
573*cdf0e10cSrcweir 	}
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 	m_nLastTopEntry = nTop;
576*cdf0e10cSrcweir }
577*cdf0e10cSrcweir // -----------------------------------------------------------------------------
578*cdf0e10cSrcweir sal_Bool VCLXAccessibleList::checkEntrySelected(sal_uInt16 _nPos,Any& _rNewValue,Reference< XAccessible >& _rxNewAcc)
579*cdf0e10cSrcweir {
580*cdf0e10cSrcweir 	OSL_ENSURE(m_pListBoxHelper,"Helper is not valid!");
581*cdf0e10cSrcweir 	sal_Bool bNowSelected = sal_False;
582*cdf0e10cSrcweir 	if ( m_pListBoxHelper )
583*cdf0e10cSrcweir 	{
584*cdf0e10cSrcweir 		bNowSelected = m_pListBoxHelper->IsEntryPosSelected (_nPos);
585*cdf0e10cSrcweir 		if ( bNowSelected )
586*cdf0e10cSrcweir 		{
587*cdf0e10cSrcweir 			_rxNewAcc = CreateChild(_nPos);
588*cdf0e10cSrcweir 			_rNewValue <<= _rxNewAcc;
589*cdf0e10cSrcweir 		}
590*cdf0e10cSrcweir 	}
591*cdf0e10cSrcweir 	return bNowSelected;
592*cdf0e10cSrcweir }
593*cdf0e10cSrcweir // -----------------------------------------------------------------------------
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir void VCLXAccessibleList::UpdateSelection_Impl(sal_uInt16)
596*cdf0e10cSrcweir {
597*cdf0e10cSrcweir 	uno::Any aOldValue, aNewValue;
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir 	{
600*cdf0e10cSrcweir 		vos::OGuard aSolarGuard( Application::GetSolarMutex() );
601*cdf0e10cSrcweir 		::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
602*cdf0e10cSrcweir 	    Reference< XAccessible > xNewAcc;
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 		if ( m_pListBoxHelper )
605*cdf0e10cSrcweir 		{
606*cdf0e10cSrcweir 			sal_uInt16 i=0;
607*cdf0e10cSrcweir 			for ( ListItems::iterator aIter = m_aAccessibleChildren.begin();
608*cdf0e10cSrcweir 				  aIter != m_aAccessibleChildren.end(); ++aIter,++i)
609*cdf0e10cSrcweir 			{
610*cdf0e10cSrcweir 				Reference< XAccessible > xHold = *aIter;
611*cdf0e10cSrcweir 				if ( xHold.is() )
612*cdf0e10cSrcweir 				{
613*cdf0e10cSrcweir 					VCLXAccessibleListItem* pItem = static_cast< VCLXAccessibleListItem* >( xHold.get() );
614*cdf0e10cSrcweir 					// Retrieve the item's index from the list entry.
615*cdf0e10cSrcweir 					sal_Bool bNowSelected = m_pListBoxHelper->IsEntryPosSelected (i);
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 					if ( bNowSelected && !pItem->IsSelected() )
618*cdf0e10cSrcweir 					{
619*cdf0e10cSrcweir 						xNewAcc = *aIter;
620*cdf0e10cSrcweir 						aNewValue <<= xNewAcc;
621*cdf0e10cSrcweir 					}
622*cdf0e10cSrcweir 					else if ( pItem->IsSelected() )
623*cdf0e10cSrcweir 						m_nLastSelectedPos = i;
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir 					pItem->SetSelected( bNowSelected );
626*cdf0e10cSrcweir 				}
627*cdf0e10cSrcweir 				else
628*cdf0e10cSrcweir 				{ // it could happen that a child was not created before
629*cdf0e10cSrcweir 					checkEntrySelected(i,aNewValue,xNewAcc);
630*cdf0e10cSrcweir 				}
631*cdf0e10cSrcweir 			}
632*cdf0e10cSrcweir 			sal_uInt16 nCount = m_pListBoxHelper->GetEntryCount();
633*cdf0e10cSrcweir 			if ( i < nCount ) // here we have to check the if any other listbox entry is selected
634*cdf0e10cSrcweir 			{
635*cdf0e10cSrcweir 				for (; i < nCount && !checkEntrySelected(i,aNewValue,xNewAcc) ;++i )
636*cdf0e10cSrcweir 					;
637*cdf0e10cSrcweir 			}
638*cdf0e10cSrcweir 			if ( xNewAcc.is() && GetWindow()->HasFocus() )
639*cdf0e10cSrcweir 			{
640*cdf0e10cSrcweir 				if ( m_nLastSelectedPos != LISTBOX_ENTRY_NOTFOUND )
641*cdf0e10cSrcweir 					aOldValue <<= getAccessibleChild( (sal_Int32)m_nLastSelectedPos );
642*cdf0e10cSrcweir 				aNewValue <<= xNewAcc;
643*cdf0e10cSrcweir 			}
644*cdf0e10cSrcweir 		}
645*cdf0e10cSrcweir 	}
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir     if ( aNewValue.hasValue() || aOldValue.hasValue() )
648*cdf0e10cSrcweir 		NotifyAccessibleEvent(
649*cdf0e10cSrcweir             AccessibleEventId::ACTIVE_DESCENDANT_CHANGED,
650*cdf0e10cSrcweir             aOldValue,
651*cdf0e10cSrcweir             aNewValue );
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 	NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
654*cdf0e10cSrcweir }
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir // -----------------------------------------------------------------------------
657*cdf0e10cSrcweir // XAccessibleSelection
658*cdf0e10cSrcweir // -----------------------------------------------------------------------------
659*cdf0e10cSrcweir void SAL_CALL VCLXAccessibleList::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
660*cdf0e10cSrcweir {
661*cdf0e10cSrcweir 	sal_Bool bNotify = sal_False;
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 	{
664*cdf0e10cSrcweir 		vos::OGuard aSolarGuard( Application::GetSolarMutex() );
665*cdf0e10cSrcweir 		::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir 		if ( m_pListBoxHelper )
668*cdf0e10cSrcweir 		{
669*cdf0e10cSrcweir 			checkSelection_Impl(nChildIndex,*m_pListBoxHelper,sal_False);
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir 			m_pListBoxHelper->SelectEntryPos( (sal_uInt16)nChildIndex, sal_True );
672*cdf0e10cSrcweir 			// call the select handler, don't handle events in this time
673*cdf0e10cSrcweir 			m_bDisableProcessEvent = true;
674*cdf0e10cSrcweir 			m_pListBoxHelper->Select();
675*cdf0e10cSrcweir 			m_bDisableProcessEvent = false;
676*cdf0e10cSrcweir 			bNotify = sal_True;
677*cdf0e10cSrcweir 		}
678*cdf0e10cSrcweir 	}
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir 	if ( bNotify )
681*cdf0e10cSrcweir         UpdateSelection_Impl();
682*cdf0e10cSrcweir }
683*cdf0e10cSrcweir // -----------------------------------------------------------------------------
684*cdf0e10cSrcweir sal_Bool SAL_CALL VCLXAccessibleList::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
685*cdf0e10cSrcweir {
686*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
687*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir     sal_Bool bRet = sal_False;
690*cdf0e10cSrcweir 	if ( m_pListBoxHelper )
691*cdf0e10cSrcweir 	{
692*cdf0e10cSrcweir 		checkSelection_Impl(nChildIndex,*m_pListBoxHelper,sal_False);
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir     	bRet = m_pListBoxHelper->IsEntryPosSelected( (sal_uInt16)nChildIndex );
695*cdf0e10cSrcweir 	}
696*cdf0e10cSrcweir     return bRet;
697*cdf0e10cSrcweir }
698*cdf0e10cSrcweir // -----------------------------------------------------------------------------
699*cdf0e10cSrcweir void SAL_CALL VCLXAccessibleList::clearAccessibleSelection(  ) throw (RuntimeException)
700*cdf0e10cSrcweir {
701*cdf0e10cSrcweir 	sal_Bool bNotify = sal_False;
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir 	{
704*cdf0e10cSrcweir 		vos::OGuard aSolarGuard( Application::GetSolarMutex() );
705*cdf0e10cSrcweir 		::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 		if ( m_pListBoxHelper )
708*cdf0e10cSrcweir 		{
709*cdf0e10cSrcweir 	    	m_pListBoxHelper->SetNoSelection();
710*cdf0e10cSrcweir 			bNotify = sal_True;
711*cdf0e10cSrcweir 		}
712*cdf0e10cSrcweir 	}
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir 	if ( bNotify )
715*cdf0e10cSrcweir         UpdateSelection_Impl();
716*cdf0e10cSrcweir }
717*cdf0e10cSrcweir // -----------------------------------------------------------------------------
718*cdf0e10cSrcweir void SAL_CALL VCLXAccessibleList::selectAllAccessibleChildren(  ) throw (RuntimeException)
719*cdf0e10cSrcweir {
720*cdf0e10cSrcweir 	sal_Bool bNotify = sal_False;
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir 	{
723*cdf0e10cSrcweir 		vos::OGuard aSolarGuard( Application::GetSolarMutex() );
724*cdf0e10cSrcweir 		::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir 		if ( m_pListBoxHelper )
727*cdf0e10cSrcweir 		{
728*cdf0e10cSrcweir 	    	sal_uInt16 nCount = m_pListBoxHelper->GetEntryCount();
729*cdf0e10cSrcweir 	    	for ( sal_uInt16 i = 0; i < nCount; ++i )
730*cdf0e10cSrcweir 	    		m_pListBoxHelper->SelectEntryPos( i, sal_True );
731*cdf0e10cSrcweir 			// call the select handler, don't handle events in this time
732*cdf0e10cSrcweir 			m_bDisableProcessEvent = true;
733*cdf0e10cSrcweir 			m_pListBoxHelper->Select();
734*cdf0e10cSrcweir 			m_bDisableProcessEvent = false;
735*cdf0e10cSrcweir 			bNotify = sal_True;
736*cdf0e10cSrcweir 		}
737*cdf0e10cSrcweir 	}
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir 	if ( bNotify )
740*cdf0e10cSrcweir         UpdateSelection_Impl();
741*cdf0e10cSrcweir }
742*cdf0e10cSrcweir // -----------------------------------------------------------------------------
743*cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXAccessibleList::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
744*cdf0e10cSrcweir {
745*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
746*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir     sal_Int32 nCount = 0;
749*cdf0e10cSrcweir 	if ( m_pListBoxHelper )
750*cdf0e10cSrcweir    		nCount = m_pListBoxHelper->GetSelectEntryCount();
751*cdf0e10cSrcweir     return nCount;
752*cdf0e10cSrcweir }
753*cdf0e10cSrcweir // -----------------------------------------------------------------------------
754*cdf0e10cSrcweir Reference< XAccessible > SAL_CALL VCLXAccessibleList::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
755*cdf0e10cSrcweir {
756*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
757*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir 	if ( m_pListBoxHelper )
760*cdf0e10cSrcweir 	{
761*cdf0e10cSrcweir 		checkSelection_Impl(nSelectedChildIndex,*m_pListBoxHelper,sal_True);
762*cdf0e10cSrcweir 		return getAccessibleChild( (sal_Int32)m_pListBoxHelper->GetSelectEntryPos( (sal_uInt16)nSelectedChildIndex ) );
763*cdf0e10cSrcweir 	}
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir 	return NULL;
766*cdf0e10cSrcweir }
767*cdf0e10cSrcweir // -----------------------------------------------------------------------------
768*cdf0e10cSrcweir void SAL_CALL VCLXAccessibleList::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
769*cdf0e10cSrcweir {
770*cdf0e10cSrcweir 	sal_Bool bNotify = sal_False;
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir 	{
773*cdf0e10cSrcweir 		vos::OGuard aSolarGuard( Application::GetSolarMutex() );
774*cdf0e10cSrcweir 		::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir 		if ( m_pListBoxHelper )
777*cdf0e10cSrcweir 		{
778*cdf0e10cSrcweir 			checkSelection_Impl(nSelectedChildIndex,*m_pListBoxHelper,sal_False);
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir 			m_pListBoxHelper->SelectEntryPos( (sal_uInt16)nSelectedChildIndex, sal_False );
781*cdf0e10cSrcweir 			// call the select handler, don't handle events in this time
782*cdf0e10cSrcweir 			m_bDisableProcessEvent = true;
783*cdf0e10cSrcweir 			m_pListBoxHelper->Select();
784*cdf0e10cSrcweir 			m_bDisableProcessEvent = false;
785*cdf0e10cSrcweir 			bNotify = sal_True;
786*cdf0e10cSrcweir 		}
787*cdf0e10cSrcweir 	}
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir 	if ( bNotify )
790*cdf0e10cSrcweir         UpdateSelection_Impl();
791*cdf0e10cSrcweir }
792*cdf0e10cSrcweir // -----------------------------------------------------------------------------
793*cdf0e10cSrcweir // accessibility::XAccessibleComponent
794*cdf0e10cSrcweir awt::Rectangle VCLXAccessibleList::implGetBounds() throw (uno::RuntimeException)
795*cdf0e10cSrcweir {
796*cdf0e10cSrcweir 	awt::Rectangle aBounds ( 0, 0, 0, 0 );
797*cdf0e10cSrcweir 	if ( m_pListBoxHelper
798*cdf0e10cSrcweir 		&& (m_pListBoxHelper->GetStyle() & WB_DROPDOWN ) == WB_DROPDOWN )
799*cdf0e10cSrcweir 	{
800*cdf0e10cSrcweir 		if ( m_pListBoxHelper->IsInDropDown() )
801*cdf0e10cSrcweir 			aBounds = AWTRectangle(m_pListBoxHelper->GetDropDownPosSizePixel());
802*cdf0e10cSrcweir 	}
803*cdf0e10cSrcweir 	else
804*cdf0e10cSrcweir 	{
805*cdf0e10cSrcweir 		// a list has the same bounds as his parent but starts at (0,0)
806*cdf0e10cSrcweir 		aBounds = VCLXAccessibleComponent::implGetBounds();
807*cdf0e10cSrcweir 		aBounds.X = 0;
808*cdf0e10cSrcweir 		aBounds.Y = 0;
809*cdf0e10cSrcweir 		if ( m_aBoxType == COMBOBOX )
810*cdf0e10cSrcweir 		{
811*cdf0e10cSrcweir 			ComboBox* pBox = static_cast<ComboBox*>(GetWindow());
812*cdf0e10cSrcweir 			if ( pBox )
813*cdf0e10cSrcweir 			{
814*cdf0e10cSrcweir 				Size aSize = pBox->GetSubEdit()->GetSizePixel();
815*cdf0e10cSrcweir 				aBounds.X += aSize.Height();
816*cdf0e10cSrcweir 				aBounds.Y += aSize.Width();
817*cdf0e10cSrcweir 				aBounds.Height -= aSize.Height();
818*cdf0e10cSrcweir 				aBounds.Width  -= aSize.Width();
819*cdf0e10cSrcweir 			}
820*cdf0e10cSrcweir 		}
821*cdf0e10cSrcweir 	}
822*cdf0e10cSrcweir 	return aBounds;
823*cdf0e10cSrcweir }
824*cdf0e10cSrcweir // -----------------------------------------------------------------------------
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir awt::Point VCLXAccessibleList::getLocationOnScreen(  ) throw (uno::RuntimeException)
827*cdf0e10cSrcweir {
828*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
829*cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir 	awt::Point aPos;
832*cdf0e10cSrcweir 	if ( m_pListBoxHelper
833*cdf0e10cSrcweir 		&& (m_pListBoxHelper->GetStyle() & WB_DROPDOWN ) == WB_DROPDOWN )
834*cdf0e10cSrcweir 	{
835*cdf0e10cSrcweir 		if ( m_pListBoxHelper->IsInDropDown() )
836*cdf0e10cSrcweir 			aPos = AWTPoint(m_pListBoxHelper->GetDropDownPosSizePixel().TopLeft());
837*cdf0e10cSrcweir 	}
838*cdf0e10cSrcweir 	else
839*cdf0e10cSrcweir 	{
840*cdf0e10cSrcweir 		aPos = VCLXAccessibleComponent::getLocationOnScreen();
841*cdf0e10cSrcweir 		if ( m_aBoxType == COMBOBOX )
842*cdf0e10cSrcweir 		{
843*cdf0e10cSrcweir 			ComboBox* pBox = static_cast<ComboBox*>(GetWindow());
844*cdf0e10cSrcweir 			if ( pBox )
845*cdf0e10cSrcweir 			{
846*cdf0e10cSrcweir 				aPos.X += pBox->GetSubEdit()->GetSizePixel().Height();
847*cdf0e10cSrcweir 				aPos.Y += pBox->GetSubEdit()->GetSizePixel().Width();
848*cdf0e10cSrcweir 			}
849*cdf0e10cSrcweir 		}
850*cdf0e10cSrcweir 	}
851*cdf0e10cSrcweir 	return aPos;
852*cdf0e10cSrcweir }
853*cdf0e10cSrcweir // -----------------------------------------------------------------------------
854*cdf0e10cSrcweir 
855