merged tag ooo/OOO330_m14
[LibreOffice.git] / framework / source / uifactory / toolbarcontrollerfactory.cxx
blob1905375f7022b7fdb8add53bd3c2a3c064a54c49
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 //_________________________________________________________________________________________________________________
32 // my own includes
33 //_________________________________________________________________________________________________________________
34 #include "uifactory/toolbarcontrollerfactory.hxx"
35 #include "uifactory/factoryconfiguration.hxx"
36 #include <threadhelp/resetableguard.hxx>
37 #include "services.h"
39 //_________________________________________________________________________________________________________________
40 // interface includes
41 //_________________________________________________________________________________________________________________
42 #include <com/sun/star/beans/PropertyValue.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/container/XNameAccess.hpp>
45 #include <com/sun/star/container/XNameContainer.hpp>
46 #include <com/sun/star/container/XContainer.hpp>
48 //_________________________________________________________________________________________________________________
49 // includes of other projects
50 //_________________________________________________________________________________________________________________
51 #include <rtl/ustrbuf.hxx>
52 #include <cppuhelper/weak.hxx>
54 //_________________________________________________________________________________________________________________
55 // Defines
56 //_________________________________________________________________________________________________________________
59 using namespace com::sun::star::uno;
60 using namespace com::sun::star::lang;
61 using namespace com::sun::star::beans;
62 using namespace com::sun::star::container;
63 using namespace ::com::sun::star::frame;
65 //_________________________________________________________________________________________________________________
66 // Namespace
67 //_________________________________________________________________________________________________________________
70 namespace framework
73 //*****************************************************************************************************************
74 // XInterface, XTypeProvider, XServiceInfo
75 //*****************************************************************************************************************
76 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( ToolbarControllerFactory ,
77 ::cppu::OWeakObject ,
78 SERVICENAME_TOOLBARCONTROLLERFACTORY ,
79 IMPLEMENTATIONNAME_TOOLBARCONTROLLERFACTORY
82 DEFINE_INIT_SERVICE ( ToolbarControllerFactory, {} )
84 ToolbarControllerFactory::ToolbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager ) :
85 ThreadHelpBase(),
86 m_bConfigRead( sal_False ),
87 m_xServiceManager( xServiceManager )
89 m_pConfigAccess = new ConfigurationAccess_ControllerFactory( m_xServiceManager,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Controller/Registered/ToolBar" )) );
90 m_pConfigAccess->acquire();
93 ToolbarControllerFactory::ToolbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager,bool ) :
94 ThreadHelpBase(),
95 m_bConfigRead( sal_False ),
96 m_xServiceManager( xServiceManager )
98 m_pConfigAccess = NULL;
101 ToolbarControllerFactory::~ToolbarControllerFactory()
103 ResetableGuard aLock( m_aLock );
105 // reduce reference count
106 m_pConfigAccess->release();
109 // XMultiComponentFactory
110 Reference< XInterface > SAL_CALL ToolbarControllerFactory::createInstanceWithContext(
111 const ::rtl::OUString& aServiceSpecifier,
112 const Reference< XComponentContext >& )
113 throw (Exception, RuntimeException)
115 // SAFE
116 ResetableGuard aLock( m_aLock );
118 if ( !m_bConfigRead )
120 m_bConfigRead = sal_True;
121 m_pConfigAccess->readConfigurationData();
124 rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( aServiceSpecifier, rtl::OUString() );
125 if ( aServiceName.getLength() > 0 )
126 return m_xServiceManager->createInstance( aServiceName );
127 else
128 return Reference< XInterface >();
129 // SAFE
132 Reference< XInterface > SAL_CALL ToolbarControllerFactory::createInstanceWithArgumentsAndContext(
133 const ::rtl::OUString& ServiceSpecifier,
134 const Sequence< Any >& Arguments,
135 const Reference< XComponentContext >& )
136 throw (Exception, RuntimeException)
138 const rtl::OUString aPropModuleName( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
139 const rtl::OUString aPropValueName( RTL_CONSTASCII_USTRINGPARAM( "Value" ));
141 rtl::OUString aPropName;
142 PropertyValue aPropValue;
144 // Retrieve the optional module name form the Arguments sequence. It is used as a part of
145 // the hash map key to support different controller implementation for the same URL but different
146 // module!!
147 for ( int i = 0; i < Arguments.getLength(); i++ )
149 if (( Arguments[i] >>= aPropValue ) && ( aPropValue.Name.equals( aPropModuleName )))
151 aPropValue.Value >>= aPropName;
152 break;
156 Sequence< Any > aNewArgs( Arguments );
158 sal_Int32 nAppendIndex = aNewArgs.getLength();
159 bool bHasValue = m_pConfigAccess->hasValue();
160 aNewArgs.realloc( aNewArgs.getLength() + (bHasValue ? 2 : 1) );
162 // Append the command URL to the Arguments sequence so that one controller can be
163 // used for more than one command URL.
164 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
165 aPropValue.Value <<= ServiceSpecifier;
166 aNewArgs[nAppendIndex] <<= aPropValue;
168 if ( bHasValue )
170 // Append the optional value argument. It's an empty string if no additional info
171 // is provided to the controller.
172 rtl::OUString aValue = m_pConfigAccess->getValueFromCommandModule( ServiceSpecifier, aPropName );
173 aPropValue.Name = aPropValueName;
174 aPropValue.Value <<= aValue;
175 aNewArgs[nAppendIndex+1] <<= aPropValue;
179 // SAFE
180 ResetableGuard aLock( m_aLock );
182 if ( !m_bConfigRead )
184 m_bConfigRead = sal_True;
185 m_pConfigAccess->readConfigurationData();
188 rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( ServiceSpecifier, aPropName );
189 Reference< XMultiServiceFactory > xServiceManager( m_xServiceManager );
191 aLock.unlock();
192 // SAFE
195 if ( aServiceName.getLength() > 0 )
196 return xServiceManager->createInstanceWithArguments( aServiceName, aNewArgs );
197 else
198 return Reference< XInterface >();
202 Sequence< ::rtl::OUString > SAL_CALL ToolbarControllerFactory::getAvailableServiceNames()
203 throw (RuntimeException)
205 return Sequence< ::rtl::OUString >();
208 // XUIControllerRegistration
209 sal_Bool SAL_CALL ToolbarControllerFactory::hasController(
210 const ::rtl::OUString& aCommandURL,
211 const rtl::OUString& aModuleName )
212 throw (::com::sun::star::uno::RuntimeException)
214 ResetableGuard aLock( m_aLock );
216 if ( !m_bConfigRead )
218 m_bConfigRead = sal_True;
219 m_pConfigAccess->readConfigurationData();
222 return ( m_pConfigAccess->getServiceFromCommandModule( aCommandURL, aModuleName ).getLength() > 0 );
225 void SAL_CALL ToolbarControllerFactory::registerController(
226 const ::rtl::OUString& aCommandURL,
227 const ::rtl::OUString& aModuleName,
228 const ::rtl::OUString& aControllerImplementationName )
229 throw (RuntimeException)
231 // SAFE
232 ResetableGuard aLock( m_aLock );
234 if ( !m_bConfigRead )
236 m_bConfigRead = sal_True;
237 m_pConfigAccess->readConfigurationData();
240 m_pConfigAccess->addServiceToCommandModule( aCommandURL, aModuleName, aControllerImplementationName );
241 // SAFE
244 void SAL_CALL ToolbarControllerFactory::deregisterController(
245 const ::rtl::OUString& aCommandURL,
246 const rtl::OUString& aModuleName )
247 throw (RuntimeException)
249 // SAFE
250 ResetableGuard aLock( m_aLock );
252 if ( !m_bConfigRead )
254 m_bConfigRead = sal_True;
255 m_pConfigAccess->readConfigurationData();
258 m_pConfigAccess->removeServiceFromCommandModule( aCommandURL, aModuleName );
259 // SAFE
262 } // namespace framework