LibreOffice Module accessibility (master) 1
accessiblemenucomponent.cxx
Go to the documentation of this file.
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
21
24
25#include <com/sun/star/accessibility/AccessibleRole.hpp>
26#include <com/sun/star/accessibility/AccessibleStateType.hpp>
27#include <com/sun/star/awt/XDevice.hpp>
28#include <com/sun/star/awt/XVclWindowPeer.hpp>
29#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
32#include <vcl/svapp.hxx>
33#include <vcl/window.hxx>
34#include <vcl/menu.hxx>
35#include <vcl/settings.hxx>
37
38using namespace ::com::sun::star::accessibility;
39using namespace ::com::sun::star::uno;
40using namespace ::com::sun::star::lang;
41using namespace ::com::sun::star;
42using namespace ::comphelper;
43
44
45
46
48{
49 return true;
50}
51
52
54{
55 bool bVisible = false;
56
57 if ( m_pMenu )
58 bVisible = m_pMenu->IsMenuVisible();
59
60 return bVisible;
61}
62
63
65{
66 if ( IsEnabled() )
67 {
68 rStateSet |= AccessibleStateType::ENABLED;
69 rStateSet |= AccessibleStateType::SENSITIVE;
70 }
71
72 rStateSet |= AccessibleStateType::FOCUSABLE;
73
74 if ( IsFocused() )
75 rStateSet |= AccessibleStateType::FOCUSED;
76
77 if ( IsVisible() )
78 {
79 rStateSet |= AccessibleStateType::VISIBLE;
80 rStateSet |= AccessibleStateType::SHOWING;
81 }
82
83 rStateSet |= AccessibleStateType::OPAQUE;
84}
85
86
87// OCommonAccessibleComponent
88
89
91{
92 awt::Rectangle aBounds( 0, 0, 0, 0 );
93
94 if ( m_pMenu )
95 {
96 vcl::Window* pWindow = m_pMenu->GetWindow();
97 if ( pWindow )
98 {
99 // get bounding rectangle of the window in screen coordinates
101 aBounds = AWTRectangle( aRect );
102
103 // get position of the accessible parent in screen coordinates
105 if ( xParent.is() )
106 {
107 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
108 if ( xParentComponent.is() )
109 {
110 awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
111
112 // calculate position of the window relative to the accessible parent
113 aBounds.X -= aParentScreenLoc.X;
114 aBounds.Y -= aParentScreenLoc.Y;
115 }
116 }
117 }
118 }
119
120 return aBounds;
121}
122
123
124// XAccessibleContext
125
126
128{
129 OExternalLockGuard aGuard( this );
130
131 return GetChildCount();
132}
133
134
136{
137 OExternalLockGuard aGuard( this );
138
139 if ( i < 0 || i >= GetChildCount() )
140 throw IndexOutOfBoundsException();
141
142 return GetChild( i );
143}
144
145
147{
148 OExternalLockGuard aGuard( this );
149
151
152 if ( m_pMenu )
153 {
154 vcl::Window* pWindow = m_pMenu->GetWindow();
155 if ( pWindow )
156 {
157 vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
158 if ( pParent )
159 xParent = pParent->GetAccessible();
160 }
161 }
162
163 return xParent;
164}
165
166
168{
169 OExternalLockGuard aGuard( this );
170
171 return AccessibleRole::UNKNOWN;
172}
173
174
176{
177 OExternalLockGuard aGuard( this );
178
179 OUString sDescription;
180 if ( m_pMenu )
181 {
182 vcl::Window* pWindow = m_pMenu->GetWindow();
183 if ( pWindow )
184 sDescription = pWindow->GetAccessibleDescription();
185 }
186
187 return sDescription;
188}
189
190
192{
193 OExternalLockGuard aGuard( this );
194
195 return OUString();
196}
197
198
199Reference< XAccessibleRelationSet > OAccessibleMenuComponent::getAccessibleRelationSet( )
200{
201 OExternalLockGuard aGuard( this );
202
204}
205
206
208{
209 OExternalLockGuard aGuard( this );
210
212}
213
214
215// XAccessibleComponent
216
217
219{
220 OExternalLockGuard aGuard( this );
221
222 return GetChildAt( rPoint );
223}
224
225
227{
228 OExternalLockGuard aGuard( this );
229
230 awt::Point aPos;
231
232 if ( m_pMenu )
233 {
234 vcl::Window* pWindow = m_pMenu->GetWindow();
235 if ( pWindow )
236 {
238 aPos = AWTPoint( aRect.TopLeft() );
239 }
240 }
241
242 return aPos;
243}
244
245
247{
248 OExternalLockGuard aGuard( this );
249
250 if ( m_pMenu )
251 {
252 vcl::Window* pWindow = m_pMenu->GetWindow();
253 if ( pWindow )
254 pWindow->GrabFocus();
255 }
256}
257
258
260{
261 OExternalLockGuard aGuard( this );
262
263 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
264 Color nColor = rStyleSettings.GetMenuTextColor();
265
266 return sal_Int32(nColor);
267}
268
269
271{
272 OExternalLockGuard aGuard( this );
273
274 return 0;
275}
276
277
278// XAccessibleExtendedComponent
279
280
281Reference< awt::XFont > OAccessibleMenuComponent::getFont( )
282{
283 OExternalLockGuard aGuard( this );
284
285 Reference< awt::XFont > xFont;
286
287 if ( m_pMenu )
288 {
289 vcl::Window* pWindow = m_pMenu->GetWindow();
290 if ( pWindow )
291 {
292 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
293 if ( xDev.is() )
294 {
295 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
296 rtl::Reference<VCLXFont> pVCLXFont = new VCLXFont;
297 pVCLXFont->Init( *xDev, rStyleSettings.GetMenuFont() );
298 xFont = pVCLXFont;
299 }
300 }
301 }
302
303 return xFont;
304}
305
306
308{
309 OExternalLockGuard aGuard( this );
310
311 return OUString();
312}
313
314
316{
317 OExternalLockGuard aGuard( this );
318
319 return OUString();
320}
321
322
323// XAccessibleSelection
324
325
327{
328 OExternalLockGuard aGuard( this );
329
330 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
331 throw IndexOutOfBoundsException();
332
333 SelectChild( nChildIndex );
334}
335
336
338{
339 OExternalLockGuard aGuard( this );
340
341 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
342 throw IndexOutOfBoundsException();
343
344 return IsChildSelected( nChildIndex );
345}
346
347
349{
350 OExternalLockGuard aGuard( this );
351
352 DeSelectAll();
353}
354
355
357{
358 // This method makes no sense in a menu, and so does nothing.
359}
360
361
363{
364 OExternalLockGuard aGuard( this );
365
366 sal_Int64 nRet = 0;
367
368 for ( sal_Int64 i = 0, nCount = GetChildCount(); i < nCount; i++ )
369 {
370 if ( IsChildSelected( i ) )
371 ++nRet;
372 }
373
374 return nRet;
375}
376
377
379{
380 OExternalLockGuard aGuard( this );
381
382 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
383 throw IndexOutOfBoundsException();
384
386
387 for ( sal_Int64 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ )
388 {
389 if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
390 {
391 xChild = GetChild( i );
392 break;
393 }
394 }
395
396 return xChild;
397}
398
399
401{
402 OExternalLockGuard aGuard( this );
403
404 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
405 throw IndexOutOfBoundsException();
406
407 DeSelectAll();
408}
409
410
411/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LanguageTag & GetLanguageTag() const
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
virtual OUString SAL_CALL getAccessibleDescription() override
virtual void SAL_CALL clearAccessibleSelection() override
virtual bool IsEnabled() override
virtual css::awt::Rectangle implGetBounds() override
virtual css::awt::Point SAL_CALL getLocationOnScreen() override
virtual OUString SAL_CALL getAccessibleName() override
virtual sal_Int32 SAL_CALL getForeground() override
virtual sal_Int32 SAL_CALL getBackground() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(sal_Int64 nSelectedChildIndex) override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
virtual void SAL_CALL selectAllAccessibleChildren() override
virtual OUString SAL_CALL getToolTipText() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual sal_Bool SAL_CALL isAccessibleChildSelected(sal_Int64 nChildIndex) override
virtual sal_Int64 SAL_CALL getSelectedAccessibleChildCount() override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
virtual void SAL_CALL selectAccessibleChild(sal_Int64 nChildIndex) override
virtual void SAL_CALL grabFocus() override
virtual bool IsVisible() override
virtual css::uno::Reference< css::awt::XFont > SAL_CALL getFont() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual void FillAccessibleStateSet(sal_Int64 &rStateSet) override
virtual OUString SAL_CALL getTitledBorderText() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual void SAL_CALL deselectAccessibleChild(sal_Int64 nChildIndex) override
const vcl::Font & GetMenuFont() const
const Color & GetMenuTextColor() const
constexpr Point TopLeft() const
tools::Rectangle GetWindowExtentsAbsolute() const
void GrabFocus()
vcl::Window * GetAccessibleParentWindow() const
virtual css::uno::Reference< css::awt::XVclWindowPeer > GetComponentInterface(bool bCreate=true)
css::uno::Reference< css::accessibility::XAccessible > GetAccessible(bool bCreate=true)
OUString GetAccessibleDescription() const
css::awt::Point AWTPoint(const ::Point &rVCLPoint)
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
int nCount
int i
bool bVisible
unsigned char sal_Bool