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 <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()
51 bool OAccessibleMenuComponent::IsVisible()
53 bool bVisible
= false;
56 bVisible
= m_pMenu
->IsMenuVisible();
62 void OAccessibleMenuComponent::FillAccessibleStateSet( sal_Int64
& rStateSet
)
66 rStateSet
|= AccessibleStateType::ENABLED
;
67 rStateSet
|= AccessibleStateType::SENSITIVE
;
70 rStateSet
|= AccessibleStateType::FOCUSABLE
;
73 rStateSet
|= AccessibleStateType::FOCUSED
;
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 );
94 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
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();
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
;
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
;
152 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
155 vcl::Window
* pParent
= pWindow
->GetAccessibleParentWindow();
157 xParent
= pParent
->GetAccessible();
165 sal_Int16
OAccessibleMenuComponent::getAccessibleRole( )
167 OExternalLockGuard
aGuard( this );
169 return AccessibleRole::UNKNOWN
;
173 OUString
OAccessibleMenuComponent::getAccessibleDescription( )
175 OExternalLockGuard
aGuard( this );
177 OUString sDescription
;
180 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
182 sDescription
= pWindow
->GetAccessibleDescription();
189 OUString
OAccessibleMenuComponent::getAccessibleName( )
191 OExternalLockGuard
aGuard( this );
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 );
232 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
235 AbsoluteScreenPixelRectangle aRect
= pWindow
->GetWindowExtentsAbsolute();
236 aPos
= vcl::unohelper::ConvertToAWTPoint(aRect
.TopLeft());
244 void OAccessibleMenuComponent::grabFocus( )
246 OExternalLockGuard
aGuard( this );
250 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
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 );
276 // XAccessibleExtendedComponent
278 OUString
OAccessibleMenuComponent::getTitledBorderText( )
280 OExternalLockGuard
aGuard( this );
286 OUString
OAccessibleMenuComponent::getToolTipText( )
288 OExternalLockGuard
aGuard( this );
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 );
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 );
339 for ( sal_Int64 i
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
341 if ( IsChildSelected( i
) )
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
);
371 void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int64 nChildIndex
)
373 OExternalLockGuard
aGuard( this );
375 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
376 throw IndexOutOfBoundsException();
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */