Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblemenubar.cxx
blob3313f93bf616fe27c84999435498093ad15e96e4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <accessibility/standard/vclxaccessiblemenubar.hxx>
22 #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 #include <vcl/svapp.hxx>
24 #include <vcl/window.hxx>
25 #include <vcl/menu.hxx>
26 #include <vcl/settings.hxx>
28 using namespace ::com::sun::star::accessibility;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star;
31 using namespace ::comphelper;
35 // class VCLXAccessibleMenuBar
38 VCLXAccessibleMenuBar::VCLXAccessibleMenuBar( Menu* pMenu )
39 :OAccessibleMenuComponent( pMenu )
41 if ( pMenu )
43 m_pWindow = pMenu->GetWindow();
45 if ( m_pWindow )
46 m_pWindow->AddEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
48 else
50 m_pWindow = 0;
56 VCLXAccessibleMenuBar::~VCLXAccessibleMenuBar()
58 if ( m_pWindow )
59 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
64 bool VCLXAccessibleMenuBar::IsFocused()
66 bool bFocused = false;
68 if ( m_pWindow && m_pWindow->HasFocus() && !IsChildHighlighted() )
69 bFocused = true;
71 return bFocused;
76 IMPL_LINK( VCLXAccessibleMenuBar, WindowEventListener, VclSimpleEvent*, pEvent )
78 OSL_ENSURE( pEvent && pEvent->ISA( VclWindowEvent ), "VCLXAccessibleMenuBar::WindowEventListener: unknown window event!" );
79 if ( pEvent && pEvent->ISA( VclWindowEvent ) )
81 OSL_ENSURE( static_cast<VclWindowEvent*>(pEvent)->GetWindow(), "VCLXAccessibleMenuBar::WindowEventListener: no window!" );
82 if ( !static_cast<VclWindowEvent*>(pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent->GetId() == VCLEVENT_OBJECT_DYING ) )
84 ProcessWindowEvent( *static_cast<VclWindowEvent*>(pEvent) );
87 return 0;
92 void VCLXAccessibleMenuBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
94 switch ( rVclWindowEvent.GetId() )
96 case VCLEVENT_WINDOW_GETFOCUS:
97 case VCLEVENT_WINDOW_LOSEFOCUS:
99 SetFocused( rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS );
101 break;
102 case VCLEVENT_OBJECT_DYING:
104 if ( m_pWindow )
106 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
107 m_pWindow = NULL;
110 break;
111 default:
114 break;
119 // XComponent
122 void VCLXAccessibleMenuBar::disposing()
124 OAccessibleMenuComponent::disposing();
126 if ( m_pWindow )
128 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
129 m_pWindow = NULL;
134 // XServiceInfo
137 OUString VCLXAccessibleMenuBar::getImplementationName() throw (RuntimeException, std::exception)
139 return OUString( "com.sun.star.comp.toolkit.AccessibleMenuBar" );
144 Sequence< OUString > VCLXAccessibleMenuBar::getSupportedServiceNames() throw (RuntimeException, std::exception)
146 Sequence< OUString > aNames(1);
147 aNames[0] = "com.sun.star.awt.AccessibleMenuBar";
148 return aNames;
152 // XAccessibleContext
155 sal_Int32 VCLXAccessibleMenuBar::getAccessibleIndexInParent( ) throw (RuntimeException, std::exception)
157 OExternalLockGuard aGuard( this );
159 sal_Int32 nIndexInParent = -1;
161 if ( m_pMenu )
163 vcl::Window* pWindow = m_pMenu->GetWindow();
164 if ( pWindow )
166 vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
167 if ( pParent )
169 for ( sal_uInt16 n = pParent->GetAccessibleChildWindowCount(); n; )
171 vcl::Window* pChild = pParent->GetAccessibleChildWindow( --n );
172 if ( pChild == pWindow )
174 nIndexInParent = n;
175 break;
182 return nIndexInParent;
187 sal_Int16 VCLXAccessibleMenuBar::getAccessibleRole( ) throw (RuntimeException, std::exception)
189 OExternalLockGuard aGuard( this );
191 return AccessibleRole::MENU_BAR;
195 // XAccessibleExtendedComponent
198 sal_Int32 VCLXAccessibleMenuBar::getBackground( ) throw (RuntimeException, std::exception)
200 OExternalLockGuard aGuard( this );
202 return Application::GetSettings().GetStyleSettings().GetMenuBarColor().GetColor();
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */