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