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()
78 // -----------------------------------------------------------------------------
80 sal_Bool
OAccessibleMenuComponent::IsVisible()
82 sal_Bool bVisible
= sal_False
;
85 bVisible
= m_pMenu
->IsMenuVisible();
90 // -----------------------------------------------------------------------------
92 void OAccessibleMenuComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
96 rStateSet
.AddState( AccessibleStateType::ENABLED
);
97 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
100 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
103 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
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 );
124 Window
* pWindow
= m_pMenu
->GetWindow();
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();
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
;
151 // -----------------------------------------------------------------------------
153 // -----------------------------------------------------------------------------
155 IMPLEMENT_FORWARD_XINTERFACE2( OAccessibleMenuComponent
, OAccessibleMenuBaseComponent
, OAccessibleMenuComponent_BASE
)
157 // -----------------------------------------------------------------------------
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
;
196 Window
* pWindow
= m_pMenu
->GetWindow();
199 Window
* pParent
= pWindow
->GetAccessibleParentWindow();
201 xParent
= pParent
->GetAccessible();
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
;
226 Window
* pWindow
= m_pMenu
->GetWindow();
228 sDescription
= pWindow
->GetAccessibleDescription();
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
;
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 );
284 Window
* pWindow
= m_pMenu
->GetWindow();
287 Rectangle aRect
= pWindow
->GetWindowExtentsRelative( NULL
);
288 aPos
= AWTPoint( aRect
.TopLeft() );
295 // -----------------------------------------------------------------------------
297 void OAccessibleMenuComponent::grabFocus( ) throw (RuntimeException
)
299 OExternalLockGuard
aGuard( this );
303 Window
* pWindow
= m_pMenu
->GetWindow();
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();
321 // -----------------------------------------------------------------------------
323 sal_Int32
OAccessibleMenuComponent::getBackground( ) throw (RuntimeException
)
325 OExternalLockGuard
aGuard( this );
330 // -----------------------------------------------------------------------------
331 // XAccessibleExtendedComponent
332 // -----------------------------------------------------------------------------
334 Reference
< awt::XFont
> OAccessibleMenuComponent::getFont( ) throw (RuntimeException
)
336 OExternalLockGuard
aGuard( this );
338 Reference
< awt::XFont
> xFont
;
342 Window
* pWindow
= m_pMenu
->GetWindow();
345 Reference
< awt::XDevice
> xDev( pWindow
->GetComponentInterface(), UNO_QUERY
);
348 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
349 VCLXFont
* pVCLXFont
= new VCLXFont
;
350 pVCLXFont
->Init( *xDev
.get(), rStyleSettings
.GetMenuFont() );
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 );
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 );
427 for ( sal_Int32 i
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
429 if ( IsChildSelected( i
) )
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
);
459 // -----------------------------------------------------------------------------
461 void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
463 OExternalLockGuard
aGuard( this );
465 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
466 throw IndexOutOfBoundsException();
471 // -----------------------------------------------------------------------------