1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
32 namespace accessibility
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
;
46 AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl( SvtIconChoiceCtrl
& _rIconCtrl
, const Reference
< XAccessible
>& _xParent
) :
48 VCLXAccessibleComponent( _rIconCtrl
.GetWindowPeer() ),
49 m_xParent ( _xParent
)
53 AccessibleIconChoiceCtrl::~AccessibleIconChoiceCtrl()
57 IMPLEMENT_FORWARD_XINTERFACE2(AccessibleIconChoiceCtrl
, VCLXAccessibleComponent
, AccessibleIconChoiceCtrl_BASE
)
58 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleIconChoiceCtrl
, VCLXAccessibleComponent
, AccessibleIconChoiceCtrl_BASE
)
60 void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
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() );
74 if ( getCtrl() && getCtrl()->HasFocus() )
76 SvxIconChoiceCtrlEntry
* pEntry
= static_cast< SvxIconChoiceCtrlEntry
* >( rVclWindowEvent
.GetData() );
79 sal_uLong nPos
= getCtrl()->GetEntryListPos( pEntry
);
80 Reference
< XAccessible
> xChild
= new AccessibleIconChoiceCtrlEntry( *getCtrl(), nPos
, this );
81 uno::Any aOldValue
, aNewValue
;
83 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOldValue
, aNewValue
);
85 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, aOldValue
, aNewValue
);
91 case VCLEVENT_WINDOW_GETFOCUS
:
93 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
94 if ( pCtrl
&& pCtrl
->HasFocus() )
96 SvxIconChoiceCtrlEntry
* pEntry
= static_cast< SvxIconChoiceCtrlEntry
* >( rVclWindowEvent
.GetData() );
100 pEntry
= getCtrl()->GetSelectedEntry ( nPos
);
104 sal_uLong nPos
= pCtrl
->GetEntryListPos( pEntry
);
105 Reference
< XAccessible
> xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, nPos
, this );
106 uno::Any aOldValue
, aNewValue
;
107 aNewValue
<<= xChild
;
108 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOldValue
, aNewValue
);
109 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, aOldValue
, aNewValue
);
115 VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent
);
122 void SAL_CALL
AccessibleIconChoiceCtrl::disposing()
124 ::osl::MutexGuard
aGuard( m_aMutex
);
131 OUString SAL_CALL
AccessibleIconChoiceCtrl::getImplementationName() throw (RuntimeException
, std::exception
)
133 return getImplementationName_Static();
136 Sequence
< OUString
> SAL_CALL
AccessibleIconChoiceCtrl::getSupportedServiceNames() throw (RuntimeException
, std::exception
)
138 return getSupportedServiceNames_Static();
141 sal_Bool SAL_CALL
AccessibleIconChoiceCtrl::supportsService( const OUString
& _rServiceName
) throw (RuntimeException
, std::exception
)
143 return cppu::supportsService(this, _rServiceName
);
146 // XServiceInfo - static methods
148 Sequence
< OUString
> AccessibleIconChoiceCtrl::getSupportedServiceNames_Static() throw (RuntimeException
)
150 Sequence
< OUString
> aSupported(3);
151 aSupported
[0] = "com.sun.star.accessibility.AccessibleContext";
152 aSupported
[1] = "com.sun.star.accessibility.AccessibleComponent";
153 aSupported
[2] = "com.sun.star.awt.AccessibleIconChoiceControl";
157 OUString
AccessibleIconChoiceCtrl::getImplementationName_Static() throw (RuntimeException
)
159 return OUString( "com.sun.star.comp.svtools.AccessibleIconChoiceControl" );
164 Reference
< XAccessibleContext
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleContext( ) throw (RuntimeException
, std::exception
)
170 // XAccessibleContext
172 sal_Int32 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChildCount( ) throw (RuntimeException
, std::exception
)
174 ::comphelper::OExternalLockGuard
aGuard( this );
177 return getCtrl()->GetEntryCount();
180 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int32 i
) throw (RuntimeException
, IndexOutOfBoundsException
, std::exception
)
182 ::comphelper::OExternalLockGuard
aGuard( this );
185 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
186 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry(i
);
188 throw RuntimeException();
190 return new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
193 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleParent( ) throw (RuntimeException
, std::exception
)
195 ::osl::MutexGuard
aGuard( m_aMutex
);
201 sal_Int16 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleRole( ) throw (RuntimeException
, std::exception
)
203 //return AccessibleRole::TREE;
204 return AccessibleRole::LIST
;
207 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleDescription( ) throw (RuntimeException
, std::exception
)
209 ::comphelper::OExternalLockGuard
aGuard( this );
212 return getCtrl()->GetAccessibleDescription();
215 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleName( ) throw (RuntimeException
, std::exception
)
217 ::comphelper::OExternalLockGuard
aGuard( this );
221 OUString sName
= getCtrl()->GetAccessibleName();
222 if ( sName
.isEmpty() )
223 sName
= "IconChoiceControl";
227 // XAccessibleSelection
229 void SAL_CALL
AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
231 ::comphelper::OExternalLockGuard
aGuard( this );
235 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
236 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
238 throw IndexOutOfBoundsException();
240 pCtrl
->SetCursor( pEntry
);
243 sal_Bool SAL_CALL
AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
245 ::comphelper::OExternalLockGuard
aGuard( this );
249 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
250 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
252 throw IndexOutOfBoundsException();
254 return ( pCtrl
->GetCursor() == pEntry
);
257 void SAL_CALL
AccessibleIconChoiceCtrl::clearAccessibleSelection( ) throw (RuntimeException
, std::exception
)
259 ::comphelper::OExternalLockGuard
aGuard( this );
262 getCtrl()->SetNoSelection();
265 void SAL_CALL
AccessibleIconChoiceCtrl::selectAllAccessibleChildren( ) throw (RuntimeException
, std::exception
)
267 ::comphelper::OExternalLockGuard
aGuard( this );
271 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
272 sal_Int32 nCount
= pCtrl
->GetEntryCount();
273 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
275 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
276 if ( pCtrl
->GetCursor() != pEntry
)
277 pCtrl
->SetCursor( pEntry
);
281 sal_Int32 SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( ) throw (RuntimeException
, std::exception
)
283 ::comphelper::OExternalLockGuard
aGuard( this );
287 sal_Int32 nSelCount
= 0;
288 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
289 sal_Int32 nCount
= pCtrl
->GetEntryCount();
290 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
292 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
293 if ( pCtrl
->GetCursor() == pEntry
)
300 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
302 ::comphelper::OExternalLockGuard
aGuard( this );
306 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
307 throw IndexOutOfBoundsException();
309 Reference
< XAccessible
> xChild
;
310 sal_Int32 nSelCount
= 0;
311 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
312 sal_Int32 nCount
= pCtrl
->GetEntryCount();
313 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
315 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
316 if ( pCtrl
->GetCursor() == pEntry
)
319 if ( nSelCount
== ( nSelectedChildIndex
+ 1 ) )
321 xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
329 void SAL_CALL
AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
331 ::comphelper::OExternalLockGuard
aGuard( this );
335 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getAccessibleChildCount() )
336 throw IndexOutOfBoundsException();
338 Reference
< XAccessible
> xChild
;
339 sal_Int32 nSelCount
= 0;
340 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
341 sal_Int32 nCount
= pCtrl
->GetEntryCount();
343 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
345 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
346 if ( pEntry
->IsSelected() )
349 if ( i
== nSelectedChildIndex
)
354 // if only one entry is selected and its index is chosen to deselect -> no selection anymore
355 if ( 1 == nSelCount
&& bFound
)
356 pCtrl
->SetNoSelection();
359 void AccessibleIconChoiceCtrl::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
361 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
364 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
365 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
366 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
370 VclPtr
< SvtIconChoiceCtrl
> AccessibleIconChoiceCtrl::getCtrl()
372 return GetAs
<SvtIconChoiceCtrl
>();
375 }// namespace accessibility
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */