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: dlgprov.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_scripting.hxx"
34 #ifndef SCRIPTING_DLGPROV_HXX
35 #include "dlgprov.hxx"
37 #include "dlgevtatt.hxx"
38 #include <com/sun/star/awt/XControlContainer.hpp>
39 #include <com/sun/star/awt/XWindowPeer.hpp>
40 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAMPROVIDER_HXX_
41 #include <com/sun/star/io/XInputStreamProvider.hpp>
43 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
44 #include <com/sun/star/script/XLibraryContainer.hpp>
45 #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_HXX_
46 #include <cppuhelper/implementationentry.hxx>
48 #include <com/sun/star/beans/XIntrospection.hpp>
49 #include <com/sun/star/resource/XStringResourceSupplier.hpp>
50 #include <com/sun/star/resource/XStringResourceManager.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
52 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
53 #include "com/sun/star/resource/XStringResourceWithLocation.hpp"
54 #include <com/sun/star/document/XEmbeddedScripts.hpp>
55 #include <sfx2/app.hxx>
56 #include <sfx2/objsh.hxx>
57 #include <xmlscript/xmldlg_imexp.hxx>
58 #include <tools/urlobj.hxx>
59 #include <comphelper/namedvaluecollection.hxx>
61 #include <com/sun/star/uri/XUriReference.hpp>
62 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
63 #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
64 #include <com/sun/star/uri/XVndSunStarExpandUrl.hpp>
65 #include <com/sun/star/util/XMacroExpander.hpp>
67 #include <util/MiscUtils.hxx>
69 using namespace ::com::sun::star
;
70 using namespace ::com::sun::star::awt
;
71 using namespace ::com::sun::star::lang
;
72 using namespace ::com::sun::star::uno
;
73 using namespace ::com::sun::star::script
;
74 using namespace ::com::sun::star::beans
;
75 using namespace ::com::sun::star::document
;
76 using namespace ::sf_misc
;
78 //.........................................................................
81 //.........................................................................
83 static ::rtl::OUString aResourceResolverPropName
= ::rtl::OUString::createFromAscii( "ResourceResolver" );
84 // =============================================================================
85 // component operations
86 // =============================================================================
88 static ::rtl::OUString
getImplementationName_DialogProviderImpl()
90 static ::rtl::OUString
* pImplName
= 0;
93 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
96 static ::rtl::OUString
aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.scripting.DialogProvider" ) );
97 pImplName
= &aImplName
;
103 // -----------------------------------------------------------------------------
105 static Sequence
< ::rtl::OUString
> getSupportedServiceNames_DialogProviderImpl()
107 static Sequence
< ::rtl::OUString
>* pNames
= 0;
110 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
113 static Sequence
< ::rtl::OUString
> aNames(3);
114 aNames
.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DialogProvider" ) );
115 aNames
.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DialogProvider2" ) );
116 aNames
.getArray()[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.ContainerWindowProvider" ) );
124 // =============================================================================
126 // =============================================================================
128 ::osl::Mutex
& getMutex()
130 static ::osl::Mutex
* s_pMutex
= 0;
133 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
136 static ::osl::Mutex s_aMutex
;
137 s_pMutex
= &s_aMutex
;
144 // =============================================================================
145 // DialogProviderImpl
146 // =============================================================================
148 DialogProviderImpl::DialogProviderImpl( const Reference
< XComponentContext
>& rxContext
)
149 :m_xContext( rxContext
)
154 // -----------------------------------------------------------------------------
156 DialogProviderImpl::~DialogProviderImpl()
160 // -----------------------------------------------------------------------------
162 Reference
< resource::XStringResourceManager
> getStringResourceFromDialogLibrary
163 ( Reference
< container::XNameContainer
> xDialogLib
)
165 Reference
< resource::XStringResourceManager
> xStringResourceManager
;
166 if( xDialogLib
.is() )
168 Reference
< resource::XStringResourceSupplier
> xStringResourceSupplier( xDialogLib
, UNO_QUERY
);
169 if( xStringResourceSupplier
.is() )
171 Reference
< resource::XStringResourceResolver
>
172 xStringResourceResolver
= xStringResourceSupplier
->getStringResource();
174 xStringResourceManager
=
175 Reference
< resource::XStringResourceManager
>( xStringResourceResolver
, UNO_QUERY
);
178 return xStringResourceManager
;
181 Reference
< container::XNameContainer
> DialogProviderImpl::createControlModel() throw ( Exception
)
183 Reference
< XMultiComponentFactory
> xSMgr_( m_xContext
->getServiceManager(), UNO_QUERY_THROW
);
184 Reference
< container::XNameContainer
> xControlModel( xSMgr_
->createInstanceWithContext( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ), m_xContext
), UNO_QUERY_THROW
);
185 return xControlModel
;
188 Reference
< container::XNameContainer
> DialogProviderImpl::createDialogModel(
189 const Reference
< io::XInputStream
>& xInput
,
190 const Reference
< resource::XStringResourceManager
>& xStringResourceManager
,
191 const Any
&aDialogSourceURL
) throw ( Exception
)
193 Reference
< container::XNameContainer
> xDialogModel( createControlModel() );
195 ::rtl::OUString
aDlgSrcUrlPropName( RTL_CONSTASCII_USTRINGPARAM( "DialogSourceURL" ) );
196 Reference
< beans::XPropertySet
> xDlgPropSet( xDialogModel
, UNO_QUERY
);
197 xDlgPropSet
->setPropertyValue( aDlgSrcUrlPropName
, aDialogSourceURL
);
199 // #TODO we really need to detect the source of the Dialog, is it
200 // located in the document or not. m_xModel need not be the location of
201 // the dialog. E.g. if the dialog was created from basic ( then we just
202 // can't tell where its from )
203 // If we are happy to always substitute the form model for the awt
204 // one then maybe the presence of a document model is enough to trigger
205 // swapping out the models ( or perhaps we only want to do this
206 // for vba mode ) there are a number of feasible and valid possibilities
207 ::xmlscript::importDialogModel( xInput
, xDialogModel
, m_xContext
, m_xModel
);
208 // Set resource property
209 if( xStringResourceManager
.is() )
211 Reference
< beans::XPropertySet
> xDlgPSet( xDialogModel
, UNO_QUERY
);
212 Any aStringResourceManagerAny
;
213 aStringResourceManagerAny
<<= xStringResourceManager
;
214 xDlgPSet
->setPropertyValue( aResourceResolverPropName
, aStringResourceManagerAny
);
220 Reference
< XControlModel
> DialogProviderImpl::createDialogModelForBasic() throw ( Exception
)
222 if ( !m_BasicInfo
.get() )
224 throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("No information to create dialog" ) ), Reference
< XInterface
>() );
225 Reference
< resource::XStringResourceManager
> xStringResourceManager
= getStringResourceFromDialogLibrary( m_BasicInfo
->mxDlgLib
);
227 rtl::OUString
aURL(RTL_CONSTASCII_USTRINGPARAM("" ));
228 Any aDialogSourceURL
;
229 aDialogSourceURL
<<= aURL
;
230 Reference
< XControlModel
> xCtrlModel( createDialogModel( m_BasicInfo
->mxInput
, xStringResourceManager
, aDialogSourceURL
), UNO_QUERY_THROW
);
234 Reference
< XControlModel
> DialogProviderImpl::createDialogModel( const ::rtl::OUString
& sURL
)
237 ::rtl::OUString
aURL( sURL
);
240 // TODO: use URL parsing class
241 // TODO: decoding of location
242 Reference
< XMultiComponentFactory
> xSMgr( m_xContext
->getServiceManager(), UNO_QUERY
);
246 throw RuntimeException(
247 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialogModel: Couldn't instantiate MultiComponent factory" ) ),
248 Reference
< XInterface
>() );
251 Reference
< uri::XUriReferenceFactory
> xFac (
252 xSMgr
->createInstanceWithContext( rtl::OUString::createFromAscii(
253 "com.sun.star.uri.UriReferenceFactory"), m_xContext
) , UNO_QUERY
);
257 throw RuntimeException(
258 ::rtl::OUString::createFromAscii( "DialogProviderImpl::getDialogModel(), could not instatiate UriReferenceFactory." ),
259 Reference
< XInterface
>() );
262 // i75778: Support non-script URLs
263 Reference
< io::XInputStream
> xInput
;
264 Reference
< container::XNameContainer
> xDialogLib
;
266 // Accept file URL to single dialog
267 bool bSingleDialog
= false;
269 Reference
< util::XMacroExpander
> xMacroExpander(
270 m_xContext
->getValueByName(
271 ::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ),
274 Reference
< uri::XUriReference
> uriRef
;
277 uriRef
= Reference
< uri::XUriReference
>( xFac
->parse( aURL
), UNO_QUERY
);
280 ::rtl::OUString errorMsg
= ::rtl::OUString::createFromAscii( "DialogProviderImpl::getDialogModel: failed to parse URI: " );
282 throw IllegalArgumentException( errorMsg
,
283 Reference
< XInterface
>(), 1 );
285 Reference
< uri::XVndSunStarExpandUrl
> sxUri( uriRef
, UNO_QUERY
);
289 aURL
= sxUri
->expand( xMacroExpander
);
292 Reference
< uri::XVndSunStarScriptUrl
> sfUri( uriRef
, UNO_QUERY
);
295 bSingleDialog
= true;
297 // Try any other URL with SimpleFileAccess
298 Reference
< ::com::sun::star::ucb::XSimpleFileAccess
> xSFI
=
299 Reference
< ::com::sun::star::ucb::XSimpleFileAccess
>( xSMgr
->createInstanceWithContext
300 ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), m_xContext
), UNO_QUERY
);
304 xInput
= xSFI
->openFileRead( aURL
);
311 ::rtl::OUString sDescription
= sfUri
->getName();
313 sal_Int32 nIndex
= 0;
315 ::rtl::OUString sLibName
= sDescription
.getToken( 0, (sal_Unicode
)'.', nIndex
);
316 ::rtl::OUString sDlgName
;
318 sDlgName
= sDescription
.getToken( 0, (sal_Unicode
)'.', nIndex
);
320 ::rtl::OUString sLocation
= sfUri
->getParameter(
321 ::rtl::OUString::createFromAscii( "location" ) );
324 // get dialog library container
325 // TODO: dialogs in packages
326 Reference
< XLibraryContainer
> xLibContainer
;
328 if ( sLocation
== ::rtl::OUString::createFromAscii( "application" ) )
330 xLibContainer
= Reference
< XLibraryContainer
>( SFX_APP()->GetDialogContainer(), UNO_QUERY
);
332 else if ( sLocation
== ::rtl::OUString::createFromAscii( "document" ) )
334 Reference
< XEmbeddedScripts
> xDocumentScripts( m_xModel
, UNO_QUERY
);
335 if ( xDocumentScripts
.is() )
337 xLibContainer
.set( xDocumentScripts
->getDialogLibraries(), UNO_QUERY
);
338 OSL_ENSURE( xLibContainer
.is(),
339 "DialogProviderImpl::createDialogModel: invalid dialog container!" );
344 Sequence
< ::rtl::OUString
> aOpenDocsTdocURLs( MiscUtils::allOpenTDocUrls( m_xContext
) );
345 const ::rtl::OUString
* pTdocURL
= aOpenDocsTdocURLs
.getConstArray();
346 const ::rtl::OUString
* pTdocURLEnd
= aOpenDocsTdocURLs
.getConstArray() + aOpenDocsTdocURLs
.getLength();
347 for ( ; pTdocURL
!= pTdocURLEnd
; ++pTdocURL
)
349 Reference
< frame::XModel
> xModel( MiscUtils::tDocUrlToModel( *pTdocURL
) );
350 OSL_ENSURE( xModel
.is(), "DialogProviderImpl::createDialogModel: invalid document model!" );
354 ::rtl::OUString sDocURL
= xModel
->getURL();
355 if ( sDocURL
.getLength() == 0 )
357 ::comphelper::NamedValueCollection
aModelArgs( xModel
->getArgs() );
358 sDocURL
= aModelArgs
.getOrDefault( "Title", sDocURL
);
361 if ( sLocation
!= sDocURL
)
364 Reference
< XEmbeddedScripts
> xDocumentScripts( m_xModel
, UNO_QUERY
);
365 if ( !xDocumentScripts
.is() )
368 xLibContainer
.set( xDocumentScripts
->getDialogLibraries(), UNO_QUERY
);
369 OSL_ENSURE( xLibContainer
.is(),
370 "DialogProviderImpl::createDialogModel: invalid dialog container!" );
374 // get input stream provider
375 Reference
< io::XInputStreamProvider
> xISP
;
376 if ( xLibContainer
.is() )
378 // load dialog library
379 if ( !xLibContainer
->isLibraryLoaded( sLibName
) )
380 xLibContainer
->loadLibrary( sLibName
);
382 // get dialog library
383 if ( xLibContainer
->hasByName( sLibName
) )
385 Any aElement
= xLibContainer
->getByName( sLibName
);
386 aElement
>>= xDialogLib
;
389 if ( xDialogLib
.is() )
391 // get input stream provider
392 if ( xDialogLib
->hasByName( sDlgName
) )
394 Any aElement
= xDialogLib
->getByName( sDlgName
);
400 throw IllegalArgumentException(
401 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialogModel: dialog not found!" ) ),
402 Reference
< XInterface
>(), 1 );
407 throw IllegalArgumentException(
408 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialogModel: library not found!" ) ),
409 Reference
< XInterface
>(), 1 );
414 throw IllegalArgumentException(
415 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getDialog: library container not found!" ) ),
416 Reference
< XInterface
>(), 1 );
420 xInput
= xISP
->createInputStream();
421 msDialogLibName
= sLibName
;
424 // import dialog model
425 Reference
< XControlModel
> xCtrlModel
;
426 if ( xInput
.is() && m_xContext
.is() )
428 Reference
< resource::XStringResourceManager
> xStringResourceManager
;
431 INetURLObject
aInetObj( aURL
);
432 ::rtl::OUString aDlgName
= aInetObj
.GetBase();
433 aInetObj
.removeSegment();
434 ::rtl::OUString aDlgLocation
= aInetObj
.GetMainURL( INetURLObject::NO_DECODE
);
435 bool bReadOnly
= true;
436 ::com::sun ::star::lang::Locale aLocale
= Application::GetSettings().GetUILocale();
437 ::rtl::OUString aComment
;
439 Sequence
<Any
> aArgs( 6 );
440 aArgs
[0] <<= aDlgLocation
;
441 aArgs
[1] <<= bReadOnly
;
442 aArgs
[2] <<= aLocale
;
443 aArgs
[3] <<= aDlgName
;
444 aArgs
[4] <<= aComment
;
446 Reference
< task::XInteractionHandler
> xDummyHandler
;
447 aArgs
[5] <<= xDummyHandler
;
448 Reference
< XMultiComponentFactory
> xSMgr_( m_xContext
->getServiceManager(), UNO_QUERY_THROW
);
450 xStringResourceManager
= Reference
< resource::XStringResourceManager
>( xSMgr_
->createInstanceWithContext
451 ( ::rtl::OUString::createFromAscii( "com.sun.star.resource.StringResourceWithLocation" ),
452 m_xContext
), UNO_QUERY
);
453 if( xStringResourceManager
.is() )
455 Reference
< XInitialization
> xInit( xStringResourceManager
, UNO_QUERY
);
457 xInit
->initialize( aArgs
);
460 else if( xDialogLib
.is() )
462 xStringResourceManager
= getStringResourceFromDialogLibrary( xDialogLib
);
465 Any aDialogSourceURLAny
;
466 aDialogSourceURLAny
<<= aURL
;
468 Reference
< container::XNameContainer
> xDialogModel( createDialogModel( xInput
, xStringResourceManager
, aDialogSourceURLAny
), UNO_QUERY_THROW
);
470 xCtrlModel
= Reference
< XControlModel
>( xDialogModel
, UNO_QUERY
);
475 // -----------------------------------------------------------------------------
477 Reference
< XControl
> DialogProviderImpl::createDialogControl
478 ( const Reference
< XControlModel
>& rxDialogModel
, const Reference
< XWindowPeer
>& xParent
)
480 OSL_ENSURE( rxDialogModel
.is(), "DialogProviderImpl::getDialogControl: no dialog model" );
482 Reference
< XControl
> xDialogControl
;
484 if ( m_xContext
.is() )
486 Reference
< XMultiComponentFactory
> xSMgr( m_xContext
->getServiceManager() );
490 xDialogControl
= Reference
< XControl
>( xSMgr
->createInstanceWithContext(
491 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialog" ) ), m_xContext
), UNO_QUERY
);
493 if ( xDialogControl
.is() )
496 if ( rxDialogModel
.is() )
497 xDialogControl
->setModel( rxDialogModel
);
500 Reference
< XWindow
> xW( xDialogControl
, UNO_QUERY
);
502 xW
->setVisible( sal_False
);
504 // get the parent of the dialog control
505 Reference
< XWindowPeer
> xPeer
;
510 else if ( m_xModel
.is() )
512 Reference
< frame::XController
> xController( m_xModel
->getCurrentController(), UNO_QUERY
);
513 if ( xController
.is() )
515 Reference
< frame::XFrame
> xFrame( xController
->getFrame(), UNO_QUERY
);
517 xPeer
= Reference
< XWindowPeer
>( xFrame
->getContainerWindow(), UNO_QUERY
);
522 Reference
< XToolkit
> xToolkit( xSMgr
->createInstanceWithContext(
523 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ), m_xContext
), UNO_QUERY
);
525 xDialogControl
->createPeer( xToolkit
, xPeer
);
530 return xDialogControl
;
533 // -----------------------------------------------------------------------------
535 void DialogProviderImpl::attachControlEvents(
536 const Reference
< XControl
>& rxControl
,
537 const Reference
< XInterface
>& rxHandler
,
538 const Reference
< XIntrospectionAccess
>& rxIntrospectionAccess
,
539 bool bDialogProviderMode
, const rtl::OUString
& sDialogLibName
)
541 if ( rxControl
.is() )
543 Reference
< XControlContainer
> xControlContainer( rxControl
, UNO_QUERY
);
545 if ( xControlContainer
.is() )
547 Sequence
< Reference
< XControl
> > aControls
= xControlContainer
->getControls();
548 const Reference
< XControl
>* pControls
= aControls
.getConstArray();
549 sal_Int32 nControlCount
= aControls
.getLength();
551 Sequence
< Reference
< XInterface
> > aObjects( nControlCount
+ 1 );
552 Reference
< XInterface
>* pObjects
= aObjects
.getArray();
553 for ( sal_Int32 i
= 0; i
< nControlCount
; ++i
)
555 pObjects
[i
] = Reference
< XInterface
>( pControls
[i
], UNO_QUERY
);
558 // also add the dialog control itself to the sequence
559 pObjects
[nControlCount
] = Reference
< XInterface
>( rxControl
, UNO_QUERY
);
561 Reference
< XScriptEventsAttacher
> xScriptEventsAttacher
= new DialogEventsAttacherImpl
562 ( m_xContext
, m_xModel
, rxControl
, rxHandler
, rxIntrospectionAccess
,
563 bDialogProviderMode
, ( m_BasicInfo
.get() ? m_BasicInfo
->mxBasicRTLListener
: NULL
), msDialogLibName
);
566 xScriptEventsAttacher
->attachEvents( aObjects
, Reference
< XScriptListener
>(), aHelper
);
571 Reference
< XIntrospectionAccess
> DialogProviderImpl::inspectHandler( const Reference
< XInterface
>& rxHandler
)
573 Reference
< XIntrospectionAccess
> xIntrospectionAccess
;
574 static Reference
< XIntrospection
> xIntrospection
;
576 if( !rxHandler
.is() )
577 return xIntrospectionAccess
;
579 if( !xIntrospection
.is() )
581 Reference
< XMultiComponentFactory
> xSMgr( m_xContext
->getServiceManager(), UNO_QUERY
);
584 throw RuntimeException(
585 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::getIntrospectionAccess: Couldn't instantiate MultiComponent factory" ) ),
586 Reference
< XInterface
>() );
589 // Get introspection service
590 Reference
< XInterface
> xI
= xSMgr
->createInstanceWithContext
591 ( rtl::OUString::createFromAscii("com.sun.star.beans.Introspection"), m_xContext
);
593 xIntrospection
= Reference
< XIntrospection
>::query( xI
);
596 if( xIntrospection
.is() )
602 aHandlerAny
<<= rxHandler
;
603 xIntrospectionAccess
= xIntrospection
->inspect( aHandlerAny
);
605 catch( RuntimeException
& )
607 xIntrospectionAccess
.clear();
610 return xIntrospectionAccess
;
614 // -----------------------------------------------------------------------------
616 // -----------------------------------------------------------------------------
618 ::rtl::OUString
DialogProviderImpl::getImplementationName( ) throw (RuntimeException
)
620 return getImplementationName_DialogProviderImpl();
623 // -----------------------------------------------------------------------------
625 sal_Bool
DialogProviderImpl::supportsService( const ::rtl::OUString
& rServiceName
) throw (RuntimeException
)
627 Sequence
< ::rtl::OUString
> aNames( getSupportedServiceNames() );
628 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
629 const ::rtl::OUString
* pEnd
= pNames
+ aNames
.getLength();
630 for ( ; pNames
!= pEnd
&& !pNames
->equals( rServiceName
); ++pNames
)
633 return pNames
!= pEnd
;
636 // -----------------------------------------------------------------------------
638 Sequence
< ::rtl::OUString
> DialogProviderImpl::getSupportedServiceNames( ) throw (RuntimeException
)
640 return getSupportedServiceNames_DialogProviderImpl();
643 // -----------------------------------------------------------------------------
645 // -----------------------------------------------------------------------------
647 void DialogProviderImpl::initialize( const Sequence
< Any
>& aArguments
) throw (Exception
, RuntimeException
)
649 ::osl::MutexGuard
aGuard( getMutex() );
651 if ( aArguments
.getLength() == 1 )
653 aArguments
[0] >>= m_xModel
;
655 if ( !m_xModel
.is() )
657 throw RuntimeException(
658 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::initialize: invalid argument format!" ) ),
659 Reference
< XInterface
>() );
662 else if ( aArguments
.getLength() == 4 )
664 // call from RTL_Impl_CreateUnoDialog
665 aArguments
[0] >>= m_xModel
;
666 m_BasicInfo
.reset( new BasicRTLParams() );
667 m_BasicInfo
->mxInput
.set( aArguments
[ 1 ], UNO_QUERY_THROW
);
668 // allow null mxDlgLib, a document dialog instantiated from
669 // from application basic is unable to provide ( or find ) it's
671 aArguments
[ 2 ] >>= m_BasicInfo
->mxDlgLib
;
672 // leave the possibility to optionally allow the old dialog creation
673 // to use the new XScriptListener ( which converts the old style macro
675 m_BasicInfo
->mxBasicRTLListener
.set( aArguments
[ 3 ], UNO_QUERY
);
677 else if ( aArguments
.getLength() > 4 )
679 throw RuntimeException(
680 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::initialize: invalid number of arguments!" ) ),
681 Reference
< XInterface
>() );
685 // -----------------------------------------------------------------------------
687 // -----------------------------------------------------------------------------
689 static ::rtl::OUString aDecorationPropName
=
690 ::rtl::OUString::createFromAscii( "Decoration" );
691 static ::rtl::OUString aTitlePropName
=
692 ::rtl::OUString::createFromAscii( "Title" );
694 Reference
< XControl
> DialogProviderImpl::createDialogImpl(
695 const ::rtl::OUString
& URL
, const Reference
< XInterface
>& xHandler
,
696 const Reference
< XWindowPeer
>& xParent
, bool bDialogProviderMode
)
697 throw (IllegalArgumentException
, RuntimeException
)
699 // if the dialog is located in a document, the document must already be open!
701 ::osl::MutexGuard
aGuard( getMutex() );
704 // m_xHandler = xHandler;
706 //Reference< XDialog > xDialog;
707 Reference
< XControl
> xCtrl
;
708 Reference
< XControlModel
> xCtrlMod
;
709 // add support for basic RTL_FUNCTION
710 if ( m_BasicInfo
.get() )
711 xCtrlMod
= createDialogModelForBasic();
714 OSL_ENSURE( URL
.getLength(), "DialogProviderImpl::getDialog: no URL!" );
715 xCtrlMod
= createDialogModel( URL
);
719 // i83963 Force decoration
720 if( bDialogProviderMode
)
722 uno::Reference
< beans::XPropertySet
> xDlgModPropSet( xCtrlMod
, uno::UNO_QUERY
);
723 if( xDlgModPropSet
.is() )
725 bool bDecoration
= true;
728 Any aDecorationAny
= xDlgModPropSet
->getPropertyValue( aDecorationPropName
);
729 aDecorationAny
>>= bDecoration
;
732 xDlgModPropSet
->setPropertyValue( aDecorationPropName
, makeAny( true ) );
733 xDlgModPropSet
->setPropertyValue( aTitlePropName
, makeAny( ::rtl::OUString() ) );
736 catch( UnknownPropertyException
& )
741 xCtrl
= Reference
< XControl
>( createDialogControl( xCtrlMod
, xParent
) );
744 //xDialog = Reference< XDialog >( xCtrl, UNO_QUERY );
745 Reference
< XIntrospectionAccess
> xIntrospectionAccess
= inspectHandler( xHandler
);
746 attachControlEvents( xCtrl
, xHandler
, xIntrospectionAccess
, bDialogProviderMode
, msDialogLibName
);
753 Reference
< XDialog
> DialogProviderImpl::createDialog( const ::rtl::OUString
& URL
)
754 throw (IllegalArgumentException
, RuntimeException
)
756 Reference
< XInterface
> xDummyHandler
;
757 Reference
< XWindowPeer
> xDummyPeer
;
758 Reference
< XControl
> xControl
= DialogProviderImpl::createDialogImpl( URL
, xDummyHandler
, xDummyPeer
, true );
759 Reference
< XDialog
> xDialog( xControl
, UNO_QUERY
);
763 Reference
< XDialog
> DialogProviderImpl::createDialogWithHandler(
764 const ::rtl::OUString
& URL
, const Reference
< XInterface
>& xHandler
)
765 throw (IllegalArgumentException
, RuntimeException
)
769 throw IllegalArgumentException(
770 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::createDialogWithHandler: Invalid xHandler!" ) ),
771 Reference
< XInterface
>(), 1 );
773 Reference
< XWindowPeer
> xDummyPeer
;
774 Reference
< XControl
> xControl
= DialogProviderImpl::createDialogImpl( URL
, xHandler
, xDummyPeer
, true );
775 Reference
< XDialog
> xDialog( xControl
, UNO_QUERY
);
779 Reference
< XWindow
> DialogProviderImpl::createContainerWindow(
780 const ::rtl::OUString
& URL
, const ::rtl::OUString
& WindowType
,
781 const Reference
< XWindowPeer
>& xParent
, const Reference
< XInterface
>& xHandler
)
782 throw (::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
)
784 (void)WindowType
; // for future use
787 throw IllegalArgumentException(
788 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogProviderImpl::createContainerWindow: Invalid xParent!" ) ),
789 Reference
< XInterface
>(), 1 );
791 Reference
< XControl
> xControl
= DialogProviderImpl::createDialogImpl( URL
, xHandler
, xParent
, false );
792 Reference
< XWindow
> xWindow( xControl
, UNO_QUERY
);
797 // =============================================================================
798 // component operations
799 // =============================================================================
801 static Reference
< XInterface
> SAL_CALL
create_DialogProviderImpl(
802 Reference
< XComponentContext
> const & xContext
)
805 return static_cast< lang::XTypeProvider
* >( new DialogProviderImpl( xContext
) );
808 // -----------------------------------------------------------------------------
810 static struct ::cppu::ImplementationEntry s_component_entries
[] =
813 create_DialogProviderImpl
, getImplementationName_DialogProviderImpl
,
814 getSupportedServiceNames_DialogProviderImpl
, ::cppu::createSingleComponentFactory
,
820 // -----------------------------------------------------------------------------
822 //.........................................................................
823 } // namespace dlgprov
824 //.........................................................................
827 // =============================================================================
829 // =============================================================================
833 void SAL_CALL
component_getImplementationEnvironment(
834 const sal_Char
** ppEnvTypeName
, uno_Environment
** ppEnv
)
838 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
;
841 sal_Bool SAL_CALL
component_writeInfo(
842 lang::XMultiServiceFactory
* pServiceManager
, registry::XRegistryKey
* pRegistryKey
)
844 return ::cppu::component_writeInfoHelper(
845 pServiceManager
, pRegistryKey
, ::dlgprov::s_component_entries
);
848 void * SAL_CALL
component_getFactory(
849 const sal_Char
* pImplName
, lang::XMultiServiceFactory
* pServiceManager
,
850 registry::XRegistryKey
* pRegistryKey
)
852 return ::cppu::component_getFactoryHelper(
853 pImplName
, pServiceManager
, pRegistryKey
, ::dlgprov::s_component_entries
);