[Libreoffice-commits] .: Branch 'feature/submodules' - 84 commits - bf_basic/source bf_basic/util bf_forms/source bf_forms/util bf_goodies/source bf_goodies/util bf_offmgr/source bf_offmgr/util bf_sch/source bf_sch/util bf_sc/source bf_sc/util bf_sd/source bf_sd/util bf_sfx2/source bf_sfx2/util bf_so3/inc bf_so3/source bf_so3/src bf_so3/util bf_starmath/source bf_starmath/util bf_svtools/source bf_svtools/util bf_svx/source bf_svx/util bf_sw/source bf_sw/util bf_xmloff/source bf_xmloff/util binfilter/bf_basic binfilter/bf_forms binfilter/bf_goodies binfilter/bf_offmgr binfilter/bf_sc binfilter/bf_sch binfilter/bf_sd binfilter/bf_sfx2 binfilter/bf_so3 binfilter/bf_starmath binfilter/bf_svtools binfilter/bf_svx binfilter/bf_sw binfilter/bf_xmloff binfilter/binfilterdetect binfilterdetect/source binfilter/filter binfilter/inc binfilter/legacysmgr binfilter/no_localization binfilter/prj binfilter/qa binfilter/README binfilter/util filter/source .gitignore inc/bf_basic inc/bf_goodies inc/bf_of fmgr inc/bf_sc inc/bf_sch inc/bf_sd inc/bf_sfx2 inc/bf_so3 inc/bf_starmath inc/bf_svtools inc/bf_svx inc/bf_sw inc/bf_tools inc/bf_xmloff inc/legacysmgr legacysmgr/source no_localization prj/build.lst prj/d.lst prj/dmake prj/l10n qa/cppunit README util/makefile.mk

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Oct 2 16:21:58 PDT 2012


Rebased ref, commits from common ancestor:
commit 6501eb7a7f6ab7dba2223a5b8a721290ef1be627
Author: Norbert Thiebaud <nthiebaud at gmail.com>
Date:   Tue Sep 25 08:05:24 2012 -0500

    ignore the right build-dir... now one level up

diff --git a/.gitignore b/.gitignore
index 0613205..0adb1e8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,28 +36,28 @@
 .stgit-edit.txt
 
 # Build directories:
-/binfilter/unxlng??
-/binfilter/unxlng??.pro
-/binfilter/unxlng???
-/binfilter/unxlng???.pro
-/binfilter/wntmsc???
-/binfilter/wntmsc???.pro
-/binfilter/wntgcc?
-/binfilter/wntgcc?.pro
-/binfilter/unxmac??
-/binfilter/unxmac??.pro
-/binfilter/unx?bsd??
-/binfilter/unx?bsd??.pro
-/binfilter/unxdfly??
-/binfilter/unxdfly??.pro
-/binfilter/unxso???
-/binfilter/unxso???.pro
-/binfilter/unxaig??
-/binfilter/unxaig??.pro
-/binfilter/unxios?
-/binfilter/unxios?.pro
-/binfilter/unxand?
-/binfilter/unxand?.pro
+/unxlng??
+/unxlng??.pro
+/unxlng???
+/unxlng???.pro
+/wntmsc???
+/wntmsc???.pro
+/wntgcc?
+/wntgcc?.pro
+/unxmac??
+/unxmac??.pro
+/unx?bsd??
+/unx?bsd??.pro
+/unxdfly??
+/unxdfly??.pro
+/unxso???
+/unxso???.pro
+/unxaig??
+/unxaig??.pro
+/unxios?
+/unxios?.pro
+/unxand?
+/unxand?.pro
 
 # libxslt debug memdump
 .memdump
commit b7c73dcb1abdd254c76cab0c0e8adcddf4e67f57
Author: Norbert Thiebaud <nthiebaud at gmail.com>
Date:   Sat Sep 1 09:49:15 2012 -0500

    move binfilter structure one directory up
    
    Change-Id: I0d6772e8b1206f8bfdb43122a47958fecf586a40

diff --git a/README b/README
new file mode 100644
index 0000000..1c2da8d
--- /dev/null
+++ b/README
@@ -0,0 +1,10 @@
+Obsolete legacy binary filters
+
+This module contains (substantially) a cut/paste job of the entire
+code-base from an ancient time. This was done to facilitate internal
+re-factoring, by allowing the old code structure (as codified in the
+legacy binary file formats) to remain the same.
+
+The basic idea is that this code runs and spits out big chunks of XML
+which are then imported by the more modern code-base, thus providing
+legacy filter support to LibreOffice.
\ No newline at end of file
diff --git a/bf_basic/source/basmgr/basmgr.cxx b/bf_basic/source/basmgr/basmgr.cxx
new file mode 100644
index 0000000..b7372a4
--- /dev/null
+++ b/bf_basic/source/basmgr/basmgr.cxx
@@ -0,0 +1,2241 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <tools/stream.hxx>
+#include <sot/storage.hxx>
+#include <tools/urlobj.hxx>
+#include <bf_svtools/smplhint.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/window.hxx>
+#include <vcl/wrkwin.hxx>
+#include <vcl/msgbox.hxx>
+#include <sbx.hxx>
+#include <sot/storinfo.hxx>
+#include <bf_svtools/pathoptions.hxx>
+#include <tools/debug.hxx>
+#include <bf_tools/list.hxx>
+
+#include <sbmod.hxx>
+
+#include "basmgr.hxx"
+#include "sbintern.hxx"
+
+#define LIB_SEP         0x01
+#define LIBINFO_SEP     0x02
+#define LIBINFO_ID      0x1491
+#define PASSWORD_MARKER 0x31452134
+
+
+// Library API, implemented for XML import/export
+
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/container/XContainer.hpp>
+#include <com/sun/star/script/XStarBasicAccess.hpp>
+#include <com/sun/star/script/XStarBasicModuleInfo.hpp>
+#include <com/sun/star/script/XStarBasicDialogInfo.hpp>
+#include <com/sun/star/script/XStarBasicLibraryInfo.hpp>
+
+#include <cppuhelper/implbase1.hxx>
+#include <vector>
+
+namespace binfilter {
+
+using namespace com::sun::star::container;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::script;
+using namespace cppu;
+using ::std::vector;
+using ::std::advance;
+
+using ::rtl::OUString;
+
+typedef WeakImplHelper1< XNameContainer > NameContainerHelper;
+typedef WeakImplHelper1< XStarBasicModuleInfo > ModuleInfoHelper;
+typedef WeakImplHelper1< XStarBasicDialogInfo > DialogInfoHelper;
+typedef WeakImplHelper1< XStarBasicLibraryInfo > LibraryInfoHelper;
+typedef WeakImplHelper1< XStarBasicAccess > StarBasicAccessHelper;
+
+
+#define CURR_VER        2
+
+// Version 1
+//    ULONG     nEndPos
+//    USHORT    nId
+//    USHORT    nVer
+//    BOOL      bDoLoad
+//    String    LibName
+//    String    AbsStorageName
+//    String    RelStorageName
+// Version 2
+//  + BOOL      bReference
+
+static const char szStdLibName[] = "Standard";
+static const char szBasicStorage[] = "StarBASIC";
+static const char szOldManagerStream[] = "BasicManager";
+static const char szManagerStream[] = "BasicManager2";
+static const char szImbedded[] = "LIBIMBEDDED";
+static const char szCryptingKey[] = "CryptedBasic";
+static const char szScriptLanguage[] = "StarBasic";
+
+static const String BasicStreamName( RTL_CONSTASCII_USTRINGPARAM(szBasicStorage) );
+static const String ManagerStreamName( RTL_CONSTASCII_USTRINGPARAM(szManagerStream) );
+
+#define DEFINE_CONST_UNICODE(CONSTASCII)    UniString(RTL_CONSTASCII_USTRINGPARAM(CONSTASCII))
+
+
+TYPEINIT1( BasicManager, SfxBroadcaster );
+DBG_NAME( BasicManager );
+
+StreamMode eStreamReadMode = STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYALL;
+StreamMode eStorageReadMode = STREAM_READ | STREAM_SHARE_DENYWRITE;
+
+typedef vector< BasicError* > BasErrorLst;
+
+//----------------------------------------------------------------------------
+// BasicManager impl data
+struct BasicManagerImpl
+{
+    LibraryContainerInfo* mpInfo;
+
+    // Save stream data
+    SvMemoryStream*  mpManagerStream;
+    SvMemoryStream** mppLibStreams;
+    sal_Int32        mnLibStreamCount;
+    sal_Bool         mbModifiedByLibraryContainer;
+    sal_Bool         mbError;
+
+    BasicManagerImpl( void )
+        : mpInfo( NULL )
+        , mpManagerStream( NULL )
+        , mppLibStreams( NULL )
+        , mnLibStreamCount( 0 )
+        , mbModifiedByLibraryContainer( sal_False )
+        , mbError( sal_False )
+    {}
+    ~BasicManagerImpl();
+};
+
+BasicManagerImpl::~BasicManagerImpl()
+{
+    delete mpInfo;
+    delete mpManagerStream;
+    if( mppLibStreams )
+    {
+        for( sal_Int32 i = 0 ; i < mnLibStreamCount ; i++ )
+            delete mppLibStreams[i];
+        delete[] mppLibStreams;
+    }
+}
+
+//============================================================================
+// BasMgrContainerListenerImpl
+//============================================================================
+
+typedef ::cppu::WeakImplHelper1< ::com::sun::star::container::XContainerListener > ContainerListenerHelper;
+
+class BasMgrContainerListenerImpl: public ContainerListenerHelper
+{
+    BasicManager* mpMgr;
+    OUString maLibName;     // empty -> no lib, but lib container
+
+public:
+    BasMgrContainerListenerImpl( BasicManager* pMgr, OUString aLibName )
+        : mpMgr( pMgr )
+        , maLibName( aLibName ) {}
+
+    static void insertLibraryImpl( const Reference< XLibraryContainer >& xScriptCont, BasicManager* pMgr,
+        Any aLibAny, OUString aLibName );
+    static void addLibraryModulesImpl( BasicManager* pMgr, Reference< XNameAccess > xLibNameAccess,
+        OUString aLibName );
+
+
+    // XEventListener
+    virtual void SAL_CALL disposing( const  ::com::sun::star::lang::EventObject& Source )
+        throw(::com::sun::star::uno::RuntimeException);
+
+    // XContainerListener
+    virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event )
+        throw(::com::sun::star::uno::RuntimeException);
+    virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event )
+        throw(::com::sun::star::uno::RuntimeException);
+    virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event )
+        throw(::com::sun::star::uno::RuntimeException);
+};
+
+
+//============================================================================
+// BasMgrContainerListenerImpl
+//============================================================================
+
+void BasMgrContainerListenerImpl::insertLibraryImpl( const Reference< XLibraryContainer >& xScriptCont,
+    BasicManager* pMgr, Any aLibAny, OUString aLibName )
+{
+    Reference< XNameAccess > xLibNameAccess;
+    aLibAny >>= xLibNameAccess;
+
+    if( !pMgr->GetLib( aLibName ) )
+    {
+        BasicManager* pBasMgr = static_cast< BasicManager* >( pMgr );
+#ifdef DBG_UTIL
+        StarBASIC* pLib =
+#endif
+        pBasMgr->CreateLibForLibContainer( aLibName, xScriptCont );
+        DBG_ASSERT( pLib, "XML Import: Basic library could not be created");
+    }
+
+    Reference< XContainer> xLibContainer( xLibNameAccess, UNO_QUERY );
+    if( xLibContainer.is() )
+    {
+        // Register listener for library
+        Reference< XContainerListener > xLibraryListener
+            = static_cast< XContainerListener* >
+                ( new BasMgrContainerListenerImpl( pMgr, aLibName ) );
+        xLibContainer->addContainerListener( xLibraryListener );
+    }
+
+    if( xScriptCont->isLibraryLoaded( aLibName ) )
+    {
+        addLibraryModulesImpl( pMgr, xLibNameAccess, aLibName );
+    }
+}
+
+
+void BasMgrContainerListenerImpl::addLibraryModulesImpl( BasicManager* pMgr,
+    Reference< XNameAccess > xLibNameAccess, OUString aLibName )
+{
+    OUString aScriptLanguage = DEFINE_CONST_UNICODE( szScriptLanguage );
+    Sequence< OUString > aModuleNames = xLibNameAccess->getElementNames();
+    sal_Int32 nModuleCount = aModuleNames.getLength();
+
+    StarBASIC* pLib = pMgr->GetLib( aLibName );
+    DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::addLibraryModulesImpl: Unknown lib!");
+    if( pLib )
+    {
+        const OUString* pNames = aModuleNames.getConstArray();
+        for( sal_Int32 j = 0 ; j < nModuleCount ; j++ )
+        {
+            OUString aModuleName = pNames[ j ];
+            Any aElement = xLibNameAccess->getByName( aModuleName );
+            OUString aMod;
+            aElement >>= aMod;
+            pLib->MakeModule32( aModuleName, aMod );
+        }
+    }
+
+    pLib->SetModified( FALSE );
+}
+
+
+
+// XEventListener
+//----------------------------------------------------------------------------
+
+void SAL_CALL BasMgrContainerListenerImpl::disposing( const  EventObject& Source )
+    throw( RuntimeException )
+{
+    (void)Source;
+}
+
+// XContainerListener
+//----------------------------------------------------------------------------
+
+void SAL_CALL BasMgrContainerListenerImpl::elementInserted( const ContainerEvent& Event )
+    throw( RuntimeException )
+{
+    sal_Bool bLibContainer = ( maLibName.getLength() == 0 );
+    OUString aName;
+    Event.Accessor >>= aName;
+
+    mpMgr->mpImpl->mbModifiedByLibraryContainer = sal_True;
+
+    if( bLibContainer )
+    {
+        Reference< XLibraryContainer > xScriptCont( Event.Source, UNO_QUERY );
+        insertLibraryImpl( xScriptCont, mpMgr, Event.Element, aName );
+    }
+    else
+    {
+        OUString aScriptLanguage = DEFINE_CONST_UNICODE( szScriptLanguage );
+        OUString aMod;
+        Event.Element >>= aMod;
+
+        StarBASIC* pLib = mpMgr->GetLib( maLibName );
+        DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::elementInserted: Unknown lib!");
+        if( pLib )
+        {
+            SbModule* pMod = pLib->FindModule( aName );
+            if( !pMod )
+            {
+                pLib->MakeModule32( aName, aMod );
+                pLib->SetModified( FALSE );
+            }
+        }
+    }
+}
+
+//----------------------------------------------------------------------------
+
+void SAL_CALL BasMgrContainerListenerImpl::elementReplaced( const ContainerEvent& Event )
+    throw( RuntimeException )
+{
+    OUString aName;
+    Event.Accessor >>= aName;
+
+    mpMgr->mpImpl->mbModifiedByLibraryContainer = sal_True;
+
+    // Replace not possible for library container
+#ifdef DBG_UTIL
+    sal_Bool bLibContainer = ( maLibName.getLength() == 0 );
+#endif
+    DBG_ASSERT( !bLibContainer, "library container fired elementReplaced()");
+
+    StarBASIC* pLib = mpMgr->GetLib( maLibName );
+    if( pLib )
+    {
+        SbModule* pMod = pLib->FindModule( aName );
+        OUString aMod;
+        Event.Element >>= aMod;
+        if( pMod )
+            pMod->SetSource32( aMod );
+        else
+            pLib->MakeModule32( aName, aMod );
+
+        pLib->SetModified( FALSE );
+    }
+}
+
+//----------------------------------------------------------------------------
+
+void SAL_CALL BasMgrContainerListenerImpl::elementRemoved( const ContainerEvent& Event )
+    throw( RuntimeException )
+{
+    OUString aName;
+    Event.Accessor >>= aName;
+
+    mpMgr->mpImpl->mbModifiedByLibraryContainer = sal_True;
+
+    sal_Bool bLibContainer = ( maLibName.getLength() == 0 );
+    if( bLibContainer )
+    {
+        StarBASIC* pLib = mpMgr->GetLib( aName );
+        if( pLib )
+        {
+            USHORT nLibId = mpMgr->GetLibId( aName );
+            mpMgr->RemoveLib( nLibId, FALSE );
+        }
+    }
+    else
+    {
+        StarBASIC* pLib = mpMgr->GetLib( maLibName );
+        SbModule* pMod = pLib ? pLib->FindModule( aName ) : NULL;
+        if( pMod )
+        {
+            pLib->Remove( pMod );
+            pLib->SetModified( FALSE );
+        }
+    }
+}
+
+
+//=====================================================================
+
+class BasicErrorManager
+{
+private:
+    BasErrorLst aErrorList;
+    size_t CurrentError;
+
+public:
+                BasicErrorManager() { CurrentError = 0; }
+                ~BasicErrorManager();
+
+    void        Reset();
+    void        InsertError( const BasicError& rError );
+
+    BOOL        HasErrors()         { return !aErrorList.empty(); }
+};
+
+BasicErrorManager::~BasicErrorManager()
+{
+    Reset();
+}
+
+void BasicErrorManager::Reset()
+{
+    for ( size_t i = 0, n = aErrorList.size(); i < n; ++i )
+        delete aErrorList[ i ];
+    aErrorList.clear();
+}
+
+void BasicErrorManager::InsertError( const BasicError& rError )
+{
+    aErrorList.push_back( new BasicError( rError ) );
+}
+
+BasicError::BasicError( ULONG nId, USHORT nR, const String& rErrStr ) :
+    aErrStr( rErrStr )
+{
+    nErrorId    = nId;
+    nReason     = nR;
+}
+
+BasicError::BasicError( const BasicError& rErr ) :
+    aErrStr( rErr.aErrStr )
+{
+    nErrorId    = rErr.nErrorId;
+    nReason     = rErr.nReason;
+}
+
+
+class BasicLibInfo
+{
+private:
+    StarBASICRef    xLib;
+    String          aLibName;
+    String          aStorageName;   // String reicht, da zur Laufzeit eindeutig.
+    String          aRelStorageName;
+    String          aPassword;
+
+    BOOL            bDoLoad;
+    BOOL            bReference;
+    BOOL            bPasswordVerified;
+    BOOL            bFoundInPath;   // Darf dann nicht neu relativiert werden!
+
+    // Lib represents library in new UNO library container
+    Reference< XLibraryContainer > mxScriptCont;
+
+public:
+    BasicLibInfo();
+
+    BOOL            IsReference() const     { return bReference; }
+    BOOL&           IsReference()           { return bReference; }
+
+    BOOL            IsExtern() const        { return ! aStorageName.EqualsAscii(szImbedded); }
+
+    void            SetStorageName( const String& rName )   { aStorageName = rName; }
+    const String&   GetStorageName() const                  { return aStorageName; }
+
+    void            SetRelStorageName( const String& rN )   { aRelStorageName = rN; }
+    const String&   GetRelStorageName() const               { return aRelStorageName; }
+
+    StarBASICRef    GetLib() const
+    {
+        if( mxScriptCont.is() && mxScriptCont->hasByName( aLibName ) &&
+            !mxScriptCont->isLibraryLoaded( aLibName ) )
+                return StarBASICRef();
+        return xLib;
+    }
+    StarBASICRef&   GetLibRef()                         { return xLib; }
+    void            SetLib( StarBASIC* pBasic )         { xLib = pBasic; }
+
+    const String&   GetLibName() const                  { return aLibName; }
+    void            SetLibName( const String& rName )   { aLibName = rName; }
+
+    // Only temporary, for saving/loading ...
+    BOOL            DoLoad()                            { return bDoLoad; }
+
+    BOOL            HasPassword() const                 { return aPassword.Len() != 0; }
+    const String&   GetPassword() const                 { return aPassword; }
+    void            SetPassword( const String& rNewPassword )
+                                                        { aPassword = rNewPassword; }
+    BOOL            IsPasswordVerified() const          { return bPasswordVerified; }
+    void            SetPasswordVerified()               { bPasswordVerified = TRUE; }
+
+    BOOL            IsFoundInPath() const               { return bFoundInPath; }
+    void            SetFoundInPath( BOOL bInPath )      { bFoundInPath = bInPath; }
+
+    void                        Store( SotStorageStream&, const String&, BOOL ) {}
+    static BasicLibInfo*    Create( SotStorageStream& rSStream );
+
+    Reference< XLibraryContainer > GetLibraryContainer( void )
+        { return mxScriptCont; }
+    void SetLibraryContainer( const Reference< XLibraryContainer >& xScriptCont )
+        { mxScriptCont = xScriptCont; }
+};
+
+typedef vector< BasicLibInfo* > BasicLibsBase;
+
+class BasicLibs
+{
+private:
+    BasicLibsBase   mpList;
+    size_t          current;
+
+public:
+    String  aBasicLibPath;      // soll eigentlich Member vom Manager werden, aber jetzt nicht inkompatibel!
+    BasicLibInfo*   GetObject( size_t i );
+    void            Insert( BasicLibInfo* item, size_t i );
+    void            Clear() { mpList.clear(); }
+    size_t          Count() { return mpList.size(); }
+    size_t          GetPos( BasicLibInfo* pItem );
+    size_t          GetCurPos() { return current; }
+    BasicLibInfo*   First();
+    BasicLibInfo*   Next();
+    BasicLibInfo*   Prev();
+    BasicLibInfo*   Last();
+    BasicLibInfo*   Remove( BasicLibInfo* pItem );
+};
+
+size_t BasicLibs::GetPos( BasicLibInfo* pItem )
+{
+    for ( size_t i = 0, n = mpList.size(); i < n; ++i )
+        if ( mpList[ i ] == pItem )
+            return i;
+    return size_t(-1);
+}
+
+void BasicLibs::Insert( BasicLibInfo* pItem, size_t i )
+{
+    if ( i >= mpList.size() )
+    {
+        mpList.push_back( pItem );
+        current = mpList.size() - 1;
+    }
+    else
+    {
+        BasicLibsBase::iterator it = mpList.begin();
+        advance( it, i );
+        mpList.insert( it, pItem );
+        current = i;
+    }
+}
+
+BasicLibInfo* BasicLibs::Remove( BasicLibInfo* pItem )
+{
+    size_t pos = GetPos( pItem );
+    if ( pos == size_t(-1) ) return NULL;
+
+    current = pos;
+    BasicLibsBase::iterator it = mpList.begin();
+    advance( it, pos );
+    mpList.erase( it );
+    return pItem;
+}
+
+BasicLibInfo* BasicLibs::GetObject( size_t i )
+{
+    if ( i >= mpList.size() ) return NULL;
+    return mpList[ i ];
+}
+
+BasicLibInfo* BasicLibs::First()
+{
+    current = 0;
+    if ( mpList.empty() ) return NULL;
+    return mpList[ current ];
+}
+
+BasicLibInfo* BasicLibs::Next()
+{
+    if (  mpList.empty()
+       || current+1 >= mpList.size()
+       )
+        return NULL;
+    current++;
+    return mpList[ current ];
+}
+
+BasicLibInfo* BasicLibs::Prev()
+{
+    if (  mpList.empty()
+       || current == 0
+       )
+        return NULL;
+    current--;
+    return mpList[ current ];
+}
+
+BasicLibInfo* BasicLibs::Last()
+{
+    if ( mpList.empty() ) return NULL;
+    current = mpList.size() - 1;
+    return mpList[ current ];
+}
+
+BasicLibInfo::BasicLibInfo()
+{
+    bReference          = FALSE;
+    bPasswordVerified   = FALSE;
+    bDoLoad             = FALSE;
+    bFoundInPath        = FALSE;
+    mxScriptCont        = NULL;
+    aStorageName        = String::CreateFromAscii(szImbedded);
+    aRelStorageName     = String::CreateFromAscii(szImbedded);
+}
+
+BasicLibInfo* BasicLibInfo::Create( SotStorageStream& rSStream )
+{
+    BasicLibInfo* pInfo = new BasicLibInfo;
+
+    sal_uInt32 nEndPos;
+    USHORT nId;
+    USHORT nVer;
+
+    rSStream >> nEndPos;
+    rSStream >> nId;
+    rSStream >> nVer;
+
+    DBG_ASSERT( nId == LIBINFO_ID, "Without BasicLibInfo !?" );
+    if( nId == LIBINFO_ID )
+    {
+        // Load again?
+        BOOL bDoLoad;
+        rSStream >> bDoLoad;
+        pInfo->bDoLoad = bDoLoad;
+
+        // Den Namen der Lib...
+        String aName = rSStream.ReadUniOrByteString(rSStream.GetStreamCharSet());
+        pInfo->SetLibName( aName );
+
+        // Absoluter Pfad....
+        String aStorageName = rSStream.ReadUniOrByteString(rSStream.GetStreamCharSet());
+        pInfo->SetStorageName( aStorageName );
+
+        // Relativer Pfad...
+        String aRelStorageName = rSStream.ReadUniOrByteString(rSStream.GetStreamCharSet());
+        pInfo->SetRelStorageName( aRelStorageName );
+
+        if ( nVer >= 2 )
+        {
+            BOOL bReferenz;
+            rSStream >> bReferenz;
+            pInfo->IsReference() = bReferenz;
+        }
+
+        rSStream.Seek( nEndPos );
+    }
+    return pInfo;
+}
+
+BasicManager::BasicManager( SotStorage& rStorage, const String& rBaseURL, StarBASIC* pParentFromStdLib, String* pLibPath )
+{
+    DBG_CTOR( BasicManager, 0 );
+
+    Init();
+
+    if( pLibPath )
+        pLibs->aBasicLibPath = *pLibPath;
+
+    String aStorName( rStorage.GetName() );
+    maStorageName = INetURLObject(aStorName, INET_PROT_FILE).GetMainURL( INetURLObject::NO_DECODE );
+
+    // #91251: Storage name not longer available for documents < 5.0
+    // Should be no real problem, because only relative storage names
+    // (links) can be affected.
+
+    // Wenn es den Manager-Stream nicht gibt, sind keine weiteren
+    // Aktionen noetig.
+    if ( rStorage.IsStream( ManagerStreamName ) )
+    {
+        LoadBasicManager( rStorage, rBaseURL );
+        // StdLib erhaelt gewuenschten Parent:
+        StarBASIC* pStdLib = GetStdLib();
+        DBG_ASSERT( pStdLib, "Standard-Lib nicht geladen?" );
+        if ( !pStdLib )
+        {
+            // Sollte eigentlich nie passieren, aber dann wenigstens nicht abstuerzen...
+            pStdLib = new StarBASIC;
+            BasicLibInfo* pStdLibInfo = pLibs->GetObject( 0 );
+            if ( !pStdLibInfo )
+                pStdLibInfo = CreateLibInfo();
+            pStdLibInfo->SetLib( pStdLib );
+            StarBASICRef xStdLib = pStdLibInfo->GetLib();
+            xStdLib->SetName( String::CreateFromAscii(szStdLibName) );
+            pStdLibInfo->SetLibName( String::CreateFromAscii(szStdLibName) );
+            xStdLib->SetFlag( SBX_DONTSTORE | SBX_EXTSEARCH );
+            xStdLib->SetModified( FALSE );
+        }
+        else
+        {
+            pStdLib->SetParent( pParentFromStdLib );
+            // Die anderen erhalten die StdLib als Parent:
+            for ( USHORT nBasic = 1; nBasic < GetLibCount(); nBasic++ )
+            {
+                StarBASIC* pBasic = GetLib( nBasic );
+                if ( pBasic )
+                {
+                    pStdLib->Insert( pBasic );
+                    pBasic->SetFlag( SBX_EXTSEARCH );
+                }
+            }
+            // Durch das Insert modified:
+            pStdLib->SetModified( FALSE );
+        }
+
+        // #91626 Save all stream data to save it unmodified if basic isn't modified
+        // in an 6.0+ office. So also the old basic dialogs can be saved.
+        SotStorageStreamRef xManagerStream = rStorage.OpenSotStream
+            ( ManagerStreamName, eStreamReadMode );
+        mpImpl->mpManagerStream = new SvMemoryStream();
+        *static_cast<SvStream*>(&xManagerStream) >> *mpImpl->mpManagerStream;
+
+        SotStorageRef xBasicStorage = rStorage.OpenSotStorage
+                                ( BasicStreamName, eStorageReadMode, FALSE );
+        if( xBasicStorage.Is() && !xBasicStorage->GetError() )
+        {
+            USHORT nLibs = GetLibCount();
+            mpImpl->mppLibStreams = new SvMemoryStream*[ nLibs ];
+            for( USHORT nL = 0; nL < nLibs; nL++ )
+            {
+                BasicLibInfo* pInfo = pLibs->GetObject( nL );
+                DBG_ASSERT( pInfo, "pInfo?!" );
+                SotStorageStreamRef xBasicStream = xBasicStorage->OpenSotStream( pInfo->GetLibName(), eStreamReadMode );
+                mpImpl->mppLibStreams[nL] = new SvMemoryStream();
+                *static_cast<SvStream*>(&xBasicStream) >> *( mpImpl->mppLibStreams[nL] );
+            }
+        }
+        else
+            mpImpl->mbError = sal_True;
+    }
+    else
+    {
+        ImpCreateStdLib( pParentFromStdLib );
+        if ( rStorage.IsStream( String::CreateFromAscii(szOldManagerStream) ) )
+            LoadOldBasicManager( rStorage );
+    }
+
+    bBasMgrModified = FALSE;
+}
+
+
+void copyToLibraryContainer( StarBASIC* pBasic, LibraryContainerInfo* pInfo )
+{
+    Reference< XLibraryContainer > xScriptCont;
+    String aLibName = pBasic->GetName();
+    if( pInfo && (xScriptCont = pInfo->mxScriptCont).is() )
+    {
+        if( !xScriptCont->hasByName( aLibName ) )
+            xScriptCont->createLibrary( aLibName );
+
+        Any aLibAny = xScriptCont->getByName( aLibName );
+        Reference< XNameContainer > xLib;
+        aLibAny >>= xLib;
+        if( xLib.is() )
+        {
+            USHORT nModCount = pBasic->GetModules()->Count();
+            for ( USHORT nMod = 0 ; nMod < nModCount ; nMod++ )
+            {
+                SbModule* pModule = (SbModule*)pBasic->GetModules()->Get( nMod );
+                DBG_ASSERT( pModule, "Modul nicht erhalten!" );
+
+                String aModName = pModule->GetName();
+                if( !xLib->hasByName( aModName ) )
+                {
+                    OUString aSource = pModule->GetSource32();
+                    Any aSourceAny;
+                    aSourceAny <<= aSource;
+                    xLib->insertByName( aModName, aSourceAny );
+                }
+            }
+        }
+    }
+}
+
+void BasicManager::SetLibraryContainerInfo( LibraryContainerInfo* pInfo )
+{
+    if( !pInfo )
+        return;
+    mpImpl->mpInfo = pInfo;
+
+    Reference< XLibraryContainer > xScriptCont;
+    StarBASIC* pStdLib = GetStdLib();
+    String aLibName = pStdLib->GetName();
+    if( mpImpl->mpInfo && (xScriptCont = mpImpl->mpInfo->mxScriptCont).is() )
+    {
+        OUString aScriptLanguage = DEFINE_CONST_UNICODE( "StarBasic" );
+
+        // Register listener for lib container
+        OUString aEmptyLibName;
+        Reference< XContainerListener > xLibContainerListener
+            = static_cast< XContainerListener* >
+                ( new BasMgrContainerListenerImpl( this, aEmptyLibName ) );
+
+        Reference< XContainer> xLibContainer( xScriptCont, UNO_QUERY );
+        xLibContainer->addContainerListener( xLibContainerListener );
+
+        Sequence< OUString > aNames = xScriptCont->getElementNames();
+        const OUString* pNames = aNames.getConstArray();
+        sal_Int32 i, nNameCount = aNames.getLength();
+
+        if( nNameCount )
+        {
+            for( i = 0 ; i < nNameCount ; i++ )
+            {
+                OUString aLibName2 = pNames[ i ];
+                Any aLibAny = xScriptCont->getByName( aLibName2 );
+
+                if( String( aLibName2 ).EqualsAscii( "Standard" ) )
+                    xScriptCont->loadLibrary( aLibName2 );
+
+                BasMgrContainerListenerImpl::insertLibraryImpl
+                    ( xScriptCont, this, aLibAny, aLibName2 );
+            }
+        }
+        else
+        {
+            // No libs? Maybe an 5.2 document already loaded
+            USHORT nLibs = GetLibCount();
+            for( USHORT nL = 0; nL < nLibs; nL++ )
+            {
+                BasicLibInfo* pBasLibInfo = pLibs->GetObject( nL );
+                StarBASIC* pLib = pBasLibInfo->GetLib();
+                if( !pLib )
+                {
+                    BOOL bLoaded = ImpLoadLibary( pBasLibInfo, NULL, FALSE );
+                    if( bLoaded )
+                        pLib = pBasLibInfo->GetLib();
+                }
+                if( pLib )
+                {
+                    copyToLibraryContainer( pLib, mpImpl->mpInfo );
+                    if( pBasLibInfo->HasPassword() )
+                    {
+                        OldBasicPassword* pOldBasicPassword =
+                            mpImpl->mpInfo->mpOldBasicPassword;
+                        if( pOldBasicPassword )
+                        {
+                            pOldBasicPassword->setLibraryPassword
+                                ( pLib->GetName(), pBasLibInfo->GetPassword() );
+                            pBasLibInfo->SetPasswordVerified();
+                        }
+                    }
+                }
+            }
+
+            mpImpl->mbModifiedByLibraryContainer = sal_False;
+        }
+    }
+}
+
+BasicManager::BasicManager( StarBASIC* pSLib, String* pLibPath )
+{
+    DBG_CTOR( BasicManager, 0 );
+    Init();
+    DBG_ASSERT( pSLib, "BasicManager kann nicht mit einem NULL-Pointer erzeugt werden!" );
+
+    if( pLibPath )
+        pLibs->aBasicLibPath = *pLibPath;
+
+    BasicLibInfo* pStdLibInfo = CreateLibInfo();
+    pStdLibInfo->SetLib( pSLib );
+    StarBASICRef xStdLib = pStdLibInfo->GetLib();
+    xStdLib->SetName( String::CreateFromAscii(szStdLibName));
+    pStdLibInfo->SetLibName( String::CreateFromAscii(szStdLibName) );
+    pSLib->SetFlag( SBX_DONTSTORE | SBX_EXTSEARCH );
+
+    // Speichern lohnt sich nur, wenn sich das Basic aendert.
+    xStdLib->SetModified( FALSE );
+    bBasMgrModified = FALSE;
+}
+
+BOOL BasicManager::HasBasicWithModules( const SotStorage& rStorage, const String& rBaseURL )
+{
+    if( !rStorage.IsStream( ManagerStreamName ) )
+        return FALSE;
+
+    StarBASIC* pDummyParentBasic = new StarBASIC();
+    BasicManager* pBasMgr = new BasicManager( (SotStorage&)rStorage, rBaseURL, pDummyParentBasic );
+    BOOL bRet = FALSE;
+
+    USHORT nLibs = pBasMgr->GetLibCount();
+    for( USHORT nL = 0; nL < nLibs; nL++ )
+    {
+        BasicLibInfo* pInfo = pBasMgr->pLibs->GetObject( nL );
+        StarBASIC* pLib = pInfo->GetLib();
+        if( !pLib )
+        {
+            BOOL bLoaded = pBasMgr->ImpLoadLibary( pInfo, NULL, FALSE );
+            if( bLoaded )
+                pLib = pInfo->GetLib();
+        }
+        if( pLib )
+        {
+            SbxArray* pModules = pLib->GetModules();
+            if( pModules->Count() )
+            {
+                bRet = TRUE;
+                break;
+            }
+        }
+    }
+
+    delete pBasMgr;
+    return bRet;
+}
+
+void BasicManager::ImpMgrNotLoaded( const String& rStorageName )
+{
+    // pErrInf wird nur zerstoert, wenn der Fehler von einem ErrorHandler
+    // gehandelt wird!
+    StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, rStorageName, ERRCODE_BUTTON_OK );
+    pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_OPENMGRSTREAM, rStorageName ) );
+
+    // Eine STD-Lib erzeugen, sonst macht es Peng!
+    BasicLibInfo* pStdLibInfo = CreateLibInfo();
+    pStdLibInfo->SetLib( new StarBASIC );
+    StarBASICRef xStdLib = pStdLibInfo->GetLib();
+    xStdLib->SetName( String::CreateFromAscii(szStdLibName) );
+    pStdLibInfo->SetLibName( String::CreateFromAscii(szStdLibName) );
+    xStdLib->SetFlag( SBX_DONTSTORE | SBX_EXTSEARCH );
+    xStdLib->SetModified( FALSE );
+}
+
+
+void BasicManager::ImpCreateStdLib( StarBASIC* pParentFromStdLib )
+{
+    BasicLibInfo* pStdLibInfo = CreateLibInfo();
+    StarBASIC* pStdLib = new StarBASIC( pParentFromStdLib );
+    pStdLibInfo->SetLib( pStdLib );
+    pStdLib->SetName( String::CreateFromAscii(szStdLibName) );
+    pStdLibInfo->SetLibName( String::CreateFromAscii(szStdLibName) );
+    pStdLib->SetFlag( SBX_DONTSTORE | SBX_EXTSEARCH );
+}
+
+
+void BasicManager::LoadBasicManager( SotStorage& rStorage, const String& rBaseURL, BOOL bLoadLibs )
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+
+    SotStorageStreamRef xManagerStream = rStorage.OpenSotStream
+        ( ManagerStreamName, eStreamReadMode );
+
+    String aStorName( rStorage.GetName() );
+    // #i13114 removed, DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
+
+    if ( !xManagerStream.Is() || xManagerStream->GetError() || ( xManagerStream->Seek( STREAM_SEEK_TO_END ) == 0 ) )
+    {
+        ImpMgrNotLoaded( aStorName );
+        return;
+    }
+
+    maStorageName = INetURLObject(aStorName, INET_PROT_FILE).GetMainURL( INetURLObject::NO_DECODE );
+    // #i13114 removed, DBG_ASSERT(aStorageName.Len() != 0, "Bad storage name");
+
+    String aRealStorageName = maStorageName;  // fuer relative Pfade, kann durch BaseURL umgebogen werden.
+
+    // Wenn aus Vorlagen geladen wird, gilt nur die BaseURL:
+    if ( rBaseURL.Len() )
+    {
+        INetURLObject aObj( rBaseURL );
+        if ( aObj.GetProtocol() == INET_PROT_FILE )
+            aRealStorageName = aObj.PathToFileName();
+    }
+
+    xManagerStream->SetBufferSize( 1024 );
+    xManagerStream->Seek( STREAM_SEEK_TO_BEGIN );
+
+    sal_uInt32 nEndPos;
+    *xManagerStream >> nEndPos;
+
+    USHORT nLibs;
+    *xManagerStream >> nLibs;
+    // Plausi!
+    if( nLibs & 0xF000 )
+    {
+        DBG_ASSERT( !this, "BasicManager-Stream defekt!" );
+        return;
+    }
+    for ( USHORT nL = 0; nL < nLibs; nL++ )
+    {
+        BasicLibInfo* pInfo = BasicLibInfo::Create( *xManagerStream );
+
+        // ggf. absoluten Pfad-Namen korrigieren, wenn rel. existiert
+        // Immer erst den relativen versuchen, falls zwei Staende auf der Platte
+        if ( pInfo->GetRelStorageName().Len() && ( ! pInfo->GetRelStorageName().EqualsAscii(szImbedded) ) )
+        {
+            INetURLObject aObj( aRealStorageName, INET_PROT_FILE );
+            aObj.removeSegment();
+            bool bWasAbsolute = FALSE;
+            aObj = aObj.smartRel2Abs( pInfo->GetRelStorageName(), bWasAbsolute );
+
+            if ( pLibs->aBasicLibPath.Len() )
+            {
+                // Lib im Pfad suchen...
+                rtl::OUString aSearchFile = pInfo->GetRelStorageName();
+                SvtPathOptions aPathCFG;
+                if( aPathCFG.SearchFile( aSearchFile, SvtPathOptions::PATH_BASIC ) )
+                {
+                    pInfo->SetStorageName( aSearchFile );
+                    pInfo->SetFoundInPath( TRUE );
+                }
+            }
+        }
+
+        pLibs->Insert( pInfo, LIST_APPEND );
+        // Libs aus externen Dateien sollen erst bei Bedarf geladen werden.
+        // Aber Referenzen werden gleich geladen, sonst bekommen die Grosskunden
+        // vielleicht Probleme...
+        if ( bLoadLibs && pInfo->DoLoad() &&
+            ( ( !pInfo->IsExtern() ) || ( pInfo->IsReference() ) ) )
+        {
+            ImpLoadLibary( pInfo, &rStorage );
+        }
+    }
+
+    xManagerStream->Seek( nEndPos );
+    xManagerStream->SetBufferSize( 0 );
+    xManagerStream.Clear();
+}
+
+void BasicManager::LoadOldBasicManager( SotStorage& rStorage )
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+
+    SotStorageStreamRef xManagerStream = rStorage.OpenSotStream
+        ( String::CreateFromAscii(szOldManagerStream), eStreamReadMode );
+
+    String aStorName( rStorage.GetName() );
+    DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
+
+    if ( !xManagerStream.Is() || xManagerStream->GetError() || ( xManagerStream->Seek( STREAM_SEEK_TO_END ) == 0 ) )
+    {
+        ImpMgrNotLoaded( aStorName );
+        return;
+    }
+
+    xManagerStream->SetBufferSize( 1024 );
+    xManagerStream->Seek( STREAM_SEEK_TO_BEGIN );
+    sal_uInt32 nBasicStartOff, nBasicEndOff;
+    *xManagerStream >> nBasicStartOff;
+    *xManagerStream >> nBasicEndOff;
+
+    DBG_ASSERT( !xManagerStream->GetError(), "Ungueltiger Manager-Stream!" );
+
+    xManagerStream->Seek( nBasicStartOff );
+    if( !ImplLoadBasic( *xManagerStream, pLibs->GetObject(0)->GetLibRef() ) )
+    {
+        StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, aStorName, ERRCODE_BUTTON_OK );
+        pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_OPENMGRSTREAM, aStorName ) );
+        // und es geht weiter...
+    }
+    xManagerStream->Seek( nBasicEndOff+1 ); // +1: 0x00 als Trenner
+    String aLibs = xManagerStream->ReadUniOrByteString(xManagerStream->GetStreamCharSet());
+    xManagerStream->SetBufferSize( 0 );
+    xManagerStream.Clear(); // Sream schliessen
+
+    if ( aLibs.Len() )
+    {
+        String aCurStorageName( aStorName );
+        INetURLObject aCurStorage( aCurStorageName, INET_PROT_FILE );
+        USHORT nLibs = aLibs.GetTokenCount( LIB_SEP );
+        for ( USHORT nLib = 0; nLib < nLibs; nLib++ )
+        {
+            String aLibInfo( aLibs.GetToken( nLib, LIB_SEP ) );
+            // == 2 soll irgendwann weg!
+            DBG_ASSERT( ( aLibInfo.GetTokenCount( LIBINFO_SEP ) == 2 ) || ( aLibInfo.GetTokenCount( LIBINFO_SEP ) == 3 ), "Ungueltige Lib-Info!" );
+            String aLibName( aLibInfo.GetToken( 0, LIBINFO_SEP ) );
+            String aLibAbsStorageName( aLibInfo.GetToken( 1, LIBINFO_SEP ) );
+            String aLibRelStorageName( aLibInfo.GetToken( 2, LIBINFO_SEP ) );
+            INetURLObject aLibAbsStorage( aLibAbsStorageName, INET_PROT_FILE );
+
+            INetURLObject aLibRelStorage( aStorName );
+            aLibRelStorage.removeSegment();
+            bool bWasAbsolute = FALSE;
+            aLibRelStorage = aLibRelStorage.smartRel2Abs( aLibRelStorageName, bWasAbsolute);
+            DBG_ASSERT(!bWasAbsolute, "RelStorageName was absolute!" );
+
+            SotStorageRef xStorageRef;
+            if ( ( aLibAbsStorage == aCurStorage ) || ( aLibRelStorageName.EqualsAscii(szImbedded) ) )
+                xStorageRef = &rStorage;
+            else
+            {
+                xStorageRef = new SotStorage( FALSE, aLibAbsStorage.GetMainURL
+                    ( INetURLObject::NO_DECODE ), eStorageReadMode, TRUE );
+                if ( xStorageRef->GetError() != ERRCODE_NONE )
+                    xStorageRef = new SotStorage( FALSE, aLibRelStorage.
+                    GetMainURL( INetURLObject::NO_DECODE ), eStorageReadMode, TRUE );
+            }
+            if ( xStorageRef.Is() )
+                AddLib( *xStorageRef, aLibName, FALSE );
+            else
+            {
+                StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, aStorName, ERRCODE_BUTTON_OK );
+                pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_STORAGENOTFOUND, aStorName ) );
+            }
+        }
+    }
+}
+
+BasicManager::~BasicManager()
+{
+    DBG_DTOR( BasicManager, 0 );
+
+    // Listener benachrichtigen, falls noch etwas zu Speichern...
+    Broadcast( SfxSimpleHint( SFX_HINT_DYING) );
+
+    // Basic-Infos zerstoeren...
+    // In umgekehrter Reihenfolge, weil die StdLib Referenzen haelt, die
+    // anderen nur die StdLib als Parent haben.
+    BasicLibInfo* pInf = pLibs->Last();
+    while ( pInf )
+    {
+        delete pInf;
+        pInf = pLibs->Prev();
+    }
+    pLibs->Clear();
+    delete pLibs;
+    delete pErrorMgr;
+    delete mpImpl;
+}
+
+void BasicManager::LegacyDeleteBasicManager( BasicManager*& _rpManager )
+{
+    delete _rpManager;
+    _rpManager = NULL;
+}
+
+void BasicManager::Init()
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    bBasMgrModified = FALSE;
+    pErrorMgr = new BasicErrorManager;
+    pLibs = new BasicLibs;
+    mpImpl = new BasicManagerImpl();
+}
+
+BasicLibInfo* BasicManager::CreateLibInfo()
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    BasicLibInfo* pInf = new BasicLibInfo;
+    pLibs->Insert( pInf, LIST_APPEND );
+    return pInf;
+}
+
+BOOL BasicManager::ImpLoadLibary( BasicLibInfo* pLibInfo, SotStorage* pCurStorage, BOOL bInfosOnly ) const
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    DBG_ASSERT( pLibInfo, "LibInfo!?" );
+
+    String aStorageName( pLibInfo->GetStorageName() );
+    if ( !aStorageName.Len() || ( aStorageName.EqualsAscii(szImbedded) ) )
+        aStorageName = GetStorageName();
+
+    SotStorageRef xStorage;
+    // Der aktuelle darf nicht nochmal geoffnet werden...
+    if ( pCurStorage )
+    {
+        String aStorName( pCurStorage->GetName() );
+        // #i13114 removed, DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
+
+        INetURLObject aCurStorageEntry(aStorName, INET_PROT_FILE);
+        // #i13114 removed, DBG_ASSERT(aCurStorageEntry.GetMainURL( INetURLObject::NO_DECODE ).Len() != 0, "Bad storage name");
+
+        INetURLObject aStorageEntry(aStorageName, INET_PROT_FILE);
+        // #i13114 removed, DBG_ASSERT(aCurStorageEntry.GetMainURL( INetURLObject::NO_DECODE ).Len() != 0, "Bad storage name");
+
+        if ( aCurStorageEntry == aStorageEntry )
+            xStorage = pCurStorage;
+    }
+
+    if ( !xStorage.Is() )
+        xStorage = new SotStorage( FALSE, aStorageName, eStorageReadMode );
+
+    SotStorageRef xBasicStorage = xStorage->OpenSotStorage
+                            ( BasicStreamName, eStorageReadMode, FALSE );
+
+    if ( !xBasicStorage.Is() || xBasicStorage->GetError() )
+    {
+        StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_MGROPEN, xStorage->GetName(), ERRCODE_BUTTON_OK );
+        pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_OPENLIBSTORAGE, pLibInfo->GetLibName() ) );
+    }
+    else
+    {
+        // In dem Basic-Storage liegt jede Lib in einem Stream...
+        SotStorageStreamRef xBasicStream = xBasicStorage->OpenSotStream( pLibInfo->GetLibName(), eStreamReadMode );
+        if ( !xBasicStream.Is() || xBasicStream->GetError() )
+        {
+            StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD , pLibInfo->GetLibName(), ERRCODE_BUTTON_OK );
+            pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_OPENLIBSTREAM, pLibInfo->GetLibName() ) );
+        }
+        else
+        {
+            BOOL bLoaded = FALSE;
+            if ( xBasicStream->Seek( STREAM_SEEK_TO_END ) != 0 )
+            {
+                if ( !bInfosOnly )
+                {
+                    if ( !pLibInfo->GetLib().Is() )
+                        pLibInfo->SetLib( new StarBASIC( GetStdLib() ) );
+                    xBasicStream->SetBufferSize( 1024 );
+                    xBasicStream->Seek( STREAM_SEEK_TO_BEGIN );
+                    bLoaded = ImplLoadBasic( *xBasicStream, pLibInfo->GetLibRef() );
+                    xBasicStream->SetBufferSize( 0 );
+                    StarBASICRef xStdLib = pLibInfo->GetLib();
+                    xStdLib->SetName( pLibInfo->GetLibName() );
+                    xStdLib->SetModified( FALSE );
+                    xStdLib->SetFlag( SBX_DONTSTORE );
+                }
+                else
+                {
+                    // Das Basic skippen...
+                    xBasicStream->Seek( STREAM_SEEK_TO_BEGIN );
+                    ImplEncryptStream( *xBasicStream );
+                    SbxBase::Skip( *xBasicStream );
+                    bLoaded = TRUE;
+                }
+            }
+            if ( !bLoaded )
+            {
+                StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_LIBLOAD, pLibInfo->GetLibName(), ERRCODE_BUTTON_OK );
+                pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_BASICLOADERROR, pLibInfo->GetLibName() ) );
+            }
+            else
+            {
+                // Ggf. stehen weitere Informationen im Stream...
+                xBasicStream->SetCryptMaskKey(szCryptingKey);
+                xBasicStream->RefreshBuffer();
+                sal_uInt32 nPasswordMarker = 0;
+                *xBasicStream >> nPasswordMarker;
+                if ( ( nPasswordMarker == PASSWORD_MARKER ) && !xBasicStream->IsEof() )
+                {
+                    String aPassword = xBasicStream->ReadUniOrByteString(xBasicStream->GetStreamCharSet());
+                    pLibInfo->SetPassword( aPassword );
+                }
+                xBasicStream->SetCryptMaskKey(rtl::OString());
+                CheckModules( pLibInfo->GetLib(), pLibInfo->IsReference() );
+            }
+            return bLoaded;
+        }
+    }
+    return FALSE;
+}
+
+BOOL BasicManager::ImplEncryptStream( SvStream& rStrm ) const
+{
+    ULONG nPos = rStrm.Tell();
+    UINT32 nCreator;
+    rStrm >> nCreator;
+    rStrm.Seek( nPos );
+    BOOL bProtected = FALSE;
+    if ( nCreator != SBXCR_SBX )
+    {
+        // sollte nur bei verschluesselten Streams nicht stimmen.
+        bProtected = TRUE;
+        rStrm.SetCryptMaskKey(szCryptingKey);
+        rStrm.RefreshBuffer();
+    }
+    return bProtected;
+}
+
+
+// Dieser Code ist notwendig, um das BASIC der Beta 1 laden zu koennen
+BOOL BasicManager::ImplLoadBasic( SvStream& rStrm, StarBASICRef& rOldBasic ) const
+{
+    BOOL bProtected = ImplEncryptStream( rStrm );
+    SbxBaseRef xNew = SbxBase::Load( rStrm );
+    BOOL bLoaded = FALSE;
+    if( xNew.Is() )
+    {
+        if( xNew->IsA( TYPE(StarBASIC) ) )
+        {
+            StarBASIC* pNew = (StarBASIC*)(SbxBase*) xNew;
+            // Den Parent des alten BASICs uebernehmen
+            if( rOldBasic.Is() )
+            {
+                pNew->SetParent( rOldBasic->GetParent() );
+                if( pNew->GetParent() )
+                    pNew->GetParent()->Insert( pNew );
+                pNew->SetFlag( SBX_EXTSEARCH );
+            }
+            rOldBasic = pNew;
+
+            // Fill new libray container (5.2 -> 6.0)
+            copyToLibraryContainer( pNew, mpImpl->mpInfo );
+
+            pNew->SetModified( FALSE );
+            bLoaded = TRUE;
+        }
+    }
+    if ( bProtected )
+        rStrm.SetCryptMaskKey(rtl::OString());
+    return bLoaded;
+}
+
+void BasicManager::CheckModules( StarBASIC* pLib, BOOL bReference ) const
+{
+    if ( !pLib )
+        return;
+
+    BOOL bModified = pLib->IsModified();
+
+    // #67477, AB 8.12.99 On demand Compilieren bei referenzierten
+    // Libraries sollte nicht zu modified fuehren
+    if( !bModified && bReference )
+    {
+        OSL_FAIL( "Per Reference eingebundene Basic-Library ist nicht compiliert!" );
+        pLib->SetModified( FALSE );
+    }
+}
+
+
+StarBASIC* BasicManager::AddLib( SotStorage& rStorage, const String& rLibName, BOOL bReference )
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    String aStorName( rStorage.GetName() );
+    DBG_ASSERT( aStorName.Len(), "No Storage Name!" );
+
+    String aStorageName = INetURLObject(aStorName, INET_PROT_FILE).GetMainURL( INetURLObject::NO_DECODE );
+    DBG_ASSERT(aStorageName.Len() != 0, "Bad storage name");
+
+    String aNewLibName( rLibName );
+    while ( HasLib( aNewLibName ) )
+        aNewLibName += '_';
+
+    BasicLibInfo* pLibInfo = CreateLibInfo();
+    // Erstmal mit dem Original-Namen, da sonst ImpLoadLibary nicht geht...
+    pLibInfo->SetLibName( rLibName );
+    // Funktioniert so aber nicht, wenn Name doppelt
+    USHORT nLibId = (USHORT) pLibs->GetPos( pLibInfo );
+
+    // Vorm Laden StorageNamen setzen, da er mit pCurStorage verglichen wird.
+    pLibInfo->SetStorageName( aStorageName );
+    BOOL bLoaded = ImpLoadLibary( pLibInfo, &rStorage );
+
+    if ( bLoaded )
+    {
+        if ( aNewLibName != rLibName )
+            SetLibName( nLibId, aNewLibName );
+
+        if ( bReference )
+        {
+            pLibInfo->GetLib()->SetModified( FALSE );   // Dann nicht speichern
+            pLibInfo->SetRelStorageName( String() );
+            pLibInfo->IsReference() = TRUE;
+        }
+        else
+        {
+            pLibInfo->GetLib()->SetModified( TRUE );        // Muss nach Add gespeichert werden!
+            pLibInfo->SetStorageName( String::CreateFromAscii(szImbedded) );            // Im BasicManager-Storage speichern
+        }
+        bBasMgrModified = TRUE;
+    }
+    else
+    {
+        RemoveLib( nLibId, FALSE );
+        pLibInfo = 0;
+    }
+
+    if( pLibInfo )
+        return &*pLibInfo->GetLib() ;
+    else
+        return 0;
+}
+BOOL BasicManager::IsReference( USHORT nLib )
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    BasicLibInfo* pLibInfo = pLibs->GetObject( nLib );
+    DBG_ASSERT( pLibInfo, "Lib?!" );
+    if ( pLibInfo )
+        return pLibInfo->IsReference();
+
+    return FALSE;
+}
+
+BOOL BasicManager::RemoveLib( USHORT nLib )
+{
+    // Nur physikalisch loeschen, wenn keine Referenz.
+    return RemoveLib( nLib, !IsReference( nLib ) );
+}
+
+BOOL BasicManager::RemoveLib( USHORT nLib, BOOL bDelBasicFromStorage )
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+    DBG_ASSERT( nLib, "Standard-Lib kann nicht entfernt werden!" );
+
+    BasicLibInfo* pLibInfo = pLibs->GetObject( nLib );
+    DBG_ASSERT( pLibInfo, "Lib nicht gefunden!" );
+
+    if ( !pLibInfo || !nLib )
+    {
+//      String aErrorText( BasicResId( IDS_SBERR_REMOVELIB ) );
+        StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, String(), ERRCODE_BUTTON_OK );
+        pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_STDLIB, pLibInfo->GetLibName() ) );
+        return FALSE;
+    }
+
+    // Wenn einer der Streams nicht geoeffnet werden kann, ist es kein
+    // Fehler, es gibt halt noch nichts zum loeschen, weil das Basic noch
+    // nie geschrieben wurde...
+    if ( bDelBasicFromStorage && !pLibInfo->IsReference() &&
+            ( !pLibInfo->IsExtern() || SotStorage::IsStorageFile( pLibInfo->GetStorageName() ) ) )
+    {
+        SotStorageRef xStorage;
+        if ( !pLibInfo->IsExtern() )
+            xStorage = new SotStorage( FALSE, GetStorageName() );
+        else
+            xStorage = new SotStorage( FALSE, pLibInfo->GetStorageName() );
+
+        if ( xStorage->IsStorage( BasicStreamName ) )
+        {
+            SotStorageRef xBasicStorage = xStorage->OpenSotStorage
+                            ( BasicStreamName, STREAM_STD_READWRITE, FALSE );
+
+            if ( !xBasicStorage.Is() || xBasicStorage->GetError() )
+            {
+                StringErrorInfo* pErrInf = new StringErrorInfo( ERRCODE_BASMGR_REMOVELIB, String(), ERRCODE_BUTTON_OK );
+                pErrorMgr->InsertError( BasicError( *pErrInf, BASERR_REASON_OPENLIBSTORAGE, pLibInfo->GetLibName() ) );
+            }
+            else if ( xBasicStorage->IsStream( pLibInfo->GetLibName() ) )
+            {
+                xBasicStorage->Remove( pLibInfo->GetLibName() );
+                xBasicStorage->Commit();
+
+                // Wenn kein weiterer Stream vorhanden,
+                // dann auch den SubStorage loeschen.
+                SvStorageInfoList aInfoList;
+                xBasicStorage->FillInfoList( &aInfoList );
+                if ( aInfoList.empty() )
+                {
+                    xBasicStorage.Clear();
+                    xStorage->Remove( BasicStreamName );
+                    xStorage->Commit();
+                    // Wenn kein weiterer Streams oder SubStorages vorhanden,
+                    // dann auch den Storage loeschen.
+                    aInfoList.clear();
+                    xStorage->FillInfoList( &aInfoList );
+                    if ( aInfoList.empty() )
+                    {
+                        String aName_( xStorage->GetName() );
+                        xStorage.Clear();
+                    }
+                }
+            }
+        }
+    }
+    bBasMgrModified = TRUE;
+    if ( pLibInfo->GetLib().Is() )
+        GetStdLib()->Remove( pLibInfo->GetLib() );
+    delete pLibs->Remove( pLibInfo );
+    return TRUE;    // Remove hat geklappt, Del unwichtig.
+}
+
+USHORT BasicManager::GetLibCount() const
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+    return (USHORT)pLibs->Count();
+}
+
+StarBASIC* BasicManager::GetLib( USHORT nLib ) const
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+    BasicLibInfo* pInf = pLibs->GetObject( nLib );
+    DBG_ASSERT( pInf, "Lib existiert nicht!" );
+    if ( pInf )
+        return pInf->GetLib();
+    return 0;
+}
+
+StarBASIC* BasicManager::GetStdLib() const
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+    StarBASIC* pLib = GetLib( 0 );
+    return pLib;
+}
+
+StarBASIC* BasicManager::GetLib( const String& rName ) const
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    BasicLibInfo* pInf = pLibs->First();
+    while ( pInf )
+    {
+        if ( pInf->GetLibName().CompareIgnoreCaseToAscii( rName ) == COMPARE_EQUAL )        // prueffen, ob vorhanden...
+            return pInf->GetLib();
+
+        pInf = pLibs->Next();
+    }
+    return 0;
+}
+
+USHORT BasicManager::GetLibId( const String& rName ) const
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    BasicLibInfo* pInf = pLibs->First();
+    while ( pInf )
+    {
+        if ( pInf->GetLibName().CompareIgnoreCaseToAscii( rName ) == COMPARE_EQUAL )
+            return (USHORT)pLibs->GetCurPos();
+
+        pInf = pLibs->Next();
+    }
+    return LIB_NOTFOUND;
+}
+
+BOOL BasicManager::HasLib( const String& rName ) const
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    BasicLibInfo* pInf = pLibs->First();
+    while ( pInf )
+    {
+        if ( pInf->GetLibName().CompareIgnoreCaseToAscii( rName ) == COMPARE_EQUAL )
+            return TRUE;
+
+        pInf = pLibs->Next();
+    }
+    return FALSE;
+}
+
+BOOL BasicManager::SetLibName( USHORT nLib, const String& rName )
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    BasicLibInfo* pLibInfo = pLibs->GetObject( nLib );
+    DBG_ASSERT( pLibInfo, "Lib?!" );
+    if ( pLibInfo )
+    {
+        pLibInfo->SetLibName( rName );
+        if ( pLibInfo->GetLib().Is() )
+        {
+            StarBASICRef xStdLib = pLibInfo->GetLib();
+            xStdLib->SetName( rName );
+            xStdLib->SetModified( TRUE );
+        }
+        bBasMgrModified = TRUE;
+        return TRUE;
+    }
+    return FALSE;
+}
+
+String BasicManager::GetLibName( USHORT nLib )
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    BasicLibInfo* pLibInfo = pLibs->GetObject( nLib );
+    DBG_ASSERT( pLibInfo, "Lib?!" );
+    if ( pLibInfo )
+        return pLibInfo->GetLibName();
+    return String();
+}
+
+StarBASIC* BasicManager::CreateLib( const String& rLibName )
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+    if ( GetLib( rLibName ) )
+        return 0;
+
+    BasicLibInfo* pLibInfo = CreateLibInfo();
+    StarBASIC* pNew = new StarBASIC( GetStdLib() );
+    GetStdLib()->Insert( pNew );
+    pNew->SetFlag( SBX_EXTSEARCH | SBX_DONTSTORE );
+    pLibInfo->SetLib( pNew );
+    pLibInfo->SetLibName( rLibName );
+    pLibInfo->GetLib()->SetName( rLibName );
+    return pLibInfo->GetLib();
+}
+
+// For XML import/export:
+StarBASIC* BasicManager::CreateLib
+    ( const String& rLibName, const String& Password, const String& LinkTargetURL )
+{
+    // Ask if lib exists because standard lib is always there
+    StarBASIC* pLib = GetLib( rLibName );
+    if( !pLib )
+    {
+        if( LinkTargetURL.Len() != 0 )
+        {
+            SotStorageRef xStorage = new SotStorage( FALSE, LinkTargetURL, STREAM_READ | STREAM_SHARE_DENYWRITE );
+            if( !xStorage->GetError() )
+            {
+                pLib = AddLib( *xStorage, rLibName, TRUE );
+
+            }
+
+            DBG_ASSERT( pLib, "XML Import: Linked basic library could not be loaded");
+        }
+        else
+        {
+            pLib = CreateLib( rLibName );
+            if( Password.Len() != 0 )
+            {
+                BasicLibInfo* pLibInfo = FindLibInfo( pLib );
+                pLibInfo ->SetPassword( Password );
+            }
+        }
+        //ExternalSourceURL ?
+    }
+    return pLib;
+}
+
+StarBASIC* BasicManager::CreateLibForLibContainer( const String& rLibName,
+    const Reference< XLibraryContainer >& xScriptCont )
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+    if ( GetLib( rLibName ) )
+        return 0;
+
+    BasicLibInfo* pLibInfo = CreateLibInfo();
+    StarBASIC* pNew = new StarBASIC( GetStdLib() );
+    GetStdLib()->Insert( pNew );
+    pNew->SetFlag( SBX_EXTSEARCH | SBX_DONTSTORE );
+    pLibInfo->SetLib( pNew );
+    pLibInfo->SetLibName( rLibName );
+    pLibInfo->GetLib()->SetName( rLibName );
+    pLibInfo->SetLibraryContainer( xScriptCont );
+    return pNew;
+}
+
+
+BasicLibInfo* BasicManager::FindLibInfo( StarBASIC* pBasic ) const
+{
+    DBG_CHKTHIS( BasicManager, 0 );
+
+    BasicLibInfo* pInf = ((BasicManager*)this)->pLibs->First();
+    while ( pInf )
+    {
+        if ( pInf->GetLib() == pBasic )
+            return pInf;
+
+        pInf = ((BasicManager*)this)->pLibs->Next();
+    }
+    return 0;
+}
+
+//=====================================================================
+
+class ModuleInfo_Impl : public ModuleInfoHelper
+{
+    OUString maName;
+    OUString maLanguage;
+    OUString maSource;
+
+public:
+    ModuleInfo_Impl( const OUString& aName, const OUString& aLanguage, const OUString& aSource )
+        : maName( aName ), maLanguage( aLanguage), maSource( aSource ) {}
+
+    // Methods XStarBasicModuleInfo
+    virtual OUString SAL_CALL getName() throw(RuntimeException)
+        { return maName; }
+    virtual OUString SAL_CALL getLanguage() throw(RuntimeException)
+        { return maLanguage; }
+    virtual OUString SAL_CALL getSource() throw(RuntimeException)
+        { return maSource; }
+};
+
+
+//=====================================================================
+
+class DialogInfo_Impl : public DialogInfoHelper
+{
+    OUString maName;
+    Sequence< sal_Int8 > mData;
+
+public:
+    DialogInfo_Impl( const OUString& aName, Sequence< sal_Int8 > Data )
+        : maName( aName ), mData( Data ) {}
+
+    // Methods XStarBasicDialogInfo
+    virtual OUString SAL_CALL getName() throw(RuntimeException)
+        { return maName; }
+    virtual Sequence< sal_Int8 > SAL_CALL getData() throw(RuntimeException)
+        { return mData; }
+};
+
+
+//=====================================================================
+
+class LibraryInfo_Impl : public LibraryInfoHelper
+{
+    OUString maName;
+    Reference< XNameContainer > mxModuleContainer;
+    Reference< XNameContainer > mxDialogContainer;
+    OUString maPassword;
+    OUString maExternaleSourceURL;
+    OUString maLinkTargetURL;
+
+public:
+    LibraryInfo_Impl
+    (
+        const OUString& aName,
+        Reference< XNameContainer > xModuleContainer,
+        Reference< XNameContainer > xDialogContainer,
+        const OUString& aPassword,
+        const OUString& aExternaleSourceURL,
+        const OUString& aLinkTargetURL
+    )
+        : maName( aName )
+        , mxModuleContainer( xModuleContainer )
+        , mxDialogContainer( xDialogContainer )
+        , maPassword( aPassword )
+        , maExternaleSourceURL( aExternaleSourceURL )
+        , maLinkTargetURL( aLinkTargetURL )
+    {}
+
+    // Methods XStarBasicLibraryInfo
+    virtual OUString SAL_CALL getName() throw(RuntimeException)
+        { return maName; }
+    virtual Reference< XNameContainer > SAL_CALL getModuleContainer() throw(RuntimeException)
+        { return mxModuleContainer; }
+    virtual Reference< XNameContainer > SAL_CALL getDialogContainer() throw(RuntimeException)
+        { return mxDialogContainer; }
+    virtual OUString SAL_CALL getPassword() throw(RuntimeException)
+        { return maPassword; }
+    virtual OUString SAL_CALL getExternalSourceURL() throw(RuntimeException)
+        { return maExternaleSourceURL; }
+    virtual OUString SAL_CALL getLinkTargetURL() throw(RuntimeException)
+        { return maLinkTargetURL; }
+};
+
+//=====================================================================
+
+class ModuleContainer_Impl : public NameContainerHelper
+{
+    StarBASIC* mpLib;
+
+public:
+    ModuleContainer_Impl( StarBASIC* pLib )
+        :mpLib( pLib ) {}
+
+    // Methods XElementAccess
+    virtual Type SAL_CALL getElementType()
+        throw(RuntimeException);
+    virtual sal_Bool SAL_CALL hasElements()
+        throw(RuntimeException);
+
+    // Methods XNameAccess
+    virtual Any SAL_CALL getByName( const OUString& aName )
+        throw(NoSuchElementException, WrappedTargetException, RuntimeException);
+    virtual Sequence< OUString > SAL_CALL getElementNames()
+        throw(RuntimeException);
+    virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
+        throw(RuntimeException);
+
+    // Methods XNameReplace
+    virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement )
+        throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
+
+    // Methods XNameContainer
+    virtual void SAL_CALL insertByName( const OUString& aName, const Any& aElement )
+        throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException);
+    virtual void SAL_CALL removeByName( const OUString& Name )
+        throw(NoSuchElementException, WrappedTargetException, RuntimeException);
+};
+
+// Methods XElementAccess
+Type ModuleContainer_Impl::getElementType()
+    throw(RuntimeException)
+{
+    Type aModuleType = ::getCppuType( (const Reference< XStarBasicModuleInfo > *)0 );
+    return aModuleType;
+}
+
+sal_Bool ModuleContainer_Impl::hasElements()
+    throw(RuntimeException)
+{
+    SbxArray* pMods = mpLib ? mpLib->GetModules() : NULL;
+    return pMods && pMods->Count() > 0;
+}
+
+// Methods XNameAccess
+Any ModuleContainer_Impl::getByName( const OUString& aName )
+    throw(NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    SbModule* pMod = mpLib ? mpLib->FindModule( aName ) : NULL;
+    if( !pMod )
+        throw NoSuchElementException();
+    Reference< XStarBasicModuleInfo > xMod = (XStarBasicModuleInfo*)new ModuleInfo_Impl
+        ( aName, OUString( RTL_CONSTASCII_USTRINGPARAM( "StarBasic" )), pMod->GetSource32() );
+    Any aRetAny;
+    aRetAny <<= xMod;
+    return aRetAny;
+}
+
+Sequence< OUString > ModuleContainer_Impl::getElementNames()
+    throw(RuntimeException)
+{
+    SbxArray* pMods = mpLib ? mpLib->GetModules() : NULL;
+    USHORT nMods = pMods ? pMods->Count() : 0;
+    Sequence< OUString > aRetSeq( nMods );
+    OUString* pRetSeq = aRetSeq.getArray();
+    for( USHORT i = 0 ; i < nMods ; i++ )
+    {
+        SbxVariable* pMod = pMods->Get( i );
+        pRetSeq[i] = OUString( pMod->GetName() );
+    }
+    return aRetSeq;
+}
+
+sal_Bool ModuleContainer_Impl::hasByName( const OUString& aName )
+    throw(RuntimeException)
+{
+    SbModule* pMod = mpLib ? mpLib->FindModule( aName ) : NULL;
+    sal_Bool bRet = (pMod != NULL);
+    return bRet;
+}
+
+
+// Methods XNameReplace
+void ModuleContainer_Impl::replaceByName( const OUString& aName, const Any& aElement )
+    throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    removeByName( aName );
+    insertByName( aName, aElement );
+}
+
+
+// Methods XNameContainer
+void ModuleContainer_Impl::insertByName( const OUString& aName, const Any& aElement )
+    throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
+{
+    Type aModuleType = ::getCppuType( (const Reference< XStarBasicModuleInfo > *)0 );
+    Type aAnyType = aElement.getValueType();
+    if( aModuleType != aAnyType )
+        throw IllegalArgumentException();
+    Reference< XStarBasicModuleInfo > xMod;
+    aElement >>= xMod;
+    mpLib->MakeModule32( aName, xMod->getSource() );
+}
+
+void ModuleContainer_Impl::removeByName( const OUString& Name )
+    throw(NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    SbModule* pMod = mpLib ? mpLib->FindModule( Name ) : NULL;
+    if( !pMod )
+        throw NoSuchElementException();
+    mpLib->Remove( pMod );
+}
+
+
+//=====================================================================
+
+Sequence< sal_Int8 > implGetDialogData( SbxObject* pDialog )
+{
+    SvMemoryStream aMemStream;
+    pDialog->Store( aMemStream );
+    sal_Int32 nLen = aMemStream.Tell();
+    Sequence< sal_Int8 > aData( nLen );
+    sal_Int8* pDestData = aData.getArray();
+    const sal_Int8* pSrcData = (const sal_Int8*)aMemStream.GetData();
+    rtl_copyMemory( pDestData, pSrcData, nLen );
+    return aData;
+}
+
+SbxObject* implCreateDialog( Sequence< sal_Int8 > aData )
+{
+    sal_Int8* pData = aData.getArray();
+    SvMemoryStream aMemStream( pData, aData.getLength(), STREAM_READ );
+    SbxObject* pDialog = (SbxObject*)SbxBase::Load( aMemStream );
+    return pDialog;
+}
+
+// HACK! Because this value is defined in basctl/inc/vcsbxdef.hxx
+// which we can't include here, we have to use the value directly
+#define SBXID_DIALOG        101
+
+
+class DialogContainer_Impl : public NameContainerHelper
+{
+    StarBASIC* mpLib;
+
+public:
+    DialogContainer_Impl( StarBASIC* pLib )
+        :mpLib( pLib ) {}
+
+    // Methods XElementAccess
+    virtual Type SAL_CALL getElementType()
+        throw(RuntimeException);
+    virtual sal_Bool SAL_CALL hasElements()
+        throw(RuntimeException);
+
+    // Methods XNameAccess
+    virtual Any SAL_CALL getByName( const OUString& aName )
+        throw(NoSuchElementException, WrappedTargetException, RuntimeException);
+    virtual Sequence< OUString > SAL_CALL getElementNames()
+        throw(RuntimeException);
+    virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
+        throw(RuntimeException);
+
+    // Methods XNameReplace
+    virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement )
+        throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
+
+    // Methods XNameContainer
+    virtual void SAL_CALL insertByName( const OUString& aName, const Any& aElement )
+        throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException);
+    virtual void SAL_CALL removeByName( const OUString& Name )
+        throw(NoSuchElementException, WrappedTargetException, RuntimeException);
+};
+
+// Methods XElementAccess
+Type DialogContainer_Impl::getElementType()
+    throw(RuntimeException)
+{
+    Type aModuleType = ::getCppuType( (const Reference< XStarBasicDialogInfo > *)0 );
+    return aModuleType;
+}
+
+sal_Bool DialogContainer_Impl::hasElements()
+    throw(RuntimeException)
+{
+    sal_Bool bRet = sal_False;
+
+    mpLib->GetAll( SbxCLASS_OBJECT );
+    sal_Int16 nCount = mpLib->GetObjects()->Count();
+    for( sal_Int16 nObj = 0; nObj < nCount ; nObj++ )
+    {
+        SbxVariable* pVar = mpLib->GetObjects()->Get( nObj );
+        if ( pVar->ISA( SbxObject ) && ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) )
+        {
+            bRet = sal_True;
+            break;
+        }
+    }
+    return bRet;
+}
+
+// Methods XNameAccess
+Any DialogContainer_Impl::getByName( const OUString& aName )
+    throw(NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    SbxVariable* pVar = mpLib->GetObjects()->Find( aName, SbxCLASS_DONTCARE );
+    if( !( pVar && pVar->ISA( SbxObject ) &&
+           ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) ) )
+    {
+        throw NoSuchElementException();
+    }
+
+    Reference< XStarBasicDialogInfo > xDialog =
+        (XStarBasicDialogInfo*)new DialogInfo_Impl
+            ( aName, implGetDialogData( (SbxObject*)pVar ) );
+
+    Any aRetAny;
+    aRetAny <<= xDialog;
+    return aRetAny;
+}
+
+Sequence< OUString > DialogContainer_Impl::getElementNames()
+    throw(RuntimeException)
+{
+    mpLib->GetAll( SbxCLASS_OBJECT );
+    sal_Int16 nCount = mpLib->GetObjects()->Count();
+    Sequence< OUString > aRetSeq( nCount );
+    OUString* pRetSeq = aRetSeq.getArray();
+    sal_Int32 nDialogCounter = 0;
+
+    for( sal_Int16 nObj = 0; nObj < nCount ; nObj++ )
+    {
+        SbxVariable* pVar = mpLib->GetObjects()->Get( nObj );
+        if ( pVar->ISA( SbxObject ) && ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) )
+        {
+            pRetSeq[ nDialogCounter ] = OUString( pVar->GetName() );
+            nDialogCounter++;
+        }
+    }
+    aRetSeq.realloc( nDialogCounter );
+    return aRetSeq;
+}
+
+sal_Bool DialogContainer_Impl::hasByName( const OUString& aName )
+    throw(RuntimeException)
+{
+    sal_Bool bRet = sal_False;
+    SbxVariable* pVar = mpLib->GetObjects()->Find( aName, SbxCLASS_DONTCARE );
+    if( pVar && pVar->ISA( SbxObject ) &&
+           ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) )
+    {
+        bRet = sal_True;
+    }
+    return bRet;
+}
+
+
+// Methods XNameReplace
+void DialogContainer_Impl::replaceByName( const OUString& aName, const Any& aElement )
+    throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    removeByName( aName );
+    insertByName( aName, aElement );
+}
+
+
+// Methods XNameContainer
+void DialogContainer_Impl::insertByName( const OUString& aName, const Any& aElement )
+    throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
+{
+    (void)aName;
+    Type aModuleType = ::getCppuType( (const Reference< XStarBasicDialogInfo > *)0 );
+    Type aAnyType = aElement.getValueType();
+    if( aModuleType != aAnyType )
+        throw IllegalArgumentException();
+    Reference< XStarBasicDialogInfo > xMod;
+    aElement >>= xMod;
+    SbxObjectRef xDialog = implCreateDialog( xMod->getData() );
+    mpLib->Insert( xDialog );
+}
+
+void DialogContainer_Impl::removeByName( const OUString& Name )
+    throw(NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    (void)Name;
+    SbxVariable* pVar = mpLib->GetObjects()->Find( Name, SbxCLASS_DONTCARE );
+    if( !( pVar && pVar->ISA( SbxObject ) &&
+           ( ((SbxObject*)pVar)->GetSbxId() == SBXID_DIALOG ) ) )
+    {
+        throw NoSuchElementException();
+    }
+    mpLib->Remove( pVar );
+}
+
+
+//=====================================================================
+
+
+class LibraryContainer_Impl : public NameContainerHelper
+{
+    BasicManager* mpMgr;
+
+public:
+    LibraryContainer_Impl( BasicManager* pMgr )
+        :mpMgr( pMgr ) {}
+
+    // Methods XElementAccess
+    virtual Type SAL_CALL getElementType()
+        throw(RuntimeException);
+    virtual sal_Bool SAL_CALL hasElements()
+        throw(RuntimeException);
+
+    // Methods XNameAccess
+    virtual Any SAL_CALL getByName( const OUString& aName )
+        throw(NoSuchElementException, WrappedTargetException, RuntimeException);
+    virtual Sequence< OUString > SAL_CALL getElementNames()
+        throw(RuntimeException);
+    virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
+        throw(RuntimeException);
+
+    // Methods XNameReplace
+    virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement )
+        throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException);
+
+    // Methods XNameContainer
+    virtual void SAL_CALL insertByName( const OUString& aName, const Any& aElement )
+        throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException);
+    virtual void SAL_CALL removeByName( const OUString& Name )
+        throw(NoSuchElementException, WrappedTargetException, RuntimeException);
+};
+
+
+// Methods XElementAccess
+Type LibraryContainer_Impl::getElementType()
+    throw(RuntimeException)
+{
+    Type aType = ::getCppuType( (const Reference< XStarBasicLibraryInfo > *)0 );
+    return aType;
+}
+
+sal_Bool LibraryContainer_Impl::hasElements()
+    throw(RuntimeException)
+{
+    sal_Int32 nLibs = mpMgr->GetLibCount();
+    sal_Bool bRet = (nLibs > 0);
+    return bRet;
+}
+
+// Methods XNameAccess
+Any LibraryContainer_Impl::getByName( const OUString& aName )
+    throw(NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    Any aRetAny;
+    if( !mpMgr->HasLib( aName ) )
+        throw NoSuchElementException();
+    StarBASIC* pLib = mpMgr->GetLib( aName );
+
+    Reference< XNameContainer > xModuleContainer =
+        (XNameContainer*)new ModuleContainer_Impl( pLib );
+
+    Reference< XNameContainer > xDialogContainer =
+        (XNameContainer*)new DialogContainer_Impl( pLib );
+
+    BasicLibInfo* pLibInfo = mpMgr->FindLibInfo( pLib );
+
+    OUString aPassword = pLibInfo->GetPassword();
+
+    // TODO Nur extern-Info liefern!
+    OUString aExternaleSourceURL;
+    OUString aLinkTargetURL;
+    if( pLibInfo->IsReference() )
+        aLinkTargetURL = pLibInfo->GetStorageName();
+    else if( pLibInfo->IsExtern() )
+        aExternaleSourceURL = pLibInfo->GetStorageName();
+
+    Reference< XStarBasicLibraryInfo > xLibInfo = new LibraryInfo_Impl
+    (
+        aName,
+        xModuleContainer,
+        xDialogContainer,
+        aPassword,
+        aExternaleSourceURL,
+        aLinkTargetURL
+    );
+
+    aRetAny <<= xLibInfo;
+    return aRetAny;
+}
+
+Sequence< OUString > LibraryContainer_Impl::getElementNames()
+    throw(RuntimeException)
+{
+    USHORT nLibs = mpMgr->GetLibCount();
+    Sequence< OUString > aRetSeq( nLibs );
+    OUString* pRetSeq = aRetSeq.getArray();
+    for( USHORT i = 0 ; i < nLibs ; i++ )
+    {
+        pRetSeq[i] = OUString( mpMgr->GetLibName( i ) );
+    }
+    return aRetSeq;
+}
+
+sal_Bool LibraryContainer_Impl::hasByName( const OUString& aName )
+    throw(RuntimeException)
+{
+    sal_Bool bRet = mpMgr->HasLib( aName );
+    return bRet;
+}
+
+// Methods XNameReplace
+void LibraryContainer_Impl::replaceByName( const OUString& aName, const Any& aElement )
+    throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    removeByName( aName );
+    insertByName( aName, aElement );
+}
+
+// Methods XNameContainer
+void LibraryContainer_Impl::insertByName( const OUString& aName, const Any& aElement )
+    throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
+{
+    (void)aName;
+    (void)aElement;
+    // TODO: Insert a complete Library?!
+}
+
+void LibraryContainer_Impl::removeByName( const OUString& Name )
+    throw(NoSuchElementException, WrappedTargetException, RuntimeException)
+{
+    StarBASIC* pLib = mpMgr->GetLib( Name );
+    if( !pLib )
+        throw NoSuchElementException();
+    USHORT nLibId = mpMgr->GetLibId( Name );
+    mpMgr->RemoveLib( nLibId );
+}
+
+//=====================================================================
+
+typedef WeakImplHelper1< XStarBasicAccess > StarBasicAccessHelper;
+
+
+class StarBasicAccess_Impl : public StarBasicAccessHelper
+{
+    BasicManager* mpMgr;
+    Reference< XNameContainer > mxLibContainer;
+
+public:
+    StarBasicAccess_Impl( BasicManager* pMgr )
+        :mpMgr( pMgr ) {}
+
+public:
+
+    // Methods
+    virtual Reference< XNameContainer > SAL_CALL getLibraryContainer()
+        throw(RuntimeException);
+    virtual void SAL_CALL createLibrary( const OUString& LibName, const OUString& Password,
+        const OUString& ExternalSourceURL, const OUString& LinkTargetURL )
+            throw(ElementExistException, RuntimeException);
+    virtual void SAL_CALL addModule( const OUString& LibraryName, const OUString& ModuleName,
+        const OUString& Language, const OUString& Source )
+            throw(NoSuchElementException, RuntimeException);
+    virtual void SAL_CALL addDialog( const OUString& LibraryName, const OUString& DialogName,
+        const Sequence< sal_Int8 >& Data )
+            throw(NoSuchElementException, RuntimeException);
+
+};
+
+Reference< XNameContainer > SAL_CALL StarBasicAccess_Impl::getLibraryContainer()
+    throw(RuntimeException)
+{
+    if( !mxLibContainer.is() )
+        mxLibContainer = (XNameContainer*)new LibraryContainer_Impl( mpMgr );
+    return mxLibContainer;
+}
+
+void SAL_CALL StarBasicAccess_Impl::createLibrary
+(
+    const OUString& LibName,
+    const OUString& Password,
+    const OUString& ExternalSourceURL,
+    const OUString& LinkTargetURL
+)
+    throw(ElementExistException, RuntimeException)
+{
+    (void)ExternalSourceURL;
+#ifdef DBG_UTIL
+    StarBASIC* pLib =
+#endif
+    mpMgr->CreateLib( LibName, Password, LinkTargetURL );
+    DBG_ASSERT( pLib, "XML Import: Basic library could not be created");
+}
+
+void SAL_CALL StarBasicAccess_Impl::addModule
+(
+    const OUString& LibraryName,
+    const OUString& ModuleName,
+    const OUString& Language,
+    const OUString& Source
+)
+    throw(NoSuchElementException, RuntimeException)
+{
+    (void)Language;
+    StarBASIC* pLib = mpMgr->GetLib( LibraryName );
+    DBG_ASSERT( pLib, "XML Import: Lib for module unknown");
+    if( pLib )
+        pLib->MakeModule32( ModuleName, Source );
+}
+
+void SAL_CALL StarBasicAccess_Impl::addDialog
+(
+    const OUString& LibraryName,
+    const OUString& DialogName,
+    const Sequence< sal_Int8 >& Data
+)
+    throw(NoSuchElementException, RuntimeException)
+{
+    (void)LibraryName;
+    (void)DialogName;
+    (void)Data;
+}
+
+// Basic XML Import/Export
+Reference< XStarBasicAccess > getStarBasicAccess( BasicManager* pMgr )
+{
+    Reference< XStarBasicAccess > xRet =
+        new StarBasicAccess_Impl( (BasicManager*)pMgr );
+    return xRet;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/bf_basic/source/basmgr/makefile.mk b/bf_basic/source/basmgr/makefile.mk
new file mode 100644
index 0000000..c0b5bd2
--- /dev/null
+++ b/bf_basic/source/basmgr/makefile.mk
@@ -0,0 +1,40 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+#   Licensed to the Apache Software Foundation (ASF) under one or more
+#   contributor license agreements. See the NOTICE file distributed
+#   with this work for additional information regarding copyright
+#   ownership. The ASF licenses this file to you under the Apache
+#   License, Version 2.0 (the "License"); you may not use this file
+#   except in compliance with the License. You may obtain a copy of
+#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+PRJ=..$/..$/..
+
+PRJNAME=binfilter
+TARGET=basic_basicmgr
+ENABLE_EXCEPTIONS=TRUE
+
+NO_HIDS=TRUE
+
+# --- Settings -----------------------------------------------------------
+
+.INCLUDE :  settings.mk
+
+INC+= -I$(PRJ)$/inc$/bf_basic
+
+# --- Allgemein -----------------------------------------------------------
+
+SLOFILES= \
+        $(SLO)$/basmgr.obj
+
+# --- Targets -------------------------------------------------------------
+
+.INCLUDE :  target.mk
diff --git a/bf_basic/source/classes/image.cxx b/bf_basic/source/classes/image.cxx
new file mode 100644
index 0000000..cda562b
--- /dev/null
+++ b/bf_basic/source/classes/image.cxx
@@ -0,0 +1,268 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <tools/stream.hxx>
+#include <tools/tenccvt.hxx>
+#include "sbx.hxx"
+#include "sb.hxx"
+#include <string.h>     // memset() etc
+#include "image.hxx"
+#include "codegen.hxx"
+
+namespace binfilter {
+
+SbiImage::SbiImage()
+{
+    pStringOff = NULL;
+    pStrings   = NULL;
+    pCode      = NULL;
+    pLegacyPCode       = NULL;
+    nFlags     = 0;
+    nStrings   = 0;
+    nStringSize= 0;
+    nCodeSize  = 0;
+    nLegacyCodeSize  =
+    nDimBase   = 0;
+    bInit      =
+    bError     = FALSE;
+    bFirstInit = TRUE;
+    eCharSet   = osl_getThreadTextEncoding();
+}
+
+SbiImage::~SbiImage()
+{
+    Clear();
+}
+
+void SbiImage::Clear()
+{
+    delete[] pStringOff;
+    delete[] pStrings;
+    delete[] pCode;
+    ReleaseLegacyBuffer();
+    pStringOff = NULL;
+    pStrings   = NULL;
+    pCode      = NULL;
+    nFlags     = 0;
+    nStrings   = 0;
+    nStringSize= 0;
+    nLegacyCodeSize  = 0;
+    nCodeSize  = 0;
+    eCharSet   = osl_getThreadTextEncoding();
+    nDimBase   = 0;
+    bError     = FALSE;
+}
+
+/**************************************************************************
+*
+*   Service routes for saving and loading
+*
+**************************************************************************/
+
+BOOL SbiGood( SvStream& r )
+{
+    return BOOL( !r.IsEof() && r.GetError() == SVSTREAM_OK );
+}
+
+BOOL SbiImage::Load( SvStream& r, UINT32& nVersion )
+{
+
+    UINT16 nSign, nCount;
+    UINT32 nLen, nOff;
+
+    Clear();
+    // Master-Record einlesen
+    r >> nSign >> nLen >> nCount;
+    ULONG nLast = r.Tell() + nLen;
+    UINT32 nCharSet;                // System-Zeichensatz
+    UINT32 lDimBase;
+    UINT16 nReserved1;
+    UINT32 nReserved2;
+    UINT32 nReserved3;
+    BOOL bBadVer = FALSE;
+    if( nSign == B_MODULE )
+    {
+        r >> nVersion >> nCharSet >> lDimBase
+          >> nFlags >> nReserved1 >> nReserved2 >> nReserved3;
+        eCharSet = (CharSet) nCharSet;
+        eCharSet = GetSOLoadTextEncoding( eCharSet );
+        bBadVer  = BOOL( nVersion > B_CURVERSION );
+        nDimBase = (USHORT) lDimBase;
+    }
+
+    bool bLegacy = ( nVersion < B_EXT_IMG_VERSION );
+
+    ULONG nNext;
+    while( ( nNext = r.Tell() ) < nLast )
+    {
+        short i;
+
+        r >> nSign >> nLen >> nCount;
+        nNext += nLen + 8;
+        if( r.GetError() == SVSTREAM_OK )
+          switch( nSign )
+        {
+            case B_NAME:
+                aName = r.ReadUniOrByteString( eCharSet );
+                break;
+            case B_COMMENT:
+                aComment = r.ReadUniOrByteString( eCharSet );
+                break;
+            case B_SOURCE:
+            {
+                aOUSource = r.ReadUniOrByteString( eCharSet );
+                break;
+            }
+            case B_EXTSOURCE:
+            {
+                for( UINT16 j = 0 ; j < nCount ; j++ )
+                {
+                    String aTmp = r.ReadUniOrByteString( eCharSet );
+                    aOUSource += aTmp;
+                }
+                break;
+            }
+            case B_PCODE:
+                if( bBadVer ) break;
+                pCode = new char[ nLen ];
+                nCodeSize = nLen;
+                r.Read( pCode, nCodeSize );
+                if ( bLegacy )
+                {
+                    ReleaseLegacyBuffer(); // release any previously held buffer
+                    nLegacyCodeSize = (UINT16) nCodeSize;
+                    pLegacyPCode = pCode;
+
+                    PCodeBuffConvertor< UINT16, UINT32 > aLegacyToNew( (BYTE*)pLegacyPCode, nLegacyCodeSize );
+                    aLegacyToNew.convert();
+                    pCode = (char*)aLegacyToNew.GetBuffer();
+                    nCodeSize = aLegacyToNew.GetSize();
+                    // we don't release the legacy buffer
+                    // right now, thats because the module
+                    // needs it to fix up the method
+                    // nStart members. When that is done
+                    // the module can release the buffer
+                    // or it can wait until this routine
+                    // is called again or when this class                       // destructs all of which will trigger
+                    // release of the buffer.
+                }
+                break;
+            case B_PUBLICS:
+            case B_POOLDIR:
+            case B_SYMPOOL:
+            case B_LINERANGES:
+                break;
+            case B_STRINGPOOL:
+                if( bBadVer ) break;
+                MakeStrings( nCount );
+                for( i = 0; i < nStrings && SbiGood( r ); i++ )
+                {
+                    r >> nOff;
+                    pStringOff[ i ] = (USHORT) nOff;
+                }
+                r >> nLen;
+                if( SbiGood( r ) )
+                {
+                    delete [] pStrings;
+                    pStrings = new sal_Unicode[ nLen ];
+                    nStringSize = (USHORT) nLen;
+
+                    char* pByteStrings = new char[ nLen ];
+                    r.Read( pByteStrings, nStringSize );
+                    for( short j = 0; j < nStrings; j++ )
+                    {
+                        USHORT nOff2 = (USHORT) pStringOff[ j ];
+                        String aStr( pByteStrings + nOff2, eCharSet );
+                        memcpy( pStrings + nOff2, aStr.GetBuffer(), (aStr.Len() + 1) * sizeof( sal_Unicode ) );
+                    }
+                    delete[] pByteStrings;
+                } break;
+            case B_MODEND:
+                goto done;
+            default:
+                break;
+        }
+        else
+            break;
+        r.Seek( nNext );
+    }
+done:
+    r.Seek( nLast );
+    if( !SbiGood( r ) )
+        bError = TRUE;
+    return BOOL( !bError );
+}
+
+/**************************************************************************
+*
+*   Routinen, die auch vom Compiler gerufen werden
+*
+**************************************************************************/
+
+void SbiImage::MakeStrings( short nSize )
+{
+    nStrings = 0;
+    nStringIdx = 0;
+    nStringOff = 0;
+    nStringSize = 1024;
+    pStrings = new sal_Unicode[ nStringSize ];
+    pStringOff = new UINT32[ nSize ];
+    if( pStrings && pStringOff )
+    {
+        nStrings = nSize;
+        memset( pStringOff, 0, nSize * sizeof( UINT32 ) );
+        memset( pStrings, 0, nStringSize * sizeof( sal_Unicode ) );
+    }
+    else
+        bError = TRUE;
+}
+
+/**************************************************************************
+*
+*   Zugriffe auf das Image
+*
+**************************************************************************/
+
+const SbxObject* SbiImage::FindType (String aTypeName) const
+{
+    return rTypes.Is() ? (SbxObject*)rTypes->Find(aTypeName,SbxCLASS_OBJECT) : NULL;
+}
+
+UINT16
+SbiImage::CalcLegacyOffset( INT32 nOffset )
+{
+    return SbiCodeGen::calcLegacyOffSet( (BYTE*)pCode, nOffset ) ;
+}
+UINT32
+SbiImage::CalcNewOffset( INT16 nOffset )
+{
+    return SbiCodeGen::calcNewOffSet( (BYTE*)pLegacyPCode, nOffset ) ;
+}
+
+void
+SbiImage::ReleaseLegacyBuffer()
+{
+    delete[] pLegacyPCode;
+    pLegacyPCode = NULL;
+    nLegacyCodeSize = 0;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/bf_basic/source/classes/makefile.mk b/bf_basic/source/classes/makefile.mk
new file mode 100644
index 0000000..3c6f90d
--- /dev/null
+++ b/bf_basic/source/classes/makefile.mk
@@ -0,0 +1,50 @@
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This file incorporates work covered by the following license notice:
+#
+#   Licensed to the Apache Software Foundation (ASF) under one or more
+#   contributor license agreements. See the NOTICE file distributed
+#   with this work for additional information regarding copyright
+#   ownership. The ASF licenses this file to you under the Apache
+#   License, Version 2.0 (the "License"); you may not use this file
+#   except in compliance with the License. You may obtain a copy of
+#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+#
+
+PRJ=..$/..$/..
+
+PRJNAME=binfilter
+TARGET=basic_classes
+
+NO_HIDS=TRUE
+
+# --- Settings -----------------------------------------------------------
+
+ENABLE_EXCEPTIONS=TRUE
+
+.INCLUDE :  settings.mk
+
+INC+= -I$(PRJ)$/inc$/bf_basic
+
+# --- Allgemein -----------------------------------------------------------
+
+SLOFILES=\
+    $(SLO)$/sb.obj       \
+    $(SLO)$/sbxmod.obj  \
+    $(SLO)$/sbunoobj.obj    \
+    $(SLO)$/image.obj   \
+    $(SLO)$/sbintern.obj    \
+
+#    $(SLO)$/propacc.obj \
+    $(SLO)$/disas.obj \
+    $(SLO)$/eventatt.obj
+
+# --- Targets -------------------------------------------------------------
+
+.INCLUDE :  target.mk
+
diff --git a/bf_basic/source/classes/sb.cxx b/bf_basic/source/classes/sb.cxx
new file mode 100644
index 0000000..11ab493
--- /dev/null
+++ b/bf_basic/source/classes/sb.cxx
@@ -0,0 +1,1346 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <stdio.h>
+
+#include "sb.hxx"
+#include <tools/rcid.h>
+#include <tools/config.hxx>
+
+#include <tools/stream.hxx>
+#ifndef __RSC //autogen
+#include <tools/errinf.hxx>
+#endif
+#include <sbx.hxx>
+#include <tools/rc.hxx>
+#include <vcl/svapp.hxx>
+#include "sbunoobj.hxx"
+#include "sbjsmeth.hxx"
+#include "sbjsmod.hxx"
+#include "sbintern.hxx"
+#include "image.hxx"
+#include "filefmt.hxx"
+
+#include <osl/mutex.hxx>
+
+namespace binfilter {
+
+TYPEINIT1(StarBASIC,SbxObject)
+
+#define RTLNAME "@SBRTL"
+
+
+//========================================================================
+// Array zur Umrechnung SFX <-> VB-Fehlercodes anlegen
+
+struct SFX_VB_ErrorItem
+{
+    USHORT  nErrorVB;
+    SbError nErrorSFX;
+};
+
+const SFX_VB_ErrorItem SFX_VB_ErrorTab[] =
+{
+    { 1, SbERR_BASIC_EXCEPTION },  // #87844 Map exception to error code 1
+    { 2, SbERR_SYNTAX },
+    { 3, SbERR_NO_GOSUB },
+    { 4, SbERR_REDO_FROM_START },
+    { 5, SbERR_BAD_ARGUMENT },
+    { 6, SbERR_MATH_OVERFLOW },
+    { 7, SbERR_NO_MEMORY },
+    { 8, SbERR_ALREADY_DIM },
+    { 9, SbERR_OUT_OF_RANGE },
+    { 10, SbERR_DUPLICATE_DEF },
+    { 11, SbERR_ZERODIV },
+    { 12, SbERR_VAR_UNDEFINED },
+    { 13, SbERR_CONVERSION },
+    { 14, SbERR_BAD_PARAMETER },
+    { 18, SbERR_USER_ABORT },
+    { 20, SbERR_BAD_RESUME },
+    { 28, SbERR_STACK_OVERFLOW },
+    { 35, SbERR_PROC_UNDEFINED },
+    { 48, SbERR_BAD_DLL_LOAD },
+    { 49, SbERR_BAD_DLL_CALL },
+    { 51, SbERR_INTERNAL_ERROR },
+    { 52, SbERR_BAD_CHANNEL },
+    { 53, SbERR_FILE_NOT_FOUND },
+    { 54, SbERR_BAD_FILE_MODE },
+    { 55, SbERR_FILE_ALREADY_OPEN },
+    { 57, SbERR_IO_ERROR },
+    { 58, SbERR_FILE_EXISTS },
+    { 59, SbERR_BAD_RECORD_LENGTH },
+    { 61, SbERR_DISK_FULL },
+    { 62, SbERR_READ_PAST_EOF },
+    { 63, SbERR_BAD_RECORD_NUMBER },
+    { 67, SbERR_TOO_MANY_FILES },
+    { 68, SbERR_NO_DEVICE },
+    { 70, SbERR_ACCESS_DENIED },
+    { 71, SbERR_NOT_READY },
+    { 73, SbERR_NOT_IMPLEMENTED },
+    { 74, SbERR_DIFFERENT_DRIVE },
+    { 75, SbERR_ACCESS_ERROR },
+    { 76, SbERR_PATH_NOT_FOUND },
+    { 91, SbERR_NO_OBJECT },
+    { 93, SbERR_BAD_PATTERN },
+    { 94, SBERR_IS_NULL },
+    { 250, SbERR_DDE_ERROR },
+    { 280, SbERR_DDE_WAITINGACK },
+    { 281, SbERR_DDE_OUTOFCHANNELS },
+    { 282, SbERR_DDE_NO_RESPONSE },
+    { 283, SbERR_DDE_MULT_RESPONSES },
+    { 284, SbERR_DDE_CHANNEL_LOCKED },
+    { 285, SbERR_DDE_NOTPROCESSED },
+    { 286, SbERR_DDE_TIMEOUT },
+    { 287, SbERR_DDE_USER_INTERRUPT },
+    { 288, SbERR_DDE_BUSY },
+    { 289, SbERR_DDE_NO_DATA },
+    { 290, SbERR_DDE_WRONG_DATA_FORMAT },
+    { 291, SbERR_DDE_PARTNER_QUIT },
+    { 292, SbERR_DDE_CONV_CLOSED },
+    { 293, SbERR_DDE_NO_CHANNEL },
+    { 294, SbERR_DDE_INVALID_LINK },
+    { 295, SbERR_DDE_QUEUE_OVERFLOW },
+    { 296, SbERR_DDE_LINK_ALREADY_EST },
+    { 297, SbERR_DDE_LINK_INV_TOPIC },
+    { 298, SbERR_DDE_DLL_NOT_FOUND },
+    { 323, SbERR_CANNOT_LOAD },
+    { 341, SbERR_BAD_INDEX },
+    { 366, SbERR_NO_ACTIVE_OBJECT },
+    { 380, SbERR_BAD_PROP_VALUE },
+    { 382, SbERR_PROP_READONLY },
+    { 394, SbERR_PROP_WRITEONLY },
+    { 420, SbERR_INVALID_OBJECT },
+    { 423, SbERR_NO_METHOD },
+    { 424, SbERR_NEEDS_OBJECT },
+    { 425, SbERR_INVALID_USAGE_OBJECT },
+    { 430, SbERR_NO_OLE },
+    { 438, SbERR_BAD_METHOD },
+    { 440, SbERR_OLE_ERROR },
+    { 445, SbERR_BAD_ACTION },
+    { 446, SbERR_NO_NAMED_ARGS },
+    { 447, SbERR_BAD_LOCALE },
+    { 448, SbERR_NAMED_NOT_FOUND },
+    { 449, SbERR_NOT_OPTIONAL },
+    { 450, SbERR_WRONG_ARGS },
+    { 451, SbERR_NOT_A_COLL },
+    { 452, SbERR_BAD_ORDINAL },
+    { 453, SbERR_DLLPROC_NOT_FOUND },
+    { 460, SbERR_BAD_CLIPBD_FORMAT },
+    { 951, SbERR_UNEXPECTED },
+    { 952, SbERR_EXPECTED },
+    { 953, SbERR_SYMBOL_EXPECTED },
+    { 954, SbERR_VAR_EXPECTED },
+    { 955, SbERR_LABEL_EXPECTED },
+    { 956, SbERR_LVALUE_EXPECTED },
+    { 957, SbERR_VAR_DEFINED },
+    { 958, SbERR_PROC_DEFINED },
+    { 959, SbERR_LABEL_DEFINED },
+    { 960, SbERR_UNDEF_VAR },
+    { 961, SbERR_UNDEF_ARRAY },
+    { 962, SbERR_UNDEF_PROC },
+    { 963, SbERR_UNDEF_LABEL },
+    { 964, SbERR_UNDEF_TYPE },
+    { 965, SbERR_BAD_EXIT },
+    { 966, SbERR_BAD_BLOCK },
+    { 967, SbERR_BAD_BRACKETS },
+    { 968, SbERR_BAD_DECLARATION },
+    { 969, SbERR_BAD_PARAMETERS },
+    { 970, SbERR_BAD_CHAR_IN_NUMBER },
+    { 971, SbERR_MUST_HAVE_DIMS },
+    { 972, SbERR_NO_IF },
+    { 973, SbERR_NOT_IN_SUBR },
+    { 974, SbERR_NOT_IN_MAIN },
+    { 975, SbERR_WRONG_DIMS },
+    { 976, SbERR_BAD_OPTION },
+    { 977, SbERR_CONSTANT_REDECLARED },
+    { 978, SbERR_PROG_TOO_LARGE },
+    { 979, SbERR_NO_STRINGS_ARRAYS },
+    { 1000, SbERR_PROPERTY_NOT_FOUND },
+    { 1001, SbERR_METHOD_NOT_FOUND },
+    { 1002, SbERR_ARG_MISSING },
+    { 1003, SbERR_BAD_NUMBER_OF_ARGS },
+    { 1004, SbERR_METHOD_FAILED },
+    { 1005, SbERR_SETPROP_FAILED },
+    { 1006, SbERR_GETPROP_FAILED },
+    { 0xFFFF, 0xFFFFFFFFL }     // End-Marke
+};
+
+
+////////////////////////////////////////////////////////////////////////////
+
+// Die StarBASIC-Factory hat einen Hack. Wenn ein SbModule eingerichtet wird,
+// wird der Pointer gespeichert und an nachfolgende SbProperties/SbMethods
+// uebergeben. Dadurch wird die Modul-Relationship wiederhergestellt. Das
+// klappt aber nur, wenn ein Modul geladen wird. Fuer getrennt geladene
+// Properties kann es Probleme geben!
+
+SbxBase* SbiFactory::Create( UINT16 nSbxId, UINT32 nCreator )
+{
+    if( nCreator ==  SBXCR_SBX )
+    {
+        String aEmpty;
+        switch( nSbxId )
+        {
+            case SBXID_BASIC:
+                return new StarBASIC( NULL );
+            case SBXID_BASICMOD:
+                return new SbModule( aEmpty );
+            case SBXID_BASICPROP:
+                return new SbProperty( aEmpty, SbxVARIANT, NULL );
+            case SBXID_BASICMETHOD:
+                return new SbMethod( aEmpty, SbxVARIANT, NULL );
+            case SBXID_JSCRIPTMOD:
+                return new SbJScriptModule( aEmpty );
+            case SBXID_JSCRIPTMETH:
+                return new SbJScriptMethod( aEmpty, SbxVARIANT, NULL );
+        }
+    }
+    return NULL;
+}
+
+SbxObject* SbiFactory::CreateObject( const String& rClass )
+{
+    if( rClass.EqualsIgnoreCaseAscii( "StarBASIC" ) )
+        return new StarBASIC( NULL );
+    else
+    if( rClass.EqualsIgnoreCaseAscii( "StarBASICModule" ) )
+    {
+        String aEmpty;
+        return new SbModule( aEmpty );
+    }
+    else
+    if( rClass.EqualsIgnoreCaseAscii( "Collection" ) )
+    {
+        String aCollectionName( RTL_CONSTASCII_USTRINGPARAM("Collection") );
+        return new BasicCollection( aCollectionName );
+    }
+    else
+        return NULL;
+}
+
+
+// Factory class to create OLE objects
+class SbOLEFactory : public SbxFactory
+{
+public:
+    virtual SbxBase* Create( UINT16 nSbxId, UINT32 = SBXCR_SBX );
+    virtual SbxObject* CreateObject( const String& );
+};
+
+SbxBase* SbOLEFactory::Create( UINT16, UINT32 )
+{
+    // Not supported
+    return NULL;
+}
+
+SbUnoObject* createOLEObject_Impl( const String& aType );   // sbunoobj.cxx
+
+SbxObject* SbOLEFactory::CreateObject( const String& rClassName )
+{
+    SbxObject* pRet = createOLEObject_Impl( rClassName );
+    return pRet;
+}
+
+
+// Factory class to create user defined objects (type command)
+class SbTypeFactory : public SbxFactory
+{
+    SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj );
+
+public:
+    virtual SbxBase* Create( UINT16 nSbxId, UINT32 = SBXCR_SBX );
+    virtual SbxObject* CreateObject( const String& );
+};
+
+SbxBase* SbTypeFactory::Create( UINT16, UINT32 )
+{
+    // Not supported
+    return NULL;
+}
+
+SbxObject* SbTypeFactory::cloneTypeObjectImpl( const SbxObject& rTypeObj )
+{
+    SbxObject* pRet = new SbxObject( rTypeObj );
+    pRet->PutObject( pRet );
+
+    // Copy the properties, not only the reference to them
+    SbxArray* pProps = pRet->GetProperties();
+    UINT32 nCount = pProps->Count32();
+    for( UINT32 i = 0 ; i < nCount ; i++ )
+    {
+        SbxVariable* pVar = pProps->Get32( i );
+        SbxProperty* pProp = PTR_CAST( SbxProperty, pVar );
+        if( pProp )
+        {
+            SbxProperty* pNewProp = new SbxProperty( *pProp );
+            pProps->PutDirect( pNewProp, i );
+        }
+    }
+    return pRet;
+}
+
+SbxObject* SbTypeFactory::CreateObject( const String& rClassName )
+{
+    SbxObject* pRet = NULL;
+    SbModule* pMod = pMOD;
+    if( pMod )
+    {
+        const SbxObject* pObj = pMod->FindType( rClassName );
+        if( pObj )
+            pRet = cloneTypeObjectImpl( *pObj );
+    }
+    return pRet;
+}
+
+TYPEINIT1(SbClassModuleObject,SbModule)
+
+SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
+    : SbModule( pClassModule->GetName() )
+    , mpClassModule( pClassModule )
+    , mbInitializeEventDone( false )
+{
+    aOUSource = pClassModule->aOUSource;
+    aComment = pClassModule->aComment;

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list