xref: /AOO41X/main/framework/source/uifactory/uicontrollerfactory.cxx (revision cbe4a5e32dd06077057875dd5ecd4d8f1991662a)
1*dccf82beSAriel Constenla-Haile /**************************************************************
2*dccf82beSAriel Constenla-Haile  *
3*dccf82beSAriel Constenla-Haile  * Licensed to the Apache Software Foundation (ASF) under one
4*dccf82beSAriel Constenla-Haile  * or more contributor license agreements.  See the NOTICE file
5*dccf82beSAriel Constenla-Haile  * distributed with this work for additional information
6*dccf82beSAriel Constenla-Haile  * regarding copyright ownership.  The ASF licenses this file
7*dccf82beSAriel Constenla-Haile  * to you under the Apache License, Version 2.0 (the
8*dccf82beSAriel Constenla-Haile  * "License"); you may not use this file except in compliance
9*dccf82beSAriel Constenla-Haile  * with the License.  You may obtain a copy of the License at
10*dccf82beSAriel Constenla-Haile  *
11*dccf82beSAriel Constenla-Haile  *   http://www.apache.org/licenses/LICENSE-2.0
12*dccf82beSAriel Constenla-Haile  *
13*dccf82beSAriel Constenla-Haile  * Unless required by applicable law or agreed to in writing,
14*dccf82beSAriel Constenla-Haile  * software distributed under the License is distributed on an
15*dccf82beSAriel Constenla-Haile  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*dccf82beSAriel Constenla-Haile  * KIND, either express or implied.  See the License for the
17*dccf82beSAriel Constenla-Haile  * specific language governing permissions and limitations
18*dccf82beSAriel Constenla-Haile  * under the License.
19*dccf82beSAriel Constenla-Haile  *
20*dccf82beSAriel Constenla-Haile  *************************************************************/
21*dccf82beSAriel Constenla-Haile 
22*dccf82beSAriel Constenla-Haile 
23*dccf82beSAriel Constenla-Haile 
24*dccf82beSAriel Constenla-Haile // MARKER(update_precomp.py): autogen include statement, do not remove
25*dccf82beSAriel Constenla-Haile #include "precompiled_framework.hxx"
26*dccf82beSAriel Constenla-Haile 
27*dccf82beSAriel Constenla-Haile #include <uifactory/uicontrollerfactory.hxx>
28*dccf82beSAriel Constenla-Haile #include <uifactory/factoryconfiguration.hxx>
29*dccf82beSAriel Constenla-Haile #include <threadhelp/resetableguard.hxx>
30*dccf82beSAriel Constenla-Haile #include "services.h"
31*dccf82beSAriel Constenla-Haile 
32*dccf82beSAriel Constenla-Haile #include <com/sun/star/beans/PropertyValue.hpp>
33*dccf82beSAriel Constenla-Haile #include <com/sun/star/beans/XPropertySet.hpp>
34*dccf82beSAriel Constenla-Haile #include <com/sun/star/container/XNameAccess.hpp>
35*dccf82beSAriel Constenla-Haile #include <com/sun/star/container/XNameContainer.hpp>
36*dccf82beSAriel Constenla-Haile #include <com/sun/star/container/XContainer.hpp>
37*dccf82beSAriel Constenla-Haile 
38*dccf82beSAriel Constenla-Haile #include <rtl/ustrbuf.hxx>
39*dccf82beSAriel Constenla-Haile #include <cppuhelper/weak.hxx>
40*dccf82beSAriel Constenla-Haile 
41*dccf82beSAriel Constenla-Haile using namespace com::sun::star::uno;
42*dccf82beSAriel Constenla-Haile using namespace com::sun::star::lang;
43*dccf82beSAriel Constenla-Haile using namespace com::sun::star::beans;
44*dccf82beSAriel Constenla-Haile using namespace com::sun::star::container;
45*dccf82beSAriel Constenla-Haile using namespace ::com::sun::star::frame;
46*dccf82beSAriel Constenla-Haile 
47*dccf82beSAriel Constenla-Haile namespace framework
48*dccf82beSAriel Constenla-Haile {
49*dccf82beSAriel Constenla-Haile 
UIControllerFactory(const Reference<XMultiServiceFactory> & xServiceManager,const rtl::OUString & rConfigurationNode)50*dccf82beSAriel Constenla-Haile UIControllerFactory::UIControllerFactory(
51*dccf82beSAriel Constenla-Haile     const Reference< XMultiServiceFactory >& xServiceManager,
52*dccf82beSAriel Constenla-Haile     const rtl::OUString &rConfigurationNode )
53*dccf82beSAriel Constenla-Haile     : ThreadHelpBase()
54*dccf82beSAriel Constenla-Haile     , m_bConfigRead( sal_False )
55*dccf82beSAriel Constenla-Haile     , m_xServiceManager( xServiceManager )
56*dccf82beSAriel Constenla-Haile     , m_pConfigAccess()
57*dccf82beSAriel Constenla-Haile {
58*dccf82beSAriel Constenla-Haile     rtl::OUStringBuffer aBuffer;
59*dccf82beSAriel Constenla-Haile     aBuffer.appendAscii(
60*dccf82beSAriel Constenla-Haile         RTL_CONSTASCII_STRINGPARAM(
61*dccf82beSAriel Constenla-Haile             "/org.openoffice.Office.UI.Controller/Registered/" ) );
62*dccf82beSAriel Constenla-Haile     aBuffer.append( rConfigurationNode );
63*dccf82beSAriel Constenla-Haile     m_pConfigAccess = new ConfigurationAccess_ControllerFactory(
64*dccf82beSAriel Constenla-Haile         m_xServiceManager, aBuffer.makeStringAndClear() );
65*dccf82beSAriel Constenla-Haile     m_pConfigAccess->acquire();
66*dccf82beSAriel Constenla-Haile }
67*dccf82beSAriel Constenla-Haile 
~UIControllerFactory()68*dccf82beSAriel Constenla-Haile UIControllerFactory::~UIControllerFactory()
69*dccf82beSAriel Constenla-Haile {
70*dccf82beSAriel Constenla-Haile     ResetableGuard aLock( m_aLock );
71*dccf82beSAriel Constenla-Haile 
72*dccf82beSAriel Constenla-Haile     // reduce reference count
73*dccf82beSAriel Constenla-Haile     m_pConfigAccess->release();
74*dccf82beSAriel Constenla-Haile }
75*dccf82beSAriel Constenla-Haile 
76*dccf82beSAriel Constenla-Haile // XMultiComponentFactory
createInstanceWithContext(const::rtl::OUString & aServiceSpecifier,const Reference<XComponentContext> &)77*dccf82beSAriel Constenla-Haile Reference< XInterface > SAL_CALL UIControllerFactory::createInstanceWithContext(
78*dccf82beSAriel Constenla-Haile     const ::rtl::OUString& aServiceSpecifier,
79*dccf82beSAriel Constenla-Haile     const Reference< XComponentContext >& )
80*dccf82beSAriel Constenla-Haile throw (Exception, RuntimeException)
81*dccf82beSAriel Constenla-Haile {
82*dccf82beSAriel Constenla-Haile     // SAFE
83*dccf82beSAriel Constenla-Haile     ResetableGuard aLock( m_aLock );
84*dccf82beSAriel Constenla-Haile 
85*dccf82beSAriel Constenla-Haile     if ( !m_bConfigRead )
86*dccf82beSAriel Constenla-Haile     {
87*dccf82beSAriel Constenla-Haile         m_bConfigRead = sal_True;
88*dccf82beSAriel Constenla-Haile         m_pConfigAccess->readConfigurationData();
89*dccf82beSAriel Constenla-Haile     }
90*dccf82beSAriel Constenla-Haile 
91*dccf82beSAriel Constenla-Haile     rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( aServiceSpecifier, rtl::OUString() );
92*dccf82beSAriel Constenla-Haile     if ( aServiceName.getLength() > 0 )
93*dccf82beSAriel Constenla-Haile         return m_xServiceManager->createInstance( aServiceName );
94*dccf82beSAriel Constenla-Haile     else
95*dccf82beSAriel Constenla-Haile         return Reference< XInterface >();
96*dccf82beSAriel Constenla-Haile     // SAFE
97*dccf82beSAriel Constenla-Haile }
98*dccf82beSAriel Constenla-Haile 
createInstanceWithArgumentsAndContext(const::rtl::OUString & ServiceSpecifier,const Sequence<Any> & Arguments,const Reference<XComponentContext> &)99*dccf82beSAriel Constenla-Haile Reference< XInterface > SAL_CALL UIControllerFactory::createInstanceWithArgumentsAndContext(
100*dccf82beSAriel Constenla-Haile     const ::rtl::OUString&                  ServiceSpecifier,
101*dccf82beSAriel Constenla-Haile     const Sequence< Any >&                  Arguments,
102*dccf82beSAriel Constenla-Haile     const Reference< XComponentContext >& )
103*dccf82beSAriel Constenla-Haile throw (Exception, RuntimeException)
104*dccf82beSAriel Constenla-Haile {
105*dccf82beSAriel Constenla-Haile     const rtl::OUString aPropModuleName( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ));
106*dccf82beSAriel Constenla-Haile     const rtl::OUString aPropValueName( RTL_CONSTASCII_USTRINGPARAM( "Value" ));
107*dccf82beSAriel Constenla-Haile 
108*dccf82beSAriel Constenla-Haile     rtl::OUString   aPropName;
109*dccf82beSAriel Constenla-Haile     PropertyValue   aPropValue;
110*dccf82beSAriel Constenla-Haile 
111*dccf82beSAriel Constenla-Haile     // Retrieve the optional module name form the Arguments sequence. It is used as a part of
112*dccf82beSAriel Constenla-Haile     // the hash map key to support different controller implementation for the same URL but different
113*dccf82beSAriel Constenla-Haile     // module!!
114*dccf82beSAriel Constenla-Haile     for ( int i = 0; i < Arguments.getLength(); i++ )
115*dccf82beSAriel Constenla-Haile     {
116*dccf82beSAriel Constenla-Haile         if (( Arguments[i] >>= aPropValue ) && ( aPropValue.Name.equals( aPropModuleName )))
117*dccf82beSAriel Constenla-Haile         {
118*dccf82beSAriel Constenla-Haile             aPropValue.Value >>= aPropName;
119*dccf82beSAriel Constenla-Haile             break;
120*dccf82beSAriel Constenla-Haile         }
121*dccf82beSAriel Constenla-Haile     }
122*dccf82beSAriel Constenla-Haile 
123*dccf82beSAriel Constenla-Haile     Sequence< Any > aNewArgs( Arguments );
124*dccf82beSAriel Constenla-Haile 
125*dccf82beSAriel Constenla-Haile     sal_Int32 nAppendIndex = aNewArgs.getLength();
126*dccf82beSAriel Constenla-Haile     bool bHasValue = m_pConfigAccess->hasValue();
127*dccf82beSAriel Constenla-Haile     aNewArgs.realloc( aNewArgs.getLength() + (bHasValue ? 2 : 1) );
128*dccf82beSAriel Constenla-Haile 
129*dccf82beSAriel Constenla-Haile     // Append the command URL to the Arguments sequence so that one controller can be
130*dccf82beSAriel Constenla-Haile     // used for more than one command URL.
131*dccf82beSAriel Constenla-Haile     aPropValue.Name     = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
132*dccf82beSAriel Constenla-Haile     aPropValue.Value  <<= ServiceSpecifier;
133*dccf82beSAriel Constenla-Haile     aNewArgs[nAppendIndex] <<= aPropValue;
134*dccf82beSAriel Constenla-Haile 
135*dccf82beSAriel Constenla-Haile     if ( bHasValue )
136*dccf82beSAriel Constenla-Haile     {
137*dccf82beSAriel Constenla-Haile         // Append the optional value argument. It's an empty string if no additional info
138*dccf82beSAriel Constenla-Haile         // is provided to the controller.
139*dccf82beSAriel Constenla-Haile         rtl::OUString aValue = m_pConfigAccess->getValueFromCommandModule( ServiceSpecifier, aPropName );
140*dccf82beSAriel Constenla-Haile         aPropValue.Name = aPropValueName;
141*dccf82beSAriel Constenla-Haile         aPropValue.Value <<= aValue;
142*dccf82beSAriel Constenla-Haile         aNewArgs[nAppendIndex+1] <<= aPropValue;
143*dccf82beSAriel Constenla-Haile     }
144*dccf82beSAriel Constenla-Haile 
145*dccf82beSAriel Constenla-Haile     {
146*dccf82beSAriel Constenla-Haile         // SAFE
147*dccf82beSAriel Constenla-Haile         ResetableGuard aLock( m_aLock );
148*dccf82beSAriel Constenla-Haile 
149*dccf82beSAriel Constenla-Haile         if ( !m_bConfigRead )
150*dccf82beSAriel Constenla-Haile         {
151*dccf82beSAriel Constenla-Haile             m_bConfigRead = sal_True;
152*dccf82beSAriel Constenla-Haile             m_pConfigAccess->readConfigurationData();
153*dccf82beSAriel Constenla-Haile         }
154*dccf82beSAriel Constenla-Haile 
155*dccf82beSAriel Constenla-Haile         rtl::OUString aServiceName = m_pConfigAccess->getServiceFromCommandModule( ServiceSpecifier, aPropName );
156*dccf82beSAriel Constenla-Haile         Reference< XMultiServiceFactory > xServiceManager( m_xServiceManager );
157*dccf82beSAriel Constenla-Haile 
158*dccf82beSAriel Constenla-Haile         aLock.unlock();
159*dccf82beSAriel Constenla-Haile         // SAFE
160*dccf82beSAriel Constenla-Haile 
161*dccf82beSAriel Constenla-Haile         if ( aServiceName.getLength() > 0 )
162*dccf82beSAriel Constenla-Haile             return xServiceManager->createInstanceWithArguments( aServiceName, aNewArgs );
163*dccf82beSAriel Constenla-Haile         else
164*dccf82beSAriel Constenla-Haile             return Reference< XInterface >();
165*dccf82beSAriel Constenla-Haile     }
166*dccf82beSAriel Constenla-Haile }
167*dccf82beSAriel Constenla-Haile 
getAvailableServiceNames()168*dccf82beSAriel Constenla-Haile Sequence< ::rtl::OUString > SAL_CALL UIControllerFactory::getAvailableServiceNames()
169*dccf82beSAriel Constenla-Haile throw (RuntimeException)
170*dccf82beSAriel Constenla-Haile {
171*dccf82beSAriel Constenla-Haile     return Sequence< ::rtl::OUString >();
172*dccf82beSAriel Constenla-Haile }
173*dccf82beSAriel Constenla-Haile 
174*dccf82beSAriel Constenla-Haile // XUIControllerRegistration
hasController(const::rtl::OUString & aCommandURL,const rtl::OUString & aModuleName)175*dccf82beSAriel Constenla-Haile sal_Bool SAL_CALL UIControllerFactory::hasController(
176*dccf82beSAriel Constenla-Haile     const ::rtl::OUString& aCommandURL,
177*dccf82beSAriel Constenla-Haile     const rtl::OUString& aModuleName )
178*dccf82beSAriel Constenla-Haile throw (::com::sun::star::uno::RuntimeException)
179*dccf82beSAriel Constenla-Haile {
180*dccf82beSAriel Constenla-Haile     ResetableGuard aLock( m_aLock );
181*dccf82beSAriel Constenla-Haile 
182*dccf82beSAriel Constenla-Haile     if ( !m_bConfigRead )
183*dccf82beSAriel Constenla-Haile     {
184*dccf82beSAriel Constenla-Haile         m_bConfigRead = sal_True;
185*dccf82beSAriel Constenla-Haile         m_pConfigAccess->readConfigurationData();
186*dccf82beSAriel Constenla-Haile     }
187*dccf82beSAriel Constenla-Haile 
188*dccf82beSAriel Constenla-Haile     return ( m_pConfigAccess->getServiceFromCommandModule( aCommandURL, aModuleName ).getLength() > 0 );
189*dccf82beSAriel Constenla-Haile }
190*dccf82beSAriel Constenla-Haile 
registerController(const::rtl::OUString & aCommandURL,const::rtl::OUString & aModuleName,const::rtl::OUString & aControllerImplementationName)191*dccf82beSAriel Constenla-Haile void SAL_CALL UIControllerFactory::registerController(
192*dccf82beSAriel Constenla-Haile     const ::rtl::OUString& aCommandURL,
193*dccf82beSAriel Constenla-Haile     const ::rtl::OUString& aModuleName,
194*dccf82beSAriel Constenla-Haile     const ::rtl::OUString& aControllerImplementationName )
195*dccf82beSAriel Constenla-Haile throw (RuntimeException)
196*dccf82beSAriel Constenla-Haile {
197*dccf82beSAriel Constenla-Haile     // SAFE
198*dccf82beSAriel Constenla-Haile     ResetableGuard aLock( m_aLock );
199*dccf82beSAriel Constenla-Haile 
200*dccf82beSAriel Constenla-Haile     if ( !m_bConfigRead )
201*dccf82beSAriel Constenla-Haile     {
202*dccf82beSAriel Constenla-Haile         m_bConfigRead = sal_True;
203*dccf82beSAriel Constenla-Haile         m_pConfigAccess->readConfigurationData();
204*dccf82beSAriel Constenla-Haile     }
205*dccf82beSAriel Constenla-Haile 
206*dccf82beSAriel Constenla-Haile     m_pConfigAccess->addServiceToCommandModule( aCommandURL, aModuleName, aControllerImplementationName );
207*dccf82beSAriel Constenla-Haile     // SAFE
208*dccf82beSAriel Constenla-Haile }
209*dccf82beSAriel Constenla-Haile 
deregisterController(const::rtl::OUString & aCommandURL,const rtl::OUString & aModuleName)210*dccf82beSAriel Constenla-Haile void SAL_CALL UIControllerFactory::deregisterController(
211*dccf82beSAriel Constenla-Haile     const ::rtl::OUString& aCommandURL,
212*dccf82beSAriel Constenla-Haile     const rtl::OUString& aModuleName )
213*dccf82beSAriel Constenla-Haile throw (RuntimeException)
214*dccf82beSAriel Constenla-Haile {
215*dccf82beSAriel Constenla-Haile     // SAFE
216*dccf82beSAriel Constenla-Haile     ResetableGuard aLock( m_aLock );
217*dccf82beSAriel Constenla-Haile 
218*dccf82beSAriel Constenla-Haile     if ( !m_bConfigRead )
219*dccf82beSAriel Constenla-Haile     {
220*dccf82beSAriel Constenla-Haile         m_bConfigRead = sal_True;
221*dccf82beSAriel Constenla-Haile         m_pConfigAccess->readConfigurationData();
222*dccf82beSAriel Constenla-Haile     }
223*dccf82beSAriel Constenla-Haile 
224*dccf82beSAriel Constenla-Haile     m_pConfigAccess->removeServiceFromCommandModule( aCommandURL, aModuleName );
225*dccf82beSAriel Constenla-Haile     // SAFE
226*dccf82beSAriel Constenla-Haile }
227*dccf82beSAriel Constenla-Haile 
228*dccf82beSAriel Constenla-Haile 
DEFINE_XSERVICEINFO_ONEINSTANCESERVICE(PopupMenuControllerFactory,::cppu::OWeakObject,SERVICENAME_POPUPMENUCONTROLLERFACTORY,IMPLEMENTATIONNAME_POPUPMENUCONTROLLERFACTORY)229*dccf82beSAriel Constenla-Haile DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   PopupMenuControllerFactory                      ,
230*dccf82beSAriel Constenla-Haile                                             ::cppu::OWeakObject                             ,
231*dccf82beSAriel Constenla-Haile                                             SERVICENAME_POPUPMENUCONTROLLERFACTORY          ,
232*dccf82beSAriel Constenla-Haile                                             IMPLEMENTATIONNAME_POPUPMENUCONTROLLERFACTORY
233*dccf82beSAriel Constenla-Haile                                         )
234*dccf82beSAriel Constenla-Haile 
235*dccf82beSAriel Constenla-Haile DEFINE_INIT_SERVICE                     (   PopupMenuControllerFactory, {} )
236*dccf82beSAriel Constenla-Haile 
237*dccf82beSAriel Constenla-Haile PopupMenuControllerFactory::PopupMenuControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager ) :
238*dccf82beSAriel Constenla-Haile     UIControllerFactory(
239*dccf82beSAriel Constenla-Haile         xServiceManager,
240*dccf82beSAriel Constenla-Haile         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PopupMenu" )) )
241*dccf82beSAriel Constenla-Haile {
242*dccf82beSAriel Constenla-Haile }
243*dccf82beSAriel Constenla-Haile 
DEFINE_XSERVICEINFO_ONEINSTANCESERVICE(ToolbarControllerFactory,::cppu::OWeakObject,SERVICENAME_TOOLBARCONTROLLERFACTORY,IMPLEMENTATIONNAME_TOOLBARCONTROLLERFACTORY)244*dccf82beSAriel Constenla-Haile DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   ToolbarControllerFactory                     ,
245*dccf82beSAriel Constenla-Haile                                             ::cppu::OWeakObject                             ,
246*dccf82beSAriel Constenla-Haile                                             SERVICENAME_TOOLBARCONTROLLERFACTORY            ,
247*dccf82beSAriel Constenla-Haile                                             IMPLEMENTATIONNAME_TOOLBARCONTROLLERFACTORY
248*dccf82beSAriel Constenla-Haile                                         )
249*dccf82beSAriel Constenla-Haile 
250*dccf82beSAriel Constenla-Haile DEFINE_INIT_SERVICE                     (   ToolbarControllerFactory, {} )
251*dccf82beSAriel Constenla-Haile 
252*dccf82beSAriel Constenla-Haile ToolbarControllerFactory::ToolbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager ) :
253*dccf82beSAriel Constenla-Haile     UIControllerFactory(
254*dccf82beSAriel Constenla-Haile         xServiceManager,
255*dccf82beSAriel Constenla-Haile         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ToolBar" )))
256*dccf82beSAriel Constenla-Haile {
257*dccf82beSAriel Constenla-Haile }
258*dccf82beSAriel Constenla-Haile 
DEFINE_XSERVICEINFO_ONEINSTANCESERVICE(StatusbarControllerFactory,::cppu::OWeakObject,SERVICENAME_STATUSBARCONTROLLERFACTORY,IMPLEMENTATIONNAME_STATUSBARCONTROLLERFACTORY)259*dccf82beSAriel Constenla-Haile DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   StatusbarControllerFactory                      ,
260*dccf82beSAriel Constenla-Haile                                             ::cppu::OWeakObject                             ,
261*dccf82beSAriel Constenla-Haile                                             SERVICENAME_STATUSBARCONTROLLERFACTORY          ,
262*dccf82beSAriel Constenla-Haile                                             IMPLEMENTATIONNAME_STATUSBARCONTROLLERFACTORY
263*dccf82beSAriel Constenla-Haile                                         )
264*dccf82beSAriel Constenla-Haile 
265*dccf82beSAriel Constenla-Haile DEFINE_INIT_SERVICE                     (   StatusbarControllerFactory, {} )
266*dccf82beSAriel Constenla-Haile 
267*dccf82beSAriel Constenla-Haile StatusbarControllerFactory::StatusbarControllerFactory( const Reference< XMultiServiceFactory >& xServiceManager ) :
268*dccf82beSAriel Constenla-Haile     UIControllerFactory(
269*dccf82beSAriel Constenla-Haile         xServiceManager,
270*dccf82beSAriel Constenla-Haile         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StatusBar" )) )
271*dccf82beSAriel Constenla-Haile {
272*dccf82beSAriel Constenla-Haile }
273*dccf82beSAriel Constenla-Haile 
274*dccf82beSAriel Constenla-Haile } // namespace framework
275