merge the formfield patch from ooo-build
[ooovba.git] / accessibility / source / standard / accessiblemenucomponent.cxx
blob5996237bc3eecc5c81a8e9b36d06f4ea99786a0c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accessiblemenucomponent.cxx,v $
10 * $Revision: 1.4 $
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"
33 #include <accessibility/standard/accessiblemenucomponent.hxx>
35 #include <toolkit/awt/vclxfont.hxx>
36 #include <toolkit/helper/convert.hxx>
38 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
39 #include <com/sun/star/accessibility/AccessibleRole.hpp>
40 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
42 #include <unotools/accessiblestatesethelper.hxx>
43 #include <unotools/accessiblerelationsethelper.hxx>
44 #include <cppuhelper/typeprovider.hxx>
45 #include <comphelper/sequence.hxx>
46 #include <vcl/svapp.hxx>
47 #include <vcl/window.hxx>
48 #include <vcl/menu.hxx>
49 #include <vcl/unohelp2.hxx>
52 using namespace ::com::sun::star::accessibility;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star;
56 using namespace ::comphelper;
59 // -----------------------------------------------------------------------------
60 // class OAccessibleMenuComponent
61 // -----------------------------------------------------------------------------
63 OAccessibleMenuComponent::OAccessibleMenuComponent( Menu* pMenu )
64 :OAccessibleMenuBaseComponent( pMenu )
68 // -----------------------------------------------------------------------------
70 OAccessibleMenuComponent::~OAccessibleMenuComponent()
74 // -----------------------------------------------------------------------------
76 sal_Bool OAccessibleMenuComponent::IsEnabled()
78 return sal_True;
81 // -----------------------------------------------------------------------------
83 sal_Bool OAccessibleMenuComponent::IsVisible()
85 sal_Bool bVisible = sal_False;
87 if ( m_pMenu )
88 bVisible = m_pMenu->IsMenuVisible();
90 return bVisible;
93 // -----------------------------------------------------------------------------
95 void OAccessibleMenuComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
97 if ( IsEnabled() )
99 rStateSet.AddState( AccessibleStateType::ENABLED );
100 rStateSet.AddState( AccessibleStateType::SENSITIVE );
103 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
105 if ( IsFocused() )
106 rStateSet.AddState( AccessibleStateType::FOCUSED );
108 if ( IsVisible() )
110 rStateSet.AddState( AccessibleStateType::VISIBLE );
111 rStateSet.AddState( AccessibleStateType::SHOWING );
114 rStateSet.AddState( AccessibleStateType::OPAQUE );
117 // -----------------------------------------------------------------------------
118 // OCommonAccessibleComponent
119 // -----------------------------------------------------------------------------
121 awt::Rectangle OAccessibleMenuComponent::implGetBounds() throw (RuntimeException)
123 awt::Rectangle aBounds( 0, 0, 0, 0 );
125 if ( m_pMenu )
127 Window* pWindow = m_pMenu->GetWindow();
128 if ( pWindow )
130 // get bounding rectangle of the window in screen coordinates
131 Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
132 aBounds = AWTRectangle( aRect );
134 // get position of the accessible parent in screen coordinates
135 Reference< XAccessible > xParent = getAccessibleParent();
136 if ( xParent.is() )
138 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
139 if ( xParentComponent.is() )
141 awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
143 // calculate position of the window relative to the accessible parent
144 aBounds.X -= aParentScreenLoc.X;
145 aBounds.Y -= aParentScreenLoc.Y;
151 return aBounds;
154 // -----------------------------------------------------------------------------
155 // XInterface
156 // -----------------------------------------------------------------------------
158 IMPLEMENT_FORWARD_XINTERFACE2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE )
160 // -----------------------------------------------------------------------------
161 // XTypeProvider
162 // -----------------------------------------------------------------------------
164 IMPLEMENT_FORWARD_XTYPEPROVIDER2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE )
166 // -----------------------------------------------------------------------------
167 // XAccessibleContext
168 // -----------------------------------------------------------------------------
170 sal_Int32 OAccessibleMenuComponent::getAccessibleChildCount() throw (RuntimeException)
172 OExternalLockGuard aGuard( this );
174 return GetChildCount();
177 // -----------------------------------------------------------------------------
179 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
181 OExternalLockGuard aGuard( this );
183 if ( i < 0 || i >= GetChildCount() )
184 throw IndexOutOfBoundsException();
186 return GetChild( i );
189 // -----------------------------------------------------------------------------
191 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleParent( ) throw (RuntimeException)
193 OExternalLockGuard aGuard( this );
195 Reference< XAccessible > xParent;
197 if ( m_pMenu )
199 Window* pWindow = m_pMenu->GetWindow();
200 if ( pWindow )
202 Window* pParent = pWindow->GetAccessibleParentWindow();
203 if ( pParent )
204 xParent = pParent->GetAccessible();
208 return xParent;
211 // -----------------------------------------------------------------------------
213 sal_Int16 OAccessibleMenuComponent::getAccessibleRole( ) throw (RuntimeException)
215 OExternalLockGuard aGuard( this );
217 return AccessibleRole::UNKNOWN;
220 // -----------------------------------------------------------------------------
222 ::rtl::OUString OAccessibleMenuComponent::getAccessibleDescription( ) throw (RuntimeException)
224 OExternalLockGuard aGuard( this );
226 ::rtl::OUString sDescription;
227 if ( m_pMenu )
229 Window* pWindow = m_pMenu->GetWindow();
230 if ( pWindow )
231 sDescription = pWindow->GetAccessibleDescription();
234 return sDescription;
237 // -----------------------------------------------------------------------------
239 ::rtl::OUString OAccessibleMenuComponent::getAccessibleName( ) throw (RuntimeException)
241 OExternalLockGuard aGuard( this );
243 return ::rtl::OUString();
246 // -----------------------------------------------------------------------------
248 Reference< XAccessibleRelationSet > OAccessibleMenuComponent::getAccessibleRelationSet( ) throw (RuntimeException)
250 OExternalLockGuard aGuard( this );
252 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
253 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
254 return xSet;
257 // -----------------------------------------------------------------------------
259 Locale OAccessibleMenuComponent::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
261 OExternalLockGuard aGuard( this );
263 return Application::GetSettings().GetLocale();
266 // -----------------------------------------------------------------------------
267 // XAccessibleComponent
268 // -----------------------------------------------------------------------------
270 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
272 OExternalLockGuard aGuard( this );
274 return GetChildAt( rPoint );
277 // -----------------------------------------------------------------------------
279 awt::Point OAccessibleMenuComponent::getLocationOnScreen( ) throw (RuntimeException)
281 OExternalLockGuard aGuard( this );
283 awt::Point aPos;
285 if ( m_pMenu )
287 Window* pWindow = m_pMenu->GetWindow();
288 if ( pWindow )
290 Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
291 aPos = AWTPoint( aRect.TopLeft() );
295 return aPos;
298 // -----------------------------------------------------------------------------
300 void OAccessibleMenuComponent::grabFocus( ) throw (RuntimeException)
302 OExternalLockGuard aGuard( this );
304 if ( m_pMenu )
306 Window* pWindow = m_pMenu->GetWindow();
307 if ( pWindow )
308 pWindow->GrabFocus();
312 // -----------------------------------------------------------------------------
314 sal_Int32 OAccessibleMenuComponent::getForeground( ) throw (RuntimeException)
316 OExternalLockGuard aGuard( this );
318 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
319 sal_Int32 nColor = rStyleSettings.GetMenuTextColor().GetColor();
321 return nColor;
324 // -----------------------------------------------------------------------------
326 sal_Int32 OAccessibleMenuComponent::getBackground( ) throw (RuntimeException)
328 OExternalLockGuard aGuard( this );
330 return 0;
333 // -----------------------------------------------------------------------------
334 // XAccessibleExtendedComponent
335 // -----------------------------------------------------------------------------
337 Reference< awt::XFont > OAccessibleMenuComponent::getFont( ) throw (RuntimeException)
339 OExternalLockGuard aGuard( this );
341 Reference< awt::XFont > xFont;
343 if ( m_pMenu )
345 Window* pWindow = m_pMenu->GetWindow();
346 if ( pWindow )
348 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
349 if ( xDev.is() )
351 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
352 VCLXFont* pVCLXFont = new VCLXFont;
353 pVCLXFont->Init( *xDev.get(), rStyleSettings.GetMenuFont() );
354 xFont = pVCLXFont;
359 return xFont;
362 // -----------------------------------------------------------------------------
364 ::rtl::OUString OAccessibleMenuComponent::getTitledBorderText( ) throw (RuntimeException)
366 OExternalLockGuard aGuard( this );
368 return ::rtl::OUString();
371 // -----------------------------------------------------------------------------
373 ::rtl::OUString OAccessibleMenuComponent::getToolTipText( ) throw (RuntimeException)
375 OExternalLockGuard aGuard( this );
377 return ::rtl::OUString();
380 // -----------------------------------------------------------------------------
381 // XAccessibleSelection
382 // -----------------------------------------------------------------------------
384 void OAccessibleMenuComponent::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
386 OExternalLockGuard aGuard( this );
388 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
389 throw IndexOutOfBoundsException();
391 SelectChild( nChildIndex );
394 // -----------------------------------------------------------------------------
396 sal_Bool OAccessibleMenuComponent::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
398 OExternalLockGuard aGuard( this );
400 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
401 throw IndexOutOfBoundsException();
403 return IsChildSelected( nChildIndex );
406 // -----------------------------------------------------------------------------
408 void OAccessibleMenuComponent::clearAccessibleSelection( ) throw (RuntimeException)
410 OExternalLockGuard aGuard( this );
412 DeSelectAll();
415 // -----------------------------------------------------------------------------
417 void OAccessibleMenuComponent::selectAllAccessibleChildren( ) throw (RuntimeException)
419 // This method makes no sense in a menu, and so does nothing.
422 // -----------------------------------------------------------------------------
424 sal_Int32 OAccessibleMenuComponent::getSelectedAccessibleChildCount( ) throw (RuntimeException)
426 OExternalLockGuard aGuard( this );
428 sal_Int32 nRet = 0;
430 for ( sal_Int32 i = 0, nCount = GetChildCount(); i < nCount; i++ )
432 if ( IsChildSelected( i ) )
433 ++nRet;
436 return nRet;
439 // -----------------------------------------------------------------------------
441 Reference< XAccessible > OAccessibleMenuComponent::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
443 OExternalLockGuard aGuard( this );
445 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
446 throw IndexOutOfBoundsException();
448 Reference< XAccessible > xChild;
450 for ( sal_Int32 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ )
452 if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
454 xChild = GetChild( i );
455 break;
459 return xChild;
462 // -----------------------------------------------------------------------------
464 void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
466 OExternalLockGuard aGuard( this );
468 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
469 throw IndexOutOfBoundsException();
471 DeSelectAll();
474 // -----------------------------------------------------------------------------