LCOV - code coverage report
Current view: top level - scripting/source/dlgprov - dlgprov.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 185 317 58.4 %
Date: 2015-06-13 12:38:46 Functions: 22 30 73.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11