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: accessiblemenucomponent.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"
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()
81 // -----------------------------------------------------------------------------
83 sal_Bool
OAccessibleMenuComponent::IsVisible()
85 sal_Bool bVisible
= sal_False
;
88 bVisible
= m_pMenu
->IsMenuVisible();
93 // -----------------------------------------------------------------------------
95 void OAccessibleMenuComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper
& rStateSet
)
99 rStateSet
.AddState( AccessibleStateType::ENABLED
);
100 rStateSet
.AddState( AccessibleStateType::SENSITIVE
);
103 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
106 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
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 );
127 Window
* pWindow
= m_pMenu
->GetWindow();
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();
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
;
154 // -----------------------------------------------------------------------------
156 // -----------------------------------------------------------------------------
158 IMPLEMENT_FORWARD_XINTERFACE2( OAccessibleMenuComponent
, OAccessibleMenuBaseComponent
, OAccessibleMenuComponent_BASE
)
160 // -----------------------------------------------------------------------------
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
;
199 Window
* pWindow
= m_pMenu
->GetWindow();
202 Window
* pParent
= pWindow
->GetAccessibleParentWindow();
204 xParent
= pParent
->GetAccessible();
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
;
229 Window
* pWindow
= m_pMenu
->GetWindow();
231 sDescription
= pWindow
->GetAccessibleDescription();
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
;
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 );
287 Window
* pWindow
= m_pMenu
->GetWindow();
290 Rectangle aRect
= pWindow
->GetWindowExtentsRelative( NULL
);
291 aPos
= AWTPoint( aRect
.TopLeft() );
298 // -----------------------------------------------------------------------------
300 void OAccessibleMenuComponent::grabFocus( ) throw (RuntimeException
)
302 OExternalLockGuard
aGuard( this );
306 Window
* pWindow
= m_pMenu
->GetWindow();
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();
324 // -----------------------------------------------------------------------------
326 sal_Int32
OAccessibleMenuComponent::getBackground( ) throw (RuntimeException
)
328 OExternalLockGuard
aGuard( this );
333 // -----------------------------------------------------------------------------
334 // XAccessibleExtendedComponent
335 // -----------------------------------------------------------------------------
337 Reference
< awt::XFont
> OAccessibleMenuComponent::getFont( ) throw (RuntimeException
)
339 OExternalLockGuard
aGuard( this );
341 Reference
< awt::XFont
> xFont
;
345 Window
* pWindow
= m_pMenu
->GetWindow();
348 Reference
< awt::XDevice
> xDev( pWindow
->GetComponentInterface(), UNO_QUERY
);
351 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
352 VCLXFont
* pVCLXFont
= new VCLXFont
;
353 pVCLXFont
->Init( *xDev
.get(), rStyleSettings
.GetMenuFont() );
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 );
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 );
430 for ( sal_Int32 i
= 0, nCount
= GetChildCount(); i
< nCount
; i
++ )
432 if ( IsChildSelected( i
) )
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
);
462 // -----------------------------------------------------------------------------
464 void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
466 OExternalLockGuard
aGuard( this );
468 if ( nChildIndex
< 0 || nChildIndex
>= GetChildCount() )
469 throw IndexOutOfBoundsException();
474 // -----------------------------------------------------------------------------