1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessiblemenu.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
34 // includes --------------------------------------------------------------
35 #include <accessibility/standard/vclxaccessiblemenu.hxx>
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
38 #include <vcl/menu.hxx>
41 using namespace ::com::sun::star
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::accessibility
;
45 using namespace ::comphelper
;
48 // -----------------------------------------------------------------------------
50 // -----------------------------------------------------------------------------
52 VCLXAccessibleMenu::VCLXAccessibleMenu( Menu
* pParent
, sal_uInt16 nItemPos
, Menu
* pMenu
)
53 :VCLXAccessibleMenuItem( pParent
, nItemPos
, pMenu
)
57 // -----------------------------------------------------------------------------
59 VCLXAccessibleMenu::~VCLXAccessibleMenu()
63 // -----------------------------------------------------------------------------
65 sal_Bool
VCLXAccessibleMenu::IsFocused()
67 sal_Bool bFocused
= sal_False
;
69 if ( IsHighlighted() && !IsChildHighlighted() )
75 // -----------------------------------------------------------------------------
77 sal_Bool
VCLXAccessibleMenu::IsPopupMenuOpen()
79 sal_Bool bPopupMenuOpen
= sal_False
;
83 PopupMenu
* pPopupMenu
= m_pParent
->GetPopupMenu( m_pParent
->GetItemId( m_nItemPos
) );
84 if ( pPopupMenu
&& pPopupMenu
->IsMenuVisible() )
85 bPopupMenuOpen
= sal_True
;
88 return bPopupMenuOpen
;
91 // -----------------------------------------------------------------------------
93 // -----------------------------------------------------------------------------
95 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleMenu
, VCLXAccessibleMenuItem
, VCLXAccessibleMenu_BASE
)
97 // -----------------------------------------------------------------------------
99 // -----------------------------------------------------------------------------
101 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleMenu
, VCLXAccessibleMenuItem
, VCLXAccessibleMenu_BASE
)
103 // -----------------------------------------------------------------------------
105 // -----------------------------------------------------------------------------
107 ::rtl::OUString
VCLXAccessibleMenu::getImplementationName() throw (RuntimeException
)
109 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleMenu" );
112 // -----------------------------------------------------------------------------
114 Sequence
< ::rtl::OUString
> VCLXAccessibleMenu::getSupportedServiceNames() throw (RuntimeException
)
116 Sequence
< ::rtl::OUString
> aNames(1);
117 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleMenu" );
121 // -----------------------------------------------------------------------------
122 // XAccessibleContext
123 // -----------------------------------------------------------------------------
125 sal_Int32
VCLXAccessibleMenu::getAccessibleChildCount( ) throw (RuntimeException
)
127 OExternalLockGuard
aGuard( this );
129 return GetChildCount();
132 // -----------------------------------------------------------------------------
134 Reference
< XAccessible
> VCLXAccessibleMenu::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
136 OExternalLockGuard
aGuard( this );
138 if ( i
< 0 || i
>= GetChildCount() )
139 throw IndexOutOfBoundsException();
141 return GetChild( i
);
144 // -----------------------------------------------------------------------------
146 sal_Int16
VCLXAccessibleMenu::getAccessibleRole( ) throw (RuntimeException
)
148 OExternalLockGuard
aGuard( this );
150 return AccessibleRole::MENU
;
153 // -----------------------------------------------------------------------------
154 // XAccessibleComponent
155 // -----------------------------------------------------------------------------
157 Reference
< XAccessible
> VCLXAccessibleMenu::getAccessibleAtPoint( const awt::Point
& rPoint
) throw (RuntimeException
)
159 OExternalLockGuard
aGuard( this );
161 return GetChildAt( rPoint
);
164 // -----------------------------------------------------------------------------
165 // XAccessibleSelection
166 // -----------------------------------------------------------------------------
168 void VCLXAccessibleMenu::selectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
170 OExternalLockGuard
aGuard( this );
172 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
173 throw IndexOutOfBoundsException();
175 SelectChild( nChildIndex
);
178 // -----------------------------------------------------------------------------
180 sal_Bool
VCLXAccessibleMenu::isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
182 OExternalLockGuard
aGuard( this );
184 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
185 throw IndexOutOfBoundsException();
187 return IsChildSelected( nChildIndex
);
190 // -----------------------------------------------------------------------------
192 void VCLXAccessibleMenu::clearAccessibleSelection( ) throw (RuntimeException
)
194 OExternalLockGuard
aGuard( this );
199 // -----------------------------------------------------------------------------
201 void VCLXAccessibleMenu::selectAllAccessibleChildren( ) throw (RuntimeException
)
203 // This method makes no sense in a menu, and so does nothing.
206 // -----------------------------------------------------------------------------
208 sal_Int32
VCLXAccessibleMenu::getSelectedAccessibleChildCount( ) throw (RuntimeException
)
210 OExternalLockGuard
aGuard( this );
214 for ( sal_Int32 i
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
216 if ( IsChildSelected( i
) )
223 // -----------------------------------------------------------------------------
225 Reference
< XAccessible
> VCLXAccessibleMenu::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
227 OExternalLockGuard
aGuard( this );
229 if ( nSelectedChildIndex
< 0 || nSelectedChildIndex
>= getSelectedAccessibleChildCount() )
230 throw IndexOutOfBoundsException();
232 Reference
< XAccessible
> xChild
;
234 for ( sal_Int32 i
= 0, j
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
236 if ( IsChildSelected( i
) && ( j
++ == nSelectedChildIndex
) )
238 xChild
= GetChild( i
);
246 // -----------------------------------------------------------------------------
248 void VCLXAccessibleMenu::deselectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
250 OExternalLockGuard
aGuard( this );
252 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
253 throw IndexOutOfBoundsException();
258 // -----------------------------------------------------------------------------