bump product version to 4.1.6.2
[LibreOffice.git] / scripting / source / dlgprov / dlgprov.cxx
blob2be567db31c84cdc8dccf2d119c1e59486f11dca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "DialogModelProvider.hxx"
22 #include "dlgprov.hxx"
23 #include "dlgevtatt.hxx"
24 #include <com/sun/star/awt/Toolkit.hpp>
25 #include <com/sun/star/awt/XControlContainer.hpp>
26 #include <com/sun/star/awt/XWindowPeer.hpp>
27 #include <com/sun/star/io/XInputStreamProvider.hpp>
28 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
29 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
30 #include <com/sun/star/script/XLibraryContainer.hpp>
31 #include <cppuhelper/implementationentry.hxx>
32 #include <cppuhelper/exc_hlp.hxx>
33 #include <com/sun/star/beans/Introspection.hpp>
34 #include <com/sun/star/resource/XStringResourceSupplier.hpp>
35 #include <com/sun/star/resource/XStringResourceManager.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
38 #include <com/sun/star/resource/XStringResourceWithLocation.hpp>
39 #include <com/sun/star/document/XEmbeddedScripts.hpp>
40 #include <sfx2/app.hxx>
41 #include <sfx2/objsh.hxx>
42 #include <xmlscript/xmldlg_imexp.hxx>
43 #include <tools/urlobj.hxx>
44 #include <comphelper/namedvaluecollection.hxx>
46 #include <com/sun/star/uri/XUriReference.hpp>
47 #include <com/sun/star/uri/UriReferenceFactory.hpp>
48 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
49 #include <com/sun/star/uri/XVndSunStarExpandUrl.hpp>
50 #include <com/sun/star/util/theMacroExpander.hpp>
52 #include <util/MiscUtils.hxx>
54 using namespace ::com::sun::star;
55 using namespace awt;
56 using namespace lang;
57 using namespace uno;
58 using namespace script;
59 using namespace beans;
60 using namespace document;
61 using namespace ::sf_misc;
63 // component helper namespace
64 namespace comp_DialogModelProvider
67 OUString SAL_CALL _getImplementationName()
69 return OUString("com.sun.star.comp.scripting.DialogModelProvider");
72 uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames()
74 uno::Sequence< OUString > s(1);
75 s[0] = OUString("com.sun.star.awt.UnoControlDialogModelProvider");
76 return s;
79 uno::Reference< uno::XInterface > SAL_CALL _create(const uno::Reference< uno::XComponentContext > & context) SAL_THROW((uno::Exception))
81 return static_cast< ::cppu::OWeakObject * >(new dlgprov::DialogModelProvider(context));
83 } // closing component helper namespace
84 //.........................................................................
85 namespace dlgprov
87 //.........................................................................
89 static OUString aResourceResolverPropName("ResourceResolver");
91 Reference< resource::XStringResourceManager > lcl_getStringResourceManager(const Reference< XComponentContext >& i_xContext,const OUString& i_sURL)
93 INetURLObject aInetObj( i_sURL );
94 OUString aDlgName = aInetObj.GetBase();
95 aInetObj.removeSegment();
96 OUString aDlgLocation = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
97 bool bReadOnly = true;
98 ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
99 OUString aComment;
101 Sequence<Any> aArgs( 6 );
102 aArgs[0] <<= aDlgLocation;
103 aArgs[1] <<= bReadOnly;
104 aArgs[2] <<= aLocale;
105 aArgs[3] <<= aDlgName;
106 aArgs[4] <<= aComment;
108 Reference< task::XInteractionHandler > xDummyHandler;
109 aArgs[5] <<= xDummyHandler;
110 Reference< XMultiComponentFactory > xSMgr_( i_xContext->getServiceManager(), UNO_QUERY_THROW );
111 // TODO: Ctor
112 Reference< resource::XStringResourceManager > xStringResourceManager( xSMgr_->createInstanceWithContext
113 ( OUString("com.sun.star.resource.StringResourceWithLocation"),
114 i_xContext ), UNO_QUERY );
115 if( xStringResourceManager.is() )
117 Reference< XInitialization > xInit( xStringResourceManager, UNO_QUERY );
118 if( xInit.is() )
119 xInit->initialize( aArgs );
121 return xStringResourceManager;
123 Reference< container::XNameContainer > lcl_createControlModel(const Reference< XComponentContext >& i_xContext)
125 Reference< XMultiComponentFactory > xSMgr_( i_xContext->getServiceManager(), UNO_QUERY_THROW );
126 Reference< container::XNameContainer > xControlModel( xSMgr_->createInstanceWithContext( OUString( "com.sun.star.awt.UnoControlDialogModel" ), i_xContext ), UNO_QUERY_THROW );
127 return xControlModel;
129 Reference< container::XNameContainer > lcl_createDialogModel( const Reference< XComponentContext >& i_xContext,
130 const Reference< io::XInputStream >& xInput,
131 const Reference< frame::XModel >& xModel,
132 const Reference< resource::XStringResourceManager >& xStringResourceManager,
133 const Any &aDialogSourceURL) throw ( Exception )
135 Reference< container::XNameContainer > xDialogModel( lcl_createControlModel(i_xContext) );
137 OUString aDlgSrcUrlPropName( "DialogSourceURL" );
138 Reference< beans::XPropertySet > xDlgPropSet( xDialogModel, UNO_QUERY );
139 xDlgPropSet->setPropertyValue( aDlgSrcUrlPropName, aDialogSourceURL );
141 // #TODO we really need to detect the source of the Dialog, is it
142 // the dialog. E.g. if the dialog was created from basic ( then we just
143 // can't tell where its from )
144 // If we are happy to always substitute the form model for the awt
145 // one then maybe the presence of a document model is enough to trigger
146 // swapping out the models ( or perhaps we only want to do this
147 // for vba mode ) there are a number of feasible and valid possibilities
148 ::xmlscript::importDialogModel( xInput, xDialogModel, i_xContext, xModel );
150 // Set resource property
151 if( xStringResourceManager.is() )
153 Reference< beans::XPropertySet > xDlgPSet( xDialogModel, UNO_QUERY );
154 Any aStringResourceManagerAny;
155 aStringResourceManagerAny <<= xStringResourceManager;
156 xDlgPSet->setPropertyValue( aResourceResolverPropName, aStringResourceManagerAny );
159 return xDialogModel;
161 // =============================================================================
162 // component operations
163 // =============================================================================
165 static OUString getImplementationName_DialogProviderImpl()
167 static OUString* pImplName = 0;
168 if ( !pImplName )
170 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
171 if ( !pImplName )
173 static OUString aImplName( "com.sun.star.comp.scripting.DialogProvider" );
174 pImplName = &aImplName;
177 return *pImplName;
180 // -----------------------------------------------------------------------------
182 static Sequence< OUString > getSupportedServiceNames_DialogProviderImpl()
184 static Sequence< OUString >* pNames = 0;
185 if ( !pNames )
187 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
188 if ( !pNames )
190 static Sequence< OUString > aNames(3);
191 aNames.getArray()[0] = OUString( "com.sun.star.awt.DialogProvider" );
192 aNames.getArray()[1] = OUString( "com.sun.star.awt.DialogProvider2" );
193 aNames.getArray()[2] = OUString( "com.sun.star.awt.ContainerWindowProvider" );
194 pNames = &aNames;
197 return *pNames;
201 // =============================================================================
202 // mutex
203 // =============================================================================
205 ::osl::Mutex& getMutex()
207 static ::osl::Mutex* s_pMutex = 0;
208 if ( !s_pMutex )
210 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
211 if ( !s_pMutex )
213 static ::osl::Mutex s_aMutex;
214 s_pMutex = &s_aMutex;
217 return *s_pMutex;
221 // =============================================================================
222 // DialogProviderImpl
223 // =============================================================================
225 DialogProviderImpl::DialogProviderImpl( const Reference< XComponentContext >& rxContext )
226 :m_xContext( rxContext )
227 ,m_xModel( 0 )
231 // -----------------------------------------------------------------------------
233 DialogProviderImpl::~DialogProviderImpl()
237 // -----------------------------------------------------------------------------
239 Reference< resource::XStringResourceManager > getStringResourceFromDialogLibrary
240 ( Reference< container::XNameContainer > xDialogLib )
242 Reference< resource::XStringResourceManager > xStringResourceManager;
243 if( xDialogLib.is() )
245 Reference< resource::XStringResourceSupplier > xStringResourceSupplier( xDialogLib, UNO_QUERY );
246 if( xStringResourceSupplier.is() )
248 Reference< resource::XStringResourceResolver >
249 xStringResourceResolver = xStringResourceSupplier->getStringResource();
251 xStringResourceManager =
252 Reference< resource::XStringResourceManager >( xStringResourceResolver, UNO_QUERY );
255 return xStringResourceManager;
258 Reference< container::XNameContainer > DialogProviderImpl::createDialogModel(
259 const Reference< io::XInputStream >& xInput,
260 const Reference< resource::XStringResourceManager >& xStringResourceManager,
261 const Any &aDialogSourceURL) throw ( Exception )
263 return lcl_createDialogModel(m_xContext,xInput,m_xModel,xStringResourceManager,aDialogSourceURL);
266 Reference< XControlModel > DialogProviderImpl::createDialogModelForBasic() throw ( Exception )
268 if ( !m_BasicInfo.get() )
269 // shouln't get here
270 throw RuntimeException( OUString( "No information to create dialog" ), Reference< XInterface >() );
271 Reference< resource::XStringResourceManager > xStringResourceManager = getStringResourceFromDialogLibrary( m_BasicInfo->mxDlgLib );
273 OUString aURL("" );
274 Any aDialogSourceURL;
275 aDialogSourceURL <<= aURL;
276 Reference< XControlModel > xCtrlModel( createDialogModel( m_BasicInfo->mxInput, xStringResourceManager, aDialogSourceURL ), UNO_QUERY_THROW );
277 return xCtrlModel;
280 Reference< XControlModel > DialogProviderImpl::createDialogModel( const OUString& sURL )
283 OUString aURL( sURL );
285 // parse URL
286 // TODO: use URL parsing class
287 // TODO: decoding of location
289 Reference< uri::XUriReferenceFactory > xFac ( uri::UriReferenceFactory::create( m_xContext ) );
291 // i75778: Support non-script URLs
292 Reference< io::XInputStream > xInput;
293 Reference< container::XNameContainer > xDialogLib;
295 // Accept file URL to single dialog
296 bool bSingleDialog = false;
298 Reference< util::XMacroExpander > xMacroExpander =
299 util::theMacroExpander::get(m_xContext);
301 Reference< uri::XUriReference > uriRef;
302 for (;;)
304 uriRef = Reference< uri::XUriReference >( xFac->parse( aURL ), UNO_QUERY );
305 if ( !uriRef.is() )
307 OUString errorMsg("DialogProviderImpl::getDialogModel: failed to parse URI: ");
308 errorMsg += aURL;
309 throw IllegalArgumentException( errorMsg,
310 Reference< XInterface >(), 1 );
312 Reference < uri::XVndSunStarExpandUrl > sxUri( uriRef, UNO_QUERY );
313 if( !sxUri.is() )
314 break;
316 aURL = sxUri->expand( xMacroExpander );
319 Reference < uri::XVndSunStarScriptUrl > sfUri( uriRef, UNO_QUERY );
320 if( !sfUri.is() )
322 bSingleDialog = true;
324 // Try any other URL with SimpleFileAccess
325 Reference< ucb::XSimpleFileAccess3 > xSFI = ucb::SimpleFileAccess::create(m_xContext);
329 xInput = xSFI->openFileRead( aURL );
331 catch( Exception& )
334 else
336 OUString sDescription = sfUri->getName();
338 sal_Int32 nIndex = 0;
340 OUString sLibName = sDescription.getToken( 0, (sal_Unicode)'.', nIndex );
341 OUString sDlgName;
342 if ( nIndex != -1 )
343 sDlgName = sDescription.getToken( 0, (sal_Unicode)'.', nIndex );
345 OUString sLocation = sfUri->getParameter(
346 OUString("location") );
349 // get dialog library container
350 // TODO: dialogs in packages
351 Reference< XLibraryContainer > xLibContainer;
353 if ( sLocation == "application" )
355 xLibContainer = Reference< XLibraryContainer >( SFX_APP()->GetDialogContainer(), UNO_QUERY );
357 else if ( sLocation == "document" )
359 Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
360 if ( xDocumentScripts.is() )
362 xLibContainer.set( xDocumentScripts->getDialogLibraries(), UNO_QUERY );
363 OSL_ENSURE( xLibContainer.is(),
364 "DialogProviderImpl::createDialogModel: invalid dialog container!" );
367 else
369 Sequence< OUString > aOpenDocsTdocURLs( MiscUtils::allOpenTDocUrls( m_xContext ) );
370 const OUString* pTdocURL = aOpenDocsTdocURLs.getConstArray();
371 const OUString* pTdocURLEnd = aOpenDocsTdocURLs.getConstArray() + aOpenDocsTdocURLs.getLength();
372 for ( ; pTdocURL != pTdocURLEnd; ++pTdocURL )
374 Reference< frame::XModel > xModel( MiscUtils::tDocUrlToModel( *pTdocURL ) );
375 OSL_ENSURE( xModel.is(), "DialogProviderImpl::createDialogModel: invalid document model!" );
376 if ( !xModel.is() )
377 continue;
379 OUString sDocURL = xModel->getURL();
380 if ( sDocURL.isEmpty() )
382 ::comphelper::NamedValueCollection aModelArgs( xModel->getArgs() );
383 sDocURL = aModelArgs.getOrDefault( "Title", sDocURL );
386 if ( sLocation != sDocURL )
387 continue;
389 Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
390 if ( !xDocumentScripts.is() )
391 continue;
393 xLibContainer.set( xDocumentScripts->getDialogLibraries(), UNO_QUERY );
394 OSL_ENSURE( xLibContainer.is(),
395 "DialogProviderImpl::createDialogModel: invalid dialog container!" );
399 // get input stream provider
400 Reference< io::XInputStreamProvider > xISP;
401 if ( xLibContainer.is() )
403 // load dialog library
404 if ( !xLibContainer->isLibraryLoaded( sLibName ) )
405 xLibContainer->loadLibrary( sLibName );
407 // get dialog library
408 if ( xLibContainer->hasByName( sLibName ) )
410 Any aElement = xLibContainer->getByName( sLibName );
411 aElement >>= xDialogLib;
414 if ( xDialogLib.is() )
416 // get input stream provider
417 if ( xDialogLib->hasByName( sDlgName ) )
419 Any aElement = xDialogLib->getByName( sDlgName );
420 aElement >>= xISP;
423 if ( !xISP.is() )
425 throw IllegalArgumentException(
426 OUString( "DialogProviderImpl::getDialogModel: dialog not found!" ),
427 Reference< XInterface >(), 1 );
430 else
432 throw IllegalArgumentException(
433 OUString( "DialogProviderImpl::getDialogModel: library not found!" ),
434 Reference< XInterface >(), 1 );
437 else
439 throw IllegalArgumentException(
440 OUString( "DialogProviderImpl::getDialog: library container not found!" ),
441 Reference< XInterface >(), 1 );
444 if ( xISP.is() )
445 xInput = xISP->createInputStream();
446 msDialogLibName = sLibName;
449 // import dialog model
450 Reference< XControlModel > xCtrlModel;
451 if ( xInput.is() && m_xContext.is() )
453 Reference< resource::XStringResourceManager > xStringResourceManager;
454 if( bSingleDialog )
456 xStringResourceManager = lcl_getStringResourceManager(m_xContext,aURL);
458 else if( xDialogLib.is() )
460 xStringResourceManager = getStringResourceFromDialogLibrary( xDialogLib );
463 Any aDialogSourceURLAny;
464 aDialogSourceURLAny <<= aURL;
466 Reference< container::XNameContainer > xDialogModel( createDialogModel( xInput , xStringResourceManager, aDialogSourceURLAny ), UNO_QUERY_THROW);
468 xCtrlModel = Reference< XControlModel >( xDialogModel, UNO_QUERY );
470 return xCtrlModel;
473 // -----------------------------------------------------------------------------
475 Reference< XControl > DialogProviderImpl::createDialogControl
476 ( const Reference< XControlModel >& rxDialogModel, const Reference< XWindowPeer >& xParent )
478 OSL_ENSURE( rxDialogModel.is(), "DialogProviderImpl::getDialogControl: no dialog model" );
480 Reference< XControl > xDialogControl;
482 if ( m_xContext.is() )
484 Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
486 if ( xSMgr.is() )
488 xDialogControl = Reference< XControl >( xSMgr->createInstanceWithContext(
489 OUString( "com.sun.star.awt.UnoControlDialog" ), m_xContext ), UNO_QUERY );
491 if ( xDialogControl.is() )
493 // set the model
494 if ( rxDialogModel.is() )
495 xDialogControl->setModel( rxDialogModel );
497 // set visible
498 Reference< XWindow > xW( xDialogControl, UNO_QUERY );
499 if ( xW.is() )
500 xW->setVisible( sal_False );
502 // get the parent of the dialog control
503 Reference< XWindowPeer > xPeer;
504 if( xParent.is() )
506 xPeer = xParent;
508 else if ( m_xModel.is() )
510 Reference< frame::XController > xController( m_xModel->getCurrentController(), UNO_QUERY );
511 if ( xController.is() )
513 Reference< frame::XFrame > xFrame( xController->getFrame(), UNO_QUERY );
514 if ( xFrame.is() )
515 xPeer = Reference< XWindowPeer>( xFrame->getContainerWindow(), UNO_QUERY );
519 // create a peer
520 Reference< XToolkit> xToolkit( Toolkit::create( m_xContext ), UNO_QUERY_THROW );
521 xDialogControl->createPeer( xToolkit, xPeer );
526 return xDialogControl;
529 // -----------------------------------------------------------------------------
531 void DialogProviderImpl::attachControlEvents(
532 const Reference< XControl >& rxControl,
533 const Reference< XInterface >& rxHandler,
534 const Reference< XIntrospectionAccess >& rxIntrospectionAccess,
535 bool bDialogProviderMode )
537 if ( rxControl.is() )
539 Reference< XControlContainer > xControlContainer( rxControl, UNO_QUERY );
541 if ( xControlContainer.is() )
543 Sequence< Reference< XControl > > aControls = xControlContainer->getControls();
544 const Reference< XControl >* pControls = aControls.getConstArray();
545 sal_Int32 nControlCount = aControls.getLength();
547 Sequence< Reference< XInterface > > aObjects( nControlCount + 1 );
548 Reference< XInterface >* pObjects = aObjects.getArray();
549 for ( sal_Int32 i = 0; i < nControlCount; ++i )
551 pObjects[i] = Reference< XInterface >( pControls[i], UNO_QUERY );
554 // also add the dialog control itself to the sequence
555 pObjects[nControlCount] = Reference< XInterface >( rxControl, UNO_QUERY );
557 Reference< XScriptEventsAttacher > xScriptEventsAttacher = new DialogEventsAttacherImpl
558 ( m_xContext, m_xModel, rxControl, rxHandler, rxIntrospectionAccess,
559 bDialogProviderMode, ( m_BasicInfo.get() ? m_BasicInfo->mxBasicRTLListener : NULL ), msDialogLibName );
561 Any aHelper;
562 xScriptEventsAttacher->attachEvents( aObjects, Reference< XScriptListener >(), aHelper );
567 Reference< XIntrospectionAccess > DialogProviderImpl::inspectHandler( const Reference< XInterface >& rxHandler )
569 Reference< XIntrospectionAccess > xIntrospectionAccess;
570 static Reference< XIntrospection > xIntrospection;
572 if( !rxHandler.is() )
573 return xIntrospectionAccess;
575 if( !xIntrospection.is() )
577 // Get introspection service
578 xIntrospection = Introspection::create( m_xContext );
581 // Do introspection
584 Any aHandlerAny;
585 aHandlerAny <<= rxHandler;
586 xIntrospectionAccess = xIntrospection->inspect( aHandlerAny );
588 catch( RuntimeException& )
590 xIntrospectionAccess.clear();
592 return xIntrospectionAccess;
596 // -----------------------------------------------------------------------------
597 // XServiceInfo
598 // -----------------------------------------------------------------------------
600 OUString DialogProviderImpl::getImplementationName( ) throw (RuntimeException)
602 return getImplementationName_DialogProviderImpl();
605 // -----------------------------------------------------------------------------
607 sal_Bool DialogProviderImpl::supportsService( const OUString& rServiceName ) throw (RuntimeException)
609 Sequence< OUString > aNames( getSupportedServiceNames() );
610 const OUString* pNames = aNames.getConstArray();
611 const OUString* pEnd = pNames + aNames.getLength();
612 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
615 return pNames != pEnd;
618 // -----------------------------------------------------------------------------
620 Sequence< OUString > DialogProviderImpl::getSupportedServiceNames( ) throw (RuntimeException)
622 return getSupportedServiceNames_DialogProviderImpl();
625 // -----------------------------------------------------------------------------
626 // XInitialization
627 // -----------------------------------------------------------------------------
629 void DialogProviderImpl::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
631 ::osl::MutexGuard aGuard( getMutex() );
633 if ( aArguments.getLength() == 1 )
635 aArguments[0] >>= m_xModel;
637 if ( !m_xModel.is() )
639 throw RuntimeException(
640 OUString( "DialogProviderImpl::initialize: invalid argument format!" ),
641 Reference< XInterface >() );
644 else if ( aArguments.getLength() == 4 )
646 // call from RTL_Impl_CreateUnoDialog
647 aArguments[0] >>= m_xModel;
648 m_BasicInfo.reset( new BasicRTLParams() );
649 m_BasicInfo->mxInput.set( aArguments[ 1 ], UNO_QUERY_THROW );
650 // allow null mxDlgLib, a document dialog instantiated from
651 // from application basic is unable to provide ( or find ) it's
652 // Library
653 aArguments[ 2 ] >>= m_BasicInfo->mxDlgLib;
654 // leave the possibility to optionally allow the old dialog creation
655 // to use the new XScriptListener ( which converts the old style macro
656 // to a SF url )
657 m_BasicInfo->mxBasicRTLListener.set( aArguments[ 3 ], UNO_QUERY);
659 else if ( aArguments.getLength() > 4 )
661 throw RuntimeException(
662 OUString( "DialogProviderImpl::initialize: invalid number of arguments!" ),
663 Reference< XInterface >() );
667 // -----------------------------------------------------------------------------
668 // XDialogProvider
669 // -----------------------------------------------------------------------------
671 static OUString aDecorationPropName("Decoration");
672 static OUString aTitlePropName("Title");
674 Reference < XControl > DialogProviderImpl::createDialogImpl(
675 const OUString& URL, const Reference< XInterface >& xHandler,
676 const Reference< XWindowPeer >& xParent, bool bDialogProviderMode )
677 throw (IllegalArgumentException, RuntimeException)
679 // if the dialog is located in a document, the document must already be open!
681 ::osl::MutexGuard aGuard( getMutex() );
684 // m_xHandler = xHandler;
686 //Reference< XDialog > xDialog;
687 Reference< XControl > xCtrl;
688 Reference< XControlModel > xCtrlMod;
691 // add support for basic RTL_FUNCTION
692 if ( m_BasicInfo.get() )
693 xCtrlMod = createDialogModelForBasic();
694 else
696 OSL_ENSURE( !URL.isEmpty(), "DialogProviderImpl::getDialog: no URL!" );
697 xCtrlMod = createDialogModel( URL );
700 catch ( const RuntimeException& ) { throw; }
701 catch ( const Exception& )
703 const Any aError( ::cppu::getCaughtException() );
704 throw WrappedTargetRuntimeException( OUString(), *this, aError );
706 if ( xCtrlMod.is() )
708 // i83963 Force decoration
709 if( bDialogProviderMode )
711 uno::Reference< beans::XPropertySet > xDlgModPropSet( xCtrlMod, uno::UNO_QUERY );
712 if( xDlgModPropSet.is() )
714 bool bDecoration = true;
717 Any aDecorationAny = xDlgModPropSet->getPropertyValue( aDecorationPropName );
718 aDecorationAny >>= bDecoration;
719 if( !bDecoration )
721 xDlgModPropSet->setPropertyValue( aDecorationPropName, makeAny( true ) );
722 xDlgModPropSet->setPropertyValue( aTitlePropName, makeAny( OUString() ) );
725 catch( UnknownPropertyException& )
730 xCtrl = Reference< XControl >( createDialogControl( xCtrlMod, xParent ) );
731 if ( xCtrl.is() )
733 //xDialog = Reference< XDialog >( xCtrl, UNO_QUERY );
734 Reference< XIntrospectionAccess > xIntrospectionAccess = inspectHandler( xHandler );
735 attachControlEvents( xCtrl, xHandler, xIntrospectionAccess, bDialogProviderMode );
739 return xCtrl;
742 Reference < XDialog > DialogProviderImpl::createDialog( const OUString& URL )
743 throw (IllegalArgumentException, RuntimeException)
745 Reference< XInterface > xDummyHandler;
746 Reference< XWindowPeer > xDummyPeer;
747 Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xDummyHandler, xDummyPeer, true );
748 Reference< XDialog > xDialog( xControl, UNO_QUERY );
749 return xDialog;
752 Reference < XDialog > DialogProviderImpl::createDialogWithHandler(
753 const OUString& URL, const Reference< XInterface >& xHandler )
754 throw (IllegalArgumentException, RuntimeException)
756 if( !xHandler.is() )
758 throw IllegalArgumentException(
759 OUString( "DialogProviderImpl::createDialogWithHandler: Invalid xHandler!" ),
760 Reference< XInterface >(), 1 );
762 Reference< XWindowPeer > xDummyPeer;
763 Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xDummyPeer, true );
764 Reference< XDialog > xDialog( xControl, UNO_QUERY );
765 return xDialog;
768 Reference < XDialog > DialogProviderImpl::createDialogWithArguments(
769 const OUString& URL, const Sequence< NamedValue >& Arguments )
770 throw (IllegalArgumentException, RuntimeException)
772 ::comphelper::NamedValueCollection aArguments( Arguments );
774 Reference< XWindowPeer > xParentPeer;
775 if ( aArguments.has( "ParentWindow" ) )
777 const Any aParentWindow( aArguments.get( "ParentWindow" ) );
778 if ( !( aParentWindow >>= xParentPeer ) )
780 const Reference< XControl > xParentControl( aParentWindow, UNO_QUERY );
781 if ( xParentControl.is() )
782 xParentPeer = xParentControl->getPeer();
786 const Reference< XInterface > xHandler( aArguments.get( "EventHandler" ), UNO_QUERY );
788 Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xParentPeer, true );
789 Reference< XDialog > xDialog( xControl, UNO_QUERY );
790 return xDialog;
793 Reference< XWindow > DialogProviderImpl::createContainerWindow(
794 const OUString& URL, const OUString& WindowType,
795 const Reference< XWindowPeer >& xParent, const Reference< XInterface >& xHandler )
796 throw (lang::IllegalArgumentException, RuntimeException)
798 (void)WindowType; // for future use
799 if( !xParent.is() )
801 throw IllegalArgumentException(
802 OUString( "DialogProviderImpl::createContainerWindow: Invalid xParent!" ),
803 Reference< XInterface >(), 1 );
805 Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xParent, false );
806 Reference< XWindow> xWindow( xControl, UNO_QUERY );
807 return xWindow;
811 // =============================================================================
812 // component operations
813 // =============================================================================
815 static Reference< XInterface > SAL_CALL create_DialogProviderImpl(
816 Reference< XComponentContext > const & xContext )
817 SAL_THROW(())
819 return static_cast< lang::XTypeProvider * >( new DialogProviderImpl( xContext ) );
822 // -----------------------------------------------------------------------------
824 static struct ::cppu::ImplementationEntry s_component_entries [] =
826 {create_DialogProviderImpl, getImplementationName_DialogProviderImpl,getSupportedServiceNames_DialogProviderImpl, ::cppu::createSingleComponentFactory,0, 0},
827 { &comp_DialogModelProvider::_create,&comp_DialogModelProvider::_getImplementationName,&comp_DialogModelProvider::_getSupportedServiceNames,&::cppu::createSingleComponentFactory, 0, 0 },
828 { 0, 0, 0, 0, 0, 0 }
831 // -----------------------------------------------------------------------------
833 //.........................................................................
834 } // namespace dlgprov
835 //.........................................................................
838 // =============================================================================
839 // component exports
840 // =============================================================================
842 extern "C"
844 SAL_DLLPUBLIC_EXPORT void * SAL_CALL dlgprov_component_getFactory(
845 const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager,
846 registry::XRegistryKey * pRegistryKey )
848 return ::cppu::component_getFactoryHelper(
849 pImplName, pServiceManager, pRegistryKey, ::dlgprov::s_component_entries );
853 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */