Line data Source code
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 :
20 : #include <com/sun/star/registry/XRegistryKey.hpp>
21 :
22 : #include "facreg.hxx"
23 : #include "sddll.hxx"
24 :
25 : #include <cppuhelper/factory.hxx>
26 : #include <sfx2/sfxmodelfactory.hxx>
27 : #include "osl/diagnose.h"
28 : #include "sal/types.h"
29 :
30 : #include <string.h>
31 :
32 : #include <boost/unordered_map.hpp>
33 : #include <boost/shared_ptr.hpp>
34 :
35 : using namespace com::sun::star;
36 :
37 : using namespace ::sd;
38 : using namespace ::sd::framework;
39 : using namespace ::sd::presenter;
40 : using namespace ::sd::slidesorter;
41 : using namespace ::sd::sidebar;
42 :
43 : // Declaration and initialization of a map from service names to locally
44 : // unique factory identifiers.
45 :
46 : enum FactoryId
47 : {
48 : SdDrawingDocumentFactoryId,
49 : SdPresentationDocumentFactoryId,
50 : SdHtmlOptionsDialogFactoryId,
51 : SdUnoModuleFactoryId,
52 : RandomNodeFactoryId,
53 :
54 : ConfigurationFactoryId,
55 : ConfigurationControllerFactoryId,
56 : ModuleControllerFactoryId,
57 : BasicPaneFactoryFactoryId,
58 : BasicToolBarFactoryFactoryId,
59 : BasicViewFactoryFactoryId,
60 : PanelFactoryFactoryId,
61 : ResourceIdFactoryId,
62 : PresentationFactoryProviderFactoryId,
63 : SlideRendererFactoryId,
64 : PresenterCanvasFactoryId,
65 : PresenterTextViewServiceFactoryId,
66 : PresenterHelperServiceFactoryId,
67 : PresenterPreviewCacheFactoryId,
68 : SlideSorterServiceFactoryId,
69 : SlideLayoutControllerFactoryId,
70 : InsertSlideControllerFactoryId,
71 : };
72 : typedef ::boost::unordered_map<OUString, FactoryId, OUStringHash> FactoryMap;
73 :
74 : namespace {
75 38 : static ::boost::shared_ptr<FactoryMap> spFactoryMap;
76 212 : ::boost::shared_ptr<FactoryMap> GetFactoryMap (void)
77 : {
78 212 : if (spFactoryMap.get() == NULL)
79 : {
80 34 : spFactoryMap.reset(new FactoryMap);
81 34 : (*spFactoryMap)[SdDrawingDocument_getImplementationName()] = SdDrawingDocumentFactoryId;
82 34 : (*spFactoryMap)[SdPresentationDocument_getImplementationName()] = SdPresentationDocumentFactoryId;
83 34 : (*spFactoryMap)[SdHtmlOptionsDialog_getImplementationName()] = SdHtmlOptionsDialogFactoryId;
84 34 : (*spFactoryMap)[SdUnoModule_getImplementationName()] = SdUnoModuleFactoryId;
85 34 : (*spFactoryMap)[RandomNode__getImplementationName()] = RandomNodeFactoryId;
86 34 : (*spFactoryMap)[Configuration_getImplementationName()] = ConfigurationFactoryId;
87 34 : (*spFactoryMap)[ConfigurationController_getImplementationName()] = ConfigurationControllerFactoryId;
88 34 : (*spFactoryMap)[ModuleController_getImplementationName()] = ModuleControllerFactoryId;
89 34 : (*spFactoryMap)[BasicPaneFactory_getImplementationName()] = BasicPaneFactoryFactoryId;
90 34 : (*spFactoryMap)[BasicToolBarFactory_getImplementationName()] = BasicToolBarFactoryFactoryId;
91 34 : (*spFactoryMap)[BasicViewFactory_getImplementationName()] = BasicViewFactoryFactoryId;
92 34 : (*spFactoryMap)[sidebar::PanelFactory_getImplementationName()] = PanelFactoryFactoryId;
93 34 : (*spFactoryMap)[ResourceId_getImplementationName()] = ResourceIdFactoryId;
94 34 : (*spFactoryMap)[PresentationFactoryProvider_getImplementationName()] = PresentationFactoryProviderFactoryId;
95 34 : (*spFactoryMap)[SlideRenderer_getImplementationName()] = SlideRendererFactoryId;
96 34 : (*spFactoryMap)[PresenterCanvas_getImplementationName()] = PresenterCanvasFactoryId;
97 34 : (*spFactoryMap)[PresenterTextViewService_getImplementationName()] = PresenterTextViewServiceFactoryId;
98 34 : (*spFactoryMap)[PresenterHelperService_getImplementationName()] = PresenterHelperServiceFactoryId;
99 34 : (*spFactoryMap)[PresenterPreviewCache_getImplementationName()] = PresenterPreviewCacheFactoryId;
100 34 : (*spFactoryMap)[SlideSorterService_getImplementationName()] = SlideSorterServiceFactoryId;
101 34 : (*spFactoryMap)[SlideLayoutController_getImplementationName()] = SlideLayoutControllerFactoryId;
102 34 : (*spFactoryMap)[InsertSlideController_getImplementationName()] = InsertSlideControllerFactoryId;
103 : }
104 212 : return spFactoryMap;
105 : };
106 : } // end of anonymous namespace
107 :
108 : extern "C"
109 : {
110 :
111 212 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL sd_component_getFactory(
112 : const sal_Char * pImplName,
113 : void * pServiceManager,
114 : void * )
115 : {
116 212 : void * pRet = 0;
117 :
118 212 : if( pServiceManager )
119 : {
120 212 : uno::Reference< lang::XMultiServiceFactory > xMSF( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
121 :
122 424 : uno::Reference<lang::XSingleServiceFactory> xFactory;
123 424 : uno::Reference<lang::XSingleComponentFactory> xComponentFactory;
124 :
125 424 : ::boost::shared_ptr<FactoryMap> pFactoryMap (GetFactoryMap());
126 424 : OUString sImplementationName (OUString::createFromAscii(pImplName));
127 212 : FactoryMap::const_iterator iFactory (pFactoryMap->find(sImplementationName));
128 212 : if (iFactory != pFactoryMap->end())
129 : {
130 212 : switch (iFactory->second)
131 : {
132 : case SdHtmlOptionsDialogFactoryId:
133 0 : xFactory = ::cppu::createSingleFactory(
134 : xMSF,
135 : SdHtmlOptionsDialog_getImplementationName(),
136 : SdHtmlOptionsDialog_CreateInstance,
137 0 : SdHtmlOptionsDialog_getSupportedServiceNames());
138 0 : break;
139 :
140 : case SdDrawingDocumentFactoryId:
141 40 : xFactory = ::sfx2::createSfxModelFactory(
142 : xMSF,
143 : SdDrawingDocument_getImplementationName(),
144 : SdDrawingDocument_createInstance,
145 20 : SdDrawingDocument_getSupportedServiceNames());
146 20 : break;
147 :
148 : case SdPresentationDocumentFactoryId:
149 40 : xFactory = ::sfx2::createSfxModelFactory(
150 : xMSF,
151 : SdPresentationDocument_getImplementationName(),
152 : SdPresentationDocument_createInstance,
153 20 : SdPresentationDocument_getSupportedServiceNames());
154 20 : break;
155 :
156 : case SdUnoModuleFactoryId:
157 4 : xFactory = ::cppu::createSingleFactory(
158 : xMSF,
159 : SdUnoModule_getImplementationName(),
160 : SdUnoModule_createInstance,
161 2 : SdUnoModule_getSupportedServiceNames());
162 2 : break;
163 :
164 : case RandomNodeFactoryId:
165 0 : xFactory = ::cppu::createSingleFactory(
166 : xMSF,
167 : sd::RandomNode__getImplementationName(),
168 : sd::RandomNode_createInstance,
169 0 : sd::RandomNode_getSupportedServiceNames());
170 0 : break;
171 :
172 : case ConfigurationFactoryId:
173 4 : xComponentFactory = ::cppu::createSingleComponentFactory(
174 : sd::framework::Configuration_createInstance,
175 : sd::framework::Configuration_getImplementationName(),
176 2 : sd::framework::Configuration_getSupportedServiceNames());
177 2 : break;
178 :
179 : case ConfigurationControllerFactoryId:
180 44 : xComponentFactory = ::cppu::createSingleComponentFactory(
181 : sd::framework::ConfigurationController_createInstance,
182 : sd::framework::ConfigurationController_getImplementationName(),
183 22 : sd::framework::ConfigurationController_getSupportedServiceNames());
184 22 : break;
185 :
186 : case ModuleControllerFactoryId:
187 44 : xComponentFactory = ::cppu::createSingleComponentFactory(
188 : sd::framework::ModuleController_createInstance,
189 : sd::framework::ModuleController_getImplementationName(),
190 22 : sd::framework::ModuleController_getSupportedServiceNames());
191 22 : break;
192 :
193 : case BasicPaneFactoryFactoryId:
194 44 : xComponentFactory = ::cppu::createSingleComponentFactory(
195 : sd::framework::BasicPaneFactory_createInstance,
196 : sd::framework::BasicPaneFactory_getImplementationName(),
197 22 : sd::framework::BasicPaneFactory_getSupportedServiceNames());
198 22 : break;
199 :
200 : case BasicToolBarFactoryFactoryId:
201 24 : xComponentFactory = ::cppu::createSingleComponentFactory(
202 : sd::framework::BasicToolBarFactory_createInstance,
203 : sd::framework::BasicToolBarFactory_getImplementationName(),
204 12 : sd::framework::BasicToolBarFactory_getSupportedServiceNames());
205 12 : break;
206 :
207 : case BasicViewFactoryFactoryId:
208 44 : xComponentFactory = ::cppu::createSingleComponentFactory(
209 : sd::framework::BasicViewFactory_createInstance,
210 : sd::framework::BasicViewFactory_getImplementationName(),
211 22 : sd::framework::BasicViewFactory_getSupportedServiceNames());
212 22 : break;
213 :
214 : case PanelFactoryFactoryId:
215 16 : xComponentFactory = ::cppu::createSingleComponentFactory(
216 : sd::sidebar::PanelFactory_createInstance,
217 : sd::sidebar::PanelFactory_getImplementationName(),
218 8 : sd::sidebar::PanelFactory_getSupportedServiceNames());
219 8 : break;
220 :
221 : case ResourceIdFactoryId:
222 36 : xComponentFactory = ::cppu::createSingleComponentFactory(
223 : sd::framework::ResourceId_createInstance,
224 : sd::framework::ResourceId_getImplementationName(),
225 18 : sd::framework::ResourceId_getSupportedServiceNames());
226 18 : break;
227 :
228 : case PresentationFactoryProviderFactoryId:
229 44 : xComponentFactory = ::cppu::createSingleComponentFactory(
230 : sd::framework::PresentationFactoryProvider_createInstance,
231 : sd::framework::PresentationFactoryProvider_getImplementationName(),
232 22 : sd::framework::PresentationFactoryProvider_getSupportedServiceNames());
233 22 : break;
234 :
235 : case SlideRendererFactoryId:
236 4 : xComponentFactory = ::cppu::createSingleComponentFactory(
237 : sd::presenter::SlideRenderer_createInstance,
238 : sd::presenter::SlideRenderer_getImplementationName(),
239 2 : sd::presenter::SlideRenderer_getSupportedServiceNames());
240 2 : break;
241 :
242 : case PresenterCanvasFactoryId:
243 4 : xComponentFactory = ::cppu::createSingleComponentFactory(
244 : sd::presenter::PresenterCanvas_createInstance,
245 : sd::presenter::PresenterCanvas_getImplementationName(),
246 2 : sd::presenter::PresenterCanvas_getSupportedServiceNames());
247 2 : break;
248 :
249 : case PresenterTextViewServiceFactoryId:
250 0 : xComponentFactory = ::cppu::createSingleComponentFactory(
251 : sd::presenter::PresenterTextViewService_createInstance,
252 : sd::presenter::PresenterTextViewService_getImplementationName(),
253 0 : sd::presenter::PresenterTextViewService_getSupportedServiceNames());
254 0 : break;
255 :
256 : case PresenterHelperServiceFactoryId:
257 0 : xComponentFactory = ::cppu::createSingleComponentFactory(
258 : sd::presenter::PresenterHelperService_createInstance,
259 : sd::presenter::PresenterHelperService_getImplementationName(),
260 0 : sd::presenter::PresenterHelperService_getSupportedServiceNames());
261 0 : break;
262 :
263 : case PresenterPreviewCacheFactoryId:
264 0 : xComponentFactory = ::cppu::createSingleComponentFactory(
265 : sd::presenter::PresenterPreviewCache_createInstance,
266 : sd::presenter::PresenterPreviewCache_getImplementationName(),
267 0 : sd::presenter::PresenterPreviewCache_getSupportedServiceNames());
268 0 : break;
269 :
270 : case SlideSorterServiceFactoryId:
271 0 : xComponentFactory = ::cppu::createSingleComponentFactory(
272 : sd::slidesorter::SlideSorterService_createInstance,
273 : sd::slidesorter::SlideSorterService_getImplementationName(),
274 0 : sd::slidesorter::SlideSorterService_getSupportedServiceNames());
275 0 : break;
276 :
277 : case SlideLayoutControllerFactoryId:
278 16 : xFactory = ::cppu::createSingleFactory(
279 : xMSF,
280 : sd::SlideLayoutController_getImplementationName(),
281 : sd::SlideLayoutController_createInstance,
282 8 : sd::SlideLayoutController_getSupportedServiceNames());
283 8 : break;
284 :
285 : case InsertSlideControllerFactoryId:
286 16 : xFactory = ::cppu::createSingleFactory(
287 : xMSF,
288 : sd::InsertSlideController_getImplementationName(),
289 : sd::InsertSlideController_createInstance,
290 8 : sd::InsertSlideController_getSupportedServiceNames());
291 : default:
292 8 : break;
293 : }
294 212 : if (xComponentFactory.is())
295 : {
296 154 : xComponentFactory->acquire();
297 154 : pRet = xComponentFactory.get();
298 : }
299 58 : else if (xFactory.is())
300 : {
301 58 : xFactory->acquire();
302 58 : pRet = xFactory.get();
303 : }
304 212 : }
305 : }
306 :
307 212 : if (pRet != NULL)
308 212 : SdDLL::Init();
309 212 : return pRet;
310 : }
311 :
312 114 : } // end of extern "C"
313 :
314 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|