Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/accessibility/vclxaccessiblemenubar.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#include <accessibility/vclxaccessiblemenubar.hxx>
21
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>
28
29
using namespace ::com::sun::star::accessibility;
30
using namespace ::com::sun::star::uno;
31
using namespace ::com::sun::star;
32
using namespace ::comphelper;
33
34
35
36
37
VCLXAccessibleMenuBar::VCLXAccessibleMenuBar( Menu* pMenu )
38
0
    :OAccessibleMenuComponent( pMenu )
39
0
{
40
0
    if ( pMenu )
41
0
    {
42
0
        m_pWindow = pMenu->GetWindow();
43
44
0
        if ( m_pWindow )
45
0
            m_pWindow->AddEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
46
0
    }
47
0
}
48
49
50
VCLXAccessibleMenuBar::~VCLXAccessibleMenuBar()
51
0
{
52
0
    if ( m_pWindow )
53
0
        m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
54
0
}
55
56
57
bool VCLXAccessibleMenuBar::IsFocused()
58
0
{
59
0
    bool bFocused = false;
60
61
0
    if ( m_pWindow && m_pWindow->HasFocus() && !IsChildHighlighted() )
62
0
        bFocused = true;
63
64
0
    return bFocused;
65
0
}
66
67
68
IMPL_LINK( VCLXAccessibleMenuBar, WindowEventListener, VclWindowEvent&, rEvent, void )
69
0
{
70
0
    assert( rEvent.GetWindow() );
71
0
    if ( !rEvent.GetWindow()->IsAccessibilityEventsSuppressed() || ( rEvent.GetId() == VclEventId::ObjectDying ) )
72
0
    {
73
0
        ProcessWindowEvent( rEvent );
74
0
    }
75
0
}
76
77
78
void VCLXAccessibleMenuBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
79
0
{
80
0
    switch ( rVclWindowEvent.GetId() )
81
0
    {
82
0
        case VclEventId::WindowGetFocus:
83
0
        case VclEventId::WindowLoseFocus:
84
0
        {
85
0
            SetFocused( rVclWindowEvent.GetId() == VclEventId::WindowGetFocus );
86
0
        }
87
0
        break;
88
0
        case VclEventId::ObjectDying:
89
0
        {
90
0
            if ( m_pWindow )
91
0
            {
92
0
                m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
93
0
                m_pWindow = nullptr;
94
0
            }
95
0
        }
96
0
        break;
97
0
        default:
98
0
        {
99
0
        }
100
0
        break;
101
0
    }
102
0
}
103
104
105
// XComponent
106
107
108
void VCLXAccessibleMenuBar::disposing()
109
0
{
110
0
    OAccessibleMenuComponent::disposing();
111
112
0
    if ( m_pWindow )
113
0
    {
114
0
        m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
115
0
        m_pWindow = nullptr;
116
0
    }
117
0
}
118
119
120
// XServiceInfo
121
122
123
OUString VCLXAccessibleMenuBar::getImplementationName()
124
0
{
125
0
    return u"com.sun.star.comp.toolkit.AccessibleMenuBar"_ustr;
126
0
}
127
128
129
Sequence< OUString > VCLXAccessibleMenuBar::getSupportedServiceNames()
130
0
{
131
0
    return { u"com.sun.star.awt.AccessibleMenuBar"_ustr };
132
0
}
133
134
135
// XAccessibleContext
136
137
138
sal_Int64 VCLXAccessibleMenuBar::getAccessibleIndexInParent(  )
139
0
{
140
0
    OExternalLockGuard aGuard( this );
141
142
0
    sal_Int64 nIndexInParent = -1;
143
144
0
    if ( m_pMenu )
145
0
    {
146
0
        vcl::Window* pWindow = m_pMenu->GetWindow();
147
0
        if ( pWindow )
148
0
        {
149
0
            vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
150
0
            if ( pParent )
151
0
            {
152
0
                for ( sal_uInt16 n = pParent->GetAccessibleChildWindowCount(); n; )
153
0
                {
154
0
                    vcl::Window* pChild = pParent->GetAccessibleChildWindow( --n );
155
0
                    if ( pChild == pWindow )
156
0
                    {
157
0
                        nIndexInParent = n;
158
0
                        break;
159
0
                    }
160
0
                }
161
0
            }
162
0
        }
163
0
    }
164
165
0
    return nIndexInParent;
166
0
}
167
168
169
sal_Int16 VCLXAccessibleMenuBar::getAccessibleRole(  )
170
0
{
171
0
    OExternalLockGuard aGuard( this );
172
173
0
    return AccessibleRole::MENU_BAR;
174
0
}
175
176
177
// XAccessibleExtendedComponent
178
179
180
sal_Int32 VCLXAccessibleMenuBar::getBackground(  )
181
0
{
182
0
    OExternalLockGuard aGuard( this );
183
184
0
    return sal_Int32(Application::GetSettings().GetStyleSettings().GetMenuBarColor());
185
0
}
186
187
188
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */