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 <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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27 #include <unotools/accessiblestatesethelper.hxx>
28 #include <vcl/svapp.hxx>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <cppuhelper/typeprovider.hxx>
33 namespace accessibility
37 // class AccessibleIconChoiceCtrl ----------------------------------------------
39 using namespace ::com::sun::star::accessibility
;
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star
;
47 AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl( SvtIconChoiceCtrl
const & _rIconCtrl
, const Reference
< XAccessible
>& _xParent
) :
48 VCLXAccessibleComponent( _rIconCtrl
.GetWindowPeer() ),
49 m_xParent ( _xParent
)
53 IMPLEMENT_FORWARD_XINTERFACE2(AccessibleIconChoiceCtrl
, VCLXAccessibleComponent
, AccessibleIconChoiceCtrl_BASE
)
54 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleIconChoiceCtrl
, VCLXAccessibleComponent
, AccessibleIconChoiceCtrl_BASE
)
56 void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
60 switch ( rVclWindowEvent
.GetId() )
62 case VclEventId::ListboxSelect
:
64 // First send an event that tells the listeners of a
65 // modified selection. The active descendant event is
66 // send after that so that the receiving AT has time to
67 // read the text or name of the active child.
68 // NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
70 if ( getCtrl() && getCtrl()->HasFocus() )
72 SvxIconChoiceCtrlEntry
* pEntry
= static_cast< SvxIconChoiceCtrlEntry
* >( rVclWindowEvent
.GetData() );
75 sal_uLong nPos
= getCtrl()->GetEntryListPos( pEntry
);
76 Reference
< XAccessible
> xChild
= new AccessibleIconChoiceCtrlEntry( *getCtrl(), nPos
, this );
77 uno::Any aOldValue
, aNewValue
;
79 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOldValue
, aNewValue
);
81 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, aOldValue
, aNewValue
);
87 case VclEventId::WindowGetFocus
:
89 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
90 if ( pCtrl
&& pCtrl
->HasFocus() )
92 SvxIconChoiceCtrlEntry
* pEntry
= static_cast< SvxIconChoiceCtrlEntry
* >( rVclWindowEvent
.GetData() );
93 if ( pEntry
== nullptr )
95 pEntry
= getCtrl()->GetSelectedEntry();
99 sal_uLong nPos
= pCtrl
->GetEntryListPos( pEntry
);
100 Reference
< XAccessible
> xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, nPos
, this );
101 uno::Any aOldValue
, aNewValue
;
102 aNewValue
<<= xChild
;
103 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOldValue
, aNewValue
);
104 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, aOldValue
, aNewValue
);
110 VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent
);
117 void SAL_CALL
AccessibleIconChoiceCtrl::disposing()
119 ::osl::MutexGuard
aGuard( m_aMutex
);
126 OUString SAL_CALL
AccessibleIconChoiceCtrl::getImplementationName()
128 return OUString( "com.sun.star.comp.svtools.AccessibleIconChoiceControl" );
131 Sequence
< OUString
> SAL_CALL
AccessibleIconChoiceCtrl::getSupportedServiceNames()
133 return {"com.sun.star.accessibility.AccessibleContext",
134 "com.sun.star.accessibility.AccessibleComponent",
135 "com.sun.star.awt.AccessibleIconChoiceControl"};
138 sal_Bool SAL_CALL
AccessibleIconChoiceCtrl::supportsService( const OUString
& _rServiceName
)
140 return cppu::supportsService(this, _rServiceName
);
145 Reference
< XAccessibleContext
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleContext( )
151 // XAccessibleContext
153 sal_Int32 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChildCount( )
155 ::comphelper::OExternalLockGuard
aGuard( this );
157 return getCtrl()->GetEntryCount();
160 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int32 i
)
162 ::comphelper::OExternalLockGuard
aGuard( this );
164 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
165 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry(i
);
167 throw RuntimeException();
169 return new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
172 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleParent( )
174 ::osl::MutexGuard
aGuard( m_aMutex
);
180 sal_Int16 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleRole( )
182 //return AccessibleRole::TREE;
183 return AccessibleRole::LIST
;
186 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleDescription( )
188 ::comphelper::OExternalLockGuard
aGuard( this );
190 return getCtrl()->GetAccessibleDescription();
193 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleName( )
195 ::comphelper::OExternalLockGuard
aGuard( this );
197 OUString sName
= getCtrl()->GetAccessibleName();
198 if ( sName
.isEmpty() )
199 sName
= "IconChoiceControl";
203 // XAccessibleSelection
205 void SAL_CALL
AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int32 nChildIndex
)
207 ::comphelper::OExternalLockGuard
aGuard( this );
209 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
210 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
212 throw IndexOutOfBoundsException();
214 pCtrl
->SetCursor( pEntry
);
217 sal_Bool SAL_CALL
AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int32 nChildIndex
)
219 ::comphelper::OExternalLockGuard
aGuard( this );
221 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
222 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
224 throw IndexOutOfBoundsException();
226 return ( pCtrl
->GetCursor() == pEntry
);
229 void SAL_CALL
AccessibleIconChoiceCtrl::clearAccessibleSelection( )
231 ::comphelper::OExternalLockGuard
aGuard( this );
232 getCtrl()->SetNoSelection();
235 void SAL_CALL
AccessibleIconChoiceCtrl::selectAllAccessibleChildren( )
237 ::comphelper::OExternalLockGuard
aGuard( this );
239 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
240 sal_Int32 nCount
= pCtrl
->GetEntryCount();
241 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
243 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
244 if ( pCtrl
->GetCursor() != pEntry
)
245 pCtrl
->SetCursor( pEntry
);
249 sal_Int32 SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( )
251 ::comphelper::OExternalLockGuard
aGuard( this );
253 sal_Int32 nSelCount
= 0;
254 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
255 sal_Int32 nCount
= pCtrl
->GetEntryCount();
256 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
258 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
259 if ( pCtrl
->GetCursor() == pEntry
)
266 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
268 ::comphelper::OExternalLockGuard
aGuard( this );
270 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
271 throw IndexOutOfBoundsException();
273 Reference
< XAccessible
> xChild
;
274 sal_Int32 nSelCount
= 0;
275 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
276 sal_Int32 nCount
= pCtrl
->GetEntryCount();
277 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
279 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
280 if ( pCtrl
->GetCursor() == pEntry
)
283 if ( nSelCount
== ( nSelectedChildIndex
+ 1 ) )
285 xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
293 void SAL_CALL
AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int32 nSelectedChildIndex
)
295 ::comphelper::OExternalLockGuard
aGuard( this );
297 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getAccessibleChildCount() )
298 throw IndexOutOfBoundsException();
300 sal_Int32 nSelCount
= 0;
301 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
302 sal_Int32 nCount
= pCtrl
->GetEntryCount();
304 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
306 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
307 if ( pEntry
->IsSelected() )
310 if ( i
== nSelectedChildIndex
)
315 // if only one entry is selected and its index is chosen to deselect -> no selection anymore
316 if ( nSelCount
== 1 && bFound
)
317 pCtrl
->SetNoSelection();
320 void AccessibleIconChoiceCtrl::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
322 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
325 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
326 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
327 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
331 VclPtr
< SvtIconChoiceCtrl
> AccessibleIconChoiceCtrl::getCtrl()
333 return GetAs
<SvtIconChoiceCtrl
>();
336 }// namespace accessibility
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */