xref: /trunk/main/scripting/source/dlgprov/dlgprov.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_scripting.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "DialogModelProvider.hxx"
32*cdf0e10cSrcweir #include "dlgprov.hxx"
33*cdf0e10cSrcweir #include "dlgevtatt.hxx"
34*cdf0e10cSrcweir #include <com/sun/star/awt/XControlContainer.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/io/XInputStreamProvider.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer.hpp>
40*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
41*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
42*cdf0e10cSrcweir #include <com/sun/star/beans/XIntrospection.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/resource/XStringResourceSupplier.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/resource/XStringResourceManager.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/resource/XStringResourceWithLocation.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedScripts.hpp>
49*cdf0e10cSrcweir #include <sfx2/app.hxx>
50*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
51*cdf0e10cSrcweir #include <xmlscript/xmldlg_imexp.hxx>
52*cdf0e10cSrcweir #include <tools/urlobj.hxx>
53*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include <com/sun/star/uri/XUriReference.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/uri/XUriReferenceFactory.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/uri/XVndSunStarExpandUrl.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp>
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir #include <util/MiscUtils.hxx>
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir using namespace ::com::sun::star;
64*cdf0e10cSrcweir using namespace awt;
65*cdf0e10cSrcweir using namespace lang;
66*cdf0e10cSrcweir using namespace uno;
67*cdf0e10cSrcweir using namespace script;
68*cdf0e10cSrcweir using namespace beans;
69*cdf0e10cSrcweir using namespace document;
70*cdf0e10cSrcweir using namespace ::sf_misc;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir // component helper namespace
73*cdf0e10cSrcweir namespace comp_DialogModelProvider
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     ::rtl::OUString SAL_CALL _getImplementationName()
77*cdf0e10cSrcweir     {
78*cdf0e10cSrcweir         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.scripting.DialogModelProvider"));
79*cdf0e10cSrcweir     }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames()
82*cdf0e10cSrcweir     {
83*cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > s(1);
84*cdf0e10cSrcweir         s[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlDialogModelProvider"));
85*cdf0e10cSrcweir         return s;
86*cdf0e10cSrcweir     }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     uno::Reference< uno::XInterface > SAL_CALL _create(const uno::Reference< uno::XComponentContext > & context) SAL_THROW((uno::Exception))
89*cdf0e10cSrcweir     {
90*cdf0e10cSrcweir         return static_cast< ::cppu::OWeakObject * >(new dlgprov::DialogModelProvider(context));
91*cdf0e10cSrcweir     }
92*cdf0e10cSrcweir } // closing component helper namespace
93*cdf0e10cSrcweir //.........................................................................
94*cdf0e10cSrcweir namespace dlgprov
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir //.........................................................................
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir static ::rtl::OUString aResourceResolverPropName = ::rtl::OUString::createFromAscii( "ResourceResolver" );
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     Reference< resource::XStringResourceManager > lcl_getStringResourceManager(const Reference< XComponentContext >& i_xContext,const ::rtl::OUString& i_sURL)
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         INetURLObject aInetObj( i_sURL );
103*cdf0e10cSrcweir         ::rtl::OUString aDlgName = aInetObj.GetBase();
104*cdf0e10cSrcweir         aInetObj.removeSegment();
105*cdf0e10cSrcweir         ::rtl::OUString aDlgLocation = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
106*cdf0e10cSrcweir         bool bReadOnly = true;
107*cdf0e10cSrcweir         ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
108*cdf0e10cSrcweir         ::rtl::OUString aComment;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         Sequence<Any> aArgs( 6 );
111*cdf0e10cSrcweir         aArgs[0] <<= aDlgLocation;
112*cdf0e10cSrcweir         aArgs[1] <<= bReadOnly;
113*cdf0e10cSrcweir         aArgs[2] <<= aLocale;
114*cdf0e10cSrcweir         aArgs[3] <<= aDlgName;
115*cdf0e10cSrcweir         aArgs[4] <<= aComment;
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir         Reference< task::XInteractionHandler > xDummyHandler;
118*cdf0e10cSrcweir         aArgs[5] <<= xDummyHandler;
119*cdf0e10cSrcweir         Reference< XMultiComponentFactory > xSMgr_( i_xContext->getServiceManager(), UNO_QUERY_THROW );
120*cdf0e10cSrcweir         // TODO: Ctor
121*cdf0e10cSrcweir         Reference< resource::XStringResourceManager > xStringResourceManager( xSMgr_->createInstanceWithContext
122*cdf0e10cSrcweir             ( ::rtl::OUString::createFromAscii( "com.sun.star.resource.StringResourceWithLocation" ),
123*cdf0e10cSrcweir                 i_xContext ), UNO_QUERY );
124*cdf0e10cSrcweir         if( xStringResourceManager.is() )
125*cdf0e10cSrcweir         {
126*cdf0e10cSrcweir             Reference< XInitialization > xInit( xStringResourceManager, UNO_QUERY );
127*cdf0e10cSrcweir             if( xInit.is() )
128*cdf0e10cSrcweir                 xInit->initialize( aArgs );
129*cdf0e10cSrcweir         }
130*cdf0e10cSrcweir         return xStringResourceManager;
131*cdf0e10cSrcweir     }
132*cdf0e10cSrcweir     Reference< container::XNameContainer > lcl_createControlModel(const Reference< XComponentContext >& i_xContext)
133*cdf0e10cSrcweir     {
134*cdf0e10cSrcweir         Reference< XMultiComponentFactory > xSMgr_( i_xContext->getServiceManager(), UNO_QUERY_THROW );
135*cdf0e10cSrcweir         Reference< container::XNameContainer > xControlModel( xSMgr_->createInstanceWithContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ), i_xContext ), UNO_QUERY_THROW );
136*cdf0e10cSrcweir         return xControlModel;
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir     Reference< container::XNameContainer > lcl_createDialogModel( const Reference< XComponentContext >& i_xContext,
139*cdf0e10cSrcweir         const Reference< io::XInputStream >& xInput,
140*cdf0e10cSrcweir         const Reference< resource::XStringResourceManager >& xStringResourceManager,
141*cdf0e10cSrcweir         const Any &aDialogSourceURL) throw ( Exception )
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         Reference< container::XNameContainer > xDialogModel(  lcl_createControlModel(i_xContext) );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir         ::rtl::OUString aDlgSrcUrlPropName( RTL_CONSTASCII_USTRINGPARAM( "DialogSourceURL" ) );
146*cdf0e10cSrcweir         Reference< beans::XPropertySet > xDlgPropSet( xDialogModel, UNO_QUERY );
147*cdf0e10cSrcweir         xDlgPropSet->setPropertyValue( aDlgSrcUrlPropName, aDialogSourceURL );
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir         ::xmlscript::importDialogModel( xInput, xDialogModel, i_xContext );
150*cdf0e10cSrcweir         // Set resource property
151*cdf0e10cSrcweir         if( xStringResourceManager.is() )
152*cdf0e10cSrcweir         {
153*cdf0e10cSrcweir             Reference< beans::XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY );
154*cdf0e10cSrcweir             Any aStringResourceManagerAny;
155*cdf0e10cSrcweir             aStringResourceManagerAny <<= xStringResourceManager;
156*cdf0e10cSrcweir             xDlgPSet->setPropertyValue( aResourceResolverPropName, aStringResourceManagerAny );
157*cdf0e10cSrcweir         }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir         return xDialogModel;
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir     // =============================================================================
162*cdf0e10cSrcweir     // component operations
163*cdf0e10cSrcweir     // =============================================================================
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     static ::rtl::OUString getImplementationName_DialogProviderImpl()
166*cdf0e10cSrcweir     {
167*cdf0e10cSrcweir         static ::rtl::OUString* pImplName = 0;
168*cdf0e10cSrcweir         if ( !pImplName )
169*cdf0e10cSrcweir         {
170*cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
171*cdf0e10cSrcweir             if ( !pImplName )
172*cdf0e10cSrcweir             {
173*cdf0e10cSrcweir                 static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.scripting.DialogProvider" ) );
174*cdf0e10cSrcweir                 pImplName = &aImplName;
175*cdf0e10cSrcweir             }
176*cdf0e10cSrcweir         }
177*cdf0e10cSrcweir         return *pImplName;
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     static Sequence< ::rtl::OUString > getSupportedServiceNames_DialogProviderImpl()
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         static Sequence< ::rtl::OUString >* pNames = 0;
185*cdf0e10cSrcweir         if ( !pNames )
186*cdf0e10cSrcweir         {
187*cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
188*cdf0e10cSrcweir             if ( !pNames )
189*cdf0e10cSrcweir             {
190*cdf0e10cSrcweir                 static Sequence< ::rtl::OUString > aNames(3);
191*cdf0e10cSrcweir                 aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DialogProvider" ) );
192*cdf0e10cSrcweir                 aNames.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DialogProvider2" ) );
193*cdf0e10cSrcweir                 aNames.getArray()[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.ContainerWindowProvider" ) );
194*cdf0e10cSrcweir                 pNames = &aNames;
195*cdf0e10cSrcweir             }
196*cdf0e10cSrcweir         }
197*cdf0e10cSrcweir         return *pNames;
198*cdf0e10cSrcweir     }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     // =============================================================================
202*cdf0e10cSrcweir     // mutex
203*cdf0e10cSrcweir     // =============================================================================
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     ::osl::Mutex& getMutex()
206*cdf0e10cSrcweir     {
207*cdf0e10cSrcweir         static ::osl::Mutex* s_pMutex = 0;
208*cdf0e10cSrcweir         if ( !s_pMutex )
209*cdf0e10cSrcweir         {
210*cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
211*cdf0e10cSrcweir             if ( !s_pMutex )
212*cdf0e10cSrcweir             {
213*cdf0e10cSrcweir                 static ::osl::Mutex s_aMutex;
214*cdf0e10cSrcweir                 s_pMutex = &s_aMutex;
215*cdf0e10cSrcweir             }
216*cdf0e10cSrcweir         }
217*cdf0e10cSrcweir         return *s_pMutex;
218*cdf0e10cSrcweir     }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     // =============================================================================
222*cdf0e10cSrcweir     // DialogProviderImpl
223*cdf0e10cSrcweir     // =============================================================================
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir     DialogProviderImpl::DialogProviderImpl( const Reference< XComponentContext >& rxContext )
226*cdf0e10cSrcweir         :m_xContext( rxContext )
227*cdf0e10cSrcweir         ,m_xModel( 0 )
228*cdf0e10cSrcweir     {
229*cdf0e10cSrcweir     }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     DialogProviderImpl::~DialogProviderImpl()
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir     }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     Reference< resource::XStringResourceManager > getStringResourceFromDialogLibrary
240*cdf0e10cSrcweir         ( Reference< container::XNameContainer > xDialogLib )
241*cdf0e10cSrcweir     {
242*cdf0e10cSrcweir         Reference< resource::XStringResourceManager > xStringResourceManager;
243*cdf0e10cSrcweir         if( xDialogLib.is() )
244*cdf0e10cSrcweir         {
245*cdf0e10cSrcweir             Reference< resource::XStringResourceSupplier > xStringResourceSupplier( xDialogLib, UNO_QUERY );
246*cdf0e10cSrcweir             if( xStringResourceSupplier.is() )
247*cdf0e10cSrcweir             {
248*cdf0e10cSrcweir                 Reference< resource::XStringResourceResolver >
249*cdf0e10cSrcweir                     xStringResourceResolver = xStringResourceSupplier->getStringResource();
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir                 xStringResourceManager =
252*cdf0e10cSrcweir                     Reference< resource::XStringResourceManager >( xStringResourceResolver, UNO_QUERY );
253*cdf0e10cSrcweir             }
254*cdf0e10cSrcweir         }
255*cdf0e10cSrcweir         return xStringResourceManager;
256*cdf0e10cSrcweir     }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     Reference< container::XNameContainer > DialogProviderImpl::createControlModel() throw ( Exception )
259*cdf0e10cSrcweir     {
260*cdf0e10cSrcweir         return lcl_createControlModel(m_xContext);
261*cdf0e10cSrcweir     }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     Reference< container::XNameContainer > DialogProviderImpl::createDialogModel(
264*cdf0e10cSrcweir         const Reference< io::XInputStream >& xInput,
265*cdf0e10cSrcweir         const Reference< resource::XStringResourceManager >& xStringResourceManager,
266*cdf0e10cSrcweir         const Any &aDialogSourceURL) throw ( Exception )
267*cdf0e10cSrcweir     {
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir         return lcl_createDialogModel(m_xContext,xInput,xStringResourceManager,aDialogSourceURL);
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     Reference< XControlModel > DialogProviderImpl::createDialogModelForBasic() throw ( Exception )
274*cdf0e10cSrcweir     {
275*cdf0e10cSrcweir         if ( !m_BasicInfo.get() )
276*cdf0e10cSrcweir             // shouln't get here
277*cdf0e10cSrcweir             throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("No information to create dialog" ) ), Reference< XInterface >() );
278*cdf0e10cSrcweir         Reference< resource::XStringResourceManager > xStringResourceManager = getStringResourceFromDialogLibrary( m_BasicInfo->mxDlgLib );
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir         rtl::OUString aURL(RTL_CONSTASCII_USTRINGPARAM("" ));
281*cdf0e10cSrcweir         Any aDialogSourceURL;
282*cdf0e10cSrcweir         aDialogSourceURL <<= aURL;
283*cdf0e10cSrcweir         Reference< XControlModel > xCtrlModel( createDialogModel( m_BasicInfo->mxInput, xStringResourceManager, aDialogSourceURL ), UNO_QUERY_THROW );
284*cdf0e10cSrcweir         return xCtrlModel;
285*cdf0e10cSrcweir     }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     Reference< XControlModel > DialogProviderImpl::createDialogModel( const ::rtl::OUString& sURL )
288*cdf0e10cSrcweir     {
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir         ::rtl::OUString aURL( sURL );
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir         // parse URL
293*cdf0e10cSrcweir         // TODO: use URL parsing class
294*cdf0e10cSrcweir         // TODO: decoding of location
295*cdf0e10cSrcweir         Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY );
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir         if ( !xSMgr.is() )
298*cdf0e10cSrcweir         {
299*cdf0e10cSrcweir             throw RuntimeException(
300*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialogModel: Couldn't instantiate MultiComponent factory" ) ),
301*cdf0e10cSrcweir                     Reference< XInterface >() );
302*cdf0e10cSrcweir         }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir         Reference< uri::XUriReferenceFactory > xFac (
305*cdf0e10cSrcweir             xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii(
306*cdf0e10cSrcweir             "com.sun.star.uri.UriReferenceFactory"), m_xContext ) , UNO_QUERY );
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir         if  ( !xFac.is() )
309*cdf0e10cSrcweir         {
310*cdf0e10cSrcweir             throw RuntimeException(
311*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "DialogProviderImpl::getDialogModel(), could not instatiate UriReferenceFactory." ),
312*cdf0e10cSrcweir                 Reference< XInterface >() );
313*cdf0e10cSrcweir         }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir         // i75778: Support non-script URLs
316*cdf0e10cSrcweir         Reference< io::XInputStream > xInput;
317*cdf0e10cSrcweir         Reference< container::XNameContainer > xDialogLib;
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir         // Accept file URL to single dialog
320*cdf0e10cSrcweir         bool bSingleDialog = false;
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir         Reference< util::XMacroExpander > xMacroExpander(
323*cdf0e10cSrcweir             m_xContext->getValueByName(
324*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ),
325*cdf0e10cSrcweir             UNO_QUERY_THROW );
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir         Reference< uri::XUriReference > uriRef;
328*cdf0e10cSrcweir         for (;;)
329*cdf0e10cSrcweir         {
330*cdf0e10cSrcweir             uriRef = Reference< uri::XUriReference >( xFac->parse( aURL ), UNO_QUERY );
331*cdf0e10cSrcweir             if ( !uriRef.is() )
332*cdf0e10cSrcweir             {
333*cdf0e10cSrcweir                 ::rtl::OUString errorMsg = ::rtl::OUString::createFromAscii( "DialogProviderImpl::getDialogModel: failed to parse URI: " );
334*cdf0e10cSrcweir                 errorMsg += aURL;
335*cdf0e10cSrcweir                 throw IllegalArgumentException( errorMsg,
336*cdf0e10cSrcweir                                                 Reference< XInterface >(), 1 );
337*cdf0e10cSrcweir             }
338*cdf0e10cSrcweir             Reference < uri::XVndSunStarExpandUrl > sxUri( uriRef, UNO_QUERY );
339*cdf0e10cSrcweir             if( !sxUri.is() )
340*cdf0e10cSrcweir                 break;
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir             aURL = sxUri->expand( xMacroExpander );
343*cdf0e10cSrcweir         }
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir         Reference < uri::XVndSunStarScriptUrl > sfUri( uriRef, UNO_QUERY );
346*cdf0e10cSrcweir         if( !sfUri.is() )
347*cdf0e10cSrcweir         {
348*cdf0e10cSrcweir             bSingleDialog = true;
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir             // Try any other URL with SimpleFileAccess
351*cdf0e10cSrcweir             Reference< ucb::XSimpleFileAccess > xSFI =
352*cdf0e10cSrcweir                 Reference< ucb::XSimpleFileAccess >( xSMgr->createInstanceWithContext
353*cdf0e10cSrcweir                 ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), m_xContext ), UNO_QUERY );
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir             try
356*cdf0e10cSrcweir             {
357*cdf0e10cSrcweir                 xInput = xSFI->openFileRead( aURL );
358*cdf0e10cSrcweir             }
359*cdf0e10cSrcweir             catch( Exception& )
360*cdf0e10cSrcweir             {}
361*cdf0e10cSrcweir         }
362*cdf0e10cSrcweir         else
363*cdf0e10cSrcweir         {
364*cdf0e10cSrcweir             ::rtl::OUString sDescription = sfUri->getName();
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir             sal_Int32 nIndex = 0;
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir             ::rtl::OUString sLibName = sDescription.getToken( 0, (sal_Unicode)'.', nIndex );
369*cdf0e10cSrcweir             ::rtl::OUString sDlgName;
370*cdf0e10cSrcweir             if ( nIndex != -1 )
371*cdf0e10cSrcweir                 sDlgName = sDescription.getToken( 0, (sal_Unicode)'.', nIndex );
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir             ::rtl::OUString sLocation = sfUri->getParameter(
374*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "location" ) );
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir             // get dialog library container
378*cdf0e10cSrcweir             // TODO: dialogs in packages
379*cdf0e10cSrcweir             Reference< XLibraryContainer > xLibContainer;
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir             if ( sLocation == ::rtl::OUString::createFromAscii( "application" ) )
382*cdf0e10cSrcweir             {
383*cdf0e10cSrcweir                 xLibContainer = Reference< XLibraryContainer >( SFX_APP()->GetDialogContainer(), UNO_QUERY );
384*cdf0e10cSrcweir             }
385*cdf0e10cSrcweir             else if ( sLocation == ::rtl::OUString::createFromAscii( "document" ) )
386*cdf0e10cSrcweir             {
387*cdf0e10cSrcweir                 Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
388*cdf0e10cSrcweir                 if ( xDocumentScripts.is() )
389*cdf0e10cSrcweir                 {
390*cdf0e10cSrcweir                     xLibContainer.set( xDocumentScripts->getDialogLibraries(), UNO_QUERY );
391*cdf0e10cSrcweir                     OSL_ENSURE( xLibContainer.is(),
392*cdf0e10cSrcweir                         "DialogProviderImpl::createDialogModel: invalid dialog container!" );
393*cdf0e10cSrcweir                 }
394*cdf0e10cSrcweir             }
395*cdf0e10cSrcweir             else
396*cdf0e10cSrcweir             {
397*cdf0e10cSrcweir                 Sequence< ::rtl::OUString > aOpenDocsTdocURLs( MiscUtils::allOpenTDocUrls( m_xContext ) );
398*cdf0e10cSrcweir                 const ::rtl::OUString* pTdocURL = aOpenDocsTdocURLs.getConstArray();
399*cdf0e10cSrcweir                 const ::rtl::OUString* pTdocURLEnd = aOpenDocsTdocURLs.getConstArray() + aOpenDocsTdocURLs.getLength();
400*cdf0e10cSrcweir                 for ( ; pTdocURL != pTdocURLEnd; ++pTdocURL )
401*cdf0e10cSrcweir                 {
402*cdf0e10cSrcweir                     Reference< frame::XModel > xModel( MiscUtils::tDocUrlToModel( *pTdocURL ) );
403*cdf0e10cSrcweir                     OSL_ENSURE( xModel.is(), "DialogProviderImpl::createDialogModel: invalid document model!" );
404*cdf0e10cSrcweir                     if ( !xModel.is() )
405*cdf0e10cSrcweir                         continue;
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir                     ::rtl::OUString sDocURL = xModel->getURL();
408*cdf0e10cSrcweir                     if ( sDocURL.getLength() == 0 )
409*cdf0e10cSrcweir                     {
410*cdf0e10cSrcweir                         ::comphelper::NamedValueCollection aModelArgs( xModel->getArgs() );
411*cdf0e10cSrcweir                         sDocURL = aModelArgs.getOrDefault( "Title", sDocURL );
412*cdf0e10cSrcweir                     }
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir                     if ( sLocation != sDocURL )
415*cdf0e10cSrcweir                         continue;
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir                     Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
418*cdf0e10cSrcweir                     if ( !xDocumentScripts.is() )
419*cdf0e10cSrcweir                         continue;
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir                     xLibContainer.set( xDocumentScripts->getDialogLibraries(), UNO_QUERY );
422*cdf0e10cSrcweir                     OSL_ENSURE( xLibContainer.is(),
423*cdf0e10cSrcweir                         "DialogProviderImpl::createDialogModel: invalid dialog container!" );
424*cdf0e10cSrcweir                 }
425*cdf0e10cSrcweir             }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir             // get input stream provider
428*cdf0e10cSrcweir             Reference< io::XInputStreamProvider > xISP;
429*cdf0e10cSrcweir             if ( xLibContainer.is() )
430*cdf0e10cSrcweir             {
431*cdf0e10cSrcweir                 // load dialog library
432*cdf0e10cSrcweir                 if ( !xLibContainer->isLibraryLoaded( sLibName ) )
433*cdf0e10cSrcweir                     xLibContainer->loadLibrary( sLibName );
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir                 // get dialog library
436*cdf0e10cSrcweir                 if ( xLibContainer->hasByName( sLibName ) )
437*cdf0e10cSrcweir                 {
438*cdf0e10cSrcweir                     Any aElement = xLibContainer->getByName( sLibName );
439*cdf0e10cSrcweir                     aElement >>= xDialogLib;
440*cdf0e10cSrcweir                 }
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir                 if ( xDialogLib.is() )
443*cdf0e10cSrcweir                 {
444*cdf0e10cSrcweir                     // get input stream provider
445*cdf0e10cSrcweir                     if ( xDialogLib->hasByName( sDlgName ) )
446*cdf0e10cSrcweir                     {
447*cdf0e10cSrcweir                         Any aElement = xDialogLib->getByName( sDlgName );
448*cdf0e10cSrcweir                         aElement >>= xISP;
449*cdf0e10cSrcweir                     }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir                     if ( !xISP.is() )
452*cdf0e10cSrcweir                     {
453*cdf0e10cSrcweir                         throw IllegalArgumentException(
454*cdf0e10cSrcweir                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialogModel: dialog not found!" ) ),
455*cdf0e10cSrcweir                             Reference< XInterface >(), 1 );
456*cdf0e10cSrcweir                     }
457*cdf0e10cSrcweir                 }
458*cdf0e10cSrcweir                 else
459*cdf0e10cSrcweir                 {
460*cdf0e10cSrcweir                     throw IllegalArgumentException(
461*cdf0e10cSrcweir                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialogModel: library not found!" ) ),
462*cdf0e10cSrcweir                         Reference< XInterface >(), 1 );
463*cdf0e10cSrcweir                 }
464*cdf0e10cSrcweir             }
465*cdf0e10cSrcweir             else
466*cdf0e10cSrcweir             {
467*cdf0e10cSrcweir                 throw IllegalArgumentException(
468*cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialog: library container not found!" ) ),
469*cdf0e10cSrcweir                     Reference< XInterface >(), 1 );
470*cdf0e10cSrcweir             }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir             if ( xISP.is() )
473*cdf0e10cSrcweir                 xInput = xISP->createInputStream();
474*cdf0e10cSrcweir         }
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir         // import dialog model
477*cdf0e10cSrcweir         Reference< XControlModel > xCtrlModel;
478*cdf0e10cSrcweir         if ( xInput.is() && m_xContext.is() )
479*cdf0e10cSrcweir         {
480*cdf0e10cSrcweir             Reference< resource::XStringResourceManager > xStringResourceManager;
481*cdf0e10cSrcweir             if( bSingleDialog )
482*cdf0e10cSrcweir             {
483*cdf0e10cSrcweir                 xStringResourceManager = lcl_getStringResourceManager(m_xContext,aURL);
484*cdf0e10cSrcweir             }
485*cdf0e10cSrcweir             else if( xDialogLib.is() )
486*cdf0e10cSrcweir             {
487*cdf0e10cSrcweir                 xStringResourceManager = getStringResourceFromDialogLibrary( xDialogLib );
488*cdf0e10cSrcweir             }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir             Any aDialogSourceURLAny;
491*cdf0e10cSrcweir             aDialogSourceURLAny <<= aURL;
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir             Reference< container::XNameContainer > xDialogModel( createDialogModel( xInput , xStringResourceManager, aDialogSourceURLAny  ), UNO_QUERY_THROW);
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir             xCtrlModel = Reference< XControlModel >( xDialogModel, UNO_QUERY );
496*cdf0e10cSrcweir         }
497*cdf0e10cSrcweir         return xCtrlModel;
498*cdf0e10cSrcweir     }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir     Reference< XControl > DialogProviderImpl::createDialogControl
503*cdf0e10cSrcweir         ( const Reference< XControlModel >& rxDialogModel, const Reference< XWindowPeer >& xParent )
504*cdf0e10cSrcweir     {
505*cdf0e10cSrcweir         OSL_ENSURE( rxDialogModel.is(), "DialogProviderImpl::getDialogControl: no dialog model" );
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir         Reference< XControl > xDialogControl;
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir         if ( m_xContext.is() )
510*cdf0e10cSrcweir         {
511*cdf0e10cSrcweir             Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir             if ( xSMgr.is() )
514*cdf0e10cSrcweir             {
515*cdf0e10cSrcweir                 xDialogControl = Reference< XControl >( xSMgr->createInstanceWithContext(
516*cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialog" ) ), m_xContext ), UNO_QUERY );
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir                 if ( xDialogControl.is() )
519*cdf0e10cSrcweir                 {
520*cdf0e10cSrcweir                     // set the model
521*cdf0e10cSrcweir                     if ( rxDialogModel.is() )
522*cdf0e10cSrcweir                         xDialogControl->setModel( rxDialogModel );
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir                     // set visible
525*cdf0e10cSrcweir                     Reference< XWindow > xW( xDialogControl, UNO_QUERY );
526*cdf0e10cSrcweir                     if ( xW.is() )
527*cdf0e10cSrcweir                         xW->setVisible( sal_False );
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir                     // get the parent of the dialog control
530*cdf0e10cSrcweir                     Reference< XWindowPeer > xPeer;
531*cdf0e10cSrcweir                     if( xParent.is() )
532*cdf0e10cSrcweir                     {
533*cdf0e10cSrcweir                         xPeer = xParent;
534*cdf0e10cSrcweir                     }
535*cdf0e10cSrcweir                     else if ( m_xModel.is() )
536*cdf0e10cSrcweir                     {
537*cdf0e10cSrcweir                         Reference< frame::XController > xController( m_xModel->getCurrentController(), UNO_QUERY );
538*cdf0e10cSrcweir                         if ( xController.is() )
539*cdf0e10cSrcweir                         {
540*cdf0e10cSrcweir                             Reference< frame::XFrame > xFrame( xController->getFrame(), UNO_QUERY );
541*cdf0e10cSrcweir                             if ( xFrame.is() )
542*cdf0e10cSrcweir                                 xPeer = Reference< XWindowPeer>( xFrame->getContainerWindow(), UNO_QUERY );
543*cdf0e10cSrcweir                         }
544*cdf0e10cSrcweir                     }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir                     // create a peer
547*cdf0e10cSrcweir                     Reference< XToolkit> xToolkit( xSMgr->createInstanceWithContext(
548*cdf0e10cSrcweir                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ), m_xContext ), UNO_QUERY );
549*cdf0e10cSrcweir                     if ( xToolkit.is() )
550*cdf0e10cSrcweir                         xDialogControl->createPeer( xToolkit, xPeer );
551*cdf0e10cSrcweir                 }
552*cdf0e10cSrcweir             }
553*cdf0e10cSrcweir         }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir         return xDialogControl;
556*cdf0e10cSrcweir     }
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir     void DialogProviderImpl::attachControlEvents(
561*cdf0e10cSrcweir         const Reference< XControl >& rxControl,
562*cdf0e10cSrcweir         const Reference< XInterface >& rxHandler,
563*cdf0e10cSrcweir         const Reference< XIntrospectionAccess >& rxIntrospectionAccess,
564*cdf0e10cSrcweir         bool bDialogProviderMode )
565*cdf0e10cSrcweir     {
566*cdf0e10cSrcweir         if ( rxControl.is() )
567*cdf0e10cSrcweir         {
568*cdf0e10cSrcweir             Reference< XControlContainer > xControlContainer( rxControl, UNO_QUERY );
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir             if ( xControlContainer.is() )
571*cdf0e10cSrcweir             {
572*cdf0e10cSrcweir                 Sequence< Reference< XControl > > aControls = xControlContainer->getControls();
573*cdf0e10cSrcweir                 const Reference< XControl >* pControls = aControls.getConstArray();
574*cdf0e10cSrcweir                 sal_Int32 nControlCount = aControls.getLength();
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir                 Sequence< Reference< XInterface > > aObjects( nControlCount + 1 );
577*cdf0e10cSrcweir                 Reference< XInterface >* pObjects = aObjects.getArray();
578*cdf0e10cSrcweir                 for ( sal_Int32 i = 0; i < nControlCount; ++i )
579*cdf0e10cSrcweir                 {
580*cdf0e10cSrcweir                     pObjects[i] = Reference< XInterface >( pControls[i], UNO_QUERY );
581*cdf0e10cSrcweir                 }
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir                 // also add the dialog control itself to the sequence
584*cdf0e10cSrcweir                 pObjects[nControlCount] = Reference< XInterface >( rxControl, UNO_QUERY );
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir                 Reference< XScriptEventsAttacher > xScriptEventsAttacher = new DialogEventsAttacherImpl
587*cdf0e10cSrcweir                     ( m_xContext, m_xModel, rxControl, rxHandler, rxIntrospectionAccess,
588*cdf0e10cSrcweir                       bDialogProviderMode, ( m_BasicInfo.get() ? m_BasicInfo->mxBasicRTLListener : NULL ) );
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir                 Any aHelper;
591*cdf0e10cSrcweir                 xScriptEventsAttacher->attachEvents( aObjects, Reference< XScriptListener >(), aHelper );
592*cdf0e10cSrcweir             }
593*cdf0e10cSrcweir         }
594*cdf0e10cSrcweir     }
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir     Reference< XIntrospectionAccess > DialogProviderImpl::inspectHandler( const Reference< XInterface >& rxHandler )
597*cdf0e10cSrcweir     {
598*cdf0e10cSrcweir         Reference< XIntrospectionAccess > xIntrospectionAccess;
599*cdf0e10cSrcweir         static Reference< XIntrospection > xIntrospection;
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir         if( !rxHandler.is() )
602*cdf0e10cSrcweir             return xIntrospectionAccess;
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir         if( !xIntrospection.is() )
605*cdf0e10cSrcweir         {
606*cdf0e10cSrcweir             Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY );
607*cdf0e10cSrcweir             if ( !xSMgr.is() )
608*cdf0e10cSrcweir             {
609*cdf0e10cSrcweir                 throw RuntimeException(
610*cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getIntrospectionAccess: Couldn't instantiate MultiComponent factory" ) ),
611*cdf0e10cSrcweir                         Reference< XInterface >() );
612*cdf0e10cSrcweir             }
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir             // Get introspection service
615*cdf0e10cSrcweir             Reference< XInterface > xI = xSMgr->createInstanceWithContext
616*cdf0e10cSrcweir                 ( rtl::OUString::createFromAscii("com.sun.star.beans.Introspection"), m_xContext );
617*cdf0e10cSrcweir             if (xI.is())
618*cdf0e10cSrcweir                 xIntrospection = Reference< XIntrospection >::query( xI );
619*cdf0e10cSrcweir         }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir         if( xIntrospection.is() )
622*cdf0e10cSrcweir         {
623*cdf0e10cSrcweir             // Do introspection
624*cdf0e10cSrcweir             try
625*cdf0e10cSrcweir             {
626*cdf0e10cSrcweir                 Any aHandlerAny;
627*cdf0e10cSrcweir                 aHandlerAny <<= rxHandler;
628*cdf0e10cSrcweir                 xIntrospectionAccess = xIntrospection->inspect( aHandlerAny );
629*cdf0e10cSrcweir             }
630*cdf0e10cSrcweir             catch( RuntimeException& )
631*cdf0e10cSrcweir             {
632*cdf0e10cSrcweir                 xIntrospectionAccess.clear();
633*cdf0e10cSrcweir             }
634*cdf0e10cSrcweir         }
635*cdf0e10cSrcweir         return xIntrospectionAccess;
636*cdf0e10cSrcweir     }
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
640*cdf0e10cSrcweir     // XServiceInfo
641*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir     ::rtl::OUString DialogProviderImpl::getImplementationName(  ) throw (RuntimeException)
644*cdf0e10cSrcweir     {
645*cdf0e10cSrcweir         return getImplementationName_DialogProviderImpl();
646*cdf0e10cSrcweir     }
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir     sal_Bool DialogProviderImpl::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
651*cdf0e10cSrcweir     {
652*cdf0e10cSrcweir         Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
653*cdf0e10cSrcweir         const ::rtl::OUString* pNames = aNames.getConstArray();
654*cdf0e10cSrcweir         const ::rtl::OUString* pEnd = pNames + aNames.getLength();
655*cdf0e10cSrcweir         for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
656*cdf0e10cSrcweir             ;
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir         return pNames != pEnd;
659*cdf0e10cSrcweir     }
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir     Sequence< ::rtl::OUString > DialogProviderImpl::getSupportedServiceNames(  ) throw (RuntimeException)
664*cdf0e10cSrcweir     {
665*cdf0e10cSrcweir         return getSupportedServiceNames_DialogProviderImpl();
666*cdf0e10cSrcweir     }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
669*cdf0e10cSrcweir     // XInitialization
670*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir     void DialogProviderImpl::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
673*cdf0e10cSrcweir     {
674*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( getMutex() );
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir         if ( aArguments.getLength() == 1 )
677*cdf0e10cSrcweir         {
678*cdf0e10cSrcweir             aArguments[0] >>= m_xModel;
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir             if ( !m_xModel.is() )
681*cdf0e10cSrcweir             {
682*cdf0e10cSrcweir                 throw RuntimeException(
683*cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::initialize: invalid argument format!" ) ),
684*cdf0e10cSrcweir                     Reference< XInterface >() );
685*cdf0e10cSrcweir             }
686*cdf0e10cSrcweir         }
687*cdf0e10cSrcweir         else if ( aArguments.getLength() == 4 )
688*cdf0e10cSrcweir         {
689*cdf0e10cSrcweir             // call from RTL_Impl_CreateUnoDialog
690*cdf0e10cSrcweir             aArguments[0] >>= m_xModel;
691*cdf0e10cSrcweir             m_BasicInfo.reset( new BasicRTLParams() );
692*cdf0e10cSrcweir             m_BasicInfo->mxInput.set( aArguments[ 1 ], UNO_QUERY_THROW );
693*cdf0e10cSrcweir             m_BasicInfo->mxDlgLib.set( aArguments[ 2 ], UNO_QUERY_THROW );
694*cdf0e10cSrcweir             // leave the possibility to optionally allow the old dialog creation
695*cdf0e10cSrcweir             // to use the new XScriptListener ( which converts the old style macro
696*cdf0e10cSrcweir             // to a SF url )
697*cdf0e10cSrcweir             m_BasicInfo->mxBasicRTLListener.set( aArguments[ 3 ], UNO_QUERY);
698*cdf0e10cSrcweir         }
699*cdf0e10cSrcweir         else if ( aArguments.getLength() > 4 )
700*cdf0e10cSrcweir         {
701*cdf0e10cSrcweir             throw RuntimeException(
702*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::initialize: invalid number of arguments!" ) ),
703*cdf0e10cSrcweir                 Reference< XInterface >() );
704*cdf0e10cSrcweir         }
705*cdf0e10cSrcweir     }
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
708*cdf0e10cSrcweir     // XDialogProvider
709*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir     static ::rtl::OUString aDecorationPropName =
712*cdf0e10cSrcweir         ::rtl::OUString::createFromAscii( "Decoration" );
713*cdf0e10cSrcweir     static ::rtl::OUString aTitlePropName =
714*cdf0e10cSrcweir         ::rtl::OUString::createFromAscii( "Title" );
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir     Reference < XControl > DialogProviderImpl::createDialogImpl(
717*cdf0e10cSrcweir         const ::rtl::OUString& URL, const Reference< XInterface >& xHandler,
718*cdf0e10cSrcweir         const Reference< XWindowPeer >& xParent, bool bDialogProviderMode )
719*cdf0e10cSrcweir             throw (IllegalArgumentException, RuntimeException)
720*cdf0e10cSrcweir     {
721*cdf0e10cSrcweir         // if the dialog is located in a document, the document must already be open!
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( getMutex() );
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir         // m_xHandler = xHandler;
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir         //Reference< XDialog > xDialog;
729*cdf0e10cSrcweir         Reference< XControl > xCtrl;
730*cdf0e10cSrcweir         Reference< XControlModel > xCtrlMod;
731*cdf0e10cSrcweir         try
732*cdf0e10cSrcweir         {
733*cdf0e10cSrcweir             // add support for basic RTL_FUNCTION
734*cdf0e10cSrcweir             if ( m_BasicInfo.get() )
735*cdf0e10cSrcweir                 xCtrlMod = createDialogModelForBasic();
736*cdf0e10cSrcweir             else
737*cdf0e10cSrcweir             {
738*cdf0e10cSrcweir                 OSL_ENSURE( URL.getLength(), "DialogProviderImpl::getDialog: no URL!" );
739*cdf0e10cSrcweir                 xCtrlMod = createDialogModel( URL );
740*cdf0e10cSrcweir             }
741*cdf0e10cSrcweir         }
742*cdf0e10cSrcweir         catch ( const RuntimeException& ) { throw; }
743*cdf0e10cSrcweir         catch ( const Exception& )
744*cdf0e10cSrcweir         {
745*cdf0e10cSrcweir             const Any aError( ::cppu::getCaughtException() );
746*cdf0e10cSrcweir             throw WrappedTargetRuntimeException( ::rtl::OUString(), *this, aError );
747*cdf0e10cSrcweir         }
748*cdf0e10cSrcweir         if ( xCtrlMod.is() )
749*cdf0e10cSrcweir         {
750*cdf0e10cSrcweir             // i83963 Force decoration
751*cdf0e10cSrcweir             if( bDialogProviderMode )
752*cdf0e10cSrcweir             {
753*cdf0e10cSrcweir                 uno::Reference< beans::XPropertySet > xDlgModPropSet( xCtrlMod, uno::UNO_QUERY );
754*cdf0e10cSrcweir                 if( xDlgModPropSet.is() )
755*cdf0e10cSrcweir                 {
756*cdf0e10cSrcweir                     bool bDecoration = true;
757*cdf0e10cSrcweir                     try
758*cdf0e10cSrcweir                     {
759*cdf0e10cSrcweir                         Any aDecorationAny = xDlgModPropSet->getPropertyValue( aDecorationPropName );
760*cdf0e10cSrcweir                         aDecorationAny >>= bDecoration;
761*cdf0e10cSrcweir                         if( !bDecoration )
762*cdf0e10cSrcweir                         {
763*cdf0e10cSrcweir                             xDlgModPropSet->setPropertyValue( aDecorationPropName, makeAny( true ) );
764*cdf0e10cSrcweir                             xDlgModPropSet->setPropertyValue( aTitlePropName, makeAny( ::rtl::OUString() ) );
765*cdf0e10cSrcweir                         }
766*cdf0e10cSrcweir                     }
767*cdf0e10cSrcweir                     catch( UnknownPropertyException& )
768*cdf0e10cSrcweir                     {}
769*cdf0e10cSrcweir                 }
770*cdf0e10cSrcweir             }
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir             xCtrl = Reference< XControl >( createDialogControl( xCtrlMod, xParent ) );
773*cdf0e10cSrcweir             if ( xCtrl.is() )
774*cdf0e10cSrcweir             {
775*cdf0e10cSrcweir                 //xDialog = Reference< XDialog >( xCtrl, UNO_QUERY );
776*cdf0e10cSrcweir                 Reference< XIntrospectionAccess > xIntrospectionAccess = inspectHandler( xHandler );
777*cdf0e10cSrcweir                 attachControlEvents( xCtrl, xHandler, xIntrospectionAccess, bDialogProviderMode );
778*cdf0e10cSrcweir             }
779*cdf0e10cSrcweir         }
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir         return xCtrl;
782*cdf0e10cSrcweir     }
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir     Reference < XDialog > DialogProviderImpl::createDialog( const ::rtl::OUString& URL )
785*cdf0e10cSrcweir         throw (IllegalArgumentException, RuntimeException)
786*cdf0e10cSrcweir     {
787*cdf0e10cSrcweir         Reference< XInterface > xDummyHandler;
788*cdf0e10cSrcweir         Reference< XWindowPeer > xDummyPeer;
789*cdf0e10cSrcweir         Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xDummyHandler, xDummyPeer, true );
790*cdf0e10cSrcweir         Reference< XDialog > xDialog( xControl, UNO_QUERY );
791*cdf0e10cSrcweir         return xDialog;
792*cdf0e10cSrcweir     }
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir     Reference < XDialog > DialogProviderImpl::createDialogWithHandler(
795*cdf0e10cSrcweir         const ::rtl::OUString& URL, const Reference< XInterface >& xHandler )
796*cdf0e10cSrcweir             throw (IllegalArgumentException, RuntimeException)
797*cdf0e10cSrcweir     {
798*cdf0e10cSrcweir         if( !xHandler.is() )
799*cdf0e10cSrcweir         {
800*cdf0e10cSrcweir             throw IllegalArgumentException(
801*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::createDialogWithHandler: Invalid xHandler!" ) ),
802*cdf0e10cSrcweir                 Reference< XInterface >(), 1 );
803*cdf0e10cSrcweir         }
804*cdf0e10cSrcweir         Reference< XWindowPeer > xDummyPeer;
805*cdf0e10cSrcweir         Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xDummyPeer, true );
806*cdf0e10cSrcweir         Reference< XDialog > xDialog( xControl, UNO_QUERY );
807*cdf0e10cSrcweir         return xDialog;
808*cdf0e10cSrcweir     }
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir     Reference < XDialog > DialogProviderImpl::createDialogWithArguments(
811*cdf0e10cSrcweir         const ::rtl::OUString& URL, const Sequence< NamedValue >& Arguments )
812*cdf0e10cSrcweir             throw (IllegalArgumentException, RuntimeException)
813*cdf0e10cSrcweir     {
814*cdf0e10cSrcweir         ::comphelper::NamedValueCollection aArguments( Arguments );
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir         Reference< XWindowPeer > xParentPeer;
817*cdf0e10cSrcweir         if ( aArguments.has( "ParentWindow" ) )
818*cdf0e10cSrcweir         {
819*cdf0e10cSrcweir             const Any aParentWindow( aArguments.get( "ParentWindow" ) );
820*cdf0e10cSrcweir             if ( !( aParentWindow >>= xParentPeer ) )
821*cdf0e10cSrcweir             {
822*cdf0e10cSrcweir                 const Reference< XControl > xParentControl( aParentWindow, UNO_QUERY );
823*cdf0e10cSrcweir                 if ( xParentControl.is() )
824*cdf0e10cSrcweir                     xParentPeer = xParentControl->getPeer();
825*cdf0e10cSrcweir             }
826*cdf0e10cSrcweir         }
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir         const Reference< XInterface > xHandler( aArguments.get( "EventHandler" ), UNO_QUERY );
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir         Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xParentPeer, true );
831*cdf0e10cSrcweir         Reference< XDialog > xDialog( xControl, UNO_QUERY );
832*cdf0e10cSrcweir         return xDialog;
833*cdf0e10cSrcweir     }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir     Reference< XWindow > DialogProviderImpl::createContainerWindow(
836*cdf0e10cSrcweir         const ::rtl::OUString& URL, const ::rtl::OUString& WindowType,
837*cdf0e10cSrcweir         const Reference< XWindowPeer >& xParent, const Reference< XInterface >& xHandler )
838*cdf0e10cSrcweir             throw (lang::IllegalArgumentException, RuntimeException)
839*cdf0e10cSrcweir     {
840*cdf0e10cSrcweir         (void)WindowType;   // for future use
841*cdf0e10cSrcweir         if( !xParent.is() )
842*cdf0e10cSrcweir         {
843*cdf0e10cSrcweir             throw IllegalArgumentException(
844*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::createContainerWindow: Invalid xParent!" ) ),
845*cdf0e10cSrcweir                 Reference< XInterface >(), 1 );
846*cdf0e10cSrcweir         }
847*cdf0e10cSrcweir         Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xParent, false );
848*cdf0e10cSrcweir         Reference< XWindow> xWindow( xControl, UNO_QUERY );
849*cdf0e10cSrcweir         return xWindow;
850*cdf0e10cSrcweir     }
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir     // =============================================================================
854*cdf0e10cSrcweir     // component operations
855*cdf0e10cSrcweir     // =============================================================================
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir     static Reference< XInterface > SAL_CALL create_DialogProviderImpl(
858*cdf0e10cSrcweir         Reference< XComponentContext > const & xContext )
859*cdf0e10cSrcweir         SAL_THROW( () )
860*cdf0e10cSrcweir     {
861*cdf0e10cSrcweir         return static_cast< lang::XTypeProvider * >( new DialogProviderImpl( xContext ) );
862*cdf0e10cSrcweir     }
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir     static struct ::cppu::ImplementationEntry s_component_entries [] =
867*cdf0e10cSrcweir     {
868*cdf0e10cSrcweir         {create_DialogProviderImpl, getImplementationName_DialogProviderImpl,getSupportedServiceNames_DialogProviderImpl, ::cppu::createSingleComponentFactory,0, 0},
869*cdf0e10cSrcweir         { &comp_DialogModelProvider::_create,&comp_DialogModelProvider::_getImplementationName,&comp_DialogModelProvider::_getSupportedServiceNames,&::cppu::createSingleComponentFactory, 0, 0 },
870*cdf0e10cSrcweir         { 0, 0, 0, 0, 0, 0 }
871*cdf0e10cSrcweir     };
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir     // -----------------------------------------------------------------------------
874*cdf0e10cSrcweir 
875*cdf0e10cSrcweir //.........................................................................
876*cdf0e10cSrcweir }   // namespace dlgprov
877*cdf0e10cSrcweir //.........................................................................
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir // =============================================================================
881*cdf0e10cSrcweir // component exports
882*cdf0e10cSrcweir // =============================================================================
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir extern "C"
885*cdf0e10cSrcweir {
886*cdf0e10cSrcweir     void SAL_CALL component_getImplementationEnvironment(
887*cdf0e10cSrcweir         const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
888*cdf0e10cSrcweir     {
889*cdf0e10cSrcweir         (void)ppEnv;
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir         *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
892*cdf0e10cSrcweir     }
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir     void * SAL_CALL component_getFactory(
895*cdf0e10cSrcweir         const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager,
896*cdf0e10cSrcweir         registry::XRegistryKey * pRegistryKey )
897*cdf0e10cSrcweir     {
898*cdf0e10cSrcweir         return ::cppu::component_getFactoryHelper(
899*cdf0e10cSrcweir             pImplName, pServiceManager, pRegistryKey, ::dlgprov::s_component_entries );
900*cdf0e10cSrcweir     }
901*cdf0e10cSrcweir }
902