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

Generated by: LCOV version 1.10