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/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
;
33 // -----------------------------------------------------------------------------
35 // -----------------------------------------------------------------------------
37 VCLXAccessibleMenu::VCLXAccessibleMenu( Menu
* pParent
, sal_uInt16 nItemPos
, Menu
* pMenu
)
38 :VCLXAccessibleMenuItem( pParent
, nItemPos
, pMenu
)
42 // -----------------------------------------------------------------------------
44 VCLXAccessibleMenu::~VCLXAccessibleMenu()
48 // -----------------------------------------------------------------------------
50 sal_Bool
VCLXAccessibleMenu::IsFocused()
52 sal_Bool bFocused
= sal_False
;
54 if ( IsHighlighted() && !IsChildHighlighted() )
60 // -----------------------------------------------------------------------------
62 sal_Bool
VCLXAccessibleMenu::IsPopupMenuOpen()
64 sal_Bool bPopupMenuOpen
= sal_False
;
68 PopupMenu
* pPopupMenu
= m_pParent
->GetPopupMenu( m_pParent
->GetItemId( m_nItemPos
) );
69 if ( pPopupMenu
&& pPopupMenu
->IsMenuVisible() )
70 bPopupMenuOpen
= sal_True
;
73 return bPopupMenuOpen
;
76 // -----------------------------------------------------------------------------
78 // -----------------------------------------------------------------------------
80 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleMenu
, VCLXAccessibleMenuItem
, VCLXAccessibleMenu_BASE
)
82 // -----------------------------------------------------------------------------
84 // -----------------------------------------------------------------------------
86 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleMenu
, VCLXAccessibleMenuItem
, VCLXAccessibleMenu_BASE
)
88 // -----------------------------------------------------------------------------
90 // -----------------------------------------------------------------------------
92 OUString
VCLXAccessibleMenu::getImplementationName() throw (RuntimeException
)
94 return OUString( "com.sun.star.comp.toolkit.AccessibleMenu" );
97 // -----------------------------------------------------------------------------
99 Sequence
< OUString
> VCLXAccessibleMenu::getSupportedServiceNames() throw (RuntimeException
)
101 Sequence
< OUString
> aNames(1);
102 aNames
[0] = "com.sun.star.awt.AccessibleMenu";
106 // -----------------------------------------------------------------------------
107 // XAccessibleContext
108 // -----------------------------------------------------------------------------
110 sal_Int32
VCLXAccessibleMenu::getAccessibleChildCount( ) throw (RuntimeException
)
112 OExternalLockGuard
aGuard( this );
114 return GetChildCount();
117 // -----------------------------------------------------------------------------
119 Reference
< XAccessible
> VCLXAccessibleMenu::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
121 OExternalLockGuard
aGuard( this );
123 if ( i
< 0 || i
>= GetChildCount() )
124 throw IndexOutOfBoundsException();
126 return GetChild( i
);
129 // -----------------------------------------------------------------------------
131 sal_Int16
VCLXAccessibleMenu::getAccessibleRole( ) throw (RuntimeException
)
133 OExternalLockGuard
aGuard( this );
135 return AccessibleRole::MENU
;
138 // -----------------------------------------------------------------------------
139 // XAccessibleComponent
140 // -----------------------------------------------------------------------------
142 Reference
< XAccessible
> VCLXAccessibleMenu::getAccessibleAtPoint( const awt::Point
& rPoint
) throw (RuntimeException
)
144 OExternalLockGuard
aGuard( this );
146 return GetChildAt( rPoint
);
149 // -----------------------------------------------------------------------------
150 // XAccessibleSelection
151 // -----------------------------------------------------------------------------
153 void VCLXAccessibleMenu::selectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
155 OExternalLockGuard
aGuard( this );
157 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
158 throw IndexOutOfBoundsException();
160 SelectChild( nChildIndex
);
163 // -----------------------------------------------------------------------------
165 sal_Bool
VCLXAccessibleMenu::isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
167 OExternalLockGuard
aGuard( this );
169 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
170 throw IndexOutOfBoundsException();
172 return IsChildSelected( nChildIndex
);
175 // -----------------------------------------------------------------------------
177 void VCLXAccessibleMenu::clearAccessibleSelection( ) throw (RuntimeException
)
179 OExternalLockGuard
aGuard( this );
184 // -----------------------------------------------------------------------------
186 void VCLXAccessibleMenu::selectAllAccessibleChildren( ) throw (RuntimeException
)
188 // This method makes no sense in a menu, and so does nothing.
191 // -----------------------------------------------------------------------------
193 sal_Int32
VCLXAccessibleMenu::getSelectedAccessibleChildCount( ) throw (RuntimeException
)
195 OExternalLockGuard
aGuard( this );
199 for ( sal_Int32 i
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
201 if ( IsChildSelected( i
) )
208 // -----------------------------------------------------------------------------
210 Reference
< XAccessible
> VCLXAccessibleMenu::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
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
);
231 // -----------------------------------------------------------------------------
233 void VCLXAccessibleMenu::deselectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
235 OExternalLockGuard
aGuard( this );
237 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
238 throw IndexOutOfBoundsException();
243 // -----------------------------------------------------------------------------
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */