update dev300-m58
[ooovba.git] / accessibility / source / extended / accessibleiconchoicectrl.cxx
blob7687b16a5d755a7ac3a24477426813bf0eb45ba2
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: accessibleiconchoicectrl.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/extended/accessibleiconchoicectrl.hxx"
34 #include "accessibility/extended/accessibleiconchoicectrlentry.hxx"
35 #include <svtools/ivctrl.hxx>
36 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
38 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 #include <unotools/accessiblestatesethelper.hxx>
40 #include <tools/debug.hxx>
41 #include <vcl/svapp.hxx>
42 #include <cppuhelper/typeprovider.hxx>
44 //........................................................................
45 namespace accessibility
47 //........................................................................
49 // class AccessibleIconChoiceCtrl ----------------------------------------------
51 using namespace ::com::sun::star::accessibility;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star;
56 DBG_NAME(AccessibleIconChoiceCtrl)
58 // -----------------------------------------------------------------------------
59 // Ctor() and Dtor()
60 // -----------------------------------------------------------------------------
61 AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl( SvtIconChoiceCtrl& _rIconCtrl, const Reference< XAccessible >& _xParent ) :
63 VCLXAccessibleComponent( _rIconCtrl.GetWindowPeer() ),
64 m_xParent ( _xParent )
66 DBG_CTOR( AccessibleIconChoiceCtrl, NULL );
68 // -----------------------------------------------------------------------------
69 AccessibleIconChoiceCtrl::~AccessibleIconChoiceCtrl()
71 DBG_DTOR( AccessibleIconChoiceCtrl, NULL );
73 // -----------------------------------------------------------------------------
74 IMPLEMENT_FORWARD_XINTERFACE2(AccessibleIconChoiceCtrl, VCLXAccessibleComponent, AccessibleIconChoiceCtrl_BASE)
75 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleIconChoiceCtrl, VCLXAccessibleComponent, AccessibleIconChoiceCtrl_BASE)
76 // -----------------------------------------------------------------------------
77 void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
79 if ( isAlive() )
81 switch ( rVclWindowEvent.GetId() )
83 case VCLEVENT_LISTBOX_SELECT :
85 // First send an event that tells the listeners of a
86 // modified selection. The active descendant event is
87 // send after that so that the receiving AT has time to
88 // read the text or name of the active child.
89 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
90 SvtIconChoiceCtrl* pCtrl = getCtrl();
91 if ( pCtrl && pCtrl->HasFocus() )
93 SvxIconChoiceCtrlEntry* pEntry = static_cast< SvxIconChoiceCtrlEntry* >( rVclWindowEvent.GetData() );
94 if ( pEntry )
96 ULONG nPos = pCtrl->GetEntryListPos( pEntry );
97 Reference< XAccessible > xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, nPos, this );
98 uno::Any aOldValue, aNewValue;
99 aNewValue <<= xChild;
100 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
103 break;
105 default:
106 VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent);
110 // -----------------------------------------------------------------------------
111 // XComponent
112 // -----------------------------------------------------------------------------
113 void SAL_CALL AccessibleIconChoiceCtrl::disposing()
115 ::osl::MutexGuard aGuard( m_aMutex );
117 m_xParent = NULL;
119 // -----------------------------------------------------------------------------
120 // XServiceInfo
121 // -----------------------------------------------------------------------------
122 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrl::getImplementationName() throw (RuntimeException)
124 return getImplementationName_Static();
126 // -----------------------------------------------------------------------------
127 Sequence< ::rtl::OUString > SAL_CALL AccessibleIconChoiceCtrl::getSupportedServiceNames() throw (RuntimeException)
129 return getSupportedServiceNames_Static();
131 // -----------------------------------------------------------------------------
132 sal_Bool SAL_CALL AccessibleIconChoiceCtrl::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
134 Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
135 const ::rtl::OUString* pSupported = aSupported.getConstArray();
136 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
137 for ( ; pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported )
140 return pSupported != pEnd;
142 // -----------------------------------------------------------------------------
143 // XServiceInfo - static methods
144 // -----------------------------------------------------------------------------
145 Sequence< ::rtl::OUString > AccessibleIconChoiceCtrl::getSupportedServiceNames_Static(void) throw (RuntimeException)
147 Sequence< ::rtl::OUString > aSupported(3);
148 aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleContext") );
149 aSupported[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleComponent") );
150 aSupported[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.AccessibleIconChoiceControl") );
151 return aSupported;
153 // -----------------------------------------------------------------------------
154 ::rtl::OUString AccessibleIconChoiceCtrl::getImplementationName_Static(void) throw (RuntimeException)
156 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.svtools.AccessibleIconChoiceControl") );
158 // -----------------------------------------------------------------------------
159 // XAccessible
160 // -----------------------------------------------------------------------------
161 Reference< XAccessibleContext > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleContext( ) throw (RuntimeException)
163 ensureAlive();
164 return this;
166 // -----------------------------------------------------------------------------
167 // XAccessibleContext
168 // -----------------------------------------------------------------------------
169 sal_Int32 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChildCount( ) throw (RuntimeException)
171 ::comphelper::OExternalLockGuard aGuard( this );
173 ensureAlive();
174 return getCtrl()->GetEntryCount();
176 // -----------------------------------------------------------------------------
177 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int32 i ) throw (RuntimeException, IndexOutOfBoundsException)
179 ::comphelper::OExternalLockGuard aGuard( this );
181 ensureAlive();
182 SvtIconChoiceCtrl* pCtrl = getCtrl();
183 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry(i);
184 if ( !pEntry )
185 throw RuntimeException();
187 return new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
189 // -----------------------------------------------------------------------------
190 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleParent( ) throw (RuntimeException)
192 ::osl::MutexGuard aGuard( m_aMutex );
194 ensureAlive();
195 return m_xParent;
197 // -----------------------------------------------------------------------------
198 sal_Int16 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleRole( ) throw (RuntimeException)
200 return AccessibleRole::TREE;
202 // -----------------------------------------------------------------------------
203 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleDescription( ) throw (RuntimeException)
205 ::comphelper::OExternalLockGuard aGuard( this );
207 ensureAlive();
208 return getCtrl()->GetAccessibleDescription();
210 // -----------------------------------------------------------------------------
211 ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleName( ) throw (RuntimeException)
213 ::comphelper::OExternalLockGuard aGuard( this );
215 ensureAlive();
217 ::rtl::OUString sName = getCtrl()->GetAccessibleName();
218 if ( sName.getLength() == 0 )
219 sName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IconChoiceControl" ) );
220 return sName;
222 // -----------------------------------------------------------------------------
223 // XAccessibleSelection
224 // -----------------------------------------------------------------------------
225 void SAL_CALL AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
227 ::comphelper::OExternalLockGuard aGuard( this );
229 ensureAlive();
231 SvtIconChoiceCtrl* pCtrl = getCtrl();
232 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
233 if ( !pEntry )
234 throw IndexOutOfBoundsException();
236 pCtrl->SetCursor( pEntry );
238 // -----------------------------------------------------------------------------
239 sal_Bool SAL_CALL AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
241 ::comphelper::OExternalLockGuard aGuard( this );
243 ensureAlive();
245 SvtIconChoiceCtrl* pCtrl = getCtrl();
246 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
247 if ( !pEntry )
248 throw IndexOutOfBoundsException();
250 return ( pCtrl->GetCursor() == pEntry );
252 // -----------------------------------------------------------------------------
253 void SAL_CALL AccessibleIconChoiceCtrl::clearAccessibleSelection( ) throw (RuntimeException)
255 ::comphelper::OExternalLockGuard aGuard( this );
257 ensureAlive();
258 getCtrl()->SetNoSelection();
260 // -----------------------------------------------------------------------------
261 void SAL_CALL AccessibleIconChoiceCtrl::selectAllAccessibleChildren( ) throw (RuntimeException)
263 ::comphelper::OExternalLockGuard aGuard( this );
265 ensureAlive();
267 sal_Int32 i, nCount = 0;
268 SvtIconChoiceCtrl* pCtrl = getCtrl();
269 nCount = pCtrl->GetEntryCount();
270 for ( i = 0; i < nCount; ++i )
272 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
273 if ( pCtrl->GetCursor() != pEntry )
274 pCtrl->SetCursor( pEntry );
277 // -----------------------------------------------------------------------------
278 sal_Int32 SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( ) throw (RuntimeException)
280 ::comphelper::OExternalLockGuard aGuard( this );
282 ensureAlive();
284 sal_Int32 i, nSelCount = 0, nCount = 0;
285 SvtIconChoiceCtrl* pCtrl = getCtrl();
286 nCount = pCtrl->GetEntryCount();
287 for ( i = 0; i < nCount; ++i )
289 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
290 if ( pCtrl->GetCursor() == pEntry )
291 ++nSelCount;
294 return nSelCount;
296 // -----------------------------------------------------------------------------
297 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
299 ::comphelper::OExternalLockGuard aGuard( this );
301 ensureAlive();
303 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
304 throw IndexOutOfBoundsException();
306 Reference< XAccessible > xChild;
307 sal_Int32 i, nSelCount = 0, nCount = 0;
308 SvtIconChoiceCtrl* pCtrl = getCtrl();
309 nCount = pCtrl->GetEntryCount();
310 for ( i = 0; i < nCount; ++i )
312 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
313 if ( pCtrl->GetCursor() == pEntry )
314 ++nSelCount;
316 if ( nSelCount == ( nSelectedChildIndex + 1 ) )
318 xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
319 break;
323 return xChild;
325 // -----------------------------------------------------------------------------
326 void SAL_CALL AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
328 ::comphelper::OExternalLockGuard aGuard( this );
330 ensureAlive();
332 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getAccessibleChildCount() )
333 throw IndexOutOfBoundsException();
335 Reference< XAccessible > xChild;
336 sal_Int32 i, nSelCount = 0, nCount = 0;
337 SvtIconChoiceCtrl* pCtrl = getCtrl();
338 nCount = pCtrl->GetEntryCount();
339 bool bFound = false;
340 for ( i = 0; i < nCount; ++i )
342 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
343 if ( pEntry->IsSelected() )
345 ++nSelCount;
346 if ( i == nSelectedChildIndex )
347 bFound = true;
351 // if only one entry is selected and its index is choosen to deselect -> no selection anymore
352 if ( 1 == nSelCount && bFound )
353 pCtrl->SetNoSelection();
355 // -----------------------------------------------------------------------------
356 void AccessibleIconChoiceCtrl::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
358 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
359 if ( isAlive() )
361 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
362 rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
363 rStateSet.AddState( AccessibleStateType::SELECTABLE );
366 // -----------------------------------------------------------------------------
367 SvtIconChoiceCtrl* AccessibleIconChoiceCtrl::getCtrl()
369 return static_cast<SvtIconChoiceCtrl*>(GetWindow());
372 //........................................................................
373 }// namespace accessibility
374 //........................................................................