Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "accessibility/extended/accessibleiconchoicectrl.hxx"
30 : : #include "accessibility/extended/accessibleiconchoicectrlentry.hxx"
31 : : #include <svtools/ivctrl.hxx>
32 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
33 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
35 : : #include <unotools/accessiblestatesethelper.hxx>
36 : : #include <vcl/svapp.hxx>
37 : : #include <cppuhelper/typeprovider.hxx>
38 : :
39 : : //........................................................................
40 : : namespace accessibility
41 : : {
42 : : //........................................................................
43 : :
44 : : // class AccessibleIconChoiceCtrl ----------------------------------------------
45 : :
46 : : using namespace ::com::sun::star::accessibility;
47 : : using namespace ::com::sun::star::uno;
48 : : using namespace ::com::sun::star::lang;
49 : : using namespace ::com::sun::star;
50 : :
51 : : // -----------------------------------------------------------------------------
52 : : // Ctor() and Dtor()
53 : : // -----------------------------------------------------------------------------
54 : 0 : AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl( SvtIconChoiceCtrl& _rIconCtrl, const Reference< XAccessible >& _xParent ) :
55 : :
56 : : VCLXAccessibleComponent( _rIconCtrl.GetWindowPeer() ),
57 [ # # ][ # # ]: 0 : m_xParent ( _xParent )
58 : : {
59 : 0 : }
60 : : // -----------------------------------------------------------------------------
61 [ # # ]: 0 : AccessibleIconChoiceCtrl::~AccessibleIconChoiceCtrl()
62 : : {
63 [ # # ]: 0 : }
64 : : // -----------------------------------------------------------------------------
65 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XINTERFACE2(AccessibleIconChoiceCtrl, VCLXAccessibleComponent, AccessibleIconChoiceCtrl_BASE)
66 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleIconChoiceCtrl, VCLXAccessibleComponent, AccessibleIconChoiceCtrl_BASE)
[ # # ]
67 : : // -----------------------------------------------------------------------------
68 : 0 : void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
69 : : {
70 [ # # ]: 0 : if ( isAlive() )
71 : : {
72 [ # # ]: 0 : switch ( rVclWindowEvent.GetId() )
73 : : {
74 : : case VCLEVENT_LISTBOX_SELECT :
75 : : {
76 : : // First send an event that tells the listeners of a
77 : : // modified selection. The active descendant event is
78 : : // send after that so that the receiving AT has time to
79 : : // read the text or name of the active child.
80 [ # # ]: 0 : NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
81 : 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
82 [ # # ][ # # ]: 0 : if ( pCtrl && pCtrl->HasFocus() )
[ # # ]
83 : : {
84 : 0 : SvxIconChoiceCtrlEntry* pEntry = static_cast< SvxIconChoiceCtrlEntry* >( rVclWindowEvent.GetData() );
85 [ # # ]: 0 : if ( pEntry )
86 : : {
87 [ # # ]: 0 : sal_uLong nPos = pCtrl->GetEntryListPos( pEntry );
88 [ # # ][ # # ]: 0 : Reference< XAccessible > xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, nPos, this );
[ # # ][ # # ]
89 : 0 : uno::Any aOldValue, aNewValue;
90 [ # # ]: 0 : aNewValue <<= xChild;
91 [ # # ]: 0 : NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
92 : : }
93 : : }
94 : 0 : break;
95 : : }
96 : : default:
97 : 0 : VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent);
98 : : }
99 : : }
100 : 0 : }
101 : : // -----------------------------------------------------------------------------
102 : : // XComponent
103 : : // -----------------------------------------------------------------------------
104 : 0 : void SAL_CALL AccessibleIconChoiceCtrl::disposing()
105 : : {
106 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
107 : :
108 [ # # ][ # # ]: 0 : m_xParent = NULL;
109 : 0 : }
110 : : // -----------------------------------------------------------------------------
111 : : // XServiceInfo
112 : : // -----------------------------------------------------------------------------
113 : 0 : ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrl::getImplementationName() throw (RuntimeException)
114 : : {
115 : 0 : return getImplementationName_Static();
116 : : }
117 : : // -----------------------------------------------------------------------------
118 : 0 : Sequence< ::rtl::OUString > SAL_CALL AccessibleIconChoiceCtrl::getSupportedServiceNames() throw (RuntimeException)
119 : : {
120 : 0 : return getSupportedServiceNames_Static();
121 : : }
122 : : // -----------------------------------------------------------------------------
123 : 0 : sal_Bool SAL_CALL AccessibleIconChoiceCtrl::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
124 : : {
125 [ # # ]: 0 : Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
126 : 0 : const ::rtl::OUString* pSupported = aSupported.getConstArray();
127 : 0 : const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
128 [ # # ][ # # ]: 0 : for ( ; pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported )
[ # # ]
129 : : ;
130 : :
131 [ # # ]: 0 : return pSupported != pEnd;
132 : : }
133 : : // -----------------------------------------------------------------------------
134 : : // XServiceInfo - static methods
135 : : // -----------------------------------------------------------------------------
136 : 0 : Sequence< ::rtl::OUString > AccessibleIconChoiceCtrl::getSupportedServiceNames_Static(void) throw (RuntimeException)
137 : : {
138 : 0 : Sequence< ::rtl::OUString > aSupported(3);
139 [ # # ][ # # ]: 0 : aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleContext") );
140 [ # # ][ # # ]: 0 : aSupported[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.accessibility.AccessibleComponent") );
141 [ # # ][ # # ]: 0 : aSupported[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.AccessibleIconChoiceControl") );
142 : 0 : return aSupported;
143 : : }
144 : : // -----------------------------------------------------------------------------
145 : 0 : ::rtl::OUString AccessibleIconChoiceCtrl::getImplementationName_Static(void) throw (RuntimeException)
146 : : {
147 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.svtools.AccessibleIconChoiceControl") );
148 : : }
149 : : // -----------------------------------------------------------------------------
150 : : // XAccessible
151 : : // -----------------------------------------------------------------------------
152 : 0 : Reference< XAccessibleContext > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleContext( ) throw (RuntimeException)
153 : : {
154 : 0 : ensureAlive();
155 : 0 : return this;
156 : : }
157 : : // -----------------------------------------------------------------------------
158 : : // XAccessibleContext
159 : : // -----------------------------------------------------------------------------
160 : 0 : sal_Int32 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChildCount( ) throw (RuntimeException)
161 : : {
162 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
163 : :
164 [ # # ]: 0 : ensureAlive();
165 [ # # ][ # # ]: 0 : return getCtrl()->GetEntryCount();
[ # # ]
166 : : }
167 : : // -----------------------------------------------------------------------------
168 : 0 : Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int32 i ) throw (RuntimeException, IndexOutOfBoundsException)
169 : : {
170 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
171 : :
172 [ # # ]: 0 : ensureAlive();
173 [ # # ]: 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
174 [ # # ]: 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry(i);
175 [ # # ]: 0 : if ( !pEntry )
176 [ # # ]: 0 : throw RuntimeException();
177 : :
178 [ # # ][ # # ]: 0 : return new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
[ # # ][ # # ]
[ # # ]
179 : : }
180 : : // -----------------------------------------------------------------------------
181 : 0 : Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleParent( ) throw (RuntimeException)
182 : : {
183 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
184 : :
185 [ # # ]: 0 : ensureAlive();
186 [ # # ]: 0 : return m_xParent;
187 : : }
188 : : // -----------------------------------------------------------------------------
189 : 0 : sal_Int16 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleRole( ) throw (RuntimeException)
190 : : {
191 : 0 : return AccessibleRole::TREE;
192 : : }
193 : : // -----------------------------------------------------------------------------
194 : 0 : ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleDescription( ) throw (RuntimeException)
195 : : {
196 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
197 : :
198 [ # # ]: 0 : ensureAlive();
199 [ # # ][ # # ]: 0 : return getCtrl()->GetAccessibleDescription();
[ # # ][ # # ]
[ # # ]
200 : : }
201 : : // -----------------------------------------------------------------------------
202 : 0 : ::rtl::OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleName( ) throw (RuntimeException)
203 : : {
204 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
205 : :
206 [ # # ]: 0 : ensureAlive();
207 : :
208 [ # # ][ # # ]: 0 : ::rtl::OUString sName = getCtrl()->GetAccessibleName();
[ # # ][ # # ]
209 [ # # ]: 0 : if ( sName.isEmpty() )
210 [ # # ]: 0 : sName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IconChoiceControl" ) );
211 [ # # ]: 0 : return sName;
212 : : }
213 : : // -----------------------------------------------------------------------------
214 : : // XAccessibleSelection
215 : : // -----------------------------------------------------------------------------
216 : 0 : void SAL_CALL AccessibleIconChoiceCtrl::selectAccessibleChild( 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 : pCtrl->SetCursor( pEntry );
228 : 0 : }
229 : : // -----------------------------------------------------------------------------
230 : 0 : sal_Bool SAL_CALL AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
231 : : {
232 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
233 : :
234 [ # # ]: 0 : ensureAlive();
235 : :
236 [ # # ]: 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
237 [ # # ]: 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
238 [ # # ]: 0 : if ( !pEntry )
239 [ # # ]: 0 : throw IndexOutOfBoundsException();
240 : :
241 [ # # ][ # # ]: 0 : return ( pCtrl->GetCursor() == pEntry );
242 : : }
243 : : // -----------------------------------------------------------------------------
244 : 0 : void SAL_CALL AccessibleIconChoiceCtrl::clearAccessibleSelection( ) throw (RuntimeException)
245 : : {
246 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
247 : :
248 [ # # ]: 0 : ensureAlive();
249 [ # # ][ # # ]: 0 : getCtrl()->SetNoSelection();
[ # # ]
250 : 0 : }
251 : : // -----------------------------------------------------------------------------
252 : 0 : void SAL_CALL AccessibleIconChoiceCtrl::selectAllAccessibleChildren( ) throw (RuntimeException)
253 : : {
254 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
255 : :
256 [ # # ]: 0 : ensureAlive();
257 : :
258 : 0 : sal_Int32 i, nCount = 0;
259 [ # # ]: 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
260 [ # # ]: 0 : nCount = pCtrl->GetEntryCount();
261 [ # # ]: 0 : for ( i = 0; i < nCount; ++i )
262 : : {
263 [ # # ]: 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
264 [ # # ][ # # ]: 0 : if ( pCtrl->GetCursor() != pEntry )
265 [ # # ]: 0 : pCtrl->SetCursor( pEntry );
266 [ # # ]: 0 : }
267 : 0 : }
268 : : // -----------------------------------------------------------------------------
269 : 0 : sal_Int32 SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( ) throw (RuntimeException)
270 : : {
271 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
272 : :
273 [ # # ]: 0 : ensureAlive();
274 : :
275 : 0 : sal_Int32 i, nSelCount = 0, nCount = 0;
276 [ # # ]: 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
277 [ # # ]: 0 : nCount = pCtrl->GetEntryCount();
278 [ # # ]: 0 : for ( i = 0; i < nCount; ++i )
279 : : {
280 [ # # ]: 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
281 [ # # ][ # # ]: 0 : if ( pCtrl->GetCursor() == pEntry )
282 : 0 : ++nSelCount;
283 : : }
284 : :
285 [ # # ]: 0 : return nSelCount;
286 : : }
287 : : // -----------------------------------------------------------------------------
288 : 0 : Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
289 : : {
290 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
291 : :
292 [ # # ]: 0 : ensureAlive();
293 : :
294 [ # # ][ # # ]: 0 : if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
[ # # ][ # # ]
295 [ # # ]: 0 : throw IndexOutOfBoundsException();
296 : :
297 : 0 : Reference< XAccessible > xChild;
298 : 0 : sal_Int32 i, nSelCount = 0, nCount = 0;
299 [ # # ]: 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
300 [ # # ]: 0 : nCount = pCtrl->GetEntryCount();
301 [ # # ]: 0 : for ( i = 0; i < nCount; ++i )
302 : : {
303 [ # # ]: 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
304 [ # # ][ # # ]: 0 : if ( pCtrl->GetCursor() == pEntry )
305 : 0 : ++nSelCount;
306 : :
307 [ # # ]: 0 : if ( nSelCount == ( nSelectedChildIndex + 1 ) )
308 : : {
309 [ # # ][ # # ]: 0 : xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
[ # # ][ # # ]
310 : 0 : break;
311 : : }
312 : : }
313 : :
314 [ # # ]: 0 : return xChild;
315 : : }
316 : : // -----------------------------------------------------------------------------
317 : 0 : void SAL_CALL AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
318 : : {
319 [ # # ]: 0 : ::comphelper::OExternalLockGuard aGuard( this );
320 : :
321 [ # # ]: 0 : ensureAlive();
322 : :
323 [ # # ][ # # ]: 0 : if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getAccessibleChildCount() )
[ # # ][ # # ]
324 [ # # ]: 0 : throw IndexOutOfBoundsException();
325 : :
326 : 0 : Reference< XAccessible > xChild;
327 : 0 : sal_Int32 i, nSelCount = 0, nCount = 0;
328 [ # # ]: 0 : SvtIconChoiceCtrl* pCtrl = getCtrl();
329 [ # # ]: 0 : nCount = pCtrl->GetEntryCount();
330 : 0 : bool bFound = false;
331 [ # # ]: 0 : for ( i = 0; i < nCount; ++i )
332 : : {
333 [ # # ]: 0 : SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
334 [ # # ]: 0 : if ( pEntry->IsSelected() )
335 : : {
336 : 0 : ++nSelCount;
337 [ # # ]: 0 : if ( i == nSelectedChildIndex )
338 : 0 : bFound = true;
339 : : }
340 : : }
341 : :
342 : : // if only one entry is selected and its index is choosen to deselect -> no selection anymore
343 [ # # ][ # # ]: 0 : if ( 1 == nSelCount && bFound )
344 [ # # ][ # # ]: 0 : pCtrl->SetNoSelection();
345 : 0 : }
346 : : // -----------------------------------------------------------------------------
347 : 0 : void AccessibleIconChoiceCtrl::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
348 : : {
349 : 0 : VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
350 [ # # ]: 0 : if ( isAlive() )
351 : : {
352 : 0 : rStateSet.AddState( AccessibleStateType::FOCUSABLE );
353 : 0 : rStateSet.AddState( AccessibleStateType::MANAGES_DESCENDANTS );
354 : 0 : rStateSet.AddState( AccessibleStateType::SELECTABLE );
355 : : }
356 : 0 : }
357 : : // -----------------------------------------------------------------------------
358 : 0 : SvtIconChoiceCtrl* AccessibleIconChoiceCtrl::getCtrl()
359 : : {
360 : 0 : return static_cast<SvtIconChoiceCtrl*>(GetWindow());
361 : : }
362 : :
363 : : //........................................................................
364 : : }// namespace accessibility
365 : : //........................................................................
366 : :
367 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|