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>
31 //........................................................................
32 namespace accessibility
34 //........................................................................
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
;
43 // -----------------------------------------------------------------------------
45 // -----------------------------------------------------------------------------
46 AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl( SvtIconChoiceCtrl
& _rIconCtrl
, const Reference
< XAccessible
>& _xParent
) :
48 VCLXAccessibleComponent( _rIconCtrl
.GetWindowPeer() ),
49 m_xParent ( _xParent
)
52 // -----------------------------------------------------------------------------
53 AccessibleIconChoiceCtrl::~AccessibleIconChoiceCtrl()
56 // -----------------------------------------------------------------------------
57 IMPLEMENT_FORWARD_XINTERFACE2(AccessibleIconChoiceCtrl
, VCLXAccessibleComponent
, AccessibleIconChoiceCtrl_BASE
)
58 IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleIconChoiceCtrl
, VCLXAccessibleComponent
, AccessibleIconChoiceCtrl_BASE
)
59 // -----------------------------------------------------------------------------
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() );
73 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
74 if ( pCtrl
&& pCtrl
->HasFocus() )
76 SvxIconChoiceCtrlEntry
* pEntry
= static_cast< SvxIconChoiceCtrlEntry
* >( rVclWindowEvent
.GetData() );
79 sal_uLong nPos
= pCtrl
->GetEntryListPos( pEntry
);
80 Reference
< XAccessible
> xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, nPos
, this );
81 uno::Any aOldValue
, aNewValue
;
83 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOldValue
, aNewValue
);
89 VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent
);
93 // -----------------------------------------------------------------------------
95 // -----------------------------------------------------------------------------
96 void SAL_CALL
AccessibleIconChoiceCtrl::disposing()
98 ::osl::MutexGuard
aGuard( m_aMutex
);
102 // -----------------------------------------------------------------------------
104 // -----------------------------------------------------------------------------
105 OUString SAL_CALL
AccessibleIconChoiceCtrl::getImplementationName() throw (RuntimeException
)
107 return getImplementationName_Static();
109 // -----------------------------------------------------------------------------
110 Sequence
< OUString
> SAL_CALL
AccessibleIconChoiceCtrl::getSupportedServiceNames() throw (RuntimeException
)
112 return getSupportedServiceNames_Static();
114 // -----------------------------------------------------------------------------
115 sal_Bool SAL_CALL
AccessibleIconChoiceCtrl::supportsService( const OUString
& _rServiceName
) throw (RuntimeException
)
117 return cppu::supportsService(this, _rServiceName
);
119 // -----------------------------------------------------------------------------
120 // XServiceInfo - static methods
121 // -----------------------------------------------------------------------------
122 Sequence
< OUString
> AccessibleIconChoiceCtrl::getSupportedServiceNames_Static(void) throw (RuntimeException
)
124 Sequence
< OUString
> aSupported(3);
125 aSupported
[0] = "com.sun.star.accessibility.AccessibleContext";
126 aSupported
[1] = "com.sun.star.accessibility.AccessibleComponent";
127 aSupported
[2] = "com.sun.star.awt.AccessibleIconChoiceControl";
130 // -----------------------------------------------------------------------------
131 OUString
AccessibleIconChoiceCtrl::getImplementationName_Static(void) throw (RuntimeException
)
133 return OUString( "com.sun.star.comp.svtools.AccessibleIconChoiceControl" );
135 // -----------------------------------------------------------------------------
137 // -----------------------------------------------------------------------------
138 Reference
< XAccessibleContext
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleContext( ) throw (RuntimeException
)
143 // -----------------------------------------------------------------------------
144 // XAccessibleContext
145 // -----------------------------------------------------------------------------
146 sal_Int32 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChildCount( ) throw (RuntimeException
)
148 ::comphelper::OExternalLockGuard
aGuard( this );
151 return getCtrl()->GetEntryCount();
153 // -----------------------------------------------------------------------------
154 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int32 i
) throw (RuntimeException
, IndexOutOfBoundsException
)
156 ::comphelper::OExternalLockGuard
aGuard( this );
159 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
160 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry(i
);
162 throw RuntimeException();
164 return new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
166 // -----------------------------------------------------------------------------
167 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleParent( ) throw (RuntimeException
)
169 ::osl::MutexGuard
aGuard( m_aMutex
);
174 // -----------------------------------------------------------------------------
175 sal_Int16 SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleRole( ) throw (RuntimeException
)
177 return AccessibleRole::TREE
;
179 // -----------------------------------------------------------------------------
180 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleDescription( ) throw (RuntimeException
)
182 ::comphelper::OExternalLockGuard
aGuard( this );
185 return getCtrl()->GetAccessibleDescription();
187 // -----------------------------------------------------------------------------
188 OUString SAL_CALL
AccessibleIconChoiceCtrl::getAccessibleName( ) throw (RuntimeException
)
190 ::comphelper::OExternalLockGuard
aGuard( this );
194 OUString sName
= getCtrl()->GetAccessibleName();
195 if ( sName
.isEmpty() )
196 sName
= "IconChoiceControl";
199 // -----------------------------------------------------------------------------
200 // XAccessibleSelection
201 // -----------------------------------------------------------------------------
202 void SAL_CALL
AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
204 ::comphelper::OExternalLockGuard
aGuard( this );
208 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
209 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
211 throw IndexOutOfBoundsException();
213 pCtrl
->SetCursor( pEntry
);
215 // -----------------------------------------------------------------------------
216 sal_Bool SAL_CALL
AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
218 ::comphelper::OExternalLockGuard
aGuard( this );
222 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
223 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( nChildIndex
);
225 throw IndexOutOfBoundsException();
227 return ( pCtrl
->GetCursor() == pEntry
);
229 // -----------------------------------------------------------------------------
230 void SAL_CALL
AccessibleIconChoiceCtrl::clearAccessibleSelection( ) throw (RuntimeException
)
232 ::comphelper::OExternalLockGuard
aGuard( this );
235 getCtrl()->SetNoSelection();
237 // -----------------------------------------------------------------------------
238 void SAL_CALL
AccessibleIconChoiceCtrl::selectAllAccessibleChildren( ) throw (RuntimeException
)
240 ::comphelper::OExternalLockGuard
aGuard( this );
244 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
245 sal_Int32 nCount
= pCtrl
->GetEntryCount();
246 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
248 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
249 if ( pCtrl
->GetCursor() != pEntry
)
250 pCtrl
->SetCursor( pEntry
);
253 // -----------------------------------------------------------------------------
254 sal_Int32 SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( ) throw (RuntimeException
)
256 ::comphelper::OExternalLockGuard
aGuard( this );
260 sal_Int32 nSelCount
= 0;
261 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
262 sal_Int32 nCount
= pCtrl
->GetEntryCount();
263 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
265 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
266 if ( pCtrl
->GetCursor() == pEntry
)
272 // -----------------------------------------------------------------------------
273 Reference
< XAccessible
> SAL_CALL
AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
275 ::comphelper::OExternalLockGuard
aGuard( this );
279 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
280 throw IndexOutOfBoundsException();
282 Reference
< XAccessible
> xChild
;
283 sal_Int32 nSelCount
= 0;
284 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
285 sal_Int32 nCount
= pCtrl
->GetEntryCount();
286 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
288 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
289 if ( pCtrl
->GetCursor() == pEntry
)
292 if ( nSelCount
== ( nSelectedChildIndex
+ 1 ) )
294 xChild
= new AccessibleIconChoiceCtrlEntry( *pCtrl
, i
, this );
301 // -----------------------------------------------------------------------------
302 void SAL_CALL
AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
304 ::comphelper::OExternalLockGuard
aGuard( this );
308 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getAccessibleChildCount() )
309 throw IndexOutOfBoundsException();
311 Reference
< XAccessible
> xChild
;
312 sal_Int32 nSelCount
= 0;
313 SvtIconChoiceCtrl
* pCtrl
= getCtrl();
314 sal_Int32 nCount
= pCtrl
->GetEntryCount();
316 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
318 SvxIconChoiceCtrlEntry
* pEntry
= pCtrl
->GetEntry( i
);
319 if ( pEntry
->IsSelected() )
322 if ( i
== nSelectedChildIndex
)
327 // if only one entry is selected and its index is choosen to deselect -> no selection anymore
328 if ( 1 == nSelCount
&& bFound
)
329 pCtrl
->SetNoSelection();
331 // -----------------------------------------------------------------------------
332 void AccessibleIconChoiceCtrl::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
334 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet
);
337 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
338 rStateSet
.AddState( AccessibleStateType::MANAGES_DESCENDANTS
);
339 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
342 // -----------------------------------------------------------------------------
343 SvtIconChoiceCtrl
* AccessibleIconChoiceCtrl::getCtrl()
345 return static_cast<SvtIconChoiceCtrl
*>(GetWindow());
348 //........................................................................
349 }// namespace accessibility
350 //........................................................................
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */