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

Generated by: LCOV version 1.10