Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / source / standard / accessiblemenucomponent.cxx
blob997abc9817ae5394d2fdc73f39b35df68c40d26f
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 <standard/accessiblemenucomponent.hxx>
22 #include <toolkit/awt/vclxfont.hxx>
23 #include <toolkit/helper/convert.hxx>
25 #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 #include <com/sun/star/awt/XDevice.hpp>
28 #include <com/sun/star/awt/XVclWindowPeer.hpp>
29 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30 #include <comphelper/accessiblecontexthelper.hxx>
31 #include <unotools/accessiblerelationsethelper.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/window.hxx>
34 #include <vcl/menu.hxx>
35 #include <vcl/settings.hxx>
36 #include <i18nlangtag/languagetag.hxx>
38 using namespace ::com::sun::star::accessibility;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star;
42 using namespace ::comphelper;
47 bool OAccessibleMenuComponent::IsEnabled()
49 return true;
53 bool OAccessibleMenuComponent::IsVisible()
55 bool bVisible = false;
57 if ( m_pMenu )
58 bVisible = m_pMenu->IsMenuVisible();
60 return bVisible;
64 void OAccessibleMenuComponent::FillAccessibleStateSet( sal_Int64& rStateSet )
66 if ( IsEnabled() )
68 rStateSet |= AccessibleStateType::ENABLED;
69 rStateSet |= AccessibleStateType::SENSITIVE;
72 rStateSet |= AccessibleStateType::FOCUSABLE;
74 if ( IsFocused() )
75 rStateSet |= AccessibleStateType::FOCUSED;
77 if ( IsVisible() )
79 rStateSet |= AccessibleStateType::VISIBLE;
80 rStateSet |= AccessibleStateType::SHOWING;
83 rStateSet |= AccessibleStateType::OPAQUE;
87 // OCommonAccessibleComponent
90 awt::Rectangle OAccessibleMenuComponent::implGetBounds()
92 awt::Rectangle aBounds( 0, 0, 0, 0 );
94 if ( m_pMenu )
96 vcl::Window* pWindow = m_pMenu->GetWindow();
97 if ( pWindow )
99 // get bounding rectangle of the window in screen coordinates
100 tools::Rectangle aRect = pWindow->GetWindowExtentsRelative( nullptr );
101 aBounds = AWTRectangle( aRect );
103 // get position of the accessible parent in screen coordinates
104 Reference< XAccessible > xParent = getAccessibleParent();
105 if ( xParent.is() )
107 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
108 if ( xParentComponent.is() )
110 awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
112 // calculate position of the window relative to the accessible parent
113 aBounds.X -= aParentScreenLoc.X;
114 aBounds.Y -= aParentScreenLoc.Y;
120 return aBounds;
124 // XAccessibleContext
127 sal_Int64 OAccessibleMenuComponent::getAccessibleChildCount()
129 OExternalLockGuard aGuard( this );
131 return GetChildCount();
135 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleChild( sal_Int64 i )
137 OExternalLockGuard aGuard( this );
139 if ( i < 0 || i >= GetChildCount() )
140 throw IndexOutOfBoundsException();
142 return GetChild( i );
146 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleParent( )
148 OExternalLockGuard aGuard( this );
150 Reference< XAccessible > xParent;
152 if ( m_pMenu )
154 vcl::Window* pWindow = m_pMenu->GetWindow();
155 if ( pWindow )
157 vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
158 if ( pParent )
159 xParent = pParent->GetAccessible();
163 return xParent;
167 sal_Int16 OAccessibleMenuComponent::getAccessibleRole( )
169 OExternalLockGuard aGuard( this );
171 return AccessibleRole::UNKNOWN;
175 OUString OAccessibleMenuComponent::getAccessibleDescription( )
177 OExternalLockGuard aGuard( this );
179 OUString sDescription;
180 if ( m_pMenu )
182 vcl::Window* pWindow = m_pMenu->GetWindow();
183 if ( pWindow )
184 sDescription = pWindow->GetAccessibleDescription();
187 return sDescription;
191 OUString OAccessibleMenuComponent::getAccessibleName( )
193 OExternalLockGuard aGuard( this );
195 return OUString();
199 Reference< XAccessibleRelationSet > OAccessibleMenuComponent::getAccessibleRelationSet( )
201 OExternalLockGuard aGuard( this );
203 return new utl::AccessibleRelationSetHelper;
207 Locale OAccessibleMenuComponent::getLocale( )
209 OExternalLockGuard aGuard( this );
211 return Application::GetSettings().GetLanguageTag().getLocale();
215 // XAccessibleComponent
218 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleAtPoint( const awt::Point& rPoint )
220 OExternalLockGuard aGuard( this );
222 return GetChildAt( rPoint );
226 awt::Point OAccessibleMenuComponent::getLocationOnScreen( )
228 OExternalLockGuard aGuard( this );
230 awt::Point aPos;
232 if ( m_pMenu )
234 vcl::Window* pWindow = m_pMenu->GetWindow();
235 if ( pWindow )
237 tools::Rectangle aRect = pWindow->GetWindowExtentsRelative( nullptr );
238 aPos = AWTPoint( aRect.TopLeft() );
242 return aPos;
246 void OAccessibleMenuComponent::grabFocus( )
248 OExternalLockGuard aGuard( this );
250 if ( m_pMenu )
252 vcl::Window* pWindow = m_pMenu->GetWindow();
253 if ( pWindow )
254 pWindow->GrabFocus();
259 sal_Int32 OAccessibleMenuComponent::getForeground( )
261 OExternalLockGuard aGuard( this );
263 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
264 Color nColor = rStyleSettings.GetMenuTextColor();
266 return sal_Int32(nColor);
270 sal_Int32 OAccessibleMenuComponent::getBackground( )
272 OExternalLockGuard aGuard( this );
274 return 0;
278 // XAccessibleExtendedComponent
281 Reference< awt::XFont > OAccessibleMenuComponent::getFont( )
283 OExternalLockGuard aGuard( this );
285 Reference< awt::XFont > xFont;
287 if ( m_pMenu )
289 vcl::Window* pWindow = m_pMenu->GetWindow();
290 if ( pWindow )
292 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
293 if ( xDev.is() )
295 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
296 rtl::Reference<VCLXFont> pVCLXFont = new VCLXFont;
297 pVCLXFont->Init( *xDev, rStyleSettings.GetMenuFont() );
298 xFont = pVCLXFont;
303 return xFont;
307 OUString OAccessibleMenuComponent::getTitledBorderText( )
309 OExternalLockGuard aGuard( this );
311 return OUString();
315 OUString OAccessibleMenuComponent::getToolTipText( )
317 OExternalLockGuard aGuard( this );
319 return OUString();
323 // XAccessibleSelection
326 void OAccessibleMenuComponent::selectAccessibleChild( sal_Int64 nChildIndex )
328 OExternalLockGuard aGuard( this );
330 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
331 throw IndexOutOfBoundsException();
333 SelectChild( nChildIndex );
337 sal_Bool OAccessibleMenuComponent::isAccessibleChildSelected( sal_Int64 nChildIndex )
339 OExternalLockGuard aGuard( this );
341 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
342 throw IndexOutOfBoundsException();
344 return IsChildSelected( nChildIndex );
348 void OAccessibleMenuComponent::clearAccessibleSelection( )
350 OExternalLockGuard aGuard( this );
352 DeSelectAll();
356 void OAccessibleMenuComponent::selectAllAccessibleChildren( )
358 // This method makes no sense in a menu, and so does nothing.
362 sal_Int64 OAccessibleMenuComponent::getSelectedAccessibleChildCount( )
364 OExternalLockGuard aGuard( this );
366 sal_Int64 nRet = 0;
368 for ( sal_Int64 i = 0, nCount = GetChildCount(); i < nCount; i++ )
370 if ( IsChildSelected( i ) )
371 ++nRet;
374 return nRet;
378 Reference< XAccessible > OAccessibleMenuComponent::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex )
380 OExternalLockGuard aGuard( this );
382 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
383 throw IndexOutOfBoundsException();
385 Reference< XAccessible > xChild;
387 for ( sal_Int64 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ )
389 if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
391 xChild = GetChild( i );
392 break;
396 return xChild;
400 void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int64 nChildIndex )
402 OExternalLockGuard aGuard( this );
404 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
405 throw IndexOutOfBoundsException();
407 DeSelectAll();
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */