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/vclxaccessiblemenu.hxx>
22 #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24 #include <vcl/menu.hxx>
27 using namespace ::com::sun::star
;
28 using namespace ::com::sun::star::lang
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::accessibility
;
31 using namespace ::comphelper
;
37 bool VCLXAccessibleMenu::IsFocused()
39 bool bFocused
= false;
41 if ( IsHighlighted() && !IsChildHighlighted() )
48 bool VCLXAccessibleMenu::IsPopupMenuOpen()
50 bool bPopupMenuOpen
= false;
54 PopupMenu
* pPopupMenu
= m_pParent
->GetPopupMenu( m_pParent
->GetItemId( m_nItemPos
) );
55 if ( pPopupMenu
&& pPopupMenu
->IsMenuVisible() )
56 bPopupMenuOpen
= true;
59 return bPopupMenuOpen
;
66 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleMenu
, VCLXAccessibleMenuItem
, VCLXAccessibleMenu_BASE
)
72 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleMenu
, VCLXAccessibleMenuItem
, VCLXAccessibleMenu_BASE
)
78 OUString
VCLXAccessibleMenu::getImplementationName()
80 return "com.sun.star.comp.toolkit.AccessibleMenu";
84 Sequence
< OUString
> VCLXAccessibleMenu::getSupportedServiceNames()
86 return { "com.sun.star.awt.AccessibleMenu" };
93 sal_Int32
VCLXAccessibleMenu::getAccessibleChildCount( )
95 OExternalLockGuard
aGuard( this );
97 return GetChildCount();
101 Reference
< XAccessible
> VCLXAccessibleMenu::getAccessibleChild( sal_Int32 i
)
103 OExternalLockGuard
aGuard( this );
105 if ( i
< 0 || i
>= GetChildCount() )
106 throw IndexOutOfBoundsException();
108 return GetChild( i
);
112 sal_Int16
VCLXAccessibleMenu::getAccessibleRole( )
114 OExternalLockGuard
aGuard( this );
116 return AccessibleRole::MENU
;
120 // XAccessibleComponent
123 Reference
< XAccessible
> VCLXAccessibleMenu::getAccessibleAtPoint( const awt::Point
& rPoint
)
125 OExternalLockGuard
aGuard( this );
127 return GetChildAt( rPoint
);
131 // XAccessibleSelection
134 void VCLXAccessibleMenu::selectAccessibleChild( sal_Int32 nChildIndex
)
136 OExternalLockGuard
aGuard( this );
138 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
139 throw IndexOutOfBoundsException();
141 SelectChild( nChildIndex
);
145 sal_Bool
VCLXAccessibleMenu::isAccessibleChildSelected( sal_Int32 nChildIndex
)
147 OExternalLockGuard
aGuard( this );
149 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
150 throw IndexOutOfBoundsException();
152 return IsChildSelected( nChildIndex
);
156 void VCLXAccessibleMenu::clearAccessibleSelection( )
158 OExternalLockGuard
aGuard( this );
164 void VCLXAccessibleMenu::selectAllAccessibleChildren( )
166 // This method makes no sense in a menu, and so does nothing.
170 sal_Int32
VCLXAccessibleMenu::getSelectedAccessibleChildCount( )
172 OExternalLockGuard
aGuard( this );
174 return implGetSelectedAccessibleChildCount();
177 sal_Int32
VCLXAccessibleMenu::implGetSelectedAccessibleChildCount( )
181 for ( sal_Int32 i
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
183 if ( IsChildSelected( i
) )
190 Reference
< XAccessible
> VCLXAccessibleMenu::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
192 OExternalLockGuard
aGuard( this );
194 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
195 throw IndexOutOfBoundsException();
197 Reference
< XAccessible
> xChild
;
199 for ( sal_Int32 i
= 0, j
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
201 if ( IsChildSelected( i
) && ( j
++ == nSelectedChildIndex
) )
203 xChild
= GetChild( i
);
212 void VCLXAccessibleMenu::deselectAccessibleChild( sal_Int32 nChildIndex
)
214 OExternalLockGuard
aGuard( this );
216 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
217 throw IndexOutOfBoundsException();
223 OUString
VCLXAccessibleMenu::getAccessibleActionDescription ( sal_Int32 nIndex
)
225 OExternalLockGuard
aGuard( this );
227 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
228 throw IndexOutOfBoundsException();
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */