Branch data 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/standard/accessiblemenucomponent.hxx>
21 : :
22 : : #include <toolkit/awt/vclxfont.hxx>
23 : : #include <toolkit/helper/convert.hxx>
24 : :
25 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
26 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
27 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 : :
29 : : #include <unotools/accessiblestatesethelper.hxx>
30 : : #include <unotools/accessiblerelationsethelper.hxx>
31 : : #include <cppuhelper/typeprovider.hxx>
32 : : #include <comphelper/sequence.hxx>
33 : : #include <vcl/svapp.hxx>
34 : : #include <vcl/window.hxx>
35 : : #include <vcl/menu.hxx>
36 : : #include <vcl/unohelp2.hxx>
37 : :
38 : :
39 : : using namespace ::com::sun::star::accessibility;
40 : : using namespace ::com::sun::star::uno;
41 : : using namespace ::com::sun::star::lang;
42 : : using namespace ::com::sun::star;
43 : : using namespace ::comphelper;
44 : :
45 : :
46 : : // -----------------------------------------------------------------------------
47 : : // class OAccessibleMenuComponent
48 : : // -----------------------------------------------------------------------------
49 : :
50 : 49 : OAccessibleMenuComponent::OAccessibleMenuComponent( Menu* pMenu )
51 : 49 : :OAccessibleMenuBaseComponent( pMenu )
52 : : {
53 : 49 : }
54 : :
55 : : // -----------------------------------------------------------------------------
56 : :
57 : 49 : OAccessibleMenuComponent::~OAccessibleMenuComponent()
58 : : {
59 [ - + ]: 49 : }
60 : :
61 : : // -----------------------------------------------------------------------------
62 : :
63 : 71 : sal_Bool OAccessibleMenuComponent::IsEnabled()
64 : : {
65 : 71 : return sal_True;
66 : : }
67 : :
68 : : // -----------------------------------------------------------------------------
69 : :
70 : 71 : sal_Bool OAccessibleMenuComponent::IsVisible()
71 : : {
72 : 71 : sal_Bool bVisible = sal_False;
73 : :
74 [ + - ]: 71 : if ( m_pMenu )
75 : 71 : bVisible = m_pMenu->IsMenuVisible();
76 : :
77 : 71 : return bVisible;
78 : : }
79 : :
80 : : // -----------------------------------------------------------------------------
81 : :
82 : 22 : void OAccessibleMenuComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
83 : : {
84 [ + - ]: 22 : if ( IsEnabled() )
85 : : {
86 : 22 : rStateSet.AddState( AccessibleStateType::ENABLED );
87 : 22 : rStateSet.AddState( AccessibleStateType::SENSITIVE );
88 : : }
89 : :
90 : 22 : rStateSet.AddState( AccessibleStateType::FOCUSABLE );
91 : :
92 [ - + ]: 22 : if ( IsFocused() )
93 : 0 : rStateSet.AddState( AccessibleStateType::FOCUSED );
94 : :
95 [ + - ]: 22 : if ( IsVisible() )
96 : : {
97 : 22 : rStateSet.AddState( AccessibleStateType::VISIBLE );
98 : 22 : rStateSet.AddState( AccessibleStateType::SHOWING );
99 : : }
100 : :
101 : 22 : rStateSet.AddState( AccessibleStateType::OPAQUE );
102 : 22 : }
103 : :
104 : : // -----------------------------------------------------------------------------
105 : : // OCommonAccessibleComponent
106 : : // -----------------------------------------------------------------------------
107 : :
108 : 0 : awt::Rectangle OAccessibleMenuComponent::implGetBounds() throw (RuntimeException)
109 : : {
110 : 0 : awt::Rectangle aBounds( 0, 0, 0, 0 );
111 : :
112 [ # # ]: 0 : if ( m_pMenu )
113 : : {
114 : 0 : Window* pWindow = m_pMenu->GetWindow();
115 [ # # ]: 0 : if ( pWindow )
116 : : {
117 : : // get bounding rectangle of the window in screen coordinates
118 [ # # ]: 0 : Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
119 [ # # ]: 0 : aBounds = AWTRectangle( aRect );
120 : :
121 : : // get position of the accessible parent in screen coordinates
122 [ # # ]: 0 : Reference< XAccessible > xParent = getAccessibleParent();
123 [ # # ]: 0 : if ( xParent.is() )
124 : : {
125 [ # # ][ # # ]: 0 : Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
[ # # ]
126 [ # # ]: 0 : if ( xParentComponent.is() )
127 : : {
128 [ # # ][ # # ]: 0 : awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
129 : :
130 : : // calculate position of the window relative to the accessible parent
131 : 0 : aBounds.X -= aParentScreenLoc.X;
132 : 0 : aBounds.Y -= aParentScreenLoc.Y;
133 : 0 : }
134 : 0 : }
135 : : }
136 : : }
137 : :
138 : 0 : return aBounds;
139 : : }
140 : :
141 : : // -----------------------------------------------------------------------------
142 : : // XInterface
143 : : // -----------------------------------------------------------------------------
144 : :
145 [ - + ][ # # ]: 37259 : IMPLEMENT_FORWARD_XINTERFACE2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE )
146 : :
147 : : // -----------------------------------------------------------------------------
148 : : // XTypeProvider
149 : : // -----------------------------------------------------------------------------
150 : :
151 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE )
[ # # ]
152 : :
153 : : // -----------------------------------------------------------------------------
154 : : // XAccessibleContext
155 : : // -----------------------------------------------------------------------------
156 : :
157 : 238 : sal_Int32 OAccessibleMenuComponent::getAccessibleChildCount() throw (RuntimeException)
158 : : {
159 [ + - ]: 238 : OExternalLockGuard aGuard( this );
160 : :
161 [ + - ][ + - ]: 238 : return GetChildCount();
162 : : }
163 : :
164 : : // -----------------------------------------------------------------------------
165 : :
166 : 1576 : Reference< XAccessible > OAccessibleMenuComponent::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
167 : : {
168 [ + - ]: 1576 : OExternalLockGuard aGuard( this );
169 : :
170 [ + - ][ + - ]: 1576 : if ( i < 0 || i >= GetChildCount() )
[ - + ][ - + ]
171 [ # # ]: 0 : throw IndexOutOfBoundsException();
172 : :
173 [ + - ][ + - ]: 1576 : return GetChild( i );
174 : : }
175 : :
176 : : // -----------------------------------------------------------------------------
177 : :
178 : 214 : Reference< XAccessible > OAccessibleMenuComponent::getAccessibleParent( ) throw (RuntimeException)
179 : : {
180 [ + - ]: 214 : OExternalLockGuard aGuard( this );
181 : :
182 : 214 : Reference< XAccessible > xParent;
183 : :
184 [ + - ]: 214 : if ( m_pMenu )
185 : : {
186 : 214 : Window* pWindow = m_pMenu->GetWindow();
187 [ + - ]: 214 : if ( pWindow )
188 : : {
189 [ + - ]: 214 : Window* pParent = pWindow->GetAccessibleParentWindow();
190 [ + - ]: 214 : if ( pParent )
191 [ + - ][ + - ]: 214 : xParent = pParent->GetAccessible();
192 : : }
193 : : }
194 : :
195 [ + - ]: 214 : return xParent;
196 : : }
197 : :
198 : : // -----------------------------------------------------------------------------
199 : :
200 : 0 : sal_Int16 OAccessibleMenuComponent::getAccessibleRole( ) throw (RuntimeException)
201 : : {
202 [ # # ]: 0 : OExternalLockGuard aGuard( this );
203 : :
204 [ # # ]: 0 : return AccessibleRole::UNKNOWN;
205 : : }
206 : :
207 : : // -----------------------------------------------------------------------------
208 : :
209 : 214 : ::rtl::OUString OAccessibleMenuComponent::getAccessibleDescription( ) throw (RuntimeException)
210 : : {
211 [ + - ]: 214 : OExternalLockGuard aGuard( this );
212 : :
213 : 214 : ::rtl::OUString sDescription;
214 [ + - ]: 214 : if ( m_pMenu )
215 : : {
216 : 214 : Window* pWindow = m_pMenu->GetWindow();
217 [ + - ]: 214 : if ( pWindow )
218 [ + - ][ + - ]: 214 : sDescription = pWindow->GetAccessibleDescription();
[ + - ]
219 : : }
220 : :
221 [ + - ]: 214 : return sDescription;
222 : : }
223 : :
224 : : // -----------------------------------------------------------------------------
225 : :
226 : 214 : ::rtl::OUString OAccessibleMenuComponent::getAccessibleName( ) throw (RuntimeException)
227 : : {
228 [ + - ]: 214 : OExternalLockGuard aGuard( this );
229 : :
230 [ + - ]: 214 : return ::rtl::OUString();
231 : : }
232 : :
233 : : // -----------------------------------------------------------------------------
234 : :
235 : 2 : Reference< XAccessibleRelationSet > OAccessibleMenuComponent::getAccessibleRelationSet( ) throw (RuntimeException)
236 : : {
237 [ + - ]: 2 : OExternalLockGuard aGuard( this );
238 : :
239 [ + - ]: 2 : utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
240 [ + - ][ + - ]: 2 : Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
241 [ + - ]: 2 : return xSet;
242 : : }
243 : :
244 : : // -----------------------------------------------------------------------------
245 : :
246 : 2 : Locale OAccessibleMenuComponent::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
247 : : {
248 [ + - ]: 2 : OExternalLockGuard aGuard( this );
249 : :
250 [ + - ][ + - ]: 2 : return Application::GetSettings().GetLocale();
[ + - ]
251 : : }
252 : :
253 : : // -----------------------------------------------------------------------------
254 : : // XAccessibleComponent
255 : : // -----------------------------------------------------------------------------
256 : :
257 : 0 : Reference< XAccessible > OAccessibleMenuComponent::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
258 : : {
259 [ # # ]: 0 : OExternalLockGuard aGuard( this );
260 : :
261 [ # # ][ # # ]: 0 : return GetChildAt( rPoint );
262 : : }
263 : :
264 : : // -----------------------------------------------------------------------------
265 : :
266 : 2952 : awt::Point OAccessibleMenuComponent::getLocationOnScreen( ) throw (RuntimeException)
267 : : {
268 [ + - ]: 2952 : OExternalLockGuard aGuard( this );
269 : :
270 : 2952 : awt::Point aPos;
271 : :
272 [ + - ]: 2952 : if ( m_pMenu )
273 : : {
274 : 2952 : Window* pWindow = m_pMenu->GetWindow();
275 [ + - ]: 2952 : if ( pWindow )
276 : : {
277 [ + - ]: 2952 : Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
278 : 2952 : aPos = AWTPoint( aRect.TopLeft() );
279 : : }
280 : : }
281 : :
282 [ + - ]: 2952 : return aPos;
283 : : }
284 : :
285 : : // -----------------------------------------------------------------------------
286 : :
287 : 0 : void OAccessibleMenuComponent::grabFocus( ) throw (RuntimeException)
288 : : {
289 [ # # ]: 0 : OExternalLockGuard aGuard( this );
290 : :
291 [ # # ]: 0 : if ( m_pMenu )
292 : : {
293 : 0 : Window* pWindow = m_pMenu->GetWindow();
294 [ # # ]: 0 : if ( pWindow )
295 [ # # ]: 0 : pWindow->GrabFocus();
296 [ # # ]: 0 : }
297 : 0 : }
298 : :
299 : : // -----------------------------------------------------------------------------
300 : :
301 : 2 : sal_Int32 OAccessibleMenuComponent::getForeground( ) throw (RuntimeException)
302 : : {
303 [ + - ]: 2 : OExternalLockGuard aGuard( this );
304 : :
305 [ + - ]: 2 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
306 : 2 : sal_Int32 nColor = rStyleSettings.GetMenuTextColor().GetColor();
307 : :
308 [ + - ]: 2 : return nColor;
309 : : }
310 : :
311 : : // -----------------------------------------------------------------------------
312 : :
313 : 0 : sal_Int32 OAccessibleMenuComponent::getBackground( ) throw (RuntimeException)
314 : : {
315 [ # # ]: 0 : OExternalLockGuard aGuard( this );
316 : :
317 [ # # ]: 0 : return 0;
318 : : }
319 : :
320 : : // -----------------------------------------------------------------------------
321 : : // XAccessibleExtendedComponent
322 : : // -----------------------------------------------------------------------------
323 : :
324 : 6 : Reference< awt::XFont > OAccessibleMenuComponent::getFont( ) throw (RuntimeException)
325 : : {
326 [ + - ]: 6 : OExternalLockGuard aGuard( this );
327 : :
328 : 6 : Reference< awt::XFont > xFont;
329 : :
330 [ + - ]: 6 : if ( m_pMenu )
331 : : {
332 : 6 : Window* pWindow = m_pMenu->GetWindow();
333 [ + - ]: 6 : if ( pWindow )
334 : : {
335 [ + - ][ + - ]: 6 : Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
336 [ + - ]: 6 : if ( xDev.is() )
337 : : {
338 [ + - ]: 6 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
339 [ + - ]: 6 : VCLXFont* pVCLXFont = new VCLXFont;
340 [ + - ][ + - ]: 6 : pVCLXFont->Init( *xDev.get(), rStyleSettings.GetMenuFont() );
341 [ + - ]: 6 : xFont = pVCLXFont;
342 : 6 : }
343 : : }
344 : : }
345 : :
346 [ + - ]: 6 : return xFont;
347 : : }
348 : :
349 : : // -----------------------------------------------------------------------------
350 : :
351 : 2 : ::rtl::OUString OAccessibleMenuComponent::getTitledBorderText( ) throw (RuntimeException)
352 : : {
353 [ + - ]: 2 : OExternalLockGuard aGuard( this );
354 : :
355 [ + - ]: 2 : return ::rtl::OUString();
356 : : }
357 : :
358 : : // -----------------------------------------------------------------------------
359 : :
360 : 2 : ::rtl::OUString OAccessibleMenuComponent::getToolTipText( ) throw (RuntimeException)
361 : : {
362 [ + - ]: 2 : OExternalLockGuard aGuard( this );
363 : :
364 [ + - ]: 2 : return ::rtl::OUString();
365 : : }
366 : :
367 : : // -----------------------------------------------------------------------------
368 : : // XAccessibleSelection
369 : : // -----------------------------------------------------------------------------
370 : :
371 : 0 : void OAccessibleMenuComponent::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
372 : : {
373 [ # # ]: 0 : OExternalLockGuard aGuard( this );
374 : :
375 [ # # ][ # # ]: 0 : if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
[ # # ][ # # ]
376 [ # # ]: 0 : throw IndexOutOfBoundsException();
377 : :
378 [ # # ][ # # ]: 0 : SelectChild( nChildIndex );
379 : 0 : }
380 : :
381 : : // -----------------------------------------------------------------------------
382 : :
383 : 0 : sal_Bool OAccessibleMenuComponent::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
384 : : {
385 [ # # ]: 0 : OExternalLockGuard aGuard( this );
386 : :
387 [ # # ][ # # ]: 0 : if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
[ # # ][ # # ]
388 [ # # ]: 0 : throw IndexOutOfBoundsException();
389 : :
390 [ # # ][ # # ]: 0 : return IsChildSelected( nChildIndex );
391 : : }
392 : :
393 : : // -----------------------------------------------------------------------------
394 : :
395 : 0 : void OAccessibleMenuComponent::clearAccessibleSelection( ) throw (RuntimeException)
396 : : {
397 [ # # ]: 0 : OExternalLockGuard aGuard( this );
398 : :
399 [ # # ][ # # ]: 0 : DeSelectAll();
400 : 0 : }
401 : :
402 : : // -----------------------------------------------------------------------------
403 : :
404 : 0 : void OAccessibleMenuComponent::selectAllAccessibleChildren( ) throw (RuntimeException)
405 : : {
406 : : // This method makes no sense in a menu, and so does nothing.
407 : 0 : }
408 : :
409 : : // -----------------------------------------------------------------------------
410 : :
411 : 0 : sal_Int32 OAccessibleMenuComponent::getSelectedAccessibleChildCount( ) throw (RuntimeException)
412 : : {
413 [ # # ]: 0 : OExternalLockGuard aGuard( this );
414 : :
415 : 0 : sal_Int32 nRet = 0;
416 : :
417 [ # # ][ # # ]: 0 : for ( sal_Int32 i = 0, nCount = GetChildCount(); i < nCount; i++ )
418 : : {
419 [ # # ][ # # ]: 0 : if ( IsChildSelected( i ) )
420 : 0 : ++nRet;
421 : : }
422 : :
423 [ # # ]: 0 : return nRet;
424 : : }
425 : :
426 : : // -----------------------------------------------------------------------------
427 : :
428 : 0 : Reference< XAccessible > OAccessibleMenuComponent::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
429 : : {
430 [ # # ]: 0 : OExternalLockGuard aGuard( this );
431 : :
432 [ # # ][ # # ]: 0 : if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
[ # # ][ # # ]
433 [ # # ]: 0 : throw IndexOutOfBoundsException();
434 : :
435 : 0 : Reference< XAccessible > xChild;
436 : :
437 [ # # ][ # # ]: 0 : for ( sal_Int32 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ )
438 : : {
439 [ # # ][ # # ]: 0 : if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
[ # # ][ # # ]
440 : : {
441 [ # # ][ # # ]: 0 : xChild = GetChild( i );
442 : 0 : break;
443 : : }
444 : : }
445 : :
446 [ # # ]: 0 : return xChild;
447 : : }
448 : :
449 : : // -----------------------------------------------------------------------------
450 : :
451 : 0 : void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
452 : : {
453 [ # # ]: 0 : OExternalLockGuard aGuard( this );
454 : :
455 [ # # ][ # # ]: 0 : if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
[ # # ][ # # ]
456 [ # # ]: 0 : throw IndexOutOfBoundsException();
457 : :
458 [ # # ][ # # ]: 0 : DeSelectAll();
459 : 0 : }
460 : :
461 : : // -----------------------------------------------------------------------------
462 : :
463 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|