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