1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/errinf.hxx>
21 #include <tools/stream.hxx>
22 #include <sot/storage.hxx>
23 #include <tools/urlobj.hxx>
24 #include <svl/hint.hxx>
25 #include <basic/sbx.hxx>
26 #include <basic/sbmeth.hxx>
27 #include <sot/storinfo.hxx>
28 #include <unotools/pathoptions.hxx>
29 #include <tools/debug.hxx>
30 #include <tools/diagnose_ex.h>
31 #include <basic/sbmod.hxx>
32 #include <unotools/transliterationwrapper.hxx>
33 #include <sal/log.hxx>
35 #include <basic/sberrors.hxx>
36 #include <basic/sbuno.hxx>
37 #include <basic/basmgr.hxx>
39 #include <com/sun/star/script/XLibraryContainer.hpp>
40 #include <com/sun/star/script/XPersistentLibraryContainer.hpp>
46 #define LIBINFO_SEP 0x02
47 #define LIBINFO_ID 0x1491
48 #define PASSWORD_MARKER 0x31452134
51 // Library API, implemented for XML import/export
53 #include <com/sun/star/container/XNameContainer.hpp>
54 #include <com/sun/star/container/XContainer.hpp>
55 #include <com/sun/star/script/XStarBasicAccess.hpp>
56 #include <com/sun/star/script/XStarBasicModuleInfo.hpp>
57 #include <com/sun/star/script/XStarBasicDialogInfo.hpp>
58 #include <com/sun/star/script/XStarBasicLibraryInfo.hpp>
59 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
60 #include <com/sun/star/script/ModuleInfo.hpp>
61 #include <com/sun/star/script/vba/XVBACompatibility.hpp>
62 #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
63 #include <com/sun/star/ucb/ContentCreationException.hpp>
65 #include <cppuhelper/implbase.hxx>
67 using com::sun::star::uno::Reference
;
68 using namespace com::sun::star
;
69 using namespace com::sun::star::script
;
72 typedef WeakImplHelper
< container::XNameContainer
> NameContainerHelper
;
73 typedef WeakImplHelper
< script::XStarBasicModuleInfo
> ModuleInfoHelper
;
74 typedef WeakImplHelper
< script::XStarBasicAccess
> StarBasicAccessHelper
;
82 // String AbsStorageName
83 // String RelStorageName
87 const char szStdLibName
[] = "Standard";
88 const char szBasicStorage
[] = "StarBASIC";
89 const char szOldManagerStream
[] = "BasicManager";
90 const char szManagerStream
[] = "BasicManager2";
91 const char szImbedded
[] = "LIBIMBEDDED";
92 const char szCryptingKey
[] = "CryptedBasic";
95 const StreamMode eStreamReadMode
= StreamMode::READ
| StreamMode::NOCREATE
| StreamMode::SHARE_DENYALL
;
96 const StreamMode eStorageReadMode
= StreamMode::READ
| StreamMode::SHARE_DENYWRITE
;
99 // BasicManager impl data
100 struct BasicManagerImpl
102 LibraryContainerInfo maContainerInfo
;
104 std::vector
<std::unique_ptr
<BasicLibInfo
>> aLibs
;
105 OUString aBasicLibPath
;
111 // BasMgrContainerListenerImpl
114 typedef ::cppu::WeakImplHelper
< container::XContainerListener
> ContainerListenerHelper
;
116 class BasMgrContainerListenerImpl
: public ContainerListenerHelper
119 OUString maLibName
; // empty -> no lib, but lib container
122 BasMgrContainerListenerImpl( BasicManager
* pMgr
, const OUString
& aLibName
)
124 , maLibName( aLibName
) {}
126 static void insertLibraryImpl( const uno::Reference
< script::XLibraryContainer
>& xScriptCont
, BasicManager
* pMgr
,
127 const uno::Any
& aLibAny
, const OUString
& aLibName
);
128 static void addLibraryModulesImpl( BasicManager
const * pMgr
, const uno::Reference
< container::XNameAccess
>& xLibNameAccess
,
129 std::u16string_view aLibName
);
133 virtual void SAL_CALL
disposing( const lang::EventObject
& Source
) override
;
135 // XContainerListener
136 virtual void SAL_CALL
elementInserted( const container::ContainerEvent
& Event
) override
;
137 virtual void SAL_CALL
elementReplaced( const container::ContainerEvent
& Event
) override
;
138 virtual void SAL_CALL
elementRemoved( const container::ContainerEvent
& Event
) override
;
142 // BasMgrContainerListenerImpl
145 void BasMgrContainerListenerImpl::insertLibraryImpl( const uno::Reference
< script::XLibraryContainer
>& xScriptCont
,
146 BasicManager
* pMgr
, const uno::Any
& aLibAny
, const OUString
& aLibName
)
148 Reference
< container::XNameAccess
> xLibNameAccess
;
149 aLibAny
>>= xLibNameAccess
;
151 if( !pMgr
->GetLib( aLibName
) )
154 pMgr
->CreateLibForLibContainer( aLibName
, xScriptCont
);
155 DBG_ASSERT( pLib
, "XML Import: Basic library could not be created");
158 uno::Reference
< container::XContainer
> xLibContainer( xLibNameAccess
, uno::UNO_QUERY
);
159 if( xLibContainer
.is() )
161 // Register listener for library
162 Reference
< container::XContainerListener
> xLibraryListener
163 = new BasMgrContainerListenerImpl( pMgr
, aLibName
);
164 xLibContainer
->addContainerListener( xLibraryListener
);
167 if( xScriptCont
->isLibraryLoaded( aLibName
) )
169 addLibraryModulesImpl( pMgr
, xLibNameAccess
, aLibName
);
174 void BasMgrContainerListenerImpl::addLibraryModulesImpl( BasicManager
const * pMgr
,
175 const uno::Reference
< container::XNameAccess
>& xLibNameAccess
, std::u16string_view aLibName
)
177 uno::Sequence
< OUString
> aModuleNames
= xLibNameAccess
->getElementNames();
178 sal_Int32 nModuleCount
= aModuleNames
.getLength();
180 StarBASIC
* pLib
= pMgr
->GetLib( aLibName
);
181 DBG_ASSERT( pLib
, "BasMgrContainerListenerImpl::addLibraryModulesImpl: Unknown lib!");
185 const OUString
* pNames
= aModuleNames
.getConstArray();
186 for( sal_Int32 j
= 0 ; j
< nModuleCount
; j
++ )
188 OUString aModuleName
= pNames
[ j
];
189 uno::Any aElement
= xLibNameAccess
->getByName( aModuleName
);
192 uno::Reference
< vba::XVBAModuleInfo
> xVBAModuleInfo( xLibNameAccess
, uno::UNO_QUERY
);
193 if ( xVBAModuleInfo
.is() && xVBAModuleInfo
->hasModuleInfo( aModuleName
) )
195 ModuleInfo aInfo
= xVBAModuleInfo
->getModuleInfo( aModuleName
);
196 pLib
->MakeModule( aModuleName
, aInfo
, aMod
);
199 pLib
->MakeModule( aModuleName
, aMod
);
202 pLib
->SetModified( false );
209 void SAL_CALL
BasMgrContainerListenerImpl::disposing( const lang::EventObject
& ) {}
211 // XContainerListener
214 void SAL_CALL
BasMgrContainerListenerImpl::elementInserted( const container::ContainerEvent
& Event
)
216 bool bLibContainer
= maLibName
.isEmpty();
218 Event
.Accessor
>>= aName
;
222 uno::Reference
< script::XLibraryContainer
> xScriptCont( Event
.Source
, uno::UNO_QUERY
);
223 if (xScriptCont
.is())
224 insertLibraryImpl(xScriptCont
, mpMgr
, Event
.Element
, aName
);
225 StarBASIC
* pLib
= mpMgr
->GetLib( aName
);
228 uno::Reference
< vba::XVBACompatibility
> xVBACompat( xScriptCont
, uno::UNO_QUERY
);
229 if ( xVBACompat
.is() )
230 pLib
->SetVBAEnabled( xVBACompat
->getVBACompatibilityMode() );
236 StarBASIC
* pLib
= mpMgr
->GetLib( maLibName
);
237 DBG_ASSERT( pLib
, "BasMgrContainerListenerImpl::elementInserted: Unknown lib!");
240 SbModule
* pMod
= pLib
->FindModule( aName
);
244 Event
.Element
>>= aMod
;
245 uno::Reference
< vba::XVBAModuleInfo
> xVBAModuleInfo( Event
.Source
, uno::UNO_QUERY
);
246 if ( xVBAModuleInfo
.is() && xVBAModuleInfo
->hasModuleInfo( aName
) )
248 ModuleInfo aInfo
= xVBAModuleInfo
->getModuleInfo( aName
);
249 pLib
->MakeModule( aName
, aInfo
, aMod
);
252 pLib
->MakeModule( aName
, aMod
);
253 pLib
->SetModified( false );
260 void SAL_CALL
BasMgrContainerListenerImpl::elementReplaced( const container::ContainerEvent
& Event
)
263 Event
.Accessor
>>= aName
;
265 // Replace not possible for library container
266 DBG_ASSERT( !maLibName
.isEmpty(), "library container fired elementReplaced()");
268 StarBASIC
* pLib
= mpMgr
->GetLib( maLibName
);
272 SbModule
* pMod
= pLib
->FindModule( aName
);
274 Event
.Element
>>= aMod
;
277 pMod
->SetSource32( aMod
);
279 pLib
->MakeModule( aName
, aMod
);
281 pLib
->SetModified( false );
285 void SAL_CALL
BasMgrContainerListenerImpl::elementRemoved( const container::ContainerEvent
& Event
)
288 Event
.Accessor
>>= aName
;
290 bool bLibContainer
= maLibName
.isEmpty();
293 StarBASIC
* pLib
= mpMgr
->GetLib( aName
);
296 sal_uInt16 nLibId
= mpMgr
->GetLibId( aName
);
297 mpMgr
->RemoveLib( nLibId
, false );
302 StarBASIC
* pLib
= mpMgr
->GetLib( maLibName
);
303 SbModule
* pMod
= pLib
? pLib
->FindModule( aName
) : nullptr;
306 pLib
->Remove( pMod
);
307 pLib
->SetModified( false );
312 BasicError::BasicError( ErrCode nId
, BasicErrorReason nR
)
318 BasicError::BasicError( const BasicError
& rErr
)
320 nErrorId
= rErr
.nErrorId
;
321 nReason
= rErr
.nReason
;
330 OUString aStorageName
; // string is sufficient, unique at runtime
331 OUString aRelStorageName
;
337 // Lib represents library in new UNO library container
338 uno::Reference
< script::XLibraryContainer
> mxScriptCont
;
343 bool IsReference() const { return bReference
; }
344 void SetReference(bool b
) { bReference
= b
; }
346 bool IsExtern() const { return aStorageName
!= szImbedded
; }
348 void SetStorageName( const OUString
& rName
) { aStorageName
= rName
; }
349 const OUString
& GetStorageName() const { return aStorageName
; }
351 void SetRelStorageName( const OUString
& rN
) { aRelStorageName
= rN
; }
352 const OUString
& GetRelStorageName() const { return aRelStorageName
; }
354 StarBASICRef
GetLib() const
356 if( mxScriptCont
.is() && mxScriptCont
->hasByName( aLibName
) &&
357 !mxScriptCont
->isLibraryLoaded( aLibName
) )
358 return StarBASICRef();
361 StarBASICRef
& GetLibRef() { return xLib
; }
362 void SetLib( StarBASIC
* pBasic
) { xLib
= pBasic
; }
364 const OUString
& GetLibName() const { return aLibName
; }
365 void SetLibName( const OUString
& rName
) { aLibName
= rName
; }
367 // Only temporary for Load/Save
368 bool DoLoad() { return bDoLoad
; }
370 bool HasPassword() const { return !aPassword
.isEmpty(); }
371 const OUString
& GetPassword() const { return aPassword
; }
372 void SetPassword( const OUString
& rNewPassword
)
373 { aPassword
= rNewPassword
; }
375 static BasicLibInfo
* Create( SotStorageStream
& rSStream
);
377 const uno::Reference
< script::XLibraryContainer
>& GetLibraryContainer() const
378 { return mxScriptCont
; }
379 void SetLibraryContainer( const uno::Reference
< script::XLibraryContainer
>& xScriptCont
)
380 { mxScriptCont
= xScriptCont
; }
384 BasicLibInfo::BasicLibInfo()
385 : aStorageName(szImbedded
)
386 , aRelStorageName(szImbedded
)
392 BasicLibInfo
* BasicLibInfo::Create( SotStorageStream
& rSStream
)
394 BasicLibInfo
* pInfo
= new BasicLibInfo
;
400 rSStream
.ReadUInt32( nEndPos
);
401 rSStream
.ReadUInt16( nId
);
402 rSStream
.ReadUInt16( nVer
);
404 DBG_ASSERT( nId
== LIBINFO_ID
, "No BasicLibInfo?!" );
405 if( nId
== LIBINFO_ID
)
409 rSStream
.ReadCharAsBool( bDoLoad
);
410 pInfo
->bDoLoad
= bDoLoad
;
412 // The name of the lib...
413 OUString aName
= rSStream
.ReadUniOrByteString(rSStream
.GetStreamCharSet());
414 pInfo
->SetLibName( aName
);
417 OUString aStorageName
= rSStream
.ReadUniOrByteString(rSStream
.GetStreamCharSet());
418 pInfo
->SetStorageName( aStorageName
);
421 OUString aRelStorageName
= rSStream
.ReadUniOrByteString(rSStream
.GetStreamCharSet());
422 pInfo
->SetRelStorageName( aRelStorageName
);
427 rSStream
.ReadCharAsBool( bReferenz
);
428 pInfo
->SetReference(bReferenz
);
431 rSStream
.Seek( nEndPos
);
436 BasicManager::BasicManager( SotStorage
& rStorage
, const OUString
& rBaseURL
, StarBASIC
* pParentFromStdLib
, OUString
const * pLibPath
, bool bDocMgr
) : mbDocMgr( bDocMgr
)
442 mpImpl
->aBasicLibPath
= *pLibPath
;
444 OUString
aStorName( rStorage
.GetName() );
445 maStorageName
= INetURLObject(aStorName
, INetProtocol::File
).GetMainURL( INetURLObject::DecodeMechanism::NONE
);
448 // If there is no Manager Stream, no further actions are necessary
449 if ( rStorage
.IsStream( szManagerStream
) )
451 LoadBasicManager( rStorage
, rBaseURL
);
452 // StdLib contains Parent:
453 StarBASIC
* pStdLib
= GetStdLib();
454 DBG_ASSERT( pStdLib
, "Standard-Lib not loaded?" );
457 // Should never happen, but if it happens we won't crash...
458 pStdLib
= new StarBASIC( nullptr, mbDocMgr
);
460 if (mpImpl
->aLibs
.empty())
463 BasicLibInfo
& rStdLibInfo
= *mpImpl
->aLibs
.front();
465 rStdLibInfo
.SetLib( pStdLib
);
466 StarBASICRef xStdLib
= rStdLibInfo
.GetLib();
467 xStdLib
->SetName( szStdLibName
);
468 rStdLibInfo
.SetLibName( szStdLibName
);
469 xStdLib
->SetFlag( SbxFlagBits::DontStore
| SbxFlagBits::ExtSearch
);
470 xStdLib
->SetModified( false );
474 pStdLib
->SetParent( pParentFromStdLib
);
475 // The other get StdLib as parent:
477 for ( sal_uInt16 nBasic
= 1; nBasic
< GetLibCount(); nBasic
++ )
479 StarBASIC
* pBasic
= GetLib( nBasic
);
482 pStdLib
->Insert( pBasic
);
483 pBasic
->SetFlag( SbxFlagBits::ExtSearch
);
486 // Modified through insert
487 pStdLib
->SetModified( false );
492 ImpCreateStdLib( pParentFromStdLib
);
493 if ( rStorage
.IsStream( szOldManagerStream
) )
494 LoadOldBasicManager( rStorage
);
498 static void copyToLibraryContainer( StarBASIC
* pBasic
, const LibraryContainerInfo
& rInfo
)
500 uno::Reference
< script::XLibraryContainer
> xScriptCont( rInfo
.mxScriptCont
.get() );
501 if ( !xScriptCont
.is() )
504 OUString aLibName
= pBasic
->GetName();
505 if( !xScriptCont
->hasByName( aLibName
) )
506 xScriptCont
->createLibrary( aLibName
);
508 uno::Any aLibAny
= xScriptCont
->getByName( aLibName
);
509 uno::Reference
< container::XNameContainer
> xLib
;
514 for ( const auto& pModule
: pBasic
->GetModules() )
516 OUString aModName
= pModule
->GetName();
517 if( !xLib
->hasByName( aModName
) )
519 OUString aSource
= pModule
->GetSource32();
521 aSourceAny
<<= aSource
;
522 xLib
->insertByName( aModName
, aSourceAny
);
527 const uno::Reference
< script::XPersistentLibraryContainer
>& BasicManager::GetDialogLibraryContainer() const
529 return mpImpl
->maContainerInfo
.mxDialogCont
;
532 const uno::Reference
< script::XPersistentLibraryContainer
>& BasicManager::GetScriptLibraryContainer() const
534 return mpImpl
->maContainerInfo
.mxScriptCont
;
537 void BasicManager::SetLibraryContainerInfo( const LibraryContainerInfo
& rInfo
)
539 mpImpl
->maContainerInfo
= rInfo
;
541 uno::Reference
< script::XLibraryContainer
> xScriptCont( mpImpl
->maContainerInfo
.mxScriptCont
.get() );
542 if( xScriptCont
.is() )
544 // Register listener for lib container
545 uno::Reference
< container::XContainerListener
> xLibContainerListener
546 = new BasMgrContainerListenerImpl( this, "" );
548 uno::Reference
< container::XContainer
> xLibContainer( xScriptCont
, uno::UNO_QUERY
);
549 xLibContainer
->addContainerListener( xLibContainerListener
);
551 const uno::Sequence
< OUString
> aScriptLibNames
= xScriptCont
->getElementNames();
553 if( aScriptLibNames
.hasElements() )
555 for(const auto& rScriptLibName
: aScriptLibNames
)
557 uno::Any aLibAny
= xScriptCont
->getByName( rScriptLibName
);
559 if ( rScriptLibName
== "Standard" || rScriptLibName
== "VBAProject")
560 xScriptCont
->loadLibrary( rScriptLibName
);
562 BasMgrContainerListenerImpl::insertLibraryImpl
563 ( xScriptCont
, this, aLibAny
, rScriptLibName
);
568 // No libs? Maybe an 5.2 document already loaded
569 for (auto const& rpBasLibInfo
: mpImpl
->aLibs
)
571 StarBASIC
* pLib
= rpBasLibInfo
->GetLib().get();
574 bool bLoaded
= ImpLoadLibrary( rpBasLibInfo
.get(), nullptr );
576 pLib
= rpBasLibInfo
->GetLib().get();
580 copyToLibraryContainer( pLib
, mpImpl
->maContainerInfo
);
581 if (rpBasLibInfo
->HasPassword())
583 OldBasicPassword
* pOldBasicPassword
=
584 mpImpl
->maContainerInfo
.mpOldBasicPassword
;
585 if( pOldBasicPassword
)
587 pOldBasicPassword
->setLibraryPassword(
588 pLib
->GetName(), rpBasLibInfo
->GetPassword() );
596 SetGlobalUNOConstant( "BasicLibraries", uno::Any( mpImpl
->maContainerInfo
.mxScriptCont
) );
597 SetGlobalUNOConstant( "DialogLibraries", uno::Any( mpImpl
->maContainerInfo
.mxDialogCont
) );
600 BasicManager::BasicManager( StarBASIC
* pSLib
, OUString
const * pLibPath
, bool bDocMgr
) : mbDocMgr( bDocMgr
)
603 DBG_ASSERT( pSLib
, "BasicManager cannot be created with a NULL-Pointer!" );
607 mpImpl
->aBasicLibPath
= *pLibPath
;
609 BasicLibInfo
* pStdLibInfo
= CreateLibInfo();
610 pStdLibInfo
->SetLib( pSLib
);
611 StarBASICRef xStdLib
= pStdLibInfo
->GetLib();
612 xStdLib
->SetName(szStdLibName
);
613 pStdLibInfo
->SetLibName(szStdLibName
);
614 pSLib
->SetFlag( SbxFlagBits::DontStore
| SbxFlagBits::ExtSearch
);
616 // Save is only necessary if basic has changed
617 xStdLib
->SetModified( false );
620 void BasicManager::ImpMgrNotLoaded( const OUString
& rStorageName
)
622 // pErrInf is only destroyed if the error os processed by an
624 StringErrorInfo
* pErrInf
= new StringErrorInfo( ERRCODE_BASMGR_MGROPEN
, rStorageName
, DialogMask::ButtonsOk
);
625 aErrors
.emplace_back(*pErrInf
, BasicErrorReason::OPENMGRSTREAM
);
627 // Create a stdlib otherwise we crash!
628 BasicLibInfo
* pStdLibInfo
= CreateLibInfo();
629 pStdLibInfo
->SetLib( new StarBASIC( nullptr, mbDocMgr
) );
630 StarBASICRef xStdLib
= pStdLibInfo
->GetLib();
631 xStdLib
->SetName( szStdLibName
);
632 pStdLibInfo
->SetLibName( szStdLibName
);
633 xStdLib
->SetFlag( SbxFlagBits::DontStore
| SbxFlagBits::ExtSearch
);
634 xStdLib
->SetModified( false );
638 void BasicManager::ImpCreateStdLib( StarBASIC
* pParentFromStdLib
)
640 BasicLibInfo
* pStdLibInfo
= CreateLibInfo();
641 StarBASIC
* pStdLib
= new StarBASIC( pParentFromStdLib
, mbDocMgr
);
642 pStdLibInfo
->SetLib( pStdLib
);
643 pStdLib
->SetName( szStdLibName
);
644 pStdLibInfo
->SetLibName( szStdLibName
);
645 pStdLib
->SetFlag( SbxFlagBits::DontStore
| SbxFlagBits::ExtSearch
);
648 void BasicManager::LoadBasicManager( SotStorage
& rStorage
, const OUString
& rBaseURL
)
650 tools::SvRef
<SotStorageStream
> xManagerStream
= rStorage
.OpenSotStream( szManagerStream
, eStreamReadMode
);
652 OUString
aStorName( rStorage
.GetName() );
653 // #i13114 removed, DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
655 if ( !xManagerStream
.is() || xManagerStream
->GetError() || ( xManagerStream
->TellEnd() == 0 ) )
657 ImpMgrNotLoaded( aStorName
);
661 maStorageName
= INetURLObject(aStorName
, INetProtocol::File
).GetMainURL( INetURLObject::DecodeMechanism::NONE
);
662 // #i13114 removed, DBG_ASSERT(aStorageName.Len() != 0, "Bad storage name");
664 OUString aRealStorageName
= maStorageName
; // for relative paths, can be modified through BaseURL
666 if ( !rBaseURL
.isEmpty() )
668 INetURLObject
aObj( rBaseURL
);
669 if ( aObj
.GetProtocol() == INetProtocol::File
)
671 aRealStorageName
= aObj
.PathToFileName();
675 xManagerStream
->SetBufferSize( 1024 );
676 xManagerStream
->Seek( STREAM_SEEK_TO_BEGIN
);
679 xManagerStream
->ReadUInt32( nEndPos
);
682 xManagerStream
->ReadUInt16( nLibs
);
686 SAL_WARN( "basic", "BasicManager-Stream defect!" );
689 const size_t nMinBasicLibSize(8);
690 const size_t nMaxPossibleLibs
= xManagerStream
->remainingSize() / nMinBasicLibSize
;
691 if (nLibs
> nMaxPossibleLibs
)
693 SAL_WARN("basic", "Parsing error: " << nMaxPossibleLibs
<<
694 " max possible entries, but " << nLibs
<< " claimed, truncating");
695 nLibs
= nMaxPossibleLibs
;
697 for (sal_uInt16 nL
= 0; nL
< nLibs
; ++nL
)
699 BasicLibInfo
* pInfo
= BasicLibInfo::Create( *xManagerStream
);
701 // Correct absolute pathname if relative is existing.
702 // Always try relative first if there are two stands on disk
703 if ( !pInfo
->GetRelStorageName().isEmpty() && pInfo
->GetRelStorageName() != szImbedded
)
705 INetURLObject
aObj( aRealStorageName
, INetProtocol::File
);
706 aObj
.removeSegment();
707 bool bWasAbsolute
= false;
708 aObj
= aObj
.smartRel2Abs( pInfo
->GetRelStorageName(), bWasAbsolute
);
710 //*** TODO: Replace if still necessary
712 if ( ! mpImpl
->aBasicLibPath
.isEmpty() )
714 // Search lib in path
715 OUString aSearchFile
= pInfo
->GetRelStorageName();
716 OUString
aSearchFileOldFormat(aSearchFile
);
717 SvtPathOptions aPathCFG
;
718 if( aPathCFG
.SearchFile( aSearchFileOldFormat
, SvtPathOptions::PATH_BASIC
) )
720 pInfo
->SetStorageName( aSearchFile
);
725 mpImpl
->aLibs
.push_back(std::unique_ptr
<BasicLibInfo
>(pInfo
));
726 // Libs from external files should be loaded only when necessary.
727 // But references are loaded at once, otherwise some big customers get into trouble
728 if ( pInfo
->DoLoad() &&
729 ( !pInfo
->IsExtern() || pInfo
->IsReference()))
731 ImpLoadLibrary( pInfo
, &rStorage
);
735 xManagerStream
->Seek( nEndPos
);
736 xManagerStream
->SetBufferSize( 0 );
737 xManagerStream
.clear();
740 void BasicManager::LoadOldBasicManager( SotStorage
& rStorage
)
742 tools::SvRef
<SotStorageStream
> xManagerStream
= rStorage
.OpenSotStream( szOldManagerStream
, eStreamReadMode
);
744 OUString
aStorName( rStorage
.GetName() );
745 DBG_ASSERT( aStorName
.getLength(), "No Storage Name!" );
747 if ( !xManagerStream
.is() || xManagerStream
->GetError() || ( xManagerStream
->TellEnd() == 0 ) )
749 ImpMgrNotLoaded( aStorName
);
753 xManagerStream
->SetBufferSize( 1024 );
754 xManagerStream
->Seek( STREAM_SEEK_TO_BEGIN
);
755 sal_uInt32 nBasicStartOff
, nBasicEndOff
;
756 xManagerStream
->ReadUInt32( nBasicStartOff
);
757 xManagerStream
->ReadUInt32( nBasicEndOff
);
759 DBG_ASSERT( !xManagerStream
->GetError(), "Invalid Manager-Stream!" );
761 xManagerStream
->Seek( nBasicStartOff
);
762 if (!ImplLoadBasic( *xManagerStream
, mpImpl
->aLibs
.front()->GetLibRef() ))
764 StringErrorInfo
* pErrInf
= new StringErrorInfo( ERRCODE_BASMGR_MGROPEN
, aStorName
, DialogMask::ButtonsOk
);
765 aErrors
.emplace_back(*pErrInf
, BasicErrorReason::OPENMGRSTREAM
);
766 // and it proceeds ...
768 xManagerStream
->Seek( nBasicEndOff
+1 ); // +1: 0x00 as separator
769 OUString aLibs
= xManagerStream
->ReadUniOrByteString(xManagerStream
->GetStreamCharSet());
770 xManagerStream
->SetBufferSize( 0 );
771 xManagerStream
.clear(); // Close stream
773 if ( aLibs
.isEmpty() )
776 INetURLObject
aCurStorage( aStorName
, INetProtocol::File
);
777 sal_Int32 nLibPos
{0};
779 const OUString
aLibInfo(aLibs
.getToken(0, LIB_SEP
, nLibPos
));
780 sal_Int32 nInfoPos
{0};
781 const OUString
aLibName( aLibInfo
.getToken( 0, LIBINFO_SEP
, nInfoPos
) );
782 DBG_ASSERT( nInfoPos
>= 0, "Invalid Lib-Info!" );
783 const OUString
aLibAbsStorageName( aLibInfo
.getToken( 0, LIBINFO_SEP
, nInfoPos
) );
784 // TODO: fail also here if there are no more tokens?
785 const OUString
aLibRelStorageName( aLibInfo
.getToken( 0, LIBINFO_SEP
, nInfoPos
) );
786 DBG_ASSERT( nInfoPos
< 0, "Invalid Lib-Info!" );
787 INetURLObject
aLibAbsStorage( aLibAbsStorageName
, INetProtocol::File
);
789 INetURLObject
aLibRelStorage( aStorName
);
790 aLibRelStorage
.removeSegment();
791 bool bWasAbsolute
= false;
792 aLibRelStorage
= aLibRelStorage
.smartRel2Abs( aLibRelStorageName
, bWasAbsolute
);
793 DBG_ASSERT(!bWasAbsolute
, "RelStorageName was absolute!" );
795 tools::SvRef
<SotStorage
> xStorageRef
;
796 if ( aLibAbsStorage
== aCurStorage
|| aLibRelStorageName
== szImbedded
)
798 xStorageRef
= &rStorage
;
802 xStorageRef
= new SotStorage( false, aLibAbsStorage
.GetMainURL
803 ( INetURLObject::DecodeMechanism::NONE
), eStorageReadMode
);
804 if ( xStorageRef
->GetError() != ERRCODE_NONE
)
805 xStorageRef
= new SotStorage( false, aLibRelStorage
.
806 GetMainURL( INetURLObject::DecodeMechanism::NONE
), eStorageReadMode
);
808 if ( xStorageRef
.is() )
810 AddLib( *xStorageRef
, aLibName
, false );
814 StringErrorInfo
* pErrInf
= new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD
, aStorName
, DialogMask::ButtonsOk
);
815 aErrors
.emplace_back(*pErrInf
, BasicErrorReason::STORAGENOTFOUND
);
817 } while (nLibPos
>=0);
820 BasicManager::~BasicManager()
822 // Notify listener if something needs to be saved
823 Broadcast( SfxHint( SfxHintId::Dying
) );
826 bool BasicManager::HasExeCode( std::u16string_view sLib
)
828 StarBASIC
* pLib
= GetLib(sLib
);
831 for (const auto& pModule
: pLib
->GetModules())
833 if (pModule
->HasExeCode())
840 void BasicManager::Init()
842 mpImpl
.reset( new BasicManagerImpl
);
845 BasicLibInfo
* BasicManager::CreateLibInfo()
847 mpImpl
->aLibs
.push_back(std::make_unique
<BasicLibInfo
>());
848 return mpImpl
->aLibs
.back().get();
851 bool BasicManager::ImpLoadLibrary( BasicLibInfo
* pLibInfo
, SotStorage
* pCurStorage
)
854 DBG_ASSERT( pLibInfo
, "LibInfo!?" );
856 OUString
aStorageName( pLibInfo
->GetStorageName() );
857 if ( aStorageName
.isEmpty() || aStorageName
== szImbedded
)
859 aStorageName
= GetStorageName();
861 tools::SvRef
<SotStorage
> xStorage
;
862 // The current must not be opened again...
865 OUString
aStorName( pCurStorage
->GetName() );
866 // #i13114 removed, DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
868 INetURLObject
aCurStorageEntry(aStorName
, INetProtocol::File
);
869 // #i13114 removed, DBG_ASSERT(aCurStorageEntry.GetMainURL( INetURLObject::DecodeMechanism::NONE ).Len() != 0, "Bad storage name");
871 INetURLObject
aStorageEntry(aStorageName
, INetProtocol::File
);
872 // #i13114 removed, DBG_ASSERT(aCurStorageEntry.GetMainURL( INetURLObject::DecodeMechanism::NONE ).Len() != 0, "Bad storage name");
874 if ( aCurStorageEntry
== aStorageEntry
)
876 xStorage
= pCurStorage
;
880 if ( !xStorage
.is() )
882 xStorage
= new SotStorage( false, aStorageName
, eStorageReadMode
);
884 tools::SvRef
<SotStorage
> xBasicStorage
= xStorage
->OpenSotStorage( szBasicStorage
, eStorageReadMode
, false );
886 if ( !xBasicStorage
.is() || xBasicStorage
->GetError() )
888 StringErrorInfo
* pErrInf
= new StringErrorInfo( ERRCODE_BASMGR_MGROPEN
, xStorage
->GetName(), DialogMask::ButtonsOk
);
889 aErrors
.emplace_back(*pErrInf
, BasicErrorReason::OPENLIBSTORAGE
);
893 // In the Basic-Storage every lib is in a Stream...
894 tools::SvRef
<SotStorageStream
> xBasicStream
= xBasicStorage
->OpenSotStream( pLibInfo
->GetLibName(), eStreamReadMode
);
895 if ( !xBasicStream
.is() || xBasicStream
->GetError() )
897 StringErrorInfo
* pErrInf
= new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD
, pLibInfo
->GetLibName(), DialogMask::ButtonsOk
);
898 aErrors
.emplace_back(*pErrInf
, BasicErrorReason::OPENLIBSTREAM
);
902 bool bLoaded
= false;
903 if ( xBasicStream
->TellEnd() != 0 )
905 if ( !pLibInfo
->GetLib().is() )
907 pLibInfo
->SetLib( new StarBASIC( GetStdLib(), mbDocMgr
) );
909 xBasicStream
->SetBufferSize( 1024 );
910 xBasicStream
->Seek( STREAM_SEEK_TO_BEGIN
);
911 bLoaded
= ImplLoadBasic( *xBasicStream
, pLibInfo
->GetLibRef() );
912 xBasicStream
->SetBufferSize( 0 );
913 StarBASICRef xStdLib
= pLibInfo
->GetLib();
914 xStdLib
->SetName( pLibInfo
->GetLibName() );
915 xStdLib
->SetModified( false );
916 xStdLib
->SetFlag( SbxFlagBits::DontStore
);
920 StringErrorInfo
* pErrInf
= new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD
, pLibInfo
->GetLibName(), DialogMask::ButtonsOk
);
921 aErrors
.emplace_back(*pErrInf
, BasicErrorReason::BASICLOADERROR
);
925 // Perhaps there are additional information in the stream...
926 xBasicStream
->SetCryptMaskKey(szCryptingKey
);
927 xBasicStream
->RefreshBuffer();
928 sal_uInt32 nPasswordMarker
= 0;
929 xBasicStream
->ReadUInt32( nPasswordMarker
);
930 if ( ( nPasswordMarker
== PASSWORD_MARKER
) && !xBasicStream
->eof() )
932 OUString aPassword
= xBasicStream
->ReadUniOrByteString(
933 xBasicStream
->GetStreamCharSet());
934 pLibInfo
->SetPassword( aPassword
);
936 xBasicStream
->SetCryptMaskKey(OString());
937 CheckModules( pLibInfo
->GetLib().get(), pLibInfo
->IsReference() );
943 catch (const css::ucb::ContentCreationException
&)
949 bool BasicManager::ImplEncryptStream( SvStream
& rStrm
)
951 sal_uInt64
const nPos
= rStrm
.Tell();
953 rStrm
.ReadUInt32( nCreator
);
955 bool bProtected
= false;
956 if ( nCreator
!= SBXCR_SBX
)
958 // Should only be the case for encrypted Streams
960 rStrm
.SetCryptMaskKey(szCryptingKey
);
961 rStrm
.RefreshBuffer();
966 // This code is necessary to load the BASIC of Beta 1
967 // TODO: Which Beta 1?
968 bool BasicManager::ImplLoadBasic( SvStream
& rStrm
, StarBASICRef
& rOldBasic
) const
970 bool bProtected
= ImplEncryptStream( rStrm
);
971 SbxBaseRef xNew
= SbxBase::Load( rStrm
);
972 bool bLoaded
= false;
975 if( auto pNew
= dynamic_cast<StarBASIC
*>( xNew
.get() ) )
977 // Use the Parent of the old BASICs
980 pNew
->SetParent( rOldBasic
->GetParent() );
981 if( pNew
->GetParent() )
983 pNew
->GetParent()->Insert( pNew
);
985 pNew
->SetFlag( SbxFlagBits::ExtSearch
);
989 // Fill new library container (5.2 -> 6.0)
990 copyToLibraryContainer( pNew
, mpImpl
->maContainerInfo
);
992 pNew
->SetModified( false );
998 rStrm
.SetCryptMaskKey(OString());
1003 void BasicManager::CheckModules( StarBASIC
* pLib
, bool bReference
)
1009 bool bModified
= pLib
->IsModified();
1011 for ( const auto& pModule
: pLib
->GetModules() )
1013 DBG_ASSERT(pModule
, "Module not received!");
1014 if ( !pModule
->IsCompiled() && !StarBASIC::GetErrorCode() )
1020 // #67477, AB 8.12.99 On demand compile in referenced libs should not
1022 if( !bModified
&& bReference
)
1024 OSL_FAIL( "Referenced basic library is not compiled!" );
1025 pLib
->SetModified( false );
1029 StarBASIC
* BasicManager::AddLib( SotStorage
& rStorage
, const OUString
& rLibName
, bool bReference
)
1031 OUString
aStorName( rStorage
.GetName() );
1032 DBG_ASSERT( !aStorName
.isEmpty(), "No Storage Name!" );
1034 OUString aStorageName
= INetURLObject(aStorName
, INetProtocol::File
).GetMainURL( INetURLObject::DecodeMechanism::NONE
);
1035 DBG_ASSERT(!aStorageName
.isEmpty(), "Bad storage name");
1037 OUString
aNewLibName( rLibName
);
1038 while ( HasLib( aNewLibName
) )
1042 BasicLibInfo
* pLibInfo
= CreateLibInfo();
1043 // Use original name otherwise ImpLoadLibrary fails...
1044 pLibInfo
->SetLibName( rLibName
);
1045 // but doesn't work this way if name exists twice
1046 sal_uInt16 nLibId
= static_cast<sal_uInt16
>(mpImpl
->aLibs
.size()) - 1;
1048 // Set StorageName before load because it is compared with pCurStorage
1049 pLibInfo
->SetStorageName( aStorageName
);
1050 bool bLoaded
= ImpLoadLibrary( pLibInfo
, &rStorage
);
1054 if ( aNewLibName
!= rLibName
)
1056 pLibInfo
->SetLibName(aNewLibName
);
1060 pLibInfo
->GetLib()->SetModified( false ); // Don't save in this case
1061 pLibInfo
->SetRelStorageName( OUString() );
1062 pLibInfo
->SetReference(true);
1066 pLibInfo
->GetLib()->SetModified( true ); // Must be saved after Add!
1067 pLibInfo
->SetStorageName( szImbedded
); // Save in BasicManager-Storage
1072 RemoveLib( nLibId
, false );
1076 return pLibInfo
? &*pLibInfo
->GetLib() : nullptr;
1080 bool BasicManager::IsReference( sal_uInt16 nLib
)
1082 DBG_ASSERT( nLib
< mpImpl
->aLibs
.size(), "Lib does not exist!" );
1083 if ( nLib
< mpImpl
->aLibs
.size() )
1085 return mpImpl
->aLibs
[nLib
]->IsReference();
1090 void BasicManager::RemoveLib( sal_uInt16 nLib
)
1092 // Only physical deletion if no reference
1093 RemoveLib( nLib
, !IsReference( nLib
) );
1096 bool BasicManager::RemoveLib( sal_uInt16 nLib
, bool bDelBasicFromStorage
)
1098 DBG_ASSERT( nLib
, "Standard-Lib cannot be removed!" );
1100 DBG_ASSERT( !nLib
|| nLib
< mpImpl
->aLibs
.size(), "Lib not found!" );
1102 if( !nLib
|| nLib
< mpImpl
->aLibs
.size() )
1104 StringErrorInfo
* pErrInf
= new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB
, OUString(), DialogMask::ButtonsOk
);
1105 aErrors
.emplace_back(*pErrInf
, BasicErrorReason::STDLIB
);
1109 auto const itLibInfo
= mpImpl
->aLibs
.begin() + nLib
;
1111 // If one of the streams cannot be opened, this is not an error,
1112 // because BASIC was never written before...
1113 if (bDelBasicFromStorage
&& !(*itLibInfo
)->IsReference() &&
1114 (!(*itLibInfo
)->IsExtern() || SotStorage::IsStorageFile((*itLibInfo
)->GetStorageName())))
1116 tools::SvRef
<SotStorage
> xStorage
;
1119 if (!(*itLibInfo
)->IsExtern())
1121 xStorage
= new SotStorage(false, GetStorageName());
1125 xStorage
= new SotStorage(false, (*itLibInfo
)->GetStorageName());
1128 catch (const css::ucb::ContentCreationException
&)
1130 TOOLS_WARN_EXCEPTION("basic", "BasicManager::RemoveLib:");
1133 if (xStorage
.is() && xStorage
->IsStorage(szBasicStorage
))
1135 tools::SvRef
<SotStorage
> xBasicStorage
= xStorage
->OpenSotStorage
1136 ( szBasicStorage
, StreamMode::STD_READWRITE
, false );
1138 if ( !xBasicStorage
.is() || xBasicStorage
->GetError() )
1140 StringErrorInfo
* pErrInf
= new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB
, OUString(), DialogMask::ButtonsOk
);
1141 aErrors
.emplace_back(*pErrInf
, BasicErrorReason::OPENLIBSTORAGE
);
1143 else if (xBasicStorage
->IsStream((*itLibInfo
)->GetLibName()))
1145 xBasicStorage
->Remove((*itLibInfo
)->GetLibName());
1146 xBasicStorage
->Commit();
1148 // If no further stream available,
1149 // delete the SubStorage.
1150 SvStorageInfoList aInfoList
;
1151 xBasicStorage
->FillInfoList( &aInfoList
);
1152 if ( aInfoList
.empty() )
1154 xBasicStorage
.clear();
1155 xStorage
->Remove( szBasicStorage
);
1157 // If no further Streams or SubStorages available,
1158 // delete the Storage, too.
1160 xStorage
->FillInfoList( &aInfoList
);
1161 if ( aInfoList
.empty() )
1163 //OUString aName_( xStorage->GetName() );
1165 //*** TODO: Replace if still necessary
1166 //SfxContentHelper::Kill( aName );
1173 if ((*itLibInfo
)->GetLib().is())
1175 GetStdLib()->Remove( (*itLibInfo
)->GetLib().get() );
1177 mpImpl
->aLibs
.erase(itLibInfo
);
1178 return true; // Remove was successful, del unimportant
1181 sal_uInt16
BasicManager::GetLibCount() const
1183 return static_cast<sal_uInt16
>(mpImpl
->aLibs
.size());
1186 StarBASIC
* BasicManager::GetLib( sal_uInt16 nLib
) const
1188 DBG_ASSERT( nLib
< mpImpl
->aLibs
.size(), "Lib does not exist!" );
1189 if ( nLib
< mpImpl
->aLibs
.size() )
1191 return mpImpl
->aLibs
[nLib
]->GetLib().get();
1196 StarBASIC
* BasicManager::GetStdLib() const
1198 StarBASIC
* pLib
= GetLib( 0 );
1202 StarBASIC
* BasicManager::GetLib( std::u16string_view rName
) const
1204 for (auto const& rpLib
: mpImpl
->aLibs
)
1206 if (rpLib
->GetLibName().equalsIgnoreAsciiCase(rName
)) // Check if available...
1208 return rpLib
->GetLib().get();
1214 sal_uInt16
BasicManager::GetLibId( std::u16string_view rName
) const
1216 for (size_t i
= 0; i
< mpImpl
->aLibs
.size(); i
++)
1218 if (mpImpl
->aLibs
[i
]->GetLibName().equalsIgnoreAsciiCase( rName
))
1220 return static_cast<sal_uInt16
>(i
);
1223 return LIB_NOTFOUND
;
1226 bool BasicManager::HasLib( std::u16string_view rName
) const
1228 for (const auto& rpLib
: mpImpl
->aLibs
)
1230 if (rpLib
->GetLibName().equalsIgnoreAsciiCase(rName
)) // Check if available...
1238 OUString
BasicManager::GetLibName( sal_uInt16 nLib
)
1240 DBG_ASSERT( nLib
< mpImpl
->aLibs
.size(), "Lib?!" );
1241 if ( nLib
< mpImpl
->aLibs
.size() )
1243 return mpImpl
->aLibs
[nLib
]->GetLibName();
1248 bool BasicManager::LoadLib( sal_uInt16 nLib
)
1251 DBG_ASSERT( nLib
< mpImpl
->aLibs
.size() , "Lib?!" );
1252 if ( nLib
< mpImpl
->aLibs
.size() )
1254 BasicLibInfo
& rLibInfo
= *mpImpl
->aLibs
[nLib
];
1255 uno::Reference
< script::XLibraryContainer
> xLibContainer
= rLibInfo
.GetLibraryContainer();
1256 if( xLibContainer
.is() )
1258 OUString aLibName
= rLibInfo
.GetLibName();
1259 xLibContainer
->loadLibrary( aLibName
);
1260 bDone
= xLibContainer
->isLibraryLoaded( aLibName
);
1264 bDone
= ImpLoadLibrary( &rLibInfo
, nullptr );
1265 StarBASIC
* pLib
= GetLib( nLib
);
1268 GetStdLib()->Insert( pLib
);
1269 pLib
->SetFlag( SbxFlagBits::ExtSearch
);
1275 StringErrorInfo
* pErrInf
= new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD
, OUString(), DialogMask::ButtonsOk
);
1276 aErrors
.emplace_back(*pErrInf
, BasicErrorReason::LIBNOTFOUND
);
1281 StarBASIC
* BasicManager::CreateLib( const OUString
& rLibName
)
1283 if ( GetLib( rLibName
) )
1287 BasicLibInfo
* pLibInfo
= CreateLibInfo();
1288 StarBASIC
* pNew
= new StarBASIC( GetStdLib(), mbDocMgr
);
1289 GetStdLib()->Insert( pNew
);
1290 pNew
->SetFlag( SbxFlagBits::ExtSearch
| SbxFlagBits::DontStore
);
1291 pLibInfo
->SetLib( pNew
);
1292 pLibInfo
->SetLibName( rLibName
);
1293 pLibInfo
->GetLib()->SetName( rLibName
);
1294 return pLibInfo
->GetLib().get();
1297 // For XML import/export:
1298 StarBASIC
* BasicManager::CreateLib( const OUString
& rLibName
, const OUString
& Password
,
1299 const OUString
& LinkTargetURL
)
1301 // Ask if lib exists because standard lib is always there
1302 StarBASIC
* pLib
= GetLib( rLibName
);
1305 if( !LinkTargetURL
.isEmpty())
1309 tools::SvRef
<SotStorage
> xStorage
= new SotStorage(false, LinkTargetURL
, StreamMode::READ
| StreamMode::SHARE_DENYWRITE
);
1310 if (!xStorage
->GetError())
1312 pLib
= AddLib(*xStorage
, rLibName
, true);
1315 catch (const css::ucb::ContentCreationException
&)
1317 TOOLS_WARN_EXCEPTION("basic", "BasicManager::RemoveLib:");
1319 DBG_ASSERT( pLib
, "XML Import: Linked basic library could not be loaded");
1323 pLib
= CreateLib( rLibName
);
1324 if( Password
.isEmpty())
1326 BasicLibInfo
* pLibInfo
= FindLibInfo( pLib
);
1327 pLibInfo
->SetPassword( Password
);
1330 //ExternalSourceURL ?
1335 StarBASIC
* BasicManager::CreateLibForLibContainer( const OUString
& rLibName
,
1336 const uno::Reference
< script::XLibraryContainer
>& xScriptCont
)
1338 if ( GetLib( rLibName
) )
1342 BasicLibInfo
* pLibInfo
= CreateLibInfo();
1343 StarBASIC
* pNew
= new StarBASIC( GetStdLib(), mbDocMgr
);
1344 GetStdLib()->Insert( pNew
);
1345 pNew
->SetFlag( SbxFlagBits::ExtSearch
| SbxFlagBits::DontStore
);
1346 pLibInfo
->SetLib( pNew
);
1347 pLibInfo
->SetLibName( rLibName
);
1348 pLibInfo
->GetLib()->SetName( rLibName
);
1349 pLibInfo
->SetLibraryContainer( xScriptCont
);
1354 BasicLibInfo
* BasicManager::FindLibInfo( StarBASIC
const * pBasic
)
1356 for (auto const& rpLib
: mpImpl
->aLibs
)
1358 if (rpLib
->GetLib().get() == pBasic
)
1367 bool BasicManager::IsBasicModified() const
1369 for (auto const& rpLib
: mpImpl
->aLibs
)
1371 if (rpLib
->GetLib().is() && rpLib
->GetLib()->IsModified())
1380 bool BasicManager::GetGlobalUNOConstant( const OUString
& rName
, uno::Any
& aOut
)
1383 StarBASIC
* pStandardLib
= GetStdLib();
1384 OSL_PRECOND( pStandardLib
, "BasicManager::GetGlobalUNOConstant: no lib to read from!" );
1386 bRes
= pStandardLib
->GetUNOConstant( rName
, aOut
);
1390 uno::Any
BasicManager::SetGlobalUNOConstant( const OUString
& rName
, const uno::Any
& _rValue
)
1394 StarBASIC
* pStandardLib
= GetStdLib();
1395 OSL_PRECOND( pStandardLib
, "BasicManager::SetGlobalUNOConstant: no lib to insert into!" );
1396 if ( !pStandardLib
)
1399 // obtain the old value
1400 SbxVariable
* pVariable
= pStandardLib
->Find( rName
, SbxClassType::Object
);
1402 aOldValue
= sbxToUnoValue( pVariable
);
1403 SbxObjectRef xUnoObj
= GetSbUnoObject( _rValue
.getValueType ().getTypeName () , _rValue
);
1404 xUnoObj
->SetName(rName
);
1405 xUnoObj
->SetFlag( SbxFlagBits::DontStore
);
1406 pStandardLib
->Insert( xUnoObj
.get() );
1411 bool BasicManager::LegacyPsswdBinaryLimitExceeded( std::vector
< OUString
>& _out_rModuleNames
)
1415 uno::Reference
< container::XNameAccess
> xScripts( GetScriptLibraryContainer(), uno::UNO_QUERY_THROW
);
1416 uno::Reference
< script::XLibraryContainerPassword
> xPassword( GetScriptLibraryContainer(), uno::UNO_QUERY_THROW
);
1418 const uno::Sequence
< OUString
> aNames( xScripts
->getElementNames() );
1419 for ( auto const & scriptElementName
: aNames
)
1421 if( !xPassword
->isLibraryPasswordProtected( scriptElementName
) )
1424 StarBASIC
* pBasicLib
= GetLib( scriptElementName
);
1428 uno::Reference
< container::XNameAccess
> xScriptLibrary( xScripts
->getByName( scriptElementName
), uno::UNO_QUERY_THROW
);
1429 const uno::Sequence
< OUString
> aElementNames( xScriptLibrary
->getElementNames() );
1430 sal_Int32 nLen
= aElementNames
.getLength();
1432 std::vector
< OUString
> aBigModules( nLen
);
1433 sal_Int32 nBigModules
= 0;
1435 for ( auto const & libraryElementName
: aElementNames
)
1437 SbModule
* pMod
= pBasicLib
->FindModule( libraryElementName
);
1438 if ( pMod
&& pMod
->ExceedsLegacyModuleSize() )
1439 aBigModules
[ nBigModules
++ ] = libraryElementName
;
1444 _out_rModuleNames
.swap(aBigModules
);
1449 catch( const uno::Exception
& )
1451 DBG_UNHANDLED_EXCEPTION("basic");
1459 SbMethod
* lcl_queryMacro( BasicManager
* i_manager
, OUString
const& i_fullyQualifiedName
)
1461 sal_Int32 nLast
= 0;
1462 const OUString sLibName
{i_fullyQualifiedName
.getToken( 0, '.', nLast
)};
1463 const OUString sModule
{i_fullyQualifiedName
.getToken( 0, '.', nLast
)};
1467 sMacro
= i_fullyQualifiedName
.copy(nLast
);
1471 sMacro
= i_fullyQualifiedName
;
1474 utl::TransliterationWrapper
& rTransliteration
= SbGlobal::GetTransliteration();
1475 sal_uInt16 nLibCount
= i_manager
->GetLibCount();
1476 for ( sal_uInt16 nLib
= 0; nLib
< nLibCount
; ++nLib
)
1478 if ( rTransliteration
.isEqual( i_manager
->GetLibName( nLib
), sLibName
) )
1480 StarBASIC
* pLib
= i_manager
->GetLib( nLib
);
1483 bool const bLoaded
= i_manager
->LoadLib( nLib
);
1486 pLib
= i_manager
->GetLib( nLib
);
1492 for ( const auto& pMod
: pLib
->GetModules() )
1494 if ( rTransliteration
.isEqual( pMod
->GetName(), sModule
) )
1496 SbMethod
* pMethod
= static_cast<SbMethod
*>(pMod
->Find( sMacro
, SbxClassType::Method
));
1510 bool BasicManager::HasMacro( OUString
const& i_fullyQualifiedName
) const
1512 return ( lcl_queryMacro( const_cast< BasicManager
* >( this ), i_fullyQualifiedName
) != nullptr );
1515 ErrCode
BasicManager::ExecuteMacro( OUString
const& i_fullyQualifiedName
, SbxArray
* i_arguments
, SbxValue
* i_retValue
)
1517 SbMethod
* pMethod
= lcl_queryMacro( this, i_fullyQualifiedName
);
1518 ErrCode nError
= ERRCODE_NONE
;
1522 pMethod
->SetParameters( i_arguments
);
1523 nError
= pMethod
->Call( i_retValue
);
1526 nError
= ERRCODE_BASIC_PROC_UNDEFINED
;
1530 ErrCode
BasicManager::ExecuteMacro( OUString
const& i_fullyQualifiedName
, OUString
const& i_commaSeparatedArgs
, SbxValue
* i_retValue
)
1532 SbMethod
* pMethod
= lcl_queryMacro( this, i_fullyQualifiedName
);
1535 return ERRCODE_BASIC_PROC_UNDEFINED
;
1537 // arguments must be quoted
1538 OUString sQuotedArgs
;
1539 OUStringBuffer
sArgs( i_commaSeparatedArgs
);
1540 if ( sArgs
.getLength()<2 || sArgs
[1] == '\"')
1542 // no args or already quoted args
1543 sQuotedArgs
= sArgs
.makeStringAndClear();
1548 sArgs
.remove( 0, 1 );
1549 sArgs
.remove( sArgs
.getLength() - 1, 1 );
1551 OUStringBuffer aBuff
;
1552 OUString sArgs2
= sArgs
.makeStringAndClear();
1555 if (!sArgs2
.isEmpty())
1561 aBuff
.append( "\"" );
1562 aBuff
.append( sArgs2
.getToken(0, ',', nPos
) );
1563 aBuff
.append( "\"" );
1566 aBuff
.append( "," );
1569 aBuff
.append( ")" );
1571 sQuotedArgs
= aBuff
.makeStringAndClear();
1574 // add quoted arguments and do the call
1575 OUString sCall
= "["
1576 + pMethod
->GetName()
1580 SbxVariable
* pRet
= pMethod
->GetParent()->Execute( sCall
);
1581 if ( pRet
&& ( pRet
!= pMethod
) )
1583 *i_retValue
= *pRet
;
1585 return SbxBase::GetError();
1590 class ModuleInfo_Impl
: public ModuleInfoHelper
1593 OUString maLanguage
;
1597 ModuleInfo_Impl( const OUString
& aName
, const OUString
& aLanguage
, const OUString
& aSource
)
1598 : maName( aName
), maLanguage( aLanguage
), maSource( aSource
) {}
1600 // Methods XStarBasicModuleInfo
1601 virtual OUString SAL_CALL
getName() override
1603 virtual OUString SAL_CALL
getLanguage() override
1604 { return maLanguage
; }
1605 virtual OUString SAL_CALL
getSource() override
1606 { return maSource
; }
1610 class DialogInfo_Impl
: public WeakImplHelper
< script::XStarBasicDialogInfo
>
1613 uno::Sequence
< sal_Int8
> mData
;
1616 DialogInfo_Impl( const OUString
& aName
, const uno::Sequence
< sal_Int8
>& Data
)
1617 : maName( aName
), mData( Data
) {}
1619 // Methods XStarBasicDialogInfo
1620 virtual OUString SAL_CALL
getName() override
1622 virtual uno::Sequence
< sal_Int8
> SAL_CALL
getData() override
1627 class LibraryInfo_Impl
: public WeakImplHelper
< script::XStarBasicLibraryInfo
>
1630 uno::Reference
< container::XNameContainer
> mxModuleContainer
;
1631 uno::Reference
< container::XNameContainer
> mxDialogContainer
;
1632 OUString maPassword
;
1633 OUString maExternaleSourceURL
;
1634 OUString maLinkTargetURL
;
1639 const OUString
& aName
,
1640 uno::Reference
< container::XNameContainer
> const & xModuleContainer
,
1641 uno::Reference
< container::XNameContainer
> const & xDialogContainer
,
1642 const OUString
& aPassword
,
1643 const OUString
& aExternaleSourceURL
,
1644 const OUString
& aLinkTargetURL
1647 , mxModuleContainer( xModuleContainer
)
1648 , mxDialogContainer( xDialogContainer
)
1649 , maPassword( aPassword
)
1650 , maExternaleSourceURL( aExternaleSourceURL
)
1651 , maLinkTargetURL( aLinkTargetURL
)
1654 // Methods XStarBasicLibraryInfo
1655 virtual OUString SAL_CALL
getName() override
1657 virtual uno::Reference
< container::XNameContainer
> SAL_CALL
getModuleContainer() override
1658 { return mxModuleContainer
; }
1659 virtual uno::Reference
< container::XNameContainer
> SAL_CALL
getDialogContainer() override
1660 { return mxDialogContainer
; }
1661 virtual OUString SAL_CALL
getPassword() override
1662 { return maPassword
; }
1663 virtual OUString SAL_CALL
getExternalSourceURL() override
1664 { return maExternaleSourceURL
; }
1665 virtual OUString SAL_CALL
getLinkTargetURL() override
1666 { return maLinkTargetURL
; }
1670 class ModuleContainer_Impl
: public NameContainerHelper
1675 explicit ModuleContainer_Impl( StarBASIC
* pLib
)
1678 // Methods XElementAccess
1679 virtual uno::Type SAL_CALL
getElementType() override
;
1680 virtual sal_Bool SAL_CALL
hasElements() override
;
1682 // Methods XNameAccess
1683 virtual uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
1684 virtual uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
1685 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
1687 // Methods XNameReplace
1688 virtual void SAL_CALL
replaceByName( const OUString
& aName
, const uno::Any
& aElement
) override
;
1690 // Methods XNameContainer
1691 virtual void SAL_CALL
insertByName( const OUString
& aName
, const uno::Any
& aElement
) override
;
1692 virtual void SAL_CALL
removeByName( const OUString
& Name
) override
;
1697 // Methods XElementAccess
1698 uno::Type
ModuleContainer_Impl::getElementType()
1700 uno::Type aModuleType
= cppu::UnoType
<script::XStarBasicModuleInfo
>::get();
1704 sal_Bool
ModuleContainer_Impl::hasElements()
1706 return mpLib
&& !mpLib
->GetModules().empty();
1709 // Methods XNameAccess
1710 uno::Any
ModuleContainer_Impl::getByName( const OUString
& aName
)
1712 SbModule
* pMod
= mpLib
? mpLib
->FindModule( aName
) : nullptr;
1714 throw container::NoSuchElementException();
1715 uno::Reference
< script::XStarBasicModuleInfo
> xMod
= new ModuleInfo_Impl( aName
, "StarBasic", pMod
->GetSource32() );
1721 uno::Sequence
< OUString
> ModuleContainer_Impl::getElementNames()
1723 sal_uInt16 nMods
= mpLib
? mpLib
->GetModules().size() : 0;
1724 uno::Sequence
< OUString
> aRetSeq( nMods
);
1725 OUString
* pRetSeq
= aRetSeq
.getArray();
1726 for( sal_uInt16 i
= 0 ; i
< nMods
; i
++ )
1728 pRetSeq
[i
] = mpLib
->GetModules()[i
]->GetName();
1733 sal_Bool
ModuleContainer_Impl::hasByName( const OUString
& aName
)
1735 SbModule
* pMod
= mpLib
? mpLib
->FindModule( aName
) : nullptr;
1736 bool bRet
= (pMod
!= nullptr);
1741 // Methods XNameReplace
1742 void ModuleContainer_Impl::replaceByName( const OUString
& aName
, const uno::Any
& aElement
)
1744 removeByName( aName
);
1745 insertByName( aName
, aElement
);
1749 // Methods XNameContainer
1750 void ModuleContainer_Impl::insertByName( const OUString
& aName
, const uno::Any
& aElement
)
1752 uno::Type aModuleType
= cppu::UnoType
<script::XStarBasicModuleInfo
>::get();
1753 const uno::Type
& aAnyType
= aElement
.getValueType();
1754 if( aModuleType
!= aAnyType
)
1756 throw lang::IllegalArgumentException();
1758 uno::Reference
< script::XStarBasicModuleInfo
> xMod
;
1760 mpLib
->MakeModule( aName
, xMod
->getSource() );
1763 void ModuleContainer_Impl::removeByName( const OUString
& Name
)
1765 SbModule
* pMod
= mpLib
? mpLib
->FindModule( Name
) : nullptr;
1768 throw container::NoSuchElementException();
1770 mpLib
->Remove( pMod
);
1774 static uno::Sequence
< sal_Int8
> implGetDialogData( SbxObject
* pDialog
)
1776 SvMemoryStream aMemStream
;
1777 pDialog
->Store( aMemStream
);
1778 sal_Int32 nLen
= aMemStream
.Tell();
1779 if (nLen
< 0) { abort(); }
1780 uno::Sequence
< sal_Int8
> aData( nLen
);
1781 sal_Int8
* pDestData
= aData
.getArray();
1782 const sal_Int8
* pSrcData
= static_cast<const sal_Int8
*>(aMemStream
.GetData());
1783 memcpy( pDestData
, pSrcData
, nLen
);
1787 static SbxObject
* implCreateDialog( const uno::Sequence
< sal_Int8
>& aData
)
1789 sal_Int8
* pData
= const_cast< uno::Sequence
< sal_Int8
>& >(aData
).getArray();
1790 SvMemoryStream
aMemStream( pData
, aData
.getLength(), StreamMode::READ
);
1791 SbxBase
* pBase
= SbxBase::Load( aMemStream
);
1792 return dynamic_cast<SbxObject
*>(pBase
);
1795 // HACK! Because this value is defined in basctl/inc/vcsbxdef.hxx
1796 // which we can't include here, we have to use the value directly
1797 #define SBXID_DIALOG 101
1801 class DialogContainer_Impl
: public NameContainerHelper
1806 explicit DialogContainer_Impl( StarBASIC
* pLib
)
1809 // Methods XElementAccess
1810 virtual uno::Type SAL_CALL
getElementType() override
;
1811 virtual sal_Bool SAL_CALL
hasElements() override
;
1813 // Methods XNameAccess
1814 virtual uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
1815 virtual uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
1816 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
1818 // Methods XNameReplace
1819 virtual void SAL_CALL
replaceByName( const OUString
& aName
, const uno::Any
& aElement
) override
;
1821 // Methods XNameContainer
1822 virtual void SAL_CALL
insertByName( const OUString
& aName
, const uno::Any
& aElement
) override
;
1823 virtual void SAL_CALL
removeByName( const OUString
& Name
) override
;
1828 // Methods XElementAccess
1829 uno::Type
DialogContainer_Impl::getElementType()
1831 uno::Type aModuleType
= cppu::UnoType
<script::XStarBasicDialogInfo
>::get();
1835 sal_Bool
DialogContainer_Impl::hasElements()
1839 sal_Int32 nCount
= mpLib
->GetObjects()->Count32();
1840 for( sal_Int32 nObj
= 0; nObj
< nCount
; nObj
++ )
1842 SbxVariable
* pVar
= mpLib
->GetObjects()->Get32( nObj
);
1843 SbxObject
* pObj
= dynamic_cast<SbxObject
*>(pVar
);
1844 if ( pObj
&& (pObj
->GetSbxId() == SBXID_DIALOG
) )
1853 // Methods XNameAccess
1854 uno::Any
DialogContainer_Impl::getByName( const OUString
& aName
)
1856 SbxVariable
* pVar
= mpLib
->GetObjects()->Find( aName
, SbxClassType::DontCare
);
1857 SbxObject
* pObj
= dynamic_cast<SbxObject
*>(pVar
);
1858 if( !( pObj
&& pObj
->GetSbxId() == SBXID_DIALOG
) )
1860 throw container::NoSuchElementException();
1863 uno::Reference
< script::XStarBasicDialogInfo
> xDialog
=
1864 new DialogInfo_Impl(aName
, implGetDialogData(pObj
));
1867 aRetAny
<<= xDialog
;
1871 uno::Sequence
< OUString
> DialogContainer_Impl::getElementNames()
1873 sal_Int32 nCount
= mpLib
->GetObjects()->Count32();
1874 uno::Sequence
< OUString
> aRetSeq( nCount
);
1875 OUString
* pRetSeq
= aRetSeq
.getArray();
1876 sal_Int32 nDialogCounter
= 0;
1878 for( sal_Int32 nObj
= 0; nObj
< nCount
; nObj
++ )
1880 SbxVariable
* pVar
= mpLib
->GetObjects()->Get32( nObj
);
1881 SbxObject
* pObj
= dynamic_cast<SbxObject
*> (pVar
);
1882 if ( pObj
&& ( pObj
->GetSbxId() == SBXID_DIALOG
) )
1884 pRetSeq
[ nDialogCounter
] = pVar
->GetName();
1888 aRetSeq
.realloc( nDialogCounter
);
1892 sal_Bool
DialogContainer_Impl::hasByName( const OUString
& aName
)
1895 SbxVariable
* pVar
= mpLib
->GetObjects()->Find( aName
, SbxClassType::DontCare
);
1896 SbxObject
* pObj
= dynamic_cast<SbxObject
*>(pVar
);
1897 if( pObj
&& ( pObj
->GetSbxId() == SBXID_DIALOG
) )
1905 // Methods XNameReplace
1906 void DialogContainer_Impl::replaceByName( const OUString
& aName
, const uno::Any
& aElement
)
1908 removeByName( aName
);
1909 insertByName( aName
, aElement
);
1913 // Methods XNameContainer
1914 void DialogContainer_Impl::insertByName( const OUString
&, const uno::Any
& aElement
)
1916 uno::Type aModuleType
= cppu::UnoType
<script::XStarBasicDialogInfo
>::get();
1917 const uno::Type
& aAnyType
= aElement
.getValueType();
1918 if( aModuleType
!= aAnyType
)
1920 throw lang::IllegalArgumentException();
1922 uno::Reference
< script::XStarBasicDialogInfo
> xMod
;
1924 SbxObjectRef xDialog
= implCreateDialog( xMod
->getData() );
1925 mpLib
->Insert( xDialog
.get() );
1928 void DialogContainer_Impl::removeByName( const OUString
& Name
)
1930 SbxVariable
* pVar
= mpLib
->GetObjects()->Find( Name
, SbxClassType::DontCare
);
1931 SbxObject
* pObj
= dynamic_cast<SbxObject
*>(pVar
);
1932 if( !( pObj
&& ( pObj
->GetSbxId() == SBXID_DIALOG
) ) )
1934 throw container::NoSuchElementException();
1936 mpLib
->Remove( pVar
);
1940 class LibraryContainer_Impl
: public NameContainerHelper
1942 BasicManager
* mpMgr
;
1945 explicit LibraryContainer_Impl( BasicManager
* pMgr
)
1948 // Methods XElementAccess
1949 virtual uno::Type SAL_CALL
getElementType() override
;
1950 virtual sal_Bool SAL_CALL
hasElements() override
;
1952 // Methods XNameAccess
1953 virtual uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
1954 virtual uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
1955 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
1957 // Methods XNameReplace
1958 virtual void SAL_CALL
replaceByName( const OUString
& aName
, const uno::Any
& aElement
) override
;
1960 // Methods XNameContainer
1961 virtual void SAL_CALL
insertByName( const OUString
& aName
, const uno::Any
& aElement
) override
;
1962 virtual void SAL_CALL
removeByName( const OUString
& Name
) override
;
1966 // Methods XElementAccess
1967 uno::Type
LibraryContainer_Impl::getElementType()
1969 uno::Type aType
= cppu::UnoType
<script::XStarBasicLibraryInfo
>::get();
1973 sal_Bool
LibraryContainer_Impl::hasElements()
1975 sal_Int32 nLibs
= mpMgr
->GetLibCount();
1976 bool bRet
= (nLibs
> 0);
1980 // Methods XNameAccess
1981 uno::Any
LibraryContainer_Impl::getByName( const OUString
& aName
)
1984 if( !mpMgr
->HasLib( aName
) )
1985 throw container::NoSuchElementException();
1986 StarBASIC
* pLib
= mpMgr
->GetLib( aName
);
1988 uno::Reference
< container::XNameContainer
> xModuleContainer
=
1989 new ModuleContainer_Impl( pLib
);
1991 uno::Reference
< container::XNameContainer
> xDialogContainer
=
1992 new DialogContainer_Impl( pLib
);
1994 BasicLibInfo
* pLibInfo
= mpMgr
->FindLibInfo( pLib
);
1996 OUString aPassword
= pLibInfo
->GetPassword();
1998 // TODO Only provide extern info!
1999 OUString aExternaleSourceURL
;
2000 OUString aLinkTargetURL
;
2001 if( pLibInfo
->IsReference() )
2003 aLinkTargetURL
= pLibInfo
->GetStorageName();
2005 else if( pLibInfo
->IsExtern() )
2007 aExternaleSourceURL
= pLibInfo
->GetStorageName();
2009 uno::Reference
< script::XStarBasicLibraryInfo
> xLibInfo
= new LibraryInfo_Impl
2015 aExternaleSourceURL
,
2019 aRetAny
<<= xLibInfo
;
2023 uno::Sequence
< OUString
> LibraryContainer_Impl::getElementNames()
2025 sal_uInt16 nLibs
= mpMgr
->GetLibCount();
2026 uno::Sequence
< OUString
> aRetSeq( nLibs
);
2027 OUString
* pRetSeq
= aRetSeq
.getArray();
2028 for( sal_uInt16 i
= 0 ; i
< nLibs
; i
++ )
2030 pRetSeq
[i
] = mpMgr
->GetLibName( i
);
2035 sal_Bool
LibraryContainer_Impl::hasByName( const OUString
& aName
)
2037 bool bRet
= mpMgr
->HasLib( aName
);
2041 // Methods XNameReplace
2042 void LibraryContainer_Impl::replaceByName( const OUString
& aName
, const uno::Any
& aElement
)
2044 removeByName( aName
);
2045 insertByName( aName
, aElement
);
2048 // Methods XNameContainer
2049 void LibraryContainer_Impl::insertByName( const OUString
&, const uno::Any
& )
2051 // TODO: Insert a complete Library?!
2054 void LibraryContainer_Impl::removeByName( const OUString
& Name
)
2056 StarBASIC
* pLib
= mpMgr
->GetLib( Name
);
2059 throw container::NoSuchElementException();
2061 sal_uInt16 nLibId
= mpMgr
->GetLibId( Name
);
2062 mpMgr
->RemoveLib( nLibId
);
2066 typedef WeakImplHelper
< script::XStarBasicAccess
> StarBasicAccessHelper
;
2069 class StarBasicAccess_Impl
: public StarBasicAccessHelper
2071 BasicManager
* mpMgr
;
2072 uno::Reference
< container::XNameContainer
> mxLibContainer
;
2075 explicit StarBasicAccess_Impl( BasicManager
* pMgr
)
2080 virtual uno::Reference
< container::XNameContainer
> SAL_CALL
getLibraryContainer() override
;
2081 virtual void SAL_CALL
createLibrary( const OUString
& LibName
, const OUString
& Password
,
2082 const OUString
& ExternalSourceURL
, const OUString
& LinkTargetURL
) override
;
2083 virtual void SAL_CALL
addModule( const OUString
& LibraryName
, const OUString
& ModuleName
,
2084 const OUString
& Language
, const OUString
& Source
) override
;
2085 virtual void SAL_CALL
addDialog( const OUString
& LibraryName
, const OUString
& DialogName
,
2086 const uno::Sequence
< sal_Int8
>& Data
) override
;
2089 uno::Reference
< container::XNameContainer
> SAL_CALL
StarBasicAccess_Impl::getLibraryContainer()
2091 if( !mxLibContainer
.is() )
2092 mxLibContainer
= new LibraryContainer_Impl( mpMgr
);
2093 return mxLibContainer
;
2096 void SAL_CALL
StarBasicAccess_Impl::createLibrary
2098 const OUString
& LibName
,
2099 const OUString
& Password
,
2101 const OUString
& LinkTargetURL
2104 StarBASIC
* pLib
= mpMgr
->CreateLib( LibName
, Password
, LinkTargetURL
);
2105 DBG_ASSERT( pLib
, "XML Import: Basic library could not be created");
2108 void SAL_CALL
StarBasicAccess_Impl::addModule
2110 const OUString
& LibraryName
,
2111 const OUString
& ModuleName
,
2113 const OUString
& Source
2116 StarBASIC
* pLib
= mpMgr
->GetLib( LibraryName
);
2117 DBG_ASSERT( pLib
, "XML Import: Lib for module unknown");
2120 pLib
->MakeModule( ModuleName
, Source
);
2124 void SAL_CALL
StarBasicAccess_Impl::addDialog
2128 const uno::Sequence
< sal_Int8
>&
2132 // Basic XML Import/Export
2133 uno::Reference
< script::XStarBasicAccess
> getStarBasicAccess( BasicManager
* pMgr
)
2135 uno::Reference
< script::XStarBasicAccess
> xRet
=
2136 new StarBasicAccess_Impl( pMgr
);
2140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */