Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblemenu.cxx
blob80758f805a6e3f0ba94d545a327b28a6dc104a42
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 <accessibility/standard/vclxaccessiblemenu.hxx>
22 #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 #include <vcl/menu.hxx>
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::lang;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::accessibility;
30 using namespace ::comphelper;
34 // VCLXAccessibleMenu
37 VCLXAccessibleMenu::VCLXAccessibleMenu( Menu* pParent, sal_uInt16 nItemPos, Menu* pMenu )
38 :VCLXAccessibleMenuItem( pParent, nItemPos, pMenu )
44 VCLXAccessibleMenu::~VCLXAccessibleMenu()
50 bool VCLXAccessibleMenu::IsFocused()
52 bool bFocused = false;
54 if ( IsHighlighted() && !IsChildHighlighted() )
55 bFocused = true;
57 return bFocused;
62 bool VCLXAccessibleMenu::IsPopupMenuOpen()
64 bool bPopupMenuOpen = false;
66 if ( m_pParent )
68 PopupMenu* pPopupMenu = m_pParent->GetPopupMenu( m_pParent->GetItemId( m_nItemPos ) );
69 if ( pPopupMenu && pPopupMenu->IsMenuVisible() )
70 bPopupMenuOpen = true;
73 return bPopupMenuOpen;
77 // XInterface
80 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleMenu, VCLXAccessibleMenuItem, VCLXAccessibleMenu_BASE )
83 // XTypeProvider
86 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleMenu, VCLXAccessibleMenuItem, VCLXAccessibleMenu_BASE )
89 // XServiceInfo
92 OUString VCLXAccessibleMenu::getImplementationName() throw (RuntimeException, std::exception)
94 return OUString( "com.sun.star.comp.toolkit.AccessibleMenu" );
99 Sequence< OUString > VCLXAccessibleMenu::getSupportedServiceNames() throw (RuntimeException, std::exception)
101 Sequence< OUString > aNames(1);
102 aNames[0] = "com.sun.star.awt.AccessibleMenu";
103 return aNames;
107 // XAccessibleContext
110 sal_Int32 VCLXAccessibleMenu::getAccessibleChildCount( ) throw (RuntimeException, std::exception)
112 OExternalLockGuard aGuard( this );
114 return GetChildCount();
119 Reference< XAccessible > VCLXAccessibleMenu::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
121 OExternalLockGuard aGuard( this );
123 if ( i < 0 || i >= GetChildCount() )
124 throw IndexOutOfBoundsException();
126 return GetChild( i );
131 sal_Int16 VCLXAccessibleMenu::getAccessibleRole( ) throw (RuntimeException, std::exception)
133 OExternalLockGuard aGuard( this );
135 return AccessibleRole::MENU;
139 // XAccessibleComponent
142 Reference< XAccessible > VCLXAccessibleMenu::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException, std::exception)
144 OExternalLockGuard aGuard( this );
146 return GetChildAt( rPoint );
150 // XAccessibleSelection
153 void VCLXAccessibleMenu::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
155 OExternalLockGuard aGuard( this );
157 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
158 throw IndexOutOfBoundsException();
160 SelectChild( nChildIndex );
165 sal_Bool VCLXAccessibleMenu::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
167 OExternalLockGuard aGuard( this );
169 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
170 throw IndexOutOfBoundsException();
172 return IsChildSelected( nChildIndex );
177 void VCLXAccessibleMenu::clearAccessibleSelection( ) throw (RuntimeException, std::exception)
179 OExternalLockGuard aGuard( this );
181 DeSelectAll();
186 void VCLXAccessibleMenu::selectAllAccessibleChildren( ) throw (RuntimeException, std::exception)
188 // This method makes no sense in a menu, and so does nothing.
193 sal_Int32 VCLXAccessibleMenu::getSelectedAccessibleChildCount( ) throw (RuntimeException, std::exception)
195 OExternalLockGuard aGuard( this );
197 sal_Int32 nRet = 0;
199 for ( sal_Int32 i = 0, nCount = GetChildCount(); i < nCount; i++ )
201 if ( IsChildSelected( i ) )
202 ++nRet;
205 return nRet;
210 Reference< XAccessible > VCLXAccessibleMenu::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
212 OExternalLockGuard aGuard( this );
214 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
215 throw IndexOutOfBoundsException();
217 Reference< XAccessible > xChild;
219 for ( sal_Int32 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ )
221 if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
223 xChild = GetChild( i );
224 break;
228 return xChild;
233 void VCLXAccessibleMenu::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
235 OExternalLockGuard aGuard( this );
237 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
238 throw IndexOutOfBoundsException();
240 DeSelectAll();
245 OUString VCLXAccessibleMenu::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
247 OExternalLockGuard aGuard( this );
249 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
250 throw IndexOutOfBoundsException();
252 return OUString( );
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */