merge the formfield patch from ooo-build
[ooovba.git] / accessibility / source / standard / vclxaccessiblelistboxlist.cxx
blobe2fad600ed4f1ab412dfe19f526e695f307c72ef
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessiblelistboxlist.cxx,v $
10 * $Revision: 1.3 $
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/vclxaccessiblelistboxlist.hxx>
34 #include <accessibility/standard/vclxaccessiblelistitem.hxx>
35 #include <accessibility/helper/listboxhelper.hxx>
37 #include <algorithm>
39 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
40 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
41 #include <tools/debug.hxx>
42 #include <vcl/svapp.hxx>
43 #include <vcl/lstbox.hxx>
44 #include <vcl/unohelp.hxx>
46 #include <toolkit/awt/vclxwindow.hxx>
47 #include <toolkit/helper/convert.hxx>
49 #include <comphelper/sequence.hxx>
50 #include <cppuhelper/typeprovider.hxx>
51 #include <unotools/accessiblestatesethelper.hxx>
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::accessibility;
59 namespace
61 void checkSelection_Impl( sal_Int32 _nIndex, const ListBox& _rListBox, sal_Bool bSelected )
62 throw (::com::sun::star::lang::IndexOutOfBoundsException)
64 sal_Int32 nCount = bSelected ? (sal_Int32)_rListBox.GetSelectEntryCount()
65 : (sal_Int32)_rListBox.GetEntryCount();
66 if ( _nIndex < 0 || _nIndex >= nCount )
67 throw ::com::sun::star::lang::IndexOutOfBoundsException();
72 VCLXAccessibleListBoxList::VCLXAccessibleListBoxList (VCLXWindow* pVCLWindow,
73 BoxType aBoxType,const Reference< XAccessible >& _xParent)
74 : VCLXAccessibleList (pVCLWindow, aBoxType, _xParent)
81 VCLXAccessibleListBoxList::~VCLXAccessibleListBoxList (void)
88 void VCLXAccessibleListBoxList::ProcessWindowEvent (const VclWindowEvent& rVclWindowEvent)
90 switch ( rVclWindowEvent.GetId() )
92 case VCLEVENT_LISTBOX_SCROLLED:
93 UpdateEntryRange_Impl();
94 break;
96 case VCLEVENT_LISTBOX_SELECT:
97 if ( !m_bDisableProcessEvent )
98 UpdateSelection_Impl();
99 break;
101 default:
102 VCLXAccessibleList::ProcessWindowEvent (rVclWindowEvent);
106 IMPLEMENT_FORWARD_XINTERFACE2(VCLXAccessibleListBoxList, VCLXAccessibleList, VCLXAccessibleListBoxList_BASE)
107 IMPLEMENT_FORWARD_XTYPEPROVIDER2(VCLXAccessibleListBoxList, VCLXAccessibleList, VCLXAccessibleListBoxList_BASE)
111 //===== XServiceInfo ========================================================
113 ::rtl::OUString VCLXAccessibleListBoxList::getImplementationName (void)
114 throw (RuntimeException)
116 return ::rtl::OUString::createFromAscii("com.sun.star.comp.toolkit.AccessibleListBoxList");
122 Sequence< ::rtl::OUString > VCLXAccessibleListBoxList::getSupportedServiceNames (void)
123 throw (RuntimeException)
125 Sequence< ::rtl::OUString > aNames = VCLXAccessibleList::getSupportedServiceNames();
126 sal_Int32 nLength = aNames.getLength();
127 aNames.realloc( nLength + 1 );
128 aNames[nLength] = ::rtl::OUString::createFromAscii(
129 "com.sun.star.accessibility.AccessibleListBoxList");
130 return aNames;
132 // -----------------------------------------------------------------------------
134 void VCLXAccessibleListBoxList::UpdateSelection_Impl()
136 uno::Any aOldValue, aNewValue;
139 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
140 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
141 Reference< XAccessible > xNewAcc;
143 ListBox* pListBox = static_cast< ListBox* >( GetWindow() );
144 if ( pListBox )
146 USHORT nPos = 0;
147 ListItems::iterator aEnd = m_aAccessibleChildren.end();
148 for ( ListItems::iterator aIter = m_aAccessibleChildren.begin();
149 aIter != aEnd; ++aIter,++nPos)
151 if ( aIter->is() )
153 VCLXAccessibleListItem* pItem = static_cast< VCLXAccessibleListItem* >( aIter->get() );
154 // Retrieve the item's index from the list entry.
155 BOOL bNowSelected = pListBox->IsEntryPosSelected (nPos);
157 if ( bNowSelected && !pItem->IsSelected() )
159 xNewAcc = *aIter;
160 aNewValue <<= xNewAcc;
161 m_nLastSelectedPos = nPos;
164 pItem->SetSelected( bNowSelected );
166 else
167 { // it could happen that a child was not created before
168 checkEntrySelected(pListBox,nPos,aNewValue,xNewAcc);
172 USHORT nCount = pListBox->GetEntryCount();
173 if ( nPos < nCount ) // here we have to check the if any other listbox entry is selected
175 for (; nPos < nCount && !checkEntrySelected(pListBox,nPos,aNewValue,xNewAcc) ;++nPos )
180 if ( xNewAcc.is() && pListBox->HasFocus() )
182 if ( m_nLastSelectedPos != LISTBOX_ENTRY_NOTFOUND )
183 aOldValue <<= getAccessibleChild( (sal_Int32)m_nLastSelectedPos );
184 aNewValue <<= xNewAcc;
188 if ( aNewValue.hasValue() || aOldValue.hasValue() )
189 NotifyAccessibleEvent(
190 AccessibleEventId::ACTIVE_DESCENDANT_CHANGED,
191 aOldValue,
192 aNewValue );
194 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
197 // -----------------------------------------------------------------------------
198 // XAccessibleSelection
199 // -----------------------------------------------------------------------------
200 void SAL_CALL VCLXAccessibleListBoxList::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
202 sal_Bool bNotify = sal_False;
205 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
206 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
208 ListBox* pListBox = static_cast< ListBox* >( GetWindow() );
209 if ( pListBox )
211 checkSelection_Impl( nChildIndex, *pListBox, sal_False );
212 pListBox->SelectEntryPos( (USHORT)nChildIndex, TRUE );
213 // call the select handler, don't handle events in this time
214 m_bDisableProcessEvent = true;
215 pListBox->Select();
216 m_bDisableProcessEvent = false;
217 bNotify = sal_True;
221 if ( bNotify )
222 UpdateSelection_Impl();
224 // -----------------------------------------------------------------------------
225 sal_Bool SAL_CALL VCLXAccessibleListBoxList::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
227 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
228 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
230 sal_Bool bRet = sal_False;
231 ListBox* pListBox = static_cast< ListBox* >( GetWindow() );
232 if ( pListBox )
234 checkSelection_Impl( nChildIndex, *pListBox, sal_False );
235 bRet = pListBox->IsEntryPosSelected( (USHORT)nChildIndex );
237 return bRet;
239 // -----------------------------------------------------------------------------
240 void SAL_CALL VCLXAccessibleListBoxList::clearAccessibleSelection( ) throw (RuntimeException)
242 sal_Bool bNotify = sal_False;
245 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
246 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
248 ListBox* pListBox = static_cast< ListBox* >( GetWindow() );
249 if ( pListBox )
251 pListBox->SetNoSelection();
252 bNotify = sal_True;
256 if ( bNotify )
257 UpdateSelection_Impl();
259 // -----------------------------------------------------------------------------
260 void SAL_CALL VCLXAccessibleListBoxList::selectAllAccessibleChildren( ) throw (RuntimeException)
262 sal_Bool bNotify = sal_False;
265 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
266 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
268 ListBox* pListBox = static_cast< ListBox* >( GetWindow() );
269 if ( pListBox )
271 USHORT nCount = pListBox->GetEntryCount();
272 for ( USHORT i = 0; i < nCount; ++i )
273 pListBox->SelectEntryPos( i, TRUE );
274 // call the select handler, don't handle events in this time
275 m_bDisableProcessEvent = true;
276 pListBox->Select();
277 m_bDisableProcessEvent = false;
278 bNotify = sal_True;
282 if ( bNotify )
283 UpdateSelection_Impl();
285 // -----------------------------------------------------------------------------
286 sal_Int32 SAL_CALL VCLXAccessibleListBoxList::getSelectedAccessibleChildCount( ) throw (RuntimeException)
288 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
289 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
291 sal_Int32 nCount = 0;
292 ListBox* pListBox = static_cast< ListBox* >( GetWindow() );
293 if ( pListBox )
294 nCount = pListBox->GetSelectEntryCount();
295 return nCount;
297 // -----------------------------------------------------------------------------
298 Reference< XAccessible > SAL_CALL VCLXAccessibleListBoxList::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
300 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
301 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
303 ListBox* pListBox = static_cast< ListBox* >( GetWindow() );
304 if ( pListBox )
306 checkSelection_Impl( nSelectedChildIndex, *pListBox, sal_True );
307 return getAccessibleChild( (sal_Int32)pListBox->GetSelectEntryPos( (USHORT)nSelectedChildIndex ) );
310 return NULL;
312 // -----------------------------------------------------------------------------
313 void SAL_CALL VCLXAccessibleListBoxList::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
315 sal_Bool bNotify = sal_False;
318 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
319 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
321 ListBox* pListBox = static_cast< ListBox* >( GetWindow() );
322 if ( pListBox )
324 checkSelection_Impl( nSelectedChildIndex, *pListBox, sal_False );
325 pListBox->SelectEntryPos( (USHORT)nSelectedChildIndex, FALSE );
326 // call the select handler, don't handle events in this time
327 m_bDisableProcessEvent = true;
328 pListBox->Select();
329 m_bDisableProcessEvent = false;
330 bNotify = sal_True;
334 if ( bNotify )
335 UpdateSelection_Impl();
337 // -----------------------------------------------------------------------------