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