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 <comphelper/accessiblecontexthelper.hxx>
27 #include <vcl/toolkit/ivctrl.hxx>
30 namespace accessibility
34 // class AccessibleIconChoiceCtrl ----------------------------------------------
36 using namespace ::com::sun::star::accessibility
;
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star
;
44 AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl(SvtIconChoiceCtrl
& _rIconCtrl
,
45 const Reference
<XAccessible
>& _xParent
)
46 : ImplInheritanceHelper(&_rIconCtrl
)
51 void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
56 switch ( rVclWindowEvent
.GetId() )
58 case VclEventId::ListboxSelect
:
60 // First send an event that tells the listeners of a
61 // modified selection. The active descendant event is
62 // send after that so that the receiving AT has time to
63 // read the text or name of the active child.
64 // NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
66 if ( getCtrl() && getCtrl()->HasFocus() )
68 SvxIconChoiceCtrlEntry
* pEntry
= static_cast< SvxIconChoiceCtrlEntry
* >( rVclWindowEvent
.GetData() );
71 sal_Int32 nPos
= getCtrl()->GetEntryListPos( pEntry
);
72 Reference
< XAccessible
> xChild
= new AccessibleIconChoiceCtrlEntry( *getCtrl(), nPos
, this );
73 uno::Any aOldValue
, aNewValue
;
75 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOldValue
, aNewValue
);
77 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, aOldValue
, aNewValue
);
83 case VclEventId::WindowGetFocus
:
85 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
86 if ( pCtrl
&& pCtrl
->HasFocus() )
88 SvxIconChoiceCtrlEntry
* pEntry
= static_cast< SvxIconChoiceCtrlEntry
* >( rVclWindowEvent
.GetData() );
89 if ( pEntry
== nullptr )
91 pEntry
= getCtrl()->GetSelectedEntry();
95 sal_Int32 nPos
= pCtrl
->GetEntryListPos( pEntry
);
96 Reference
< XAccessible
> xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, nPos
, this );
97 uno::Any aOldValue
, aNewValue
;
99 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOldValue
, aNewValue
);
100 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, aOldValue
, aNewValue
);
106 VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent
);
112 void SAL_CALL
AccessibleIconChoiceCtrl::disposing()
114 ::osl::MutexGuard
aGuard( m_aMutex
);
121 OUString SAL_CALL
AccessibleIconChoiceCtrl::getImplementationName()
123 return u
"com.sun.star.comp.svtools.AccessibleIconChoiceControl"_ustr
;
126 Sequence
< OUString
> SAL_CALL
AccessibleIconChoiceCtrl::getSupportedServiceNames()
128 return {u
"com.sun.star.accessibility.AccessibleContext"_ustr
,
129 u
"com.sun.star.accessibility.AccessibleComponent"_ustr
,
130 u
"com.sun.star.awt.AccessibleIconChoiceControl"_ustr
};
135 Reference
< XAccessibleContext
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleContext( )
141 // XAccessibleContext
143 sal_Int64 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChildCount( )
145 ::comphelper::OExternalLockGuard
aGuard( this );
147 return getCtrl()->GetEntryCount();
150 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int64 i
)
152 ::comphelper::OExternalLockGuard
aGuard( this );
154 if (i
< 0 || i
>= getAccessibleChildCount())
155 throw IndexOutOfBoundsException();
157 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
158 return new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
161 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleParent( )
163 ::osl::MutexGuard
aGuard( m_aMutex
);
169 sal_Int16 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleRole( )
171 //return AccessibleRole::TREE;
172 return AccessibleRole::LIST
;
175 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleDescription( )
177 ::comphelper::OExternalLockGuard
aGuard( this );
179 return getCtrl()->GetAccessibleDescription();
182 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleName( )
184 ::comphelper::OExternalLockGuard
aGuard( this );
186 return getCtrl()->GetAccessibleName();
189 // XAccessibleSelection
191 void SAL_CALL
AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int64 nChildIndex
)
193 ::comphelper::OExternalLockGuard
aGuard( this );
195 if (nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount())
196 throw IndexOutOfBoundsException();
198 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
199 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
201 throw IndexOutOfBoundsException();
203 pCtrl
->SetCursor( pEntry
);
206 sal_Bool SAL_CALL
AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int64 nChildIndex
)
208 ::comphelper::OExternalLockGuard
aGuard( this );
210 if (nChildIndex
< 0 || nChildIndex
>= getAccessibleChildCount())
211 throw IndexOutOfBoundsException();
213 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
214 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
216 throw IndexOutOfBoundsException();
218 return ( pCtrl
->GetCursor() == pEntry
);
221 void SAL_CALL
AccessibleIconChoiceCtrl::clearAccessibleSelection( )
223 // one entry should always be selected, so don't unselect
226 void SAL_CALL
AccessibleIconChoiceCtrl::selectAllAccessibleChildren( )
228 ::comphelper::OExternalLockGuard
aGuard( this );
230 // don't do anything if there are no or multiple entries, as only
231 // a single one can be selected
232 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
233 sal_Int32 nCount
= pCtrl
->GetEntryCount();
237 pCtrl
->SetCursor(pCtrl
->GetEntry(0));
240 sal_Int64 SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( )
242 ::comphelper::OExternalLockGuard
aGuard( this );
244 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
245 if (pCtrl
->GetCursor())
251 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex
)
253 ::comphelper::OExternalLockGuard
aGuard( this );
255 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
256 throw IndexOutOfBoundsException();
258 Reference
< XAccessible
> xChild
;
259 sal_Int32 nSelCount
= 0;
260 VclPtr
<SvtIconChoiceCtrl
> pCtrl
= getCtrl();
261 sal_Int32 nCount
= pCtrl
->GetEntryCount();
262 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
264 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
265 if ( pCtrl
->GetCursor() == pEntry
)
268 if ( nSelCount
== ( nSelectedChildIndex
+ 1 ) )
270 xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
278 void SAL_CALL
AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int64 nSelectedChildIndex
)
280 ::comphelper::OExternalLockGuard
aGuard( this );
282 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getAccessibleChildCount() )
283 throw IndexOutOfBoundsException();
285 // one entry should always be selected, so don't unselect
288 void AccessibleIconChoiceCtrl::FillAccessibleStateSet( sal_Int64
& rStateSet
)
290 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
293 rStateSet
|= AccessibleStateType::FOCUSABLE
;
294 rStateSet
|= AccessibleStateType::MANAGES_DESCENDANTS
;
298 VclPtr
< SvtIconChoiceCtrl
> AccessibleIconChoiceCtrl::getCtrl() const
300 return GetAs
<SvtIconChoiceCtrl
>();
303 }// namespace accessibility
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */