Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / accessibility / source / extended / accessibleiconchoicectrl.cxx
blob869ec89571f46e6177c8bc3a4fe1105f35bba913
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "accessibility/extended/accessibleiconchoicectrl.hxx"
21 #include "accessibility/extended/accessibleiconchoicectrlentry.hxx"
22 #include <svtools/ivctrl.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
24 #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <unotools/accessiblestatesethelper.hxx>
27 #include <vcl/svapp.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <cppuhelper/typeprovider.hxx>
31 //........................................................................
32 namespace accessibility
34 //........................................................................
36 // class AccessibleIconChoiceCtrl ----------------------------------------------
38 using namespace ::com::sun::star::accessibility;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star;
43 // -----------------------------------------------------------------------------
44 // Ctor() and Dtor()
45 // -----------------------------------------------------------------------------
46 AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl( SvtIconChoiceCtrl& _rIconCtrl, const Reference< XAccessible >& _xParent ) :
48 VCLXAccessibleComponent( _rIconCtrl.GetWindowPeer() ),
49 m_xParent ( _xParent )
52 // -----------------------------------------------------------------------------
53 AccessibleIconChoiceCtrl::~AccessibleIconChoiceCtrl()
56 // -----------------------------------------------------------------------------
57 IMPLEMENT_FORWARD_XINTERFACE2(AccessibleIconChoiceCtrl, VCLXAccessibleComponent, AccessibleIconChoiceCtrl_BASE)
58 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleIconChoiceCtrl, VCLXAccessibleComponent, AccessibleIconChoiceCtrl_BASE)
59 // -----------------------------------------------------------------------------
60 void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
62 if ( isAlive() )
64 switch ( rVclWindowEvent.GetId() )
66 case VCLEVENT_LISTBOX_SELECT :
68 // First send an event that tells the listeners of a
69 // modified selection. The active descendant event is
70 // send after that so that the receiving AT has time to
71 // read the text or name of the active child.
72 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
73 SvtIconChoiceCtrl* pCtrl = getCtrl();
74 if ( pCtrl && pCtrl->HasFocus() )
76 SvxIconChoiceCtrlEntry* pEntry = static_cast< SvxIconChoiceCtrlEntry* >( rVclWindowEvent.GetData() );
77 if ( pEntry )
79 sal_uLong nPos = pCtrl->GetEntryListPos( pEntry );
80 Reference< XAccessible > xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, nPos, this );
81 uno::Any aOldValue, aNewValue;
82 aNewValue <<= xChild;
83 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
86 break;
88 default:
89 VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent);
93 // -----------------------------------------------------------------------------
94 // XComponent
95 // -----------------------------------------------------------------------------
96 void SAL_CALL AccessibleIconChoiceCtrl::disposing()
98 ::osl::MutexGuard aGuard( m_aMutex );
100 m_xParent = NULL;
102 // -----------------------------------------------------------------------------
103 // XServiceInfo
104 // -----------------------------------------------------------------------------
105 OUString SAL_CALL AccessibleIconChoiceCtrl::getImplementationName() throw (RuntimeException)
107 return getImplementationName_Static();
109 // -----------------------------------------------------------------------------
110 Sequence< OUString > SAL_CALL AccessibleIconChoiceCtrl::getSupportedServiceNames() throw (RuntimeException)
112 return getSupportedServiceNames_Static();
114 // -----------------------------------------------------------------------------
115 sal_Bool SAL_CALL AccessibleIconChoiceCtrl::supportsService( const OUString& _rServiceName ) throw (RuntimeException)
117 return cppu::supportsService(this, _rServiceName);
119 // -----------------------------------------------------------------------------
120 // XServiceInfo - static methods
121 // -----------------------------------------------------------------------------
122 Sequence< OUString > AccessibleIconChoiceCtrl::getSupportedServiceNames_Static(void) throw (RuntimeException)
124 Sequence< OUString > aSupported(3);
125 aSupported[0] = "com.sun.star.accessibility.AccessibleContext";
126 aSupported[1] = "com.sun.star.accessibility.AccessibleComponent";
127 aSupported[2] = "com.sun.star.awt.AccessibleIconChoiceControl";
128 return aSupported;
130 // -----------------------------------------------------------------------------
131 OUString AccessibleIconChoiceCtrl::getImplementationName_Static(void) throw (RuntimeException)
133 return OUString( "com.sun.star.comp.svtools.AccessibleIconChoiceControl" );
135 // -----------------------------------------------------------------------------
136 // XAccessible
137 // -----------------------------------------------------------------------------
138 Reference< XAccessibleContext > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleContext( ) throw (RuntimeException)
140 ensureAlive();
141 return this;
143 // -----------------------------------------------------------------------------
144 // XAccessibleContext
145 // -----------------------------------------------------------------------------
146 sal_Int32 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChildCount( ) throw (RuntimeException)
148 ::comphelper::OExternalLockGuard aGuard( this );
150 ensureAlive();
151 return getCtrl()->GetEntryCount();
153 // -----------------------------------------------------------------------------
154 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int32 i ) throw (RuntimeException, IndexOutOfBoundsException)
156 ::comphelper::OExternalLockGuard aGuard( this );
158 ensureAlive();
159 SvtIconChoiceCtrl* pCtrl = getCtrl();
160 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry(i);
161 if ( !pEntry )
162 throw RuntimeException();
164 return new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
166 // -----------------------------------------------------------------------------
167 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleParent( ) throw (RuntimeException)
169 ::osl::MutexGuard aGuard( m_aMutex );
171 ensureAlive();
172 return m_xParent;
174 // -----------------------------------------------------------------------------
175 sal_Int16 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleRole( ) throw (RuntimeException)
177 return AccessibleRole::TREE;
179 // -----------------------------------------------------------------------------
180 OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleDescription( ) throw (RuntimeException)
182 ::comphelper::OExternalLockGuard aGuard( this );
184 ensureAlive();
185 return getCtrl()->GetAccessibleDescription();
187 // -----------------------------------------------------------------------------
188 OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleName( ) throw (RuntimeException)
190 ::comphelper::OExternalLockGuard aGuard( this );
192 ensureAlive();
194 OUString sName = getCtrl()->GetAccessibleName();
195 if ( sName.isEmpty() )
196 sName = "IconChoiceControl";
197 return sName;
199 // -----------------------------------------------------------------------------
200 // XAccessibleSelection
201 // -----------------------------------------------------------------------------
202 void SAL_CALL AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
204 ::comphelper::OExternalLockGuard aGuard( this );
206 ensureAlive();
208 SvtIconChoiceCtrl* pCtrl = getCtrl();
209 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
210 if ( !pEntry )
211 throw IndexOutOfBoundsException();
213 pCtrl->SetCursor( pEntry );
215 // -----------------------------------------------------------------------------
216 sal_Bool SAL_CALL AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
218 ::comphelper::OExternalLockGuard aGuard( this );
220 ensureAlive();
222 SvtIconChoiceCtrl* pCtrl = getCtrl();
223 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
224 if ( !pEntry )
225 throw IndexOutOfBoundsException();
227 return ( pCtrl->GetCursor() == pEntry );
229 // -----------------------------------------------------------------------------
230 void SAL_CALL AccessibleIconChoiceCtrl::clearAccessibleSelection( ) throw (RuntimeException)
232 ::comphelper::OExternalLockGuard aGuard( this );
234 ensureAlive();
235 getCtrl()->SetNoSelection();
237 // -----------------------------------------------------------------------------
238 void SAL_CALL AccessibleIconChoiceCtrl::selectAllAccessibleChildren( ) throw (RuntimeException)
240 ::comphelper::OExternalLockGuard aGuard( this );
242 ensureAlive();
244 SvtIconChoiceCtrl* pCtrl = getCtrl();
245 sal_Int32 nCount = pCtrl->GetEntryCount();
246 for ( sal_Int32 i = 0; i < nCount; ++i )
248 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
249 if ( pCtrl->GetCursor() != pEntry )
250 pCtrl->SetCursor( pEntry );
253 // -----------------------------------------------------------------------------
254 sal_Int32 SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( ) throw (RuntimeException)
256 ::comphelper::OExternalLockGuard aGuard( this );
258 ensureAlive();
260 sal_Int32 nSelCount = 0;
261 SvtIconChoiceCtrl* pCtrl = getCtrl();
262 sal_Int32 nCount = pCtrl->GetEntryCount();
263 for ( sal_Int32 i = 0; i < nCount; ++i )
265 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
266 if ( pCtrl->GetCursor() == pEntry )
267 ++nSelCount;
270 return nSelCount;
272 // -----------------------------------------------------------------------------
273 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
275 ::comphelper::OExternalLockGuard aGuard( this );
277 ensureAlive();
279 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
280 throw IndexOutOfBoundsException();
282 Reference< XAccessible > xChild;
283 sal_Int32 nSelCount = 0;
284 SvtIconChoiceCtrl* pCtrl = getCtrl();
285 sal_Int32 nCount = pCtrl->GetEntryCount();
286 for ( sal_Int32 i = 0; i < nCount; ++i )
288 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
289 if ( pCtrl->GetCursor() == pEntry )
290 ++nSelCount;
292 if ( nSelCount == ( nSelectedChildIndex + 1 ) )
294 xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
295 break;
299 return xChild;
301 // -----------------------------------------------------------------------------
302 void SAL_CALL AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
304 ::comphelper::OExternalLockGuard aGuard( this );
306 ensureAlive();
308 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getAccessibleChildCount() )
309 throw IndexOutOfBoundsException();
311 Reference< XAccessible > xChild;
312 sal_Int32 nSelCount = 0;
313 SvtIconChoiceCtrl* pCtrl = getCtrl();
314 sal_Int32 nCount = pCtrl->GetEntryCount();
315 bool bFound = false;
316 for ( sal_Int32 i = 0; i < nCount; ++i )
318 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
319 if ( pEntry->IsSelected() )
321 ++nSelCount;
322 if ( i == nSelectedChildIndex )
323 bFound = true;
327 // if only one entry is selected and its index is choosen to deselect -> no selection anymore
328 if ( 1 == nSelCount && bFound )
329 pCtrl->SetNoSelection();
331 // -----------------------------------------------------------------------------
332 void AccessibleIconChoiceCtrl::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
334 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
335 if ( isAlive() )
337 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
338 rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
339 rStateSet.AddState( AccessibleStateType::SELECTABLE );
342 // -----------------------------------------------------------------------------
343 SvtIconChoiceCtrl* AccessibleIconChoiceCtrl::getCtrl()
345 return static_cast<SvtIconChoiceCtrl*>(GetWindow());
348 //........................................................................
349 }// namespace accessibility
350 //........................................................................
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */