Coverage Report

Created: 2026-06-30 11:14

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
104
{
23
104
    class SetFlagContext : public cppu::WeakImplHelper<css::uno::XCurrentContext>
24
104
    {
25
104
    public:
26
104
        SetFlagContext(const OUString& sName, bool bValue)
27
104
            : msName(sName)
28
104
            , mbValue(bValue)
29
104
        {
30
104
        }
31
32
104
        virtual css::uno::Any SAL_CALL getValueByName(const OUString& Name) override
33
104
        {
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
104
    private:
42
104
        OUString msName;
43
104
        bool mbValue;
44
104
        css::uno::Reference<css::uno::XCurrentContext> mxNext = css::uno::getCurrentContext();
45
104
    };
46
104
    return new SetFlagContext(sName, bValue);
47
104
}
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: */