LCOV - code coverage report
Current view: top level - basic/source/basmgr - basicmanagerrepository.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 149 175 85.1 %
Date: 2015-06-13 12:38:46 Functions: 23 26 88.5 %
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             : #include <basic/basicmanagerrepository.hxx>
      21             : #include <basic/basmgr.hxx>
      22             : #include "scriptcont.hxx"
      23             : #include "dlgcont.hxx"
      24             : #include <basic/sbuno.hxx>
      25             : #include "sbintern.hxx"
      26             : 
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : #include <com/sun/star/document/XStorageBasedDocument.hpp>
      29             : #include <com/sun/star/document/XEmbeddedScripts.hpp>
      30             : #include <com/sun/star/frame/Desktop.hpp>
      31             : #include <svtools/ehdl.hxx>
      32             : #include <svtools/sfxecode.hxx>
      33             : #include <unotools/pathoptions.hxx>
      34             : #include <svl/smplhint.hxx>
      35             : #include <vcl/svapp.hxx>
      36             : #include <tools/debug.hxx>
      37             : #include <tools/diagnose_ex.h>
      38             : #include <tools/urlobj.hxx>
      39             : #include <comphelper/stl_types.hxx>
      40             : #include <comphelper/processfactory.hxx>
      41             : #include <comphelper/documentinfo.hxx>
      42             : #include <unotools/eventlisteneradapter.hxx>
      43             : 
      44             : #include <osl/getglobalmutex.hxx>
      45             : #include <rtl/instance.hxx>
      46             : #include <rtl/strbuf.hxx>
      47             : 
      48             : #include <map>
      49             : 
      50             : 
      51             : namespace basic
      52             : {
      53             : 
      54             : 
      55             :     using ::com::sun::star::uno::Reference;
      56             :     using ::com::sun::star::uno::XComponentContext;
      57             :     using ::com::sun::star::frame::XModel;
      58             :     using ::com::sun::star::frame::Desktop;
      59             :     using ::com::sun::star::uno::XInterface;
      60             :     using ::com::sun::star::uno::UNO_QUERY;
      61             :     using ::com::sun::star::embed::XStorage;
      62             :     using ::com::sun::star::script::XPersistentLibraryContainer;
      63             :     using ::com::sun::star::uno::Any;
      64             :     using ::com::sun::star::lang::XMultiServiceFactory;
      65             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      66             :     using ::com::sun::star::beans::XPropertySet;
      67             :     using ::com::sun::star::uno::Exception;
      68             :     using ::com::sun::star::document::XStorageBasedDocument;
      69             :     using ::com::sun::star::lang::XComponent;
      70             :     using ::com::sun::star::document::XEmbeddedScripts;
      71             : 
      72             :     typedef ::std::map< Reference< XInterface >, BasicManager*, ::comphelper::OInterfaceCompare< XInterface > > BasicManagerStore;
      73             : 
      74             :     typedef ::std::vector< BasicManagerCreationListener* >  CreationListeners;
      75             : 
      76           0 :     class ImplRepository : public ::utl::OEventListenerAdapter, public SfxListener
      77             :     {
      78             :     private:
      79             :         friend struct CreateImplRepository;
      80             :         ImplRepository();
      81             : 
      82             :     private:
      83             :         BasicManagerStore   m_aStore;
      84             :         CreationListeners   m_aCreationListeners;
      85             : 
      86             :     public:
      87             :         static ImplRepository& Instance();
      88             : 
      89             :         BasicManager*   getDocumentBasicManager( const Reference< XModel >& _rxDocumentModel );
      90             :         BasicManager*   getApplicationBasicManager( bool _bCreate );
      91             :         void            setApplicationBasicManager( BasicManager* _pBasicManager );
      92             :         void    registerCreationListener( BasicManagerCreationListener& _rListener );
      93             :         void    revokeCreationListener( BasicManagerCreationListener& _rListener );
      94             : 
      95             :     private:
      96             :         /** retrieves the location at which the BasicManager for the given model
      97             :             is stored.
      98             : 
      99             :             If previously, the BasicManager for this model has never been requested,
     100             :             then the model is added to the map, with an initial NULL BasicManager.
     101             : 
     102             :             @param _rxDocumentModel
     103             :                 the model whose BasicManager's location is to be retrieved. Must not be <NULL/>.
     104             : 
     105             :             @precond
     106             :                 our mutex is locked
     107             :         */
     108             :         BasicManager*&
     109             :                 impl_getLocationForModel( const Reference< XModel >& _rxDocumentModel );
     110             : 
     111             :         /** creates a new BasicManager instance for the given model
     112             : 
     113             :             @param _out_rpBasicManager
     114             :                 reference to the pointer variable that will hold the new
     115             :                 BasicManager.
     116             : 
     117             :             @param _rxDocumentModel
     118             :                 the model whose BasicManager will be created. Must not be <NULL/>.
     119             :         */
     120             :         void impl_createManagerForModel(
     121             :                     BasicManager*& _out_rpBasicManager,
     122             :                     const Reference< XModel >& _rxDocumentModel );
     123             : 
     124             :         /** creates the application-wide BasicManager
     125             :         */
     126             :         BasicManager* impl_createApplicationBasicManager();
     127             : 
     128             :         /** notifies all listeners which expressed interest in the creation of BasicManager instances.
     129             :         */
     130             :         void    impl_notifyCreationListeners(
     131             :                     const Reference< XModel >& _rxDocumentModel,
     132             :                     BasicManager& _rManager
     133             :                  );
     134             : 
     135             :         /** retrieves the current storage of a given document
     136             : 
     137             :             @param  _rxDocument
     138             :                 the document whose storage is to be retrieved.
     139             : 
     140             :             @param  _out_rStorage
     141             :                 takes the storage upon successful return. Note that this might be <NULL/> even
     142             :                 if <TRUE/> is returned. In this case, the document has not yet been saved.
     143             : 
     144             :             @return
     145             :                 <TRUE/> if the storage could be successfully retrieved (in which case
     146             :                 <arg>_out_rStorage</arg> might or might not be <NULL/>), <FALSE/> otherwise.
     147             :                 In the latter case, processing this document should stop.
     148             :         */
     149             :         static bool impl_getDocumentStorage_nothrow( const Reference< XModel >& _rxDocument, Reference< XStorage >& _out_rStorage );
     150             : 
     151             :         /** retrieves the containers for Basic and Dialog libraries for a given document
     152             : 
     153             :             @param  _rxDocument
     154             :                 the document whose containers are to be retrieved.
     155             : 
     156             :             @param _out_rxBasicLibraries
     157             :                 takes the basic library container upon successful return
     158             : 
     159             :             @param _out_rxDialogLibraries
     160             :                 takes the dialog library container upon successful return
     161             : 
     162             :             @return
     163             :                 <TRUE/> if and only if both containers exist, and could successfully be retrieved
     164             :         */
     165             :         static bool impl_getDocumentLibraryContainers_nothrow(
     166             :                     const Reference< XModel >& _rxDocument,
     167             :                     Reference< XPersistentLibraryContainer >& _out_rxBasicLibraries,
     168             :                     Reference< XPersistentLibraryContainer >& _out_rxDialogLibraries
     169             :                 );
     170             : 
     171             :         /** initializes the given library containers, which belong to a document
     172             :         */
     173             :         static void impl_initDocLibraryContainers_nothrow(
     174             :                     const Reference< XPersistentLibraryContainer >& _rxBasicLibraries,
     175             :                     const Reference< XPersistentLibraryContainer >& _rxDialogLibraries
     176             :                 );
     177             : 
     178             :         // OEventListenerAdapter overridables
     179             :         virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource ) SAL_OVERRIDE;
     180             : 
     181             :         // SfxListener overridables
     182             :         virtual void Notify( SfxBroadcaster& _rBC, const SfxHint& _rHint ) SAL_OVERRIDE;
     183             : 
     184             :         /** removes the Model/BasicManager pair given by iterator from our store
     185             :         */
     186             :         void impl_removeFromRepository( BasicManagerStore::iterator _pos );
     187             : 
     188             :     private:
     189             :         StarBASIC* impl_getDefaultAppBasicLibrary();
     190             :     };
     191             : 
     192             : 
     193             :     struct CreateImplRepository
     194             :     {
     195         208 :         ImplRepository* operator()()
     196             :         {
     197         208 :             static ImplRepository* pRepository = new ImplRepository;
     198         208 :             return pRepository;
     199             :         }
     200             :     };
     201             : 
     202             : 
     203         208 :     ImplRepository::ImplRepository()
     204             :     {
     205         208 :     }
     206             : 
     207             : 
     208       15131 :     ImplRepository& ImplRepository::Instance()
     209             :     {
     210             :         return *rtl_Instance< ImplRepository, CreateImplRepository, ::osl::MutexGuard, ::osl::GetGlobalMutex >::
     211       15131 :             create( CreateImplRepository(), ::osl::GetGlobalMutex() );
     212             :     }
     213             : 
     214             : 
     215        2114 :     BasicManager* ImplRepository::getDocumentBasicManager( const Reference< XModel >& _rxDocumentModel )
     216             :     {
     217        2114 :         SolarMutexGuard g;
     218             : 
     219             :         /*  #163556# (DR) - This function may be called recursively while
     220             :             constructing the Basic manager and loading the Basic storage. By
     221             :             passing the map entry received from impl_getLocationForModel() to
     222             :             the function impl_createManagerForModel(), the new Basic manager
     223             :             will be put immediately into the map of existing Basic managers,
     224             :             thus a recursive call of this function will find and return it
     225             :             without creating another instance.
     226             :          */
     227        2114 :         BasicManager*& pBasicManager = impl_getLocationForModel( _rxDocumentModel );
     228        2114 :         if ( pBasicManager == NULL )
     229        2054 :             impl_createManagerForModel( pBasicManager, _rxDocumentModel );
     230             : 
     231        2113 :         return pBasicManager;
     232             :     }
     233             : 
     234             : 
     235       14820 :     BasicManager* ImplRepository::getApplicationBasicManager( bool _bCreate )
     236             :     {
     237       14820 :         SolarMutexGuard g;
     238             : 
     239       14820 :         BasicManager* pAppManager = GetSbData()->pAppBasMgr;
     240       14820 :         if ( ( pAppManager == NULL ) && _bCreate )
     241         112 :             pAppManager = impl_createApplicationBasicManager();
     242             : 
     243       14819 :         return pAppManager;
     244             :     }
     245             : 
     246             : 
     247         231 :     void ImplRepository::setApplicationBasicManager( BasicManager* _pBasicManager )
     248             :     {
     249         231 :         SolarMutexGuard g;
     250             : 
     251         231 :         BasicManager* pPreviousManager = getApplicationBasicManager( false );
     252         231 :         delete pPreviousManager;
     253             : 
     254         231 :         GetSbData()->pAppBasMgr = _pBasicManager;
     255         231 :     }
     256             : 
     257             : 
     258         112 :     BasicManager* ImplRepository::impl_createApplicationBasicManager()
     259             :     {
     260         112 :         SolarMutexGuard g;
     261             : 
     262             :         OSL_PRECOND( getApplicationBasicManager( false ) == NULL, "ImplRepository::impl_createApplicationBasicManager: there already is one!" );
     263             : 
     264             :         // Determine Directory
     265         224 :         SvtPathOptions aPathCFG;
     266         224 :         OUString aAppBasicDir( aPathCFG.GetBasicPath() );
     267         112 :         if ( aAppBasicDir.isEmpty() )
     268             :         {
     269           0 :             aPathCFG.SetBasicPath(OUString("$(prog)"));
     270             :         }
     271             : 
     272             :         // Create basic and load it
     273             :         // AppBasicDir is now a PATH
     274         224 :         INetURLObject aAppBasic( SvtPathOptions().SubstituteVariable(OUString("$(progurl)")) );
     275         112 :         aAppBasic.insertName( Application::GetAppName() );
     276             : 
     277         112 :         BasicManager* pBasicManager = new BasicManager( new StarBASIC, &aAppBasicDir );
     278         112 :         setApplicationBasicManager( pBasicManager );
     279             : 
     280             :         // The first dir in the path as destination:
     281         224 :         OUString aFileName( aAppBasic.getName() );
     282         112 :         aAppBasic = INetURLObject( aAppBasicDir.getToken(1, ';') );
     283             :         DBG_ASSERT(aAppBasic.GetProtocol() != INetProtocol::NotValid,
     284             :             OString("Invalid URL: \"" +
     285             :                     OUStringToOString(aAppBasicDir, osl_getThreadTextEncoding()) +
     286             :                     "\"").getStr());
     287         112 :         aAppBasic.insertName( aFileName );
     288         112 :         pBasicManager->SetStorageName( aAppBasic.PathToFileName() );
     289             : 
     290             :         // Basic container
     291         113 :         SfxScriptLibraryContainer* pBasicCont = new SfxScriptLibraryContainer( Reference< XStorage >() );
     292         222 :         Reference< XPersistentLibraryContainer > xBasicCont( pBasicCont );
     293         111 :         pBasicCont->setBasicManager( pBasicManager );
     294             : 
     295             :         // Dialog container
     296         111 :         SfxDialogLibraryContainer* pDialogCont = new SfxDialogLibraryContainer( Reference< XStorage >() );
     297         222 :         Reference< XPersistentLibraryContainer > xDialogCont( pDialogCont );
     298             : 
     299         222 :         LibraryContainerInfo aInfo( xBasicCont, xDialogCont, static_cast< OldBasicPassword* >( pBasicCont ) );
     300         111 :         pBasicManager->SetLibraryContainerInfo( aInfo );
     301             : 
     302             :         // global constants
     303             : 
     304             :         // StarDesktop
     305         222 :         Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     306         111 :         pBasicManager->SetGlobalUNOConstant( "StarDesktop", makeAny( Desktop::create(xContext)));
     307             : 
     308             :         // (BasicLibraries and DialogLibraries have automatically been added in SetLibraryContainerInfo)
     309             : 
     310             :         // notify
     311         111 :         impl_notifyCreationListeners( NULL, *pBasicManager );
     312             : 
     313             :         // outta here
     314         223 :         return pBasicManager;
     315             :     }
     316             : 
     317             : 
     318         228 :     void ImplRepository::registerCreationListener( BasicManagerCreationListener& _rListener )
     319             :     {
     320         228 :         SolarMutexGuard g;
     321             : 
     322         228 :         m_aCreationListeners.push_back( &_rListener );
     323         228 :     }
     324             : 
     325             : 
     326         135 :     void ImplRepository::revokeCreationListener( BasicManagerCreationListener& _rListener )
     327             :     {
     328         135 :         SolarMutexGuard g;
     329             : 
     330         135 :         CreationListeners::iterator pos = ::std::find( m_aCreationListeners.begin(), m_aCreationListeners.end(), &_rListener );
     331         135 :         if ( pos != m_aCreationListeners.end() )
     332         135 :             m_aCreationListeners.erase( pos );
     333             :         else {
     334             :             OSL_FAIL( "ImplRepository::revokeCreationListener: listener is not registered!" );
     335         135 :         }
     336         135 :     }
     337             : 
     338             : 
     339        2117 :     void ImplRepository::impl_notifyCreationListeners( const Reference< XModel >& _rxDocumentModel, BasicManager& _rManager )
     340             :     {
     341       12756 :         for (   CreationListeners::const_iterator loop = m_aCreationListeners.begin();
     342        8504 :                 loop != m_aCreationListeners.end();
     343             :                 ++loop
     344             :             )
     345             :         {
     346        2135 :             (*loop)->onBasicManagerCreated( _rxDocumentModel, _rManager );
     347             :         }
     348        2117 :     }
     349             : 
     350             : 
     351        2054 :     StarBASIC* ImplRepository::impl_getDefaultAppBasicLibrary()
     352             :     {
     353        2054 :         BasicManager* pAppManager = getApplicationBasicManager( true );
     354             : 
     355        2053 :         StarBASIC* pAppBasic = pAppManager ? pAppManager->GetLib(0) : NULL;
     356             :         DBG_ASSERT( pAppBasic != NULL, "impl_getApplicationBasic: unable to determine the default application's Basic library!" );
     357        2053 :         return pAppBasic;
     358             :     }
     359             : 
     360             : 
     361        2114 :     BasicManager*& ImplRepository::impl_getLocationForModel( const Reference< XModel >& _rxDocumentModel )
     362             :     {
     363        2114 :         Reference< XInterface > xNormalized( _rxDocumentModel, UNO_QUERY );
     364             :         DBG_ASSERT( _rxDocumentModel.is(), "ImplRepository::impl_getLocationForModel: invalid model!" );
     365             : 
     366        2114 :         BasicManager*& location = m_aStore[ xNormalized ];
     367        2114 :         return location;
     368             :     }
     369             : 
     370             : 
     371        2006 :     void ImplRepository::impl_initDocLibraryContainers_nothrow( const Reference< XPersistentLibraryContainer >& _rxBasicLibraries, const Reference< XPersistentLibraryContainer >& _rxDialogLibraries )
     372             :     {
     373             :         OSL_PRECOND( _rxBasicLibraries.is() && _rxDialogLibraries.is(),
     374             :             "ImplRepository::impl_initDocLibraryContainers_nothrow: illegal library containers, this will crash!" );
     375             : 
     376             :         try
     377             :         {
     378             :             // ensure there's a standard library in the basic container
     379        2006 :             OUString aStdLibName( "Standard" );
     380        2006 :             if ( !_rxBasicLibraries->hasByName( aStdLibName ) )
     381             :             {
     382           1 :                 _rxBasicLibraries->createLibrary( aStdLibName );
     383             :             }
     384             :             // as well as in the dialog container
     385        2006 :             if ( !_rxDialogLibraries->hasByName( aStdLibName ) )
     386             :             {
     387        2004 :                 _rxDialogLibraries->createLibrary( aStdLibName );
     388        2006 :             }
     389             :         }
     390           0 :         catch( const Exception& )
     391             :         {
     392             :             DBG_UNHANDLED_EXCEPTION();
     393             :         }
     394        2006 :     }
     395             : 
     396             : 
     397        2054 :     void ImplRepository::impl_createManagerForModel( BasicManager*& _out_rpBasicManager, const Reference< XModel >& _rxDocumentModel )
     398             :     {
     399        2054 :         StarBASIC* pAppBasic = impl_getDefaultAppBasicLibrary();
     400             : 
     401        2053 :         _out_rpBasicManager = 0;
     402        2053 :         Reference< XStorage > xStorage;
     403        2053 :         if ( !impl_getDocumentStorage_nothrow( _rxDocumentModel, xStorage ) )
     404             :         {
     405             :             // the document is not able to provide the storage it is based on.
     406           0 :             return;
     407             :         }
     408        4059 :         Reference< XPersistentLibraryContainer > xBasicLibs;
     409        4059 :         Reference< XPersistentLibraryContainer > xDialogLibs;
     410        2053 :         if ( !impl_getDocumentLibraryContainers_nothrow( _rxDocumentModel, xBasicLibs, xDialogLibs ) )
     411             :             // the document does not have BasicLibraries and DialogLibraries
     412          47 :             return;
     413             : 
     414        2006 :         if ( xStorage.is() )
     415             :         {
     416             :             // load BASIC-manager
     417             :             SfxErrorContext aErrContext( ERRCTX_SFX_LOADBASIC,
     418        2006 :                 ::comphelper::DocumentInfo::getDocumentTitle( _rxDocumentModel ) );
     419        4012 :             OUString aAppBasicDir = SvtPathOptions().GetBasicPath();
     420             : 
     421             :             // Storage and BaseURL are only needed by binary documents!
     422        6018 :             tools::SvRef<SotStorage> xDummyStor = new SotStorage( OUString() );
     423             :             _out_rpBasicManager = new BasicManager( *xDummyStor, OUString() /* TODO/LATER: xStorage */,
     424             :                                                                 pAppBasic,
     425        2006 :                                                                 &aAppBasicDir, true );
     426        2006 :             if ( !_out_rpBasicManager->GetErrors().empty() )
     427             :             {
     428             :                 // handle errors
     429           0 :                 std::vector<BasicError>& aErrors = _out_rpBasicManager->GetErrors();
     430           0 :                 for(std::vector<BasicError>::const_iterator i = aErrors.begin(); i != aErrors.end(); ++i)
     431             :                 {
     432             :                     // show message to user
     433           0 :                     if ( ERRCODE_BUTTON_CANCEL == ErrorHandler::HandleError( i->GetErrorId() ) )
     434             :                     {
     435             :                         // user wants to break loading of BASIC-manager
     436           0 :                         delete _out_rpBasicManager;
     437           0 :                         _out_rpBasicManager = NULL;
     438           0 :                         xStorage.clear();
     439           0 :                         break;
     440             :                     }
     441             :                 }
     442        2006 :             }
     443             :         }
     444             : 
     445             :         // not loaded?
     446        2006 :         if ( !xStorage.is() )
     447             :         {
     448             :             // create new BASIC-manager
     449           0 :             StarBASIC* pBasic = new StarBASIC( pAppBasic );
     450           0 :             pBasic->SetFlag( SBX_EXTSEARCH );
     451           0 :             _out_rpBasicManager = new BasicManager( pBasic, NULL, true );
     452             :         }
     453             : 
     454             :         // knit the containers with the BasicManager
     455        4012 :         LibraryContainerInfo aInfo( xBasicLibs, xDialogLibs, dynamic_cast< OldBasicPassword* >( xBasicLibs.get() ) );
     456             :         OSL_ENSURE( aInfo.mpOldBasicPassword, "ImplRepository::impl_createManagerForModel: wrong BasicLibraries implementation!" );
     457        2006 :         _out_rpBasicManager->SetLibraryContainerInfo( aInfo );
     458             : 
     459             :         // initialize the containers
     460        2006 :         impl_initDocLibraryContainers_nothrow( xBasicLibs, xDialogLibs );
     461             : 
     462             :         // so that also dialogs etc. could be 'qualified' addressed
     463        2006 :         _out_rpBasicManager->GetLib(0)->SetParent( pAppBasic );
     464             : 
     465             :         // global properties in the document's Basic
     466        2006 :         _out_rpBasicManager->SetGlobalUNOConstant( "ThisComponent", makeAny( _rxDocumentModel ) );
     467             : 
     468             :         // notify
     469        2006 :         impl_notifyCreationListeners( _rxDocumentModel, *_out_rpBasicManager );
     470             : 
     471             :         // register as listener for this model being disposed/closed
     472             :         OSL_ENSURE( _rxDocumentModel.is(), "ImplRepository::impl_createManagerForModel: the document must be an XComponent!" );
     473        2006 :         startComponentListening( _rxDocumentModel );
     474             : 
     475             :         // register as listener for the BasicManager being destroyed
     476        2006 :         StartListening( *_out_rpBasicManager );
     477             : 
     478             :         // #i104876: Library container must not be modified just after
     479             :         // creation. This happens as side effect when creating default
     480             :         // "Standard" libraries and needs to be corrected here
     481        2006 :         xBasicLibs->setModified( sal_False );
     482        4012 :         xDialogLibs->setModified( sal_False );
     483             : 
     484             :     }
     485             : 
     486             : 
     487        2053 :     bool ImplRepository::impl_getDocumentStorage_nothrow( const Reference< XModel >& _rxDocument, Reference< XStorage >& _out_rStorage )
     488             :     {
     489        2053 :         _out_rStorage.clear();
     490             :         try
     491             :         {
     492        2053 :             Reference< XStorageBasedDocument > xStorDoc( _rxDocument, UNO_QUERY_THROW );
     493        2053 :             _out_rStorage.set( xStorDoc->getDocumentStorage() );
     494             :         }
     495           0 :         catch( const Exception& )
     496             :         {
     497             :             DBG_UNHANDLED_EXCEPTION();
     498           0 :             return false;
     499             :         }
     500        2053 :         return true;
     501             :     }
     502             : 
     503             : 
     504        2053 :     bool ImplRepository::impl_getDocumentLibraryContainers_nothrow( const Reference< XModel >& _rxDocument,
     505             :         Reference< XPersistentLibraryContainer >& _out_rxBasicLibraries, Reference< XPersistentLibraryContainer >& _out_rxDialogLibraries )
     506             :     {
     507        2053 :         _out_rxBasicLibraries.clear();
     508        2053 :         _out_rxDialogLibraries.clear();
     509             :         try
     510             :         {
     511        2053 :             Reference< XEmbeddedScripts > xScripts( _rxDocument, UNO_QUERY_THROW );
     512        2053 :             _out_rxBasicLibraries.set( xScripts->getBasicLibraries(), UNO_QUERY_THROW );
     513        2006 :             _out_rxDialogLibraries.set( xScripts->getDialogLibraries(), UNO_QUERY_THROW );
     514             :         }
     515          47 :         catch( const Exception& )
     516             :         {
     517             :             DBG_UNHANDLED_EXCEPTION();
     518             :         }
     519        2053 :         return _out_rxBasicLibraries.is() && _out_rxDialogLibraries.is();
     520             :     }
     521             : 
     522             : 
     523        2006 :     void ImplRepository::impl_removeFromRepository( BasicManagerStore::iterator _pos )
     524             :     {
     525             :         OSL_PRECOND( _pos != m_aStore.end(), "ImplRepository::impl_removeFromRepository: invalid position!" );
     526             : 
     527        2006 :         BasicManager* pManager = _pos->second;
     528             : 
     529             :         // *first* remove from map (else Notify won't work properly)
     530        2006 :         m_aStore.erase( _pos );
     531             : 
     532             :         // *then* delete the BasicManager
     533        2006 :         EndListening( *pManager );
     534        2006 :         delete pManager;
     535        2006 :     }
     536             : 
     537             : 
     538        2006 :     void ImplRepository::_disposing( const ::com::sun::star::lang::EventObject& _rSource )
     539             :     {
     540        2006 :         SolarMutexGuard g;
     541             : 
     542        4012 :         Reference< XInterface > xNormalizedSource( _rSource.Source, UNO_QUERY );
     543             :     #if OSL_DEBUG_LEVEL > 0
     544             :         bool bFound = false;
     545             :     #endif
     546             : 
     547        7866 :         for (   BasicManagerStore::iterator loop = m_aStore.begin();
     548        5244 :                 loop != m_aStore.end();
     549             :                 ++loop
     550             :             )
     551             :         {
     552        2622 :             if ( loop->first.get() == xNormalizedSource.get() )
     553             :             {
     554        2006 :                 impl_removeFromRepository( loop );
     555             :             #if OSL_DEBUG_LEVEL > 0
     556             :                 bFound = true;
     557             :             #endif
     558        2006 :                 break;
     559             :             }
     560             :         }
     561             : 
     562        2006 :         OSL_ENSURE( bFound, "ImplRepository::_disposing: where does this come from?" );
     563        2006 :     }
     564             : 
     565             : 
     566           0 :     void ImplRepository::Notify( SfxBroadcaster& _rBC, const SfxHint& _rHint )
     567             :     {
     568           0 :         const SfxSimpleHint* pSimpleHint = dynamic_cast< const SfxSimpleHint* >( &_rHint );
     569           0 :         if ( !pSimpleHint || ( pSimpleHint->GetId() != SFX_HINT_DYING ) )
     570             :             // not interested in
     571           0 :             return;
     572             : 
     573           0 :         BasicManager* pManager = dynamic_cast< BasicManager* >( &_rBC );
     574             :         OSL_ENSURE( pManager, "ImplRepository::Notify: where does this come from?" );
     575             : 
     576           0 :         for (   BasicManagerStore::iterator loop = m_aStore.begin();
     577           0 :                 loop != m_aStore.end();
     578             :                 ++loop
     579             :             )
     580             :         {
     581           0 :             if ( loop->second == pManager )
     582             :             {
     583             :                 // a BasicManager which is still in our repository is being deleted.
     584             :                 // That's bad, since by definition, we *own* all instances in our
     585             :                 // repository.
     586             :                 OSL_FAIL( "ImplRepository::Notify: nobody should tamper with the managers, except ourself!" );
     587           0 :                 m_aStore.erase( loop );
     588           0 :                 break;
     589             :             }
     590             :         }
     591             :     }
     592             : 
     593             : 
     594        2114 :     BasicManager* BasicManagerRepository::getDocumentBasicManager( const Reference< XModel >& _rxDocumentModel )
     595             :     {
     596        2114 :         return ImplRepository::Instance().getDocumentBasicManager( _rxDocumentModel );
     597             :     }
     598             : 
     599             : 
     600       12535 :     BasicManager* BasicManagerRepository::getApplicationBasicManager( bool _bCreate )
     601             :     {
     602       12535 :         return ImplRepository::Instance().getApplicationBasicManager( _bCreate );
     603             :     }
     604             : 
     605             : 
     606         119 :     void BasicManagerRepository::resetApplicationBasicManager()
     607             :     {
     608         119 :         return ImplRepository::Instance().setApplicationBasicManager( NULL );
     609             :     }
     610             : 
     611             : 
     612         228 :     void BasicManagerRepository::registerCreationListener( BasicManagerCreationListener& _rListener )
     613             :     {
     614         228 :         ImplRepository::Instance().registerCreationListener( _rListener );
     615         228 :     }
     616             : 
     617             : 
     618         135 :     void BasicManagerRepository::revokeCreationListener( BasicManagerCreationListener& _rListener )
     619             :     {
     620         135 :         ImplRepository::Instance().revokeCreationListener( _rListener );
     621         135 :     }
     622             : 
     623             : 
     624             : } // namespace basic
     625             : 
     626             : 
     627             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11