1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <standard/vclxaccessiblemenubar.hxx>
22 #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 #include <comphelper/accessiblecontexthelper.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/window.hxx>
26 #include <vcl/menu.hxx>
27 #include <vcl/settings.hxx>
29 using namespace ::com::sun::star::accessibility
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star
;
32 using namespace ::comphelper
;
37 VCLXAccessibleMenuBar::VCLXAccessibleMenuBar( Menu
* pMenu
)
38 :OAccessibleMenuComponent( pMenu
)
42 m_pWindow
= pMenu
->GetWindow();
45 m_pWindow
->AddEventListener( LINK( this, VCLXAccessibleMenuBar
, WindowEventListener
) );
50 VCLXAccessibleMenuBar::~VCLXAccessibleMenuBar()
53 m_pWindow
->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar
, WindowEventListener
) );
57 bool VCLXAccessibleMenuBar::IsFocused()
59 bool bFocused
= false;
61 if ( m_pWindow
&& m_pWindow
->HasFocus() && !IsChildHighlighted() )
68 IMPL_LINK( VCLXAccessibleMenuBar
, WindowEventListener
, VclWindowEvent
&, rEvent
, void )
70 assert( rEvent
.GetWindow() );
71 if ( !rEvent
.GetWindow()->IsAccessibilityEventsSuppressed() || ( rEvent
.GetId() == VclEventId::ObjectDying
) )
73 ProcessWindowEvent( rEvent
);
78 void VCLXAccessibleMenuBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
80 switch ( rVclWindowEvent
.GetId() )
82 case VclEventId::WindowGetFocus
:
83 case VclEventId::WindowLoseFocus
:
85 SetFocused( rVclWindowEvent
.GetId() == VclEventId::WindowGetFocus
);
88 case VclEventId::ObjectDying
:
92 m_pWindow
->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar
, WindowEventListener
) );
108 void VCLXAccessibleMenuBar::disposing()
110 OAccessibleMenuComponent::disposing();
114 m_pWindow
->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar
, WindowEventListener
) );
123 OUString
VCLXAccessibleMenuBar::getImplementationName()
125 return "com.sun.star.comp.toolkit.AccessibleMenuBar";
129 Sequence
< OUString
> VCLXAccessibleMenuBar::getSupportedServiceNames()
131 return { "com.sun.star.awt.AccessibleMenuBar" };
135 // XAccessibleContext
138 sal_Int64
VCLXAccessibleMenuBar::getAccessibleIndexInParent( )
140 OExternalLockGuard
aGuard( this );
142 sal_Int64 nIndexInParent
= -1;
146 vcl::Window
* pWindow
= m_pMenu
->GetWindow();
149 vcl::Window
* pParent
= pWindow
->GetAccessibleParentWindow();
152 for ( sal_uInt16 n
= pParent
->GetAccessibleChildWindowCount(); n
; )
154 vcl::Window
* pChild
= pParent
->GetAccessibleChildWindow( --n
);
155 if ( pChild
== pWindow
)
165 return nIndexInParent
;
169 sal_Int16
VCLXAccessibleMenuBar::getAccessibleRole( )
171 OExternalLockGuard
aGuard( this );
173 return AccessibleRole::MENU_BAR
;
177 // XAccessibleExtendedComponent
180 sal_Int32
VCLXAccessibleMenuBar::getBackground( )
182 OExternalLockGuard
aGuard( this );
184 return sal_Int32(Application::GetSettings().GetStyleSettings().GetMenuBarColor());
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */