xref: /trunk/main/sd/source/ui/unoidl/facreg.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 #include <com/sun/star/registry/XRegistryKey.hpp>
27 
28 #include "sddll.hxx"
29 
30 #include <cppuhelper/factory.hxx>
31 #include <uno/lbnames.h>
32 #include <sfx2/sfxmodelfactory.hxx>
33 #include "osl/diagnose.h"
34 #include "sal/types.h"
35 
36 #ifndef INCLUDED_STRING_H
37 #include <string.h>
38 #define INCLUDED_STRING_H
39 #endif
40 #include <comphelper/stl_types.hxx>
41 #include <hash_map>
42 #include <boost/shared_ptr.hpp>
43 
44 using namespace rtl;
45 using namespace com::sun::star;
46 
47 
48 // Forward declarations of the factories.
49 
50 extern uno::Reference< uno::XInterface > SAL_CALL SdDrawingDocument_createInstance( const uno::Reference< lang::XMultiServiceFactory > & _rxFactory, const sal_uInt64 _nCreationFlags );
51 extern OUString SdDrawingDocument_getImplementationName();
52 extern uno::Sequence< OUString > SAL_CALL SdDrawingDocument_getSupportedServiceNames();
53 
54 extern uno::Reference< uno::XInterface > SAL_CALL SdPresentationDocument_createInstance( const uno::Reference< lang::XMultiServiceFactory > & _rxFactory, const sal_uInt64 _nCreationFlags );
55 extern OUString SdPresentationDocument_getImplementationName();
56 extern uno::Sequence< OUString > SAL_CALL SdPresentationDocument_getSupportedServiceNames();
57 
58 extern uno::Reference< uno::XInterface > SAL_CALL SdHtmlOptionsDialog_CreateInstance( const uno::Reference< lang::XMultiServiceFactory > & _rxFactory );
59 extern OUString SdHtmlOptionsDialog_getImplementationName();
60 extern uno::Sequence< OUString > SAL_CALL SdHtmlOptionsDialog_getSupportedServiceNames();
61 
62 extern uno::Reference< uno::XInterface > SAL_CALL SdUnoModule_createInstance( const uno::Reference< lang::XMultiServiceFactory > & _rxFactory );
63 extern OUString SdUnoModule_getImplementationName();
64 extern uno::Sequence< OUString > SAL_CALL SdUnoModule_getSupportedServiceNames();
65 
66 namespace sd
67 {
68 extern uno::Reference< uno::XInterface > SAL_CALL RandomNode_createInstance( const uno::Reference< lang::XMultiServiceFactory > & _rxFactory );
69 extern OUString RandomNode__getImplementationName();
70 extern uno::Sequence< OUString > SAL_CALL RandomNode_getSupportedServiceNames();
71 
72 extern uno::Reference< uno::XInterface > SAL_CALL SlideLayoutController_createInstance( const uno::Reference< lang::XMultiServiceFactory > & _rxFactory );
73 extern OUString SlideLayoutController_getImplementationName();
74 extern uno::Sequence< OUString >  SlideLayoutController_getSupportedServiceNames();
75 
76 extern uno::Reference< uno::XInterface > SAL_CALL InsertSlideController_createInstance( const uno::Reference< lang::XMultiServiceFactory > & _rxFactory );
77 extern OUString InsertSlideController_getImplementationName();
78 extern uno::Sequence< OUString >  InsertSlideController_getSupportedServiceNames();
79 }
80 
81 namespace sd { namespace framework {
82 
83 extern uno::Reference<uno::XInterface> SAL_CALL Configuration_createInstance(
84     const uno::Reference<uno::XComponentContext>& rxContext);
85 extern OUString Configuration_getImplementationName(void);
86 extern uno::Sequence<OUString> SAL_CALL Configuration_getSupportedServiceNames (void);
87 
88 extern uno::Reference<uno::XInterface> SAL_CALL ConfigurationController_createInstance(
89     const uno::Reference<uno::XComponentContext>& rxContext);
90 extern OUString ConfigurationController_getImplementationName(void);
91 extern uno::Sequence<OUString> SAL_CALL ConfigurationController_getSupportedServiceNames (void);
92 
93 extern uno::Reference<uno::XInterface> SAL_CALL ModuleController_createInstance(
94     const uno::Reference<uno::XComponentContext>& rxContext);
95 extern OUString ModuleController_getImplementationName(void);
96 extern uno::Sequence<OUString> SAL_CALL ModuleController_getSupportedServiceNames (void);
97 
98 extern uno::Reference<uno::XInterface> SAL_CALL BasicPaneFactory_createInstance(
99     const uno::Reference<uno::XComponentContext>& rxContext);
100 extern OUString BasicPaneFactory_getImplementationName(void);
101 extern uno::Sequence<OUString> SAL_CALL BasicPaneFactory_getSupportedServiceNames (void);
102 
103 extern uno::Reference<uno::XInterface> SAL_CALL BasicToolBarFactory_createInstance(
104     const uno::Reference<uno::XComponentContext>& rxContext);
105 extern OUString BasicToolBarFactory_getImplementationName(void);
106 extern uno::Sequence<OUString> SAL_CALL BasicToolBarFactory_getSupportedServiceNames (void);
107 
108 extern uno::Reference<uno::XInterface> SAL_CALL BasicViewFactory_createInstance(
109     const uno::Reference<uno::XComponentContext>& rxContext);
110 extern OUString BasicViewFactory_getImplementationName(void);
111 extern uno::Sequence<OUString> SAL_CALL BasicViewFactory_getSupportedServiceNames (void);
112 
113 extern uno::Reference<uno::XInterface> SAL_CALL ResourceId_createInstance(
114     const uno::Reference<uno::XComponentContext>& rxContext);
115 extern OUString ResourceId_getImplementationName(void);
116 extern uno::Sequence<OUString> SAL_CALL ResourceId_getSupportedServiceNames (void);
117 
118 extern uno::Reference<uno::XInterface> SAL_CALL PresentationFactoryProvider_createInstance(
119     const uno::Reference<uno::XComponentContext>& rxContext);
120 extern OUString PresentationFactoryProvider_getImplementationName(void);
121 extern uno::Sequence<OUString> SAL_CALL PresentationFactoryProvider_getSupportedServiceNames (void);
122 } }
123 
124 namespace sd { namespace sidebar {
125 
126 extern uno::Reference<uno::XInterface> SAL_CALL PanelFactory_createInstance(
127     const uno::Reference<uno::XComponentContext>& rxContext);
128 extern OUString PanelFactory_getImplementationName(void);
129 extern uno::Sequence<OUString> SAL_CALL PanelFactory_getSupportedServiceNames (void);
130 
131 } }
132 
133 namespace sd { namespace presenter {
134 extern uno::Reference<uno::XInterface> SAL_CALL SlideRenderer_createInstance(
135     const uno::Reference<uno::XComponentContext>& rxContext);
136 extern OUString SlideRenderer_getImplementationName(void);
137 extern uno::Sequence<OUString> SAL_CALL SlideRenderer_getSupportedServiceNames (void);
138 
139 extern uno::Reference<uno::XInterface> SAL_CALL PresenterCanvas_createInstance(
140     const uno::Reference<uno::XComponentContext>& rxContext);
141 extern OUString PresenterCanvas_getImplementationName(void);
142 extern uno::Sequence<OUString> SAL_CALL PresenterCanvas_getSupportedServiceNames (void);
143 
144 extern uno::Reference<uno::XInterface> SAL_CALL PresenterTextViewService_createInstance(
145     const uno::Reference<uno::XComponentContext>& rxContext);
146 extern OUString PresenterTextViewService_getImplementationName(void);
147 extern uno::Sequence<OUString> SAL_CALL PresenterTextViewService_getSupportedServiceNames (void);
148 
149 extern uno::Reference<uno::XInterface> SAL_CALL PresenterHelperService_createInstance(
150     const uno::Reference<uno::XComponentContext>& rxContext);
151 extern OUString PresenterHelperService_getImplementationName(void);
152 extern uno::Sequence<OUString> SAL_CALL PresenterHelperService_getSupportedServiceNames (void);
153 
154 extern uno::Reference<uno::XInterface> SAL_CALL PresenterPreviewCache_createInstance(
155     const uno::Reference<uno::XComponentContext>& rxContext);
156 extern OUString PresenterPreviewCache_getImplementationName(void);
157 extern uno::Sequence<OUString> SAL_CALL PresenterPreviewCache_getSupportedServiceNames (void);
158 } }
159 
160 
161 namespace sd { namespace slidesorter {
162 extern uno::Reference<uno::XInterface> SAL_CALL SlideSorterService_createInstance(
163     const uno::Reference<uno::XComponentContext>& rxContext);
164 extern OUString SlideSorterService_getImplementationName(void);
165 extern uno::Sequence<OUString> SAL_CALL SlideSorterService_getSupportedServiceNames (void);
166 } }
167 
168 using namespace ::sd;
169 using namespace ::sd::framework;
170 using namespace ::sd::presenter;
171 using namespace ::sd::slidesorter;
172 using namespace ::sd::sidebar;
173 
174 
175 
176 
177 // ----------------------------------------------------------------------------
178 // Declaration and initialization of a map from service names to locally
179 // unique factory identifiers.
180 
181 enum FactoryId
182 {
183     SdDrawingDocumentFactoryId,
184     SdPresentationDocumentFactoryId,
185     SdHtmlOptionsDialogFactoryId,
186     SdUnoModuleFactoryId,
187     RandomNodeFactoryId,
188 
189     ConfigurationFactoryId,
190     ConfigurationControllerFactoryId,
191     ModuleControllerFactoryId,
192     BasicPaneFactoryFactoryId,
193     BasicToolBarFactoryFactoryId,
194     BasicViewFactoryFactoryId,
195     PanelFactoryFactoryId,
196     ResourceIdFactoryId,
197     PresentationFactoryProviderFactoryId,
198     SlideRendererFactoryId,
199     PresenterCanvasFactoryId,
200     PresenterTextViewServiceFactoryId,
201     PresenterHelperServiceFactoryId,
202     PresenterPreviewCacheFactoryId,
203     SlideSorterServiceFactoryId,
204     SlideLayoutControllerFactoryId,
205     InsertSlideControllerFactoryId,
206 };
207 typedef ::std::hash_map<OUString, FactoryId, comphelper::UStringHash, comphelper::UStringEqual> FactoryMap;
208 
209 
210 namespace {
211 static ::boost::shared_ptr<FactoryMap> spFactoryMap;
GetFactoryMap(void)212 ::boost::shared_ptr<FactoryMap> GetFactoryMap (void)
213 {
214     if (spFactoryMap.get() == NULL)
215     {
216         spFactoryMap.reset(new FactoryMap);
217         (*spFactoryMap)[SdDrawingDocument_getImplementationName()] = SdDrawingDocumentFactoryId;
218         (*spFactoryMap)[SdPresentationDocument_getImplementationName()] = SdPresentationDocumentFactoryId;
219         (*spFactoryMap)[SdHtmlOptionsDialog_getImplementationName()] = SdHtmlOptionsDialogFactoryId;
220         (*spFactoryMap)[SdUnoModule_getImplementationName()] = SdUnoModuleFactoryId;
221         (*spFactoryMap)[RandomNode__getImplementationName()] = RandomNodeFactoryId;
222         (*spFactoryMap)[Configuration_getImplementationName()] = ConfigurationFactoryId;
223         (*spFactoryMap)[ConfigurationController_getImplementationName()] = ConfigurationControllerFactoryId;
224         (*spFactoryMap)[ModuleController_getImplementationName()] = ModuleControllerFactoryId;
225         (*spFactoryMap)[BasicPaneFactory_getImplementationName()] = BasicPaneFactoryFactoryId;
226         (*spFactoryMap)[BasicToolBarFactory_getImplementationName()] = BasicToolBarFactoryFactoryId;
227         (*spFactoryMap)[BasicViewFactory_getImplementationName()] = BasicViewFactoryFactoryId;
228         (*spFactoryMap)[sidebar::PanelFactory_getImplementationName()] = PanelFactoryFactoryId;
229         (*spFactoryMap)[ResourceId_getImplementationName()] = ResourceIdFactoryId;
230         (*spFactoryMap)[PresentationFactoryProvider_getImplementationName()] = PresentationFactoryProviderFactoryId;
231         (*spFactoryMap)[SlideRenderer_getImplementationName()] = SlideRendererFactoryId;
232         (*spFactoryMap)[PresenterCanvas_getImplementationName()] = PresenterCanvasFactoryId;
233         (*spFactoryMap)[PresenterTextViewService_getImplementationName()] = PresenterTextViewServiceFactoryId;
234         (*spFactoryMap)[PresenterHelperService_getImplementationName()] = PresenterHelperServiceFactoryId;
235         (*spFactoryMap)[PresenterPreviewCache_getImplementationName()] = PresenterPreviewCacheFactoryId;
236         (*spFactoryMap)[SlideSorterService_getImplementationName()] = SlideSorterServiceFactoryId;
237         (*spFactoryMap)[SlideLayoutController_getImplementationName()] = SlideLayoutControllerFactoryId;
238         (*spFactoryMap)[InsertSlideController_getImplementationName()] = InsertSlideControllerFactoryId;
239     }
240     return spFactoryMap;
241 };
242 } // end of anonymous namespace
243 
244 
245 extern "C"
246 {
247 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)248 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
249     const sal_Char  ** ppEnvTypeName,
250     uno_Environment **  )
251 {
252     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
253 }
254 
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void *)255 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
256     const sal_Char * pImplName,
257     void           * pServiceManager,
258     void           *  )
259 {
260     void * pRet = 0;
261 
262     if( pServiceManager )
263     {
264         uno::Reference< lang::XMultiServiceFactory > xMSF( reinterpret_cast< lang::XMultiServiceFactory * >( pServiceManager ) );
265 
266         uno::Reference<lang::XSingleServiceFactory> xFactory;
267         uno::Reference<lang::XSingleComponentFactory> xComponentFactory;
268 
269         ::boost::shared_ptr<FactoryMap> pFactoryMap (GetFactoryMap());
270         OUString sImplementationName (OUString::createFromAscii(pImplName));
271         FactoryMap::const_iterator iFactory (pFactoryMap->find(sImplementationName));
272         if (iFactory != pFactoryMap->end())
273         {
274             switch (iFactory->second)
275             {
276                 case SdHtmlOptionsDialogFactoryId:
277                     xFactory = ::cppu::createSingleFactory(
278                         xMSF,
279                         SdHtmlOptionsDialog_getImplementationName(),
280                         SdHtmlOptionsDialog_CreateInstance,
281                         SdHtmlOptionsDialog_getSupportedServiceNames());
282                     break;
283 
284                 case SdDrawingDocumentFactoryId:
285                     xFactory = ::sfx2::createSfxModelFactory(
286                         xMSF,
287                         SdDrawingDocument_getImplementationName(),
288                         SdDrawingDocument_createInstance,
289                         SdDrawingDocument_getSupportedServiceNames());
290                     break;
291 
292                 case SdPresentationDocumentFactoryId:
293                     xFactory = ::sfx2::createSfxModelFactory(
294                         xMSF,
295                         SdPresentationDocument_getImplementationName(),
296                         SdPresentationDocument_createInstance,
297                         SdPresentationDocument_getSupportedServiceNames());
298                     break;
299 
300                 case SdUnoModuleFactoryId:
301                     xFactory = ::cppu::createSingleFactory(
302                         xMSF,
303                         SdUnoModule_getImplementationName(),
304                         SdUnoModule_createInstance,
305                         SdUnoModule_getSupportedServiceNames());
306                     break;
307 
308                 case RandomNodeFactoryId:
309                     xFactory = ::cppu::createSingleFactory(
310                         xMSF,
311                         sd::RandomNode__getImplementationName(),
312                         sd::RandomNode_createInstance,
313                         sd::RandomNode_getSupportedServiceNames());
314                     break;
315 
316                 case ConfigurationFactoryId:
317                     xComponentFactory = ::cppu::createSingleComponentFactory(
318                         sd::framework::Configuration_createInstance,
319                         sd::framework::Configuration_getImplementationName(),
320                         sd::framework::Configuration_getSupportedServiceNames());
321                     break;
322 
323                 case ConfigurationControllerFactoryId:
324                     xComponentFactory = ::cppu::createSingleComponentFactory(
325                         sd::framework::ConfigurationController_createInstance,
326                         sd::framework::ConfigurationController_getImplementationName(),
327                         sd::framework::ConfigurationController_getSupportedServiceNames());
328                     break;
329 
330                 case ModuleControllerFactoryId:
331                     xComponentFactory = ::cppu::createSingleComponentFactory(
332                         sd::framework::ModuleController_createInstance,
333                         sd::framework::ModuleController_getImplementationName(),
334                         sd::framework::ModuleController_getSupportedServiceNames());
335                     break;
336 
337                 case BasicPaneFactoryFactoryId:
338                     xComponentFactory = ::cppu::createSingleComponentFactory(
339                         sd::framework::BasicPaneFactory_createInstance,
340                         sd::framework::BasicPaneFactory_getImplementationName(),
341                         sd::framework::BasicPaneFactory_getSupportedServiceNames());
342                     break;
343 
344                 case BasicToolBarFactoryFactoryId:
345                     xComponentFactory = ::cppu::createSingleComponentFactory(
346                         sd::framework::BasicToolBarFactory_createInstance,
347                         sd::framework::BasicToolBarFactory_getImplementationName(),
348                         sd::framework::BasicToolBarFactory_getSupportedServiceNames());
349                     break;
350 
351                 case BasicViewFactoryFactoryId:
352                     xComponentFactory = ::cppu::createSingleComponentFactory(
353                         sd::framework::BasicViewFactory_createInstance,
354                         sd::framework::BasicViewFactory_getImplementationName(),
355                         sd::framework::BasicViewFactory_getSupportedServiceNames());
356                     break;
357 
358                 case PanelFactoryFactoryId:
359                     xComponentFactory = ::cppu::createSingleComponentFactory(
360                         sd::sidebar::PanelFactory_createInstance,
361                         sd::sidebar::PanelFactory_getImplementationName(),
362                         sd::sidebar::PanelFactory_getSupportedServiceNames());
363                     break;
364 
365                 case ResourceIdFactoryId:
366                     xComponentFactory = ::cppu::createSingleComponentFactory(
367                         sd::framework::ResourceId_createInstance,
368                         sd::framework::ResourceId_getImplementationName(),
369                         sd::framework::ResourceId_getSupportedServiceNames());
370                     break;
371 
372                 case PresentationFactoryProviderFactoryId:
373                     xComponentFactory = ::cppu::createSingleComponentFactory(
374                         sd::framework::PresentationFactoryProvider_createInstance,
375                         sd::framework::PresentationFactoryProvider_getImplementationName(),
376                         sd::framework::PresentationFactoryProvider_getSupportedServiceNames());
377                     break;
378 
379                 case SlideRendererFactoryId:
380                     xComponentFactory = ::cppu::createSingleComponentFactory(
381                         sd::presenter::SlideRenderer_createInstance,
382                         sd::presenter::SlideRenderer_getImplementationName(),
383                         sd::presenter::SlideRenderer_getSupportedServiceNames());
384                     break;
385 
386                 case PresenterCanvasFactoryId:
387                     xComponentFactory = ::cppu::createSingleComponentFactory(
388                         sd::presenter::PresenterCanvas_createInstance,
389                         sd::presenter::PresenterCanvas_getImplementationName(),
390                         sd::presenter::PresenterCanvas_getSupportedServiceNames());
391                     break;
392 
393                 case PresenterTextViewServiceFactoryId:
394                     xComponentFactory = ::cppu::createSingleComponentFactory(
395                         sd::presenter::PresenterTextViewService_createInstance,
396                         sd::presenter::PresenterTextViewService_getImplementationName(),
397                         sd::presenter::PresenterTextViewService_getSupportedServiceNames());
398                     break;
399 
400                 case PresenterHelperServiceFactoryId:
401                     xComponentFactory = ::cppu::createSingleComponentFactory(
402                         sd::presenter::PresenterHelperService_createInstance,
403                         sd::presenter::PresenterHelperService_getImplementationName(),
404                         sd::presenter::PresenterHelperService_getSupportedServiceNames());
405                     break;
406 
407                 case PresenterPreviewCacheFactoryId:
408                     xComponentFactory = ::cppu::createSingleComponentFactory(
409                         sd::presenter::PresenterPreviewCache_createInstance,
410                         sd::presenter::PresenterPreviewCache_getImplementationName(),
411                         sd::presenter::PresenterPreviewCache_getSupportedServiceNames());
412                     break;
413 
414                 case SlideSorterServiceFactoryId:
415                     xComponentFactory = ::cppu::createSingleComponentFactory(
416                         sd::slidesorter::SlideSorterService_createInstance,
417                         sd::slidesorter::SlideSorterService_getImplementationName(),
418                         sd::slidesorter::SlideSorterService_getSupportedServiceNames());
419                     break;
420 
421                 case SlideLayoutControllerFactoryId:
422                     xFactory = ::cppu::createSingleFactory(
423                         xMSF,
424                         sd::SlideLayoutController_getImplementationName(),
425                         sd::SlideLayoutController_createInstance,
426                         sd::SlideLayoutController_getSupportedServiceNames());
427                     break;
428 
429                 case InsertSlideControllerFactoryId:
430                     xFactory = ::cppu::createSingleFactory(
431                         xMSF,
432                         sd::InsertSlideController_getImplementationName(),
433                         sd::InsertSlideController_createInstance,
434                         sd::InsertSlideController_getSupportedServiceNames());
435                 default:
436                     break;
437             }
438             if (xComponentFactory.is())
439             {
440                 xComponentFactory->acquire();
441                 pRet = xComponentFactory.get();
442             }
443             else if (xFactory.is())
444             {
445                 xFactory->acquire();
446                 pRet = xFactory.get();
447             }
448         }
449     }
450 
451     if (pRet != NULL)
452         SdDLL::Init();
453     return pRet;
454 }
455 
456 } // end of extern "C"
457