/src/libreoffice/vcl/source/accessibility/accessiblemenucomponent.cxx
Line | Count | Source (jump to first uncovered line) |
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/accessiblemenucomponent.hxx> |
21 | | |
22 | | #include <com/sun/star/accessibility/AccessibleRole.hpp> |
23 | | #include <com/sun/star/accessibility/AccessibleStateType.hpp> |
24 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
25 | | #include <comphelper/accessiblecontexthelper.hxx> |
26 | | #include <unotools/accessiblerelationsethelper.hxx> |
27 | | #include <vcl/svapp.hxx> |
28 | | #include <vcl/window.hxx> |
29 | | #include <vcl/menu.hxx> |
30 | | #include <vcl/settings.hxx> |
31 | | #include <vcl/unohelp.hxx> |
32 | | #include <i18nlangtag/languagetag.hxx> |
33 | | |
34 | | using namespace ::com::sun::star::accessibility; |
35 | | using namespace ::com::sun::star::uno; |
36 | | using namespace ::com::sun::star::lang; |
37 | | using namespace ::com::sun::star; |
38 | | using namespace ::comphelper; |
39 | | |
40 | | |
41 | | |
42 | | |
43 | | bool OAccessibleMenuComponent::IsEnabled() |
44 | 0 | { |
45 | 0 | return true; |
46 | 0 | } |
47 | | |
48 | | |
49 | | bool OAccessibleMenuComponent::IsVisible() |
50 | 0 | { |
51 | 0 | bool bVisible = false; |
52 | |
|
53 | 0 | if ( m_pMenu ) |
54 | 0 | bVisible = m_pMenu->IsMenuVisible(); |
55 | |
|
56 | 0 | return bVisible; |
57 | 0 | } |
58 | | |
59 | | |
60 | | void OAccessibleMenuComponent::FillAccessibleStateSet( sal_Int64& rStateSet ) |
61 | 0 | { |
62 | 0 | if ( IsEnabled() ) |
63 | 0 | { |
64 | 0 | rStateSet |= AccessibleStateType::ENABLED; |
65 | 0 | rStateSet |= AccessibleStateType::SENSITIVE; |
66 | 0 | } |
67 | |
|
68 | 0 | rStateSet |= AccessibleStateType::FOCUSABLE; |
69 | |
|
70 | 0 | if ( IsFocused() ) |
71 | 0 | rStateSet |= AccessibleStateType::FOCUSED; |
72 | |
|
73 | 0 | if ( IsVisible() ) |
74 | 0 | { |
75 | 0 | rStateSet |= AccessibleStateType::VISIBLE; |
76 | 0 | rStateSet |= AccessibleStateType::SHOWING; |
77 | 0 | } |
78 | |
|
79 | 0 | rStateSet |= AccessibleStateType::OPAQUE; |
80 | 0 | } |
81 | | |
82 | | // OAccessible |
83 | | |
84 | | awt::Rectangle OAccessibleMenuComponent::implGetBounds() |
85 | 0 | { |
86 | 0 | awt::Rectangle aBounds( 0, 0, 0, 0 ); |
87 | |
|
88 | 0 | if ( m_pMenu ) |
89 | 0 | { |
90 | 0 | vcl::Window* pWindow = m_pMenu->GetWindow(); |
91 | 0 | if ( pWindow ) |
92 | 0 | { |
93 | | // get bounding rectangle of the window in screen coordinates |
94 | 0 | AbsoluteScreenPixelRectangle aRect = pWindow->GetWindowExtentsAbsolute(); |
95 | 0 | aBounds = vcl::unohelper::ConvertToAWTRect(aRect); |
96 | | |
97 | | // get position of the accessible parent in screen coordinates |
98 | 0 | Reference< XAccessible > xParent = getAccessibleParent(); |
99 | 0 | if ( xParent.is() ) |
100 | 0 | { |
101 | 0 | Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY ); |
102 | 0 | if ( xParentComponent.is() ) |
103 | 0 | { |
104 | 0 | awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen(); |
105 | | |
106 | | // calculate position of the window relative to the accessible parent |
107 | 0 | aBounds.X -= aParentScreenLoc.X; |
108 | 0 | aBounds.Y -= aParentScreenLoc.Y; |
109 | 0 | } |
110 | 0 | } |
111 | 0 | } |
112 | 0 | } |
113 | |
|
114 | 0 | return aBounds; |
115 | 0 | } |
116 | | |
117 | | |
118 | | // XAccessibleContext |
119 | | |
120 | | |
121 | | sal_Int64 OAccessibleMenuComponent::getAccessibleChildCount() |
122 | 0 | { |
123 | 0 | OExternalLockGuard aGuard( this ); |
124 | |
|
125 | 0 | return GetChildCount(); |
126 | 0 | } |
127 | | |
128 | | |
129 | | Reference< XAccessible > OAccessibleMenuComponent::getAccessibleChild( sal_Int64 i ) |
130 | 0 | { |
131 | 0 | OExternalLockGuard aGuard( this ); |
132 | |
|
133 | 0 | if ( i < 0 || i >= GetChildCount() ) |
134 | 0 | throw IndexOutOfBoundsException(); |
135 | | |
136 | 0 | return GetChild( i ); |
137 | 0 | } |
138 | | |
139 | | |
140 | | Reference< XAccessible > OAccessibleMenuComponent::getAccessibleParent( ) |
141 | 0 | { |
142 | 0 | OExternalLockGuard aGuard( this ); |
143 | |
|
144 | 0 | Reference< XAccessible > xParent; |
145 | |
|
146 | 0 | if ( m_pMenu ) |
147 | 0 | { |
148 | 0 | vcl::Window* pWindow = m_pMenu->GetWindow(); |
149 | 0 | if ( pWindow ) |
150 | 0 | xParent = pWindow->GetAccessibleParent(); |
151 | 0 | } |
152 | |
|
153 | 0 | return xParent; |
154 | 0 | } |
155 | | |
156 | | |
157 | | sal_Int16 OAccessibleMenuComponent::getAccessibleRole( ) |
158 | 0 | { |
159 | 0 | OExternalLockGuard aGuard( this ); |
160 | |
|
161 | 0 | return AccessibleRole::UNKNOWN; |
162 | 0 | } |
163 | | |
164 | | |
165 | | OUString OAccessibleMenuComponent::getAccessibleDescription( ) |
166 | 0 | { |
167 | 0 | OExternalLockGuard aGuard( this ); |
168 | |
|
169 | 0 | OUString sDescription; |
170 | 0 | if ( m_pMenu ) |
171 | 0 | { |
172 | 0 | vcl::Window* pWindow = m_pMenu->GetWindow(); |
173 | 0 | if ( pWindow ) |
174 | 0 | sDescription = pWindow->GetAccessibleDescription(); |
175 | 0 | } |
176 | |
|
177 | 0 | return sDescription; |
178 | 0 | } |
179 | | |
180 | | |
181 | | OUString OAccessibleMenuComponent::getAccessibleName( ) |
182 | 0 | { |
183 | 0 | OExternalLockGuard aGuard( this ); |
184 | |
|
185 | 0 | return OUString(); |
186 | 0 | } |
187 | | |
188 | | |
189 | | Reference< XAccessibleRelationSet > OAccessibleMenuComponent::getAccessibleRelationSet( ) |
190 | 0 | { |
191 | 0 | OExternalLockGuard aGuard( this ); |
192 | |
|
193 | 0 | return new utl::AccessibleRelationSetHelper; |
194 | 0 | } |
195 | | |
196 | | |
197 | | Locale OAccessibleMenuComponent::getLocale( ) |
198 | 0 | { |
199 | 0 | OExternalLockGuard aGuard( this ); |
200 | |
|
201 | 0 | return Application::GetSettings().GetLanguageTag().getLocale(); |
202 | 0 | } |
203 | | |
204 | | |
205 | | // XAccessibleComponent |
206 | | |
207 | | |
208 | | Reference< XAccessible > OAccessibleMenuComponent::getAccessibleAtPoint( const awt::Point& rPoint ) |
209 | 0 | { |
210 | 0 | OExternalLockGuard aGuard( this ); |
211 | |
|
212 | 0 | return GetChildAt( rPoint ); |
213 | 0 | } |
214 | | |
215 | | |
216 | | awt::Point OAccessibleMenuComponent::getLocationOnScreen( ) |
217 | 0 | { |
218 | 0 | OExternalLockGuard aGuard( this ); |
219 | |
|
220 | 0 | awt::Point aPos; |
221 | |
|
222 | 0 | if ( m_pMenu ) |
223 | 0 | { |
224 | 0 | vcl::Window* pWindow = m_pMenu->GetWindow(); |
225 | 0 | if ( pWindow ) |
226 | 0 | { |
227 | 0 | AbsoluteScreenPixelRectangle aRect = pWindow->GetWindowExtentsAbsolute(); |
228 | 0 | aPos = vcl::unohelper::ConvertToAWTPoint(aRect.TopLeft()); |
229 | 0 | } |
230 | 0 | } |
231 | |
|
232 | 0 | return aPos; |
233 | 0 | } |
234 | | |
235 | | |
236 | | void OAccessibleMenuComponent::grabFocus( ) |
237 | 0 | { |
238 | 0 | OExternalLockGuard aGuard( this ); |
239 | |
|
240 | 0 | if ( m_pMenu ) |
241 | 0 | { |
242 | 0 | vcl::Window* pWindow = m_pMenu->GetWindow(); |
243 | 0 | if ( pWindow ) |
244 | 0 | pWindow->GrabFocus(); |
245 | 0 | } |
246 | 0 | } |
247 | | |
248 | | |
249 | | sal_Int32 OAccessibleMenuComponent::getForeground( ) |
250 | 0 | { |
251 | 0 | OExternalLockGuard aGuard( this ); |
252 | |
|
253 | 0 | const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); |
254 | 0 | Color nColor = rStyleSettings.GetMenuTextColor(); |
255 | |
|
256 | 0 | return sal_Int32(nColor); |
257 | 0 | } |
258 | | |
259 | | |
260 | | sal_Int32 OAccessibleMenuComponent::getBackground( ) |
261 | 0 | { |
262 | 0 | OExternalLockGuard aGuard( this ); |
263 | |
|
264 | 0 | return 0; |
265 | 0 | } |
266 | | |
267 | | // XAccessibleSelection |
268 | | |
269 | | |
270 | | void OAccessibleMenuComponent::selectAccessibleChild( sal_Int64 nChildIndex ) |
271 | 0 | { |
272 | 0 | OExternalLockGuard aGuard( this ); |
273 | |
|
274 | 0 | if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) |
275 | 0 | throw IndexOutOfBoundsException(); |
276 | | |
277 | 0 | SelectChild( nChildIndex ); |
278 | 0 | } |
279 | | |
280 | | |
281 | | sal_Bool OAccessibleMenuComponent::isAccessibleChildSelected( sal_Int64 nChildIndex ) |
282 | 0 | { |
283 | 0 | OExternalLockGuard aGuard( this ); |
284 | |
|
285 | 0 | if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) |
286 | 0 | throw IndexOutOfBoundsException(); |
287 | | |
288 | 0 | return IsChildSelected( nChildIndex ); |
289 | 0 | } |
290 | | |
291 | | |
292 | | void OAccessibleMenuComponent::clearAccessibleSelection( ) |
293 | 0 | { |
294 | 0 | OExternalLockGuard aGuard( this ); |
295 | |
|
296 | 0 | DeSelectAll(); |
297 | 0 | } |
298 | | |
299 | | |
300 | | void OAccessibleMenuComponent::selectAllAccessibleChildren( ) |
301 | 0 | { |
302 | | // This method makes no sense in a menu, and so does nothing. |
303 | 0 | } |
304 | | |
305 | | |
306 | | sal_Int64 OAccessibleMenuComponent::getSelectedAccessibleChildCount( ) |
307 | 0 | { |
308 | 0 | OExternalLockGuard aGuard( this ); |
309 | |
|
310 | 0 | sal_Int64 nRet = 0; |
311 | |
|
312 | 0 | for ( sal_Int64 i = 0, nCount = GetChildCount(); i < nCount; i++ ) |
313 | 0 | { |
314 | 0 | if ( IsChildSelected( i ) ) |
315 | 0 | ++nRet; |
316 | 0 | } |
317 | |
|
318 | 0 | return nRet; |
319 | 0 | } |
320 | | |
321 | | |
322 | | Reference< XAccessible > OAccessibleMenuComponent::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex ) |
323 | 0 | { |
324 | 0 | OExternalLockGuard aGuard( this ); |
325 | |
|
326 | 0 | if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() ) |
327 | 0 | throw IndexOutOfBoundsException(); |
328 | | |
329 | 0 | Reference< XAccessible > xChild; |
330 | |
|
331 | 0 | for ( sal_Int64 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ ) |
332 | 0 | { |
333 | 0 | if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) ) |
334 | 0 | { |
335 | 0 | xChild = GetChild( i ); |
336 | 0 | break; |
337 | 0 | } |
338 | 0 | } |
339 | |
|
340 | 0 | return xChild; |
341 | 0 | } |
342 | | |
343 | | |
344 | | void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int64 nChildIndex ) |
345 | 0 | { |
346 | 0 | OExternalLockGuard aGuard( this ); |
347 | |
|
348 | 0 | if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) |
349 | 0 | throw IndexOutOfBoundsException(); |
350 | | |
351 | 0 | DeSelectAll(); |
352 | 0 | } |
353 | | |
354 | | |
355 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |