LCOV - code coverage report
Current view: top level - basic/source/basmgr - basmgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 283 1084 26.1 %
Date: 2012-08-25 Functions: 45 159 28.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 291 2296 12.7 %

           Branch data     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 <tools/stream.hxx>
      21                 :            : #include <sot/storage.hxx>
      22                 :            : #include <tools/urlobj.hxx>
      23                 :            : #include <svl/smplhint.hxx>
      24                 :            : #include <vcl/svapp.hxx>
      25                 :            : #include <vcl/window.hxx>
      26                 :            : #include <vcl/wrkwin.hxx>
      27                 :            : #include <vcl/msgbox.hxx>
      28                 :            : #include <basic/sbx.hxx>
      29                 :            : #include <sot/storinfo.hxx>
      30                 :            : #include <unotools/pathoptions.hxx>
      31                 :            : #include <tools/debug.hxx>
      32                 :            : #include <tools/diagnose_ex.h>
      33                 :            : #include <basic/sbmod.hxx>
      34                 :            : #include <unotools/intlwrapper.hxx>
      35                 :            : #include <comphelper/processfactory.hxx>
      36                 :            : #include <comphelper/string.hxx>
      37                 :            : 
      38                 :            : #include <basic/sbuno.hxx>
      39                 :            : #include <basic/basmgr.hxx>
      40                 :            : #include <basic/global.hxx>
      41                 :            : #include <sbunoobj.hxx>
      42                 :            : #include "basrid.hxx"
      43                 :            : #include "sbintern.hxx"
      44                 :            : #include <sb.hrc>
      45                 :            : 
      46                 :            : #include <vector>
      47                 :            : 
      48                 :            : #define LIB_SEP         0x01
      49                 :            : #define LIBINFO_SEP     0x02
      50                 :            : #define LIBINFO_ID      0x1491
      51                 :            : #define PASSWORD_MARKER 0x31452134
      52                 :            : 
      53                 :            : 
      54                 :            : // Library API, implemented for XML import/export
      55                 :            : 
      56                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      57                 :            : #include <com/sun/star/container/XContainer.hpp>
      58                 :            : #include <com/sun/star/script/XStarBasicAccess.hpp>
      59                 :            : #include <com/sun/star/script/XStarBasicModuleInfo.hpp>
      60                 :            : #include <com/sun/star/script/XStarBasicDialogInfo.hpp>
      61                 :            : #include <com/sun/star/script/XStarBasicLibraryInfo.hpp>
      62                 :            : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
      63                 :            : #include <com/sun/star/script/ModuleInfo.hpp>
      64                 :            : #include <com/sun/star/script/vba/XVBACompatibility.hpp>
      65                 :            : #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
      66                 :            : 
      67                 :            : #include <cppuhelper/implbase1.hxx>
      68                 :            : 
      69                 :            : using com::sun::star::uno::Reference;
      70                 :            : using ::std::vector;
      71                 :            : using ::std::advance;
      72                 :            : using namespace com::sun::star::container;
      73                 :            : using namespace com::sun::star::uno;
      74                 :            : using namespace com::sun::star::lang;
      75                 :            : using namespace com::sun::star::script;
      76                 :            : using namespace cppu;
      77                 :            : 
      78                 :            : typedef WeakImplHelper1< XNameContainer > NameContainerHelper;
      79                 :            : typedef WeakImplHelper1< XStarBasicModuleInfo > ModuleInfoHelper;
      80                 :            : typedef WeakImplHelper1< XStarBasicDialogInfo > DialogInfoHelper;
      81                 :            : typedef WeakImplHelper1< XStarBasicLibraryInfo > LibraryInfoHelper;
      82                 :            : typedef WeakImplHelper1< XStarBasicAccess > StarBasicAccessHelper;
      83                 :            : 
      84                 :            : // Version 1
      85                 :            : //    sal_uIntPtr   nEndPos
      86                 :            : //    sal_uInt16    nId
      87                 :            : //    sal_uInt16    nVer
      88                 :            : //    sal_Bool      bDoLoad
      89                 :            : //    String    LibName
      90                 :            : //    String    AbsStorageName
      91                 :            : //    String    RelStorageName
      92                 :            : // Version 2
      93                 :            : //  + sal_Bool      bReference
      94                 :            : 
      95                 :            : static const char szStdLibName[] = "Standard";
      96                 :            : static const char szBasicStorage[] = "StarBASIC";
      97                 :            : static const char szOldManagerStream[] = "BasicManager";
      98                 :            : static const char szManagerStream[] = "BasicManager2";
      99                 :            : static const char szImbedded[] = "LIBIMBEDDED";
     100                 :            : static const char szCryptingKey[] = "CryptedBasic";
     101                 :            : static const char szScriptLanguage[] = "StarBasic";
     102                 :            : 
     103 [ #  # ][ #  # ]:          0 : TYPEINIT1( BasicManager, SfxBroadcaster );
     104                 :            : DBG_NAME( BasicManager );
     105                 :            : 
     106                 :            : StreamMode eStreamReadMode = STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYALL;
     107                 :            : StreamMode eStorageReadMode = STREAM_READ | STREAM_SHARE_DENYWRITE;
     108                 :            : 
     109                 :            : //----------------------------------------------------------------------------
     110                 :            : // BasicManager impl data
     111                 :            : struct BasicManagerImpl
     112                 :            : {
     113                 :            :     LibraryContainerInfo    maContainerInfo;
     114                 :            : 
     115                 :            :     // Save stream data
     116                 :            :     SvMemoryStream*  mpManagerStream;
     117                 :            :     SvMemoryStream** mppLibStreams;
     118                 :            :     sal_Int32        mnLibStreamCount;
     119                 :            :     sal_Bool         mbError;
     120                 :            : 
     121                 :        187 :     BasicManagerImpl( void )
     122                 :            :         : mpManagerStream( NULL )
     123                 :            :         , mppLibStreams( NULL )
     124                 :            :         , mnLibStreamCount( 0 )
     125                 :        187 :         , mbError( sal_False )
     126                 :        187 :     {}
     127                 :            :     ~BasicManagerImpl();
     128                 :            : };
     129                 :            : 
     130                 :        124 : BasicManagerImpl::~BasicManagerImpl()
     131                 :            : {
     132 [ -  + ][ #  # ]:        124 :     delete mpManagerStream;
     133         [ -  + ]:        124 :     if( mppLibStreams )
     134                 :            :     {
     135         [ #  # ]:          0 :         for( sal_Int32 i = 0 ; i < mnLibStreamCount ; i++ )
     136 [ #  # ][ #  # ]:          0 :             delete mppLibStreams[i];
     137         [ #  # ]:          0 :         delete[] mppLibStreams;
     138                 :            :     }
     139                 :        124 : }
     140                 :            : 
     141                 :            : //============================================================================
     142                 :            : // BasMgrContainerListenerImpl
     143                 :            : //============================================================================
     144                 :            : 
     145                 :            : typedef ::cppu::WeakImplHelper1< ::com::sun::star::container::XContainerListener > ContainerListenerHelper;
     146                 :            : 
     147         [ -  + ]:       1632 : class BasMgrContainerListenerImpl: public ContainerListenerHelper
     148                 :            : {
     149                 :            :     BasicManager* mpMgr;
     150                 :            :     ::rtl::OUString maLibName;      // empty -> no lib, but lib container
     151                 :            : 
     152                 :            : public:
     153                 :        947 :     BasMgrContainerListenerImpl( BasicManager* pMgr, ::rtl::OUString aLibName )
     154                 :            :         : mpMgr( pMgr )
     155                 :        947 :         , maLibName( aLibName ) {}
     156                 :            : 
     157                 :            :     static void insertLibraryImpl( const Reference< XLibraryContainer >& xScriptCont, BasicManager* pMgr,
     158                 :            :         Any aLibAny, ::rtl::OUString aLibName );
     159                 :            :     static void addLibraryModulesImpl( BasicManager* pMgr, Reference< XNameAccess > xLibNameAccess,
     160                 :            :         ::rtl::OUString aLibName );
     161                 :            : 
     162                 :            : 
     163                 :            :     // XEventListener
     164                 :            :     virtual void SAL_CALL disposing( const  ::com::sun::star::lang::EventObject& Source )
     165                 :            :         throw(::com::sun::star::uno::RuntimeException);
     166                 :            : 
     167                 :            :     // XContainerListener
     168                 :            :     virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event )
     169                 :            :         throw(::com::sun::star::uno::RuntimeException);
     170                 :            :     virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event )
     171                 :            :         throw(::com::sun::star::uno::RuntimeException);
     172                 :            :     virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event )
     173                 :            :         throw(::com::sun::star::uno::RuntimeException);
     174                 :            : };
     175                 :            : 
     176                 :            : 
     177                 :            : //============================================================================
     178                 :            : // BasMgrContainerListenerImpl
     179                 :            : //============================================================================
     180                 :            : 
     181                 :        760 : void BasMgrContainerListenerImpl::insertLibraryImpl( const Reference< XLibraryContainer >& xScriptCont,
     182                 :            :     BasicManager* pMgr, Any aLibAny, ::rtl::OUString aLibName )
     183                 :            : {
     184                 :        760 :     Reference< XNameAccess > xLibNameAccess;
     185         [ +  - ]:        760 :     aLibAny >>= xLibNameAccess;
     186                 :            : 
     187 [ +  - ][ +  - ]:        760 :     if( !pMgr->GetLib( aLibName ) )
         [ +  - ][ +  + ]
     188                 :            :     {
     189                 :        573 :         BasicManager* pBasMgr = static_cast< BasicManager* >( pMgr );
     190                 :            : #ifdef DBG_UTIL
     191                 :            :         StarBASIC* pLib =
     192                 :            : #endif
     193 [ +  - ][ +  - ]:        573 :         pBasMgr->CreateLibForLibContainer( aLibName, xScriptCont );
                 [ +  - ]
     194                 :            :         DBG_ASSERT( pLib, "XML Import: Basic library could not be created");
     195                 :            :     }
     196                 :            : 
     197         [ +  - ]:        760 :     Reference< XContainer> xLibContainer( xLibNameAccess, UNO_QUERY );
     198         [ +  - ]:        760 :     if( xLibContainer.is() )
     199                 :            :     {
     200                 :            :         // Register listener for library
     201                 :            :         Reference< XContainerListener > xLibraryListener
     202                 :            :             = static_cast< XContainerListener* >
     203 [ +  - ][ +  - ]:        760 :                 ( new BasMgrContainerListenerImpl( pMgr, aLibName ) );
                 [ +  - ]
     204 [ +  - ][ +  - ]:        760 :         xLibContainer->addContainerListener( xLibraryListener );
     205                 :            :     }
     206                 :            : 
     207 [ +  - ][ +  - ]:        760 :     if( xScriptCont->isLibraryLoaded( aLibName ) )
                 [ +  + ]
     208                 :            :     {
     209         [ +  - ]:        202 :         addLibraryModulesImpl( pMgr, xLibNameAccess, aLibName );
     210                 :        760 :     }
     211                 :        760 : }
     212                 :            : 
     213                 :            : 
     214                 :        202 : void BasMgrContainerListenerImpl::addLibraryModulesImpl( BasicManager* pMgr,
     215                 :            :     Reference< XNameAccess > xLibNameAccess, ::rtl::OUString aLibName )
     216                 :            : {
     217 [ +  - ][ +  - ]:        202 :     Sequence< ::rtl::OUString > aModuleNames = xLibNameAccess->getElementNames();
     218                 :        202 :     sal_Int32 nModuleCount = aModuleNames.getLength();
     219                 :            : 
     220 [ +  - ][ +  - ]:        202 :     StarBASIC* pLib = pMgr->GetLib( aLibName );
                 [ +  - ]
     221                 :            :     DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::addLibraryModulesImpl: Unknown lib!");
     222         [ +  - ]:        202 :     if( pLib )
     223                 :            :     {
     224                 :        202 :         const ::rtl::OUString* pNames = aModuleNames.getConstArray();
     225         [ +  + ]:        278 :         for( sal_Int32 j = 0 ; j < nModuleCount ; j++ )
     226                 :            :         {
     227                 :         76 :             ::rtl::OUString aModuleName = pNames[ j ];
     228 [ +  - ][ +  - ]:         76 :             Any aElement = xLibNameAccess->getByName( aModuleName );
     229                 :         76 :             ::rtl::OUString aMod;
     230                 :         76 :             aElement >>= aMod;
     231         [ +  - ]:         76 :             Reference< vba::XVBAModuleInfo > xVBAModuleInfo( xLibNameAccess, UNO_QUERY );
     232 [ +  - ][ +  - ]:         76 :             if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( aModuleName ) )
         [ +  - ][ -  + ]
                 [ -  + ]
     233                 :            :             {
     234 [ #  # ][ #  # ]:          0 :                 ModuleInfo mInfo = xVBAModuleInfo->getModuleInfo( aModuleName );
     235                 :            :                 OSL_TRACE("#addLibraryModulesImpl - aMod");
     236 [ #  # ][ #  # ]:          0 :                 pLib->MakeModule32( aModuleName, mInfo, aMod );
         [ #  # ][ #  # ]
     237                 :            :             }
     238                 :            :             else
     239 [ +  - ][ +  - ]:         76 :         pLib->MakeModule32( aModuleName, aMod );
                 [ +  - ]
     240                 :         76 :         }
     241                 :            : 
     242         [ +  - ]:        202 :         pLib->SetModified( sal_False );
     243         [ +  - ]:        202 :     }
     244                 :        202 : }
     245                 :            : 
     246                 :            : 
     247                 :            : 
     248                 :            : // XEventListener
     249                 :            : //----------------------------------------------------------------------------
     250                 :            : 
     251                 :          0 : void SAL_CALL BasMgrContainerListenerImpl::disposing( const  EventObject& Source )
     252                 :            :     throw( RuntimeException )
     253                 :            : {
     254                 :            :     (void)Source;
     255                 :          0 : }
     256                 :            : 
     257                 :            : // XContainerListener
     258                 :            : //----------------------------------------------------------------------------
     259                 :            : 
     260                 :        186 : void SAL_CALL BasMgrContainerListenerImpl::elementInserted( const ContainerEvent& Event )
     261                 :            :     throw( RuntimeException )
     262                 :            : {
     263                 :        186 :     sal_Bool bLibContainer = ( maLibName.getLength() == 0 );
     264                 :        186 :     ::rtl::OUString aName;
     265                 :        186 :     Event.Accessor >>= aName;
     266                 :            : 
     267         [ +  + ]:        186 :     if( bLibContainer )
     268                 :            :     {
     269         [ +  - ]:        121 :         Reference< XLibraryContainer > xScriptCont( Event.Source, UNO_QUERY );
     270         [ +  - ]:        121 :         insertLibraryImpl( xScriptCont, mpMgr, Event.Element, aName );
     271 [ +  - ][ +  - ]:        121 :         StarBASIC* pLib = mpMgr->GetLib( aName );
                 [ +  - ]
     272         [ +  - ]:        121 :         if ( pLib )
     273                 :            :         {
     274         [ +  - ]:        121 :             Reference< vba::XVBACompatibility > xVBACompat( xScriptCont, UNO_QUERY );
     275         [ +  - ]:        121 :             if ( xVBACompat.is() )
     276 [ +  - ][ +  - ]:        121 :                 pLib->SetVBAEnabled( xVBACompat->getVBACompatibilityMode() );
                 [ +  - ]
     277                 :        121 :         }
     278                 :            :     }
     279                 :            :     else
     280                 :            :     {
     281                 :            : 
     282 [ +  - ][ +  - ]:         65 :         StarBASIC* pLib = mpMgr->GetLib( maLibName );
                 [ +  - ]
     283                 :            :         DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::elementInserted: Unknown lib!");
     284         [ +  - ]:         65 :         if( pLib )
     285                 :            :         {
     286 [ +  - ][ +  - ]:         65 :             SbModule* pMod = pLib->FindModule( aName );
                 [ +  - ]
     287         [ +  - ]:         65 :             if( !pMod )
     288                 :            :             {
     289                 :         65 :             ::rtl::OUString aMod;
     290                 :         65 :             Event.Element >>= aMod;
     291         [ +  - ]:         65 :                 Reference< vba::XVBAModuleInfo > xVBAModuleInfo( Event.Source, UNO_QUERY );
     292 [ +  - ][ +  - ]:         65 :                 if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( aName ) )
         [ +  - ][ +  - ]
                 [ +  - ]
     293                 :            :                 {
     294 [ +  - ][ +  - ]:         65 :                     ModuleInfo mInfo = xVBAModuleInfo->getModuleInfo( aName );
     295 [ +  - ][ +  - ]:         65 :                     pLib->MakeModule32( aName, mInfo, aMod );
         [ +  - ][ +  - ]
     296                 :            :                 }
     297                 :            :                 else
     298 [ #  # ][ #  # ]:          0 :                     pLib->MakeModule32( aName, aMod );
                 [ #  # ]
     299         [ +  - ]:         65 :                 pLib->SetModified( sal_False );
     300                 :            :             }
     301                 :            :         }
     302                 :        186 :     }
     303                 :        186 : }
     304                 :            : 
     305                 :            : //----------------------------------------------------------------------------
     306                 :            : 
     307                 :          0 : void SAL_CALL BasMgrContainerListenerImpl::elementReplaced( const ContainerEvent& Event )
     308                 :            :     throw( RuntimeException )
     309                 :            : {
     310                 :          0 :     ::rtl::OUString aName;
     311                 :          0 :     Event.Accessor >>= aName;
     312                 :            : 
     313                 :            :     // Replace not possible for library container
     314                 :            : #ifdef DBG_UTIL
     315                 :            :     sal_Bool bLibContainer = ( maLibName.getLength() == 0 );
     316                 :            : #endif
     317                 :            :     DBG_ASSERT( !bLibContainer, "library container fired elementReplaced()");
     318                 :            : 
     319 [ #  # ][ #  # ]:          0 :     StarBASIC* pLib = mpMgr->GetLib( maLibName );
                 [ #  # ]
     320         [ #  # ]:          0 :     if( pLib )
     321                 :            :     {
     322 [ #  # ][ #  # ]:          0 :         SbModule* pMod = pLib->FindModule( aName );
                 [ #  # ]
     323                 :          0 :         ::rtl::OUString aMod;
     324                 :          0 :         Event.Element >>= aMod;
     325                 :            : 
     326         [ #  # ]:          0 :         if( pMod )
     327         [ #  # ]:          0 :                 pMod->SetSource32( aMod );
     328                 :            :         else
     329 [ #  # ][ #  # ]:          0 :                 pLib->MakeModule32( aName, aMod );
                 [ #  # ]
     330                 :            : 
     331         [ #  # ]:          0 :         pLib->SetModified( sal_False );
     332                 :          0 :     }
     333                 :          0 : }
     334                 :            : 
     335                 :            : //----------------------------------------------------------------------------
     336                 :            : 
     337                 :          0 : void SAL_CALL BasMgrContainerListenerImpl::elementRemoved( const ContainerEvent& Event )
     338                 :            :     throw( RuntimeException )
     339                 :            : {
     340                 :          0 :     ::rtl::OUString aName;
     341                 :          0 :     Event.Accessor >>= aName;
     342                 :            : 
     343                 :          0 :     sal_Bool bLibContainer = ( maLibName.getLength() == 0 );
     344         [ #  # ]:          0 :     if( bLibContainer )
     345                 :            :     {
     346 [ #  # ][ #  # ]:          0 :         StarBASIC* pLib = mpMgr->GetLib( aName );
                 [ #  # ]
     347         [ #  # ]:          0 :         if( pLib )
     348                 :            :         {
     349 [ #  # ][ #  # ]:          0 :             sal_uInt16 nLibId = mpMgr->GetLibId( aName );
                 [ #  # ]
     350         [ #  # ]:          0 :             mpMgr->RemoveLib( nLibId, sal_False );
     351                 :            :         }
     352                 :            :     }
     353                 :            :     else
     354                 :            :     {
     355 [ #  # ][ #  # ]:          0 :         StarBASIC* pLib = mpMgr->GetLib( maLibName );
                 [ #  # ]
     356 [ #  # ][ #  # ]:          0 :         SbModule* pMod = pLib ? pLib->FindModule( aName ) : NULL;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     357         [ #  # ]:          0 :         if( pMod )
     358                 :            :         {
     359         [ #  # ]:          0 :             pLib->Remove( pMod );
     360         [ #  # ]:          0 :             pLib->SetModified( sal_False );
     361                 :            :         }
     362                 :          0 :     }
     363                 :          0 : }
     364                 :            : 
     365                 :          0 : BasicError::BasicError( sal_uIntPtr nId, sal_uInt16 nR, const String& rErrStr ) :
     366                 :          0 :     aErrStr( rErrStr )
     367                 :            : {
     368                 :          0 :     nErrorId    = nId;
     369                 :          0 :     nReason     = nR;
     370                 :          0 : }
     371                 :            : 
     372                 :          0 : BasicError::BasicError( const BasicError& rErr ) :
     373                 :          0 :     aErrStr( rErr.aErrStr )
     374                 :            : {
     375                 :          0 :     nErrorId    = rErr.nErrorId;
     376                 :          0 :     nReason     = rErr.nReason;
     377                 :          0 : }
     378                 :            : 
     379                 :            : 
     380                 :            : //=====================================================================
     381                 :            : 
     382 [ +  - ][ +  - ]:        697 : class BasicLibInfo
         [ +  - ][ +  - ]
     383                 :            : {
     384                 :            : private:
     385                 :            :     StarBASICRef    xLib;
     386                 :            :     String          aLibName;
     387                 :            :     String          aStorageName;   // String is sufficient, unique at runtime
     388                 :            :     String          aRelStorageName;
     389                 :            :     String          aPassword;
     390                 :            : 
     391                 :            :     sal_Bool            bDoLoad;
     392                 :            :     sal_Bool            bReference;
     393                 :            :     sal_Bool            bPasswordVerified;
     394                 :            :     sal_Bool            bFoundInPath;   // Must not relativated again!
     395                 :            : 
     396                 :            :     // Lib represents library in new UNO library container
     397                 :            :     Reference< XLibraryContainer > mxScriptCont;
     398                 :            : 
     399                 :            : public:
     400                 :            :     BasicLibInfo();
     401                 :            : 
     402                 :            :     sal_Bool            IsReference() const     { return bReference; }
     403                 :          0 :     sal_Bool&           IsReference()           { return bReference; }
     404                 :            : 
     405                 :          0 :     sal_Bool            IsExtern() const        { return ! aStorageName.EqualsAscii(szImbedded); }
     406                 :            : 
     407                 :          0 :     void            SetStorageName( const String& rName )   { aStorageName = rName; }
     408                 :          0 :     const String&   GetStorageName() const                  { return aStorageName; }
     409                 :            : 
     410                 :          0 :     void            SetRelStorageName( const String& rN )   { aRelStorageName = rN; }
     411                 :          0 :     const String&   GetRelStorageName() const               { return aRelStorageName; }
     412                 :            : 
     413                 :      12879 :     StarBASICRef    GetLib() const
     414                 :            :     {
     415 [ +  + ][ +  - ]:      26217 :         if( mxScriptCont.is() && mxScriptCont->hasByName( aLibName ) &&
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
                 [ +  + ]
           [ -  +  #  # ]
     416 [ +  - ][ +  - ]:      13338 :             !mxScriptCont->isLibraryLoaded( aLibName ) )
         [ +  - ][ +  + ]
                 [ #  # ]
     417                 :          0 :                 return StarBASICRef();
     418                 :      12879 :         return xLib;
     419                 :            :     }
     420                 :          0 :     StarBASICRef&   GetLibRef()                         { return xLib; }
     421                 :        760 :     void            SetLib( StarBASIC* pBasic )         { xLib = pBasic; }
     422                 :            : 
     423                 :       7092 :     const String&   GetLibName() const                  { return aLibName; }
     424                 :        760 :     void            SetLibName( const String& rName )   { aLibName = rName; }
     425                 :            : 
     426                 :            :     // Only temporary for Load/Save
     427                 :          0 :     sal_Bool            DoLoad()                            { return bDoLoad; }
     428                 :            : 
     429                 :        106 :     sal_Bool            HasPassword() const                 { return aPassword.Len() != 0; }
     430                 :          0 :     const String&   GetPassword() const                 { return aPassword; }
     431                 :          0 :     void            SetPassword( const String& rNewPassword )
     432                 :          0 :                                                         { aPassword = rNewPassword; }
     433                 :            :     sal_Bool            IsPasswordVerified() const          { return bPasswordVerified; }
     434                 :          0 :     void            SetPasswordVerified()               { bPasswordVerified = sal_True; }
     435                 :            : 
     436                 :            :     sal_Bool            IsFoundInPath() const               { return bFoundInPath; }
     437                 :          0 :     void            SetFoundInPath( sal_Bool bInPath )      { bFoundInPath = bInPath; }
     438                 :            : 
     439                 :            :     static BasicLibInfo*    Create( SotStorageStream& rSStream );
     440                 :            : 
     441                 :          0 :     Reference< XLibraryContainer > GetLibraryContainer( void )
     442                 :          0 :         { return mxScriptCont; }
     443                 :        573 :     void SetLibraryContainer( const Reference< XLibraryContainer >& xScriptCont )
     444                 :        573 :         { mxScriptCont = xScriptCont; }
     445                 :            : };
     446                 :            : 
     447                 :            : 
     448                 :            : //=====================================================================
     449                 :            : 
     450         [ +  - ]:        187 : class BasicLibs
     451                 :            : {
     452                 :            : private:
     453                 :            :     vector< BasicLibInfo* > aList;
     454                 :            :     size_t CurrentLib;
     455                 :            : 
     456                 :            : public:
     457                 :            :     ~BasicLibs();
     458                 :            :     String          aBasicLibPath; // TODO: Should be member of manager, but currently not incompatible
     459                 :            :     BasicLibInfo*   GetObject( size_t i );
     460                 :            :     BasicLibInfo*   First();
     461                 :            :     BasicLibInfo*   Next();
     462                 :            :     size_t          GetPos( BasicLibInfo* LibInfo );
     463                 :        106 :     size_t          Count() const { return aList.size(); };
     464                 :          0 :     size_t          GetCurPos() const { return CurrentLib; };
     465                 :            :     void            Insert( BasicLibInfo* LibInfo );
     466                 :            :     BasicLibInfo*   Remove( BasicLibInfo* LibInfo );
     467                 :            : };
     468                 :            : 
     469         [ +  - ]:        124 : BasicLibs::~BasicLibs() {
     470         [ +  + ]:        821 :     for ( size_t i = 0, n = aList.size(); i < n; ++i )
     471 [ +  - ][ +  - ]:        697 :         delete aList[ i ];
     472                 :        124 :     aList.clear();
     473                 :        124 : }
     474                 :            : 
     475                 :      11167 : BasicLibInfo* BasicLibs::GetObject( size_t i )
     476                 :            : {
     477   [ +  -  -  + ]:      22334 :     if (  aList.empty()
                 [ -  + ]
     478                 :      11167 :        || aList.size()  <= i
     479                 :            :        )
     480                 :          0 :         return NULL;
     481                 :      11167 :     CurrentLib = i;
     482                 :      11167 :     return aList[ CurrentLib ];
     483                 :            : }
     484                 :            : 
     485                 :       2169 : BasicLibInfo* BasicLibs::First()
     486                 :            : {
     487         [ -  + ]:       2169 :     if ( aList.empty() )
     488                 :          0 :         return NULL;
     489                 :       2169 :     CurrentLib = 0;
     490                 :       2169 :     return aList[ CurrentLib ];
     491                 :            : }
     492                 :            : 
     493                 :       6075 : BasicLibInfo* BasicLibs::Next()
     494                 :            : {
     495   [ +  -  +  + ]:      12150 :     if (  aList.empty()
                 [ +  + ]
     496                 :       6075 :        || CurrentLib >= ( aList.size() - 1 )
     497                 :            :        )
     498                 :       1152 :         return NULL;
     499                 :       4923 :     ++CurrentLib;
     500                 :       6075 :     return aList[ CurrentLib ];
     501                 :            : }
     502                 :            : 
     503                 :          0 : size_t BasicLibs::GetPos( BasicLibInfo* LibInfo )
     504                 :            : {
     505         [ #  # ]:          0 :     for ( size_t i = 0, n = aList.size(); i < n; ++i )
     506         [ #  # ]:          0 :         if ( aList[ i ] == LibInfo )
     507                 :          0 :             return i;
     508                 :          0 :     return size_t( -1 );
     509                 :            : }
     510                 :            : 
     511                 :        760 : void BasicLibs::Insert( BasicLibInfo* LibInfo )
     512                 :            : {
     513                 :        760 :     aList.push_back( LibInfo );
     514                 :        760 :     CurrentLib = aList.size() - 1;
     515                 :        760 : }
     516                 :            : 
     517                 :          0 : BasicLibInfo* BasicLibs::Remove( BasicLibInfo* LibInfo )
     518                 :            : {
     519                 :          0 :     vector< BasicLibInfo* >::iterator it, eit = aList.end();
     520 [ #  # ][ #  # ]:          0 :     for (it = aList.begin(); it != eit; ++it)
     521                 :            :     {
     522         [ #  # ]:          0 :         if (*it == LibInfo)
     523                 :            :         {
     524         [ #  # ]:          0 :             aList.erase(it);
     525                 :          0 :             break;
     526                 :            :         }
     527                 :            :     }
     528                 :          0 :     return LibInfo;
     529                 :            : }
     530                 :            : 
     531                 :            : 
     532                 :            : //=====================================================================
     533                 :            : 
     534 [ +  - ][ +  - ]:        760 : BasicLibInfo::BasicLibInfo()
         [ +  - ][ +  - ]
     535                 :            : {
     536                 :        760 :     bReference          = sal_False;
     537                 :        760 :     bPasswordVerified   = sal_False;
     538                 :        760 :     bDoLoad             = sal_False;
     539                 :        760 :     bFoundInPath        = sal_False;
     540         [ +  - ]:        760 :     mxScriptCont        = NULL;
     541         [ +  - ]:        760 :     aStorageName        = rtl::OUString(szImbedded);
     542         [ +  - ]:        760 :     aRelStorageName     = rtl::OUString(szImbedded);
     543                 :        760 : }
     544                 :            : 
     545                 :          0 : BasicLibInfo* BasicLibInfo::Create( SotStorageStream& rSStream )
     546                 :            : {
     547 [ #  # ][ #  # ]:          0 :     BasicLibInfo* pInfo = new BasicLibInfo;
     548                 :            : 
     549                 :            :     sal_uInt32 nEndPos;
     550                 :            :     sal_uInt16 nId;
     551                 :            :     sal_uInt16 nVer;
     552                 :            : 
     553         [ #  # ]:          0 :     rSStream >> nEndPos;
     554         [ #  # ]:          0 :     rSStream >> nId;
     555         [ #  # ]:          0 :     rSStream >> nVer;
     556                 :            : 
     557                 :            :     DBG_ASSERT( nId == LIBINFO_ID, "Keine BasicLibInfo !?" );
     558         [ #  # ]:          0 :     if( nId == LIBINFO_ID )
     559                 :            :     {
     560                 :            :         // Reload?
     561                 :            :         sal_Bool bDoLoad;
     562         [ #  # ]:          0 :         rSStream >> bDoLoad;
     563                 :          0 :         pInfo->bDoLoad = bDoLoad;
     564                 :            : 
     565                 :            :         // The name of the lib...
     566 [ #  # ][ #  # ]:          0 :         String aName = rSStream.ReadUniOrByteString(rSStream.GetStreamCharSet());
     567         [ #  # ]:          0 :         pInfo->SetLibName( aName );
     568                 :            : 
     569                 :            :         // Absolute path...
     570 [ #  # ][ #  # ]:          0 :         String aStorageName = rSStream.ReadUniOrByteString(rSStream.GetStreamCharSet());
     571         [ #  # ]:          0 :         pInfo->SetStorageName( aStorageName );
     572                 :            : 
     573                 :            :         // Relative path...
     574 [ #  # ][ #  # ]:          0 :         String aRelStorageName = rSStream.ReadUniOrByteString(rSStream.GetStreamCharSet());
     575         [ #  # ]:          0 :         pInfo->SetRelStorageName( aRelStorageName );
     576                 :            : 
     577         [ #  # ]:          0 :         if ( nVer >= 2 )
     578                 :            :         {
     579                 :            :             sal_Bool bReferenz;
     580         [ #  # ]:          0 :             rSStream >> bReferenz;
     581                 :          0 :             pInfo->IsReference() = bReferenz;
     582                 :            :         }
     583                 :            : 
     584 [ #  # ][ #  # ]:          0 :         rSStream.Seek( nEndPos );
         [ #  # ][ #  # ]
     585                 :            :     }
     586                 :          0 :     return pInfo;
     587                 :            : }
     588                 :            : 
     589 [ +  - ][ +  - ]:         65 : BasicManager::BasicManager( SotStorage& rStorage, const String& rBaseURL, StarBASIC* pParentFromStdLib, String* pLibPath, sal_Bool bDocMgr ) : mbDocMgr( bDocMgr )
                 [ +  - ]
     590                 :            : {
     591                 :            :     DBG_CTOR( BasicManager, 0 );
     592                 :            : 
     593         [ +  - ]:         65 :     Init();
     594                 :            : 
     595         [ +  - ]:         65 :     if( pLibPath )
     596         [ +  - ]:         65 :         pLibs->aBasicLibPath = *pLibPath;
     597                 :            : 
     598 [ +  - ][ +  - ]:         65 :     String aStorName( rStorage.GetName() );
     599 [ +  - ][ +  - ]:         65 :     maStorageName = INetURLObject(aStorName, INET_PROT_FILE).GetMainURL( INetURLObject::NO_DECODE );
         [ +  - ][ +  - ]
                 [ +  - ]
     600                 :            : 
     601                 :            : 
     602                 :            :     // If there is no Manager Stream, no further actions are necessary
     603 [ +  - ][ +  - ]:         65 :     if ( rStorage.IsStream( String(RTL_CONSTASCII_USTRINGPARAM(szManagerStream)) ) )
         [ -  + ][ +  - ]
     604                 :            :     {
     605         [ #  # ]:          0 :         LoadBasicManager( rStorage, rBaseURL );
     606                 :            :         // StdLib contains Parent:
     607         [ #  # ]:          0 :         StarBASIC* pStdLib = GetStdLib();
     608                 :            :         DBG_ASSERT( pStdLib, "Standard-Lib not loaded?" );
     609         [ #  # ]:          0 :         if ( !pStdLib )
     610                 :            :         {
     611                 :            :             // Should never happen, but if it happens we wont crash...
     612 [ #  # ][ #  # ]:          0 :             pStdLib = new StarBASIC( NULL, mbDocMgr );
     613         [ #  # ]:          0 :             BasicLibInfo* pStdLibInfo = pLibs->GetObject( 0 );
     614         [ #  # ]:          0 :             if ( !pStdLibInfo )
     615         [ #  # ]:          0 :                 pStdLibInfo = CreateLibInfo();
     616         [ #  # ]:          0 :             pStdLibInfo->SetLib( pStdLib );
     617         [ #  # ]:          0 :             StarBASICRef xStdLib = pStdLibInfo->GetLib();
     618 [ #  # ][ #  # ]:          0 :             xStdLib->SetName( rtl::OUString(szStdLibName) );
                 [ #  # ]
     619 [ #  # ][ #  # ]:          0 :             pStdLibInfo->SetLibName( rtl::OUString(szStdLibName) );
                 [ #  # ]
     620                 :          0 :             xStdLib->SetFlag( SBX_DONTSTORE | SBX_EXTSEARCH );
     621 [ #  # ][ #  # ]:          0 :             xStdLib->SetModified( sal_False );
     622                 :            :         }
     623                 :            :         else
     624                 :            :         {
     625         [ #  # ]:          0 :             pStdLib->SetParent( pParentFromStdLib );
     626                 :            :             // The other get StdLib as parent:
     627 [ #  # ][ #  # ]:          0 :             for ( sal_uInt16 nBasic = 1; nBasic < GetLibCount(); nBasic++ )
     628                 :            :             {
     629         [ #  # ]:          0 :                 StarBASIC* pBasic = GetLib( nBasic );
     630         [ #  # ]:          0 :                 if ( pBasic )
     631                 :            :                 {
     632         [ #  # ]:          0 :                     pStdLib->Insert( pBasic );
     633                 :          0 :                     pBasic->SetFlag( SBX_EXTSEARCH );
     634                 :            :                 }
     635                 :            :             }
     636                 :            :             // Modified through insert
     637         [ #  # ]:          0 :             pStdLib->SetModified( sal_False );
     638                 :            :         }
     639                 :            : 
     640                 :            :         // #91626 Save all stream data to save it unmodified if basic isn't modified
     641                 :            :         // in an 6.0+ office. So also the old basic dialogs can be saved.
     642                 :            :         SotStorageStreamRef xManagerStream = rStorage.OpenSotStream
     643 [ #  # ][ #  # ]:          0 :             ( String(RTL_CONSTASCII_USTRINGPARAM(szManagerStream)), eStreamReadMode );
                 [ #  # ]
     644 [ #  # ][ #  # ]:          0 :         mpImpl->mpManagerStream = new SvMemoryStream();
     645         [ #  # ]:          0 :         *static_cast<SvStream*>(&xManagerStream) >> *mpImpl->mpManagerStream;
     646                 :            : 
     647                 :            :         SotStorageRef xBasicStorage = rStorage.OpenSotStorage
     648 [ #  # ][ #  # ]:          0 :                                 ( String(RTL_CONSTASCII_USTRINGPARAM(szBasicStorage)), eStorageReadMode, sal_False );
                 [ #  # ]
     649 [ #  # ][ #  # ]:          0 :         if( xBasicStorage.Is() && !xBasicStorage->GetError() )
                 [ #  # ]
     650                 :            :         {
     651         [ #  # ]:          0 :             sal_uInt16 nLibs = GetLibCount();
     652         [ #  # ]:          0 :             mpImpl->mppLibStreams = new SvMemoryStream*[ nLibs ];
     653         [ #  # ]:          0 :             for( sal_uInt16 nL = 0; nL < nLibs; nL++ )
     654                 :            :             {
     655         [ #  # ]:          0 :                 BasicLibInfo* pInfo = pLibs->GetObject( nL );
     656                 :            :                 DBG_ASSERT( pInfo, "pInfo?!" );
     657         [ #  # ]:          0 :                 SotStorageStreamRef xBasicStream = xBasicStorage->OpenSotStream( pInfo->GetLibName(), eStreamReadMode );
     658 [ #  # ][ #  # ]:          0 :                 mpImpl->mppLibStreams[nL] = new SvMemoryStream();
     659         [ #  # ]:          0 :                 *static_cast<SvStream*>(&xBasicStream) >> *( mpImpl->mppLibStreams[nL] );
     660         [ #  # ]:          0 :             }
     661                 :            :         }
     662                 :            :         else
     663 [ #  # ][ #  # ]:          0 :             mpImpl->mbError = sal_True;
     664                 :            :     }
     665                 :            :     else
     666                 :            :     {
     667         [ +  - ]:         65 :         ImpCreateStdLib( pParentFromStdLib );
     668 [ +  - ][ +  - ]:         65 :         if ( rStorage.IsStream( rtl::OUString(szOldManagerStream) ) )
         [ +  - ][ -  + ]
     669         [ #  # ]:          0 :             LoadOldBasicManager( rStorage );
     670         [ +  - ]:         65 :     }
     671                 :         65 : }
     672                 :            : 
     673                 :        106 : void copyToLibraryContainer( StarBASIC* pBasic, const LibraryContainerInfo& rInfo )
     674                 :            : {
     675 [ +  - ][ +  - ]:        106 :     Reference< XLibraryContainer > xScriptCont( rInfo.mxScriptCont.get() );
                 [ +  - ]
     676         [ -  + ]:        106 :     if ( !xScriptCont.is() )
     677                 :            :         return;
     678                 :            : 
     679 [ +  - ][ +  - ]:        106 :     String aLibName = pBasic->GetName();
     680 [ +  - ][ +  - ]:        106 :     if( !xScriptCont->hasByName( aLibName ) )
         [ +  - ][ +  - ]
     681 [ +  - ][ +  - ]:        106 :         xScriptCont->createLibrary( aLibName );
                 [ +  - ]
     682                 :            : 
     683 [ +  - ][ +  - ]:        106 :     Any aLibAny = xScriptCont->getByName( aLibName );
                 [ +  - ]
     684                 :        106 :     Reference< XNameContainer > xLib;
     685         [ +  - ]:        106 :     aLibAny >>= xLib;
     686         [ -  + ]:        106 :     if ( !xLib.is() )
     687                 :            :         return;
     688                 :            : 
     689         [ +  - ]:        106 :     sal_uInt16 nModCount = pBasic->GetModules()->Count();
     690         [ -  + ]:        106 :     for ( sal_uInt16 nMod = 0 ; nMod < nModCount ; nMod++ )
     691                 :            :     {
     692         [ #  # ]:          0 :         SbModule* pModule = (SbModule*)pBasic->GetModules()->Get( nMod );
     693                 :            :         DBG_ASSERT( pModule, "Modul nicht erhalten!" );
     694                 :            : 
     695 [ #  # ][ #  # ]:          0 :         String aModName = pModule->GetName();
     696 [ #  # ][ #  # ]:          0 :         if( !xLib->hasByName( aModName ) )
         [ #  # ][ #  # ]
     697                 :            :         {
     698         [ #  # ]:          0 :             ::rtl::OUString aSource = pModule->GetSource32();
     699                 :          0 :             Any aSourceAny;
     700         [ #  # ]:          0 :             aSourceAny <<= aSource;
     701 [ #  # ][ #  # ]:          0 :             xLib->insertByName( aModName, aSourceAny );
                 [ #  # ]
     702                 :            :         }
     703 [ #  # ][ -  + ]:        106 :     }
         [ -  + ][ +  - ]
         [ -  + ][ +  - ]
     704                 :            : }
     705                 :            : 
     706                 :        181 : const Reference< XPersistentLibraryContainer >& BasicManager::GetDialogLibraryContainer()  const
     707                 :            : {
     708                 :        181 :     return mpImpl->maContainerInfo.mxDialogCont;
     709                 :            : }
     710                 :            : 
     711                 :        221 : const Reference< XPersistentLibraryContainer >& BasicManager::GetScriptLibraryContainer()  const
     712                 :            : {
     713                 :        221 :     return mpImpl->maContainerInfo.mxScriptCont;
     714                 :            : }
     715                 :            : 
     716                 :        187 : void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo& rInfo )
     717                 :            : {
     718         [ +  - ]:        187 :     mpImpl->maContainerInfo = rInfo;
     719                 :            : 
     720 [ +  - ][ +  - ]:        187 :     Reference< XLibraryContainer > xScriptCont( mpImpl->maContainerInfo.mxScriptCont.get() );
                 [ +  - ]
     721         [ +  - ]:        187 :     StarBASIC* pStdLib = GetStdLib();
     722 [ +  - ][ +  - ]:        187 :     String aLibName = pStdLib->GetName();
     723         [ +  - ]:        187 :     if( xScriptCont.is() )
     724                 :            :     {
     725                 :            :         // Register listener for lib container
     726                 :        187 :         ::rtl::OUString aEmptyLibName;
     727                 :            :         Reference< XContainerListener > xLibContainerListener
     728                 :            :             = static_cast< XContainerListener* >
     729 [ +  - ][ +  - ]:        187 :                 ( new BasMgrContainerListenerImpl( this, aEmptyLibName ) );
                 [ +  - ]
     730                 :            : 
     731         [ +  - ]:        187 :         Reference< XContainer> xLibContainer( xScriptCont, UNO_QUERY );
     732 [ +  - ][ +  - ]:        187 :         xLibContainer->addContainerListener( xLibContainerListener );
     733                 :            : 
     734 [ +  - ][ +  - ]:        187 :         Sequence< ::rtl::OUString > aScriptLibNames = xScriptCont->getElementNames();
     735                 :        187 :         const ::rtl::OUString* pScriptLibName = aScriptLibNames.getConstArray();
     736                 :        187 :         sal_Int32 i, nNameCount = aScriptLibNames.getLength();
     737                 :            : 
     738         [ +  + ]:        187 :         if( nNameCount )
     739                 :            :         {
     740         [ +  + ]:        720 :             for( i = 0 ; i < nNameCount ; ++i, ++pScriptLibName )
     741                 :            :             {
     742 [ +  - ][ +  - ]:        639 :                 Any aLibAny = xScriptCont->getByName( *pScriptLibName );
     743                 :            : 
     744         [ +  + ]:        639 :                 if ( *pScriptLibName == "Standard" )
     745 [ +  - ][ +  - ]:         66 :                     xScriptCont->loadLibrary( *pScriptLibName );
     746                 :            : 
     747                 :            :                 BasMgrContainerListenerImpl::insertLibraryImpl
     748         [ +  - ]:        639 :                     ( xScriptCont, this, aLibAny, *pScriptLibName );
     749                 :        639 :             }
     750                 :            :         }
     751                 :            :         else
     752                 :            :         {
     753                 :            :             // No libs? Maybe an 5.2 document already loaded
     754         [ +  - ]:        106 :             sal_uInt16 nLibs = GetLibCount();
     755         [ +  + ]:        212 :             for( sal_uInt16 nL = 0; nL < nLibs; nL++ )
     756                 :            :             {
     757         [ +  - ]:        106 :                 BasicLibInfo* pBasLibInfo = pLibs->GetObject( nL );
     758 [ +  - ][ +  - ]:        106 :                 StarBASIC* pLib = pBasLibInfo->GetLib();
     759         [ -  + ]:        106 :                 if( !pLib )
     760                 :            :                 {
     761         [ #  # ]:          0 :                     sal_Bool bLoaded = ImpLoadLibary( pBasLibInfo, NULL, sal_False );
     762         [ #  # ]:          0 :                     if( bLoaded )
     763 [ #  # ][ #  # ]:          0 :                         pLib = pBasLibInfo->GetLib();
     764                 :            :                 }
     765         [ +  - ]:        106 :                 if( pLib )
     766                 :            :                 {
     767         [ +  - ]:        106 :                     copyToLibraryContainer( pLib, mpImpl->maContainerInfo );
     768         [ -  + ]:        106 :                     if( pBasLibInfo->HasPassword() )
     769                 :            :                     {
     770                 :            :                         OldBasicPassword* pOldBasicPassword =
     771                 :          0 :                             mpImpl->maContainerInfo.mpOldBasicPassword;
     772         [ #  # ]:          0 :                         if( pOldBasicPassword )
     773                 :            :                         {
     774                 :            :                             pOldBasicPassword->setLibraryPassword
     775 [ #  # ][ #  # ]:          0 :                                 ( pLib->GetName(), pBasLibInfo->GetPassword() );
     776                 :          0 :                             pBasLibInfo->SetPasswordVerified();
     777                 :            :                         }
     778                 :            :                     }
     779                 :            :                 }
     780                 :            :             }
     781         [ +  - ]:        187 :         }
     782                 :            :     }
     783                 :            : 
     784 [ +  - ][ +  - ]:        187 :     SetGlobalUNOConstant( "BasicLibraries", makeAny( mpImpl->maContainerInfo.mxScriptCont ) );
     785 [ +  - ][ +  - ]:        187 :     SetGlobalUNOConstant( "DialogLibraries", makeAny( mpImpl->maContainerInfo.mxDialogCont ) );
                 [ +  - ]
     786                 :        187 : }
     787                 :            : 
     788 [ +  - ][ +  - ]:        122 : BasicManager::BasicManager( StarBASIC* pSLib, String* pLibPath, sal_Bool bDocMgr ) : mbDocMgr( bDocMgr )
                 [ +  - ]
     789                 :            : {
     790                 :            :     DBG_CTOR( BasicManager, 0 );
     791         [ +  - ]:        122 :     Init();
     792                 :            :     DBG_ASSERT( pSLib, "BasicManager cannot be created with a NULL-Pointer!" );
     793                 :            : 
     794         [ +  - ]:        122 :     if( pLibPath )
     795         [ +  - ]:        122 :         pLibs->aBasicLibPath = *pLibPath;
     796                 :            : 
     797         [ +  - ]:        122 :     BasicLibInfo* pStdLibInfo = CreateLibInfo();
     798         [ +  - ]:        122 :     pStdLibInfo->SetLib( pSLib );
     799         [ +  - ]:        122 :     StarBASICRef xStdLib = pStdLibInfo->GetLib();
     800 [ +  - ][ +  - ]:        122 :     xStdLib->SetName(rtl::OUString(szStdLibName));
                 [ +  - ]
     801 [ +  - ][ +  - ]:        122 :     pStdLibInfo->SetLibName( rtl::OUString(szStdLibName) );
                 [ +  - ]
     802                 :        122 :     pSLib->SetFlag( SBX_DONTSTORE | SBX_EXTSEARCH );
     803                 :            : 
     804                 :            :     // Save is only necessary if basic has changed
     805 [ +  - ][ +  - ]:        122 :     xStdLib->SetModified( sal_False );
     806                 :        122 : }
     807                 :            : 
     808                 :          0 : void BasicManager::ImpMgrNotLoaded( const String& rStorageName )
     809                 :            : {
     810                 :            :     // pErrInf is only destroyed if the error os processed by an
     811                 :            :     // ErrorHandler
     812 [ #  # ][ #  # ]:          0 :     StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, rStorageName, ERRCODE_BUTTON_OK );
     813 [ #  # ][ #  # ]:          0 :     aErrors.push_back(BasicError(*pErrInf, BASERR_REASON_OPENMGRSTREAM, rStorageName));
         [ #  # ][ #  # ]
     814                 :            : 
     815                 :            :     // Create a stdlib otherwise we crash!
     816         [ #  # ]:          0 :     BasicLibInfo* pStdLibInfo = CreateLibInfo();
     817 [ #  # ][ #  # ]:          0 :     pStdLibInfo->SetLib( new StarBASIC( NULL, mbDocMgr ) );
                 [ #  # ]
     818         [ #  # ]:          0 :     StarBASICRef xStdLib = pStdLibInfo->GetLib();
     819 [ #  # ][ #  # ]:          0 :     xStdLib->SetName( rtl::OUString(szStdLibName) );
                 [ #  # ]
     820 [ #  # ][ #  # ]:          0 :     pStdLibInfo->SetLibName( rtl::OUString(szStdLibName) );
                 [ #  # ]
     821                 :          0 :     xStdLib->SetFlag( SBX_DONTSTORE | SBX_EXTSEARCH );
     822 [ #  # ][ #  # ]:          0 :     xStdLib->SetModified( sal_False );
     823                 :          0 : }
     824                 :            : 
     825                 :            : 
     826                 :         65 : void BasicManager::ImpCreateStdLib( StarBASIC* pParentFromStdLib )
     827                 :            : {
     828                 :         65 :     BasicLibInfo* pStdLibInfo = CreateLibInfo();
     829         [ +  - ]:         65 :     StarBASIC* pStdLib = new StarBASIC( pParentFromStdLib, mbDocMgr );
     830                 :         65 :     pStdLibInfo->SetLib( pStdLib );
     831 [ +  - ][ +  - ]:         65 :     pStdLib->SetName( rtl::OUString(szStdLibName) );
                 [ +  - ]
     832 [ +  - ][ +  - ]:         65 :     pStdLibInfo->SetLibName( rtl::OUString(szStdLibName) );
                 [ +  - ]
     833                 :         65 :     pStdLib->SetFlag( SBX_DONTSTORE | SBX_EXTSEARCH );
     834                 :         65 : }
     835                 :            : 
     836                 :          0 : void BasicManager::LoadBasicManager( SotStorage& rStorage, const String& rBaseURL, sal_Bool bLoadLibs )
     837                 :            : {
     838                 :            :     DBG_CHKTHIS( BasicManager, 0 );
     839                 :            : 
     840                 :            : 
     841                 :            :     SotStorageStreamRef xManagerStream = rStorage.OpenSotStream
     842 [ #  # ][ #  # ]:          0 :         ( String(RTL_CONSTASCII_USTRINGPARAM(szManagerStream)), eStreamReadMode );
                 [ #  # ]
     843                 :            : 
     844 [ #  # ][ #  # ]:          0 :     String aStorName( rStorage.GetName() );
     845                 :            :     // #i13114 removed, DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
     846                 :            : 
     847 [ #  # ][ #  # ]:          0 :     if ( !xManagerStream.Is() || xManagerStream->GetError() || ( xManagerStream->Seek( STREAM_SEEK_TO_END ) == 0 ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     848                 :            :     {
     849         [ #  # ]:          0 :         ImpMgrNotLoaded( aStorName );
     850                 :            :         return;
     851                 :            :     }
     852                 :            : 
     853 [ #  # ][ #  # ]:          0 :     maStorageName = INetURLObject(aStorName, INET_PROT_FILE).GetMainURL( INetURLObject::NO_DECODE );
         [ #  # ][ #  # ]
                 [ #  # ]
     854                 :            :     // #i13114 removed, DBG_ASSERT(aStorageName.Len() != 0, "Bad storage name");
     855                 :            : 
     856         [ #  # ]:          0 :     String aRealStorageName = maStorageName;  // for relative paths, can be modified through BaseURL
     857                 :            : 
     858         [ #  # ]:          0 :     if ( rBaseURL.Len() )
     859                 :            :     {
     860 [ #  # ][ #  # ]:          0 :         INetURLObject aObj( rBaseURL );
     861         [ #  # ]:          0 :         if ( aObj.GetProtocol() == INET_PROT_FILE )
     862 [ #  # ][ #  # ]:          0 :             aRealStorageName = aObj.PathToFileName();
                 [ #  # ]
     863                 :            :     }
     864                 :            : 
     865         [ #  # ]:          0 :     xManagerStream->SetBufferSize( 1024 );
     866         [ #  # ]:          0 :     xManagerStream->Seek( STREAM_SEEK_TO_BEGIN );
     867                 :            : 
     868                 :            :     sal_uInt32 nEndPos;
     869         [ #  # ]:          0 :     *xManagerStream >> nEndPos;
     870                 :            : 
     871                 :            :     sal_uInt16 nLibs;
     872         [ #  # ]:          0 :     *xManagerStream >> nLibs;
     873                 :            :     // Plausibility!
     874         [ #  # ]:          0 :     if( nLibs & 0xF000 )
     875                 :            :     {
     876                 :            :         DBG_ASSERT( !this, "BasicManager-Stream defect!" );
     877                 :            :         return;
     878                 :            :     }
     879         [ #  # ]:          0 :     for ( sal_uInt16 nL = 0; nL < nLibs; nL++ )
     880                 :            :     {
     881         [ #  # ]:          0 :         BasicLibInfo* pInfo = BasicLibInfo::Create( *xManagerStream );
     882                 :            : 
     883                 :            :         // Correct absolute pathname if relative is existing.
     884                 :            :         // Always try relative first if there are two stands on disk
     885 [ #  # ][ #  # ]:          0 :         if ( pInfo->GetRelStorageName().Len() && ( ! pInfo->GetRelStorageName().EqualsAscii(szImbedded) ) )
         [ #  # ][ #  # ]
     886                 :            :         {
     887 [ #  # ][ #  # ]:          0 :             INetURLObject aObj( aRealStorageName, INET_PROT_FILE );
     888         [ #  # ]:          0 :             aObj.removeSegment();
     889                 :          0 :             bool bWasAbsolute = sal_False;
     890 [ #  # ][ #  # ]:          0 :             aObj = aObj.smartRel2Abs( pInfo->GetRelStorageName(), bWasAbsolute );
         [ #  # ][ #  # ]
     891                 :            : 
     892                 :            :             //*** TODO: Replace if still necessary
     893                 :            :             //*** TODO-End
     894         [ #  # ]:          0 :             if ( pLibs->aBasicLibPath.Len() )
     895                 :            :             {
     896                 :            :                 // Search lib in path
     897         [ #  # ]:          0 :                 String aSearchFile = pInfo->GetRelStorageName();
     898         [ #  # ]:          0 :                 SvtPathOptions aPathCFG;
     899 [ #  # ][ #  # ]:          0 :                 if( aPathCFG.SearchFile( aSearchFile, SvtPathOptions::PATH_BASIC ) )
     900                 :            :                 {
     901         [ #  # ]:          0 :                     pInfo->SetStorageName( aSearchFile );
     902                 :          0 :                     pInfo->SetFoundInPath( sal_True );
     903 [ #  # ][ #  # ]:          0 :                 }
     904         [ #  # ]:          0 :             }
     905                 :            :         }
     906                 :            : 
     907         [ #  # ]:          0 :         pLibs->Insert( pInfo );
     908                 :            :         // Libs from external files should be loaded only when necessary.
     909                 :            :         // But references are loaded at once, otherwise some big customers get into trouble
     910 [ #  # ][ #  # ]:          0 :         if ( bLoadLibs && pInfo->DoLoad() &&
           [ #  #  #  # ]
                 [ #  # ]
     911         [ #  # ]:          0 :             ( ( !pInfo->IsExtern() ) || ( pInfo->IsReference() ) ) )
     912                 :            :         {
     913         [ #  # ]:          0 :             ImpLoadLibary( pInfo, &rStorage );
     914                 :            :         }
     915                 :            :     }
     916                 :            : 
     917         [ #  # ]:          0 :     xManagerStream->Seek( nEndPos );
     918         [ #  # ]:          0 :     xManagerStream->SetBufferSize( 0 );
     919 [ #  # ][ #  # ]:          0 :     xManagerStream.Clear();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     920                 :            : }
     921                 :            : 
     922                 :          0 : void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
     923                 :            : {
     924                 :            :     DBG_CHKTHIS( BasicManager, 0 );
     925                 :            : 
     926                 :            : 
     927                 :            :     SotStorageStreamRef xManagerStream = rStorage.OpenSotStream
     928 [ #  # ][ #  # ]:          0 :         ( rtl::OUString(szOldManagerStream), eStreamReadMode );
                 [ #  # ]
     929                 :            : 
     930 [ #  # ][ #  # ]:          0 :     String aStorName( rStorage.GetName() );
     931                 :            :     DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
     932                 :            : 
     933 [ #  # ][ #  # ]:          0 :     if ( !xManagerStream.Is() || xManagerStream->GetError() || ( xManagerStream->Seek( STREAM_SEEK_TO_END ) == 0 ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     934                 :            :     {
     935         [ #  # ]:          0 :         ImpMgrNotLoaded( aStorName );
     936                 :          0 :         return;
     937                 :            :     }
     938                 :            : 
     939         [ #  # ]:          0 :     xManagerStream->SetBufferSize( 1024 );
     940         [ #  # ]:          0 :     xManagerStream->Seek( STREAM_SEEK_TO_BEGIN );
     941                 :            :     sal_uInt32 nBasicStartOff, nBasicEndOff;
     942         [ #  # ]:          0 :     *xManagerStream >> nBasicStartOff;
     943         [ #  # ]:          0 :     *xManagerStream >> nBasicEndOff;
     944                 :            : 
     945                 :            :     DBG_ASSERT( !xManagerStream->GetError(), "Ungueltiger Manager-Stream!" );
     946                 :            : 
     947         [ #  # ]:          0 :     xManagerStream->Seek( nBasicStartOff );
     948 [ #  # ][ #  # ]:          0 :     if( !ImplLoadBasic( *xManagerStream, pLibs->GetObject(0)->GetLibRef() ) )
                 [ #  # ]
     949                 :            :     {
     950 [ #  # ][ #  # ]:          0 :         StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, aStorName, ERRCODE_BUTTON_OK );
     951 [ #  # ][ #  # ]:          0 :         aErrors.push_back(BasicError(*pErrInf, BASERR_REASON_OPENMGRSTREAM, aStorName));
         [ #  # ][ #  # ]
     952                 :            :         // and it proceeds ...
     953                 :            :     }
     954         [ #  # ]:          0 :     xManagerStream->Seek( nBasicEndOff+1 ); // +1: 0x00 as separator
     955 [ #  # ][ #  # ]:          0 :     String aLibs = xManagerStream->ReadUniOrByteString(xManagerStream->GetStreamCharSet());
     956         [ #  # ]:          0 :     xManagerStream->SetBufferSize( 0 );
     957         [ #  # ]:          0 :     xManagerStream.Clear(); // Close stream
     958                 :            : 
     959         [ #  # ]:          0 :     if ( aLibs.Len() )
     960                 :            :     {
     961         [ #  # ]:          0 :         String aCurStorageName( aStorName );
     962 [ #  # ][ #  # ]:          0 :         INetURLObject aCurStorage( aCurStorageName, INET_PROT_FILE );
     963 [ #  # ][ #  # ]:          0 :         sal_Int32 nLibs = comphelper::string::getTokenCount(aLibs, LIB_SEP);
     964         [ #  # ]:          0 :         for ( sal_Int32 nLib = 0; nLib < nLibs; nLib++ )
     965                 :            :         {
     966 [ #  # ][ #  # ]:          0 :             String aLibInfo(comphelper::string::getToken(aLibs, nLib, LIB_SEP));
     967                 :            :             // TODO: Remove == 2
     968                 :            :             DBG_ASSERT( ( comphelper::string::getTokenCount(aLibInfo, LIBINFO_SEP) == 2 ) || ( comphelper::string::getTokenCount(aLibInfo, LIBINFO_SEP) == 3 ), "Ungueltige Lib-Info!" );
     969         [ #  # ]:          0 :             String aLibName( aLibInfo.GetToken( 0, LIBINFO_SEP ) );
     970         [ #  # ]:          0 :             String aLibAbsStorageName( aLibInfo.GetToken( 1, LIBINFO_SEP ) );
     971         [ #  # ]:          0 :             String aLibRelStorageName( aLibInfo.GetToken( 2, LIBINFO_SEP ) );
     972 [ #  # ][ #  # ]:          0 :             INetURLObject aLibAbsStorage( aLibAbsStorageName, INET_PROT_FILE );
     973                 :            : 
     974 [ #  # ][ #  # ]:          0 :             INetURLObject aLibRelStorage( aStorName );
     975         [ #  # ]:          0 :             aLibRelStorage.removeSegment();
     976                 :          0 :             bool bWasAbsolute = sal_False;
     977 [ #  # ][ #  # ]:          0 :             aLibRelStorage = aLibRelStorage.smartRel2Abs( aLibRelStorageName, bWasAbsolute);
         [ #  # ][ #  # ]
     978                 :            :             DBG_ASSERT(!bWasAbsolute, "RelStorageName was absolute!" );
     979                 :            : 
     980                 :          0 :             SotStorageRef xStorageRef;
     981 [ #  # ][ #  # ]:          0 :             if ( ( aLibAbsStorage == aCurStorage ) || ( aLibRelStorageName.EqualsAscii(szImbedded) ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     982         [ #  # ]:          0 :                 xStorageRef = &rStorage;
     983                 :            :             else
     984                 :            :             {
     985                 :            :                 xStorageRef = new SotStorage( sal_False, aLibAbsStorage.GetMainURL
     986 [ #  # ][ #  # ]:          0 :                     ( INetURLObject::NO_DECODE ), eStorageReadMode, sal_True );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     987         [ #  # ]:          0 :                 if ( xStorageRef->GetError() != ERRCODE_NONE )
     988                 :            :                     xStorageRef = new SotStorage( sal_False, aLibRelStorage.
     989 [ #  # ][ #  # ]:          0 :                     GetMainURL( INetURLObject::NO_DECODE ), eStorageReadMode, sal_True );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     990                 :            :             }
     991         [ #  # ]:          0 :             if ( xStorageRef.Is() )
     992         [ #  # ]:          0 :                 AddLib( *xStorageRef, aLibName, sal_False );
     993                 :            :             else
     994                 :            :             {
     995 [ #  # ][ #  # ]:          0 :                 StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, aStorName, ERRCODE_BUTTON_OK );
     996 [ #  # ][ #  # ]:          0 :                 aErrors.push_back(BasicError(*pErrInf, BASERR_REASON_STORAGENOTFOUND, aStorName));
         [ #  # ][ #  # ]
     997                 :            :             }
     998 [ #  # ][ #  # ]:          0 :         }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     999 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
                 [ #  # ]
    1000                 :            : }
    1001                 :            : 
    1002 [ +  - ][ +  - ]:        124 : BasicManager::~BasicManager()
    1003                 :            : {
    1004                 :            :     DBG_DTOR( BasicManager, 0 );
    1005                 :            : 
    1006                 :            :     // Notify listener if something needs to be saved
    1007 [ +  - ][ +  - ]:        124 :     Broadcast( SfxSimpleHint( SFX_HINT_DYING) );
                 [ +  - ]
    1008                 :            : 
    1009                 :            :     // Destroy Basic-Infos...
    1010                 :            :     // In reverse order
    1011 [ +  - ][ +  - ]:        124 :     delete pLibs;
    1012 [ +  - ][ +  - ]:        124 :     delete mpImpl;
    1013         [ -  + ]:        248 : }
    1014                 :            : 
    1015                 :          0 : void BasicManager::LegacyDeleteBasicManager( BasicManager*& _rpManager )
    1016                 :            : {
    1017         [ #  # ]:          0 :     delete _rpManager;
    1018                 :          0 :     _rpManager = NULL;
    1019                 :          0 : }
    1020                 :            : 
    1021                 :            : 
    1022                 :         63 : bool BasicManager::HasExeCode( const String& sLib )
    1023                 :            : {
    1024                 :         63 :     StarBASIC* pLib = GetLib(sLib);
    1025         [ +  - ]:         63 :     if ( pLib )
    1026                 :            :     {
    1027                 :         63 :         SbxArray* pMods = pLib->GetModules();
    1028         [ +  - ]:         63 :         sal_uInt16 nMods = pMods ? pMods->Count() : 0;
    1029         [ +  + ]:         67 :         for( sal_uInt16 i = 0; i < nMods; i++ )
    1030                 :            :         {
    1031                 :         21 :             SbModule* p = (SbModule*) pMods->Get( i );
    1032         [ +  - ]:         21 :             if ( p )
    1033         [ +  + ]:         21 :                 if ( p->HasExeCode() )
    1034                 :         17 :                     return true;
    1035                 :            :         }
    1036                 :            :     }
    1037                 :         63 :     return false;
    1038                 :            : }
    1039                 :            : 
    1040                 :        187 : void BasicManager::Init()
    1041                 :            : {
    1042                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1043                 :            : 
    1044         [ +  - ]:        187 :     pLibs = new BasicLibs;
    1045         [ +  - ]:        187 :     mpImpl = new BasicManagerImpl();
    1046                 :        187 : }
    1047                 :            : 
    1048                 :        760 : BasicLibInfo* BasicManager::CreateLibInfo()
    1049                 :            : {
    1050                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1051                 :            : 
    1052         [ +  - ]:        760 :     BasicLibInfo* pInf = new BasicLibInfo;
    1053                 :        760 :     pLibs->Insert( pInf );
    1054                 :        760 :     return pInf;
    1055                 :            : }
    1056                 :            : 
    1057                 :          0 : sal_Bool BasicManager::ImpLoadLibary( BasicLibInfo* pLibInfo, SotStorage* pCurStorage, sal_Bool bInfosOnly )
    1058                 :            : {
    1059                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1060                 :            : 
    1061                 :            :     DBG_ASSERT( pLibInfo, "LibInfo!?" );
    1062                 :            : 
    1063         [ #  # ]:          0 :     String aStorageName( pLibInfo->GetStorageName() );
    1064 [ #  # ][ #  # ]:          0 :     if ( !aStorageName.Len() || ( aStorageName.EqualsAscii(szImbedded) ) )
         [ #  # ][ #  # ]
    1065 [ #  # ][ #  # ]:          0 :         aStorageName = GetStorageName();
                 [ #  # ]
    1066                 :            : 
    1067                 :          0 :     SotStorageRef xStorage;
    1068                 :            :     // The current must not be opened again...
    1069         [ #  # ]:          0 :     if ( pCurStorage )
    1070                 :            :     {
    1071 [ #  # ][ #  # ]:          0 :         String aStorName( pCurStorage->GetName() );
    1072                 :            :         // #i13114 removed, DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
    1073                 :            : 
    1074 [ #  # ][ #  # ]:          0 :         INetURLObject aCurStorageEntry(aStorName, INET_PROT_FILE);
    1075                 :            :         // #i13114 removed, DBG_ASSERT(aCurStorageEntry.GetMainURL( INetURLObject::NO_DECODE ).Len() != 0, "Bad storage name");
    1076                 :            : 
    1077 [ #  # ][ #  # ]:          0 :         INetURLObject aStorageEntry(aStorageName, INET_PROT_FILE);
    1078                 :            :         // #i13114 removed, DBG_ASSERT(aCurStorageEntry.GetMainURL( INetURLObject::NO_DECODE ).Len() != 0, "Bad storage name");
    1079                 :            : 
    1080 [ #  # ][ #  # ]:          0 :         if ( aCurStorageEntry == aStorageEntry )
    1081 [ #  # ][ #  # ]:          0 :             xStorage = pCurStorage;
         [ #  # ][ #  # ]
    1082                 :            :     }
    1083                 :            : 
    1084         [ #  # ]:          0 :     if ( !xStorage.Is() )
    1085 [ #  # ][ #  # ]:          0 :         xStorage = new SotStorage( sal_False, aStorageName, eStorageReadMode );
                 [ #  # ]
    1086                 :            : 
    1087                 :            :     SotStorageRef xBasicStorage = xStorage->OpenSotStorage
    1088 [ #  # ][ #  # ]:          0 :                             ( String(RTL_CONSTASCII_USTRINGPARAM(szBasicStorage)), eStorageReadMode, sal_False );
                 [ #  # ]
    1089                 :            : 
    1090 [ #  # ][ #  # ]:          0 :     if ( !xBasicStorage.Is() || xBasicStorage->GetError() )
                 [ #  # ]
    1091                 :            :     {
    1092 [ #  # ][ #  # ]:          0 :         StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, xStorage->GetName(), ERRCODE_BUTTON_OK );
                 [ #  # ]
    1093 [ #  # ][ #  # ]:          0 :         aErrors.push_back(BasicError(*pErrInf, BASERR_REASON_OPENLIBSTORAGE, pLibInfo->GetLibName()));
         [ #  # ][ #  # ]
    1094                 :            :     }
    1095                 :            :     else
    1096                 :            :     {
    1097                 :            :         // In the Basic-Storage every lib is in a Stream...
    1098         [ #  # ]:          0 :         SotStorageStreamRef xBasicStream = xBasicStorage->OpenSotStream( pLibInfo->GetLibName(), eStreamReadMode );
    1099 [ #  # ][ #  # ]:          0 :         if ( !xBasicStream.Is() || xBasicStream->GetError() )
                 [ #  # ]
    1100                 :            :         {
    1101 [ #  # ][ #  # ]:          0 :             StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD , pLibInfo->GetLibName(), ERRCODE_BUTTON_OK );
    1102 [ #  # ][ #  # ]:          0 :             aErrors.push_back(BasicError(*pErrInf, BASERR_REASON_OPENLIBSTREAM, pLibInfo->GetLibName()));
         [ #  # ][ #  # ]
    1103                 :            :         }
    1104                 :            :         else
    1105                 :            :         {
    1106                 :          0 :             sal_Bool bLoaded = sal_False;
    1107 [ #  # ][ #  # ]:          0 :             if ( xBasicStream->Seek( STREAM_SEEK_TO_END ) != 0 )
    1108                 :            :             {
    1109         [ #  # ]:          0 :                 if ( !bInfosOnly )
    1110                 :            :                 {
    1111 [ #  # ][ #  # ]:          0 :                     if ( !pLibInfo->GetLib().Is() )
                 [ #  # ]
    1112 [ #  # ][ #  # ]:          0 :                         pLibInfo->SetLib( new StarBASIC( GetStdLib(), mbDocMgr ) );
         [ #  # ][ #  # ]
    1113         [ #  # ]:          0 :                     xBasicStream->SetBufferSize( 1024 );
    1114         [ #  # ]:          0 :                     xBasicStream->Seek( STREAM_SEEK_TO_BEGIN );
    1115         [ #  # ]:          0 :                     bLoaded = ImplLoadBasic( *xBasicStream, pLibInfo->GetLibRef() );
    1116         [ #  # ]:          0 :                     xBasicStream->SetBufferSize( 0 );
    1117         [ #  # ]:          0 :                     StarBASICRef xStdLib = pLibInfo->GetLib();
    1118         [ #  # ]:          0 :                     xStdLib->SetName( pLibInfo->GetLibName() );
    1119         [ #  # ]:          0 :                     xStdLib->SetModified( sal_False );
    1120         [ #  # ]:          0 :                     xStdLib->SetFlag( SBX_DONTSTORE );
    1121                 :            :                 }
    1122                 :            :                 else
    1123                 :            :                 {
    1124                 :            :                     // Skip Basic...
    1125         [ #  # ]:          0 :                     xBasicStream->Seek( STREAM_SEEK_TO_BEGIN );
    1126         [ #  # ]:          0 :                     ImplEncryptStream( *xBasicStream );
    1127         [ #  # ]:          0 :                     SbxBase::Skip( *xBasicStream );
    1128                 :          0 :                     bLoaded = sal_True;
    1129                 :            :                 }
    1130                 :            :             }
    1131         [ #  # ]:          0 :             if ( !bLoaded )
    1132                 :            :             {
    1133 [ #  # ][ #  # ]:          0 :                 StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, pLibInfo->GetLibName(), ERRCODE_BUTTON_OK );
    1134 [ #  # ][ #  # ]:          0 :                 aErrors.push_back(BasicError(*pErrInf, BASERR_REASON_BASICLOADERROR, pLibInfo->GetLibName()));
         [ #  # ][ #  # ]
    1135                 :            :             }
    1136                 :            :             else
    1137                 :            :             {
    1138                 :            :                 // Perhaps there are additional information in the stream...
    1139         [ #  # ]:          0 :                 xBasicStream->SetCryptMaskKey(szCryptingKey);
    1140         [ #  # ]:          0 :                 xBasicStream->RefreshBuffer();
    1141                 :          0 :                 sal_uInt32 nPasswordMarker = 0;
    1142         [ #  # ]:          0 :                 *xBasicStream >> nPasswordMarker;
    1143 [ #  # ][ #  # ]:          0 :                 if ( ( nPasswordMarker == PASSWORD_MARKER ) && !xBasicStream->IsEof() )
                 [ #  # ]
    1144                 :            :                 {
    1145                 :          0 :                     String aPassword = xBasicStream->ReadUniOrByteString(
    1146 [ #  # ][ #  # ]:          0 :                         xBasicStream->GetStreamCharSet());
    1147 [ #  # ][ #  # ]:          0 :                     pLibInfo->SetPassword( aPassword );
    1148                 :            :                 }
    1149         [ #  # ]:          0 :                 xBasicStream->SetCryptMaskKey(rtl::OString());
    1150 [ #  # ][ #  # ]:          0 :                 CheckModules( pLibInfo->GetLib(), pLibInfo->IsReference() );
                 [ #  # ]
    1151                 :            :             }
    1152                 :          0 :             return bLoaded;
    1153 [ #  # ][ #  # ]:          0 :         }
    1154                 :            :     }
    1155 [ #  # ][ #  # ]:          0 :     return sal_False;
                 [ #  # ]
    1156                 :            : }
    1157                 :            : 
    1158                 :          0 : sal_Bool BasicManager::ImplEncryptStream( SvStream& rStrm ) const
    1159                 :            : {
    1160                 :          0 :     sal_uIntPtr nPos = rStrm.Tell();
    1161                 :            :     sal_uInt32 nCreator;
    1162         [ #  # ]:          0 :     rStrm >> nCreator;
    1163         [ #  # ]:          0 :     rStrm.Seek( nPos );
    1164                 :          0 :     sal_Bool bProtected = sal_False;
    1165         [ #  # ]:          0 :     if ( nCreator != SBXCR_SBX )
    1166                 :            :     {
    1167                 :            :         // Should only be the case for encrypted Streams
    1168                 :          0 :         bProtected = sal_True;
    1169         [ #  # ]:          0 :         rStrm.SetCryptMaskKey(szCryptingKey);
    1170         [ #  # ]:          0 :         rStrm.RefreshBuffer();
    1171                 :            :     }
    1172                 :          0 :     return bProtected;
    1173                 :            : }
    1174                 :            : 
    1175                 :            : // This code is necessary to load the BASIC of Beta 1
    1176                 :            : // TODO: Which Beta 1?
    1177                 :          0 : sal_Bool BasicManager::ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) const
    1178                 :            : {
    1179         [ #  # ]:          0 :     sal_Bool bProtected = ImplEncryptStream( rStrm );
    1180         [ #  # ]:          0 :     SbxBaseRef xNew = SbxBase::Load( rStrm );
    1181                 :          0 :     sal_Bool bLoaded = sal_False;
    1182         [ #  # ]:          0 :     if( xNew.Is() )
    1183                 :            :     {
    1184 [ #  # ][ #  # ]:          0 :         if( xNew->IsA( TYPE(StarBASIC) ) )
                 [ #  # ]
    1185                 :            :         {
    1186                 :          0 :             StarBASIC* pNew = (StarBASIC*)(SbxBase*) xNew;
    1187                 :            :             // Use the Parent of the old BASICs
    1188         [ #  # ]:          0 :             if( rOldBasic.Is() )
    1189                 :            :             {
    1190 [ #  # ][ #  # ]:          0 :                 pNew->SetParent( rOldBasic->GetParent() );
    1191 [ #  # ][ #  # ]:          0 :                 if( pNew->GetParent() )
    1192 [ #  # ][ #  # ]:          0 :                     pNew->GetParent()->Insert( pNew );
    1193                 :          0 :                 pNew->SetFlag( SBX_EXTSEARCH );
    1194                 :            :             }
    1195         [ #  # ]:          0 :             rOldBasic = pNew;
    1196                 :            : 
    1197                 :            :             // Fill new libray container (5.2 -> 6.0)
    1198         [ #  # ]:          0 :             copyToLibraryContainer( pNew, mpImpl->maContainerInfo );
    1199                 :            : 
    1200         [ #  # ]:          0 :             pNew->SetModified( sal_False );
    1201                 :          0 :             bLoaded = sal_True;
    1202                 :            :         }
    1203                 :            :     }
    1204         [ #  # ]:          0 :     if ( bProtected )
    1205         [ #  # ]:          0 :         rStrm.SetCryptMaskKey(rtl::OString());
    1206         [ #  # ]:          0 :     return bLoaded;
    1207                 :            : }
    1208                 :            : 
    1209                 :          0 : void BasicManager::CheckModules( StarBASIC* pLib, sal_Bool bReference ) const
    1210                 :            : {
    1211         [ #  # ]:          0 :     if ( !pLib )
    1212                 :          0 :         return;
    1213                 :            : 
    1214                 :          0 :     sal_Bool bModified = pLib->IsModified();
    1215                 :            : 
    1216         [ #  # ]:          0 :     for ( sal_uInt16 nMod = 0; nMod < pLib->GetModules()->Count(); nMod++ )
    1217                 :            :     {
    1218                 :          0 :         SbModule* pModule = (SbModule*)pLib->GetModules()->Get( nMod );
    1219                 :            :         DBG_ASSERT( pModule, "Modul nicht erhalten!" );
    1220 [ #  # ][ #  # ]:          0 :         if ( !pModule->IsCompiled() && !StarBASIC::GetErrorCode() )
                 [ #  # ]
    1221                 :          0 :             pLib->Compile( pModule );
    1222                 :            :     }
    1223                 :            : 
    1224                 :            :     // #67477, AB 8.12.99 On demand compile in referenced libs should not
    1225                 :            :     // cause modified
    1226 [ #  # ][ #  # ]:          0 :     if( !bModified && bReference )
    1227                 :            :     {
    1228                 :            :         OSL_FAIL( "Per Reference eingebundene Basic-Library ist nicht compiliert!" );
    1229                 :          0 :         pLib->SetModified( sal_False );
    1230                 :            :     }
    1231                 :            : }
    1232                 :            : 
    1233                 :          0 : StarBASIC* BasicManager::AddLib( SotStorage& rStorage, const String& rLibName, sal_Bool bReference )
    1234                 :            : {
    1235                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1236                 :            : 
    1237 [ #  # ][ #  # ]:          0 :     String aStorName( rStorage.GetName() );
    1238                 :            :     DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
    1239                 :            : 
    1240 [ #  # ][ #  # ]:          0 :     String aStorageName = INetURLObject(aStorName, INET_PROT_FILE).GetMainURL( INetURLObject::NO_DECODE );
         [ #  # ][ #  # ]
                 [ #  # ]
    1241                 :            :     DBG_ASSERT(aStorageName.Len() != 0, "Bad storage name");
    1242                 :            : 
    1243         [ #  # ]:          0 :     String aNewLibName( rLibName );
    1244 [ #  # ][ #  # ]:          0 :     while ( HasLib( aNewLibName ) )
    1245         [ #  # ]:          0 :         aNewLibName += '_';
    1246                 :            : 
    1247         [ #  # ]:          0 :     BasicLibInfo* pLibInfo = CreateLibInfo();
    1248                 :            :     // Use original name otherwise ImpLoadLibary failes...
    1249         [ #  # ]:          0 :     pLibInfo->SetLibName( rLibName );
    1250                 :            :     // but doesn't work this way if name exists twice
    1251         [ #  # ]:          0 :     sal_uInt16 nLibId = (sal_uInt16) pLibs->GetPos( pLibInfo );
    1252                 :            : 
    1253                 :            :     // Set StorageName before load because it is compared with pCurStorage
    1254         [ #  # ]:          0 :     pLibInfo->SetStorageName( aStorageName );
    1255         [ #  # ]:          0 :     sal_Bool bLoaded = ImpLoadLibary( pLibInfo, &rStorage );
    1256                 :            : 
    1257         [ #  # ]:          0 :     if ( bLoaded )
    1258                 :            :     {
    1259 [ #  # ][ #  # ]:          0 :         if ( aNewLibName != rLibName )
    1260         [ #  # ]:          0 :             SetLibName( nLibId, aNewLibName );
    1261                 :            : 
    1262         [ #  # ]:          0 :         if ( bReference )
    1263                 :            :         {
    1264 [ #  # ][ #  # ]:          0 :             pLibInfo->GetLib()->SetModified( sal_False );   // Don't save in this case
                 [ #  # ]
    1265 [ #  # ][ #  # ]:          0 :             pLibInfo->SetRelStorageName( String() );
                 [ #  # ]
    1266                 :          0 :             pLibInfo->IsReference() = sal_True;
    1267                 :            :         }
    1268                 :            :         else
    1269                 :            :         {
    1270 [ #  # ][ #  # ]:          0 :             pLibInfo->GetLib()->SetModified( sal_True ); // Must be saved after Add!
                 [ #  # ]
    1271 [ #  # ][ #  # ]:          0 :             pLibInfo->SetStorageName( rtl::OUString(szImbedded) ); // Save in BasicManager-Storage
                 [ #  # ]
    1272                 :            :         }
    1273                 :            :     }
    1274                 :            :     else
    1275                 :            :     {
    1276         [ #  # ]:          0 :         RemoveLib( nLibId, sal_False );
    1277                 :          0 :         pLibInfo = 0;
    1278                 :            :     }
    1279                 :            : 
    1280         [ #  # ]:          0 :     if( pLibInfo )
    1281 [ #  # ][ #  # ]:          0 :         return &*pLibInfo->GetLib() ;
    1282                 :            :     else
    1283 [ #  # ][ #  # ]:          0 :         return 0;
                 [ #  # ]
    1284                 :            : }
    1285                 :            : 
    1286                 :          0 : sal_Bool BasicManager::IsReference( sal_uInt16 nLib )
    1287                 :            : {
    1288                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1289                 :            : 
    1290                 :          0 :     BasicLibInfo* pLibInfo = pLibs->GetObject( nLib );
    1291                 :            :     DBG_ASSERT( pLibInfo, "Lib?!" );
    1292         [ #  # ]:          0 :     if ( pLibInfo )
    1293                 :          0 :         return pLibInfo->IsReference();
    1294                 :            : 
    1295                 :          0 :     return sal_False;
    1296                 :            : }
    1297                 :            : 
    1298                 :          0 : sal_Bool BasicManager::RemoveLib( sal_uInt16 nLib )
    1299                 :            : {
    1300                 :            :     // Only pyhsical deletion if no reference
    1301                 :          0 :     return RemoveLib( nLib, !IsReference( nLib ) );
    1302                 :            : }
    1303                 :            : 
    1304                 :          0 : sal_Bool BasicManager::RemoveLib( sal_uInt16 nLib, sal_Bool bDelBasicFromStorage )
    1305                 :            : {
    1306                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1307                 :            :     DBG_ASSERT( nLib, "Standard-Lib cannot be removed!" );
    1308                 :            : 
    1309                 :          0 :     BasicLibInfo* pLibInfo = pLibs->GetObject( nLib );
    1310                 :            :     DBG_ASSERT( pLibInfo, "Lib not found!" );
    1311                 :            : 
    1312 [ #  # ][ #  # ]:          0 :     if ( !pLibInfo || !nLib )
    1313                 :            :     {
    1314 [ #  # ][ #  # ]:          0 :         StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, String(), ERRCODE_BUTTON_OK );
    1315         [ #  # ]:          0 :         aErrors.push_back(BasicError(*pErrInf, BASERR_REASON_STDLIB, pLibInfo->GetLibName()));
    1316                 :          0 :         return sal_False;
    1317                 :            :     }
    1318                 :            : 
    1319                 :            :     // If one of the streams cannot be opened, this is not an error,
    1320                 :            :     // because BASIC was never written before...
    1321 [ #  # ][ #  #  :          0 :     if ( bDelBasicFromStorage && !pLibInfo->IsReference() &&
             #  #  #  # ]
                 [ #  # ]
    1322                 :          0 :             ( !pLibInfo->IsExtern() || SotStorage::IsStorageFile( pLibInfo->GetStorageName() ) ) )
    1323                 :            :     {
    1324                 :          0 :         SotStorageRef xStorage;
    1325 [ #  # ][ #  # ]:          0 :         if ( !pLibInfo->IsExtern() )
    1326 [ #  # ][ #  # ]:          0 :             xStorage = new SotStorage( sal_False, GetStorageName() );
         [ #  # ][ #  # ]
                 [ #  # ]
    1327                 :            :         else
    1328 [ #  # ][ #  # ]:          0 :             xStorage = new SotStorage( sal_False, pLibInfo->GetStorageName() );
                 [ #  # ]
    1329                 :            : 
    1330 [ #  # ][ #  # ]:          0 :         if ( xStorage->IsStorage( String(RTL_CONSTASCII_USTRINGPARAM(szBasicStorage)) ) )
         [ #  # ][ #  # ]
    1331                 :            :         {
    1332                 :            :             SotStorageRef xBasicStorage = xStorage->OpenSotStorage
    1333 [ #  # ][ #  # ]:          0 :                             ( String(RTL_CONSTASCII_USTRINGPARAM(szBasicStorage)), STREAM_STD_READWRITE, sal_False );
                 [ #  # ]
    1334                 :            : 
    1335 [ #  # ][ #  # ]:          0 :             if ( !xBasicStorage.Is() || xBasicStorage->GetError() )
                 [ #  # ]
    1336                 :            :             {
    1337 [ #  # ][ #  # ]:          0 :                 StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, String(), ERRCODE_BUTTON_OK );
         [ #  # ][ #  # ]
    1338 [ #  # ][ #  # ]:          0 :                 aErrors.push_back(BasicError(*pErrInf, BASERR_REASON_OPENLIBSTORAGE, pLibInfo->GetLibName()));
         [ #  # ][ #  # ]
    1339                 :            :             }
    1340 [ #  # ][ #  # ]:          0 :             else if ( xBasicStorage->IsStream( pLibInfo->GetLibName() ) )
    1341                 :            :             {
    1342         [ #  # ]:          0 :                 xBasicStorage->Remove( pLibInfo->GetLibName() );
    1343         [ #  # ]:          0 :                 xBasicStorage->Commit();
    1344                 :            : 
    1345                 :            :                 // If no further stream available,
    1346                 :            :                 // delete the SubStorage.
    1347         [ #  # ]:          0 :                 SvStorageInfoList aInfoList;
    1348         [ #  # ]:          0 :                 xBasicStorage->FillInfoList( &aInfoList );
    1349         [ #  # ]:          0 :                 if ( aInfoList.empty() )
    1350                 :            :                 {
    1351         [ #  # ]:          0 :                     xBasicStorage.Clear();
    1352 [ #  # ][ #  # ]:          0 :                     xStorage->Remove( String(RTL_CONSTASCII_USTRINGPARAM(szBasicStorage)) );
                 [ #  # ]
    1353         [ #  # ]:          0 :                     xStorage->Commit();
    1354                 :            :                     // If no further Streams or SubStorages available,
    1355                 :            :                     // delete the Storage, too.
    1356                 :          0 :                     aInfoList.clear();
    1357         [ #  # ]:          0 :                     xStorage->FillInfoList( &aInfoList );
    1358         [ #  # ]:          0 :                     if ( aInfoList.empty() )
    1359                 :            :                     {
    1360 [ #  # ][ #  # ]:          0 :                         String aName_( xStorage->GetName() );
    1361 [ #  # ][ #  # ]:          0 :                         xStorage.Clear();
    1362                 :            :                         //*** TODO: Replace if still necessary
    1363                 :            :                         //SfxContentHelper::Kill( aName );
    1364                 :            :                         //*** TODO-End
    1365                 :            :                     }
    1366                 :          0 :                 }
    1367         [ #  # ]:          0 :             }
    1368         [ #  # ]:          0 :         }
    1369                 :            :     }
    1370         [ #  # ]:          0 :     if ( pLibInfo->GetLib().Is() )
    1371         [ #  # ]:          0 :         GetStdLib()->Remove( pLibInfo->GetLib() );
    1372         [ #  # ]:          0 :     delete pLibs->Remove( pLibInfo );
    1373                 :          0 :     return sal_True;    // Remove was successful, del unimportant
    1374                 :            : }
    1375                 :            : 
    1376                 :        106 : sal_uInt16 BasicManager::GetLibCount() const
    1377                 :            : {
    1378                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1379                 :        106 :     return (sal_uInt16)pLibs->Count();
    1380                 :            : }
    1381                 :            : 
    1382                 :      11061 : StarBASIC* BasicManager::GetLib( sal_uInt16 nLib ) const
    1383                 :            : {
    1384                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1385                 :      11061 :     BasicLibInfo* pInf = pLibs->GetObject( nLib );
    1386                 :            :     DBG_ASSERT( pInf, "Lib existiert nicht!" );
    1387         [ +  - ]:      11061 :     if ( pInf )
    1388                 :      11061 :         return pInf->GetLib();
    1389                 :      11061 :     return 0;
    1390                 :            : }
    1391                 :            : 
    1392                 :      10084 : StarBASIC* BasicManager::GetStdLib() const
    1393                 :            : {
    1394                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1395                 :      10084 :     StarBASIC* pLib = GetLib( 0 );
    1396                 :      10084 :     return pLib;
    1397                 :            : }
    1398                 :            : 
    1399                 :       2166 : StarBASIC* BasicManager::GetLib( const String& rName ) const
    1400                 :            : {
    1401                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1402                 :            : 
    1403                 :       2166 :     BasicLibInfo* pInf = pLibs->First();
    1404         [ +  + ]:       8238 :     while ( pInf )
    1405                 :            :     {
    1406         [ +  + ]:       7089 :         if ( pInf->GetLibName().CompareIgnoreCaseToAscii( rName ) == COMPARE_EQUAL )// Check if available...
    1407                 :       1017 :             return pInf->GetLib();
    1408                 :            : 
    1409                 :       6072 :         pInf = pLibs->Next();
    1410                 :            :     }
    1411                 :       2166 :     return 0;
    1412                 :            : }
    1413                 :            : 
    1414                 :          3 : sal_uInt16 BasicManager::GetLibId( const String& rName ) const
    1415                 :            : {
    1416                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1417                 :            : 
    1418                 :          3 :     BasicLibInfo* pInf = pLibs->First();
    1419         [ +  + ]:          6 :     while ( pInf )
    1420                 :            :     {
    1421         [ -  + ]:          3 :         if ( pInf->GetLibName().CompareIgnoreCaseToAscii( rName ) == COMPARE_EQUAL )
    1422                 :          0 :             return (sal_uInt16)pLibs->GetCurPos();
    1423                 :            : 
    1424                 :          3 :         pInf = pLibs->Next();
    1425                 :            :     }
    1426                 :          3 :     return LIB_NOTFOUND;
    1427                 :            : }
    1428                 :            : 
    1429                 :          0 : sal_Bool BasicManager::HasLib( const String& rName ) const
    1430                 :            : {
    1431                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1432                 :            : 
    1433                 :          0 :     BasicLibInfo* pInf = pLibs->First();
    1434         [ #  # ]:          0 :     while ( pInf )
    1435                 :            :     {
    1436         [ #  # ]:          0 :         if ( pInf->GetLibName().CompareIgnoreCaseToAscii( rName ) == COMPARE_EQUAL )
    1437                 :          0 :             return sal_True;
    1438                 :            : 
    1439                 :          0 :         pInf = pLibs->Next();
    1440                 :            :     }
    1441                 :          0 :     return sal_False;
    1442                 :            : }
    1443                 :            : 
    1444                 :          0 : sal_Bool BasicManager::SetLibName( sal_uInt16 nLib, const String& rName )
    1445                 :            : {
    1446                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1447                 :            : 
    1448                 :          0 :     BasicLibInfo* pLibInfo = pLibs->GetObject( nLib );
    1449                 :            :     DBG_ASSERT( pLibInfo, "Lib?!" );
    1450         [ #  # ]:          0 :     if ( pLibInfo )
    1451                 :            :     {
    1452                 :          0 :         pLibInfo->SetLibName( rName );
    1453         [ #  # ]:          0 :         if ( pLibInfo->GetLib().Is() )
    1454                 :            :         {
    1455         [ #  # ]:          0 :             StarBASICRef xStdLib = pLibInfo->GetLib();
    1456         [ #  # ]:          0 :             xStdLib->SetName( rName );
    1457 [ #  # ][ #  # ]:          0 :             xStdLib->SetModified( sal_True );
    1458                 :            :         }
    1459                 :          0 :         return sal_True;
    1460                 :            :     }
    1461                 :          0 :     return sal_False;
    1462                 :            : }
    1463                 :            : 
    1464                 :          0 : String BasicManager::GetLibName( sal_uInt16 nLib )
    1465                 :            : {
    1466                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1467                 :            : 
    1468                 :          0 :     BasicLibInfo* pLibInfo = pLibs->GetObject( nLib );
    1469                 :            :     DBG_ASSERT( pLibInfo, "Lib?!" );
    1470         [ #  # ]:          0 :     if ( pLibInfo )
    1471                 :          0 :         return pLibInfo->GetLibName();
    1472                 :          0 :     return String();
    1473                 :            : }
    1474                 :            : 
    1475                 :          0 : sal_Bool BasicManager::LoadLib( sal_uInt16 nLib )
    1476                 :            : {
    1477                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1478                 :            : 
    1479                 :          0 :     sal_Bool bDone = sal_False;
    1480                 :          0 :     BasicLibInfo* pLibInfo = pLibs->GetObject( nLib );
    1481                 :            :     DBG_ASSERT( pLibInfo, "Lib?!" );
    1482         [ #  # ]:          0 :     if ( pLibInfo )
    1483                 :            :     {
    1484         [ #  # ]:          0 :         Reference< XLibraryContainer > xLibContainer = pLibInfo->GetLibraryContainer();
    1485         [ #  # ]:          0 :         if( xLibContainer.is() )
    1486                 :            :         {
    1487         [ #  # ]:          0 :             String aLibName = pLibInfo->GetLibName();
    1488 [ #  # ][ #  # ]:          0 :             xLibContainer->loadLibrary( aLibName );
                 [ #  # ]
    1489 [ #  # ][ #  # ]:          0 :             bDone = xLibContainer->isLibraryLoaded( aLibName );;
         [ #  # ][ #  # ]
    1490                 :            :         }
    1491                 :            :         else
    1492                 :            :         {
    1493         [ #  # ]:          0 :             bDone = ImpLoadLibary( pLibInfo, NULL, sal_False );
    1494         [ #  # ]:          0 :             StarBASIC* pLib = GetLib( nLib );
    1495         [ #  # ]:          0 :             if ( pLib )
    1496                 :            :             {
    1497 [ #  # ][ #  # ]:          0 :                 GetStdLib()->Insert( pLib );
    1498                 :          0 :                 pLib->SetFlag( SBX_EXTSEARCH );
    1499                 :            :             }
    1500                 :          0 :         }
    1501                 :            :     }
    1502                 :            :     else
    1503                 :            :     {
    1504 [ #  # ][ #  # ]:          0 :         StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, rtl::OUString(), ERRCODE_BUTTON_OK );
         [ #  # ][ #  # ]
    1505 [ #  # ][ #  # ]:          0 :         aErrors.push_back(BasicError(*pErrInf, BASERR_REASON_LIBNOTFOUND, rtl::OUString::valueOf(static_cast<sal_Int32>(nLib))));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1506                 :            :     }
    1507                 :          0 :     return bDone;
    1508                 :            : }
    1509                 :            : 
    1510                 :          0 : StarBASIC* BasicManager::CreateLib( const String& rLibName )
    1511                 :            : {
    1512                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1513         [ #  # ]:          0 :     if ( GetLib( rLibName ) )
    1514                 :          0 :         return 0;
    1515                 :            : 
    1516                 :          0 :     BasicLibInfo* pLibInfo = CreateLibInfo();
    1517         [ #  # ]:          0 :     StarBASIC* pNew = new StarBASIC( GetStdLib(), mbDocMgr );
    1518                 :          0 :     GetStdLib()->Insert( pNew );
    1519                 :          0 :     pNew->SetFlag( SBX_EXTSEARCH | SBX_DONTSTORE );
    1520                 :          0 :     pLibInfo->SetLib( pNew );
    1521                 :          0 :     pLibInfo->SetLibName( rLibName );
    1522         [ #  # ]:          0 :     pLibInfo->GetLib()->SetName( rLibName );
    1523                 :          0 :     return pLibInfo->GetLib();
    1524                 :            : }
    1525                 :            : 
    1526                 :            : // For XML import/export:
    1527                 :          0 : StarBASIC* BasicManager::CreateLib
    1528                 :            :     ( const String& rLibName, const String& Password, const String& LinkTargetURL )
    1529                 :            : {
    1530                 :            :     // Ask if lib exists because standard lib is always there
    1531                 :          0 :     StarBASIC* pLib = GetLib( rLibName );
    1532         [ #  # ]:          0 :     if( !pLib )
    1533                 :            :     {
    1534         [ #  # ]:          0 :         if( LinkTargetURL.Len() != 0 )
    1535                 :            :         {
    1536 [ #  # ][ #  # ]:          0 :             SotStorageRef xStorage = new SotStorage( sal_False, LinkTargetURL, STREAM_READ | STREAM_SHARE_DENYWRITE );
    1537         [ #  # ]:          0 :             if( !xStorage->GetError() )
    1538                 :            :             {
    1539         [ #  # ]:          0 :                 pLib = AddLib( *xStorage, rLibName, sal_True );
    1540                 :            :             }
    1541                 :            : 
    1542         [ #  # ]:          0 :             DBG_ASSERT( pLib, "XML Import: Linked basic library could not be loaded");
    1543                 :            :         }
    1544                 :            :         else
    1545                 :            :         {
    1546                 :          0 :             pLib = CreateLib( rLibName );
    1547         [ #  # ]:          0 :             if( Password.Len() != 0 )
    1548                 :            :             {
    1549                 :          0 :                 BasicLibInfo* pLibInfo = FindLibInfo( pLib );
    1550                 :          0 :                 pLibInfo ->SetPassword( Password );
    1551                 :            :             }
    1552                 :            :         }
    1553                 :            :         //ExternalSourceURL ?
    1554                 :            :     }
    1555                 :          0 :     return pLib;
    1556                 :            : }
    1557                 :            : 
    1558                 :        573 : StarBASIC* BasicManager::CreateLibForLibContainer( const String& rLibName,
    1559                 :            :     const Reference< XLibraryContainer >& xScriptCont )
    1560                 :            : {
    1561                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1562         [ -  + ]:        573 :     if ( GetLib( rLibName ) )
    1563                 :          0 :         return 0;
    1564                 :            : 
    1565                 :        573 :     BasicLibInfo* pLibInfo = CreateLibInfo();
    1566         [ +  - ]:        573 :     StarBASIC* pNew = new StarBASIC( GetStdLib(), mbDocMgr );
    1567                 :        573 :     GetStdLib()->Insert( pNew );
    1568                 :        573 :     pNew->SetFlag( SBX_EXTSEARCH | SBX_DONTSTORE );
    1569                 :        573 :     pLibInfo->SetLib( pNew );
    1570                 :        573 :     pLibInfo->SetLibName( rLibName );
    1571         [ +  - ]:        573 :     pLibInfo->GetLib()->SetName( rLibName );
    1572                 :        573 :     pLibInfo->SetLibraryContainer( xScriptCont );
    1573                 :        573 :     return pNew;
    1574                 :            : }
    1575                 :            : 
    1576                 :            : 
    1577                 :          0 : BasicLibInfo* BasicManager::FindLibInfo( StarBASIC* pBasic ) const
    1578                 :            : {
    1579                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1580                 :            : 
    1581                 :          0 :     BasicLibInfo* pInf = ((BasicManager*)this)->pLibs->First();
    1582         [ #  # ]:          0 :     while ( pInf )
    1583                 :            :     {
    1584         [ #  # ]:          0 :         if ( pInf->GetLib() == pBasic )
    1585                 :          0 :             return pInf;
    1586                 :            : 
    1587                 :          0 :         pInf = ((BasicManager*)this)->pLibs->Next();
    1588                 :            :     }
    1589                 :          0 :     return 0;
    1590                 :            : }
    1591                 :            : 
    1592                 :            : 
    1593                 :          0 : sal_Bool BasicManager::IsBasicModified() const
    1594                 :            : {
    1595                 :            :     DBG_CHKTHIS( BasicManager, 0 );
    1596                 :            : 
    1597                 :          0 :     BasicLibInfo* pInf = pLibs->First();
    1598         [ #  # ]:          0 :     while ( pInf )
    1599                 :            :     {
    1600 [ #  # ][ #  # ]:          0 :         if ( pInf->GetLib().Is() && pInf->GetLib()->IsModified() )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
    1601                 :          0 :             return sal_True;
    1602                 :            : 
    1603                 :          0 :         pInf = pLibs->Next();
    1604                 :            :     }
    1605                 :          0 :     return sal_False;
    1606                 :            : }
    1607                 :            : 
    1608                 :         65 : std::vector<BasicError>& BasicManager::GetErrors()
    1609                 :            : {
    1610                 :         65 :     return aErrors;
    1611                 :            : }
    1612                 :            : 
    1613                 :       4670 : bool BasicManager::GetGlobalUNOConstant( const sal_Char* _pAsciiName, ::com::sun::star::uno::Any& aOut )
    1614                 :            : {
    1615                 :       4670 :     bool bRes = false;
    1616                 :       4670 :     StarBASIC* pStandardLib = GetStdLib();
    1617                 :            :     OSL_PRECOND( pStandardLib, "BasicManager::GetGlobalUNOConstant: no lib to read from!" );
    1618         [ +  - ]:       4670 :     if ( pStandardLib )
    1619                 :       4670 :         bRes = pStandardLib->GetUNOConstant( _pAsciiName, aOut );
    1620                 :       4670 :     return bRes;
    1621                 :            : }
    1622                 :            : 
    1623                 :       4081 : Any BasicManager::SetGlobalUNOConstant( const sal_Char* _pAsciiName, const Any& _rValue )
    1624                 :            : {
    1625                 :       4081 :     Any aOldValue;
    1626                 :            : 
    1627         [ +  - ]:       4081 :     StarBASIC* pStandardLib = GetStdLib();
    1628                 :            :     OSL_PRECOND( pStandardLib, "BasicManager::SetGlobalUNOConstant: no lib to insert into!" );
    1629         [ +  - ]:       4081 :     if ( !pStandardLib )
    1630                 :            :         return aOldValue;
    1631                 :            : 
    1632                 :       4081 :     ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) );
    1633                 :            : 
    1634                 :            :     // obtain the old value
    1635         [ +  - ]:       4081 :     SbxVariable* pVariable = pStandardLib->Find( sVarName, SbxCLASS_OBJECT );
    1636         [ +  + ]:       4081 :     if ( pVariable )
    1637         [ +  - ]:       3552 :         aOldValue = sbxToUnoValue( pVariable );
    1638                 :            : 
    1639         [ +  - ]:       4081 :     SbxObjectRef xUnoObj = GetSbUnoObject( sVarName, _rValue );
    1640                 :       4081 :     xUnoObj->SetFlag( SBX_DONTSTORE );
    1641         [ +  - ]:       4081 :     pStandardLib->Insert( xUnoObj );
    1642                 :            : 
    1643         [ +  - ]:       4081 :     return aOldValue;
    1644                 :            : }
    1645                 :            : 
    1646                 :         20 : bool BasicManager::LegacyPsswdBinaryLimitExceeded( ::com::sun::star::uno::Sequence< rtl::OUString >& _out_rModuleNames )
    1647                 :            : {
    1648                 :            :     try
    1649                 :            :     {
    1650 [ +  - ][ +  - ]:         20 :         Reference< XNameAccess > xScripts( GetScriptLibraryContainer(), UNO_QUERY_THROW );
    1651 [ +  - ][ +  - ]:         20 :         Reference< XLibraryContainerPassword > xPassword( GetScriptLibraryContainer(), UNO_QUERY_THROW );
    1652                 :            : 
    1653 [ +  - ][ +  - ]:         20 :         Sequence< ::rtl::OUString > aNames( xScripts->getElementNames() );
    1654                 :         20 :         const ::rtl::OUString* pNames = aNames.getConstArray();
    1655                 :         20 :         const ::rtl::OUString* pNamesEnd = aNames.getConstArray() + aNames.getLength();
    1656         [ +  + ]:         40 :         for ( ; pNames != pNamesEnd; ++pNames )
    1657                 :            :         {
    1658 [ +  - ][ +  - ]:         20 :             if( !xPassword->isLibraryPasswordProtected( *pNames ) )
                 [ +  - ]
    1659                 :         20 :                 continue;
    1660                 :            : 
    1661 [ #  # ][ #  # ]:          0 :             StarBASIC* pBasicLib = GetLib( *pNames );
                 [ #  # ]
    1662         [ #  # ]:          0 :             if ( !pBasicLib )
    1663                 :          0 :                 continue;
    1664                 :            : 
    1665 [ #  # ][ #  # ]:          0 :             Reference< XNameAccess > xScriptLibrary( xScripts->getByName( *pNames ), UNO_QUERY_THROW );
                 [ #  # ]
    1666 [ #  # ][ #  # ]:          0 :             Sequence< ::rtl::OUString > aElementNames( xScriptLibrary->getElementNames() );
    1667                 :          0 :             sal_Int32 nLen = aElementNames.getLength();
    1668                 :            : 
    1669         [ #  # ]:          0 :             Sequence< ::rtl::OUString > aBigModules( nLen );
    1670                 :          0 :             sal_Int32 nBigModules = 0;
    1671                 :            : 
    1672                 :          0 :             const ::rtl::OUString* pElementNames = aElementNames.getConstArray();
    1673                 :          0 :             const ::rtl::OUString* pElementNamesEnd = aElementNames.getConstArray() + aElementNames.getLength();
    1674         [ #  # ]:          0 :             for ( ; pElementNames != pElementNamesEnd; ++pElementNames )
    1675                 :            :             {
    1676 [ #  # ][ #  # ]:          0 :                 SbModule* pMod = pBasicLib->FindModule( *pElementNames );
                 [ #  # ]
    1677 [ #  # ][ #  # ]:          0 :                 if ( pMod && pMod->ExceedsLegacyModuleSize() )
         [ #  # ][ #  # ]
    1678         [ #  # ]:          0 :                     aBigModules[ nBigModules++ ] = *pElementNames;
    1679                 :            :             }
    1680                 :            : 
    1681         [ #  # ]:          0 :             if ( nBigModules )
    1682                 :            :             {
    1683         [ #  # ]:          0 :                 aBigModules.realloc( nBigModules );
    1684         [ #  # ]:          0 :                 _out_rModuleNames = aBigModules;
    1685                 :          0 :                 return true;
    1686                 :            :             }
    1687 [ #  # ][ #  # ]:         40 :         }
         [ #  # ][ #  # ]
         [ #  # ][ +  - ]
         [ -  + ][ -  + ]
         [ +  - ][ #  # ]
    1688                 :            :     }
    1689                 :          0 :     catch( const Exception& )
    1690                 :            :     {
    1691                 :            :         DBG_UNHANDLED_EXCEPTION();
    1692                 :            :     }
    1693                 :         20 :     return false;
    1694                 :            : }
    1695                 :            : 
    1696                 :            : 
    1697                 :            : namespace
    1698                 :            : {
    1699                 :          0 :     SbMethod* lcl_queryMacro( BasicManager* i_manager, String const& i_fullyQualifiedName )
    1700                 :            :     {
    1701                 :          0 :         sal_uInt16 nLast = 0;
    1702         [ #  # ]:          0 :         String sMacro = i_fullyQualifiedName;
    1703         [ #  # ]:          0 :         String sLibName = sMacro.GetToken( 0, '.', nLast );
    1704         [ #  # ]:          0 :         String sModule = sMacro.GetToken( 0, '.', nLast );
    1705         [ #  # ]:          0 :         sMacro.Erase( 0, nLast );
    1706                 :            : 
    1707         [ #  # ]:          0 :         utl::TransliterationWrapper& rTransliteration = SbGlobal::GetTransliteration();
    1708         [ #  # ]:          0 :         sal_uInt16 nLibCount = i_manager->GetLibCount();
    1709         [ #  # ]:          0 :         for ( sal_uInt16 nLib = 0; nLib < nLibCount; ++nLib )
    1710                 :            :         {
    1711 [ #  # ][ #  # ]:          0 :             if ( rTransliteration.isEqual( i_manager->GetLibName( nLib ), sLibName ) )
         [ #  # ][ #  # ]
    1712                 :            :             {
    1713         [ #  # ]:          0 :                 StarBASIC* pLib = i_manager->GetLib( nLib );
    1714         [ #  # ]:          0 :                 if( !pLib )
    1715                 :            :                 {
    1716         [ #  # ]:          0 :                     i_manager->LoadLib( nLib );
    1717         [ #  # ]:          0 :                     pLib = i_manager->GetLib( nLib );
    1718                 :            :                 }
    1719                 :            : 
    1720         [ #  # ]:          0 :                 if( pLib )
    1721                 :            :                 {
    1722         [ #  # ]:          0 :                     sal_uInt16 nModCount = pLib->GetModules()->Count();
    1723         [ #  # ]:          0 :                     for( sal_uInt16 nMod = 0; nMod < nModCount; ++nMod )
    1724                 :            :                     {
    1725         [ #  # ]:          0 :                         SbModule* pMod = (SbModule*)pLib->GetModules()->Get( nMod );
    1726 [ #  # ][ #  # ]:          0 :                         if ( pMod && rTransliteration.isEqual( pMod->GetName(), sModule ) )
         [ #  # ][ #  # ]
                 [ #  # ]
    1727                 :            :                         {
    1728 [ #  # ][ #  # ]:          0 :                             SbMethod* pMethod = (SbMethod*)pMod->Find( sMacro, SbxCLASS_METHOD );
    1729         [ #  # ]:          0 :                             if( pMethod )
    1730                 :          0 :                                 return pMethod;
    1731                 :            :                         }
    1732                 :            :                     }
    1733                 :            :                 }
    1734                 :            :             }
    1735                 :            :         }
    1736 [ #  # ][ #  # ]:          0 :         return 0;
                 [ #  # ]
    1737                 :            :     }
    1738                 :            : }
    1739                 :            : 
    1740                 :          0 : bool BasicManager::HasMacro( String const& i_fullyQualifiedName ) const
    1741                 :            : {
    1742                 :          0 :     return ( NULL != lcl_queryMacro( const_cast< BasicManager* >( this ), i_fullyQualifiedName ) );
    1743                 :            : }
    1744                 :            : 
    1745                 :          0 : ErrCode BasicManager::ExecuteMacro( String const& i_fullyQualifiedName, SbxArray* i_arguments, SbxValue* i_retValue )
    1746                 :            : {
    1747                 :          0 :     SbMethod* pMethod = lcl_queryMacro( this, i_fullyQualifiedName );
    1748                 :          0 :     ErrCode nError = 0;
    1749         [ #  # ]:          0 :     if ( pMethod )
    1750                 :            :     {
    1751         [ #  # ]:          0 :         if ( i_arguments )
    1752                 :          0 :             pMethod->SetParameters( i_arguments );
    1753                 :          0 :         nError = pMethod->Call( i_retValue );
    1754                 :            :     }
    1755                 :            :     else
    1756                 :          0 :         nError = ERRCODE_BASIC_PROC_UNDEFINED;
    1757                 :          0 :     return nError;
    1758                 :            : }
    1759                 :            : 
    1760                 :          0 : ErrCode BasicManager::ExecuteMacro( String const& i_fullyQualifiedName, String const& i_commaSeparatedArgs, SbxValue* i_retValue )
    1761                 :            : {
    1762         [ #  # ]:          0 :     SbMethod* pMethod = lcl_queryMacro( this, i_fullyQualifiedName );
    1763         [ #  # ]:          0 :     if ( !pMethod )
    1764                 :          0 :         return ERRCODE_BASIC_PROC_UNDEFINED;
    1765                 :            : 
    1766                 :            :     // arguments must be quoted
    1767         [ #  # ]:          0 :     String sQuotedArgs;
    1768         [ #  # ]:          0 :     String sArgs( i_commaSeparatedArgs );
    1769 [ #  # ][ #  # ]:          0 :     if ( sArgs.Len()<2 || sArgs.GetBuffer()[1] == '\"')
                 [ #  # ]
    1770                 :            :         // no args or already quoted args
    1771         [ #  # ]:          0 :         sQuotedArgs = sArgs;
    1772                 :            :     else
    1773                 :            :     {
    1774                 :            :         // quote parameters
    1775         [ #  # ]:          0 :         sArgs.Erase( 0, 1 );
    1776         [ #  # ]:          0 :         sArgs.Erase( sArgs.Len()-1, 1 );
    1777                 :            : 
    1778         [ #  # ]:          0 :         sQuotedArgs = '(';
    1779                 :            : 
    1780 [ #  # ][ #  # ]:          0 :         sal_Int32 nCount = comphelper::string::getTokenCount(sArgs, ',');
    1781         [ #  # ]:          0 :         for (sal_Int32 n=0; n < nCount; ++n)
    1782                 :            :         {
    1783         [ #  # ]:          0 :             sQuotedArgs += '\"';
    1784 [ #  # ][ #  # ]:          0 :             sQuotedArgs += comphelper::string::getToken(sArgs, n, ',');
    1785         [ #  # ]:          0 :             sQuotedArgs += '\"';
    1786         [ #  # ]:          0 :             if ( n<nCount-1 )
    1787         [ #  # ]:          0 :                 sQuotedArgs += ',';
    1788                 :            :         }
    1789                 :            : 
    1790         [ #  # ]:          0 :         sQuotedArgs += ')';
    1791                 :            :     }
    1792                 :            : 
    1793                 :            :     // add quoted arguments and do the call
    1794                 :            :     rtl::OUString sCall = rtl::OUStringBuffer().
    1795         [ #  # ]:          0 :         append('[').
    1796 [ #  # ][ #  # ]:          0 :         append(pMethod->GetName()).
                 [ #  # ]
    1797 [ #  # ][ #  # ]:          0 :         append(sQuotedArgs).
    1798         [ #  # ]:          0 :         append(']').
    1799         [ #  # ]:          0 :         makeStringAndClear();
    1800                 :            : 
    1801 [ #  # ][ #  # ]:          0 :     SbxVariable* pRet = pMethod->GetParent()->Execute( sCall );
         [ #  # ][ #  # ]
    1802 [ #  # ][ #  # ]:          0 :     if ( pRet && ( pRet != pMethod ) )
    1803         [ #  # ]:          0 :         *i_retValue = *pRet;
    1804 [ #  # ][ #  # ]:          0 :     return SbxBase::GetError();
                 [ #  # ]
    1805                 :            : }
    1806                 :            : 
    1807                 :            : //=====================================================================
    1808                 :            : 
    1809         [ #  # ]:          0 : class ModuleInfo_Impl : public ModuleInfoHelper
    1810                 :            : {
    1811                 :            :     ::rtl::OUString maName;
    1812                 :            :     ::rtl::OUString maLanguage;
    1813                 :            :     ::rtl::OUString maSource;
    1814                 :            : 
    1815                 :            : public:
    1816                 :          0 :     ModuleInfo_Impl( const ::rtl::OUString& aName, const ::rtl::OUString& aLanguage, const ::rtl::OUString& aSource )
    1817                 :          0 :         : maName( aName ), maLanguage( aLanguage), maSource( aSource ) {}
    1818                 :            : 
    1819                 :            :     // Methods XStarBasicModuleInfo
    1820                 :          0 :     virtual ::rtl::OUString SAL_CALL getName() throw(RuntimeException)
    1821                 :          0 :         { return maName; }
    1822                 :          0 :     virtual ::rtl::OUString SAL_CALL getLanguage() throw(RuntimeException)
    1823                 :          0 :         { return maLanguage; }
    1824                 :          0 :     virtual ::rtl::OUString SAL_CALL getSource() throw(RuntimeException)
    1825                 :          0 :         { return maSource; }
    1826                 :            : };
    1827                 :            : 
    1828                 :            : 
    1829                 :            : //=====================================================================
    1830                 :            : 
    1831 [ #  # ][ #  # ]:          0 : class DialogInfo_Impl : public DialogInfoHelper
    1832                 :            : {
    1833                 :            :     ::rtl::OUString maName;
    1834                 :            :     Sequence< sal_Int8 > mData;
    1835                 :            : 
    1836                 :            : public:
    1837                 :          0 :     DialogInfo_Impl( const ::rtl::OUString& aName, Sequence< sal_Int8 > Data )
    1838         [ #  # ]:          0 :         : maName( aName ), mData( Data ) {}
    1839                 :            : 
    1840                 :            :     // Methods XStarBasicDialogInfo
    1841                 :          0 :     virtual ::rtl::OUString SAL_CALL getName() throw(RuntimeException)
    1842                 :          0 :         { return maName; }
    1843                 :          0 :     virtual Sequence< sal_Int8 > SAL_CALL getData() throw(RuntimeException)
    1844                 :          0 :         { return mData; }
    1845                 :            : };
    1846                 :            : 
    1847                 :            : 
    1848                 :            : //=====================================================================
    1849                 :            : 
    1850         [ #  # ]:          0 : class LibraryInfo_Impl : public LibraryInfoHelper
    1851                 :            : {
    1852                 :            :     ::rtl::OUString maName;
    1853                 :            :     Reference< XNameContainer > mxModuleContainer;
    1854                 :            :     Reference< XNameContainer > mxDialogContainer;
    1855                 :            :     ::rtl::OUString maPassword;
    1856                 :            :     ::rtl::OUString maExternaleSourceURL;
    1857                 :            :     ::rtl::OUString maLinkTargetURL;
    1858                 :            : 
    1859                 :            : public:
    1860                 :          0 :     LibraryInfo_Impl
    1861                 :            :     (
    1862                 :            :         const ::rtl::OUString& aName,
    1863                 :            :         Reference< XNameContainer > xModuleContainer,
    1864                 :            :         Reference< XNameContainer > xDialogContainer,
    1865                 :            :         const ::rtl::OUString& aPassword,
    1866                 :            :         const ::rtl::OUString& aExternaleSourceURL,
    1867                 :            :         const ::rtl::OUString& aLinkTargetURL
    1868                 :            :     )
    1869                 :            :         : maName( aName )
    1870                 :            :         , mxModuleContainer( xModuleContainer )
    1871                 :            :         , mxDialogContainer( xDialogContainer )
    1872                 :            :         , maPassword( aPassword )
    1873                 :            :         , maExternaleSourceURL( aExternaleSourceURL )
    1874                 :          0 :         , maLinkTargetURL( aLinkTargetURL )
    1875                 :          0 :     {}
    1876                 :            : 
    1877                 :            :     // Methods XStarBasicLibraryInfo
    1878                 :          0 :     virtual ::rtl::OUString SAL_CALL getName() throw(RuntimeException)
    1879                 :          0 :         { return maName; }
    1880                 :          0 :     virtual Reference< XNameContainer > SAL_CALL getModuleContainer() throw(RuntimeException)
    1881                 :          0 :         { return mxModuleContainer; }
    1882                 :          0 :     virtual Reference< XNameContainer > SAL_CALL getDialogContainer() throw(RuntimeException)
    1883                 :          0 :         { return mxDialogContainer; }
    1884                 :          0 :     virtual ::rtl::OUString SAL_CALL getPassword() throw(RuntimeException)
    1885                 :          0 :         { return maPassword; }
    1886                 :          0 :     virtual ::rtl::OUString SAL_CALL getExternalSourceURL() throw(RuntimeException)
    1887                 :          0 :         { return maExternaleSourceURL; }
    1888                 :          0 :     virtual ::rtl::OUString SAL_CALL getLinkTargetURL() throw(RuntimeException)
    1889                 :          0 :         { return maLinkTargetURL; }
    1890                 :            : };
    1891                 :            : 
    1892                 :            : //=====================================================================
    1893                 :            : 
    1894         [ #  # ]:          0 : class ModuleContainer_Impl : public NameContainerHelper
    1895                 :            : {
    1896                 :            :     StarBASIC* mpLib;
    1897                 :            : 
    1898                 :            : public:
    1899                 :          0 :     ModuleContainer_Impl( StarBASIC* pLib )
    1900                 :          0 :         :mpLib( pLib ) {}
    1901                 :            : 
    1902                 :            :     // Methods XElementAccess
    1903                 :            :     virtual Type SAL_CALL getElementType()
    1904                 :            :         throw(RuntimeException);
    1905                 :            :     virtual sal_Bool SAL_CALL hasElements()
    1906                 :            :         throw(RuntimeException);
    1907                 :            : 
    1908                 :            :     // Methods XNameAccess
    1909                 :            :     virtual Any SAL_CALL getByName( const ::rtl::OUString& aName )
    1910                 :            :         throw(NoSuchElementException, WrappedTargetException, RuntimeException);
    1911                 :            :     virtual Sequence< ::rtl::OUString > SAL_CALL getElementNames()
    1912                 :            :         throw(RuntimeException);
    1913                 :            :     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
    1914                 :            :         throw(RuntimeException);
    1915                 :            : 
    1916                 :            :     // Methods XNameReplace
    1917                 :            :     virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const Any& aElement )
    1918                 :            :         throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
    1919                 :            : 
    1920                 :            :     // Methods XNameContainer
    1921                 :            :     virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const Any& aElement )
    1922                 :            :         throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException);
    1923                 :            :     virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
    1924                 :            :         throw(NoSuchElementException, WrappedTargetException, RuntimeException);
    1925                 :            : };
    1926                 :            : 
    1927                 :            : // Methods XElementAccess
    1928                 :          0 : Type ModuleContainer_Impl::getElementType()
    1929                 :            :     throw(RuntimeException)
    1930                 :            : {
    1931                 :          0 :     Type aModuleType = ::getCppuType( (const Reference< XStarBasicModuleInfo > *)0 );
    1932                 :          0 :     return aModuleType;
    1933                 :            : }
    1934                 :            : 
    1935                 :          0 : sal_Bool ModuleContainer_Impl::hasElements()
    1936                 :            :     throw(RuntimeException)
    1937                 :            : {
    1938         [ #  # ]:          0 :     SbxArray* pMods = mpLib ? mpLib->GetModules() : NULL;
    1939 [ #  # ][ #  # ]:          0 :     return pMods && pMods->Count() > 0;
    1940                 :            : }
    1941                 :            : 
    1942                 :            : // Methods XNameAccess
    1943                 :          0 : Any ModuleContainer_Impl::getByName( const ::rtl::OUString& aName )
    1944                 :            :     throw(NoSuchElementException, WrappedTargetException, RuntimeException)
    1945                 :            : {
    1946 [ #  # ][ #  # ]:          0 :     SbModule* pMod = mpLib ? mpLib->FindModule( aName ) : NULL;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1947         [ #  # ]:          0 :     if( !pMod )
    1948         [ #  # ]:          0 :         throw NoSuchElementException();
    1949                 :            :     Reference< XStarBasicModuleInfo > xMod = (XStarBasicModuleInfo*)new ModuleInfo_Impl
    1950 [ #  # ][ #  # ]:          0 :         ( aName, ::rtl::OUString::createFromAscii( szScriptLanguage ), pMod->GetSource32() );
         [ #  # ][ #  # ]
    1951                 :          0 :     Any aRetAny;
    1952         [ #  # ]:          0 :     aRetAny <<= xMod;
    1953                 :          0 :     return aRetAny;
    1954                 :            : }
    1955                 :            : 
    1956                 :          0 : Sequence< ::rtl::OUString > ModuleContainer_Impl::getElementNames()
    1957                 :            :     throw(RuntimeException)
    1958                 :            : {
    1959         [ #  # ]:          0 :     SbxArray* pMods = mpLib ? mpLib->GetModules() : NULL;
    1960         [ #  # ]:          0 :     sal_uInt16 nMods = pMods ? pMods->Count() : 0;
    1961                 :          0 :     Sequence< ::rtl::OUString > aRetSeq( nMods );
    1962         [ #  # ]:          0 :     ::rtl::OUString* pRetSeq = aRetSeq.getArray();
    1963         [ #  # ]:          0 :     for( sal_uInt16 i = 0 ; i < nMods ; i++ )
    1964                 :            :     {
    1965         [ #  # ]:          0 :         SbxVariable* pMod = pMods->Get( i );
    1966 [ #  # ][ #  # ]:          0 :         pRetSeq[i] = ::rtl::OUString( pMod->GetName() );
    1967                 :            :     }
    1968                 :          0 :     return aRetSeq;
    1969                 :            : }
    1970                 :            : 
    1971                 :          0 : sal_Bool ModuleContainer_Impl::hasByName( const ::rtl::OUString& aName )
    1972                 :            :     throw(RuntimeException)
    1973                 :            : {
    1974 [ #  # ][ #  # ]:          0 :     SbModule* pMod = mpLib ? mpLib->FindModule( aName ) : NULL;
         [ #  # ][ #  # ]
                 [ #  # ]
    1975                 :          0 :     sal_Bool bRet = (pMod != NULL);
    1976                 :          0 :     return bRet;
    1977                 :            : }
    1978                 :            : 
    1979                 :            : 
    1980                 :            : // Methods XNameReplace
    1981                 :          0 : void ModuleContainer_Impl::replaceByName( const ::rtl::OUString& aName, const Any& aElement )
    1982                 :            :     throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
    1983                 :            : {
    1984                 :          0 :     removeByName( aName );
    1985                 :          0 :     insertByName( aName, aElement );
    1986                 :          0 : }
    1987                 :            : 
    1988                 :            : 
    1989                 :            : // Methods XNameContainer
    1990                 :          0 : void ModuleContainer_Impl::insertByName( const ::rtl::OUString& aName, const Any& aElement )
    1991                 :            :     throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
    1992                 :            : {
    1993         [ #  # ]:          0 :     Type aModuleType = ::getCppuType( (const Reference< XStarBasicModuleInfo > *)0 );
    1994                 :          0 :     Type aAnyType = aElement.getValueType();
    1995         [ #  # ]:          0 :     if( aModuleType != aAnyType )
    1996         [ #  # ]:          0 :         throw IllegalArgumentException();
    1997                 :          0 :     Reference< XStarBasicModuleInfo > xMod;
    1998         [ #  # ]:          0 :     aElement >>= xMod;
    1999 [ #  # ][ #  # ]:          0 :     mpLib->MakeModule32( aName, xMod->getSource() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2000                 :          0 : }
    2001                 :            : 
    2002                 :          0 : void ModuleContainer_Impl::removeByName( const ::rtl::OUString& Name )
    2003                 :            :     throw(NoSuchElementException, WrappedTargetException, RuntimeException)
    2004                 :            : {
    2005 [ #  # ][ #  # ]:          0 :     SbModule* pMod = mpLib ? mpLib->FindModule( Name ) : NULL;
         [ #  # ][ #  # ]
                 [ #  # ]
    2006         [ #  # ]:          0 :     if( !pMod )
    2007         [ #  # ]:          0 :         throw NoSuchElementException();
    2008                 :          0 :     mpLib->Remove( pMod );
    2009                 :          0 : }
    2010                 :            : 
    2011                 :            : 
    2012                 :            : //=====================================================================
    2013                 :            : 
    2014                 :          0 : Sequence< sal_Int8 > implGetDialogData( SbxObject* pDialog )
    2015                 :            : {
    2016         [ #  # ]:          0 :     SvMemoryStream aMemStream;
    2017         [ #  # ]:          0 :     pDialog->Store( aMemStream );
    2018                 :          0 :     sal_Int32 nLen = aMemStream.Tell();
    2019         [ #  # ]:          0 :     Sequence< sal_Int8 > aData( nLen );
    2020         [ #  # ]:          0 :     sal_Int8* pDestData = aData.getArray();
    2021         [ #  # ]:          0 :     const sal_Int8* pSrcData = (const sal_Int8*)aMemStream.GetData();
    2022         [ #  # ]:          0 :     rtl_copyMemory( pDestData, pSrcData, nLen );
    2023         [ #  # ]:          0 :     return aData;
    2024                 :            : }
    2025                 :            : 
    2026                 :          0 : SbxObject* implCreateDialog( Sequence< sal_Int8 > aData )
    2027                 :            : {
    2028         [ #  # ]:          0 :     sal_Int8* pData = aData.getArray();
    2029         [ #  # ]:          0 :     SvMemoryStream aMemStream( pData, aData.getLength(), STREAM_READ );
    2030         [ #  # ]:          0 :     SbxObject* pDialog = (SbxObject*)SbxBase::Load( aMemStream );
    2031         [ #  # ]:          0 :     return pDialog;
    2032                 :            : }
    2033                 :            : 
    2034                 :            : // HACK! Because this value is defined in basctl/inc/vcsbxdef.hxx
    2035                 :            : // which we can't include here, we have to use the value directly
    2036                 :            : #define SBXID_DIALOG        101
    2037                 :            : 
    2038                 :            : 
    2039         [ #  # ]:          0 : class DialogContainer_Impl : public NameContainerHelper
    2040                 :            : {
    2041                 :            :     StarBASIC* mpLib;
    2042                 :            : 
    2043                 :            : public:
    2044                 :          0 :     DialogContainer_Impl( StarBASIC* pLib )
    2045                 :          0 :         :mpLib( pLib ) {}
    2046                 :            : 
    2047                 :            :     // Methods XElementAccess
    2048                 :            :     virtual Type SAL_CALL getElementType()
    2049                 :            :         throw(RuntimeException);
    2050                 :            :     virtual sal_Bool SAL_CALL hasElements()
    2051                 :            :         throw(RuntimeException);
    2052                 :            : 
    2053                 :            :     // Methods XNameAccess
    2054                 :            :     virtual Any SAL_CALL getByName( const ::rtl::OUString& aName )
    2055                 :            :         throw(NoSuchElementException, WrappedTargetException, RuntimeException);
    2056                 :            :     virtual Sequence< ::rtl::OUString > SAL_CALL getElementNames()
    2057                 :            :         throw(RuntimeException);
    2058                 :            :     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
    2059                 :            :         throw(RuntimeException);
    2060                 :            : 
    2061                 :            :     // Methods XNameReplace
    2062                 :            :     virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const Any& aElement )
    2063                 :            :         throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
    2064                 :            : 
    2065                 :            :     // Methods XNameContainer
    2066                 :            :     virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const Any& aElement )
    2067                 :            :         throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException);
    2068                 :            :     virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
    2069                 :            :         throw(NoSuchElementException, WrappedTargetException, RuntimeException);
    2070                 :            : };
    2071                 :            : 
    2072                 :            : // Methods XElementAccess
    2073                 :          0 : Type DialogContainer_Impl::getElementType()
    2074                 :            :     throw(RuntimeException)
    2075                 :            : {
    2076                 :          0 :     Type aModuleType = ::getCppuType( (const Reference< XStarBasicDialogInfo > *)0 );
    2077                 :          0 :     return aModuleType;
    2078                 :            : }
    2079                 :            : 
    2080                 :          0 : sal_Bool DialogContainer_Impl::hasElements()
    2081                 :            :     throw(RuntimeException)
    2082                 :            : {
    2083                 :          0 :     sal_Bool bRet = sal_False;
    2084                 :            : 
    2085                 :          0 :     mpLib->GetAll( SbxCLASS_OBJECT );
    2086                 :          0 :     sal_Int16 nCount = mpLib->GetObjects()->Count();
    2087         [ #  # ]:          0 :     for( sal_Int16 nObj = 0; nObj < nCount ; nObj++ )
    2088                 :            :     {
    2089                 :          0 :         SbxVariable* pVar = mpLib->GetObjects()->Get( nObj );
    2090 [ #  # ][ #  # ]:          0 :         if ( pVar->ISA( SbxObject ) && ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) )
                 [ #  # ]
    2091                 :            :         {
    2092                 :          0 :             bRet = sal_True;
    2093                 :          0 :             break;
    2094                 :            :         }
    2095                 :            :     }
    2096                 :          0 :     return bRet;
    2097                 :            : }
    2098                 :            : 
    2099                 :            : // Methods XNameAccess
    2100                 :          0 : Any DialogContainer_Impl::getByName( const ::rtl::OUString& aName )
    2101                 :            :     throw(NoSuchElementException, WrappedTargetException, RuntimeException)
    2102                 :            : {
    2103         [ #  # ]:          0 :     SbxVariable* pVar = mpLib->GetObjects()->Find( aName, SbxCLASS_DONTCARE );
    2104 [ #  # ][ #  # ]:          0 :     if( !( pVar && pVar->ISA( SbxObject ) &&
                 [ #  # ]
    2105 [ #  # ][ #  # ]:          0 :            ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) ) )
         [ #  # ][ #  # ]
    2106                 :            :     {
    2107         [ #  # ]:          0 :         throw NoSuchElementException();
    2108                 :            :     }
    2109                 :            : 
    2110                 :            :     Reference< XStarBasicDialogInfo > xDialog =
    2111                 :            :         (XStarBasicDialogInfo*)new DialogInfo_Impl
    2112 [ #  # ][ #  # ]:          0 :             ( aName, implGetDialogData( (SbxObject*)pVar ) );
         [ #  # ][ #  # ]
                 [ #  # ]
    2113                 :            : 
    2114                 :          0 :     Any aRetAny;
    2115         [ #  # ]:          0 :     aRetAny <<= xDialog;
    2116                 :          0 :     return aRetAny;
    2117                 :            : }
    2118                 :            : 
    2119                 :          0 : Sequence< ::rtl::OUString > DialogContainer_Impl::getElementNames()
    2120                 :            :     throw(RuntimeException)
    2121                 :            : {
    2122                 :          0 :     mpLib->GetAll( SbxCLASS_OBJECT );
    2123                 :          0 :     sal_Int16 nCount = mpLib->GetObjects()->Count();
    2124                 :          0 :     Sequence< ::rtl::OUString > aRetSeq( nCount );
    2125         [ #  # ]:          0 :     ::rtl::OUString* pRetSeq = aRetSeq.getArray();
    2126                 :          0 :     sal_Int32 nDialogCounter = 0;
    2127                 :            : 
    2128         [ #  # ]:          0 :     for( sal_Int16 nObj = 0; nObj < nCount ; nObj++ )
    2129                 :            :     {
    2130         [ #  # ]:          0 :         SbxVariable* pVar = mpLib->GetObjects()->Get( nObj );
    2131 [ #  # ][ #  # ]:          0 :         if ( pVar->ISA( SbxObject ) && ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2132                 :            :         {
    2133 [ #  # ][ #  # ]:          0 :             pRetSeq[ nDialogCounter ] = ::rtl::OUString( pVar->GetName() );
    2134                 :          0 :             nDialogCounter++;
    2135                 :            :         }
    2136                 :            :     }
    2137         [ #  # ]:          0 :     aRetSeq.realloc( nDialogCounter );
    2138                 :          0 :     return aRetSeq;
    2139                 :            : }
    2140                 :            : 
    2141                 :          0 : sal_Bool DialogContainer_Impl::hasByName( const ::rtl::OUString& aName )
    2142                 :            :     throw(RuntimeException)
    2143                 :            : {
    2144                 :          0 :     sal_Bool bRet = sal_False;
    2145                 :          0 :     SbxVariable* pVar = mpLib->GetObjects()->Find( aName, SbxCLASS_DONTCARE );
    2146   [ #  #  #  # ]:          0 :     if( pVar && pVar->ISA( SbxObject ) &&
         [ #  # ][ #  # ]
    2147                 :          0 :            ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) )
    2148                 :            :     {
    2149                 :          0 :         bRet = sal_True;
    2150                 :            :     }
    2151                 :          0 :     return bRet;
    2152                 :            : }
    2153                 :            : 
    2154                 :            : 
    2155                 :            : // Methods XNameReplace
    2156                 :          0 : void DialogContainer_Impl::replaceByName( const ::rtl::OUString& aName, const Any& aElement )
    2157                 :            :     throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
    2158                 :            : {
    2159                 :          0 :     removeByName( aName );
    2160                 :          0 :     insertByName( aName, aElement );
    2161                 :          0 : }
    2162                 :            : 
    2163                 :            : 
    2164                 :            : // Methods XNameContainer
    2165                 :          0 : void DialogContainer_Impl::insertByName( const ::rtl::OUString& aName, const Any& aElement )
    2166                 :            :     throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
    2167                 :            : {
    2168                 :            :     (void)aName;
    2169         [ #  # ]:          0 :     Type aModuleType = ::getCppuType( (const Reference< XStarBasicDialogInfo > *)0 );
    2170                 :          0 :     Type aAnyType = aElement.getValueType();
    2171         [ #  # ]:          0 :     if( aModuleType != aAnyType )
    2172         [ #  # ]:          0 :         throw IllegalArgumentException();
    2173                 :          0 :     Reference< XStarBasicDialogInfo > xMod;
    2174         [ #  # ]:          0 :     aElement >>= xMod;
    2175 [ #  # ][ #  # ]:          0 :     SbxObjectRef xDialog = implCreateDialog( xMod->getData() );
         [ #  # ][ #  # ]
    2176 [ #  # ][ #  # ]:          0 :     mpLib->Insert( xDialog );
    2177                 :          0 : }
    2178                 :            : 
    2179                 :          0 : void DialogContainer_Impl::removeByName( const ::rtl::OUString& Name )
    2180                 :            :     throw(NoSuchElementException, WrappedTargetException, RuntimeException)
    2181                 :            : {
    2182                 :            :     (void)Name;
    2183                 :          0 :     SbxVariable* pVar = mpLib->GetObjects()->Find( Name, SbxCLASS_DONTCARE );
    2184         [ #  # ]:          0 :     if( !( pVar && pVar->ISA( SbxObject ) &&
    2185         [ #  # ]:          0 :            ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) ) )
           [ #  #  #  # ]
    2186                 :            :     {
    2187         [ #  # ]:          0 :         throw NoSuchElementException();
    2188                 :            :     }
    2189                 :          0 :     mpLib->Remove( pVar );
    2190                 :          0 : }
    2191                 :            : 
    2192                 :            : 
    2193                 :            : //=====================================================================
    2194                 :            : 
    2195                 :            : 
    2196         [ #  # ]:          0 : class LibraryContainer_Impl : public NameContainerHelper
    2197                 :            : {
    2198                 :            :     BasicManager* mpMgr;
    2199                 :            : 
    2200                 :            : public:
    2201                 :          0 :     LibraryContainer_Impl( BasicManager* pMgr )
    2202                 :          0 :         :mpMgr( pMgr ) {}
    2203                 :            : 
    2204                 :            :     // Methods XElementAccess
    2205                 :            :     virtual Type SAL_CALL getElementType()
    2206                 :            :         throw(RuntimeException);
    2207                 :            :     virtual sal_Bool SAL_CALL hasElements()
    2208                 :            :         throw(RuntimeException);
    2209                 :            : 
    2210                 :            :     // Methods XNameAccess
    2211                 :            :     virtual Any SAL_CALL getByName( const ::rtl::OUString& aName )
    2212                 :            :         throw(NoSuchElementException, WrappedTargetException, RuntimeException);
    2213                 :            :     virtual Sequence< ::rtl::OUString > SAL_CALL getElementNames()
    2214                 :            :         throw(RuntimeException);
    2215                 :            :     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
    2216                 :            :         throw(RuntimeException);
    2217                 :            : 
    2218                 :            :     // Methods XNameReplace
    2219                 :            :     virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const Any& aElement )
    2220                 :            :         throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
    2221                 :            : 
    2222                 :            :     // Methods XNameContainer
    2223                 :            :     virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const Any& aElement )
    2224                 :            :         throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException);
    2225                 :            :     virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
    2226                 :            :         throw(NoSuchElementException, WrappedTargetException, RuntimeException);
    2227                 :            : };
    2228                 :            : 
    2229                 :            : 
    2230                 :            : // Methods XElementAccess
    2231                 :          0 : Type LibraryContainer_Impl::getElementType()
    2232                 :            :     throw(RuntimeException)
    2233                 :            : {
    2234                 :          0 :     Type aType = ::getCppuType( (const Reference< XStarBasicLibraryInfo > *)0 );
    2235                 :          0 :     return aType;
    2236                 :            : }
    2237                 :            : 
    2238                 :          0 : sal_Bool LibraryContainer_Impl::hasElements()
    2239                 :            :     throw(RuntimeException)
    2240                 :            : {
    2241                 :          0 :     sal_Int32 nLibs = mpMgr->GetLibCount();
    2242                 :          0 :     sal_Bool bRet = (nLibs > 0);
    2243                 :          0 :     return bRet;
    2244                 :            : }
    2245                 :            : 
    2246                 :            : // Methods XNameAccess
    2247                 :          0 : Any LibraryContainer_Impl::getByName( const ::rtl::OUString& aName )
    2248                 :            :     throw(NoSuchElementException, WrappedTargetException, RuntimeException)
    2249                 :            : {
    2250                 :          0 :     Any aRetAny;
    2251 [ #  # ][ #  # ]:          0 :     if( !mpMgr->HasLib( aName ) )
         [ #  # ][ #  # ]
    2252         [ #  # ]:          0 :         throw NoSuchElementException();
    2253 [ #  # ][ #  # ]:          0 :     StarBASIC* pLib = mpMgr->GetLib( aName );
                 [ #  # ]
    2254                 :            : 
    2255                 :            :     Reference< XNameContainer > xModuleContainer =
    2256 [ #  # ][ #  # ]:          0 :         (XNameContainer*)new ModuleContainer_Impl( pLib );
                 [ #  # ]
    2257                 :            : 
    2258                 :            :     Reference< XNameContainer > xDialogContainer =
    2259 [ #  # ][ #  # ]:          0 :         (XNameContainer*)new DialogContainer_Impl( pLib );
                 [ #  # ]
    2260                 :            : 
    2261         [ #  # ]:          0 :     BasicLibInfo* pLibInfo = mpMgr->FindLibInfo( pLib );
    2262                 :            : 
    2263         [ #  # ]:          0 :     ::rtl::OUString aPassword = pLibInfo->GetPassword();
    2264                 :            : 
    2265                 :            :     // TODO Only provide extern info!
    2266                 :          0 :     ::rtl::OUString aExternaleSourceURL;
    2267                 :          0 :     ::rtl::OUString aLinkTargetURL;
    2268         [ #  # ]:          0 :     if( pLibInfo->IsReference() )
    2269         [ #  # ]:          0 :         aLinkTargetURL = pLibInfo->GetStorageName();
    2270 [ #  # ][ #  # ]:          0 :     else if( pLibInfo->IsExtern() )
    2271         [ #  # ]:          0 :         aExternaleSourceURL = pLibInfo->GetStorageName();
    2272                 :            : 
    2273                 :            :     Reference< XStarBasicLibraryInfo > xLibInfo = new LibraryInfo_Impl
    2274                 :            :     (
    2275                 :            :         aName,
    2276                 :            :         xModuleContainer,
    2277                 :            :         xDialogContainer,
    2278                 :            :         aPassword,
    2279                 :            :         aExternaleSourceURL,
    2280                 :            :         aLinkTargetURL
    2281 [ #  # ][ #  # ]:          0 :     );
                 [ #  # ]
    2282                 :            : 
    2283         [ #  # ]:          0 :     aRetAny <<= xLibInfo;
    2284                 :          0 :     return aRetAny;
    2285                 :            : }
    2286                 :            : 
    2287                 :          0 : Sequence< ::rtl::OUString > LibraryContainer_Impl::getElementNames()
    2288                 :            :     throw(RuntimeException)
    2289                 :            : {
    2290                 :          0 :     sal_uInt16 nLibs = mpMgr->GetLibCount();
    2291                 :          0 :     Sequence< ::rtl::OUString > aRetSeq( nLibs );
    2292         [ #  # ]:          0 :     ::rtl::OUString* pRetSeq = aRetSeq.getArray();
    2293         [ #  # ]:          0 :     for( sal_uInt16 i = 0 ; i < nLibs ; i++ )
    2294                 :            :     {
    2295 [ #  # ][ #  # ]:          0 :         pRetSeq[i] = ::rtl::OUString( mpMgr->GetLibName( i ) );
                 [ #  # ]
    2296                 :            :     }
    2297                 :          0 :     return aRetSeq;
    2298                 :            : }
    2299                 :            : 
    2300                 :          0 : sal_Bool LibraryContainer_Impl::hasByName( const ::rtl::OUString& aName )
    2301                 :            :     throw(RuntimeException)
    2302                 :            : {
    2303         [ #  # ]:          0 :     sal_Bool bRet = mpMgr->HasLib( aName );
    2304                 :          0 :     return bRet;
    2305                 :            : }
    2306                 :            : 
    2307                 :            : // Methods XNameReplace
    2308                 :          0 : void LibraryContainer_Impl::replaceByName( const ::rtl::OUString& aName, const Any& aElement )
    2309                 :            :     throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
    2310                 :            : {
    2311                 :          0 :     removeByName( aName );
    2312                 :          0 :     insertByName( aName, aElement );
    2313                 :          0 : }
    2314                 :            : 
    2315                 :            : // Methods XNameContainer
    2316                 :          0 : void LibraryContainer_Impl::insertByName( const ::rtl::OUString& aName, const Any& aElement )
    2317                 :            :     throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
    2318                 :            : {
    2319                 :            :     (void)aName;
    2320                 :            :     (void)aElement;
    2321                 :            :     // TODO: Insert a complete Library?!
    2322                 :          0 : }
    2323                 :            : 
    2324                 :          0 : void LibraryContainer_Impl::removeByName( const ::rtl::OUString& Name )
    2325                 :            :     throw(NoSuchElementException, WrappedTargetException, RuntimeException)
    2326                 :            : {
    2327         [ #  # ]:          0 :     StarBASIC* pLib = mpMgr->GetLib( Name );
    2328         [ #  # ]:          0 :     if( !pLib )
    2329         [ #  # ]:          0 :         throw NoSuchElementException();
    2330         [ #  # ]:          0 :     sal_uInt16 nLibId = mpMgr->GetLibId( Name );
    2331                 :          0 :     mpMgr->RemoveLib( nLibId );
    2332                 :          0 : }
    2333                 :            : 
    2334                 :            : //=====================================================================
    2335                 :            : 
    2336                 :            : typedef WeakImplHelper1< XStarBasicAccess > StarBasicAccessHelper;
    2337                 :            : 
    2338                 :            : 
    2339         [ #  # ]:          0 : class StarBasicAccess_Impl : public StarBasicAccessHelper
    2340                 :            : {
    2341                 :            :     BasicManager* mpMgr;
    2342                 :            :     Reference< XNameContainer > mxLibContainer;
    2343                 :            : 
    2344                 :            : public:
    2345                 :          0 :     StarBasicAccess_Impl( BasicManager* pMgr )
    2346                 :          0 :         :mpMgr( pMgr ) {}
    2347                 :            : 
    2348                 :            : public:
    2349                 :            : 
    2350                 :            :     // Methods
    2351                 :            :     virtual Reference< XNameContainer > SAL_CALL getLibraryContainer()
    2352                 :            :         throw(RuntimeException);
    2353                 :            :     virtual void SAL_CALL createLibrary( const ::rtl::OUString& LibName, const ::rtl::OUString& Password,
    2354                 :            :         const ::rtl::OUString& ExternalSourceURL, const ::rtl::OUString& LinkTargetURL )
    2355                 :            :             throw(ElementExistException, RuntimeException);
    2356                 :            :     virtual void SAL_CALL addModule( const ::rtl::OUString& LibraryName, const ::rtl::OUString& ModuleName,
    2357                 :            :         const ::rtl::OUString& Language, const ::rtl::OUString& Source )
    2358                 :            :             throw(NoSuchElementException, RuntimeException);
    2359                 :            :     virtual void SAL_CALL addDialog( const ::rtl::OUString& LibraryName, const ::rtl::OUString& DialogName,
    2360                 :            :         const Sequence< sal_Int8 >& Data )
    2361                 :            :             throw(NoSuchElementException, RuntimeException);
    2362                 :            : 
    2363                 :            : };
    2364                 :            : 
    2365                 :          0 : Reference< XNameContainer > SAL_CALL StarBasicAccess_Impl::getLibraryContainer()
    2366                 :            :     throw(RuntimeException)
    2367                 :            : {
    2368         [ #  # ]:          0 :     if( !mxLibContainer.is() )
    2369 [ #  # ][ #  # ]:          0 :         mxLibContainer = (XNameContainer*)new LibraryContainer_Impl( mpMgr );
    2370                 :          0 :     return mxLibContainer;
    2371                 :            : }
    2372                 :            : 
    2373                 :          0 : void SAL_CALL StarBasicAccess_Impl::createLibrary
    2374                 :            : (
    2375                 :            :     const ::rtl::OUString& LibName,
    2376                 :            :     const ::rtl::OUString& Password,
    2377                 :            :     const ::rtl::OUString& ExternalSourceURL,
    2378                 :            :     const ::rtl::OUString& LinkTargetURL
    2379                 :            : )
    2380                 :            :     throw(ElementExistException, RuntimeException)
    2381                 :            : {
    2382                 :            :     (void)ExternalSourceURL;
    2383                 :            : #ifdef DBG_UTIL
    2384                 :            :     StarBASIC* pLib =
    2385                 :            : #endif
    2386 [ #  # ][ #  # ]:          0 :     mpMgr->CreateLib( LibName, Password, LinkTargetURL );
         [ #  # ][ #  # ]
                 [ #  # ]
    2387                 :            :     DBG_ASSERT( pLib, "XML Import: Basic library could not be created");
    2388                 :          0 : }
    2389                 :            : 
    2390                 :          0 : void SAL_CALL StarBasicAccess_Impl::addModule
    2391                 :            : (
    2392                 :            :     const ::rtl::OUString& LibraryName,
    2393                 :            :     const ::rtl::OUString& ModuleName,
    2394                 :            :     const ::rtl::OUString& Language,
    2395                 :            :     const ::rtl::OUString& Source
    2396                 :            : )
    2397                 :            :     throw(NoSuchElementException, RuntimeException)
    2398                 :            : {
    2399                 :            :     (void)Language;
    2400         [ #  # ]:          0 :     StarBASIC* pLib = mpMgr->GetLib( LibraryName );
    2401                 :            :     DBG_ASSERT( pLib, "XML Import: Lib for module unknown");
    2402         [ #  # ]:          0 :     if( pLib )
    2403         [ #  # ]:          0 :         pLib->MakeModule32( ModuleName, Source );
    2404                 :          0 : }
    2405                 :            : 
    2406                 :          0 : void SAL_CALL StarBasicAccess_Impl::addDialog
    2407                 :            : (
    2408                 :            :     const ::rtl::OUString& LibraryName,
    2409                 :            :     const ::rtl::OUString& DialogName,
    2410                 :            :     const Sequence< sal_Int8 >& Data
    2411                 :            : )
    2412                 :            :     throw(NoSuchElementException, RuntimeException)
    2413                 :            : {
    2414                 :            :     (void)LibraryName;
    2415                 :            :     (void)DialogName;
    2416                 :            :     (void)Data;
    2417                 :          0 : }
    2418                 :            : 
    2419                 :            : // Basic XML Import/Export
    2420                 :          0 : Reference< XStarBasicAccess > getStarBasicAccess( BasicManager* pMgr )
    2421                 :            : {
    2422                 :            :     Reference< XStarBasicAccess > xRet =
    2423 [ #  # ][ #  # ]:          0 :         new StarBasicAccess_Impl( (BasicManager*)pMgr );
                 [ #  # ]
    2424                 :          0 :     return xRet;
    2425                 :            : }
    2426                 :            : 
    2427                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10