tdf#163962 Enable spell checking in editable sections in read-only mode
[LibreOffice.git] / vcl / source / accessibility / accessiblemenucomponent.cxx
blob4163d096011e79e7191fecc0d9d0ab433c29ac0f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <accessibility/accessiblemenucomponent.hxx>
22 #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
24 #include <com/sun/star/awt/XDevice.hpp>
25 #include <com/sun/star/awt/XVclWindowPeer.hpp>
26 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27 #include <comphelper/accessiblecontexthelper.hxx>
28 #include <unotools/accessiblerelationsethelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/window.hxx>
31 #include <vcl/menu.hxx>
32 #include <vcl/settings.hxx>
33 #include <vcl/unohelp.hxx>
34 #include <i18nlangtag/languagetag.hxx>
36 using namespace ::com::sun::star::accessibility;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star;
40 using namespace ::comphelper;
45 bool OAccessibleMenuComponent::IsEnabled()
47 return true;
51 bool OAccessibleMenuComponent::IsVisible()
53 bool bVisible = false;
55 if ( m_pMenu )
56 bVisible = m_pMenu->IsMenuVisible();
58 return bVisible;
62 void OAccessibleMenuComponent::FillAccessibleStateSet( sal_Int64& rStateSet )
64 if ( IsEnabled() )
66 rStateSet |= AccessibleStateType::ENABLED;
67 rStateSet |= AccessibleStateType::SENSITIVE;
70 rStateSet |= AccessibleStateType::FOCUSABLE;
72 if ( IsFocused() )
73 rStateSet |= AccessibleStateType::FOCUSED;
75 if ( IsVisible() )
77 rStateSet |= AccessibleStateType::VISIBLE;
78 rStateSet |= AccessibleStateType::SHOWING;
81 rStateSet |= AccessibleStateType::OPAQUE;
85 // OCommonAccessibleComponent
88 awt::Rectangle OAccessibleMenuComponent::implGetBounds()
90 awt::Rectangle aBounds( 0, 0, 0, 0 );
92 if ( m_pMenu )
94 vcl::Window* pWindow = m_pMenu->GetWindow();
95 if ( pWindow )
97 // get bounding rectangle of the window in screen coordinates
98 AbsoluteScreenPixelRectangle aRect = pWindow->GetWindowExtentsAbsolute();
99 aBounds = vcl::unohelper::ConvertToAWTRect(aRect);
101 // get position of the accessible parent in screen coordinates
102 Reference< XAccessible > xParent = getAccessibleParent();
103 if ( xParent.is() )
105 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
106 if ( xParentComponent.is() )
108 awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
110 // calculate position of the window relative to the accessible parent
111 aBounds.X -= aParentScreenLoc.X;
112 aBounds.Y -= aParentScreenLoc.Y;
118 return aBounds;
122 // XAccessibleContext
125 sal_Int64 OAccessibleMenuComponent::getAccessibleChildCount()
127 OExternalLockGuard aGuard( this );
129 return GetChildCount();
133 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleChild( sal_Int64 i )
135 OExternalLockGuard aGuard( this );
137 if ( i < 0 || i >= GetChildCount() )
138 throw IndexOutOfBoundsException();
140 return GetChild( i );
144 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleParent( )
146 OExternalLockGuard aGuard( this );
148 Reference< XAccessible > xParent;
150 if ( m_pMenu )
152 vcl::Window* pWindow = m_pMenu->GetWindow();
153 if ( pWindow )
155 vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
156 if ( pParent )
157 xParent = pParent->GetAccessible();
161 return xParent;
165 sal_Int16 OAccessibleMenuComponent::getAccessibleRole( )
167 OExternalLockGuard aGuard( this );
169 return AccessibleRole::UNKNOWN;
173 OUString OAccessibleMenuComponent::getAccessibleDescription( )
175 OExternalLockGuard aGuard( this );
177 OUString sDescription;
178 if ( m_pMenu )
180 vcl::Window* pWindow = m_pMenu->GetWindow();
181 if ( pWindow )
182 sDescription = pWindow->GetAccessibleDescription();
185 return sDescription;
189 OUString OAccessibleMenuComponent::getAccessibleName( )
191 OExternalLockGuard aGuard( this );
193 return OUString();
197 Reference< XAccessibleRelationSet > OAccessibleMenuComponent::getAccessibleRelationSet( )
199 OExternalLockGuard aGuard( this );
201 return new utl::AccessibleRelationSetHelper;
205 Locale OAccessibleMenuComponent::getLocale( )
207 OExternalLockGuard aGuard( this );
209 return Application::GetSettings().GetLanguageTag().getLocale();
213 // XAccessibleComponent
216 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleAtPoint( const awt::Point& rPoint )
218 OExternalLockGuard aGuard( this );
220 return GetChildAt( rPoint );
224 awt::Point OAccessibleMenuComponent::getLocationOnScreen( )
226 OExternalLockGuard aGuard( this );
228 awt::Point aPos;
230 if ( m_pMenu )
232 vcl::Window* pWindow = m_pMenu->GetWindow();
233 if ( pWindow )
235 AbsoluteScreenPixelRectangle aRect = pWindow->GetWindowExtentsAbsolute();
236 aPos = vcl::unohelper::ConvertToAWTPoint(aRect.TopLeft());
240 return aPos;
244 void OAccessibleMenuComponent::grabFocus( )
246 OExternalLockGuard aGuard( this );
248 if ( m_pMenu )
250 vcl::Window* pWindow = m_pMenu->GetWindow();
251 if ( pWindow )
252 pWindow->GrabFocus();
257 sal_Int32 OAccessibleMenuComponent::getForeground( )
259 OExternalLockGuard aGuard( this );
261 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
262 Color nColor = rStyleSettings.GetMenuTextColor();
264 return sal_Int32(nColor);
268 sal_Int32 OAccessibleMenuComponent::getBackground( )
270 OExternalLockGuard aGuard( this );
272 return 0;
276 // XAccessibleExtendedComponent
278 OUString OAccessibleMenuComponent::getTitledBorderText( )
280 OExternalLockGuard aGuard( this );
282 return OUString();
286 OUString OAccessibleMenuComponent::getToolTipText( )
288 OExternalLockGuard aGuard( this );
290 return OUString();
294 // XAccessibleSelection
297 void OAccessibleMenuComponent::selectAccessibleChild( sal_Int64 nChildIndex )
299 OExternalLockGuard aGuard( this );
301 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
302 throw IndexOutOfBoundsException();
304 SelectChild( nChildIndex );
308 sal_Bool OAccessibleMenuComponent::isAccessibleChildSelected( sal_Int64 nChildIndex )
310 OExternalLockGuard aGuard( this );
312 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
313 throw IndexOutOfBoundsException();
315 return IsChildSelected( nChildIndex );
319 void OAccessibleMenuComponent::clearAccessibleSelection( )
321 OExternalLockGuard aGuard( this );
323 DeSelectAll();
327 void OAccessibleMenuComponent::selectAllAccessibleChildren( )
329 // This method makes no sense in a menu, and so does nothing.
333 sal_Int64 OAccessibleMenuComponent::getSelectedAccessibleChildCount( )
335 OExternalLockGuard aGuard( this );
337 sal_Int64 nRet = 0;
339 for ( sal_Int64 i = 0, nCount = GetChildCount(); i < nCount; i++ )
341 if ( IsChildSelected( i ) )
342 ++nRet;
345 return nRet;
349 Reference< XAccessible > OAccessibleMenuComponent::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
351 OExternalLockGuard aGuard( this );
353 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
354 throw IndexOutOfBoundsException();
356 Reference< XAccessible > xChild;
358 for ( sal_Int64 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ )
360 if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
362 xChild = GetChild( i );
363 break;
367 return xChild;
371 void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int64 nChildIndex )
373 OExternalLockGuard aGuard( this );
375 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
376 throw IndexOutOfBoundsException();
378 DeSelectAll();
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */