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

Generated by: LCOV version 1.10