1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: toolbarcontrollerfactory.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
37 #include "uifactory/toolbarcontrollerfactory.hxx"
38 #include "uifactory/factoryconfiguration.hxx"
39 #include <threadhelp/resetableguard.hxx>
42 //_________________________________________________________________________________________________________________
44 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/container/XNameAccess.hpp>
48 #include <com/sun/star/container/XNameContainer.hpp>
49 #include <com/sun/star/container/XContainer.hpp>
51 //_________________________________________________________________________________________________________________
52 // includes of other projects
53 //_________________________________________________________________________________________________________________
54 #include <rtl/ustrbuf.hxx>
55 #include <cppuhelper/weak.hxx>
57 //_________________________________________________________________________________________________________________
59 //_________________________________________________________________________________________________________________
62 using namespace com::sun::star::uno
;
63 using namespace com::sun::star::lang
;
64 using namespace com::sun::star::beans
;
65 using namespace com::sun::star::container
;
66 using namespace ::com::sun::star::frame
;
68 //_________________________________________________________________________________________________________________
70 //_________________________________________________________________________________________________________________
76 //*****************************************************************************************************************
77 // XInterface, XTypeProvider, XServiceInfo
78 //*****************************************************************************************************************
79 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( ToolbarControllerFactory
,
81 SERVICENAME_TOOLBARCONTROLLERFACTORY
,
82 IMPLEMENTATIONNAME_TOOLBARCONTROLLERFACTORY
85 DEFINE_INIT_SERVICE ( ToolbarControllerFactory
, {} )
87 ToolbarControllerFactory::ToolbarControllerFactory( const Reference
< XMultiServiceFactory
>& xServiceManager
) :
89 m_bConfigRead( sal_False
),
90 m_xServiceManager( xServiceManager
)
92 m_pConfigAccess
= new ConfigurationAccess_ControllerFactory( m_xServiceManager
,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.Controller/Registered/ToolBar" )) );
93 m_pConfigAccess
->acquire();
96 ToolbarControllerFactory::ToolbarControllerFactory( const Reference
< XMultiServiceFactory
>& xServiceManager
,bool ) :
98 m_bConfigRead( sal_False
),
99 m_xServiceManager( xServiceManager
)
101 m_pConfigAccess
= NULL
;
104 ToolbarControllerFactory::~ToolbarControllerFactory()
106 ResetableGuard
aLock( m_aLock
);
108 // reduce reference count
109 m_pConfigAccess
->release();
112 // XMultiComponentFactory
113 Reference
< XInterface
> SAL_CALL
ToolbarControllerFactory::createInstanceWithContext(
114 const ::rtl::OUString
& aServiceSpecifier
,
115 const Reference
< XComponentContext
>& )
116 throw (Exception
, RuntimeException
)
119 ResetableGuard
aLock( m_aLock
);
121 if ( !m_bConfigRead
)
123 m_bConfigRead
= sal_True
;
124 m_pConfigAccess
->readConfigurationData();
127 rtl::OUString aServiceName
= m_pConfigAccess
->getServiceFromCommandModule( aServiceSpecifier
, rtl::OUString() );
128 if ( aServiceName
.getLength() > 0 )
129 return m_xServiceManager
->createInstance( aServiceName
);
131 return Reference
< XInterface
>();
135 Reference
< XInterface
> SAL_CALL
ToolbarControllerFactory::createInstanceWithArgumentsAndContext(
136 const ::rtl::OUString
& ServiceSpecifier
,
137 const Sequence
< Any
>& Arguments
,
138 const Reference
< XComponentContext
>& )
139 throw (Exception
, RuntimeException
)
141 const rtl::OUString
aPropModuleName( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
142 const rtl::OUString
aPropValueName( RTL_CONSTASCII_USTRINGPARAM( "Value" ));
144 rtl::OUString aPropName
;
145 PropertyValue aPropValue
;
147 // Retrieve the optional module name form the Arguments sequence. It is used as a part of
148 // the hash map key to support different controller implementation for the same URL but different
150 for ( int i
= 0; i
< Arguments
.getLength(); i
++ )
152 if (( Arguments
[i
] >>= aPropValue
) && ( aPropValue
.Name
.equals( aPropModuleName
)))
154 aPropValue
.Value
>>= aPropName
;
159 Sequence
< Any
> aNewArgs( Arguments
);
161 sal_Int32 nAppendIndex
= aNewArgs
.getLength();
162 bool bHasValue
= m_pConfigAccess
->hasValue();
163 aNewArgs
.realloc( aNewArgs
.getLength() + (bHasValue
? 2 : 1) );
165 // Append the command URL to the Arguments sequence so that one controller can be
166 // used for more than one command URL.
167 aPropValue
.Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
168 aPropValue
.Value
<<= ServiceSpecifier
;
169 aNewArgs
[nAppendIndex
] <<= aPropValue
;
173 // Append the optional value argument. It's an empty string if no additional info
174 // is provided to the controller.
175 rtl::OUString aValue
= m_pConfigAccess
->getValueFromCommandModule( ServiceSpecifier
, aPropName
);
176 aPropValue
.Name
= aPropValueName
;
177 aPropValue
.Value
<<= aValue
;
178 aNewArgs
[nAppendIndex
+1] <<= aPropValue
;
183 ResetableGuard
aLock( m_aLock
);
185 if ( !m_bConfigRead
)
187 m_bConfigRead
= sal_True
;
188 m_pConfigAccess
->readConfigurationData();
191 rtl::OUString aServiceName
= m_pConfigAccess
->getServiceFromCommandModule( ServiceSpecifier
, aPropName
);
192 Reference
< XMultiServiceFactory
> xServiceManager( m_xServiceManager
);
198 if ( aServiceName
.getLength() > 0 )
199 return xServiceManager
->createInstanceWithArguments( aServiceName
, aNewArgs
);
201 return Reference
< XInterface
>();
205 Sequence
< ::rtl::OUString
> SAL_CALL
ToolbarControllerFactory::getAvailableServiceNames()
206 throw (RuntimeException
)
208 return Sequence
< ::rtl::OUString
>();
211 // XUIControllerRegistration
212 sal_Bool SAL_CALL
ToolbarControllerFactory::hasController(
213 const ::rtl::OUString
& aCommandURL
,
214 const rtl::OUString
& aModuleName
)
215 throw (::com::sun::star::uno::RuntimeException
)
217 ResetableGuard
aLock( m_aLock
);
219 if ( !m_bConfigRead
)
221 m_bConfigRead
= sal_True
;
222 m_pConfigAccess
->readConfigurationData();
225 return ( m_pConfigAccess
->getServiceFromCommandModule( aCommandURL
, aModuleName
).getLength() > 0 );
228 void SAL_CALL
ToolbarControllerFactory::registerController(
229 const ::rtl::OUString
& aCommandURL
,
230 const ::rtl::OUString
& aModuleName
,
231 const ::rtl::OUString
& aControllerImplementationName
)
232 throw (RuntimeException
)
235 ResetableGuard
aLock( m_aLock
);
237 if ( !m_bConfigRead
)
239 m_bConfigRead
= sal_True
;
240 m_pConfigAccess
->readConfigurationData();
243 m_pConfigAccess
->addServiceToCommandModule( aCommandURL
, aModuleName
, aControllerImplementationName
);
247 void SAL_CALL
ToolbarControllerFactory::deregisterController(
248 const ::rtl::OUString
& aCommandURL
,
249 const rtl::OUString
& aModuleName
)
250 throw (RuntimeException
)
253 ResetableGuard
aLock( m_aLock
);
255 if ( !m_bConfigRead
)
257 m_bConfigRead
= sal_True
;
258 m_pConfigAccess
->readConfigurationData();
261 m_pConfigAccess
->removeServiceFromCommandModule( aCommandURL
, aModuleName
);
265 } // namespace framework