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 <comphelper/accessiblecontexthelper.hxx>
25 #include <vcl/menu.hxx>
28 using namespace ::com::sun::star
;
29 using namespace ::com::sun::star::lang
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::accessibility
;
32 using namespace ::comphelper
;
38 bool VCLXAccessibleMenu::IsFocused()
40 bool bFocused
= false;
42 if ( IsHighlighted() && !IsChildHighlighted() )
49 bool VCLXAccessibleMenu::IsPopupMenuOpen()
51 bool bPopupMenuOpen
= false;
55 PopupMenu
* pPopupMenu
= m_pParent
->GetPopupMenu( m_pParent
->GetItemId( m_nItemPos
) );
56 if ( pPopupMenu
&& pPopupMenu
->IsMenuVisible() )
57 bPopupMenuOpen
= true;
60 return bPopupMenuOpen
;
67 OUString
VCLXAccessibleMenu::getImplementationName()
69 return "com.sun.star.comp.toolkit.AccessibleMenu";
73 Sequence
< OUString
> VCLXAccessibleMenu::getSupportedServiceNames()
75 return { "com.sun.star.awt.AccessibleMenu" };
82 sal_Int64
VCLXAccessibleMenu::getAccessibleChildCount( )
84 OExternalLockGuard
aGuard( this );
86 return GetChildCount();
90 Reference
< XAccessible
> VCLXAccessibleMenu::getAccessibleChild( sal_Int64 i
)
92 OExternalLockGuard
aGuard( this );
94 if ( i
< 0 || i
>= GetChildCount() )
95 throw IndexOutOfBoundsException();
101 sal_Int16
VCLXAccessibleMenu::getAccessibleRole( )
103 OExternalLockGuard
aGuard( this );
105 return AccessibleRole::MENU
;
109 // XAccessibleComponent
112 Reference
< XAccessible
> VCLXAccessibleMenu::getAccessibleAtPoint( const awt::Point
& rPoint
)
114 OExternalLockGuard
aGuard( this );
116 return GetChildAt( rPoint
);
120 // XAccessibleSelection
123 void VCLXAccessibleMenu::selectAccessibleChild( sal_Int64 nChildIndex
)
125 OExternalLockGuard
aGuard( this );
127 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
128 throw IndexOutOfBoundsException();
130 SelectChild( nChildIndex
);
134 sal_Bool
VCLXAccessibleMenu::isAccessibleChildSelected( sal_Int64 nChildIndex
)
136 OExternalLockGuard
aGuard( this );
138 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
139 throw IndexOutOfBoundsException();
141 return IsChildSelected( nChildIndex
);
145 void VCLXAccessibleMenu::clearAccessibleSelection( )
147 OExternalLockGuard
aGuard( this );
153 void VCLXAccessibleMenu::selectAllAccessibleChildren( )
155 // This method makes no sense in a menu, and so does nothing.
159 sal_Int64
VCLXAccessibleMenu::getSelectedAccessibleChildCount( )
161 OExternalLockGuard
aGuard( this );
163 return implGetSelectedAccessibleChildCount();
166 sal_Int64
VCLXAccessibleMenu::implGetSelectedAccessibleChildCount( )
170 for ( sal_Int64 i
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
172 if ( IsChildSelected( i
) )
179 Reference
< XAccessible
> VCLXAccessibleMenu::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex
)
181 OExternalLockGuard
aGuard( this );
183 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
184 throw IndexOutOfBoundsException();
186 Reference
< XAccessible
> xChild
;
188 for ( sal_Int64 i
= 0, j
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
190 if ( IsChildSelected( i
) && ( j
++ == nSelectedChildIndex
) )
192 xChild
= GetChild( i
);
201 void VCLXAccessibleMenu::deselectAccessibleChild( sal_Int64 nChildIndex
)
203 OExternalLockGuard
aGuard( this );
205 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
206 throw IndexOutOfBoundsException();
212 OUString
VCLXAccessibleMenu::getAccessibleActionDescription ( sal_Int32 nIndex
)
214 OExternalLockGuard
aGuard( this );
216 if ( nIndex
< 0 || nIndex
>= getAccessibleActionCount() )
217 throw IndexOutOfBoundsException();
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */