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: uielementfactorymanager.cxx,v $
10 * $Revision: 1.10.12.1 $
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/windowcontentfactorymanager.hxx>
38 #include <uifactory/uielementfactorymanager.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>
50 #include <com/sun/star/frame/XFrame.hpp>
51 #include <com/sun/star/awt/XToolkit.hpp>
52 #include <com/sun/star/awt/XControlModel.hpp>
53 #include <com/sun/star/awt/XControl.hpp>
55 //_________________________________________________________________________________________________________________
56 // includes of other projects
57 //_________________________________________________________________________________________________________________
58 #include <rtl/ustrbuf.hxx>
59 #include <cppuhelper/weak.hxx>
60 #include <tools/urlobj.hxx>
61 #include <vcl/svapp.hxx>
63 //_________________________________________________________________________________________________________________
65 //_________________________________________________________________________________________________________________
68 using namespace ::com::sun::star
;
70 //_________________________________________________________________________________________________________________
72 //_________________________________________________________________________________________________________________
78 //*****************************************************************************************************************
79 // XInterface, XTypeProvider, XServiceInfo
80 //*****************************************************************************************************************
81 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( WindowContentFactoryManager
,
83 SERVICENAME_WINDOWCONTENTFACTORYMANAGER
,
84 IMPLEMENTATIONNAME_WINDOWCONTENTFACTORYMANAGER
87 DEFINE_INIT_SERVICE ( WindowContentFactoryManager
, {} )
89 WindowContentFactoryManager::WindowContentFactoryManager( const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
) :
90 ThreadHelpBase( &Application::GetSolarMutex() ),
91 m_bConfigRead( sal_False
),
92 m_xServiceManager( xServiceManager
)
94 m_pConfigAccess
= new ConfigurationAccess_FactoryManager( m_xServiceManager
,rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.UI.WindowContentFactories/Registered/ContentFactories" )) );
95 m_pConfigAccess
->acquire();
96 m_xModuleManager
= uno::Reference
< frame::XModuleManager
>( m_xServiceManager
->createInstance( SERVICENAME_MODULEMANAGER
), uno::UNO_QUERY
);
99 WindowContentFactoryManager::~WindowContentFactoryManager()
101 ResetableGuard
aLock( m_aLock
);
103 // reduce reference count
104 m_pConfigAccess
->release();
107 void WindowContentFactoryManager::RetrieveTypeNameFromResourceURL( const rtl::OUString
& aResourceURL
, rtl::OUString
& aType
, rtl::OUString
& aName
)
109 const sal_Int32 RESOURCEURL_PREFIX_SIZE
= 17;
110 const char RESOURCEURL_PREFIX
[] = "private:resource/";
112 if (( aResourceURL
.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_PREFIX
))) == 0 ) &&
113 ( aResourceURL
.getLength() > RESOURCEURL_PREFIX_SIZE
))
115 rtl::OUString
aTmpStr( aResourceURL
.copy( RESOURCEURL_PREFIX_SIZE
));
116 sal_Int32 nToken
= 0;
120 ::rtl::OUString sToken
= aTmpStr
.getToken( 0, '/', nToken
);
121 if ( sToken
.getLength() )
125 else if ( nPart
== 1 )
136 // XSingleComponentFactory
137 uno::Reference
< uno::XInterface
> SAL_CALL
WindowContentFactoryManager::createInstanceWithContext(
138 const uno::Reference
< uno::XComponentContext
>& /*xContext*/ )
139 throw (uno::Exception
, uno::RuntimeException
)
142 // Currently this method cannot be implemented for generic use. There is no way for external
143 code to get a handle to the dialog model.
145 uno::Reference< lang::XMultiServiceFactory > xServiceManager( xContext->getServiceManager(), uno::UNO_QUERY );
147 const ::rtl::OUString sToolkitService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.Toolkit"));
148 uno::Reference< awt::XToolkit > xToolkit( xServiceManager->createInstance( sToolkitService ), uno::UNO_QUERY_THROW );
150 const ::rtl::OUString sDialogModelService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlDialogModel"));
151 uno::Reference< awt::XControlModel > xDialogModel( xServiceManager->createInstance( sDialogModelService ), uno::UNO_QUERY_THROW );
153 const ::rtl::OUString sDecoration(RTL_CONSTASCII_USTRINGPARAM("Decoration"));
154 uno::Reference< beans::XPropertySet > xPropSet( xDialogModel, uno::UNO_QUERY_THROW );
155 xPropSet->setPropertyValue( sDecoration, uno::makeAny(false));
157 const ::rtl::OUString sDialogService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlDialog"));
158 uno::Reference< awt::XControl > xDialogControl( xServiceManager->createInstance( sDialogService ), uno::UNO_QUERY_THROW );
160 xDialogControl->setModel( xDialogModel );
162 uno::Reference< awt::XWindowPeer > xWindowParentPeer( xToolkit->getDesktopWindow(), uno::UNO_QUERY );
163 xDialogControl->createPeer( xToolkit, xWindowParentPeer );
164 uno::Reference< uno::XInterface > xWindow( xDialogControl->getPeer(), uno::UNO_QUERY );
166 uno::Reference
< uno::XInterface
> xWindow
;
170 uno::Reference
< uno::XInterface
> SAL_CALL
WindowContentFactoryManager::createInstanceWithArgumentsAndContext(
171 const uno::Sequence
< uno::Any
>& Arguments
, const uno::Reference
< uno::XComponentContext
>& Context
)
172 throw (uno::Exception
, uno::RuntimeException
)
174 uno::Reference
< uno::XInterface
> xWindow
;
175 uno::Reference
< frame::XFrame
> xFrame
;
176 ::rtl::OUString aResourceURL
;
178 for (sal_Int32 i
=0; i
< Arguments
.getLength(); i
++ )
180 beans::PropertyValue aPropValue
;
181 if ( Arguments
[i
] >>= aPropValue
)
183 if ( aPropValue
.Name
.equalsAscii( "Frame" ))
184 aPropValue
.Value
>>= xFrame
;
185 else if ( aPropValue
.Name
.equalsAscii( "ResourceURL" ))
186 aPropValue
.Value
>>= aResourceURL
;
190 uno::Reference
< frame::XModuleManager
> xModuleManager
;
193 ResetableGuard
aLock( m_aLock
);
194 xModuleManager
= m_xModuleManager
;
198 // Determine the module identifier
199 ::rtl::OUString aType
;
200 ::rtl::OUString aName
;
201 ::rtl::OUString aModuleId
;
204 if ( xFrame
.is() && xModuleManager
.is() )
205 aModuleId
= xModuleManager
->identify( uno::Reference
< uno::XInterface
>( xFrame
, uno::UNO_QUERY
) );
207 catch ( frame::UnknownModuleException
& )
211 RetrieveTypeNameFromResourceURL( aResourceURL
, aType
, aName
);
212 if ( aType
.getLength() > 0 &&
213 aName
.getLength() > 0 &&
214 aModuleId
.getLength() > 0 )
216 ::rtl::OUString aImplementationName
;
217 uno::Reference
< uno::XInterface
> xHolder( static_cast<cppu::OWeakObject
*>(this), uno::UNO_QUERY
);
219 // Detetmine the implementation name of the window content factory dependent on the
220 // module identifier, user interface element type and name
222 ResetableGuard
aLock( m_aLock
);
223 aImplementationName
= m_pConfigAccess
->getFactorySpecifierFromTypeNameModule( aType
, aName
, aModuleId
);
224 if ( aImplementationName
.getLength() > 0 )
229 uno::Reference
< lang::XMultiServiceFactory
> xServiceManager( Context
->getServiceManager(), uno::UNO_QUERY
);
230 if ( xServiceManager
.is() )
232 uno::Reference
< lang::XSingleComponentFactory
> xFactory(
233 xServiceManager
->createInstance( aImplementationName
), uno::UNO_QUERY
);
236 // Be careful: We call external code. Therefore here we have to catch all exceptions
239 xWindow
= xFactory
->createInstanceWithArgumentsAndContext( Arguments
, Context
);
241 catch ( uno::RuntimeException
& )
244 catch ( uno::Exception
& )
255 // Fallback: Use internal factory code to create a toolkit dialog as a content window
256 xWindow
= createInstanceWithContext(Context
);
262 } // namespace framework