LibreOffice Module sd (master) 1
ModuleController.cxx
Go to the documentation of this file.
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
25#include <DrawController.hxx>
26#include <com/sun/star/frame/XController.hpp>
27#include <com/sun/star/uno/XComponentContext.hpp>
28#include <com/sun/star/container/XNameAccess.hpp>
29
32
34#include <rtl/ref.hxx>
35#include <sal/log.hxx>
36
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::uno;
40
41namespace sd::framework {
42
44{
45 assert(rxController);
46
52 "com.sun.star.drawing.framework.BasicPaneFactory",
53 { "private:resource/pane/CenterPane",
54 "private:resource/pane/LeftImpressPane",
55 "private:resource/pane/LeftDrawPane" });
57 "com.sun.star.drawing.framework.BasicViewFactory",
58 { "private:resource/view/ImpressView",
59 "private:resource/view/GraphicView",
60 "private:resource/view/OutlineView",
61 "private:resource/view/NotesView",
62 "private:resource/view/HandoutView",
63 "private:resource/view/SlideSorter",
64 "private:resource/view/PresentationView" });
66 "com.sun.star.drawing.framework.BasicToolBarFactory",
67 { "private:resource/toolbar/ViewTabBar" });
68
69 try
70 {
71 mxController = rxController;
72
74 }
75 catch (RuntimeException&)
76 {}
77}
78
80{
81}
82
83void ModuleController::disposing(std::unique_lock<std::mutex>&)
84{
85 // Break the cyclic reference back to DrawController object
86 maLoadedFactories.clear();
88 mxController.clear();
89}
90
91void ModuleController::ProcessFactory (const OUString& sServiceName, ::std::vector<OUString> aURLs)
92{
93 // Get all resource URLs that are created by the factory.
94
95 SAL_INFO("sd.fwk", __func__ << ": ModuleController::adding factory " << sServiceName);
96
97 // Add the resource URLs to the map.
98 for (const auto& rResource : aURLs)
99 {
101 SAL_INFO("sd.fwk", __func__ << ": " << rResource);
102 }
103}
104
106{
107 try
108 {
109 // Instantiate service.
110 // Note that when the new object will be destroyed at the end of
111 // this scope when it does not register itself anywhere.
112 // Typically it will add itself as ConfigurationChangeListener
113 // at the configuration controller.
115 }
116 catch (Exception&)
117 {
118 SAL_WARN("sd.fwk", "ERROR in ModuleController::InstantiateStartupServices");
119 }
120}
121
122//----- XModuleController -----------------------------------------------------
123
124void SAL_CALL ModuleController::requestResource (const OUString& rsResourceURL)
125{
126 auto iFactory = maResourceToFactoryMap.find(rsResourceURL);
127 if (iFactory == maResourceToFactoryMap.end())
128 return;
129
130 // Check that the factory has already been loaded and not been
131 // destroyed in the meantime.
132 Reference<XInterface> xFactory;
133 auto iLoadedFactory = maLoadedFactories.find(iFactory->second);
134 if (iLoadedFactory != maLoadedFactories.end())
135 xFactory.set(iLoadedFactory->second, UNO_QUERY);
136 if ( xFactory.is())
137 return;
138
139 // Create a new instance of the factory.
140 Reference<uno::XComponentContext> xContext =
141 ::comphelper::getProcessComponentContext();
142
143 // Create the factory service.
144 if (iFactory->second == "com.sun.star.drawing.framework.BasicPaneFactory")
145 xFactory = uno::Reference<css::drawing::framework::XResourceFactory>(new BasicPaneFactory(xContext, mxController));
146 else if (iFactory->second == "com.sun.star.drawing.framework.BasicViewFactory")
147 xFactory = uno::Reference<css::drawing::framework::XResourceFactory>(new BasicViewFactory(mxController));
148 else if (iFactory->second == "com.sun.star.drawing.framework.BasicToolBarFactory")
149 xFactory = uno::Reference<css::drawing::framework::XResourceFactory>(new BasicToolBarFactory(mxController));
150 else
151 throw RuntimeException("unknown factory");
152
153 // Remember that this factory has been instanced.
154 maLoadedFactories[iFactory->second] = xFactory;
155}
156
157} // end of namespace sd::framework
158
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
This factory provides the frequently used standard panes private:resource/pane/CenterPane private:res...
This factory provides some of the frequently used tool bars: private:resource/toolbar/ViewTabBar.
Factory for the frequently used standard views of the drawing framework: private:resource/view/ priva...
std::unordered_map< OUString, css::uno::WeakReference< css::uno::XInterface > > maLoadedFactories
ModuleController(const rtl::Reference<::sd::DrawController > &rxController)
void ProcessFactory(const OUString &ServiceName, ::std::vector< OUString > aURLs)
Called for every entry in the ResourceFactories configuration entry.
void InstantiateStartupServices()
Instantiate startup services.
rtl::Reference<::sd::DrawController > mxController
virtual void SAL_CALL requestResource(const OUString &rsResourceURL) override
virtual ~ModuleController() noexcept override
virtual void disposing(std::unique_lock< std::mutex > &) override
std::unordered_map< OUString, OUString > maResourceToFactoryMap
static void install(const rtl::Reference<::sd::DrawController > &rxController)
Reference< XSingleServiceFactory > xFactory
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
@ Exception