Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / source / extended / accessibleiconchoicectrl.cxx
blob032c9dae95bc15617cd5a378950605be03fbc394
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 <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>
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;
43 // Ctor() and Dtor()
45 AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl( SvtIconChoiceCtrl const & _rIconCtrl, const Reference< XAccessible >& _xParent ) :
46 ImplInheritanceHelper( _rIconCtrl.GetWindowPeer() ),
47 m_xParent ( _xParent )
51 void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
53 if ( !isAlive() )
54 return;
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() );
69 if ( pEntry )
71 sal_Int32 nPos = getCtrl()->GetEntryListPos( pEntry );
72 Reference< XAccessible > xChild = new AccessibleIconChoiceCtrlEntry( *getCtrl(), nPos, this );
73 uno::Any aOldValue, aNewValue;
74 aNewValue <<= xChild;
75 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
77 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, aOldValue, aNewValue );
81 break;
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();
93 if ( pEntry )
95 sal_Int32 nPos = pCtrl->GetEntryListPos( pEntry );
96 Reference< XAccessible > xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, nPos, this );
97 uno::Any aOldValue, aNewValue;
98 aNewValue <<= xChild;
99 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
100 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, aOldValue, aNewValue );
103 break;
105 default:
106 VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent);
110 // XComponent
112 void SAL_CALL AccessibleIconChoiceCtrl::disposing()
114 ::osl::MutexGuard aGuard( m_aMutex );
116 m_xParent = nullptr;
119 // XServiceInfo
121 OUString SAL_CALL AccessibleIconChoiceCtrl::getImplementationName()
123 return "com.sun.star.comp.svtools.AccessibleIconChoiceControl";
126 Sequence< OUString > SAL_CALL AccessibleIconChoiceCtrl::getSupportedServiceNames()
128 return {"com.sun.star.accessibility.AccessibleContext",
129 "com.sun.star.accessibility.AccessibleComponent",
130 "com.sun.star.awt.AccessibleIconChoiceControl"};
133 sal_Bool SAL_CALL AccessibleIconChoiceCtrl::supportsService( const OUString& _rServiceName )
135 return cppu::supportsService(this, _rServiceName);
138 // XAccessible
140 Reference< XAccessibleContext > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleContext( )
142 ensureAlive();
143 return this;
146 // XAccessibleContext
148 sal_Int64 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChildCount( )
150 ::comphelper::OExternalLockGuard aGuard( this );
152 return getCtrl()->GetEntryCount();
155 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int64 i )
157 ::comphelper::OExternalLockGuard aGuard( this );
159 if (i < 0 || i >= getAccessibleChildCount())
160 throw IndexOutOfBoundsException();
162 VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl();
163 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry(i);
164 if ( !pEntry )
165 throw RuntimeException("getAccessibleChild: Entry "
166 + OUString::number(i) + " not found",
167 getXWeak());
169 return new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
172 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleParent( )
174 ::osl::MutexGuard aGuard( m_aMutex );
176 ensureAlive();
177 return m_xParent;
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";
200 return sName;
203 // XAccessibleSelection
205 void SAL_CALL AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int64 nChildIndex )
207 ::comphelper::OExternalLockGuard aGuard( this );
209 if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
210 throw IndexOutOfBoundsException();
212 VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl();
213 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
214 if ( !pEntry )
215 throw IndexOutOfBoundsException();
217 pCtrl->SetCursor( pEntry );
220 sal_Bool SAL_CALL AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int64 nChildIndex )
222 ::comphelper::OExternalLockGuard aGuard( this );
224 if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
225 throw IndexOutOfBoundsException();
227 VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl();
228 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
229 if ( !pEntry )
230 throw IndexOutOfBoundsException();
232 return ( pCtrl->GetCursor() == pEntry );
235 void SAL_CALL AccessibleIconChoiceCtrl::clearAccessibleSelection( )
237 ::comphelper::OExternalLockGuard aGuard( this );
238 getCtrl()->SetNoSelection();
241 void SAL_CALL AccessibleIconChoiceCtrl::selectAllAccessibleChildren( )
243 ::comphelper::OExternalLockGuard aGuard( this );
245 VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl();
246 sal_Int32 nCount = pCtrl->GetEntryCount();
247 for ( sal_Int32 i = 0; i < nCount; ++i )
249 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
250 if ( pCtrl->GetCursor() != pEntry )
251 pCtrl->SetCursor( pEntry );
255 sal_Int64 SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( )
257 ::comphelper::OExternalLockGuard aGuard( this );
259 sal_Int64 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 )
266 ++nSelCount;
269 return nSelCount;
272 Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
274 ::comphelper::OExternalLockGuard aGuard( this );
276 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
277 throw IndexOutOfBoundsException();
279 Reference< XAccessible > xChild;
280 sal_Int32 nSelCount = 0;
281 VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl();
282 sal_Int32 nCount = pCtrl->GetEntryCount();
283 for ( sal_Int32 i = 0; i < nCount; ++i )
285 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
286 if ( pCtrl->GetCursor() == pEntry )
287 ++nSelCount;
289 if ( nSelCount == ( nSelectedChildIndex + 1 ) )
291 xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
292 break;
296 return xChild;
299 void SAL_CALL AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int64 nSelectedChildIndex )
301 ::comphelper::OExternalLockGuard aGuard( this );
303 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getAccessibleChildCount() )
304 throw IndexOutOfBoundsException();
306 sal_Int32 nSelCount = 0;
307 VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl();
308 sal_Int32 nCount = pCtrl->GetEntryCount();
309 bool bFound = false;
310 for ( sal_Int32 i = 0; i < nCount; ++i )
312 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
313 if ( pEntry->IsSelected() )
315 ++nSelCount;
316 if ( i == nSelectedChildIndex )
317 bFound = true;
321 // if only one entry is selected and its index is chosen to deselect -> no selection anymore
322 if ( nSelCount == 1 && bFound )
323 pCtrl->SetNoSelection();
326 void AccessibleIconChoiceCtrl::FillAccessibleStateSet( sal_Int64& rStateSet )
328 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
329 if ( isAlive() )
331 rStateSet |= AccessibleStateType::FOCUSABLE;
332 rStateSet |= AccessibleStateType::MANAGES_DESCENDANTS;
333 rStateSet |= AccessibleStateType::SELECTABLE;
337 VclPtr< SvtIconChoiceCtrl > AccessibleIconChoiceCtrl::getCtrl() const
339 return GetAs<SvtIconChoiceCtrl >();
342 }// namespace accessibility
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */