Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/comphelper/SetFlagContextHelper.hxx
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
10
#pragma once
11
12
#include <sal/config.h>
13
14
#include <cppuhelper/implbase.hxx>
15
#include <uno/current_context.hxx>
16
17
namespace comphelper
18
{
19
// Returns a new context layer that assigns the given boolean value to the name
20
inline css::uno::Reference<css::uno::XCurrentContext> NewFlagContext(const OUString& sName,
21
                                                                     bool bValue = true)
22
3
{
23
3
    class SetFlagContext : public cppu::WeakImplHelper<css::uno::XCurrentContext>
24
3
    {
25
3
    public:
26
3
        SetFlagContext(const OUString& sName, bool bValue)
27
3
            : msName(sName)
28
3
            , mbValue(bValue)
29
3
        {
30
3
        }
31
32
3
        virtual css::uno::Any SAL_CALL getValueByName(const OUString& Name) override
33
3
        {
34
0
            if (Name == msName)
35
0
                return css::uno::Any(mbValue);
36
0
            if (mxNext)
37
0
                return mxNext->getValueByName(Name);
38
0
            return css::uno::Any();
39
0
        }
40
41
3
    private:
42
3
        OUString msName;
43
3
        bool mbValue;
44
3
        css::uno::Reference<css::uno::XCurrentContext> mxNext = css::uno::getCurrentContext();
45
3
    };
46
3
    return new SetFlagContext(sName, bValue);
47
3
}
48
49
// A specialization for preventing "Java must be enabled" interaction
50
inline css::uno::Reference<css::uno::XCurrentContext> NoEnableJavaInteractionContext()
51
0
{
52
0
    return NewFlagContext(u"DontEnableJava"_ustr);
53
0
}
54
55
inline bool IsContextFlagActive(const OUString& sName)
56
0
{
57
0
    bool bFlag = false;
58
0
    if (const auto xContext = css::uno::getCurrentContext())
59
0
        xContext->getValueByName(sName) >>= bFlag;
60
0
    return bFlag;
61
0
}
62
63
} // namespace comphelper
64
65
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */