xref: /trunk/main/accessibility/source/standard/vclxaccessiblemenu.cxx (revision 154667709de12a9d1edbfc113ef193f0e43b3b3b)
10841af79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
30841af79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
40841af79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
50841af79SAndrew Rist  * distributed with this work for additional information
60841af79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
70841af79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
80841af79SAndrew Rist  * "License"); you may not use this file except in compliance
90841af79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
110841af79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
130841af79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
140841af79SAndrew Rist  * software distributed under the License is distributed on an
150841af79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160841af79SAndrew Rist  * KIND, either express or implied.  See the License for the
170841af79SAndrew Rist  * specific language governing permissions and limitations
180841af79SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
200841af79SAndrew Rist  *************************************************************/
210841af79SAndrew Rist 
220841af79SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // includes --------------------------------------------------------------
28cdf0e10cSrcweir #include <accessibility/standard/vclxaccessiblemenu.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
31cdf0e10cSrcweir #include <vcl/menu.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::com::sun::star;
35cdf0e10cSrcweir using namespace ::com::sun::star::lang;
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
38cdf0e10cSrcweir using namespace ::comphelper;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // -----------------------------------------------------------------------------
42cdf0e10cSrcweir // VCLXAccessibleMenu
43cdf0e10cSrcweir // -----------------------------------------------------------------------------
44cdf0e10cSrcweir 
VCLXAccessibleMenu(Menu * pParent,sal_uInt16 nItemPos,Menu * pMenu)45cdf0e10cSrcweir VCLXAccessibleMenu::VCLXAccessibleMenu( Menu* pParent, sal_uInt16 nItemPos, Menu* pMenu )
46cdf0e10cSrcweir     :VCLXAccessibleMenuItem( pParent, nItemPos, pMenu )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
50cdf0e10cSrcweir // -----------------------------------------------------------------------------
51cdf0e10cSrcweir 
~VCLXAccessibleMenu()52cdf0e10cSrcweir VCLXAccessibleMenu::~VCLXAccessibleMenu()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // -----------------------------------------------------------------------------
57cdf0e10cSrcweir 
IsFocused()58cdf0e10cSrcweir sal_Bool VCLXAccessibleMenu::IsFocused()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     sal_Bool bFocused = sal_False;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     if ( IsHighlighted() && !IsChildHighlighted() )
63cdf0e10cSrcweir         bFocused = sal_True;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     return bFocused;
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir // -----------------------------------------------------------------------------
69cdf0e10cSrcweir 
IsPopupMenuOpen()70cdf0e10cSrcweir sal_Bool VCLXAccessibleMenu::IsPopupMenuOpen()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     sal_Bool bPopupMenuOpen = sal_False;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     if ( m_pParent )
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         PopupMenu* pPopupMenu = m_pParent->GetPopupMenu( m_pParent->GetItemId( m_nItemPos ) );
77cdf0e10cSrcweir         if ( pPopupMenu && pPopupMenu->IsMenuVisible() )
78cdf0e10cSrcweir             bPopupMenuOpen = sal_True;
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     return bPopupMenuOpen;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir // -----------------------------------------------------------------------------
85cdf0e10cSrcweir // XInterface
86cdf0e10cSrcweir // -----------------------------------------------------------------------------
87cdf0e10cSrcweir 
IMPLEMENT_FORWARD_XINTERFACE2(VCLXAccessibleMenu,VCLXAccessibleMenuItem,VCLXAccessibleMenu_BASE)88cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleMenu, VCLXAccessibleMenuItem, VCLXAccessibleMenu_BASE )
89cdf0e10cSrcweir 
90cdf0e10cSrcweir // -----------------------------------------------------------------------------
91cdf0e10cSrcweir // XTypeProvider
92cdf0e10cSrcweir // -----------------------------------------------------------------------------
93cdf0e10cSrcweir 
94cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleMenu, VCLXAccessibleMenuItem, VCLXAccessibleMenu_BASE )
95cdf0e10cSrcweir 
96cdf0e10cSrcweir // -----------------------------------------------------------------------------
97cdf0e10cSrcweir // XServiceInfo
98cdf0e10cSrcweir // -----------------------------------------------------------------------------
99cdf0e10cSrcweir 
100cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenu::getImplementationName() throw (RuntimeException)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleMenu" );
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir // -----------------------------------------------------------------------------
106cdf0e10cSrcweir 
getSupportedServiceNames()107cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleMenu::getSupportedServiceNames() throw (RuntimeException)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     Sequence< ::rtl::OUString > aNames(1);
110cdf0e10cSrcweir     aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleMenu" );
111cdf0e10cSrcweir     return aNames;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir // -----------------------------------------------------------------------------
115cdf0e10cSrcweir // XAccessibleContext
116cdf0e10cSrcweir // -----------------------------------------------------------------------------
117cdf0e10cSrcweir 
getAccessibleChildCount()118cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenu::getAccessibleChildCount(  ) throw (RuntimeException)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     return GetChildCount();
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir // -----------------------------------------------------------------------------
126cdf0e10cSrcweir 
getAccessibleChild(sal_Int32 i)127cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleMenu::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     if ( i < 0 || i >= GetChildCount() )
132cdf0e10cSrcweir         throw IndexOutOfBoundsException();
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     return GetChild( i );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir // -----------------------------------------------------------------------------
138cdf0e10cSrcweir 
getAccessibleRole()139cdf0e10cSrcweir sal_Int16 VCLXAccessibleMenu::getAccessibleRole(  ) throw (RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     return AccessibleRole::MENU;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir // -----------------------------------------------------------------------------
147cdf0e10cSrcweir // XAccessibleComponent
148cdf0e10cSrcweir // -----------------------------------------------------------------------------
149cdf0e10cSrcweir 
getAccessibleAtPoint(const awt::Point & rPoint)150cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleMenu::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     return GetChildAt( rPoint );
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir // -----------------------------------------------------------------------------
158cdf0e10cSrcweir // XAccessibleSelection
159cdf0e10cSrcweir // -----------------------------------------------------------------------------
160cdf0e10cSrcweir 
selectAccessibleChild(sal_Int32 nChildIndex)161cdf0e10cSrcweir void VCLXAccessibleMenu::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
166cdf0e10cSrcweir         throw IndexOutOfBoundsException();
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     SelectChild( nChildIndex );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir // -----------------------------------------------------------------------------
172cdf0e10cSrcweir 
isAccessibleChildSelected(sal_Int32 nChildIndex)173cdf0e10cSrcweir sal_Bool VCLXAccessibleMenu::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
178cdf0e10cSrcweir         throw IndexOutOfBoundsException();
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     return IsChildSelected( nChildIndex );
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir // -----------------------------------------------------------------------------
184cdf0e10cSrcweir 
clearAccessibleSelection()185cdf0e10cSrcweir void VCLXAccessibleMenu::clearAccessibleSelection(  ) throw (RuntimeException)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     DeSelectAll();
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir // -----------------------------------------------------------------------------
193cdf0e10cSrcweir 
selectAllAccessibleChildren()194cdf0e10cSrcweir void VCLXAccessibleMenu::selectAllAccessibleChildren(  ) throw (RuntimeException)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     // This method makes no sense in a menu, and so does nothing.
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir // -----------------------------------------------------------------------------
200cdf0e10cSrcweir 
getSelectedAccessibleChildCount()201cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenu::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     sal_Int32 nRet = 0;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     for ( sal_Int32 i = 0, nCount = GetChildCount(); i < nCount; i++ )
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         if ( IsChildSelected( i ) )
210cdf0e10cSrcweir             ++nRet;
211cdf0e10cSrcweir     }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     return nRet;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir // -----------------------------------------------------------------------------
217cdf0e10cSrcweir 
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)218cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleMenu::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
223cdf0e10cSrcweir         throw IndexOutOfBoundsException();
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     Reference< XAccessible > xChild;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     for ( sal_Int32 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ )
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir         if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             xChild = GetChild( i );
232cdf0e10cSrcweir             break;
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     return xChild;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
239cdf0e10cSrcweir // -----------------------------------------------------------------------------
240cdf0e10cSrcweir 
deselectAccessibleChild(sal_Int32 nChildIndex)241cdf0e10cSrcweir void VCLXAccessibleMenu::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
246cdf0e10cSrcweir         throw IndexOutOfBoundsException();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     DeSelectAll();
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir // -----------------------------------------------------------------------------
252*21075d77SSteve Yin 
getAccessibleActionDescription(sal_Int32 nIndex)253*21075d77SSteve Yin ::rtl::OUString VCLXAccessibleMenu::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
254*21075d77SSteve Yin {
255*21075d77SSteve Yin     OExternalLockGuard aGuard( this );
256*21075d77SSteve Yin 
257*21075d77SSteve Yin     if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
258*21075d77SSteve Yin         throw IndexOutOfBoundsException();
259*21075d77SSteve Yin 
260*21075d77SSteve Yin     return ::rtl::OUString(  );
261*21075d77SSteve Yin }
262