Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
30 :
31 : //........................................................................
32 : namespace accessibility
33 : {
34 : //........................................................................
35 :
36 : // class AccessibleIconChoiceCtrl ----------------------------------------------
37 :
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;
42 :
43 : // -----------------------------------------------------------------------------
44 : // Ctor() and Dtor()
45 : // -----------------------------------------------------------------------------
46 0 : AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl( SvtIconChoiceCtrl& _rIconCtrl, const Reference< XAccessible >& _xParent ) :
47 :
48 : VCLXAccessibleComponent( _rIconCtrl.GetWindowPeer() ),
49 0 : m_xParent ( _xParent )
50 : {
51 0 : }
52 : // -----------------------------------------------------------------------------
53 0 : AccessibleIconChoiceCtrl::~AccessibleIconChoiceCtrl()
54 : {
55 0 : }
56 : // -----------------------------------------------------------------------------
57 0 : IMPLEMENT_FORWARD_XINTERFACE2(AccessibleIconChoiceCtrl, VCLXAccessibleComponent, AccessibleIconChoiceCtrl_BASE)
58 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleIconChoiceCtrl, VCLXAccessibleComponent, AccessibleIconChoiceCtrl_BASE)
59 : // -----------------------------------------------------------------------------
60 0 : void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
61 : {
62 0 : if ( isAlive() )
63 : {
64 0 : switch ( rVclWindowEvent.GetId() )
65 : {
66 : case VCLEVENT_LISTBOX_SELECT :
67 : {
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 0 : NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
73 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
74 0 : if ( pCtrl && pCtrl->HasFocus() )
75 : {
76 0 : SvxIconChoiceCtrlEntry* pEntry = static_cast< SvxIconChoiceCtrlEntry* >( rVclWindowEvent.GetData() );
77 0 : if ( pEntry )
78 : {
79 0 : sal_uLong nPos = pCtrl->GetEntryListPos( pEntry );
80 0 : Reference< XAccessible > xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, nPos, this );
81 0 : uno::Any aOldValue, aNewValue;
82 0 : aNewValue <<= xChild;
83 0 : NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
84 : }
85 : }
86 0 : break;
87 : }
88 : default:
89 0 : VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent);
90 : }
91 : }
92 0 : }
93 : // -----------------------------------------------------------------------------
94 : // XComponent
95 : // -----------------------------------------------------------------------------
96 0 : void SAL_CALL AccessibleIconChoiceCtrl::disposing()
97 : {
98 0 : ::osl::MutexGuard aGuard( m_aMutex );
99 :
100 0 : m_xParent = NULL;
101 0 : }
102 : // -----------------------------------------------------------------------------
103 : // XServiceInfo
104 : // -----------------------------------------------------------------------------
105 0 : OUString SAL_CALL AccessibleIconChoiceCtrl::getImplementationName() throw (RuntimeException)
106 : {
107 0 : return getImplementationName_Static();
108 : }
109 : // -----------------------------------------------------------------------------
110 0 : Sequence< OUString > SAL_CALL AccessibleIconChoiceCtrl::getSupportedServiceNames() throw (RuntimeException)
111 : {
112 0 : return getSupportedServiceNames_Static();
113 : }
114 : // -----------------------------------------------------------------------------
115 0 : sal_Bool SAL_CALL AccessibleIconChoiceCtrl::supportsService( const OUString& _rServiceName ) throw (RuntimeException)
116 : {
117 0 : return cppu::supportsService(this, _rServiceName);
118 : }
119 : // -----------------------------------------------------------------------------
120 : // XServiceInfo - static methods
121 : // -----------------------------------------------------------------------------
122 0 : Sequence< OUString > AccessibleIconChoiceCtrl::getSupportedServiceNames_Static(void) throw (RuntimeException)
123 : {
124 0 : Sequence< OUString > aSupported(3);
125 0 : aSupported[0] = "com.sun.star.accessibility.AccessibleContext";
126 0 : aSupported[1] = "com.sun.star.accessibility.AccessibleComponent";
127 0 : aSupported[2] = "com.sun.star.awt.AccessibleIconChoiceControl";
128 0 : return aSupported;
129 : }
130 : // -----------------------------------------------------------------------------
131 0 : OUString AccessibleIconChoiceCtrl::getImplementationName_Static(void) throw (RuntimeException)
132 : {
133 0 : return OUString( "com.sun.star.comp.svtools.AccessibleIconChoiceControl" );
134 : }
135 : // -----------------------------------------------------------------------------
136 : // XAccessible
137 : // -----------------------------------------------------------------------------
138 0 : Reference< XAccessibleContext > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleContext( ) throw (RuntimeException)
139 : {
140 0 : ensureAlive();
141 0 : return this;
142 : }
143 : // -----------------------------------------------------------------------------
144 : // XAccessibleContext
145 : // -----------------------------------------------------------------------------
146 0 : sal_Int32 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChildCount( ) throw (RuntimeException)
147 : {
148 0 : ::comphelper::OExternalLockGuard aGuard( this );
149 :
150 0 : ensureAlive();
151 0 : return getCtrl()->GetEntryCount();
152 : }
153 : // -----------------------------------------------------------------------------
154 0 : Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int32 i ) throw (RuntimeException, IndexOutOfBoundsException)
155 : {
156 0 : ::comphelper::OExternalLockGuard aGuard( this );
157 :
158 0 : ensureAlive();
159 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
160 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry(i);
161 0 : if ( !pEntry )
162 0 : throw RuntimeException();
163 :
164 0 : return new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
165 : }
166 : // -----------------------------------------------------------------------------
167 0 : Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleParent( ) throw (RuntimeException)
168 : {
169 0 : ::osl::MutexGuard aGuard( m_aMutex );
170 :
171 0 : ensureAlive();
172 0 : return m_xParent;
173 : }
174 : // -----------------------------------------------------------------------------
175 0 : sal_Int16 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleRole( ) throw (RuntimeException)
176 : {
177 0 : return AccessibleRole::TREE;
178 : }
179 : // -----------------------------------------------------------------------------
180 0 : OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleDescription( ) throw (RuntimeException)
181 : {
182 0 : ::comphelper::OExternalLockGuard aGuard( this );
183 :
184 0 : ensureAlive();
185 0 : return getCtrl()->GetAccessibleDescription();
186 : }
187 : // -----------------------------------------------------------------------------
188 0 : OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleName( ) throw (RuntimeException)
189 : {
190 0 : ::comphelper::OExternalLockGuard aGuard( this );
191 :
192 0 : ensureAlive();
193 :
194 0 : OUString sName = getCtrl()->GetAccessibleName();
195 0 : if ( sName.isEmpty() )
196 0 : sName = "IconChoiceControl";
197 0 : return sName;
198 : }
199 : // -----------------------------------------------------------------------------
200 : // XAccessibleSelection
201 : // -----------------------------------------------------------------------------
202 0 : void SAL_CALL AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
203 : {
204 0 : ::comphelper::OExternalLockGuard aGuard( this );
205 :
206 0 : ensureAlive();
207 :
208 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
209 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
210 0 : if ( !pEntry )
211 0 : throw IndexOutOfBoundsException();
212 :
213 0 : pCtrl->SetCursor( pEntry );
214 0 : }
215 : // -----------------------------------------------------------------------------
216 0 : sal_Bool SAL_CALL AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
217 : {
218 0 : ::comphelper::OExternalLockGuard aGuard( this );
219 :
220 0 : ensureAlive();
221 :
222 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
223 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
224 0 : if ( !pEntry )
225 0 : throw IndexOutOfBoundsException();
226 :
227 0 : return ( pCtrl->GetCursor() == pEntry );
228 : }
229 : // -----------------------------------------------------------------------------
230 0 : void SAL_CALL AccessibleIconChoiceCtrl::clearAccessibleSelection( ) throw (RuntimeException)
231 : {
232 0 : ::comphelper::OExternalLockGuard aGuard( this );
233 :
234 0 : ensureAlive();
235 0 : getCtrl()->SetNoSelection();
236 0 : }
237 : // -----------------------------------------------------------------------------
238 0 : void SAL_CALL AccessibleIconChoiceCtrl::selectAllAccessibleChildren( ) throw (RuntimeException)
239 : {
240 0 : ::comphelper::OExternalLockGuard aGuard( this );
241 :
242 0 : ensureAlive();
243 :
244 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
245 0 : sal_Int32 nCount = pCtrl->GetEntryCount();
246 0 : for ( sal_Int32 i = 0; i < nCount; ++i )
247 : {
248 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
249 0 : if ( pCtrl->GetCursor() != pEntry )
250 0 : pCtrl->SetCursor( pEntry );
251 0 : }
252 0 : }
253 : // -----------------------------------------------------------------------------
254 0 : sal_Int32 SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( ) throw (RuntimeException)
255 : {
256 0 : ::comphelper::OExternalLockGuard aGuard( this );
257 :
258 0 : ensureAlive();
259 :
260 0 : sal_Int32 nSelCount = 0;
261 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
262 0 : sal_Int32 nCount = pCtrl->GetEntryCount();
263 0 : for ( sal_Int32 i = 0; i < nCount; ++i )
264 : {
265 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
266 0 : if ( pCtrl->GetCursor() == pEntry )
267 0 : ++nSelCount;
268 : }
269 :
270 0 : return nSelCount;
271 : }
272 : // -----------------------------------------------------------------------------
273 0 : Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
274 : {
275 0 : ::comphelper::OExternalLockGuard aGuard( this );
276 :
277 0 : ensureAlive();
278 :
279 0 : if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
280 0 : throw IndexOutOfBoundsException();
281 :
282 0 : Reference< XAccessible > xChild;
283 0 : sal_Int32 nSelCount = 0;
284 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
285 0 : sal_Int32 nCount = pCtrl->GetEntryCount();
286 0 : for ( sal_Int32 i = 0; i < nCount; ++i )
287 : {
288 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
289 0 : if ( pCtrl->GetCursor() == pEntry )
290 0 : ++nSelCount;
291 :
292 0 : if ( nSelCount == ( nSelectedChildIndex + 1 ) )
293 : {
294 0 : xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
295 0 : break;
296 : }
297 : }
298 :
299 0 : return xChild;
300 : }
301 : // -----------------------------------------------------------------------------
302 0 : void SAL_CALL AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
303 : {
304 0 : ::comphelper::OExternalLockGuard aGuard( this );
305 :
306 0 : ensureAlive();
307 :
308 0 : if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getAccessibleChildCount() )
309 0 : throw IndexOutOfBoundsException();
310 :
311 0 : Reference< XAccessible > xChild;
312 0 : sal_Int32 nSelCount = 0;
313 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
314 0 : sal_Int32 nCount = pCtrl->GetEntryCount();
315 0 : bool bFound = false;
316 0 : for ( sal_Int32 i = 0; i < nCount; ++i )
317 : {
318 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
319 0 : if ( pEntry->IsSelected() )
320 : {
321 0 : ++nSelCount;
322 0 : if ( i == nSelectedChildIndex )
323 0 : bFound = true;
324 : }
325 : }
326 :
327 : // if only one entry is selected and its index is choosen to deselect -> no selection anymore
328 0 : if ( 1 == nSelCount && bFound )
329 0 : pCtrl->SetNoSelection();
330 0 : }
331 : // -----------------------------------------------------------------------------
332 0 : void AccessibleIconChoiceCtrl::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
333 : {
334 0 : VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
335 0 : if ( isAlive() )
336 : {
337 0 : rStateSet.AddState( AccessibleStateType::FOCUSABLE );
338 0 : rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
339 0 : rStateSet.AddState( AccessibleStateType::SELECTABLE );
340 : }
341 0 : }
342 : // -----------------------------------------------------------------------------
343 0 : SvtIconChoiceCtrl* AccessibleIconChoiceCtrl::getCtrl()
344 : {
345 0 : return static_cast<SvtIconChoiceCtrl*>(GetWindow());
346 : }
347 :
348 : //........................................................................
349 : }// namespace accessibility
350 : //........................................................................
351 :
352 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|