fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uiconfiguration / moduleuicfgsupplier.cxx
blob49fd22ca81a5331185e35707eb7d479fa22b1ab9
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 <stdtypes.h>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/container/XNameAccess.hpp>
24 #include <com/sun/star/embed/ElementModes.hpp>
25 #include <com/sun/star/frame/ModuleManager.hpp>
26 #include <com/sun/star/io/XOutputStream.hpp>
27 #include <com/sun/star/io/XInputStream.hpp>
28 #include <com/sun/star/io/XSeekable.hpp>
29 #include <com/sun/star/embed/XPackageStructureCreator.hpp>
30 #include <com/sun/star/ui/ModuleUIConfigurationManager.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
33 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
34 #include <com/sun/star/ui/XModuleUIConfigurationManager2.hpp>
35 #include <com/sun/star/frame/XModuleManager2.hpp>
37 #include <cppuhelper/basemutex.hxx>
38 #include <cppuhelper/compbase2.hxx>
39 #include <cppuhelper/supportsservice.hxx>
40 #include <vcl/svapp.hxx>
42 #include <unordered_map>
44 using namespace com::sun::star::uno;
45 using namespace com::sun::star::io;
46 using namespace com::sun::star::lang;
47 using namespace com::sun::star::container;
48 using namespace com::sun::star::beans;
49 using namespace com::sun::star::embed;
50 using namespace ::com::sun::star::ui;
51 using namespace ::com::sun::star::frame;
52 using namespace framework;
54 namespace {
56 typedef cppu::WeakComponentImplHelper2<
57 css::lang::XServiceInfo,
58 css::ui::XModuleUIConfigurationManagerSupplier >
59 ModuleUIConfigurationManagerSupplier_BASE;
61 class ModuleUIConfigurationManagerSupplier : private cppu::BaseMutex,
62 public ModuleUIConfigurationManagerSupplier_BASE
64 public:
65 ModuleUIConfigurationManagerSupplier( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
66 virtual ~ModuleUIConfigurationManagerSupplier();
68 virtual OUString SAL_CALL getImplementationName()
69 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
71 return OUString("com.sun.star.comp.framework.ModuleUIConfigurationManagerSupplier");
74 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
75 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
77 return cppu::supportsService(this, ServiceName);
80 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
81 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
83 css::uno::Sequence< OUString > aSeq(1);
84 aSeq[0] = "com.sun.star.ui.ModuleUIConfigurationManagerSupplier";
85 return aSeq;
88 // XModuleUIConfigurationManagerSupplier
89 virtual css::uno::Reference< css::ui::XUIConfigurationManager > SAL_CALL getUIConfigurationManager( const OUString& ModuleIdentifier )
90 throw (css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
92 private:
93 virtual void SAL_CALL disposing() SAL_OVERRIDE;
95 typedef std::unordered_map< OUString, css::uno::Reference< css::ui::XModuleUIConfigurationManager2 >, OUStringHash, std::equal_to< OUString > > ModuleToModuleCfgMgr;
97 //TODO_AS void impl_initStorages();
99 ModuleToModuleCfgMgr m_aModuleToModuleUICfgMgrMap;
100 css::uno::Reference< css::frame::XModuleManager2 > m_xModuleMgr;
101 css::uno::Reference< css::uno::XComponentContext > m_xContext;
104 ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XComponentContext >& xContext ) :
105 ModuleUIConfigurationManagerSupplier_BASE(m_aMutex)
106 , m_xModuleMgr( ModuleManager::create( xContext ) )
107 , m_xContext( xContext )
111 // Retrieve known modules and insert them into our unordered_map to speed-up access time.
112 Reference< XNameAccess > xNameAccess( m_xModuleMgr, UNO_QUERY_THROW );
113 const Sequence< OUString > aNameSeq = xNameAccess->getElementNames();
114 const OUString* pNameSeq = aNameSeq.getConstArray();
115 for ( sal_Int32 n = 0; n < aNameSeq.getLength(); n++ )
116 m_aModuleToModuleUICfgMgrMap.insert( ModuleToModuleCfgMgr::value_type( pNameSeq[n], Reference< XModuleUIConfigurationManager2 >() ));
118 catch(...)
123 ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier()
125 disposing();
128 void SAL_CALL ModuleUIConfigurationManagerSupplier::disposing()
130 osl::MutexGuard g(rBHelper.rMutex);
132 // dispose all our module user interface configuration managers
133 ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin();
134 while ( pIter != m_aModuleToModuleUICfgMgrMap.end() )
136 Reference< XComponent > xComponent( pIter->second, UNO_QUERY );
137 if ( xComponent.is() )
138 xComponent->dispose();
139 ++pIter;
141 m_aModuleToModuleUICfgMgrMap.clear();
142 m_xModuleMgr.clear();
145 // XModuleUIConfigurationManagerSupplier
146 Reference< XUIConfigurationManager > SAL_CALL ModuleUIConfigurationManagerSupplier::getUIConfigurationManager( const OUString& sModuleIdentifier )
147 throw ( NoSuchElementException, RuntimeException, std::exception)
149 osl::MutexGuard g(rBHelper.rMutex);
150 /* SAFE AREA ----------------------------------------------------------------------------------------------- */
152 ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( sModuleIdentifier );
153 if ( pIter == m_aModuleToModuleUICfgMgrMap.end() )
154 throw NoSuchElementException();
155 //TODO_AS impl_initStorages();
157 // Create instance on demand
158 if ( !pIter->second.is() )
160 OUString sShort;
163 Sequence< PropertyValue > lProps;
164 Reference< XNameAccess > xCont(m_xModuleMgr, UNO_QUERY);
165 xCont->getByName(sModuleIdentifier) >>= lProps;
166 for (sal_Int32 i=0; i<lProps.getLength(); ++i)
168 if ( lProps[i].Name == "ooSetupFactoryShortName" )
170 lProps[i].Value >>= sShort;
171 break;
175 catch( const Exception& )
177 sShort.clear();
180 if (sShort.isEmpty())
181 throw NoSuchElementException();
183 pIter->second = css::ui::ModuleUIConfigurationManager::createDefault(m_xContext, sShort, sModuleIdentifier);
186 return pIter->second;
189 struct Instance {
190 explicit Instance(
191 css::uno::Reference<css::uno::XComponentContext> const & context):
192 instance(static_cast<cppu::OWeakObject *>(
193 new ModuleUIConfigurationManagerSupplier(context)))
197 css::uno::Reference<css::uno::XInterface> instance;
200 struct Singleton:
201 public rtl::StaticWithArg<
202 Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
207 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
208 com_sun_star_comp_framework_ModuleUIConfigurationManagerSupplier_get_implementation(
209 css::uno::XComponentContext *context,
210 css::uno::Sequence<css::uno::Any> const &)
212 return cppu::acquire(static_cast<cppu::OWeakObject *>(
213 Singleton::get(context).instance.get()));
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */