41#include <com/sun/star/script/XLibraryContainer.hpp>
42#include <com/sun/star/script/XPersistentLibraryContainer.hpp>
50#define LIBINFO_SEP 0x02
51#define LIBINFO_ID 0x1491
52#define PASSWORD_MARKER 0x31452134
57#include <com/sun/star/container/XNameContainer.hpp>
58#include <com/sun/star/container/XContainer.hpp>
59#include <com/sun/star/script/XStarBasicAccess.hpp>
60#include <com/sun/star/script/XStarBasicModuleInfo.hpp>
61#include <com/sun/star/script/XStarBasicDialogInfo.hpp>
62#include <com/sun/star/script/XStarBasicLibraryInfo.hpp>
63#include <com/sun/star/script/XLibraryContainerPassword.hpp>
64#include <com/sun/star/script/ModuleInfo.hpp>
65#include <com/sun/star/script/vba/XVBACompatibility.hpp>
66#include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
67#include <com/sun/star/ucb/ContentCreationException.hpp>
118 const uno::Any& aLibAny,
const OUString& aLibName );
120 std::u16string_view aLibName );
124 virtual void SAL_CALL
disposing(
const lang::EventObject& Source )
override;
127 virtual void SAL_CALL
elementInserted(
const container::ContainerEvent& Event )
override;
128 virtual void SAL_CALL
elementReplaced(
const container::ContainerEvent& Event )
override;
129 virtual void SAL_CALL
elementRemoved(
const container::ContainerEvent& Event )
override;
140 aLibAny >>= xLibNameAccess;
142 if( !pMgr->
GetLib( aLibName ) )
146 DBG_ASSERT(
pLib,
"XML Import: Basic library could not be created");
149 uno::Reference< container::XContainer> xLibContainer( xLibNameAccess, uno::UNO_QUERY );
150 if( xLibContainer.is() )
155 xLibContainer->addContainerListener( xLibraryListener );
158 if( xScriptCont->isLibraryLoaded( aLibName ) )
166 const uno::Reference< container::XNameAccess >& xLibNameAccess, std::u16string_view aLibName )
168 uno::Sequence< OUString > aModuleNames = xLibNameAccess->getElementNames();
169 sal_Int32 nModuleCount = aModuleNames.getLength();
172 DBG_ASSERT(
pLib,
"BasMgrContainerListenerImpl::addLibraryModulesImpl: Unknown lib!");
176 const OUString* pNames = aModuleNames.getConstArray();
177 for( sal_Int32 j = 0 ; j < nModuleCount ; j++ )
179 OUString aModuleName = pNames[ j ];
180 uno::Any aElement = xLibNameAccess->getByName( aModuleName );
183 uno::Reference< vba::XVBAModuleInfo > xVBAModuleInfo( xLibNameAccess, uno::UNO_QUERY );
184 if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo( aModuleName ) )
186 ModuleInfo aInfo = xVBAModuleInfo->getModuleInfo( aModuleName );
187 pLib->MakeModule( aModuleName, aInfo, aMod );
190 pLib->MakeModule( aModuleName, aMod );
193 pLib->SetModified(
false );
207 bool bLibContainer =
maLibName.isEmpty();
209 Event.Accessor >>=
aName;
213 uno::Reference< script::XLibraryContainer > xScriptCont( Event.Source, uno::UNO_QUERY );
214 if (xScriptCont.is())
219 uno::Reference< vba::XVBACompatibility > xVBACompat( xScriptCont, uno::UNO_QUERY );
220 if ( xVBACompat.is() )
221 pLib->SetVBAEnabled( xVBACompat->getVBACompatibilityMode() );
228 DBG_ASSERT(
pLib,
"BasMgrContainerListenerImpl::elementInserted: Unknown lib!");
235 Event.Element >>= aMod;
236 uno::Reference< vba::XVBAModuleInfo > xVBAModuleInfo( Event.Source, uno::UNO_QUERY );
237 if ( xVBAModuleInfo.is() && xVBAModuleInfo->hasModuleInfo(
aName ) )
239 ModuleInfo aInfo = xVBAModuleInfo->getModuleInfo(
aName );
244 pLib->SetModified(
false );
254 Event.Accessor >>=
aName;
265 Event.Element >>= aMod;
272 pLib->SetModified(
false );
279 Event.Accessor >>=
aName;
281 bool bLibContainer =
maLibName.isEmpty();
297 pLib->Remove( pMod );
298 pLib->SetModified(
false );
391 rSStream.ReadUInt32( nEndPos );
392 rSStream.ReadUInt16(
nId );
393 rSStream.ReadUInt16( nVer );
400 rSStream.ReadCharAsBool(
bDoLoad );
404 OUString
aName = rSStream.ReadUniOrByteString(rSStream.GetStreamCharSet());
408 OUString
aStorageName = rSStream.ReadUniOrByteString(rSStream.GetStreamCharSet());
412 OUString
aRelStorageName = rSStream.ReadUniOrByteString(rSStream.GetStreamCharSet());
418 rSStream.ReadCharAsBool( bReferenz );
422 rSStream.Seek( nEndPos );
433 OUString aStorName( rStorage.
GetName() );
443 DBG_ASSERT( pStdLib,
"Standard-Lib not loaded?" );
454 rStdLibInfo.
SetLib( pStdLib );
459 xStdLib->SetModified(
false );
466 for ( sal_uInt16 nBasic = 1; nBasic <
GetLibCount(); nBasic++ )
471 pStdLib->
Insert( pBasic );
489 uno::Reference< script::XLibraryContainer > xScriptCont( rInfo.
mxScriptCont );
490 if ( !xScriptCont.is() )
493 OUString aLibName = pBasic->
GetName();
494 if( !xScriptCont->hasByName( aLibName ) )
495 xScriptCont->createLibrary( aLibName );
497 uno::Any aLibAny = xScriptCont->getByName( aLibName );
498 uno::Reference< container::XNameContainer > xLib;
503 for (
const auto& pModule: pBasic->
GetModules() )
505 OUString aModName = pModule->GetName();
506 if( !xLib->hasByName( aModName ) )
508 OUString aSource = pModule->GetSource32();
510 aSourceAny <<= aSource;
511 xLib->insertByName( aModName, aSourceAny );
531 if( xScriptCont.is() )
534 uno::Reference< container::XContainerListener > xLibContainerListener
537 uno::Reference< container::XContainer> xLibContainer( xScriptCont, uno::UNO_QUERY );
538 xLibContainer->addContainerListener( xLibContainerListener );
540 const uno::Sequence< OUString > aScriptLibNames = xScriptCont->getElementNames();
542 if( aScriptLibNames.hasElements() )
544 for(
const auto& rScriptLibName : aScriptLibNames)
546 uno::Any aLibAny = xScriptCont->getByName( rScriptLibName );
548 if ( rScriptLibName ==
"Standard" || rScriptLibName ==
"VBAProject")
549 xScriptCont->loadLibrary( rScriptLibName );
552 ( xScriptCont,
this, aLibAny, rScriptLibName );
558 for (
auto const& rpBasLibInfo :
maLibs)
565 pLib = rpBasLibInfo->GetLib().get();
570 if (rpBasLibInfo->HasPassword())
574 if( pOldBasicPassword )
577 pLib->GetName(), rpBasLibInfo->GetPassword() );
591 DBG_ASSERT( pSLib,
"BasicManager cannot be created with a NULL-Pointer!" );
598 pStdLibInfo->
SetLib( pSLib );
605 xStdLib->SetModified(
false );
622 xStdLib->SetModified(
false );
630 pStdLibInfo->
SetLib( pStdLib );
640 OUString aStorName( rStorage.
GetName() );
643 if ( !xManagerStream.
is() || xManagerStream->GetError() || ( xManagerStream->TellEnd() == 0 ) )
654 if ( !rBaseURL.empty() )
663 xManagerStream->SetBufferSize( 1024 );
667 xManagerStream->ReadUInt32( nEndPos );
670 xManagerStream->ReadUInt16( nLibs );
674 SAL_WARN(
"basic",
"BasicManager-Stream defect!" );
677 const size_t nMinBasicLibSize(8);
678 const size_t nMaxPossibleLibs = xManagerStream->remainingSize() / nMinBasicLibSize;
679 if (nLibs > nMaxPossibleLibs)
681 SAL_WARN(
"basic",
"Parsing error: " << nMaxPossibleLibs <<
682 " max possible entries, but " << nLibs <<
" claimed, truncating");
683 nLibs = nMaxPossibleLibs;
685 for (sal_uInt16 nL = 0; nL < nLibs; ++nL)
695 bool bWasAbsolute =
false;
704 OUString aSearchFileOldFormat(aSearchFile);
713 maLibs.push_back(std::unique_ptr<BasicLibInfo>(pInfo));
723 xManagerStream->Seek( nEndPos );
724 xManagerStream->SetBufferSize( 0 );
725 xManagerStream.
clear();
732 OUString aStorName( rStorage.
GetName() );
733 DBG_ASSERT( aStorName.getLength(),
"No Storage Name!" );
735 if ( !xManagerStream.
is() || xManagerStream->GetError() || ( xManagerStream->TellEnd() == 0 ) )
741 xManagerStream->SetBufferSize( 1024 );
743 sal_uInt32 nBasicStartOff, nBasicEndOff;
744 xManagerStream->ReadUInt32( nBasicStartOff );
745 xManagerStream->ReadUInt32( nBasicEndOff );
747 DBG_ASSERT( !xManagerStream->GetError(),
"Invalid Manager-Stream!" );
749 xManagerStream->Seek( nBasicStartOff );
756 xManagerStream->Seek( nBasicEndOff+1 );
757 OUString aLibs = xManagerStream->ReadUniOrByteString(xManagerStream->GetStreamCharSet());
758 xManagerStream->SetBufferSize( 0 );
759 xManagerStream.
clear();
761 if ( aLibs.isEmpty() )
765 sal_Int32 nLibPos {0};
767 const OUString aLibInfo(aLibs.getToken(0,
LIB_SEP, nLibPos));
768 sal_Int32 nInfoPos {0};
769 const OUString aLibName( aLibInfo.getToken( 0,
LIBINFO_SEP, nInfoPos ) );
770 DBG_ASSERT( nInfoPos >= 0,
"Invalid Lib-Info!" );
771 const OUString aLibAbsStorageName( aLibInfo.getToken( 0,
LIBINFO_SEP, nInfoPos ) );
773 const OUString aLibRelStorageName( aLibInfo.getToken( 0,
LIBINFO_SEP, nInfoPos ) );
774 DBG_ASSERT( nInfoPos < 0,
"Invalid Lib-Info!" );
775 INetURLObject aLibAbsStorage( aLibAbsStorageName, INetProtocol::File );
779 bool bWasAbsolute =
false;
780 aLibRelStorage = aLibRelStorage.
smartRel2Abs( aLibRelStorageName, bWasAbsolute);
781 DBG_ASSERT(!bWasAbsolute,
"RelStorageName was absolute!" );
784 if ( aLibAbsStorage == aCurStorage || aLibRelStorageName ==
szImbedded )
786 xStorageRef = &rStorage;
793 xStorageRef =
new SotStorage(
false, aLibRelStorage.
796 if ( xStorageRef.
is() )
798 AddLib( *xStorageRef, aLibName,
false );
805 }
while (nLibPos>=0);
819 for (
const auto& pModule:
pLib->GetModules())
821 if (pModule->HasExeCode())
830 maLibs.push_back(std::make_unique<BasicLibInfo>());
831 return maLibs.back().get();
840 if ( aStorageName.isEmpty() || aStorageName ==
szImbedded )
848 OUString aStorName( pCurStorage->
GetName() );
851 INetURLObject aCurStorageEntry(aStorName, INetProtocol::File);
854 INetURLObject aStorageEntry(aStorageName, INetProtocol::File);
857 if ( aCurStorageEntry == aStorageEntry )
859 xStorage = pCurStorage;
863 if ( !xStorage.
is() )
869 if ( !xBasicStorage.
is() || xBasicStorage->GetError() )
878 if ( !xBasicStream.
is() || xBasicStream->GetError() )
885 bool bLoaded =
false;
886 if ( xBasicStream->TellEnd() != 0 )
892 xBasicStream->SetBufferSize( 1024 );
895 xBasicStream->SetBufferSize( 0 );
898 xStdLib->SetModified(
false );
910 xBasicStream->RefreshBuffer();
911 sal_uInt32 nPasswordMarker = 0;
912 xBasicStream->ReadUInt32( nPasswordMarker );
915 OUString aPassword = xBasicStream->ReadUniOrByteString(
916 xBasicStream->GetStreamCharSet());
919 xBasicStream->SetCryptMaskKey(OString());
926 catch (
const css::ucb::ContentCreationException&)
938 bool bProtected =
false;
955 bool bLoaded =
false;
958 if(
auto pNew =
dynamic_cast<StarBASIC*
>( xNew.
get() ) )
963 pNew->SetParent( rOldBasic->GetParent() );
964 if( pNew->GetParent() )
966 pNew->GetParent()->Insert( pNew );
975 pNew->SetModified(
false );
992 bool bModified =
pLib->IsModified();
994 for (
const auto& pModule:
pLib->GetModules() )
1005 if( !bModified && bReference )
1007 OSL_FAIL(
"Referenced basic library is not compiled!" );
1008 pLib->SetModified(
false );
1014 OUString aStorName( rStorage.
GetName() );
1015 DBG_ASSERT( !aStorName.isEmpty(),
"No Storage Name!" );
1018 DBG_ASSERT(!aStorageName.isEmpty(),
"Bad storage name");
1020 OUString aNewLibName( rLibName );
1021 while (
HasLib( aNewLibName ) )
1029 sal_uInt16 nLibId =
static_cast<sal_uInt16
>(
maLibs.size()) - 1;
1037 if ( aNewLibName != rLibName )
1043 pLibInfo->
GetLib()->SetModified(
false );
1049 pLibInfo->
GetLib()->SetModified(
true );
1059 return pLibInfo ? &*pLibInfo->
GetLib() :
nullptr;
1066 if ( nLib <
maLibs.size() )
1068 return maLibs[nLib]->IsReference();
1081 DBG_ASSERT( nLib,
"Standard-Lib cannot be removed!" );
1085 if( !nLib || nLib <
maLibs.size() )
1092 auto const itLibInfo =
maLibs.begin() + nLib;
1096 if (bDelBasicFromStorage && !(*itLibInfo)->IsReference() &&
1102 if (!(*itLibInfo)->IsExtern())
1108 xStorage =
new SotStorage(
false, (*itLibInfo)->GetStorageName());
1111 catch (
const css::ucb::ContentCreationException&)
1121 if ( !xBasicStorage.
is() || xBasicStorage->GetError() )
1126 else if (xBasicStorage->IsStream((*itLibInfo)->GetLibName()))
1128 xBasicStorage->Remove((*itLibInfo)->GetLibName());
1129 xBasicStorage->Commit();
1134 xBasicStorage->FillInfoList( &aInfoList );
1135 if ( aInfoList.empty() )
1137 xBasicStorage.
clear();
1143 xStorage->FillInfoList( &aInfoList );
1144 if ( aInfoList.empty() )
1156 if ((*itLibInfo)->GetLib().is())
1166 return static_cast<sal_uInt16
>(
maLibs.size());
1172 if ( nLib <
maLibs.size() )
1174 return maLibs[nLib]->GetLib().get();
1187 for (
auto const& rpLib :
maLibs)
1189 if (rpLib->GetLibName().equalsIgnoreAsciiCase(rName))
1191 return rpLib->GetLib().get();
1199 for (
size_t i = 0;
i <
maLibs.size();
i++)
1203 return static_cast<sal_uInt16
>(
i);
1211 for (
const auto& rpLib :
maLibs)
1213 if (rpLib->GetLibName().equalsIgnoreAsciiCase(rName))
1224 if ( nLib <
maLibs.size() )
1226 return maLibs[nLib]->GetLibName();
1235 if ( nLib <
maLibs.size() )
1238 uno::Reference< script::XLibraryContainer > xLibContainer = rLibInfo.
GetLibraryContainer();
1239 if( xLibContainer.is() )
1242 xLibContainer->loadLibrary( aLibName );
1243 bDone = xLibContainer->isLibraryLoaded( aLibName );
1266 if (
GetLib( rLibName ) )
1274 pLibInfo->
SetLib( pNew );
1276 pLibInfo->
GetLib()->SetName( rLibName );
1282 const OUString& LinkTargetURL )
1288 if( !LinkTargetURL.isEmpty())
1293 if (!xStorage->GetError())
1298 catch (
const css::ucb::ContentCreationException&)
1302 DBG_ASSERT(
pLib,
"XML Import: Linked basic library could not be loaded");
1319 const uno::Reference< script::XLibraryContainer >& xScriptCont )
1321 if (
GetLib( rLibName ) )
1329 pLibInfo->
SetLib( pNew );
1331 pLibInfo->
GetLib()->SetName( rLibName );
1339 for (
auto const& rpLib :
maLibs)
1341 if (rpLib->GetLib().get() == pBasic)
1352 for (
auto const& rpLib :
maLibs)
1354 if (rpLib->GetLib().is() && rpLib->GetLib()->IsModified())
1367 OSL_PRECOND( pStandardLib,
"BasicManager::GetGlobalUNOConstant: no lib to read from!" );
1376 OSL_PRECOND( pStandardLib,
"BasicManager::SetGlobalUNOConstant: no lib to insert into!" );
1377 if ( !pStandardLib )
1388 xUnoObj->SetName(rName);
1400 const uno::Sequence< OUString > aNames( xScripts->getElementNames() );
1401 for (
auto const & scriptElementName : aNames )
1403 if( !xPassword->isLibraryPasswordProtected( scriptElementName ) )
1410 uno::Reference< container::XNameAccess > xScriptLibrary( xScripts->getByName( scriptElementName ), uno::UNO_QUERY_THROW );
1411 const uno::Sequence< OUString > aElementNames( xScriptLibrary->getElementNames() );
1413 std::vector<OUString> aBigModules;
1414 for (
auto const & libraryElementName : aElementNames )
1418 aBigModules.push_back(libraryElementName);
1421 if (!aBigModules.empty())
1423 _out_rModuleNames.swap(aBigModules);
1428 catch(
const uno::Exception& )
1440 sal_Int32 nLast = 0;
1441 const OUString sLibName {i_fullyQualifiedName.getToken( 0,
'.', nLast )};
1442 const OUString sModule {i_fullyQualifiedName.getToken( 0,
'.', nLast )};
1446 sMacro = i_fullyQualifiedName.copy(nLast);
1450 sMacro = i_fullyQualifiedName;
1455 for ( sal_uInt16 nLib = 0; nLib < nLibCount; ++nLib )
1462 bool const bLoaded = i_manager->
LoadLib( nLib );
1471 for (
const auto& pMod:
pLib->GetModules() )
1473 if ( rTransliteration.
isEqual( pMod->GetName(), sModule ) )
1491 return ( lcl_queryMacro(
const_cast< BasicManager*
>(
this ), i_fullyQualifiedName ) !=
nullptr );
1496 SbMethod* pMethod = lcl_queryMacro(
this, i_fullyQualifiedName );
1502 nError = pMethod->
Call( i_retValue );
1511 SbMethod* pMethod = lcl_queryMacro(
this, i_fullyQualifiedName );
1517 OUString sQuotedArgs;
1518 OUStringBuffer sArgs( i_commaSeparatedArgs );
1519 if ( sArgs.getLength()<2 || sArgs[1] ==
'\"')
1522 sQuotedArgs = sArgs.makeStringAndClear();
1527 sArgs.remove( 0, 1 );
1528 sArgs.remove( sArgs.getLength() - 1, 1 );
1530 OUStringBuffer aBuff;
1531 OUString sArgs2 = sArgs.makeStringAndClear();
1534 if (!sArgs2.isEmpty())
1540 aBuff.append( OUString::Concat(
"\"")
1545 aBuff.append(
"," );
1548 aBuff.append(
")" );
1550 sQuotedArgs = aBuff.makeStringAndClear();
1554 OUString sCall =
"["
1560 if ( pRet && ( pRet != pMethod ) )
1562 *i_retValue = *pRet;
1572 OUString maLanguage;
1576 ModuleInfo_Impl( OUString aName, OUString aLanguage, OUString aSource )
1577 :
maName(
std::move(
aName )), maLanguage(
std::move( aLanguage)), maSource(
std::move( aSource )) {}
1580 virtual OUString SAL_CALL getName()
override
1582 virtual OUString SAL_CALL getLanguage()
override
1583 {
return maLanguage; }
1584 virtual OUString SAL_CALL getSource()
override
1585 {
return maSource; }
1589class DialogInfo_Impl :
public WeakImplHelper< script::XStarBasicDialogInfo >
1592 uno::Sequence< sal_Int8 > mData;
1595 DialogInfo_Impl( OUString aName,
const uno::Sequence< sal_Int8 >& Data )
1599 virtual OUString SAL_CALL getName()
override
1601 virtual uno::Sequence< sal_Int8 > SAL_CALL getData()
override
1606class LibraryInfo_Impl :
public WeakImplHelper< script::XStarBasicLibraryInfo >
1609 uno::Reference< container::XNameContainer > mxModuleContainer;
1610 uno::Reference< container::XNameContainer > mxDialogContainer;
1611 OUString maPassword;
1612 OUString maExternaleSourceURL;
1613 OUString maLinkTargetURL;
1619 uno::Reference< container::XNameContainer > xModuleContainer,
1620 uno::Reference< container::XNameContainer > xDialogContainer,
1622 OUString aExternaleSourceURL,
1623 OUString aLinkTargetURL
1626 , mxModuleContainer(
std::move( xModuleContainer ))
1627 , mxDialogContainer(
std::move( xDialogContainer ))
1628 , maPassword(
std::move( aPassword ))
1629 , maExternaleSourceURL(
std::move( aExternaleSourceURL ))
1630 , maLinkTargetURL(
std::move( aLinkTargetURL ))
1634 virtual OUString SAL_CALL getName()
override
1636 virtual uno::Reference< container::XNameContainer > SAL_CALL getModuleContainer()
override
1637 {
return mxModuleContainer; }
1638 virtual uno::Reference< container::XNameContainer > SAL_CALL getDialogContainer()
override
1639 {
return mxDialogContainer; }
1641 {
return maPassword; }
1642 virtual OUString SAL_CALL getExternalSourceURL()
override
1643 {
return maExternaleSourceURL; }
1644 virtual OUString SAL_CALL getLinkTargetURL()
override
1645 {
return maLinkTargetURL; }
1654 explicit ModuleContainer_Impl(
StarBASIC* pLib )
1658 virtual uno::Type SAL_CALL getElementType()
override;
1659 virtual sal_Bool SAL_CALL hasElements()
override;
1662 virtual uno::Any SAL_CALL getByName(
const OUString& aName )
override;
1663 virtual uno::Sequence< OUString > SAL_CALL getElementNames()
override;
1664 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override;
1667 virtual void SAL_CALL replaceByName(
const OUString& aName,
const uno::Any& aElement )
override;
1670 virtual void SAL_CALL insertByName(
const OUString& aName,
const uno::Any& aElement )
override;
1671 virtual void SAL_CALL removeByName(
const OUString& Name )
override;
1677uno::Type ModuleContainer_Impl::getElementType()
1683sal_Bool ModuleContainer_Impl::hasElements()
1685 return mpLib && !mpLib->GetModules().empty();
1689uno::Any ModuleContainer_Impl::getByName(
const OUString& aName )
1691 SbModule* pMod = mpLib ? mpLib->FindModule( aName ) :
nullptr;
1693 throw container::NoSuchElementException();
1694 uno::Reference< script::XStarBasicModuleInfo > xMod =
new ModuleInfo_Impl( aName,
"StarBasic", pMod->
GetSource32() );
1700uno::Sequence< OUString > ModuleContainer_Impl::getElementNames()
1702 sal_uInt16 nMods = mpLib ? mpLib->GetModules().size() : 0;
1703 uno::Sequence< OUString > aRetSeq( nMods );
1704 OUString* pRetSeq = aRetSeq.getArray();
1705 for( sal_uInt16 i = 0 ;
i < nMods ;
i++ )
1707 pRetSeq[
i] = mpLib->GetModules()[
i]->GetName();
1712sal_Bool ModuleContainer_Impl::hasByName(
const OUString& aName )
1714 SbModule* pMod = mpLib ? mpLib->FindModule( aName ) :
nullptr;
1715 bool bRet = (pMod !=
nullptr);
1721void ModuleContainer_Impl::replaceByName(
const OUString& aName,
const uno::Any& aElement )
1723 removeByName( aName );
1724 insertByName( aName, aElement );
1729void ModuleContainer_Impl::insertByName(
const OUString& aName,
const uno::Any& aElement )
1732 const uno::Type& aAnyType = aElement.getValueType();
1733 if( aModuleType != aAnyType )
1735 throw lang::IllegalArgumentException(
"types do not match", getXWeak(), 2);
1737 uno::Reference< script::XStarBasicModuleInfo > xMod;
1739 mpLib->MakeModule( aName, xMod->getSource() );
1742void ModuleContainer_Impl::removeByName(
const OUString& Name )
1744 SbModule* pMod = mpLib ? mpLib->FindModule( Name ) :
nullptr;
1747 throw container::NoSuchElementException();
1749 mpLib->Remove( pMod );
1756 pDialog->
Store( aMemStream );
1757 sal_Int32 nLen = aMemStream.
Tell();
1758 if (nLen < 0) { abort(); }
1759 uno::Sequence< sal_Int8 >
aData( nLen );
1762 memcpy( pDestData, pSrcData, nLen );
1776#define SBXID_DIALOG 101
1789 virtual uno::Type SAL_CALL getElementType()
override;
1790 virtual sal_Bool SAL_CALL hasElements()
override;
1793 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override;
1794 virtual uno::Sequence< OUString > SAL_CALL getElementNames()
override;
1795 virtual sal_Bool SAL_CALL hasByName(
const OUString&
aName )
override;
1798 virtual void SAL_CALL replaceByName(
const OUString&
aName,
const uno::Any& aElement )
override;
1801 virtual void SAL_CALL insertByName(
const OUString&
aName,
const uno::Any& aElement )
override;
1802 virtual void SAL_CALL removeByName(
const OUString&
Name )
override;
1808uno::Type DialogContainer_Impl::getElementType()
1814sal_Bool DialogContainer_Impl::hasElements()
1818 sal_Int32
nCount = mpLib->GetObjects()->Count();
1819 for( sal_Int32 nObj = 0; nObj <
nCount ; nObj++ )
1833uno::Any DialogContainer_Impl::getByName(
const OUString& aName )
1839 throw container::NoSuchElementException();
1842 uno::Reference< script::XStarBasicDialogInfo > xDialog =
1846 aRetAny <<= xDialog;
1850uno::Sequence< OUString > DialogContainer_Impl::getElementNames()
1852 sal_Int32
nCount = mpLib->GetObjects()->Count();
1853 uno::Sequence< OUString > aRetSeq( nCount );
1854 OUString* pRetSeq = aRetSeq.getArray();
1855 sal_Int32 nDialogCounter = 0;
1857 for( sal_Int32 nObj = 0; nObj <
nCount ; nObj++ )
1863 pRetSeq[ nDialogCounter ] = pVar->
GetName();
1867 aRetSeq.realloc( nDialogCounter );
1871sal_Bool DialogContainer_Impl::hasByName(
const OUString& aName )
1885void DialogContainer_Impl::replaceByName(
const OUString& aName,
const uno::Any& aElement )
1887 removeByName( aName );
1888 insertByName( aName, aElement );
1893void DialogContainer_Impl::insertByName(
const OUString&,
const uno::Any& aElement )
1896 const uno::Type& aAnyType = aElement.getValueType();
1897 if( aModuleType != aAnyType )
1899 throw lang::IllegalArgumentException(
"types do not match", getXWeak(), 2);
1901 uno::Reference< script::XStarBasicDialogInfo > xMod;
1904 mpLib->Insert( xDialog.
get() );
1907void DialogContainer_Impl::removeByName(
const OUString& Name )
1913 throw container::NoSuchElementException();
1915 mpLib->Remove( pVar );
1933 virtual uno::Sequence< OUString > SAL_CALL
getElementNames()
override;
1940 virtual void SAL_CALL
insertByName(
const OUString& aName,
const uno::Any& aElement )
override;
1941 virtual void SAL_CALL
removeByName(
const OUString& Name )
override;
1955 bool bRet = (nLibs > 0);
1964 throw container::NoSuchElementException();
1967 uno::Reference< container::XNameContainer > xModuleContainer =
1968 new ModuleContainer_Impl(
pLib );
1970 uno::Reference< container::XNameContainer > xDialogContainer =
1971 new DialogContainer_Impl(
pLib );
1978 OUString aExternaleSourceURL;
1979 OUString aLinkTargetURL;
1988 uno::Reference< script::XStarBasicLibraryInfo > xLibInfo =
new LibraryInfo_Impl
1994 aExternaleSourceURL,
1998 aRetAny <<= xLibInfo;
2005 uno::Sequence< OUString > aRetSeq( nLibs );
2006 OUString* pRetSeq = aRetSeq.getArray();
2007 for( sal_uInt16
i = 0 ;
i < nLibs ;
i++ )
2038 throw container::NoSuchElementException();
2059 virtual uno::Reference< container::XNameContainer > SAL_CALL
getLibraryContainer()
override;
2060 virtual void SAL_CALL
createLibrary(
const OUString& LibName,
const OUString& Password,
2061 const OUString& ExternalSourceURL,
const OUString& LinkTargetURL )
override;
2062 virtual void SAL_CALL
addModule(
const OUString& LibraryName,
const OUString& ModuleName,
2063 const OUString& Language,
const OUString& Source )
override;
2064 virtual void SAL_CALL
addDialog(
const OUString& LibraryName,
const OUString& DialogName,
2065 const uno::Sequence< sal_Int8 >& Data )
override;
2077 const OUString& LibName,
2078 const OUString& Password,
2080 const OUString& LinkTargetURL
2084 DBG_ASSERT(
pLib,
"XML Import: Basic library could not be created");
2089 const OUString& LibraryName,
2090 const OUString& ModuleName,
2092 const OUString& Source
2107 const uno::Sequence< sal_Int8 >&
2114 uno::Reference< script::XStarBasicAccess > xRet =
constexpr OUStringLiteral szBasicStorage
WeakImplHelper< script::XStarBasicAccess > StarBasicAccessHelper
const StreamMode eStreamReadMode
constexpr OStringLiteral szCryptingKey
uno::Reference< script::XStarBasicAccess > getStarBasicAccess(BasicManager *pMgr)
WeakImplHelper< script::XStarBasicModuleInfo > ModuleInfoHelper
WeakImplHelper< container::XNameContainer > NameContainerHelper
static void copyToLibraryContainer(StarBASIC *pBasic, const LibraryContainerInfo &rInfo)
constexpr OUStringLiteral szStdLibName
const StreamMode eStorageReadMode
constexpr OUStringLiteral szManagerStream
constexpr OUStringLiteral szOldManagerStream
::cppu::WeakImplHelper< container::XContainerListener > ContainerListenerHelper
constexpr OUStringLiteral szImbedded
static SbxObjectRef implCreateDialog(const uno::Sequence< sal_Int8 > &aData)
static uno::Sequence< sal_Int8 > implGetDialogData(SbxObject *pDialog)
virtual void SAL_CALL elementRemoved(const container::ContainerEvent &Event) override
static void addLibraryModulesImpl(BasicManager const *pMgr, const uno::Reference< container::XNameAccess > &xLibNameAccess, std::u16string_view aLibName)
virtual void SAL_CALL elementInserted(const container::ContainerEvent &Event) override
virtual void SAL_CALL elementReplaced(const container::ContainerEvent &Event) override
BasMgrContainerListenerImpl(BasicManager *pMgr, OUString aLibName)
virtual void SAL_CALL disposing(const lang::EventObject &Source) override
static void insertLibraryImpl(const uno::Reference< script::XLibraryContainer > &xScriptCont, BasicManager *pMgr, const uno::Any &aLibAny, const OUString &aLibName)
BasicError(const BasicError &rErr)
StarBASICRef GetLib() const
void SetLibraryContainer(const uno::Reference< script::XLibraryContainer > &xScriptCont)
void SetLib(StarBASIC *pBasic)
void SetStorageName(const OUString &rName)
static BasicLibInfo * Create(SotStorageStream &rSStream)
const uno::Reference< script::XLibraryContainer > & GetLibraryContainer() const
void SetReference(bool b)
uno::Reference< script::XLibraryContainer > mxScriptCont
const OUString & GetStorageName() const
void SetPassword(const OUString &rNewPassword)
const OUString & GetRelStorageName() const
const OUString & GetLibName() const
void SetLibName(const OUString &rName)
void SetRelStorageName(const OUString &rN)
const OUString & GetPassword() const
StarBASICRef & GetLibRef()
BASIC_DLLPRIVATE StarBASIC * AddLib(SotStorage &rStorage, const OUString &rLibName, bool bReference)
StarBASIC * GetLib(sal_uInt16 nLib) const
const OUString & GetStorageName() const
void SetLibraryContainerInfo(const LibraryContainerInfo &rInfo)
announces the library containers which belong to this BasicManager
bool ImplLoadBasic(SvStream &rStrm, StarBASICRef &rOldBasic) const
bool ImpLoadLibrary(BasicLibInfo *pLibInfo, SotStorage *pCurStorage)
OUString GetLibName(sal_uInt16 nLib)
bool HasMacro(OUString const &i_fullyQualifiedName) const
determines whether the Basic Manager has a given macro, given by fully qualified name
ErrCode ExecuteMacro(OUString const &i_fullyQualifiedName, SbxArray *i_arguments, SbxValue *i_retValue)
executes a given macro
bool HasExeCode(std::u16string_view)
const css::uno::Reference< css::script::XPersistentLibraryContainer > & GetScriptLibraryContainer() const
BASIC_DLLPRIVATE bool HasLib(std::u16string_view rName) const
BASIC_DLLPRIVATE StarBASIC * CreateLibForLibContainer(const OUString &rLibName, const css::uno::Reference< css::script::XLibraryContainer > &xScriptCont)
void LoadOldBasicManager(SotStorage &rStorage)
virtual ~BasicManager() override
BASIC_DLLPRIVATE bool IsReference(sal_uInt16 nLib)
void ImpCreateStdLib(StarBASIC *pParentFromStdLib)
void SetGlobalUNOConstant(const OUString &rName, const css::uno::Any &_rValue, css::uno::Any *pOldValue=nullptr)
sets a global constant in the basic library, referring to some UNO object, to a new value.
bool IsBasicModified() const
LibraryContainerInfo maContainerInfo
BasicLibInfo * FindLibInfo(StarBASIC const *pBasic)
std::vector< BasicError > aErrors
const css::uno::Reference< css::script::XPersistentLibraryContainer > & GetDialogLibraryContainer() const
BasicManager(SotStorage &rStorage, std::u16string_view rBaseURL, StarBASIC *pParentFromStdLib=nullptr, OUString const *pLibPath=nullptr, bool bDocMgr=false)
static void CheckModules(StarBASIC *pBasic, bool bReference)
sal_uInt16 GetLibCount() const
bool RemoveLib(sal_uInt16 nLib, bool bDelBasicFromStorage)
void LoadBasicManager(SotStorage &rStorage, std::u16string_view rBaseURL)
bool GetGlobalUNOConstant(const OUString &rName, css::uno::Any &aOut)
retrieves a global constant in the basic library, referring to some UNO object, returns true if a val...
bool ImgVersion12PsswdBinaryLimitExceeded(std::vector< OUString > &_out_rModuleNames)
determines whether there are password-protected modules whose size exceeds the B_IMG_VERSION_12 modul...
bool LoadLib(sal_uInt16 nLib)
BASIC_DLLPRIVATE StarBASIC * CreateLib(const OUString &rLibName)
std::vector< std::unique_ptr< BasicLibInfo > > maLibs
sal_uInt16 GetLibId(std::u16string_view rName) const
BASIC_DLLPRIVATE StarBASIC * GetStdLib() const
static bool ImplEncryptStream(SvStream &rStream)
BasicLibInfo * CreateLibInfo()
friend class BasMgrContainerListenerImpl
void ImpMgrNotLoaded(const OUString &rStorageName)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetURLObject smartRel2Abs(OUString const &rTheRelURIRef, bool &rWasAbsolute, bool bIgnoreFragment=false, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, bool bRelativeNonURIs=false, FSysStyle eStyle=FSysStyle::Detect) const
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
OUString PathToFileName() const
INetProtocol GetProtocol() const
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual sal_Bool SAL_CALL hasElements() override
virtual void SAL_CALL insertByName(const OUString &aName, const uno::Any &aElement) override
virtual uno::Any SAL_CALL getByName(const OUString &aName) override
virtual void SAL_CALL replaceByName(const OUString &aName, const uno::Any &aElement) override
virtual void SAL_CALL removeByName(const OUString &Name) override
LibraryContainer_Impl(BasicManager *pMgr)
virtual uno::Type SAL_CALL getElementType() override
virtual uno::Sequence< OUString > SAL_CALL getElementNames() override
static utl::TransliterationWrapper & GetTransliteration()
ErrCode Call(SbxValue *pRet, SbxVariable *pCaller=nullptr)
SAL_DLLPRIVATE bool ExceedsImgVersion12ModuleSize()
const OUString & GetSource32() const
void SetSource32(const OUString &r)
static ErrCode const & GetError()
void SetFlag(SbxFlagBits n)
virtual sal_uInt16 GetSbxId() const =0
std::pair< bool, sal_uInt32 > Store(SvStream &)
static SbxBaseRef Load(SvStream &)
SbxVariable * Execute(const OUString &)
bool Get(SbxValues &) const
const SbxObject * GetParent() const
void SetName(const OUString &)
void SetParameters(SbxArray *p)
const OUString & GetName(SbxNameType=SbxNameType::NONE) const
virtual void SetParent(SbxObject *)
void Broadcast(const SfxHint &rHint)
bool IsStream(const OUString &rEleName) const
const OUString & GetName() const
tools::SvRef< SotStorageStream > OpenSotStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE)
static bool IsStorageFile(OUString const &rFileName)
virtual SbxVariable * Find(const OUString &, SbxClassType) override
bool GetUNOConstant(const OUString &rName, css::uno::Any &aOut)
static ErrCode const & GetErrorCode()
SbModule * FindModule(std::u16string_view)
virtual void Remove(SbxVariable *) override
virtual void Insert(SbxVariable *) override
virtual void SetModified(bool) override
virtual uno::Reference< container::XNameContainer > SAL_CALL getLibraryContainer() override
StarBasicAccess_Impl(BasicManager *pMgr)
virtual void SAL_CALL createLibrary(const OUString &LibName, const OUString &Password, const OUString &ExternalSourceURL, const OUString &LinkTargetURL) override
virtual void SAL_CALL addModule(const OUString &LibraryName, const OUString &ModuleName, const OUString &Language, const OUString &Source) override
virtual void SAL_CALL addDialog(const OUString &LibraryName, const OUString &DialogName, const uno::Sequence< sal_Int8 > &Data) override
uno::Reference< container::XNameContainer > mxLibContainer
void SetCryptMaskKey(const OString &rCryptMaskKey)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
sal_uInt64 Seek(sal_uInt64 nPos)
bool SearchFile(OUString &rIniFile, Paths ePath=Paths::UserConfig)
void setLibraryPassword(const OUString &rLibraryName, const OUString &rPassword)
css::uno::Type const & get()
bool isEqual(const OUString &rStr1, const OUString &rStr2) const
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
::cppu::WeakImplHelper< css::container::XContainerListener > ContainerListenerHelper
std::unique_ptr< sal_Int32[]> pData
constexpr OUStringLiteral aData
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
bool getPassword(const css::uno::Reference< css::task::XInteractionHandler > &xHandler, OUString &rOutPwd, bool bFirstTry, const OUString &rDocName)
#define ERRCODE_BASIC_PROC_UNDEFINED
#define ERRCODE_BASMGR_REMOVELIB
#define ERRCODE_BASMGR_LIBLOAD
#define ERRCODE_BASMGR_MGROPEN
tools::SvRef< StarBASIC > StarBASICRef
SbxObjectRef GetSbUnoObject(const OUString &aName, const Any &aUnoObj_)
Any sbxToUnoValue(const SbxValue *pVar)
std::vector< SvStorageInfo > SvStorageInfoList
#define STREAM_SEEK_TO_BEGIN
css::uno::Reference< css::script::XPersistentLibraryContainer > mxDialogCont
basic::SfxScriptLibraryContainer * mpOldBasicPassword
css::uno::Reference< css::script::XPersistentLibraryContainer > mxScriptCont