1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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()
53 bool OAccessibleMenuComponent::IsVisible()
55 bool bVisible
= false;
58 bVisible
= m_pMenu
->IsMenuVisible();
64 void OAccessibleMenuComponent::FillAccessibleStateSet( sal_Int64
& rStateSet
)
68 rStateSet
|= AccessibleStateType::ENABLED
;
69 rStateSet
|= AccessibleStateType::SENSITIVE
;
72 rStateSet
|= AccessibleStateType::FOCUSABLE
;
75 rStateSet
|= AccessibleStateType::FOCUSED
;
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 );
96 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
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();
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
;
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
;
154 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
157 vcl::Window
* pParent
= pWindow
->GetAccessibleParentWindow();
159 xParent
= pParent
->GetAccessible();
167 sal_Int16
OAccessibleMenuComponent::getAccessibleRole( )
169 OExternalLockGuard
aGuard( this );
171 return AccessibleRole::UNKNOWN
;
175 OUString
OAccessibleMenuComponent::getAccessibleDescription( )
177 OExternalLockGuard
aGuard( this );
179 OUString sDescription
;
182 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
184 sDescription
= pWindow
->GetAccessibleDescription();
191 OUString
OAccessibleMenuComponent::getAccessibleName( )
193 OExternalLockGuard
aGuard( this );
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 );
234 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
237 tools::Rectangle aRect
= pWindow
->GetWindowExtentsRelative( nullptr );
238 aPos
= AWTPoint( aRect
.TopLeft() );
246 void OAccessibleMenuComponent::grabFocus( )
248 OExternalLockGuard
aGuard( this );
252 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
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 );
278 // XAccessibleExtendedComponent
281 Reference
< awt::XFont
> OAccessibleMenuComponent::getFont( )
283 OExternalLockGuard
aGuard( this );
285 Reference
< awt::XFont
> xFont
;
289 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
292 Reference
< awt::XDevice
> xDev( pWindow
->GetComponentInterface(), UNO_QUERY
);
295 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
296 rtl::Reference
<VCLXFont
> pVCLXFont
= new VCLXFont
;
297 pVCLXFont
->Init( *xDev
, rStyleSettings
.GetMenuFont() );
307 OUString
OAccessibleMenuComponent::getTitledBorderText( )
309 OExternalLockGuard
aGuard( this );
315 OUString
OAccessibleMenuComponent::getToolTipText( )
317 OExternalLockGuard
aGuard( this );
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 );
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 );
368 for ( sal_Int64 i
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
370 if ( IsChildSelected( i
) )
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
);
400 void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int64 nChildIndex
)
402 OExternalLockGuard
aGuard( this );
404 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
405 throw IndexOutOfBoundsException();
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */