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: vclxaccessiblemenubar.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/vclxaccessiblemenubar.hxx>
35 #include <com/sun/star/accessibility/AccessibleRole.hpp>
36 #include <vcl/svapp.hxx>
37 #include <vcl/window.hxx>
38 #include <vcl/menu.hxx>
41 using namespace ::com::sun::star::accessibility
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star
;
44 using namespace ::comphelper
;
47 // -----------------------------------------------------------------------------
48 // class VCLXAccessibleMenuBar
49 // -----------------------------------------------------------------------------
51 VCLXAccessibleMenuBar::VCLXAccessibleMenuBar( Menu
* pMenu
)
52 :OAccessibleMenuComponent( pMenu
)
56 m_pWindow
= pMenu
->GetWindow();
59 m_pWindow
->AddEventListener( LINK( this, VCLXAccessibleMenuBar
, WindowEventListener
) );
63 // -----------------------------------------------------------------------------
65 VCLXAccessibleMenuBar::~VCLXAccessibleMenuBar()
68 m_pWindow
->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar
, WindowEventListener
) );
71 // -----------------------------------------------------------------------------
73 sal_Bool
VCLXAccessibleMenuBar::IsFocused()
75 sal_Bool bFocused
= sal_False
;
77 if ( m_pWindow
&& m_pWindow
->HasFocus() && !IsChildHighlighted() )
83 // -----------------------------------------------------------------------------
85 IMPL_LINK( VCLXAccessibleMenuBar
, WindowEventListener
, VclSimpleEvent
*, pEvent
)
87 DBG_ASSERT( pEvent
&& pEvent
->ISA( VclWindowEvent
), "VCLXAccessibleMenuBar::WindowEventListener: unknown window event!" );
88 if ( pEvent
&& pEvent
->ISA( VclWindowEvent
) )
90 DBG_ASSERT( ((VclWindowEvent
*)pEvent
)->GetWindow(), "VCLXAccessibleMenuBar::WindowEventListener: no window!" );
91 if ( !((VclWindowEvent
*)pEvent
)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent
->GetId() == VCLEVENT_OBJECT_DYING
) )
93 ProcessWindowEvent( *(VclWindowEvent
*)pEvent
);
99 // -----------------------------------------------------------------------------
101 void VCLXAccessibleMenuBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
103 switch ( rVclWindowEvent
.GetId() )
105 case VCLEVENT_WINDOW_GETFOCUS
:
106 case VCLEVENT_WINDOW_LOSEFOCUS
:
108 SetFocused( rVclWindowEvent
.GetId() == VCLEVENT_WINDOW_GETFOCUS
);
111 case VCLEVENT_OBJECT_DYING
:
115 m_pWindow
->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar
, WindowEventListener
) );
127 // -----------------------------------------------------------------------------
129 // -----------------------------------------------------------------------------
131 void VCLXAccessibleMenuBar::disposing()
133 OAccessibleMenuComponent::disposing();
137 m_pWindow
->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar
, WindowEventListener
) );
142 // -----------------------------------------------------------------------------
144 // -----------------------------------------------------------------------------
146 ::rtl::OUString
VCLXAccessibleMenuBar::getImplementationName() throw (RuntimeException
)
148 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleMenuBar" );
151 // -----------------------------------------------------------------------------
153 Sequence
< ::rtl::OUString
> VCLXAccessibleMenuBar::getSupportedServiceNames() throw (RuntimeException
)
155 Sequence
< ::rtl::OUString
> aNames(1);
156 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleMenuBar" );
160 // -----------------------------------------------------------------------------
161 // XAccessibleContext
162 // -----------------------------------------------------------------------------
164 sal_Int32
VCLXAccessibleMenuBar::getAccessibleIndexInParent( ) throw (RuntimeException
)
166 OExternalLockGuard
aGuard( this );
168 sal_Int32 nIndexInParent
= -1;
172 Window
* pWindow
= m_pMenu
->GetWindow();
175 Window
* pParent
= pWindow
->GetAccessibleParentWindow();
178 for ( USHORT n
= pParent
->GetAccessibleChildWindowCount(); n
; )
180 Window
* pChild
= pParent
->GetAccessibleChildWindow( --n
);
181 if ( pChild
== pWindow
)
191 return nIndexInParent
;
194 // -----------------------------------------------------------------------------
196 sal_Int16
VCLXAccessibleMenuBar::getAccessibleRole( ) throw (RuntimeException
)
198 OExternalLockGuard
aGuard( this );
200 return AccessibleRole::MENU_BAR
;
203 // -----------------------------------------------------------------------------
204 // XAccessibleExtendedComponent
205 // -----------------------------------------------------------------------------
207 sal_Int32
VCLXAccessibleMenuBar::getBackground( ) throw (RuntimeException
)
209 OExternalLockGuard
aGuard( this );
211 return Application::GetSettings().GetStyleSettings().GetMenuBarColor().GetColor();
214 // -----------------------------------------------------------------------------