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/.
10 #ifndef INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
11 #define INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
13 #include <com/sun/star/uno/XCurrentContext.hpp>
14 #include <cppuhelper/implbase.hxx>
15 #include <uno/current_context.hxx>
20 // Used to flag some named value to be true for all code running in this context
21 class SetFlagContext final
: public cppu::WeakImplHelper
<css::uno::XCurrentContext
>
24 explicit SetFlagContext(OUString sName
, css::uno::Reference
<css::uno::XCurrentContext
> xContext
)
25 : m_sName(std::move(sName
))
26 , mxNextContext(std::move(xContext
))
29 SetFlagContext(const SetFlagContext
&) = delete;
30 SetFlagContext
& operator=(const SetFlagContext
&) = delete;
32 virtual css::uno::Any SAL_CALL
getValueByName(OUString
const& Name
) override
35 return css::uno::Any(true);
36 else if (mxNextContext
.is())
37 return mxNextContext
->getValueByName(Name
);
39 return css::uno::Any();
44 css::uno::Reference
<css::uno::XCurrentContext
> mxNextContext
;
47 // Returns a new context that reports the named value to be true
48 inline css::uno::Reference
<css::uno::XCurrentContext
> NewFlagContext(const OUString
& sName
)
50 return new SetFlagContext(sName
, css::uno::getCurrentContext());
53 // A specialization for preventing "Java must be enabled" interaction
54 inline css::uno::Reference
<css::uno::XCurrentContext
> NoEnableJavaInteractionContext()
56 return NewFlagContext("DontEnableJava");
59 inline bool IsContextFlagActive(const OUString
& sName
)
62 if (const auto xContext
= css::uno::getCurrentContext())
63 xContext
->getValueByName(sName
) >>= bFlag
;
67 } // namespace comphelper
69 #endif // INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
71 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */