bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / unoidl / facreg.cxx
blobb6268254dfff870723b87946de80c2af117d7fc1
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/.
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>
24 #include <facreg.hxx>
25 #include <sddll.hxx>
27 #include <cppuhelper/factory.hxx>
28 #include <sfx2/sfxmodelfactory.hxx>
29 #include <sal/types.h>
31 #include <string.h>
32 #include <memory>
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.
40 enum FactoryId
42 SdDrawingDocumentFactoryId,
43 SdPresentationDocumentFactoryId,
45 typedef std::unordered_map<OUString, FactoryId> FactoryMap;
47 namespace {
48 FactoryMap const & GetFactoryMap()
50 static FactoryMap aFactoryMap
52 { SdDrawingDocument_getImplementationName(), SdDrawingDocumentFactoryId },
53 { SdPresentationDocument_getImplementationName(), SdPresentationDocumentFactoryId }
55 return aFactoryMap;
57 } // end of anonymous namespace
59 extern "C"
62 SAL_DLLPUBLIC_EXPORT void * sd_component_getFactory(
63 const sal_Char * pImplName,
64 void * pServiceManager,
65 void * )
67 void * pRet = nullptr;
69 if( pServiceManager )
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(
85 xMSF,
86 SdDrawingDocument_getImplementationName(),
87 SdDrawingDocument_createInstance,
88 SdDrawingDocument_getSupportedServiceNames());
89 break;
91 case SdPresentationDocumentFactoryId:
92 xFactory = ::sfx2::createSfxModelFactory(
93 xMSF,
94 SdPresentationDocument_getImplementationName(),
95 SdPresentationDocument_createInstance,
96 SdPresentationDocument_getSupportedServiceNames());
97 break;
99 default:
100 break;
102 if (xComponentFactory.is())
104 xComponentFactory->acquire();
105 pRet = xComponentFactory.get();
107 else if (xFactory.is())
109 xFactory->acquire();
110 pRet = xFactory.get();
115 if (pRet != nullptr)
116 SdDLL::Init();
117 return pRet;
120 } // end of extern "C"
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */