Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblemenubar.cxx
blobc54f376fe0567a909cd38fbd2a297949844de4d8
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 <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 )
40 if ( pMenu )
42 m_pWindow = pMenu->GetWindow();
44 if ( m_pWindow )
45 m_pWindow->AddEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
50 VCLXAccessibleMenuBar::~VCLXAccessibleMenuBar()
52 if ( m_pWindow )
53 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
57 bool VCLXAccessibleMenuBar::IsFocused()
59 bool bFocused = false;
61 if ( m_pWindow && m_pWindow->HasFocus() && !IsChildHighlighted() )
62 bFocused = true;
64 return bFocused;
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 );
87 break;
88 case VclEventId::ObjectDying:
90 if ( m_pWindow )
92 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
93 m_pWindow = nullptr;
96 break;
97 default:
100 break;
105 // XComponent
108 void VCLXAccessibleMenuBar::disposing()
110 OAccessibleMenuComponent::disposing();
112 if ( m_pWindow )
114 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
115 m_pWindow = nullptr;
120 // XServiceInfo
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;
144 if ( m_pMenu )
146 vcl::Window* pWindow = m_pMenu->GetWindow();
147 if ( pWindow )
149 vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
150 if ( pParent )
152 for ( sal_uInt16 n = pParent->GetAccessibleChildWindowCount(); n; )
154 vcl::Window* pChild = pParent->GetAccessibleChildWindow( --n );
155 if ( pChild == pWindow )
157 nIndexInParent = n;
158 break;
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: */