LibreOffice Module accessibility (master) 1
accessiblemenuitemcomponent.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
22
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#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/mnemonic.hxx>
36#include <vcl/settings.hxx>
38
39using namespace ::com::sun::star::accessibility;
40using namespace ::com::sun::star::uno;
41using namespace ::com::sun::star::beans;
42using namespace ::com::sun::star::lang;
43using namespace ::com::sun::star;
44using namespace ::comphelper;
45
46
47
48
51 ,m_pParent( pParent )
52 ,m_nItemPos( nItemPos )
53{
56}
57
59{
60}
61
63{
64 OExternalLockGuard aGuard( this );
65
66 bool bEnabled = false;
67 if ( m_pParent )
68 bEnabled = m_pParent->IsItemEnabled( m_pParent->GetItemId( m_nItemPos ) );
69
70 return bEnabled;
71}
72
73
75{
76 bool bVisible = false;
77
78 if ( m_pParent )
79 bVisible = m_pParent->IsItemPosVisible( m_nItemPos );
80
81 return bVisible;
82}
83
84
86{
87 // open the parent menu
89 if ( xParent.is() )
90 {
91 OAccessibleMenuBaseComponent* pComp = static_cast< OAccessibleMenuBaseComponent* >( xParent.get() );
92 if ( pComp && pComp->getAccessibleRole() == AccessibleRole::MENU && !pComp->IsPopupMenuOpen() )
93 pComp->Click();
94 }
95
96 // highlight the menu item
97 if ( m_pParent )
98 m_pParent->HighlightItem( m_nItemPos );
99}
100
101
103{
104 if ( m_pParent && IsSelected() )
105 m_pParent->DeHighlight();
106}
107
108
110{
111 // open the parent menu
113 if ( xParent.is() )
114 {
115 OAccessibleMenuBaseComponent* pComp = static_cast< OAccessibleMenuBaseComponent* >( xParent.get() );
116 if ( pComp && pComp->getAccessibleRole() == AccessibleRole::MENU && !pComp->IsPopupMenuOpen() )
117 pComp->Click();
118 }
119
120 // click the menu item
121 if ( !m_pParent )
122 return;
123
124 vcl::Window* pWindow = m_pParent->GetWindow();
125 if ( !pWindow )
126 return;
127
128 // #102438# Menu items are not selectable
129 // Popup menus are executed asynchronously, triggered by a timer.
130 // As Menu::SelectItem only works, if the corresponding menu window is
131 // already created, we have to set the menu delay to 0, so
132 // that the popup menus are executed synchronously.
133 AllSettings aSettings = pWindow->GetSettings();
134 MouseSettings aMouseSettings = aSettings.GetMouseSettings();
135 sal_Int32 nDelay = aMouseSettings.GetMenuDelay();
136 aMouseSettings.SetMenuDelay( 0 );
137 aSettings.SetMouseSettings( aMouseSettings );
138 pWindow->SetSettings( aSettings );
139
140 m_pParent->SelectItem( m_pParent->GetItemId( m_nItemPos ) );
141
142 // meanwhile the window pointer may be invalid
143 pWindow = m_pParent->GetWindow();
144 if ( pWindow )
145 {
146 // set the menu delay back to the old value
147 aSettings = pWindow->GetSettings();
148 aMouseSettings = aSettings.GetMouseSettings();
149 aMouseSettings.SetMenuDelay( nDelay );
150 aSettings.SetMouseSettings( aMouseSettings );
151 pWindow->SetSettings( aSettings );
152 }
153}
154
155
157{
158 m_nItemPos = nItemPos;
159}
160
161
162void OAccessibleMenuItemComponent::SetAccessibleName( const OUString& sAccessibleName )
163{
164 if ( m_sAccessibleName != sAccessibleName )
165 {
166 Any aOldValue, aNewValue;
167 aOldValue <<= m_sAccessibleName;
168 aNewValue <<= sAccessibleName;
169 m_sAccessibleName = sAccessibleName;
170 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
171 }
172}
173
174
176{
177 OUString sName;
178 if ( m_pParent )
179 {
180 sal_uInt16 nItemId = m_pParent->GetItemId( m_nItemPos );
181 sName = m_pParent->GetAccessibleName( nItemId );
182 if ( sName.isEmpty() )
183 sName = m_pParent->GetItemText( nItemId );
185#if defined(_WIN32)
186 if ( m_pParent->GetAccelKey( nItemId ).GetName().getLength() )
187 sName += "\t" + m_pParent->GetAccelKey(nItemId).GetName();
188#endif
189 }
190
191 return sName;
192}
193
194
195void OAccessibleMenuItemComponent::SetItemText( const OUString& sItemText )
196{
197 Any aOldValue, aNewValue;
198 if ( OCommonAccessibleText::implInitTextChangedEvent( m_sItemText, sItemText, aOldValue, aNewValue ) )
199 {
200 m_sItemText = sItemText;
201 NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue );
202 }
203}
204
205
207{
208 OUString sText;
209 if ( m_pParent )
210 sText = removeMnemonicFromString( m_pParent->GetItemText( m_pParent->GetItemId( m_nItemPos ) ) );
211
212 return sText;
213}
214
215
217{
218 bool bEnabled = IsEnabled();
219 if ( bEnabled )
220 {
221 rStateSet |= AccessibleStateType::ENABLED;
222 rStateSet |= AccessibleStateType::SENSITIVE;
223 }
224
225 if ( IsVisible() )
226 {
227 rStateSet |= AccessibleStateType::SHOWING;
228 if( !IsMenuHideDisabledEntries() || bEnabled )
229 rStateSet |= AccessibleStateType::VISIBLE;
230 }
231 rStateSet |= AccessibleStateType::OPAQUE;
232}
233
234
235// OCommonAccessibleComponent
236
237
239{
240 awt::Rectangle aBounds( 0, 0, 0, 0 );
241
242 if ( m_pParent )
243 {
244 // get bounding rectangle of the item relative to the containing window
245 aBounds = AWTRectangle( m_pParent->GetBoundingRectangle( m_nItemPos ) );
246
247 // get position of containing window in screen coordinates
248 vcl::Window* pWindow = m_pParent->GetWindow();
249 if ( pWindow )
250 {
252 awt::Point aWindowScreenLoc = AWTPoint( aRect.TopLeft() );
253
254 // get position of accessible parent in screen coordinates
256 if ( xParent.is() )
257 {
258 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
259 if ( xParentComponent.is() )
260 {
261 awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
262
263 // calculate bounding rectangle of the item relative to the accessible parent
264 aBounds.X += aWindowScreenLoc.X - aParentScreenLoc.X;
265 aBounds.Y += aWindowScreenLoc.Y - aParentScreenLoc.Y;
266 }
267 }
268 }
269 }
270
271 return aBounds;
272}
273
274
275// XComponent
276
277
279{
281
282 m_pParent = nullptr;
283 m_sAccessibleName.clear();
284 m_sItemText.clear();
285}
286
287
288// XAccessibleContext
289
290
292{
293 OExternalLockGuard aGuard( this );
294
295 return 0;
296}
297
298
300{
301 OExternalLockGuard aGuard( this );
302
303 if ( i < 0 || i >= getAccessibleChildCount() )
304 throw IndexOutOfBoundsException();
305
307}
308
309
311{
312 OExternalLockGuard aGuard( this );
313
314 return m_pParent->GetAccessible();
315}
316
317
319{
320 OExternalLockGuard aGuard( this );
321
322 return m_nItemPos;
323}
324
325
327{
328 OExternalLockGuard aGuard( this );
329
330 return AccessibleRole::UNKNOWN;
331}
332
333
335{
336 OExternalLockGuard aGuard( this );
337
338 OUString sDescription;
339 if ( m_pParent )
340 sDescription = m_pParent->GetAccessibleDescription( m_pParent->GetItemId( m_nItemPos ) );
341
342 return sDescription;
343}
344
345
347{
348 OExternalLockGuard aGuard( this );
349
350 return m_sAccessibleName;
351}
352
353
354Reference< XAccessibleRelationSet > OAccessibleMenuItemComponent::getAccessibleRelationSet( )
355{
356 OExternalLockGuard aGuard( this );
357
359}
360
361
363{
364 OExternalLockGuard aGuard( this );
365
367}
368
369
370// XAccessibleComponent
371
372
374{
375 OExternalLockGuard aGuard( this );
376
378}
379
380
382{
383 // no focus for items
384}
385
386
388{
389 OExternalLockGuard aGuard( this );
390
391 sal_Int32 nColor = 0;
393 if ( xParent.is() )
394 {
395 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
396 if ( xParentComp.is() )
397 nColor = xParentComp->getForeground();
398 }
399
400 return nColor;
401}
402
403
405{
406 OExternalLockGuard aGuard( this );
407
408 sal_Int32 nColor = 0;
410 if ( xParent.is() )
411 {
412 Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
413 if ( xParentComp.is() )
414 nColor = xParentComp->getBackground();
415 }
416
417 return nColor;
418}
419
420
421// XAccessibleExtendedComponent
422
423
425{
426 OExternalLockGuard aGuard( this );
427
428 Reference< awt::XFont > xFont;
430 if ( xParent.is() )
431 {
432 Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
433 if ( xParentComp.is() )
434 xFont = xParentComp->getFont();
435 }
436
437 return xFont;
438}
439
440
442{
443 OExternalLockGuard aGuard( this );
444
445 return OUString();
446}
447
448
450{
451 OExternalLockGuard aGuard( this );
452
453 OUString sRet;
454 if ( m_pParent )
455 sRet = m_pParent->GetTipHelpText( m_pParent->GetItemId( m_nItemPos ) );
456
457 return sRet;
458}
459
460
462{
463 if (m_pParent )
464 {
465 if( m_pParent->GetMenuFlags() & MenuFlags::HideDisabledEntries)
466 {
467 return true;
468 }
469 }
470 return false;
471}
472
473/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LanguageTag & GetLanguageTag() const
const MouseSettings & GetMouseSettings() const
void SetMouseSettings(const MouseSettings &rSet)
static const AllSettings & GetSettings()
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
sal_Int32 GetMenuDelay() const
void SetMenuDelay(sal_Int32 nDelay)
virtual void SAL_CALL disposing() override
virtual void FillAccessibleStateSet(sal_Int64 &rStateSet) override
void SetItemText(const OUString &sItemText)
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
virtual void SAL_CALL disposing() override
virtual css::uno::Reference< css::awt::XFont > SAL_CALL getFont() override
virtual OUString SAL_CALL getToolTipText() override
virtual OUString SAL_CALL getAccessibleDescription() override
virtual sal_Int32 SAL_CALL getBackground() override
virtual bool IsMenuHideDisabledEntries() override
virtual void SAL_CALL grabFocus() override
virtual OUString SAL_CALL getTitledBorderText() override
virtual OUString SAL_CALL getAccessibleName() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
void SetAccessibleName(const OUString &sAccessibleName)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual css::awt::Rectangle implGetBounds() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
virtual sal_Int32 SAL_CALL getForeground() override
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
constexpr Point TopLeft() const
tools::Rectangle GetWindowExtentsAbsolute() const
const AllSettings & GetSettings() const
void SetSettings(const AllSettings &rSettings)
css::awt::Point AWTPoint(const ::Point &rVCLPoint)
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
OUString sName
VCL_DLLPUBLIC OUString removeMnemonicFromString(OUString const &rStr, sal_Int32 &rMnemonicPos)
bool bVisible