LibreOffice Module accessibility (master) 1
vclxaccessiblemenubar.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#include <com/sun/star/accessibility/AccessibleRole.hpp>
24#include <vcl/svapp.hxx>
25#include <vcl/window.hxx>
26#include <vcl/menu.hxx>
27#include <vcl/settings.hxx>
28
29using namespace ::com::sun::star::accessibility;
30using namespace ::com::sun::star::uno;
31using namespace ::com::sun::star;
32using namespace ::comphelper;
33
34
35
36
39{
40 if ( pMenu )
41 {
42 m_pWindow = pMenu->GetWindow();
43
44 if ( m_pWindow )
45 m_pWindow->AddEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
46 }
47}
48
49
51{
52 if ( m_pWindow )
53 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
54}
55
56
58{
59 bool bFocused = false;
60
61 if ( m_pWindow && m_pWindow->HasFocus() && !IsChildHighlighted() )
62 bFocused = true;
63
64 return bFocused;
65}
66
67
68IMPL_LINK( VCLXAccessibleMenuBar, WindowEventListener, VclWindowEvent&, rEvent, void )
69{
70 assert( rEvent.GetWindow() );
71 if ( !rEvent.GetWindow()->IsAccessibilityEventsSuppressed() || ( rEvent.GetId() == VclEventId::ObjectDying ) )
72 {
73 ProcessWindowEvent( rEvent );
74 }
75}
76
77
79{
80 switch ( rVclWindowEvent.GetId() )
81 {
82 case VclEventId::WindowGetFocus:
83 case VclEventId::WindowLoseFocus:
84 {
85 SetFocused( rVclWindowEvent.GetId() == VclEventId::WindowGetFocus );
86 }
87 break;
88 case VclEventId::ObjectDying:
89 {
90 if ( m_pWindow )
91 {
92 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
93 m_pWindow = nullptr;
94 }
95 }
96 break;
97 default:
98 {
99 }
100 break;
101 }
102}
103
104
105// XComponent
106
107
109{
110 OAccessibleMenuComponent::disposing();
111
112 if ( m_pWindow )
113 {
114 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
115 m_pWindow = nullptr;
116 }
117}
118
119
120// XServiceInfo
121
122
124{
125 return "com.sun.star.comp.toolkit.AccessibleMenuBar";
126}
127
128
130{
131 return { "com.sun.star.awt.AccessibleMenuBar" };
132}
133
134
135// XAccessibleContext
136
137
139{
140 OExternalLockGuard aGuard( this );
141
142 sal_Int64 nIndexInParent = -1;
143
144 if ( m_pMenu )
145 {
146 vcl::Window* pWindow = m_pMenu->GetWindow();
147 if ( pWindow )
148 {
149 vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
150 if ( pParent )
151 {
152 for ( sal_uInt16 n = pParent->GetAccessibleChildWindowCount(); n; )
153 {
154 vcl::Window* pChild = pParent->GetAccessibleChildWindow( --n );
155 if ( pChild == pWindow )
156 {
157 nIndexInParent = n;
158 break;
159 }
160 }
161 }
162 }
163 }
164
165 return nIndexInParent;
166}
167
168
170{
171 OExternalLockGuard aGuard( this );
172
173 return AccessibleRole::MENU_BAR;
174}
175
176
177// XAccessibleExtendedComponent
178
179
181{
182 OExternalLockGuard aGuard( this );
183
184 return sal_Int32(Application::GetSettings().GetStyleSettings().GetMenuBarColor());
185}
186
187
188/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const AllSettings & GetSettings()
vcl::Window * GetWindow() const
virtual sal_Int32 SAL_CALL getBackground() override
void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent)
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
VclPtr< vcl::Window > m_pWindow
virtual bool IsFocused() override
virtual ~VCLXAccessibleMenuBar() override
virtual void SAL_CALL disposing() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
VclEventId GetId() const
vcl::Window * GetAccessibleChildWindow(sal_uInt16 n)
sal_uInt16 GetAccessibleChildWindowCount()
vcl::Window * GetAccessibleParentWindow() const
sal_Int64 n
IMPL_LINK(VCLXAccessibleMenuBar, WindowEventListener, VclWindowEvent &, rEvent, void)