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 <extended/accessibleiconchoicectrl.hxx>
21 #include <extended/accessibleiconchoicectrlentry.hxx>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
24 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <unotools/accessiblestatesethelper.hxx>
27 #include <vcl/ivctrl.hxx>
28 #include <cppuhelper/supportsservice.hxx>
31 namespace accessibility
35 // class AccessibleIconChoiceCtrl ----------------------------------------------
37 using namespace ::com::sun::star::accessibility
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star
;
45 AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl( SvtIconChoiceCtrl
const & _rIconCtrl
, const Reference
< XAccessible
>& _xParent
) :
46 VCLXAccessibleComponent( _rIconCtrl
.GetWindowPeer() ),
47 m_xParent ( _xParent
)
51 IMPLEMENT_FORWARD_XINTERFACE2(AccessibleIconChoiceCtrl
, VCLXAccessibleComponent
, AccessibleIconChoiceCtrl_BASE
)
52 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleIconChoiceCtrl
, VCLXAccessibleComponent
, AccessibleIconChoiceCtrl_BASE
)
54 void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
58 switch ( rVclWindowEvent
.GetId() )
60 case VclEventId::ListboxSelect
:
62 // First send an event that tells the listeners of a
63 // modified selection. The active descendant event is
64 // send after that so that the receiving AT has time to
65 // read the text or name of the active child.
66 // NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
68 if ( getCtrl() && getCtrl()->HasFocus() )
70 SvxIconChoiceCtrlEntry
* pEntry
= static_cast< SvxIconChoiceCtrlEntry
* >( rVclWindowEvent
.GetData() );
73 sal_Int32 nPos
= getCtrl()->GetEntryListPos( pEntry
);
74 Reference
< XAccessible
> xChild
= new AccessibleIconChoiceCtrlEntry( *getCtrl(), nPos
, this );
75 uno::Any aOldValue
, aNewValue
;
77 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOldValue
, aNewValue
);
79 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, aOldValue
, aNewValue
);
85 case VclEventId::WindowGetFocus
:
87 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
88 if ( pCtrl
&& pCtrl
->HasFocus() )
90 SvxIconChoiceCtrlEntry
* pEntry
= static_cast< SvxIconChoiceCtrlEntry
* >( rVclWindowEvent
.GetData() );
91 if ( pEntry
== nullptr )
93 pEntry
= getCtrl()->GetSelectedEntry();
97 sal_Int32 nPos
= pCtrl
->GetEntryListPos( pEntry
);
98 Reference
< XAccessible
> xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, nPos
, this );
99 uno::Any aOldValue
, aNewValue
;
100 aNewValue
<<= xChild
;
101 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOldValue
, aNewValue
);
102 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, aOldValue
, aNewValue
);
108 VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent
);
115 void SAL_CALL
AccessibleIconChoiceCtrl::disposing()
117 ::osl::MutexGuard
aGuard( m_aMutex
);
124 OUString SAL_CALL
AccessibleIconChoiceCtrl::getImplementationName()
126 return "com.sun.star.comp.svtools.AccessibleIconChoiceControl";
129 Sequence
< OUString
> SAL_CALL
AccessibleIconChoiceCtrl::getSupportedServiceNames()
131 return {"com.sun.star.accessibility.AccessibleContext",
132 "com.sun.star.accessibility.AccessibleComponent",
133 "com.sun.star.awt.AccessibleIconChoiceControl"};
136 sal_Bool SAL_CALL
AccessibleIconChoiceCtrl::supportsService( const OUString
& _rServiceName
)
138 return cppu::supportsService(this, _rServiceName
);
143 Reference
< XAccessibleContext
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleContext( )
149 // XAccessibleContext
151 sal_Int32 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChildCount( )
153 ::comphelper::OExternalLockGuard
aGuard( this );
155 return getCtrl()->GetEntryCount();
158 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int32 i
)
160 ::comphelper::OExternalLockGuard
aGuard( this );
162 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
163 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry(i
);
165 throw RuntimeException();
167 return new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
170 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleParent( )
172 ::osl::MutexGuard
aGuard( m_aMutex
);
178 sal_Int16 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleRole( )
180 //return AccessibleRole::TREE;
181 return AccessibleRole::LIST
;
184 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleDescription( )
186 ::comphelper::OExternalLockGuard
aGuard( this );
188 return getCtrl()->GetAccessibleDescription();
191 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleName( )
193 ::comphelper::OExternalLockGuard
aGuard( this );
195 OUString sName
= getCtrl()->GetAccessibleName();
196 if ( sName
.isEmpty() )
197 sName
= "IconChoiceControl";
201 // XAccessibleSelection
203 void SAL_CALL
AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int32 nChildIndex
)
205 ::comphelper::OExternalLockGuard
aGuard( this );
207 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
208 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
210 throw IndexOutOfBoundsException();
212 pCtrl
->SetCursor( pEntry
);
215 sal_Bool SAL_CALL
AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int32 nChildIndex
)
217 ::comphelper::OExternalLockGuard
aGuard( this );
219 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
220 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
222 throw IndexOutOfBoundsException();
224 return ( pCtrl
->GetCursor() == pEntry
);
227 void SAL_CALL
AccessibleIconChoiceCtrl::clearAccessibleSelection( )
229 ::comphelper::OExternalLockGuard
aGuard( this );
230 getCtrl()->SetNoSelection();
233 void SAL_CALL
AccessibleIconChoiceCtrl::selectAllAccessibleChildren( )
235 ::comphelper::OExternalLockGuard
aGuard( this );
237 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
238 sal_Int32 nCount
= pCtrl
->GetEntryCount();
239 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
241 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
242 if ( pCtrl
->GetCursor() != pEntry
)
243 pCtrl
->SetCursor( pEntry
);
247 sal_Int32 SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( )
249 ::comphelper::OExternalLockGuard
aGuard( this );
251 sal_Int32 nSelCount
= 0;
252 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
253 sal_Int32 nCount
= pCtrl
->GetEntryCount();
254 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
256 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
257 if ( pCtrl
->GetCursor() == pEntry
)
264 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
266 ::comphelper::OExternalLockGuard
aGuard( this );
268 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
269 throw IndexOutOfBoundsException();
271 Reference
< XAccessible
> xChild
;
272 sal_Int32 nSelCount
= 0;
273 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
274 sal_Int32 nCount
= pCtrl
->GetEntryCount();
275 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
277 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
278 if ( pCtrl
->GetCursor() == pEntry
)
281 if ( nSelCount
== ( nSelectedChildIndex
+ 1 ) )
283 xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
291 void SAL_CALL
AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int32 nSelectedChildIndex
)
293 ::comphelper::OExternalLockGuard
aGuard( this );
295 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getAccessibleChildCount() )
296 throw IndexOutOfBoundsException();
298 sal_Int32 nSelCount
= 0;
299 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
300 sal_Int32 nCount
= pCtrl
->GetEntryCount();
302 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
304 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
305 if ( pEntry
->IsSelected() )
308 if ( i
== nSelectedChildIndex
)
313 // if only one entry is selected and its index is chosen to deselect -> no selection anymore
314 if ( nSelCount
== 1 && bFound
)
315 pCtrl
->SetNoSelection();
318 void AccessibleIconChoiceCtrl::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
320 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
323 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
324 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
325 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
329 VclPtr
< SvtIconChoiceCtrl
> AccessibleIconChoiceCtrl::getCtrl() const
331 return GetAs
<SvtIconChoiceCtrl
>();
334 }// namespace accessibility
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */