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