1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/registry/XRegistryKey.hpp>
21 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
22 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
27 #include <cppuhelper/factory.hxx>
28 #include <sfx2/sfxmodelfactory.hxx>
29 #include <sal/types.h>
33 #include <unordered_map>
35 using namespace com::sun::star
;
37 // Declaration and initialization of a map from service names to locally
38 // unique factory identifiers.
42 SdDrawingDocumentFactoryId
,
43 SdPresentationDocumentFactoryId
,
45 typedef std::unordered_map
<OUString
, FactoryId
> FactoryMap
;
48 FactoryMap
const & GetFactoryMap()
50 static FactoryMap aFactoryMap
52 { SdDrawingDocument_getImplementationName(), SdDrawingDocumentFactoryId
},
53 { SdPresentationDocument_getImplementationName(), SdPresentationDocumentFactoryId
}
57 } // end of anonymous namespace
62 SAL_DLLPUBLIC_EXPORT
void * sd_component_getFactory(
63 const sal_Char
* pImplName
,
64 void * pServiceManager
,
67 void * pRet
= nullptr;
71 uno::Reference
< lang::XMultiServiceFactory
> xMSF( static_cast< lang::XMultiServiceFactory
* >( pServiceManager
) );
73 uno::Reference
<lang::XSingleServiceFactory
> xFactory
;
74 uno::Reference
<lang::XSingleComponentFactory
> xComponentFactory
;
76 const FactoryMap
& rFactoryMap (GetFactoryMap());
77 OUString
sImplementationName (OUString::createFromAscii(pImplName
));
78 FactoryMap::const_iterator
iFactory (rFactoryMap
.find(sImplementationName
));
79 if (iFactory
!= rFactoryMap
.end())
81 switch (iFactory
->second
)
83 case SdDrawingDocumentFactoryId
:
84 xFactory
= ::sfx2::createSfxModelFactory(
86 SdDrawingDocument_getImplementationName(),
87 SdDrawingDocument_createInstance
,
88 SdDrawingDocument_getSupportedServiceNames());
91 case SdPresentationDocumentFactoryId
:
92 xFactory
= ::sfx2::createSfxModelFactory(
94 SdPresentationDocument_getImplementationName(),
95 SdPresentationDocument_createInstance
,
96 SdPresentationDocument_getSupportedServiceNames());
102 if (xComponentFactory
.is())
104 xComponentFactory
->acquire();
105 pRet
= xComponentFactory
.get();
107 else if (xFactory
.is())
110 pRet
= xFactory
.get();
120 } // end of extern "C"
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */