android: Update app-specific/MIME type icons
[LibreOffice.git] / include / comphelper / SetFlagContextHelper.hxx
blobb1b15eabba260f08c7cdc3aa84fbbebcc7bffa27
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/.
8 */
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>
16 #include <utility>
18 namespace comphelper
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>
23 public:
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
34 if (Name == m_sName)
35 return css::uno::Any(true);
36 else if (mxNextContext.is())
37 return mxNextContext->getValueByName(Name);
38 else
39 return css::uno::Any();
42 private:
43 OUString m_sName;
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)
61 bool bFlag = false;
62 if (const auto xContext = css::uno::getCurrentContext())
63 xContext->getValueByName(sName) >>= bFlag;
64 return bFlag;
67 } // namespace comphelper
69 #endif // INCLUDED_COMPHELPER_SETFLAGCONTEXTHELPER_HXX
71 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */