feat(invert): Allow inverted background on init
[LibreOffice.git] / cppuhelper / source / defaultbootstrap.cxx
blobca70a91d3f57611a1c236101218e4e5f306b21b8
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 #include <sal/config.h>
12 #include <vector>
14 #include <com/sun/star/uno/DeploymentException.hpp>
15 #include <com/sun/star/uno/Any.hxx>
16 #include <com/sun/star/uno/Reference.hxx>
17 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
18 #include <cppuhelper/bootstrap.hxx>
19 #include <cppuhelper/component_context.hxx>
20 #include <cppuhelper/weak.hxx>
21 #include <rtl/bootstrap.hxx>
22 #include <rtl/ref.hxx>
23 #include <rtl/ustring.hxx>
25 #include "macro_expander.hxx"
26 #include "paths.hxx"
27 #include "servicemanager.hxx"
28 #include "typemanager.hxx"
30 namespace com :: sun :: star :: uno { class XComponentContext; }
32 namespace {
34 OUString getBootstrapVariable(
35 rtl::Bootstrap const & bootstrap, OUString const & name)
37 OUString v;
38 if (!bootstrap.getFrom(name, v)) {
39 throw css::uno::DeploymentException(
40 "Cannot obtain " + name + " from uno ini");
42 return v;
47 css::uno::Reference< css::uno::XComponentContext >
48 cppu::defaultBootstrap_InitialComponentContext(OUString const & iniUri)
50 rtl::Bootstrap bs(iniUri);
51 if (bs.getHandle() == nullptr) {
52 throw css::uno::DeploymentException(
53 "Cannot open uno ini " + iniUri);
55 rtl::Reference smgr(
56 new cppuhelper::ServiceManager);
57 smgr->init(getBootstrapVariable(bs, u"UNO_SERVICES"_ustr));
58 rtl::Reference tmgr(new cppuhelper::TypeManager);
59 tmgr->init(getBootstrapVariable(bs, u"UNO_TYPES"_ustr));
60 std::vector< cppu::ContextEntry_Init > context_values
62 cppu::ContextEntry_Init(
63 u"/singletons/com.sun.star.lang.theServiceManager"_ustr,
64 css::uno::Any(
65 css::uno::Reference< css::uno::XInterface >(
66 static_cast< cppu::OWeakObject * >(smgr.get()))),
67 false),
68 cppu::ContextEntry_Init(
69 u"/singletons/com.sun.star.reflection.theTypeDescriptionManager"_ustr,
70 css::uno::Any(
71 css::uno::Reference< css::uno::XInterface >(
72 static_cast< cppu::OWeakObject * >(tmgr.get()))),
73 false),
74 cppu::ContextEntry_Init( //TODO: from services.rdb?
75 u"/singletons/com.sun.star.util.theMacroExpander"_ustr,
76 css::uno::Any(
77 cppuhelper::detail::create_bootstrap_macro_expander_factory()),
78 true)
80 smgr->addSingletonContextEntries(&context_values);
81 context_values.push_back(
82 cppu::ContextEntry_Init(
83 u"/services/com.sun.star.security.AccessController/mode"_ustr,
84 css::uno::Any(u"off"_ustr), false));
85 context_values.push_back(
86 cppu::ContextEntry_Init(
87 u"/singletons/com.sun.star.security.theAccessController"_ustr,
88 css::uno::Any(
89 u"com.sun.star.security.AccessController"_ustr),
90 true));
91 css::uno::Reference< css::uno::XComponentContext > context(
92 createComponentContext(context_values.data(), context_values.size()));
93 smgr->setContext(context);
94 cppu::installTypeDescriptionManager(tmgr);
95 return context;
98 css::uno::Reference< css::uno::XComponentContext >
99 cppu::defaultBootstrap_InitialComponentContext()
101 return defaultBootstrap_InitialComponentContext(getUnoIniUri());
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */