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 4 : OUString SAL_CALL _getImplementationName()
70 : {
71 4 : 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)
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 4 : 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 4 : Reference< container::XNameContainer > lcl_createControlModel(const Reference< XComponentContext >& i_xContext)
126 : {
127 4 : Reference< XMultiComponentFactory > xSMgr_( i_xContext->getServiceManager(), UNO_QUERY_THROW );
128 4 : Reference< container::XNameContainer > xControlModel( xSMgr_->createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", i_xContext ), UNO_QUERY_THROW );
129 4 : return xControlModel;
130 : }
131 4 : 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 4 : Reference< container::XNameContainer > xDialogModel( lcl_createControlModel(i_xContext) );
138 :
139 8 : OUString aDlgSrcUrlPropName( "DialogSourceURL" );
140 8 : Reference< beans::XPropertySet > xDlgPropSet( xDialogModel, UNO_QUERY );
141 4 : 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 4 : ::xmlscript::importDialogModel( xInput, xDialogModel, i_xContext, xModel );
151 :
152 : // Set resource property
153 4 : 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 8 : return xDialogModel;
162 : }
163 :
164 : // component operations
165 :
166 :
167 4 : static OUString getImplementationName_DialogProviderImpl()
168 : {
169 : static OUString* pImplName = 0;
170 4 : if ( !pImplName )
171 : {
172 4 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
173 4 : if ( !pImplName )
174 : {
175 4 : static OUString aImplName( "com.sun.star.comp.scripting.DialogProvider" );
176 4 : pImplName = &aImplName;
177 4 : }
178 : }
179 4 : return *pImplName;
180 : }
181 :
182 :
183 :
184 4 : static Sequence< OUString > getSupportedServiceNames_DialogProviderImpl()
185 : {
186 : static Sequence< OUString >* pNames = 0;
187 4 : if ( !pNames )
188 : {
189 4 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
190 4 : if ( !pNames )
191 : {
192 4 : static Sequence< OUString > aNames(3);
193 4 : aNames[0] = "com.sun.star.awt.DialogProvider";
194 4 : aNames[1] = "com.sun.star.awt.DialogProvider2";
195 4 : aNames[2] = "com.sun.star.awt.ContainerWindowProvider";
196 4 : pNames = &aNames;
197 4 : }
198 : }
199 4 : return *pNames;
200 : }
201 :
202 :
203 :
204 : // mutex
205 :
206 :
207 12 : ::osl::Mutex& getMutex()
208 : {
209 : static ::osl::Mutex* s_pMutex = 0;
210 12 : if ( !s_pMutex )
211 : {
212 2 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
213 2 : if ( !s_pMutex )
214 : {
215 2 : static ::osl::Mutex s_aMutex;
216 2 : s_pMutex = &s_aMutex;
217 2 : }
218 : }
219 12 : return *s_pMutex;
220 : }
221 :
222 :
223 :
224 : // DialogProviderImpl
225 :
226 :
227 8 : DialogProviderImpl::DialogProviderImpl( const Reference< XComponentContext >& rxContext )
228 : :m_xContext( rxContext )
229 8 : ,m_xModel( 0 )
230 : {
231 8 : }
232 :
233 :
234 :
235 16 : DialogProviderImpl::~DialogProviderImpl()
236 : {
237 16 : }
238 :
239 :
240 :
241 4 : Reference< resource::XStringResourceManager > getStringResourceFromDialogLibrary
242 : ( Reference< container::XNameContainer > xDialogLib )
243 : {
244 4 : Reference< resource::XStringResourceManager > xStringResourceManager;
245 4 : if( xDialogLib.is() )
246 : {
247 4 : Reference< resource::XStringResourceSupplier > xStringResourceSupplier( xDialogLib, UNO_QUERY );
248 4 : if( xStringResourceSupplier.is() )
249 : {
250 : Reference< resource::XStringResourceResolver >
251 4 : xStringResourceResolver = xStringResourceSupplier->getStringResource();
252 :
253 8 : xStringResourceManager =
254 8 : Reference< resource::XStringResourceManager >( xStringResourceResolver, UNO_QUERY );
255 4 : }
256 : }
257 4 : return xStringResourceManager;
258 : }
259 :
260 4 : 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 4 : 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" );
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 4 : Reference< XControlModel > DialogProviderImpl::createDialogModel( const OUString& sURL )
283 : {
284 :
285 4 : OUString aURL( sURL );
286 :
287 : // parse URL
288 : // TODO: use URL parsing class
289 : // TODO: decoding of location
290 :
291 8 : Reference< uri::XUriReferenceFactory > xFac ( uri::UriReferenceFactory::create( m_xContext ) );
292 :
293 : // i75778: Support non-script URLs
294 8 : Reference< io::XInputStream > xInput;
295 8 : Reference< container::XNameContainer > xDialogLib;
296 :
297 : // Accept file URL to single dialog
298 4 : bool bSingleDialog = false;
299 :
300 : Reference< util::XMacroExpander > xMacroExpander =
301 8 : util::theMacroExpander::get(m_xContext);
302 :
303 8 : Reference< uri::XUriReference > uriRef;
304 : for (;;)
305 : {
306 4 : uriRef = Reference< uri::XUriReference >( xFac->parse( aURL ), UNO_QUERY );
307 4 : 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 4 : Reference < uri::XVndSunStarExpandUrl > sxUri( uriRef, UNO_QUERY );
315 4 : if( !sxUri.is() )
316 4 : break;
317 :
318 0 : aURL = sxUri->expand( xMacroExpander );
319 0 : }
320 :
321 8 : Reference < uri::XVndSunStarScriptUrl > sfUri( uriRef, UNO_QUERY );
322 4 : 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 4 : OUString sDescription = sfUri->getName();
339 :
340 4 : sal_Int32 nIndex = 0;
341 :
342 8 : OUString sLibName = sDescription.getToken( 0, (sal_Unicode)'.', nIndex );
343 8 : OUString sDlgName;
344 4 : if ( nIndex != -1 )
345 4 : sDlgName = sDescription.getToken( 0, (sal_Unicode)'.', nIndex );
346 :
347 4 : OUString sLocation = sfUri->getParameter(
348 8 : OUString("location") );
349 :
350 :
351 : // get dialog library container
352 : // TODO: dialogs in packages
353 8 : Reference< XLibraryContainer > xLibContainer;
354 :
355 4 : if ( sLocation == "application" )
356 : {
357 0 : xLibContainer = Reference< XLibraryContainer >( SfxGetpApp()->GetDialogContainer(), UNO_QUERY );
358 : }
359 4 : else if ( sLocation == "document" )
360 : {
361 4 : Reference< XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
362 4 : if ( xDocumentScripts.is() )
363 : {
364 4 : xLibContainer.set( xDocumentScripts->getDialogLibraries(), UNO_QUERY );
365 : OSL_ENSURE( xLibContainer.is(),
366 : "DialogProviderImpl::createDialogModel: invalid dialog container!" );
367 4 : }
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 8 : Reference< io::XInputStreamProvider > xISP;
403 4 : if ( xLibContainer.is() )
404 : {
405 : // load dialog library
406 4 : if ( !xLibContainer->isLibraryLoaded( sLibName ) )
407 0 : xLibContainer->loadLibrary( sLibName );
408 :
409 : // get dialog library
410 4 : if ( xLibContainer->hasByName( sLibName ) )
411 : {
412 4 : Any aElement = xLibContainer->getByName( sLibName );
413 4 : aElement >>= xDialogLib;
414 : }
415 :
416 4 : if ( xDialogLib.is() )
417 : {
418 : // get input stream provider
419 4 : if ( xDialogLib->hasByName( sDlgName ) )
420 : {
421 4 : Any aElement = xDialogLib->getByName( sDlgName );
422 4 : aElement >>= xISP;
423 : }
424 :
425 4 : if ( !xISP.is() )
426 : {
427 : throw IllegalArgumentException(
428 : "DialogProviderImpl::getDialogModel: dialog not found!",
429 0 : Reference< XInterface >(), 1 );
430 : }
431 : }
432 : else
433 : {
434 : throw IllegalArgumentException(
435 : "DialogProviderImpl::getDialogModel: library not found!",
436 0 : Reference< XInterface >(), 1 );
437 : }
438 : }
439 : else
440 : {
441 : throw IllegalArgumentException(
442 : "DialogProviderImpl::getDialog: library container not found!",
443 0 : Reference< XInterface >(), 1 );
444 : }
445 :
446 4 : if ( xISP.is() )
447 4 : xInput = xISP->createInputStream();
448 8 : msDialogLibName = sLibName;
449 : }
450 :
451 : // import dialog model
452 4 : Reference< XControlModel > xCtrlModel;
453 4 : if ( xInput.is() && m_xContext.is() )
454 : {
455 4 : Reference< resource::XStringResourceManager > xStringResourceManager;
456 4 : if( bSingleDialog )
457 : {
458 0 : xStringResourceManager = lcl_getStringResourceManager(m_xContext,aURL);
459 : }
460 4 : else if( xDialogLib.is() )
461 : {
462 4 : xStringResourceManager = getStringResourceFromDialogLibrary( xDialogLib );
463 : }
464 :
465 8 : Any aDialogSourceURLAny;
466 4 : aDialogSourceURLAny <<= aURL;
467 :
468 8 : Reference< container::XNameContainer > xDialogModel( createDialogModel( xInput , xStringResourceManager, aDialogSourceURLAny ), UNO_QUERY_THROW);
469 :
470 8 : xCtrlModel = Reference< XControlModel >( xDialogModel, UNO_QUERY );
471 : }
472 8 : return xCtrlModel;
473 : }
474 :
475 :
476 :
477 4 : 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 4 : Reference< XUnoControlDialog > xDialogControl;
483 :
484 4 : if ( m_xContext.is() )
485 : {
486 4 : xDialogControl = UnoControlDialog::create( m_xContext );
487 :
488 : // set the model
489 4 : if ( rxDialogModel.is() )
490 4 : xDialogControl->setModel( rxDialogModel );
491 :
492 : // set visible
493 4 : xDialogControl->setVisible( sal_False );
494 :
495 : // get the parent of the dialog control
496 4 : Reference< XWindowPeer > xPeer;
497 4 : if( xParent.is() )
498 : {
499 0 : xPeer = xParent;
500 : }
501 4 : else if ( m_xModel.is() )
502 : {
503 4 : Reference< frame::XController > xController( m_xModel->getCurrentController(), UNO_QUERY );
504 4 : if ( xController.is() )
505 : {
506 4 : Reference< frame::XFrame > xFrame( xController->getFrame(), UNO_QUERY );
507 4 : if ( xFrame.is() )
508 4 : xPeer = Reference< XWindowPeer>( xFrame->getContainerWindow(), UNO_QUERY );
509 4 : }
510 : }
511 :
512 : // create a peer
513 8 : Reference< XToolkit> xToolkit( Toolkit::create( m_xContext ), UNO_QUERY_THROW );
514 8 : xDialogControl->createPeer( xToolkit, xPeer );
515 : }
516 :
517 4 : return xDialogControl;
518 : }
519 :
520 :
521 :
522 4 : void DialogProviderImpl::attachControlEvents(
523 : const Reference< XControl >& rxControl,
524 : const Reference< XInterface >& rxHandler,
525 : const Reference< XIntrospectionAccess >& rxIntrospectionAccess,
526 : bool bDialogProviderMode )
527 : {
528 4 : if ( rxControl.is() )
529 : {
530 4 : Reference< XControlContainer > xControlContainer( rxControl, UNO_QUERY );
531 :
532 4 : if ( xControlContainer.is() )
533 : {
534 4 : Sequence< Reference< XControl > > aControls = xControlContainer->getControls();
535 4 : const Reference< XControl >* pControls = aControls.getConstArray();
536 4 : sal_Int32 nControlCount = aControls.getLength();
537 :
538 8 : Sequence< Reference< XInterface > > aObjects( nControlCount + 1 );
539 4 : Reference< XInterface >* pObjects = aObjects.getArray();
540 16 : for ( sal_Int32 i = 0; i < nControlCount; ++i )
541 : {
542 12 : pObjects[i] = Reference<XInterface>( pControls[i], UNO_QUERY );
543 : }
544 :
545 : // also add the dialog control itself to the sequence
546 4 : pObjects[nControlCount] = Reference<XInterface>( rxControl, UNO_QUERY );
547 :
548 : Reference< XScriptEventsAttacher > xScriptEventsAttacher = new DialogEventsAttacherImpl
549 : ( m_xContext, m_xModel, rxControl, rxHandler, rxIntrospectionAccess,
550 8 : bDialogProviderMode, ( m_BasicInfo.get() ? m_BasicInfo->mxBasicRTLListener : NULL ), msDialogLibName );
551 :
552 8 : Any aHelper;
553 8 : xScriptEventsAttacher->attachEvents( aObjects, Reference< XScriptListener >(), aHelper );
554 4 : }
555 : }
556 4 : }
557 :
558 4 : Reference< XIntrospectionAccess > DialogProviderImpl::inspectHandler( const Reference< XInterface >& rxHandler )
559 : {
560 4 : Reference< XIntrospectionAccess > xIntrospectionAccess;
561 4 : static Reference< XIntrospection > xIntrospection;
562 :
563 4 : if( !rxHandler.is() )
564 4 : 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 4 : void DialogProviderImpl::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException, std::exception)
611 : {
612 4 : ::osl::MutexGuard aGuard( getMutex() );
613 :
614 4 : if ( aArguments.getLength() == 1 )
615 : {
616 4 : aArguments[0] >>= m_xModel;
617 :
618 4 : if ( !m_xModel.is() )
619 : {
620 0 : throw RuntimeException( "DialogProviderImpl::initialize: invalid argument format!" );
621 : }
622 : }
623 0 : else if ( aArguments.getLength() == 4 )
624 : {
625 : // call from RTL_Impl_CreateUnoDialog
626 0 : aArguments[0] >>= m_xModel;
627 0 : m_BasicInfo.reset( new BasicRTLParams() );
628 0 : m_BasicInfo->mxInput.set( aArguments[ 1 ], UNO_QUERY_THROW );
629 : // allow null mxDlgLib, a document dialog instantiated from
630 : // from application basic is unable to provide ( or find ) it's
631 : // Library
632 0 : aArguments[ 2 ] >>= m_BasicInfo->mxDlgLib;
633 : // leave the possibility to optionally allow the old dialog creation
634 : // to use the new XScriptListener ( which converts the old style macro
635 : // to a SF url )
636 0 : m_BasicInfo->mxBasicRTLListener.set( aArguments[ 3 ], UNO_QUERY);
637 : }
638 0 : else if ( aArguments.getLength() > 4 )
639 : {
640 0 : throw RuntimeException( "DialogProviderImpl::initialize: invalid number of arguments!" );
641 4 : }
642 4 : }
643 :
644 :
645 : // XDialogProvider
646 :
647 :
648 4 : static OUString aDecorationPropName("Decoration");
649 4 : static OUString aTitlePropName("Title");
650 :
651 4 : Reference < XControl > DialogProviderImpl::createDialogImpl(
652 : const OUString& URL, const Reference< XInterface >& xHandler,
653 : const Reference< XWindowPeer >& xParent, bool bDialogProviderMode )
654 : throw (IllegalArgumentException, RuntimeException)
655 : {
656 : // if the dialog is located in a document, the document must already be open!
657 :
658 4 : ::osl::MutexGuard aGuard( getMutex() );
659 :
660 :
661 : // m_xHandler = xHandler;
662 :
663 : //Reference< XDialog > xDialog;
664 4 : Reference< XControl > xCtrl;
665 8 : Reference< XControlModel > xCtrlMod;
666 : try
667 : {
668 : // add support for basic RTL_FUNCTION
669 4 : if ( m_BasicInfo.get() )
670 0 : xCtrlMod = createDialogModelForBasic();
671 : else
672 : {
673 : OSL_ENSURE( !URL.isEmpty(), "DialogProviderImpl::getDialog: no URL!" );
674 4 : xCtrlMod = createDialogModel( URL );
675 : }
676 : }
677 0 : catch ( const RuntimeException& ) { throw; }
678 0 : catch ( const Exception& )
679 : {
680 0 : const Any aError( ::cppu::getCaughtException() );
681 0 : throw WrappedTargetRuntimeException( OUString(), *this, aError );
682 : }
683 4 : if ( xCtrlMod.is() )
684 : {
685 : // i83963 Force decoration
686 4 : if( bDialogProviderMode )
687 : {
688 4 : uno::Reference< beans::XPropertySet > xDlgModPropSet( xCtrlMod, uno::UNO_QUERY );
689 4 : if( xDlgModPropSet.is() )
690 : {
691 4 : bool bDecoration = true;
692 : try
693 : {
694 4 : Any aDecorationAny = xDlgModPropSet->getPropertyValue( aDecorationPropName );
695 4 : aDecorationAny >>= bDecoration;
696 4 : if( !bDecoration )
697 : {
698 0 : xDlgModPropSet->setPropertyValue( aDecorationPropName, makeAny( true ) );
699 0 : xDlgModPropSet->setPropertyValue( aTitlePropName, makeAny( OUString() ) );
700 4 : }
701 : }
702 0 : catch( UnknownPropertyException& )
703 : {}
704 4 : }
705 : }
706 :
707 4 : xCtrl = Reference< XControl >( createDialogControl( xCtrlMod, xParent ) );
708 4 : if ( xCtrl.is() )
709 : {
710 : //xDialog = Reference< XDialog >( xCtrl, UNO_QUERY );
711 4 : Reference< XIntrospectionAccess > xIntrospectionAccess = inspectHandler( xHandler );
712 4 : attachControlEvents( xCtrl, xHandler, xIntrospectionAccess, bDialogProviderMode );
713 : }
714 : }
715 :
716 8 : return xCtrl;
717 : }
718 :
719 4 : Reference < XDialog > DialogProviderImpl::createDialog( const OUString& URL )
720 : throw (IllegalArgumentException, RuntimeException, std::exception)
721 : {
722 4 : Reference< XInterface > xDummyHandler;
723 8 : Reference< XWindowPeer > xDummyPeer;
724 8 : Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xDummyHandler, xDummyPeer, true );
725 4 : Reference< XDialog > xDialog( xControl, UNO_QUERY );
726 8 : return xDialog;
727 : }
728 :
729 0 : Reference < XDialog > DialogProviderImpl::createDialogWithHandler(
730 : const OUString& URL, const Reference< XInterface >& xHandler )
731 : throw (IllegalArgumentException, RuntimeException, std::exception)
732 : {
733 0 : if( !xHandler.is() )
734 : {
735 : throw IllegalArgumentException(
736 : "DialogProviderImpl::createDialogWithHandler: Invalid xHandler!",
737 0 : Reference< XInterface >(), 1 );
738 : }
739 0 : Reference< XWindowPeer > xDummyPeer;
740 0 : Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xDummyPeer, true );
741 0 : Reference< XDialog > xDialog( xControl, UNO_QUERY );
742 0 : return xDialog;
743 : }
744 :
745 0 : Reference < XDialog > DialogProviderImpl::createDialogWithArguments(
746 : const OUString& URL, const Sequence< NamedValue >& Arguments )
747 : throw (IllegalArgumentException, RuntimeException, std::exception)
748 : {
749 0 : ::comphelper::NamedValueCollection aArguments( Arguments );
750 :
751 0 : Reference< XWindowPeer > xParentPeer;
752 0 : if ( aArguments.has( "ParentWindow" ) )
753 : {
754 0 : const Any aParentWindow( aArguments.get( "ParentWindow" ) );
755 0 : if ( !( aParentWindow >>= xParentPeer ) )
756 : {
757 0 : const Reference< XControl > xParentControl( aParentWindow, UNO_QUERY );
758 0 : if ( xParentControl.is() )
759 0 : xParentPeer = xParentControl->getPeer();
760 0 : }
761 : }
762 :
763 0 : const Reference< XInterface > xHandler( aArguments.get( "EventHandler" ), UNO_QUERY );
764 :
765 0 : Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xParentPeer, true );
766 0 : Reference< XDialog > xDialog( xControl, UNO_QUERY );
767 0 : return xDialog;
768 : }
769 :
770 0 : Reference< XWindow > DialogProviderImpl::createContainerWindow(
771 : const OUString& URL, const OUString& WindowType,
772 : const Reference< XWindowPeer >& xParent, const Reference< XInterface >& xHandler )
773 : throw (lang::IllegalArgumentException, RuntimeException, std::exception)
774 : {
775 : (void)WindowType; // for future use
776 0 : if( !xParent.is() )
777 : {
778 : throw IllegalArgumentException(
779 : "DialogProviderImpl::createContainerWindow: Invalid xParent!",
780 0 : Reference< XInterface >(), 1 );
781 : }
782 0 : Reference < XControl > xControl = DialogProviderImpl::createDialogImpl( URL, xHandler, xParent, false );
783 0 : Reference< XWindow> xWindow( xControl, UNO_QUERY );
784 0 : return xWindow;
785 : }
786 :
787 :
788 :
789 : // component operations
790 :
791 :
792 8 : static Reference< XInterface > SAL_CALL create_DialogProviderImpl(
793 : Reference< XComponentContext > const & xContext )
794 : {
795 8 : return static_cast< lang::XTypeProvider * >( new DialogProviderImpl( xContext ) );
796 : }
797 :
798 :
799 :
800 : static struct ::cppu::ImplementationEntry s_component_entries [] =
801 : {
802 : {create_DialogProviderImpl, getImplementationName_DialogProviderImpl,getSupportedServiceNames_DialogProviderImpl, ::cppu::createSingleComponentFactory,0, 0},
803 : { &comp_DialogModelProvider::_create,&comp_DialogModelProvider::_getImplementationName,&comp_DialogModelProvider::_getSupportedServiceNames,&::cppu::createSingleComponentFactory, 0, 0 },
804 : { 0, 0, 0, 0, 0, 0 }
805 : };
806 :
807 :
808 :
809 :
810 : } // namespace dlgprov
811 :
812 :
813 :
814 :
815 : // component exports
816 :
817 :
818 : extern "C"
819 : {
820 4 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL dlgprov_component_getFactory(
821 : const sal_Char * pImplName, void * pServiceManager,
822 : void * pRegistryKey )
823 : {
824 : return ::cppu::component_getFactoryHelper(
825 4 : pImplName, pServiceManager, pRegistryKey, ::dlgprov::s_component_entries );
826 : }
827 12 : }
828 :
829 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|