LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/appl - appbaslib.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 71 59.2 %
Date: 2012-12-17 Functions: 10 16 62.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "appbaslib.hxx"
      22             : 
      23             : #include <sfx2/sfxuno.hxx>
      24             : #include "sfxtypes.hxx"
      25             : #include <sfx2/app.hxx>
      26             : 
      27             : #include <basic/basmgr.hxx>
      28             : #include <tools/diagnose_ex.h>
      29             : #include <comphelper/processfactory.hxx>
      30             : 
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::lang;
      33             : using namespace ::com::sun::star::script;
      34             : using namespace ::com::sun::star::embed;
      35             : using ::rtl::OUString;
      36             : using ::osl::MutexGuard;
      37             : using ::osl::Mutex;
      38             : 
      39             : //============================================================================
      40        1582 : SfxBasicManagerHolder::SfxBasicManagerHolder()
      41        1582 :     :mpBasicManager( NULL )
      42             : {
      43        1582 : }
      44             : 
      45        1412 : void SfxBasicManagerHolder::reset( BasicManager* _pBasicManager )
      46             : {
      47        1412 :     impl_releaseContainers();
      48             : 
      49             : #ifdef DISABLE_SCRIPTING
      50             :     (void) _pBasicManager;
      51             : #else
      52             :     // Note: we do not delete the old BasicManager. BasicManager instances are
      53             :     // nowadays obtained from the BasicManagerRepository, and the ownership is with
      54             :     // the repository.
      55             :     // @see basic::BasicManagerRepository::getApplicationBasicManager
      56             :     // @see basic::BasicManagerRepository::getDocumentBasicManager
      57        1412 :     mpBasicManager = _pBasicManager;
      58             : 
      59        1412 :     if ( mpBasicManager )
      60             :     {
      61             :         try
      62             :         {
      63         548 :             mxBasicContainer.set( mpBasicManager->GetScriptLibraryContainer(), UNO_QUERY_THROW );
      64         548 :             mxDialogContainer.set( mpBasicManager->GetDialogLibraryContainer(), UNO_QUERY_THROW  );
      65             :         }
      66           0 :         catch( const Exception& )
      67             :         {
      68             :             DBG_UNHANDLED_EXCEPTION();
      69             :         }
      70             :     }
      71             : #endif
      72        1412 : }
      73             : 
      74           2 : void SfxBasicManagerHolder::storeAllLibraries()
      75             : {
      76             : #ifndef DISABLE_SCRIPTING
      77             :     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
      78             :     try
      79             :     {
      80           2 :         if ( mxBasicContainer.is() )
      81           2 :             mxBasicContainer->storeLibraries();
      82           2 :         if ( mxDialogContainer.is() )
      83           2 :             mxDialogContainer->storeLibraries();
      84             :     }
      85           0 :     catch( const Exception& )
      86             :     {
      87             :         DBG_UNHANDLED_EXCEPTION();
      88             :     }
      89             : #endif
      90           2 : }
      91             : 
      92         572 : void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage )
      93             : {
      94             : #ifdef DISABLE_SCRIPTING
      95             :     (void) _rxStorage;
      96             : #else
      97             :     try
      98             :     {
      99         572 :         if ( mxBasicContainer.is() )
     100         568 :             mxBasicContainer->setRootStorage( _rxStorage );
     101         572 :         if ( mxDialogContainer.is() )
     102         568 :             mxDialogContainer->setRootStorage( _rxStorage );
     103             :     }
     104           0 :     catch( const Exception& )
     105             :     {
     106             :         DBG_UNHANDLED_EXCEPTION();
     107             :     }
     108             : #endif
     109         572 : }
     110             : 
     111         572 : void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage )
     112             : {
     113             : #ifdef DISABLE_SCRIPTING
     114             :     (void) _rxStorage;
     115             : #else
     116             :     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
     117             : 
     118         572 :     if ( mxBasicContainer.is() )
     119         572 :         mxBasicContainer->storeLibrariesToStorage( _rxStorage );
     120         572 :     if ( mxDialogContainer.is() )
     121         572 :         mxDialogContainer->storeLibrariesToStorage( _rxStorage );
     122             : #endif
     123         572 : }
     124             : 
     125          12 : Reference< XLibraryContainer > SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType )
     126             : {
     127             :     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
     128             : 
     129          12 :     switch ( _eType )
     130             :     {
     131          12 :     case SCRIPTS:   return mxBasicContainer.get();
     132           0 :     case DIALOGS:   return mxDialogContainer.get();
     133             :     }
     134             :     OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
     135           0 :     return NULL;
     136             : }
     137             : 
     138        1412 : void SfxBasicManagerHolder::impl_releaseContainers()
     139             : {
     140        1412 :     mxBasicContainer.clear();
     141        1412 :     mxDialogContainer.clear();
     142        1412 : }
     143             : 
     144             : sal_Bool
     145           4 : SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence< rtl::OUString >& sModules )
     146             : {
     147             : #ifdef DISABLE_SCRIPTING
     148             :     (void) sModules;
     149             : #else
     150           4 :     if ( mpBasicManager )
     151           4 :         return mpBasicManager->LegacyPsswdBinaryLimitExceeded( sModules );
     152             : #endif
     153           0 :     return sal_True;
     154             : }
     155             : 
     156             : //============================================================================
     157             : // Service for application library container
     158           0 : SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationDialogLibraryContainer )
     159             : 
     160           0 : Sequence< OUString > SfxApplicationDialogLibraryContainer::impl_getStaticSupportedServiceNames()
     161             : {
     162           0 :     static Sequence< OUString > seqServiceNames( 1 );
     163             :     static sal_Bool bNeedsInit = sal_True;
     164             : 
     165           0 :     MutexGuard aGuard( Mutex::getGlobalMutex() );
     166           0 :     if( bNeedsInit )
     167             :     {
     168           0 :         OUString* pSeq = seqServiceNames.getArray();
     169           0 :         pSeq[0] = OUString("com.sun.star.script.ApplicationDialogLibraryContainer");
     170           0 :         bNeedsInit = sal_False;
     171             :     }
     172           0 :     return seqServiceNames;
     173             : }
     174             : 
     175         176 : OUString SfxApplicationDialogLibraryContainer::impl_getStaticImplementationName()
     176             : {
     177         176 :     return OUString("com.sun.star.comp.sfx2.ApplicationDialogLibraryContainer");
     178             : }
     179             : 
     180           0 : Reference< XInterface > SAL_CALL SfxApplicationDialogLibraryContainer::impl_createInstance
     181             :     ( const Reference< XMultiServiceFactory >& )
     182             :         throw( Exception )
     183             : {
     184           0 :     SFX_APP()->GetBasicManager();
     185             :     Reference< XInterface > xRet =
     186           0 :         Reference< XInterface >( SFX_APP()->GetDialogContainer(), UNO_QUERY );
     187           0 :     return xRet;
     188             : }
     189             : 
     190             : //============================================================================
     191             : // Service for application library container
     192           0 : SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationScriptLibraryContainer )
     193             : 
     194           0 : Sequence< OUString > SfxApplicationScriptLibraryContainer::impl_getStaticSupportedServiceNames()
     195             : {
     196           0 :     Sequence< OUString > seqServiceNames( 1 );
     197           0 :     OUString* pSeq = seqServiceNames.getArray();
     198           0 :     pSeq[0] = OUString("com.sun.star.script.ApplicationScriptLibraryContainer");
     199           0 :     return seqServiceNames;
     200             : }
     201             : 
     202         176 : OUString SfxApplicationScriptLibraryContainer::impl_getStaticImplementationName()
     203             : {
     204         176 :     return OUString("com.sun.star.comp.sfx2.ApplicationScriptLibraryContainer");
     205             : }
     206             : 
     207           0 : Reference< XInterface > SAL_CALL SfxApplicationScriptLibraryContainer::impl_createInstance
     208             :     ( const Reference< XMultiServiceFactory >& )
     209             :         throw( Exception )
     210             : {
     211           0 :     SFX_APP()->GetBasicManager();
     212             :     Reference< XInterface > xRet =
     213           0 :         Reference< XInterface >( SFX_APP()->GetBasicContainer(), UNO_QUERY );
     214           0 :     return xRet;
     215             : }
     216             : 
     217             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10