merged tag ooo/DEV300_m102
[LibreOffice.git] / accessibility / source / standard / accessiblemenucomponent.cxx
blob05ba722a9453782fa7b000c01be0df26ffc80932
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
30 #include <accessibility/standard/accessiblemenucomponent.hxx>
32 #include <toolkit/awt/vclxfont.hxx>
33 #include <toolkit/helper/convert.hxx>
35 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
36 #include <com/sun/star/accessibility/AccessibleRole.hpp>
37 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 #include <unotools/accessiblestatesethelper.hxx>
40 #include <unotools/accessiblerelationsethelper.hxx>
41 #include <cppuhelper/typeprovider.hxx>
42 #include <comphelper/sequence.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vcl/window.hxx>
45 #include <vcl/menu.hxx>
46 #include <vcl/unohelp2.hxx>
49 using namespace ::com::sun::star::accessibility;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::lang;
52 using namespace ::com::sun::star;
53 using namespace ::comphelper;
56 // -----------------------------------------------------------------------------
57 // class OAccessibleMenuComponent
58 // -----------------------------------------------------------------------------
60 OAccessibleMenuComponent::OAccessibleMenuComponent( Menu* pMenu )
61 :OAccessibleMenuBaseComponent( pMenu )
65 // -----------------------------------------------------------------------------
67 OAccessibleMenuComponent::~OAccessibleMenuComponent()
71 // -----------------------------------------------------------------------------
73 sal_Bool OAccessibleMenuComponent::IsEnabled()
75 return sal_True;
78 // -----------------------------------------------------------------------------
80 sal_Bool OAccessibleMenuComponent::IsVisible()
82 sal_Bool bVisible = sal_False;
84 if ( m_pMenu )
85 bVisible = m_pMenu->IsMenuVisible();
87 return bVisible;
90 // -----------------------------------------------------------------------------
92 void OAccessibleMenuComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
94 if ( IsEnabled() )
96 rStateSet.AddState( AccessibleStateType::ENABLED );
97 rStateSet.AddState( AccessibleStateType::SENSITIVE );
100 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
102 if ( IsFocused() )
103 rStateSet.AddState( AccessibleStateType::FOCUSED );
105 if ( IsVisible() )
107 rStateSet.AddState( AccessibleStateType::VISIBLE );
108 rStateSet.AddState( AccessibleStateType::SHOWING );
111 rStateSet.AddState( AccessibleStateType::OPAQUE );
114 // -----------------------------------------------------------------------------
115 // OCommonAccessibleComponent
116 // -----------------------------------------------------------------------------
118 awt::Rectangle OAccessibleMenuComponent::implGetBounds() throw (RuntimeException)
120 awt::Rectangle aBounds( 0, 0, 0, 0 );
122 if ( m_pMenu )
124 Window* pWindow = m_pMenu->GetWindow();
125 if ( pWindow )
127 // get bounding rectangle of the window in screen coordinates
128 Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
129 aBounds = AWTRectangle( aRect );
131 // get position of the accessible parent in screen coordinates
132 Reference< XAccessible > xParent = getAccessibleParent();
133 if ( xParent.is() )
135 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
136 if ( xParentComponent.is() )
138 awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
140 // calculate position of the window relative to the accessible parent
141 aBounds.X -= aParentScreenLoc.X;
142 aBounds.Y -= aParentScreenLoc.Y;
148 return aBounds;
151 // -----------------------------------------------------------------------------
152 // XInterface
153 // -----------------------------------------------------------------------------
155 IMPLEMENT_FORWARD_XINTERFACE2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE )
157 // -----------------------------------------------------------------------------
158 // XTypeProvider
159 // -----------------------------------------------------------------------------
161 IMPLEMENT_FORWARD_XTYPEPROVIDER2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE )
163 // -----------------------------------------------------------------------------
164 // XAccessibleContext
165 // -----------------------------------------------------------------------------
167 sal_Int32 OAccessibleMenuComponent::getAccessibleChildCount() throw (RuntimeException)
169 OExternalLockGuard aGuard( this );
171 return GetChildCount();
174 // -----------------------------------------------------------------------------
176 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
178 OExternalLockGuard aGuard( this );
180 if ( i < 0 || i >= GetChildCount() )
181 throw IndexOutOfBoundsException();
183 return GetChild( i );
186 // -----------------------------------------------------------------------------
188 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleParent( ) throw (RuntimeException)
190 OExternalLockGuard aGuard( this );
192 Reference< XAccessible > xParent;
194 if ( m_pMenu )
196 Window* pWindow = m_pMenu->GetWindow();
197 if ( pWindow )
199 Window* pParent = pWindow->GetAccessibleParentWindow();
200 if ( pParent )
201 xParent = pParent->GetAccessible();
205 return xParent;
208 // -----------------------------------------------------------------------------
210 sal_Int16 OAccessibleMenuComponent::getAccessibleRole( ) throw (RuntimeException)
212 OExternalLockGuard aGuard( this );
214 return AccessibleRole::UNKNOWN;
217 // -----------------------------------------------------------------------------
219 ::rtl::OUString OAccessibleMenuComponent::getAccessibleDescription( ) throw (RuntimeException)
221 OExternalLockGuard aGuard( this );
223 ::rtl::OUString sDescription;
224 if ( m_pMenu )
226 Window* pWindow = m_pMenu->GetWindow();
227 if ( pWindow )
228 sDescription = pWindow->GetAccessibleDescription();
231 return sDescription;
234 // -----------------------------------------------------------------------------
236 ::rtl::OUString OAccessibleMenuComponent::getAccessibleName( ) throw (RuntimeException)
238 OExternalLockGuard aGuard( this );
240 return ::rtl::OUString();
243 // -----------------------------------------------------------------------------
245 Reference< XAccessibleRelationSet > OAccessibleMenuComponent::getAccessibleRelationSet( ) throw (RuntimeException)
247 OExternalLockGuard aGuard( this );
249 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
250 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
251 return xSet;
254 // -----------------------------------------------------------------------------
256 Locale OAccessibleMenuComponent::getLocale( ) throw (IllegalAccessibleComponentStateException, RuntimeException)
258 OExternalLockGuard aGuard( this );
260 return Application::GetSettings().GetLocale();
263 // -----------------------------------------------------------------------------
264 // XAccessibleComponent
265 // -----------------------------------------------------------------------------
267 Reference< XAccessible > OAccessibleMenuComponent::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
269 OExternalLockGuard aGuard( this );
271 return GetChildAt( rPoint );
274 // -----------------------------------------------------------------------------
276 awt::Point OAccessibleMenuComponent::getLocationOnScreen( ) throw (RuntimeException)
278 OExternalLockGuard aGuard( this );
280 awt::Point aPos;
282 if ( m_pMenu )
284 Window* pWindow = m_pMenu->GetWindow();
285 if ( pWindow )
287 Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
288 aPos = AWTPoint( aRect.TopLeft() );
292 return aPos;
295 // -----------------------------------------------------------------------------
297 void OAccessibleMenuComponent::grabFocus( ) throw (RuntimeException)
299 OExternalLockGuard aGuard( this );
301 if ( m_pMenu )
303 Window* pWindow = m_pMenu->GetWindow();
304 if ( pWindow )
305 pWindow->GrabFocus();
309 // -----------------------------------------------------------------------------
311 sal_Int32 OAccessibleMenuComponent::getForeground( ) throw (RuntimeException)
313 OExternalLockGuard aGuard( this );
315 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
316 sal_Int32 nColor = rStyleSettings.GetMenuTextColor().GetColor();
318 return nColor;
321 // -----------------------------------------------------------------------------
323 sal_Int32 OAccessibleMenuComponent::getBackground( ) throw (RuntimeException)
325 OExternalLockGuard aGuard( this );
327 return 0;
330 // -----------------------------------------------------------------------------
331 // XAccessibleExtendedComponent
332 // -----------------------------------------------------------------------------
334 Reference< awt::XFont > OAccessibleMenuComponent::getFont( ) throw (RuntimeException)
336 OExternalLockGuard aGuard( this );
338 Reference< awt::XFont > xFont;
340 if ( m_pMenu )
342 Window* pWindow = m_pMenu->GetWindow();
343 if ( pWindow )
345 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
346 if ( xDev.is() )
348 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
349 VCLXFont* pVCLXFont = new VCLXFont;
350 pVCLXFont->Init( *xDev.get(), rStyleSettings.GetMenuFont() );
351 xFont = pVCLXFont;
356 return xFont;
359 // -----------------------------------------------------------------------------
361 ::rtl::OUString OAccessibleMenuComponent::getTitledBorderText( ) throw (RuntimeException)
363 OExternalLockGuard aGuard( this );
365 return ::rtl::OUString();
368 // -----------------------------------------------------------------------------
370 ::rtl::OUString OAccessibleMenuComponent::getToolTipText( ) throw (RuntimeException)
372 OExternalLockGuard aGuard( this );
374 return ::rtl::OUString();
377 // -----------------------------------------------------------------------------
378 // XAccessibleSelection
379 // -----------------------------------------------------------------------------
381 void OAccessibleMenuComponent::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
383 OExternalLockGuard aGuard( this );
385 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
386 throw IndexOutOfBoundsException();
388 SelectChild( nChildIndex );
391 // -----------------------------------------------------------------------------
393 sal_Bool OAccessibleMenuComponent::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
395 OExternalLockGuard aGuard( this );
397 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
398 throw IndexOutOfBoundsException();
400 return IsChildSelected( nChildIndex );
403 // -----------------------------------------------------------------------------
405 void OAccessibleMenuComponent::clearAccessibleSelection( ) throw (RuntimeException)
407 OExternalLockGuard aGuard( this );
409 DeSelectAll();
412 // -----------------------------------------------------------------------------
414 void OAccessibleMenuComponent::selectAllAccessibleChildren( ) throw (RuntimeException)
416 // This method makes no sense in a menu, and so does nothing.
419 // -----------------------------------------------------------------------------
421 sal_Int32 OAccessibleMenuComponent::getSelectedAccessibleChildCount( ) throw (RuntimeException)
423 OExternalLockGuard aGuard( this );
425 sal_Int32 nRet = 0;
427 for ( sal_Int32 i = 0, nCount = GetChildCount(); i < nCount; i++ )
429 if ( IsChildSelected( i ) )
430 ++nRet;
433 return nRet;
436 // -----------------------------------------------------------------------------
438 Reference< XAccessible > OAccessibleMenuComponent::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
440 OExternalLockGuard aGuard( this );
442 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
443 throw IndexOutOfBoundsException();
445 Reference< XAccessible > xChild;
447 for ( sal_Int32 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ )
449 if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
451 xChild = GetChild( i );
452 break;
456 return xChild;
459 // -----------------------------------------------------------------------------
461 void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
463 OExternalLockGuard aGuard( this );
465 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
466 throw IndexOutOfBoundsException();
468 DeSelectAll();
471 // -----------------------------------------------------------------------------