ooo-build r13346 - in trunk: . patches/dev300 patches/vba



Author: noelpwer
Date: Tue Jul 22 11:34:41 2008
New Revision: 13346
URL: http://svn.gnome.org/viewvc/ooo-build?rev=13346&view=rev

Log:
2008-07-22  Noel Power  <noel power novell com>

        * patches/dev300/apply: support m25 and also suck in fix for i#91038
        * patches/vba/ObjectModule.diff:
        * patches/vba/vba-userform-activate-fix.diff:
        * patches/vba/vba-userform.diff:
        * patches/vba/ObjectModule-m22.diff:
        * patches/vba/vba-userform-activate-fix-m22.diff:
        * patches/vba/vba-userform-m22.diff:



Added:
   trunk/patches/vba/ObjectModule-m22.diff
   trunk/patches/vba/vba-userform-activate-fix-m22.diff
   trunk/patches/vba/vba-userform-m22.diff
Modified:
   trunk/ChangeLog
   trunk/patches/dev300/apply
   trunk/patches/vba/ObjectModule.diff
   trunk/patches/vba/vba-userform-activate-fix.diff
   trunk/patches/vba/vba-userform.diff

Modified: trunk/patches/dev300/apply
==============================================================================
--- trunk/patches/dev300/apply	(original)
+++ trunk/patches/dev300/apply	Tue Jul 22 11:34:41 2008
@@ -1649,15 +1649,21 @@
 vba-support-properties-inmodules.diff
 #FIXME: creates a circural build dependcy between toolkit and goodies 
 # controls-with-images-in-document.diff, i#38215, noelpwer 
-
-# FIXME: disabled now (mmeeks) - needs porting to m22.
-[ VBAObjects < dev300-m22 >= beb300-m1 ]
 # object module support... getting there
 ObjectModule.diff
 # userform ( depends on ObjectModule.diff )
 vba-userform.diff
+# extracted from vcl92
+vba-userform-activate-fix.diff, i#91038
+
+[ VBAObjects < dev300-m22 >= beb300-m1 ]
+# object module support... getting there
+ObjectModule-m22.diff
+# userform ( depends on ObjectModule.diff )
+vba-userform-m22.diff
 # fix userform activate event re-compute
-vba-userform-activate-fix.diff, Jianhua
+vba-userform-activate-fix-m22.diff, Jianhua
+vba-userform-activate-fix.diff, i#91038
 
 [ VBAObjects < dev300-m24 ]
 # another bug with event bindings for dialogs ( awaiting iz id from andreas )

Added: trunk/patches/vba/ObjectModule-m22.diff
==============================================================================
--- (empty file)
+++ trunk/patches/vba/ObjectModule-m22.diff	Tue Jul 22 11:34:41 2008
@@ -0,0 +1,1982 @@
+diff --git basctl/source/basicide/basides1.cxx basctl/source/basicide/basides1.cxx
+index aed5958..3d79067 100644
+--- basctl/source/basicide/basides1.cxx
++++ basctl/source/basicide/basides1.cxx
+@@ -1201,10 +1201,16 @@ IDEBaseWindow* BasicIDEShell::FindWindow
+                 // return any non-suspended window
+                 return pWin;
+             }
+-            else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rName &&
++            else if ( pWin->IsDocument( rDocument ) )
++            {
++                OSL_TRACE("FindWindow pWin->GetLibName() %s rLibName %s",
++			rtl::OUStringToOString( pWin->GetLibName(), RTL_TEXTENCODING_UTF8 ).getStr(),
++			rtl::OUStringToOString( rLibName, RTL_TEXTENCODING_UTF8 ).getStr() );
++                OSL_TRACE("pWin->pWin->IsA( TYPE( ModulWindow ) %d && nType %d = BASICIDE_TYPE_MODULE %d", pWin->IsA( TYPE( ModulWindow ) ), nType, BASICIDE_TYPE_MODULE );
++                OSL_TRACE("pWin->pWin->IsA( TYPE( DialogWindow ) %d && nType %d = BASICIDE_TYPE_DIALOG %d", pWin->IsA( TYPE( DialogWindow ) ), nType, BASICIDE_TYPE_DIALOG );
++		if (  pWin->GetLibName() == rLibName && pWin->GetName() == rName &&
+                       ( ( pWin->IsA( TYPE( ModulWindow ) )  && nType == BASICIDE_TYPE_MODULE ) ||
+                         ( pWin->IsA( TYPE( DialogWindow ) ) && nType == BASICIDE_TYPE_DIALOG ) ) )
+-            {
+                 return pWin;
+             }
+         }
+diff --git basctl/source/basicide/basides2.cxx basctl/source/basicide/basides2.cxx
+index 76dcea0..90cec19 100644
+--- basctl/source/basicide/basides2.cxx
++++ basctl/source/basicide/basides2.cxx
+@@ -251,9 +251,12 @@ ModulWindow* BasicIDEShell::CreateBasWin
+ 
+         if ( bSuccess )
+         {
+-			// new module window
+-			pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule );
+-			nKey = InsertWindowInTable( pWin );
++			pWin = FindBasWin( rDocument, aLibName, aModName, FALSE, TRUE );
++            if( !pWin )
++			{    // new module window
++			    pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule );
++			    nKey = InsertWindowInTable( pWin );
++            }
+         }
+ 	}
+ 	else
+@@ -268,7 +271,8 @@ ModulWindow* BasicIDEShell::CreateBasWin
+ 		}
+ 		DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
+ 	}
+-	pTabBar->InsertPage( (USHORT)nKey, aModName );
++    if( nKey )
++	    pTabBar->InsertPage( (USHORT)nKey, aModName );
+ 	pTabBar->Sort();
+ 	pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
+ 	if ( !pCurWin )
+diff --git basctl/source/basicide/basidesh.cxx basctl/source/basicide/basidesh.cxx
+index 666c4aa..2e854f8 100644
+--- basctl/source/basicide/basidesh.cxx
++++ basctl/source/basicide/basidesh.cxx
+@@ -80,6 +80,9 @@
+ #include <com/sun/star/script/XLibraryContainer.hpp>
+ #include <com/sun/star/script/XLibraryContainerPassword.hpp>
+ #include <com/sun/star/container/XNameContainer.hpp>
++#include <com/sun/star/container/XContainer.hpp>
++#include <com/sun/star/container/XContainerListener.hpp>
++#include <com/sun/star/script/XLibraryContainer.hpp>
+ 
+ #include <svx/xmlsecctrl.hxx>
+ 
+@@ -87,6 +90,71 @@ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star;
+ using ::rtl::OUString;
+ 
++static const rtl::OUString sStandardLibName(  rtl::OUString::createFromAscii("Standard") );
++
++typedef ::cppu::WeakImplHelper1< container::XContainerListener > ContainerListenerBASE;
++
++class ContainerListenerImpl : public ContainerListenerBASE
++{
++    BasicIDEShell* mpShell;
++public:
++
++    ContainerListenerImpl( BasicIDEShell* pShell ) : mpShell( pShell ) {}
++
++    ~ContainerListenerImpl() 
++    {
++    }
++
++    void addContainerListener( const ScriptDocument& rScriptDocument )
++    {
++        uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, sStandardLibName, FALSE ), uno::UNO_QUERY );
++        if ( rScriptDocument.isDocument() && xContainer.is() )
++        {
++            uno::Reference< container::XContainerListener > xContainerListener( this );
++            try
++            {
++                xContainer->addContainerListener( xContainerListener );
++            }
++            catch( uno::Exception& ) {}
++        }
++    }
++    void removeContainerListener( const ScriptDocument& rScriptDocument )
++    {
++        uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, sStandardLibName, FALSE ), uno::UNO_QUERY );
++        if ( rScriptDocument.isDocument(), xContainer.is() )
++        {
++            uno::Reference< container::XContainerListener > xContainerListener( this );
++            try
++            {
++               xContainer->removeContainerListener( xContainerListener );
++            }
++            catch( uno::Exception& ) {}
++        }
++    }
++
++    // XEventListener
++    virtual void SAL_CALL disposing( const lang::EventObject& ) throw( uno::RuntimeException ) {}
++
++    // XContainerListener
++    virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException )
++    {
++        rtl::OUString sModuleName;
++        if( mpShell && ( Event.Accessor >>= sModuleName ) )
++            mpShell->FindBasWin( mpShell->m_aCurDocument, sStandardLibName, sModuleName, TRUE, FALSE );
++    }
++    virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) throw( com::sun::star::uno::RuntimeException ) { }
++    virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException )
++    {
++        rtl::OUString sModuleName;
++        if( mpShell  && ( Event.Accessor >>= sModuleName ) )
++        {
++            IDEBaseWindow* pWin = mpShell->FindWindow( mpShell->m_aCurDocument, sStandardLibName, sModuleName, BASICIDE_TYPE_MODULE, TRUE );
++            if( pWin )
++                mpShell->RemoveWindow( pWin, FALSE, TRUE );
++        }
++    }
++
++};
+ 
+ TYPEINIT1( BasicIDEShell, SfxViewShell );
+ 
+@@ -124,6 +192,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFra
+         m_bAppBasicModified( FALSE ),
+         m_aNotifier( *this )
+ {
++    m_xLibListener = new ContainerListenerImpl( this );
+ 	Init();
+     GnBasicIDEShellCount++;
+ }
+@@ -139,6 +208,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFra
+         m_aNotifier( *this )
+ {
+ 	DBG_ERROR( "Zweite Ansicht auf Debugger nicht moeglich!" );
++    m_xLibListener = new ContainerListenerImpl( this );
+     GnBasicIDEShellCount++;
+ }
+ 
+@@ -153,6 +223,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFra
+         m_aNotifier( *this )
+ {
+ 	Init();
++    m_xLibListener = new ContainerListenerImpl( this );
+     GnBasicIDEShellCount++;
+ }
+ 
+@@ -243,6 +314,12 @@ __EXPORT BasicIDEShell::~BasicIDEShell()
+ 	delete pTabBar;
+ 	delete pObjectCatalog;
+ 	DestroyModulWindowLayout();
++
++        ContainerListenerImpl* pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() );
++        // Destroy all ContainerListeners for Basic Container.
++        if ( pListener )
++            pListener->removeContainerListener( m_aCurDocument );
++    
+ 	// MI: Das gab einen GPF im SDT beim Schliessen da dann der ViewFrame die
+ 	// ObjSh loslaesst. Es wusste auch keiner mehr wozu das gut war.
+ 	// GetViewFrame()->GetObjectShell()->Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
+@@ -968,7 +1045,15 @@ void BasicIDEShell::SetCurLib( const Scr
+ {
+     if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
+     {
++        ContainerListenerImpl* pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() );
++        if ( pListener )
++        	pListener->removeContainerListener( m_aCurDocument );
++
+         m_aCurDocument = rDocument;
++
++        if ( pListener )
++            pListener->addContainerListener( m_aCurDocument );
++
+         m_aCurLibName = aLibName;
+         if ( bUpdateWindows )
+             UpdateWindows();
+diff --git basctl/source/basicide/scriptdocument.cxx basctl/source/basicide/scriptdocument.cxx
+index 5d22053..0483cce 100644
+--- basctl/source/basicide/scriptdocument.cxx
++++ basctl/source/basicide/scriptdocument.cxx
+@@ -56,6 +56,7 @@
+ #include <com/sun/star/frame/XModel2.hpp>
+ #include <com/sun/star/awt/XWindow2.hpp>
+ #include <com/sun/star/document/XEmbeddedScripts.hpp>
++#include <com/sun/star/script/ModuleInfo.hpp>
+ /** === end UNO includes === **/
+ 
+ #include <sfx2/objsh.hxx>
+@@ -141,6 +142,7 @@ namespace basctl
+     using ::com::sun::star::uno::RuntimeException;
+     using ::com::sun::star::document::XEventBroadcaster;
+     using ::com::sun::star::document::XEmbeddedScripts;
++    using ::com::sun::star::script::ModuleInfo;
+     /** === end UNO using === **/
+     namespace MacroExecMode = ::com::sun::star::document::MacroExecMode;
+     namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag;
+@@ -673,6 +675,15 @@ namespace basctl
+             }
+ 
+ 		    // insert element by new name in container
++            if ( _eType == E_SCRIPTS )
++            {
++                ModuleInfo sModuleInfo;
++                if ( aElement >>= sModuleInfo )
++                {
++                    sModuleInfo.ModuleName = _rNewName;
++                    aElement <<= sModuleInfo;
++                }
++            }
+ 		    xLib->insertByName( _rNewName, aElement );
+             return true;
+         }
+@@ -1431,7 +1442,15 @@ namespace basctl
+         Any aCode;
+         if ( !m_pImpl->getModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, aCode ) )
+             return false;
+-        OSL_VERIFY( aCode >>= _out_rModuleSource );
++        ModuleInfo sModuleInfo;
++        if ( aCode >>= sModuleInfo )
++        {
++            _out_rModuleSource = sModuleInfo.ModuleSource;
++        }
++        else
++        {
++            OSL_VERIFY( aCode >>= _out_rModuleSource );
++        }
+         return true;
+     }
+ 
+diff --git basctl/source/inc/basidesh.hxx basctl/source/inc/basidesh.hxx
+index 109fedd..fa4cbe9 100644
+--- basctl/source/inc/basidesh.hxx
++++ basctl/source/inc/basidesh.hxx
+@@ -48,7 +48,7 @@
+ #ifndef _COM_SUN_STAR_IO_XINPUTSTREAMPROVIDER_HXX_
+ #include <com/sun/star/io/XInputStreamProvider.hpp>
+ #endif
+-
++#include <com/sun/star/container/XContainerListener.hpp>
+ 
+ //----------------------------------------------------------------------------
+ 
+@@ -76,13 +76,15 @@ DECLARE_TABLE( IDEWindowTable, IDEBaseWi
+ typedef Table IDEWindowTable;
+ #endif
+ 
++namespace css = ::com::sun::star;
++
+ class BasicIDEShell :public SfxViewShell
+                     ,public ::basctl::DocumentEventListener
+ {
+ friend class JavaDebuggingListenerImpl;
+ friend class LocalizationMgr;
+ friend class BasicIDE;
+-
++friend class ContainerListenerImpl;
+ 	ObjectCatalog* 		pObjectCatalog;
+ 
+ 	IDEWindowTable		aIDEWindowTable;
+@@ -102,6 +104,7 @@ friend class BasicIDE;
+     BOOL                m_bAppBasicModified;
+     ::basctl::DocumentEventNotifier
+                         m_aNotifier;
++	css::uno::Reference< css::container::XContainerListener > m_xLibListener; 	
+ 
+ #if _SOLAR__PRIVATE
+ 	void				Init();
+diff --git basic/inc/basic/sbmod.hxx basic/inc/basic/sbmod.hxx
+index 122a664..e676a49 100644
+--- basic/inc/basic/sbmod.hxx
++++ basic/inc/basic/sbmod.hxx
+@@ -37,7 +37,7 @@
+ #ifndef _RTL_USTRING_HXX
+ #include <rtl/ustring.hxx>
+ #endif
+-
++#include <com/sun/star/script/ModuleType.hpp>
+ class SbMethod;
+ class SbProperty;
+ class SbiRuntime;
+@@ -67,6 +67,9 @@ protected:
+ 	SbiBreakpoints*	pBreaks;			// Breakpoints
+ 	SbClassData*	pClassData;
+ 	bool mbVBACompat;
++	INT32 mnType; 
++	SbxObjectRef pDocObject; // an impl object ( used by Document Modules )
++	bool 	bIsProxyModule;
+ 
+ 	void			StartDefinitions();
+ 	SbMethod*		GetMethod( const String&, SbxDataType );
+@@ -91,7 +94,7 @@ protected:
+ public:
+ 	SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_BASICMOD,2);
+ 	TYPEINFO();
+-					SbModule( const String& );
++					SbModule( const String&, bool bCompat = false );
+ 	virtual void	SetParent( SbxObject* );
+ 	virtual void 	Clear();
+ 
+@@ -127,8 +130,12 @@ public:
+ 	BOOL LoadBinaryData( SvStream& );
+ 	BOOL ExceedsLegacyModuleSize();
+ 	void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = NULL ) const;
+-        bool IsVBACompat() { return mbVBACompat; }
+         bool HasExeCode();
++        bool IsVBACompat();
++        void SetVBACompat( bool bCompat );
++        INT32 GetModuleType() { return mnType; }
++        void SetModuleType( INT32 nType ) { mnType = nType; }
++	bool GetIsProxyModule() { return bIsProxyModule; }
+ };
+ 
+ #ifndef __SB_SBMODULEREF_HXX
+diff --git basic/inc/basic/sbstar.hxx basic/inc/basic/sbstar.hxx
+index ebd10ae..3c7e149 100644
+--- basic/inc/basic/sbstar.hxx
++++ basic/inc/basic/sbstar.hxx
+@@ -40,6 +40,7 @@
+ 
+ #include <basic/sbdef.hxx>
+ #include <basic/sberrors.hxx>
++#include <com/sun/star/script/ModuleInfo.hpp>
+ 
+ class SbModule;                     // fertiges Modul
+ class SbiInstance;                  // Laufzeit-Instanz
+@@ -71,6 +72,7 @@ class StarBASIC : public SbxObject
+ 	BOOL			bNoRtl;				// TRUE: RTL nicht durchsuchen
+ 	BOOL			bBreak;				// TRUE: Break, sonst Step
+ 	BOOL			bDocBasic;
++    BOOL            bVBAEnabled;
+ 	BasicLibInfo*	pLibInfo;			// Infoblock fuer Basic-Manager
+ 	SbLanguageMode	eLanguageMode;		// LanguageMode des Basic-Objekts
+ protected:
+@@ -113,7 +115,8 @@ public:
+ 
+ 	// Compiler-Interface
+ 	SbModule*   	MakeModule( const String& rName, const String& rSrc );
+-    SbModule*   	MakeModule32( const String& rName, const ::rtl::OUString& rSrc );
++    SbModule*       MakeModule32( const String& rName, const ::rtl::OUString& rSrc );
++    SbModule*       MakeModule32( const com::sun::star::script::ModuleInfo& mInfo );
+ 	BOOL			Compile( SbModule* );
+ 	BOOL 			Disassemble( SbModule*, String& rText );
+ 	static void 	Stop();
+@@ -185,6 +188,8 @@ public:
+ 					( const String& rName, USHORT& rStatus );
+ 	static SbMethod* GetActiveMethod( USHORT nLevel = 0 );
+ 	static SbModule* GetActiveModule();
++    void SetVBAEnabled( BOOL bEnabled );
++    BOOL isVBAEnabled();
+ 
+ 	// #60175 TRUE: SFX-Resource wird bei Basic-Fehlern nicht angezogen
+ 	static void StaticSuppressSfxResource( BOOL bSuppress );
+diff --git basic/source/basmgr/basmgr.cxx basic/source/basmgr/basmgr.cxx
+index 54f6426..b5394ae 100644
+--- basic/source/basmgr/basmgr.cxx
++++ basic/source/basmgr/basmgr.cxx
+@@ -67,6 +67,8 @@
+ #include <com/sun/star/script/XStarBasicDialogInfo.hpp>
+ #include <com/sun/star/script/XStarBasicLibraryInfo.hpp>
+ #include <com/sun/star/script/XLibraryContainerPassword.hpp>
++#include <com/sun/star/script/ModuleInfo.hpp>
++#include <com/sun/star/script/ModuleType.hpp>
+ 
+ #include <cppuhelper/implbase1.hxx>
+ 
+@@ -110,6 +112,7 @@ static const char* szScriptLanguage = "S
+ static const String BasicStreamName( String::CreateFromAscii(szBasicStorage) );
+ static const String ManagerStreamName( String::CreateFromAscii(szManagerStream) );
+ 
++//enum ModuleType { Unknown = 0, Normal, Class, Form, Document };
+ 
+ #define	DEFINE_CONST_UNICODE(CONSTASCII)    UniString(RTL_CONSTASCII_USTRINGPARAM(CONSTASCII))
+ 
+@@ -244,9 +247,18 @@ void BasMgrContainerListenerImpl::addLib
+ 		{
+ 			OUString aModuleName = pNames[ j ];
+ 			Any aElement = xLibNameAccess->getByName( aModuleName );
+-			OUString aMod;
+-			aElement >>= aMod;
+-			pLib->MakeModule32( aModuleName, aMod );
++            ModuleInfo mInfo;
++            if ( aElement >>= mInfo )
++            {
++                OSL_TRACE("#addLibraryModulesImpl - aMod");
++                pLib->MakeModule32( mInfo );
++            }
++            else
++            {
++			    OUString aMod;
++			    aElement >>= aMod;
++			    pLib->MakeModule32( aModuleName, aMod );
++            }
+ 		}
+ 	}
+ 
+@@ -283,8 +295,6 @@ void SAL_CALL BasMgrContainerListenerImp
+ 	}
+ 	else
+ 	{
+-		OUString aMod;
+-		Event.Element >>= aMod;
+ 
+ 		StarBASIC* pLib = mpMgr->GetLib( maLibName );
+ 		DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::elementInserted: Unknown lib!");
+@@ -293,7 +303,17 @@ void SAL_CALL BasMgrContainerListenerImp
+     		SbModule* pMod = pLib->FindModule( aName );
+             if( !pMod )
+             {
+-			    pLib->MakeModule32( aName, aMod );
++                ModuleInfo mInfo;
++                if( Event.Element >>= mInfo )
++                {
++                    pLib->MakeModule32( mInfo );
++                }
++                else
++                {
++        		    OUString aMod;
++        		    Event.Element >>= aMod;
++			        pLib->MakeModule32( aName, aMod );
++                }
+ 			    pLib->SetModified( FALSE );
+             }
+ 		}
+@@ -319,13 +339,23 @@ void SAL_CALL BasMgrContainerListenerImp
+ 	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 );
++         ModuleInfo mInfo;
++        if( Event.Element >>= mInfo )
++        {
++            OSL_TRACE("#elementReplaced Mod");
++            pLib->MakeModule32( mInfo );
++        }
++        else
++        {
++		    SbModule* pMod = pLib->FindModule( aName );
++
++		    OUString aMod;
++            Event.Element >>= aMod;
++		    if( pMod )
++		   	    pMod->SetSource32( aMod );
++            else
++			    pLib->MakeModule32( aName, aMod );
++        }
+ 
+ 		pLib->SetModified( FALSE );
+ 	}
+diff --git basic/source/classes/sb.cxx basic/source/classes/sb.cxx
+index f65c6ca..5226d3f 100644
+--- basic/source/classes/sb.cxx
++++ basic/source/classes/sb.cxx
+@@ -52,12 +52,17 @@
+ #include "disas.hxx"
+ #include "runtime.hxx"
+ #include <basic/sbuno.hxx>
++#include <basic/sbobjmod.hxx>
+ #include "stdobj.hxx"
+ #include "filefmt.hxx"
+ #include "sb.hrc"
+ #include <basrid.hxx>
+ #include <vos/mutex.hxx>
+ 
++#include <com/sun/star/script/ModuleType.hpp>
++#include <com/sun/star/script/ModuleInfo.hpp>
++using namespace ::com::sun::star::script;
++
+ // #pragma SW_SEGMENT_CLASS( SBASIC, SBASIC_CODE )
+ 
+ SV_IMPL_VARARR(SbTextPortions,SbTextPortion)
+@@ -249,6 +254,8 @@ SbxObject* SbiFactory::CreateObject( con
+ 	else
+ 	if( rClass.EqualsIgnoreCaseAscii( "Collection" ) )
+ 	{
++			// Only variables qualified by the Module Name e.g. Sheet1.foo
++			// should work for Documant && Class type Modules
+ 		String aCollectionName( RTL_CONSTASCII_USTRINGPARAM("Collection") );
+ 		return new BasicCollection( aCollectionName );
+ 	}
+@@ -446,6 +453,7 @@ SbClassModuleObject::SbClassModuleObject
+ 			}
+ 		}
+ 	}
++	SetModuleType( com::sun::star::script::ModuleType::Class );
+ }
+ 
+ SbClassModuleObject::~SbClassModuleObject()
+@@ -581,6 +589,7 @@ StarBASIC::StarBASIC( StarBASIC* p, BOOL
+ 	SetParent( p );
+ 	pLibInfo = NULL;
+ 	bNoRtl = bBreak = FALSE;
++    bVBAEnabled = FALSE;
+ 	pModules = new SbxArray;
+ 
+ 	if( !GetSbData()->nInst++ )
+@@ -683,12 +692,38 @@ SbModule* StarBASIC::MakeModule( const S
+ 
+ SbModule* StarBASIC::MakeModule32( const String& rName, const ::rtl::OUString& rSrc )
+ {
+-	SbModule* p = new SbModule( rName );
+-	p->SetSource32( rSrc );
++    ModuleInfo mInfo;
++    mInfo.ModuleSource = rSrc;
++    mInfo.ModuleType = ModuleType::Normal;
++    mInfo.ModuleName = rName;
++    return MakeModule32(  mInfo );
++}
++SbModule* StarBASIC::MakeModule32( const ModuleInfo& mInfo )
++{
++    
++    OSL_TRACE("create module %s type mInfo %d", rtl::OUStringToOString( mInfo.ModuleName, RTL_TEXTENCODING_UTF8 ).getStr(), mInfo.ModuleType );
++    SbModule* p = NULL;
++    switch ( mInfo.ModuleType )
++    {
++        case ModuleType::Document:
++            // In theory we should be able to create Object modules
++            // in ordinary basic ( in vba mode thought these are create
++            // by the application/basic and not by the user )
++            p = new SbObjModule( mInfo, isVBAEnabled() );
++            break;
++        case ModuleType::Class:
++            p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
++			p->SetModuleType( com::sun::star::script::ModuleType::Class );	
++	    break;
++        default:
++            p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
++            
++    }
++	p->SetSource32( mInfo.ModuleSource );
+ 	p->SetParent( this );
+ 	pModules->Insert( p, pModules->Count() );
+ 	SetModified( TRUE );
+-	return p;
++    return p;
+ }
+ 
+ void StarBASIC::Insert( SbxVariable* pVar )
+@@ -862,6 +897,12 @@ SbxVariable* StarBASIC::Find( const Stri
+ 				}
+ 				pNamed = p;
+ 			}
++			// Only variables qualified by the Module Name e.g. Sheet1.foo
++			// should work for Documant && Class type Modules
++			INT32 nType = p->GetModuleType();
++            //if ( nType == com::sun::star::script::ModuleType::Class || nType == com::sun::star::script::ModuleType::Document )
++            if ( nType == com::sun::star::script::ModuleType::Document )
++                continue;
+ 			// Sonst testen, ob das Element vorhanden ist
+ 			// GBLSEARCH-Flag rausnehmen (wg. Rekursion)
+ 			USHORT nGblFlag = p->GetFlags() & SBX_GBLSEARCH;
+diff --git basic/source/classes/sbxmod.cxx basic/source/classes/sbxmod.cxx
+index de94bf3..388f437 100644
+--- basic/source/classes/sbxmod.cxx
++++ basic/source/classes/sbxmod.cxx
+@@ -51,6 +51,8 @@
+ #include <basic/hilight.hxx>
+ #include <basic/basrdll.hxx>
+ #include <vos/mutex.hxx>
++#include <basic/sbobjmod.hxx>
++#include <com/sun/star/lang/XServiceInfo.hpp>
+ 
+ // for the bsearch
+ #ifdef WNT
+@@ -65,6 +67,17 @@
+ 
+ #include <stdio.h>
+ 
++#include <comphelper/processfactory.hxx>
++#include <com/sun/star/script/XLibraryContainer.hpp>
++#include <com/sun/star/lang/XMultiServiceFactory.hpp>
++#include <com/sun/star/awt/XDialogProvider.hpp>
++#include <com/sun/star/awt/XTopWindow.hpp>
++#include <com/sun/star/awt/XControl.hpp>
++#include <com/sun/star/frame/XModel.hpp>
++#include <cppuhelper/implbase1.hxx>
++#include <comphelper/anytostring.hxx>
++
++using namespace ::com::sun::star; 
+ 
+ TYPEINIT1(SbModule,SbxObject)
+ TYPEINIT1(SbMethod,SbxMethod)
+@@ -72,6 +85,7 @@ TYPEINIT1(SbProperty,SbxProperty)
+ TYPEINIT1(SbProcedureProperty,SbxProperty)
+ TYPEINIT1(SbJScriptModule,SbModule)
+ TYPEINIT1(SbJScriptMethod,SbMethod)
++TYPEINIT1(SbObjModule,SbModule)
+ 
+ SV_DECL_VARARR(SbiBreakpoints,USHORT,4,4)
+ SV_IMPL_VARARR(SbiBreakpoints,USHORT)
+@@ -80,7 +94,7 @@ SV_IMPL_VARARR(SbiBreakpoints,USHORT)
+ SV_IMPL_VARARR(HighlightPortions, HighlightPortion)
+ 
+ // ##########################################################################
+-// ACHTUNG!!!  Alle Woerter dieser Tabelle müKLEIN geschrieben werden!!!
++// ACHTUNG!!!  Alle Woerter dieser Tabelle mÃssen KLEIN geschrieben werden!!!
+ // ##########################################################################
+ static const char* strListBasicKeyWords[] = {
+ 	"access",
+@@ -221,12 +235,13 @@ extern "C" int CDECL compare_strings( co
+ // Ein BASIC-Modul hat EXTSEARCH gesetzt, damit die im Modul enthaltenen
+ // Elemente von anderen Modulen aus gefunden werden koennen.
+ 
+-SbModule::SbModule( const String& rName )
++SbModule::SbModule( const String& rName, bool bVBACompat )
+ 		 : SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASICModule") ) ),
+-		   pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), mbVBACompat( false )
++		   pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), mbVBACompat( bVBACompat ),  pDocObject( NULL ), bIsProxyModule( false )
+ {
+ 	SetName( rName );
+ 	SetFlag( SBX_EXTSEARCH | SBX_GBLSEARCH );
++	SetModuleType( com::sun::star::script::ModuleType::Normal );
+ }
+ 
+ SbModule::~SbModule()
+@@ -401,7 +416,10 @@ void SbModule::Clear()
+ 
+ SbxVariable* SbModule::Find( const XubString& rName, SbxClassType t )
+ {
++	// make sure a search in an uninstatiated class module will fail
+ 	SbxVariable* pRes = SbxObject::Find( rName, t );
++	if ( bIsProxyModule )
++		return NULL;
+ 	if( !pRes && pImage )
+ 	{
+ 		SbiInstance* pInst = pINST;
+@@ -561,6 +579,7 @@ void SbModule::SetSource32( const ::rtl:
+ 	aOUSource = r;
+ 	StartDefinitions();
+ 	SbiTokenizer aTok( r );
++        aTok.SetCompatible( IsVBACompat() );
+ 	while( !aTok.IsEof() )
+ 	{
+ 		SbiToken eEndTok = NIL;
+@@ -585,14 +604,6 @@ void SbModule::SetSource32( const ::rtl:
+ 				{
+ 					eEndTok = ENDPROPERTY; break;
+ 				}
+-				if( eCurTok == OPTION )
+-				{
+-					eCurTok = aTok.Next();
+-					mbVBACompat = ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) && ( aTok.GetDbl()== 1 );
+-					if( eCurTok == COMPATIBLE 
+-					|| mbVBACompat )
+-						aTok.SetCompatible( true );
+-				}
+ 			}
+ 			eLastTok = eCurTok;
+ 		}
+@@ -731,10 +742,19 @@ void ClearUnoObjectsInRTL_Impl( StarBASI
+     if( ((StarBASIC*)p) != pBasic )
+ 	    ClearUnoObjectsInRTL_Impl_Rek( (StarBASIC*)p );
+ }
++bool SbModule::IsVBACompat()
++{
++	return mbVBACompat;
++}
+ 
++void SbModule::SetVBACompat( bool bCompat )
++{
++	mbVBACompat = bCompat;
++}
+ // Ausfuehren eines BASIC-Unterprogramms
+ USHORT SbModule::Run( SbMethod* pMeth )
+ {
++	OSL_TRACE("About to run %s, vba compatmode is %d", rtl::OUStringToOString( pMeth->GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), mbVBACompat );
+ 	static USHORT nMaxCallLevel = 0;
+ 	static String aMSOMacroRuntimeLibName = String::CreateFromAscii( "Launcher" );
+ 	static String aMSOMacroRuntimeAppSymbol = String::CreateFromAscii( "Application" );
+@@ -826,10 +846,10 @@ USHORT SbModule::Run( SbMethod* pMeth )
+ 			if( pRt->pNext )
+ 				pRt->pNext->block();
+ 			pINST->pRun = pRt;
+-			if ( SbiRuntime ::isVBAEnabled() )
++			if ( mbVBACompat )
+                         {
+ 				pINST->EnableCompatibility( TRUE );
+-				pRt->SetVBAEnabled( true );
++				//pRt->SetVBAEnabled( true ); // can we get rid of this
+                         }
+ 			while( pRt->Step() ) {}
+ 			if( pRt->pNext )
+@@ -1404,7 +1424,6 @@ BOOL SbModule::LoadBinaryData( SvStream&
+     return bRet;
+ }
+ 
+-
+ BOOL SbModule::LoadCompleted()
+ {
+ 	SbxArray* p = GetMethods();
+@@ -2223,3 +2242,44 @@ SbProcedureProperty::~SbProcedurePropert
+ {}
+ 
+ 
++/////////////////////////////////////////////////////////////////////////
++SbObjModule::SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible )
++    : SbModule( mInfo.ModuleName, bIsVbaCompatible )
++{
++    SetModuleType( mInfo.ModuleType );
++    try
++    {
++        com::sun::star::uno::Any aObject( mInfo.ModuleObject );
++        pDocObject = new SbUnoObject( GetName(), aObject );
++        com::sun::star::uno::Reference< com::sun::star::lang::XServiceInfo > xServiceInfo( aObject, com::sun::star::uno::UNO_QUERY_THROW );
++        if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "org.openoffice.excel.Worksheet" ) ) )
++        {
++            SetClassName( rtl::OUString::createFromAscii( "Worksheet" ) );
++        }
++        else if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "org.openoffice.excel.Workbook" ) ) )
++        {
++            SetClassName( rtl::OUString::createFromAscii( "Workbook" ) );
++        }
++    }
++    catch( com::sun::star::uno::RuntimeException e )
++    {
++        OSL_TRACE("***** Failed to initialise API Object." );
++    }
++}
++
++SbxVariable*
++SbObjModule::GetObject() 
++{
++    return pDocObject;
++}
++SbxVariable*
++SbObjModule::Find( const XubString& rName, SbxClassType t )
++{
++    //OSL_TRACE("SbObjectModule find for %s", rtl::OUStringToOString(  rName, RTL_TEXTENCODING_UTF8 ).getStr() );
++    SbxVariable* pVar = NULL;
++    if ( !pVar && pDocObject)
++        pVar = pDocObject->Find( rName, t );
++    if ( !pVar )
++        pVar = SbModule::Find( rName, t );
++    return pVar;
++}
+diff --git basic/source/comp/codegen.cxx basic/source/comp/codegen.cxx
+index 9f88fb6..46e0450 100644
+--- basic/source/comp/codegen.cxx
++++ basic/source/comp/codegen.cxx
+@@ -130,12 +130,12 @@ void SbiCodeGen::Save()
+ 	// OPTION EXPLICIT-Flag uebernehmen
+ 	if( pParser->bExplicit )
+ 		p->SetFlag( SBIMG_EXPLICIT );
+-	if( pParser->IsVBASupportOn() )
+-		p->SetFlag( SBIMG_VBASUPPORT );
+ 	
+ 	int nIfaceCount = 0;
+-	if( pParser->bClassModule )
++	if( rMod.mnType == com::sun::star::script::ModuleType::Class )
+ 	{
++                OSL_TRACE("COdeGen::save() classmodule processing");
++		rMod.bIsProxyModule = true;
+ 		p->SetFlag( SBIMG_CLASSMODULE );
+ 		pCLASSFAC->AddClassModule( &rMod );
+ 
+@@ -158,6 +158,10 @@ void SbiCodeGen::Save()
+ 	else
+ 	{
+ 		pCLASSFAC->RemoveClassModule( &rMod );
++		// Only a ClassModule can revert to Normal
++                if ( rMod.mnType == com::sun::star::script::ModuleType::Class )
++			rMod.mnType = com::sun::star::script::ModuleType::Normal;
++		rMod.bIsProxyModule = false;
+ 	}
+ 	if( pParser->bText )
+ 		p->SetFlag( SBIMG_COMPARETEXT );
+@@ -240,6 +244,8 @@ void SbiCodeGen::Save()
+ 					if( nPass == 1 )
+ 						aPropName = aPropName.Copy( aIfaceName.Len() + 1 );
+ 					SbProcedureProperty* pProcedureProperty = NULL;
++                                        OSL_TRACE("*** getProcedureProperty for thing %s",
++						rtl::OUStringToOString( aPropName,RTL_TEXTENCODING_UTF8 ).getStr() );
+ 					pProcedureProperty = rMod.GetProcedureProperty( aPropName, ePropType );
+ 				}
+ 				if( nPass == 1 )
+diff --git basic/source/comp/parser.cxx basic/source/comp/parser.cxx
+index 931b6c7..7bc712e 100644
+--- basic/source/comp/parser.cxx
++++ basic/source/comp/parser.cxx
+@@ -144,7 +144,8 @@ SbiParser::SbiParser( StarBASIC* pb, SbM
+ 	bNewGblDefs =
+ 	bSingleLineIf =
+ 	bExplicit = FALSE;
+-	bClassModule = FALSE;
++	bClassModule = ( pm->GetModuleType() == com::sun::star::script::ModuleType::Class );
++	OSL_TRACE("Parser - %s, bClassModule %d", rtl::OUStringToOString( pm->GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), bClassModule );
+ 	pPool	 = &aPublics;
+ 	for( short i = 0; i < 26; i++ )
+ 		eDefTypes[ i ] = SbxVARIANT;    // Kein expliziter Defaulttyp
+@@ -157,6 +158,10 @@ SbiParser::SbiParser( StarBASIC* pb, SbM
+ 
+ 	rTypeArray = new SbxArray; // Array fuer Benutzerdefinierte Typen
+ 	rEnumArray = new SbxArray; // Array for Enum types
++	bVBASupportOn = pm->IsVBACompat();
++	if ( bVBASupportOn )
++		EnableCompatibility();
++
+ }
+ 
+ 
+@@ -751,8 +756,9 @@ void SbiParser::Option()
+ 
+ 		case CLASSMODULE:
+ 			bClassModule = TRUE; 
++			aGen.GetModule().SetModuleType( com::sun::star::script::ModuleType::Class );
+ 			break;
+-		case VBASUPPORT:
++		case VBASUPPORT: // Option VBASupport used to override the module mode ( in fact this must reset the mode
+ 			if( Next() == NUMBER )
+ 			{
+ 				if ( nVal == 1 || nVal == 0 )
+@@ -760,6 +766,10 @@ void SbiParser::Option()
+ 					bVBASupportOn = ( nVal == 1 );
+ 					if ( bVBASupportOn )
+ 						EnableCompatibility();
++					// if the module setting is different
++					// reset it to what the Option tells us
++					if ( bVBASupportOn != aGen.GetModule().IsVBACompat() )
++						aGen.GetModule().SetVBACompat( bVBASupportOn );
+ 					break;
+ 				}
+ 			}
+--- /dev/null	2007-05-04 11:54:36.000000000 +0100
++++ basic/inc/basic/sbobjmod.hxx	2008-05-28 10:58:33.000000000 +0100
+@@ -0,0 +1,65 @@
++/*************************************************************************
++ *
++ *  OpenOffice.org - a multi-platform office productivity suite
++ *
++ *  $RCSfile: sbobjmod.hxx,v $
++ *
++ *  $Revision: 1.4 $
++ *
++ *  last change: $Author:  $ $Date: 2007/08/27 16:31:39 $
++ *
++ *  The Contents of this file are made available subject to
++ *  the terms of GNU Lesser General Public License Version 2.1.
++ *
++ *
++ *    GNU Lesser General Public License Version 2.1
++ *    =============================================
++ *    Copyright 2005 by Sun Microsystems, Inc.
++ *    901 San Antonio Road, Palo Alto, CA 94303, USA
++ *
++ *    This library is free software; you can redistribute it and/or
++ *    modify it under the terms of the GNU Lesser General Public
++ *    License version 2.1, as published by the Free Software Foundation.
++ *
++ *    This library 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 for more details.
++ *
++ *    You should have received a copy of the GNU Lesser General Public
++ *    License along with this library; if not, write to the Free Software
++ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ *    MA  02111-1307  USA
++ *
++ ************************************************************************/
++
++#ifndef _SB_OBJMOD_HXX
++#define _SB_OBJMOD_HXX
++
++#include <basic/sbmod.hxx>
++#include <basic/sbstar.hxx>
++#include <com/sun/star/script/ModuleInfo.hpp>
++#include <com/sun/star/lang/XEventListener.hpp>
++#include <com/sun/star/awt/XDialog.hpp>
++
++namespace css = ::com::sun::star;
++
++// Basic-Module for excel object.
++
++class SbObjModule : public SbModule
++{
++public:
++    TYPEINFO();
++    SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible );
++    virtual SbxVariable* Find( const XubString& rName, SbxClassType t );
++    SbxVariable* GetObject();
++};
++
++#ifndef __SB_SBOBJMODULEREF_HXX
++#define __SB_SBOBJMODULEREF_HXX
++
++SV_DECL_IMPL_REF(SbObjModule);
++
++#endif
++#endif
++
+diff --git basic/source/inc/codegen.hxx basic/source/inc/codegen.hxx
+index ad11d02..a054af7 100644
+--- basic/source/inc/codegen.hxx
++++ basic/source/inc/codegen.hxx
+@@ -56,6 +56,7 @@ public:
+ 	void GenStmnt();			// evtl. Statement-Opcode erzeugen
+ 	UINT32 GetPC();
+ 	UINT32 GetOffset()				{ return GetPC() + 1; }
++    SbModule& GetModule() { return rMod; } 
+ 	void Save();
+ 
+ 	// #29955 for-Schleifen-Ebene pflegen
+diff --git basic/source/inc/image.hxx basic/source/inc/image.hxx
+index 8a454cf..c371a85 100644
+--- basic/source/inc/image.hxx
++++ basic/source/inc/image.hxx
+@@ -109,6 +109,5 @@ public:
+ #define	SBIMG_COMPARETEXT	0x0002	// OPTION COMPARE TEXT ist aktiv
+ #define	SBIMG_INITCODE		0x0004	// Init-Code vorhanden
+ #define	SBIMG_CLASSMODULE	0x0008	// OPTION ClassModule is active
+-#define	SBIMG_VBASUPPORT	0x0020	// OPTION VBASupport is 1
+ 
+ #endif
+diff --git basic/source/runtime/methods1.cxx basic/source/runtime/methods1.cxx
+index 313bf17..c891643 100644
+--- basic/source/runtime/methods1.cxx
++++ basic/source/runtime/methods1.cxx
+@@ -44,6 +44,7 @@
+ #ifndef _SBX_HXX
+ #include <basic/sbx.hxx>
+ #endif
++#include <basic/sbstar.hxx>
+ #include <svtools/zforlist.hxx>
+ #include <tools/fsys.hxx>
+ #include <tools/urlobj.hxx>
+@@ -64,6 +65,7 @@
+ #endif
+ 
+ #include <vcl/jobset.hxx>
++#include <basic/sbobjmod.hxx>
+ 
+ #include "sbintern.hxx"
+ #include "runtime.hxx"
+@@ -2585,13 +2587,13 @@ RTLFUNC(Me)
+     
+ 	SbModule* pActiveModule = pINST->GetActiveModule();
+ 	SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pActiveModule);
++    SbxVariableRef refVar = rPar.Get(0);
+ 	if( pClassModuleObject == NULL )
+ 	{
+-		StarBASIC::Error( SbERR_INVALID_USAGE_OBJECT );
++        SbObjModule* pMod = PTR_CAST(SbObjModule,pActiveModule);
++        if ( pMod )
++            refVar->PutObject( pMod );
+ 	}
+ 	else
+-	{
+-		SbxVariableRef refVar = rPar.Get(0);
+ 		refVar->PutObject( pClassModuleObject );
+-	}
+ }
+diff --git basic/source/runtime/runtime.cxx basic/source/runtime/runtime.cxx
+index 020b7e2..9de19fd 100644
+--- basic/source/runtime/runtime.cxx
++++ basic/source/runtime/runtime.cxx
+@@ -53,7 +53,8 @@ bool SbiRuntime::isVBAEnabled()
+ 	bool result = false;
+ 	SbiInstance* pInst = pINST;
+ 	if ( pInst && pINST->pRun )
+-		result = pInst->pRun->GetImageFlag( SBIMG_VBASUPPORT );
++		//result = pInst->pRun->GetImageFlag( SBIMG_VBASUPPORT );
++		result = pInst->pRun->bVBAEnabled;
+ 	return result; 
+ }
+ 
+@@ -64,6 +65,24 @@ void StarBASIC::StaticEnableReschedule( 
+ {
+     bStaticGlobalEnableReschedule = bReschedule;
+ }
++void StarBASIC::SetVBAEnabled( BOOL bEnabled )
++{
++    if ( bDocBasic )
++    {
++        bVBAEnabled = bEnabled;
++    }
++}
++
++BOOL StarBASIC::isVBAEnabled()
++{
++    if ( bDocBasic )
++    { 
++        if( SbiRuntime::isVBAEnabled() )
++            return TRUE;
++        return bVBAEnabled;
++    }
++    return FALSE;
++}
+ 
+ 
+ struct SbiArgvStack {					// Argv stack:
+@@ -519,6 +538,7 @@ SbiRuntime::SbiRuntime( SbModule* pm, Sb
+ 	nForLvl   = 0;
+ 	nOps	  = 0;
+ 	refExprStk = new SbxArray;
++	SetVBAEnabled( pMod->IsVBACompat() );
+ #if defined GCC
+ 	SetParameters( pe ? pe->GetParameters() : (class SbxArray *)NULL );
+ #else
+@@ -526,7 +546,6 @@ SbiRuntime::SbiRuntime( SbModule* pm, Sb
+ #endif
+ 	pRefSaveList = NULL;
+ 	pItemStoreList = NULL;
+-	bVBAEnabled = isVBAEnabled();
+ }
+ 
+ SbiRuntime::~SbiRuntime()
+diff --git basic/source/uno/namecont.cxx basic/source/uno/namecont.cxx
+index 93ea95d..e5f37c7 100644
+--- basic/source/uno/namecont.cxx
++++ basic/source/uno/namecont.cxx
+@@ -72,6 +72,9 @@
+ #include <cppuhelper/exc_hlp.hxx>
+ #include <basic/sbmod.hxx>
+ 
++#ifndef _COM_SUN_STAR_SCRIPT_MODULEINFO_HPP_
++#include <com/sun/star/script/ModuleInfo.hpp>
++#endif
+ 
+ namespace basic
+ {
+@@ -150,7 +153,7 @@ void NameContainer::replaceByName( const
+ 	throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
+ {
+ 	Type aAnyType = aElement.getValueType();
+-	if( mType != aAnyType )
++    if( mType != aAnyType && aAnyType != getCppuType( static_cast< ModuleInfo* >( NULL ) ) )
+ 		throw IllegalArgumentException();
+ 
+ 	NameContainerNameMap::iterator aIt = mHashMap.find( aName );
+@@ -192,7 +195,7 @@ void NameContainer::insertByName( const 
+ 	throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
+ {
+ 	Type aAnyType = aElement.getValueType();
+-	if( mType != aAnyType )
++    if( mType != aAnyType && aAnyType != getCppuType( static_cast< ModuleInfo* >( NULL ) ) )
+ 		throw IllegalArgumentException();
+ 
+ 	NameContainerNameMap::iterator aIt = mHashMap.find( aName );
+diff --git sc/inc/servuno.hxx sc/inc/servuno.hxx
+index c93cdb3..73fdec1 100644
+--- sc/inc/servuno.hxx
++++ sc/inc/servuno.hxx
+@@ -93,8 +93,8 @@ class ScDocShell;
+ 
+ #define SC_SERVICE_FORMULAPARS  38
+ #define SC_SERVICE_OPCODEMAPPER 39
+-
+-#define SC_SERVICE_COUNT        40
++#define SC_SERVICE_VBAOBJECTPROVIDER   40
++#define SC_SERVICE_COUNT        41
+ #define SC_SERVICE_INVALID		USHRT_MAX
+ 
+ 
+diff --git sc/source/filter/excel/excimp8.cxx sc/source/filter/excel/excimp8.cxx
+index c7dac08..9fd0be4 100644
+--- sc/source/filter/excel/excimp8.cxx
++++ sc/source/filter/excel/excimp8.cxx
+@@ -281,6 +281,7 @@ bool lcl_hasVBAEnabled()
+ 
+ void ImportExcel8::ReadBasic( void )
+ {
++    //bHasBasic = TRUE;
+     bHasBasic = TRUE;
+ 
+     SfxObjectShell* pShell = GetDocShell();
+@@ -308,6 +309,10 @@ void ImportExcel8::EndSheet( void )
+ 
+ void ImportExcel8::PostDocLoad( void )
+ {
++    // delay reading basic until sheet object ( codenames etc. ) are read
++
++    if ( bHasBasic ) 
++        ReadBasic();
+     // #i11776# filtered ranges before outlines and hidden rows
+     if( pExcRoot->pAutoFilterBuffer )
+         pExcRoot->pAutoFilterBuffer->Apply();
+diff --git sc/source/filter/excel/read.cxx sc/source/filter/excel/read.cxx
+index d65e496..403c0e2 100644
+--- sc/source/filter/excel/read.cxx
++++ sc/source/filter/excel/read.cxx
+@@ -946,7 +946,8 @@ FltError ImportExcel8::Read( void )
+ 					case 0x22:	Rec1904(); break;		// 1904			[ 2345   ]
+ 					case 0x56:	Builtinfmtcnt(); break;	// BUILTINFMTCNT[  34    ]
+ 					case 0x8D:	Hideobj(); break;		// HIDEOBJ		[  345   ]
+-					case 0xD3:	ReadBasic(); break;
++					case 0xD3:	/*ReadBasic()*/bHasBasic = true; break;
++//					case 0xD3:	ReadBasic(); break;
+                     case 0xDE:  Olesize(); break;
+ 					case 0x01BA: Codename( TRUE ); break;
+ 
+diff -rup sc/source/filter/excel/xiescher.cxx sc/source/filter/excel/xiescher.cxx
+--- sc/source/filter/excel/xiescher.cxx	2008-06-03 16:08:20.000000000 +0100
++++ sc/source/filter/excel/xiescher.cxx	2008-06-03 16:36:05.000000000 +0100
+@@ -834,7 +834,7 @@ bool XclImpTbxControlObj::FillMacroDescr
+         {
+             // set the macro name
+             rEvent.ScriptType = XclControlObjHelper::GetTbxScriptType();
+-            rEvent.ScriptCode = XclControlObjHelper::GetScMacroName( GetMacroName() );
++            rEvent.ScriptCode = XclControlObjHelper::GetScMacroName( GetMacroName(), GetDocShell() );
+             return true;
+         }
+     }
+@@ -1711,7 +1711,7 @@ SdrObject* XclImpDffManager::ProcessObj(
+             if( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( xSdrObj.get(), TRUE ) )
+             {
+                 if ( rMacro.Len() > 0 )
+-                pInfo->SetMacro( XclControlObjHelper::GetScMacroName( rMacro ) );
++                pInfo->SetMacro( XclControlObjHelper::GetScMacroName( rMacro, GetDocShell() ) );
+                 if ( aHlink.getLength() > 0 )
+                 pInfo->SetHlink( aHlink );
+             }
+diff -rup sc/source/filter/excel/xlescher.cxx sc/source/filter/excel/xlescher.cxx
+--- sc/source/filter/excel/xlescher.cxx	2008-05-29 23:19:09.000000000 +0100
++++ sc/source/filter/excel/xlescher.cxx	2008-06-03 15:38:21.000000000 +0100
+@@ -37,7 +37,10 @@
+ #include "xistream.hxx"
+ #include "xestream.hxx"
+ #include "globstr.hrc"
+-
++#include <sfx2/objsh.hxx>
++#include <basic/sbstar.hxx>
++#include <basic/sbmod.hxx>
++#include <basic/sbmeth.hxx>
+ using ::rtl::OUString;
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::UNO_QUERY;
+@@ -405,9 +408,16 @@ OUString XclControlObjHelper::GetTbxScri
+ #define EXC_TBX_MACRONAME_PRE "vnd.sun.star.script:Standard."
+ #define EXC_TBX_MACRONAME_SUF "?language=Basic&location=document"
+ 
+-OUString XclControlObjHelper::GetScMacroName( const String& rXclMacroName )
++OUString XclControlObjHelper::GetScMacroName( const String& rXclMacroName, SfxObjectShell* pDocShell )
+ {
+-    return CREATE_OUSTRING( EXC_TBX_MACRONAME_PRE ) + rXclMacroName + CREATE_OUSTRING( EXC_TBX_MACRONAME_SUF );
++    String sTmp( rXclMacroName );
++    if (  ( sTmp.Search( '.' ) == STRING_NOTFOUND) && pDocShell )
++                    if( StarBASIC* pBasic = pDocShell->GetBasic() )
++                        if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pBasic->Find( sTmp, SbxCLASS_METHOD ) ) )
++                            if( SbModule* pModule = pMethod->GetModule() )
++                                sTmp.Insert( '.', 0 ).Insert( pModule->GetName(), 0 );
++    
++    return CREATE_OUSTRING( EXC_TBX_MACRONAME_PRE ) + sTmp + CREATE_OUSTRING( EXC_TBX_MACRONAME_SUF );
+ }
+ 
+ String XclControlObjHelper::GetXclMacroName( const OUString& rScMacroName )
+diff -rup sc/source/filter/inc/xlescher.hxx sc/source/filter/inc/xlescher.hxx
+--- sc/source/filter/inc/xlescher.hxx	2008-05-29 23:19:09.000000000 +0100
++++ sc/source/filter/inc/xlescher.hxx	2008-06-03 15:28:12.000000000 +0100
+@@ -279,7 +279,7 @@ public:
+     static ::rtl::OUString GetTbxScriptType();
+ 
+     /** Returns the Calc macro name from an Excel macro name. */
+-    static ::rtl::OUString GetScMacroName( const String& rXclMacroName );
++    static ::rtl::OUString GetScMacroName( const String& rXclMacroName, SfxObjectShell* pShell = NULL );
+     /** Returns the Excel macro name from a Calc macro name. */
+     static String       GetXclMacroName( const ::rtl::OUString& rScMacroName );
+ };
+diff --git sc/source/ui/docshell/docfunc.cxx sc/source/ui/docshell/docfunc.cxx
+index c0253ae..79e8eed 100644
+--- sc/source/ui/docshell/docfunc.cxx
++++ sc/source/ui/docshell/docfunc.cxx
+@@ -51,6 +51,12 @@
+ #include <svtools/zforlist.hxx>
+ #include <svtools/PasswordHelper.hxx>
+ 
++#include <basic/sbstar.hxx>
++#include <com/sun/star/container/XNameContainer.hpp>
++#include <com/sun/star/script/XLibraryContainer.hpp>
++#include <com/sun/star/script/ModuleInfo.hpp>
++#include <com/sun/star/script/ModuleType.hpp>
++
+ #include <list>
+ 
+ #include "docfunc.hxx"
+@@ -94,6 +100,7 @@
+ #include "scui_def.hxx" //CHINA001
+ using namespace com::sun::star;
+ 
++
+ // STATIC DATA -----------------------------------------------------------
+ 
+ //========================================================================
+@@ -2016,6 +2023,85 @@ BOOL ScDocFunc::MoveBlock( const ScRange
+ }
+ 
+ //------------------------------------------------------------------------
++script::ModuleInfo lcl_InitModuleInfo( ScDocShell& rDocSh, String& sModule )
++{
++    ::rtl::OUString aModName( sModule );
++    uno::Reference< lang::XMultiServiceFactory> xSF(rDocSh.GetModel(), uno::UNO_QUERY);
++    ::rtl::OUString sVbaOption( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=VBADocumentModule\nOption VBASupport 1\n" ));
++    script::ModuleInfo sModuleInfo;
++    sModuleInfo.ModuleName = aModName;
++    sModuleInfo.ModuleSource = sVbaOption;
++    sModuleInfo.ModuleType = script::ModuleType::Document;
++    uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess;
++    if ( xSF.is() )
++    {
++        uno::Sequence< uno::Any > aArgs(1);
++        aArgs[0] = uno::Any( aModName );
++        xVBACodeNamedObjectAccess.set( xSF->createInstanceWithArguments( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.vba.VBAObjectModuleObjectProvider")), aArgs), uno::UNO_QUERY );    
++        sModuleInfo.ModuleObject.set( xVBACodeNamedObjectAccess->getByName( aModName ), uno::UNO_QUERY );    
++    }
++    return sModuleInfo;
++}
++
++void lcl_InsertModule( ScDocShell& rDocSh, SCTAB nTab, String& sModuleName )
++{
++    SFX_APP()->EnterBasicCall();
++    script::ModuleInfo sModuleInfo = lcl_InitModuleInfo(  rDocSh, sModuleName );
++    uno::Reference< script::XLibraryContainer > xLibContainer = rDocSh.GetBasicContainer();
++    DBG_ASSERT( xLibContainer.is(), "No BasicContainer!" );
++
++    uno::Reference< container::XNameContainer > xLib;
++    if( xLibContainer.is() )
++    {
++        String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
++        uno::Any aLibAny = xLibContainer->getByName( aLibName );
++        aLibAny >>= xLib;
++    }
++    if( xLib.is() )
++    {
++        // test Module has exist
++        // if the Module is exist. changed to another name
++        // and at this time the string like "SheetX"
++        sal_Int32 nNum = 1;
++        while( xLib->hasByName( sModuleInfo.ModuleName  ) )
++        {
++            sModuleName = rtl::OUString::createFromAscii( "Sheet" ) + rtl::OUString::valueOf( nNum );
++            nNum += 1;
++        }
++        sModuleInfo.ModuleName = sModuleName;
++        uno::Any aSourceAny;
++        aSourceAny <<= sModuleInfo;
++        xLib->insertByName( sModuleName, aSourceAny );
++        ScDocument* pDoc = rDocSh.GetDocument();
++        String sCodeName( sModuleName );
++        pDoc->SetCodeName( nTab, sCodeName );
++    }
++    SFX_APP()->LeaveBasicCall();
++}
++
++void lcl_DeleteModule( ScDocShell& rDocSh, String& sModuleName )
++{
++    SFX_APP()->EnterBasicCall();
++    uno::Reference< script::XLibraryContainer > xLibContainer = rDocSh.GetBasicContainer();
++    DBG_ASSERT( xLibContainer.is(), "No BasicContainer!" );
++
++    uno::Reference< container::XNameContainer > xLib;
++    if( xLibContainer.is() )
++    {
++        String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
++        uno::Any aLibAny = xLibContainer->getByName( aLibName );
++        aLibAny >>= xLib;
++    }
++    if( xLib.is() )
++    {
++        if( xLib->hasByName( sModuleName ) )
++        {
++            xLib->removeByName( sModuleName );
++        }
++    }
++    SFX_APP()->LeaveBasicCall();
++}
++
+ 
+ BOOL ScDocFunc::InsertTable( SCTAB nTab, const String& rName, BOOL bRecord, BOOL bApi )
+ {
+@@ -2025,8 +2111,12 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
+ 	ScDocShellModificator aModificator( rDocShell );
+ 
+ 	ScDocument* pDoc = rDocShell.GetDocument();
++    StarBASIC* pStarBASIC = rDocShell.GetBasic();
++    BOOL bVbaEnabled = pStarBASIC->isVBAEnabled();
+ 	if (bRecord && !pDoc->IsUndoEnabled())
+ 		bRecord = FALSE;
++    if ( bVbaEnabled )
++        bRecord = FALSE;
+ 	if (bRecord)
+ 		pDoc->BeginDrawUndo();							//	InsertTab erzeugt ein SdrUndoNewPage
+ 
+@@ -2041,6 +2131,11 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
+ 			rDocShell.GetUndoManager()->AddUndoAction(
+ 						new ScUndoInsertTab( &rDocShell, nTab, bAppend, rName));
+ 		//	Views updaten:
++        if( bVbaEnabled )
++        {
++            String sCodeName( rName );
++            lcl_InsertModule( rDocShell, nTab, sCodeName );
++        }
+ 		rDocShell.Broadcast( ScTablesHint( SC_TAB_INSERTED, nTab ) );
+ 
+ 		rDocShell.PostPaintExtras();
+@@ -2062,8 +2157,12 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
+ 
+ 	BOOL bSuccess = FALSE;
+ 	ScDocument* pDoc = rDocShell.GetDocument();
++    StarBASIC* pStarBASIC = rDocShell.GetBasic();
++    BOOL bVbaEnabled = pStarBASIC->isVBAEnabled();
+ 	if (bRecord && !pDoc->IsUndoEnabled())
+ 		bRecord = FALSE;
++    if ( bVbaEnabled )
++        bRecord = FALSE;
+ 	BOOL bWasLinked = pDoc->IsLinked(nTab);
+ 	ScDocument* pUndoDoc = NULL;
+ 	ScRefUndoData* pUndoData = NULL;
+@@ -2104,6 +2203,8 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
+ 		pUndoData = new ScRefUndoData( pDoc );
+ 	}
+ 
++    String sCodeName;
++    BOOL bHasCodeName = pDoc->GetCodeName( nTab, sCodeName );
+ 	if (pDoc->DeleteTab( nTab, pUndoDoc ))
+ 	{
+ 		if (bRecord)
+@@ -2114,6 +2215,13 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
+ 						new ScUndoDeleteTab( &rDocShell, theTabs, pUndoDoc, pUndoData ));
+ 		}
+ 		//	Views updaten:
++        if( bVbaEnabled )
++        {
++            if( bHasCodeName )
++            {
++                lcl_DeleteModule( rDocShell, sCodeName );
++            }
++        }
+ 		rDocShell.Broadcast( ScTablesHint( SC_TAB_DELETED, nTab ) );
+ 
+ 		if (bWasLinked)
+diff --git sc/source/ui/unoobj/servuno.cxx sc/source/ui/unoobj/servuno.cxx
+index 9a3edb8..b1a8a85 100644
+--- sc/source/ui/unoobj/servuno.cxx
++++ sc/source/ui/unoobj/servuno.cxx
+@@ -38,6 +38,7 @@
+ #include <svx/unofill.hxx>
+ #include <svx/unonrule.hxx>
+ #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
++#include <com/sun/star/container/XNameAccess.hpp>
+ 
+ #include "servuno.hxx"
+ #include "unonames.hxx"
+@@ -61,8 +62,103 @@
+ #include <svx/xmleohlp.hxx>
+ #include <svx/xmlgrhlp.hxx>
+ 
++#include <comphelper/processfactory.hxx>
++
+ using namespace ::com::sun::star;
+ 
++class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
++{
++    uno::Any maWorkbook;
++    uno::Any maCachedObject;
++    uno::Reference<lang::XMultiServiceFactory> mxSF;
++    ScDocShell* mpDocShell;
++public:
++    ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
++    {
++        mxSF.set(comphelper::getProcessServiceFactory());
++        uno::Reference<beans::XPropertySet> xProps(mxSF, uno::UNO_QUERY);
++        if( xProps.is() )
++        {
++            ScDocument* pDoc = mpDocShell->GetDocument();
++            if ( !pDoc )
++                throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("")), uno::Reference< uno::XInterface >() );
++
++            uno::Sequence< uno::Any > aArgs(2);
++            aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() );
++            aArgs[1] = uno::Any( mpDocShell->GetModel() );
++            maWorkbook <<= mxSF->createInstanceWithArguments(  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.excel.Workbook") ), aArgs );
++        }
++    }
++
++    virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
++    {
++        maCachedObject = uno::Any(); // clear cached object
++        String sName = aName;
++        ScDocument* pDoc = mpDocShell->GetDocument();
++        if ( !pDoc )
++            throw uno::RuntimeException();
++        if ( sName == pDoc->GetCodeName() )
++            maCachedObject = maWorkbook;
++        else 
++        {
++            String sCodeName;
++            SCTAB nCount = pDoc->GetTableCount();
++            for( SCTAB i = 0; i < nCount; i++ )
++            {
++                pDoc->GetCodeName( i, sCodeName );
++                if( sCodeName == sName )
++                {
++                    String sSheetName;
++                    if( pDoc->GetName( i, sSheetName ) )
++                    {
++                        uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
++                        uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
++                        uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
++                        uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
++                        uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
++                        uno::Sequence< uno::Any > aArgs(3);
++                        aArgs[0] = maWorkbook;
++                        aArgs[1] = uno::Any( xModel );
++                        aArgs[2] = uno::Any( rtl::OUString( sSheetName ) );
++                        maCachedObject <<= mxSF->createInstanceWithArguments(  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.excel.Worksheet") ), aArgs );
++                        break;
++                    }
++                }
++            }
++        }
++        return maCachedObject.hasValue();
++
++    }
++    ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
++    {
++        OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
++            rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
++        if ( !hasByName( aName ) )
++            throw ::com::sun::star::container::NoSuchElementException();
++        return maCachedObject;
++    }
++    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw (::com::sun::star::uno::RuntimeException)
++    {
++        ScDocument* pDoc = mpDocShell->GetDocument();
++        if ( !pDoc )
++            throw uno::RuntimeException();
++        SCTAB nCount = pDoc->GetTableCount();
++        uno::Sequence< rtl::OUString > aNames( nCount + 1 ); 
++        SCTAB index = 0;
++        String sCodeName;
++        for( ; index < nCount; ++index )
++        {
++            pDoc->GetCodeName( index, sCodeName );
++            aNames[ index ] = sCodeName;
++        }
++        aNames[ index ] = pDoc->GetCodeName();
++        return aNames;
++    }
++    // XElemenAccess
++    virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); }
++    virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; }
++
++};
+ 
+ //------------------------------------------------------------------------
+ 
+@@ -112,7 +208,8 @@ static const sal_Char* __FAR_DATA aProvN
+ 
+         SC_SERVICENAME_CHDATAPROV,                  // SC_SERVICE_CHDATAPROV
+         SC_SERVICENAME_FORMULAPARS,                 // SC_SERVICE_FORMULAPARS
+-        SC_SERVICENAME_OPCODEMAPPER                 // SC_SERVICE_OPCODEMAPPER
++        SC_SERVICENAME_OPCODEMAPPER,                 // SC_SERVICE_OPCODEMAPPER
++"org.openoffice.vba.VBAObjectModuleObjectProvider",// SC_SERVICE_VBAOBJECTPROVIDER
+ 	};
+ 
+ //
+@@ -164,7 +261,8 @@ static const sal_Char* __FAR_DATA aOldNa
+         "",                                         // SC_SERVICE_SHEETDOCSET
+         "",                                         // SC_SERVICE_CHDATAPROV
+         "",                                         // SC_SERVICE_FORMULAPARS
+-        ""                                          // SC_SERVICE_OPCODEMAPPER
++        "",                                         // SC_SERVICE_OPCODEMAPPER
++        "",                                         // SC_SERVICE_VBAOBJECTPROVIDER
+ 	};
+ 
+ 
+@@ -357,6 +455,9 @@ uno::Reference<uno::XInterface> ScServic
+         case SC_SERVICE_OPCODEMAPPER:
+             xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj));
+             break;
++        case SC_SERVICE_VBAOBJECTPROVIDER:
++            xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
++            break;
+ 	}
+ 	return xRet;
+ }
+diff --git sc/source/ui/view/viewfun2.cxx sc/source/ui/view/viewfun2.cxx
+index 674b835..dcbb8c6 100644
+--- sc/source/ui/view/viewfun2.cxx
++++ sc/source/ui/view/viewfun2.cxx
+@@ -57,6 +57,11 @@
+ #include <vcl/sound.hxx>
+ #include <vcl/waitobj.hxx>
+ 
++#include <basic/sbstar.hxx>
++#include <com/sun/star/container/XNameContainer.hpp>
++#include <com/sun/star/script/XLibraryContainer.hpp>
++using namespace com::sun::star;
++
+ #include "viewfunc.hxx"
+ 
+ #include "sc.hrc"
+@@ -2092,15 +2097,42 @@ BOOL ScViewFunc::DeleteTable( SCTAB nTab
+ 	return bSuccess;
+ }
+ 
++void lcl_DeleteModule( ScDocShell* rDocSh, String& sModuleName )
++{
++    SFX_APP()->EnterBasicCall();
++    uno::Reference< script::XLibraryContainer > xLibContainer = rDocSh->GetBasicContainer();
++    DBG_ASSERT( xLibContainer.is(), "No BasicContainer!" );
++
++    uno::Reference< container::XNameContainer > xLib;
++    if( xLibContainer.is() )
++    {
++        String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
++        uno::Any aLibAny = xLibContainer->getByName( aLibName );
++        aLibAny >>= xLib;
++    }
++    if( xLib.is() )
++    {
++        if( xLib->hasByName( sModuleName ) )
++        {
++            xLib->removeByName( sModuleName );
++        }
++    }
++    SFX_APP()->LeaveBasicCall();
++}
++
+ BOOL ScViewFunc::DeleteTables(const SvShorts &TheTabs, BOOL bRecord )
+ {
+ 	ScDocShell* pDocSh	= GetViewData()->GetDocShell();
+ 	ScDocument* pDoc 	= pDocSh->GetDocument();
++    StarBASIC* pStarBASIC = pDocSh->GetBasic();
++    BOOL bVbaEnabled = pStarBASIC->isVBAEnabled();
+ 	SCTAB		nNewTab = TheTabs[0];
+ 	int			i;
+ 	WaitObject aWait( GetFrameWin() );
+ 	if (bRecord && !pDoc->IsUndoEnabled())
+ 		bRecord = FALSE;
++    if ( bVbaEnabled )
++        bRecord = FALSE;
+ 
+ 	while ( nNewTab > 0 && !pDoc->IsVisible( nNewTab ) )
+ 		--nNewTab;
+@@ -2167,9 +2199,18 @@ BOOL ScViewFunc::DeleteTables(const SvSh
+ 
+ 	for(i=TheTabs.Count()-1;i>=0;i--)
+ 	{
++        String sCodeName;
++        BOOL bHasCodeName = pDoc->GetCodeName( TheTabs[sal::static_int_cast<USHORT>(i)], sCodeName );
+         if (pDoc->DeleteTab( TheTabs[sal::static_int_cast<USHORT>(i)], pUndoDoc ))
+ 		{
+ 			bDelDone = TRUE;
++            if( bVbaEnabled )
++            {
++                if( bHasCodeName )
++                {
++                    lcl_DeleteModule( pDocSh, sCodeName );
++                }
++            }
+             pDocSh->Broadcast( ScTablesHint( SC_TAB_DELETED, TheTabs[sal::static_int_cast<USHORT>(i)] ) );
+ 		}
+ 	}
+@@ -2197,6 +2238,7 @@ BOOL ScViewFunc::DeleteTables(const SvSh
+ 		pDocSh->PostPaintExtras();
+ 		pDocSh->SetDocumentModified();
+ 
++
+         SfxApplication* pSfxApp = SFX_APP();                                // Navigator
+         pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
+         pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
+diff --git svx/source/msfilter/msvbasic.cxx svx/source/msfilter/msvbasic.cxx
+index 2e4f500..2eff354 100644
+--- svx/source/msfilter/msvbasic.cxx
++++ svx/source/msfilter/msvbasic.cxx
+@@ -41,6 +41,8 @@
+ #include <rtl/tencinfo.h>   //rtl_getTextEncodingFromWindowsCodePage
+ #include "msvbasic.hxx"
+ 
++using namespace ::com::sun::star::script;
++
+ /*
+ A few urls which may in the future be of some use
+ http://www.virusbtn.com/vb2000/Programme/papers/bontchev.pdf
+@@ -432,7 +434,7 @@ int VBA_Impl::ReadVBAProject(const SvSto
+  *
+ */
+ 
+-ModuleType VBA_Impl::GetModuleType( const UniString& rModuleName )
++ModType VBA_Impl::GetModuleType( const UniString& rModuleName )
+ {
+     ModuleTypeHash::iterator iter = mhModHash.find( rModuleName );
+     ModuleTypeHash::iterator iterEnd = mhModHash.end();
+@@ -440,7 +442,7 @@ ModuleType VBA_Impl::GetModuleType( cons
+     {
+         return iter->second;
+     }
+-    return Unknown;
++    return ModuleType::Unknown;
+ }
+ 
+ bool VBA_Impl::Open( const String &rToplevel, const String &rSublevel )
+@@ -483,7 +485,7 @@ bool VBA_Impl::Open( const String &rTopl
+         static const String sClass(     RTL_CONSTASCII_USTRINGPARAM( "Class" ) );
+         static const String sBaseClass( RTL_CONSTASCII_USTRINGPARAM( "BaseClass" ) );
+         static const String sDocument(  RTL_CONSTASCII_USTRINGPARAM( "Document" ) );
+-        mhModHash[ sThisDoc ] = Class;
++        mhModHash[ sThisDoc ] = ModuleType::Class;
+         while ( pStp->ReadByteStringLine( tmp, meCharSet ) )
+         {
+             xub_StrLen index = tmp.Search( '=' );
+@@ -493,14 +495,14 @@ bool VBA_Impl::Open( const String &rTopl
+                 String value = tmp.Copy( index + 1 );
+                 if ( key == sClass )
+                 {
+-                    mhModHash[ value ] = Class;
++                    mhModHash[ value ] = ModuleType::Class;
+                     OSL_TRACE("Module %s is of type Class",
+                         ::rtl::OUStringToOString( value ,
+                             RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+                 }
+                 else if ( key == sBaseClass )
+                 {
+-                    mhModHash[ value ] =  Form;
++                    mhModHash[ value ] =  ModuleType::Form;
+                     OSL_TRACE("Module %s is of type Form",
+                         ::rtl::OUStringToOString( value ,
+                             RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+@@ -513,14 +515,14 @@ bool VBA_Impl::Open( const String &rTopl
+                     // value is of form <name>/&H<identifier>, strip the identifier
+                     value.Erase( value.Search( '/' ) );
+ 
+-                    mhModHash[ value ] = Document;
++                    mhModHash[ value ] = ModuleType::Document;
+                     OSL_TRACE("Module %s is of type Document VBA",
+                         ::rtl::OUStringToOString( value ,
+                             RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+                 }
+                 else if ( key == sModule )
+                 {
+-                    mhModHash[ value ] = Normal;
++                    mhModHash[ value ] = ModuleType::Normal;
+                     OSL_TRACE("Module %s is of type Normal VBA",
+                         ::rtl::OUStringToOString( value ,
+                             RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+diff --git svx/source/msfilter/msvbasic.hxx svx/source/msfilter/msvbasic.hxx
+index 8492062..a0536ae 100644
+--- svx/source/msfilter/msvbasic.hxx
++++ svx/source/msfilter/msvbasic.hxx
+@@ -45,6 +45,8 @@
+ #include <vector>
+ #endif
+ #include<map>
++#include <com/sun/star/script/ModuleType.hpp>
++using namespace ::com::sun::star::script::ModuleType;
+ 
+ /* class VBA:
+  * The VBA class provides a set of methods to handle Visual Basic For
+@@ -68,13 +70,12 @@ DECLARE_DYNARRAY(StringArray,String *)
+ // #117718# define internal types to distinguish between
+ // module types, form, class & normal
+ // #i37965# DR 2004-12-03: add "Document", used in Excel for macros attached to sheet
+-enum ModuleType { Unknown = 0, Normal, Class, Form, Document };
+ 
+ // #117718# define map to hold types of module
+ //
+-
++typedef sal_Int32 ModType;
+ typedef ::std::map< UniString,
+-    ModuleType > ModuleTypeHash;
++    ModType > ModuleTypeHash;
+ 
+ class VBA_Impl
+ {
+@@ -95,7 +96,7 @@ public:
+     void Output(int len, const sal_uInt8 *data);
+     //
+     // #117718# member map of module names to types of module
+-    ModuleType GetModuleType( const UniString& rModuleName );
++    ModType GetModuleType( const UniString& rModuleName );
+ 
+     std::vector<String> maReferences;
+ private:
+diff --git svx/source/msfilter/svxmsbas.cxx svx/source/msfilter/svxmsbas.cxx
+index 20840a8..27d8054 100644
+--- svx/source/msfilter/svxmsbas.cxx
++++ svx/source/msfilter/svxmsbas.cxx
+@@ -53,6 +53,7 @@ using namespace com::sun::star::awt;
+ 
+ #include <com/sun/star/container/XNameContainer.hpp>
+ #include <com/sun/star/script/XLibraryContainer.hpp>
++#include <com/sun/star/script/ModuleInfo.hpp>
+ using namespace com::sun::star::container;
+ using namespace com::sun::star::script;
+ using namespace com::sun::star::uno;
+@@ -251,6 +252,20 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+         }
+ 		if( xLib.is() )
+ 		{
++            Reference< container::XNameAccess > xVBAObjectForCodeName;
++			if ( !bAsComment )
++            {
++                rDocSh.GetBasic()->SetVBAEnabled( true );
++                Reference< XMultiServiceFactory> xSF(rDocSh.GetModel(), UNO_QUERY);
++                if ( xSF.is() )
++                {
++                    try
++                    {
++                        xVBAObjectForCodeName.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.vba.VBAObjectModuleObjectProvider"))), UNO_QUERY );
++                    }
++                    catch( Exception& ) { }
++                }
++            }
+ 			for( UINT16 i=0; i<nStreamCount;i++)
+ 			{
+ 				StringArray aDecompressed = aVBA.Decompress(i);
+@@ -284,7 +299,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+                 // is the same as the encoding for the names
+                 // that are keys in the map used by GetModuleType method
+                 const String &sOrigVBAModName = aVBA.GetStreamName( i );
+-                ModuleType mType = aVBA.GetModuleType( sOrigVBAModName );
++                ModType mType = aVBA.GetModuleType( sOrigVBAModName );
+ 
+                 rtl::OUString sClassRem( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=" ) );
+ 
+@@ -292,23 +307,23 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+ 
+                 switch( mType )
+                 {
+-                    case Class:
++                    case ModuleType::Class:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAClassModule\n" ) );
+                         break;
+-                    case Form:
++                    case ModuleType::Form:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAFormModule\n" ) );
+                         break;
+-                    case Document:
++                    case ModuleType::Document:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBADocumentModule\n" ) );
+                         break;
+-                    case Normal:
++                    case ModuleType::Normal:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAModule\n" ) );
+                         break;
+-                    case Unknown:
++                    case ModuleType::Unknown:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAUnknown\n" ) );
+                         break;
+@@ -318,10 +333,10 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+                 }
+ 				static ::rtl::OUString sVBAOption( RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n" ) ); 
+ 				static ::rtl::OUString sClassOption( RTL_CONSTASCII_USTRINGPARAM( "Option ClassModule\n" ) ); 
+-				if ( !bAsComment )
++				if ( !bAsComment /*&& !rDocSh.GetBasic()->isVBAEnabled() */)
+ 				{
+ 					modeTypeComment = modeTypeComment + sVBAOption;
+-					if ( mType == Class )
++					if ( mType == ModuleType::Class )
+ 						modeTypeComment = modeTypeComment + sClassOption;
+ 
+ 				}
+@@ -383,12 +398,24 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+ 						aSource += rtl::OUString::createFromAscii("\nEnd Sub");
+ 				}
+ 				::rtl::OUString aModName( sModule );
+-				if ( aSource.getLength() )
+ 				{
+ 					aSource = modeTypeComment + aSource;
+ 
+ 					Any aSourceAny;
+-					aSourceAny <<= aSource;
++                    OSL_TRACE("erm %d", mType );
++                    if (  xVBAObjectForCodeName.is() && ( mType == ModuleType::Document || mType == ModuleType::Class ) )
++                    {
++                        OSL_TRACE("vba processing  %d", mType );
++                        script::ModuleInfo sModuleInfo;
++                        sModuleInfo.ModuleName = aModName;
++                        sModuleInfo.ModuleSource = aSource;
++                        sModuleInfo.ModuleType = mType;
++						if ( mType != ModuleType::Class )
++                        	sModuleInfo.ModuleObject.set( xVBAObjectForCodeName->getByName( aModName ), UNO_QUERY );
++                        aSourceAny <<= sModuleInfo;
++                    }
++                    else
++					    aSourceAny <<= aSource;
+ 					if( xLib->hasByName( aModName ) )
+ 						xLib->replaceByName( aModName, aSourceAny );
+ 					else
+@@ -398,6 +425,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+ 				bRet = true;
+ 			}
+ 		}
++        if( bRet )
+ 		SFX_APP()->LeaveBasicCall();
+ 	}
+ 	return bRet;
+diff --git udkapi/com/sun/star/script/ModuleInfo.idl udkapi/com/sun/star/script/ModuleInfo.idl
+new file mode 100644
+index 0000000..00204f9
+--- /dev/null
++++ udkapi/com/sun/star/script/ModuleInfo.idl
+@@ -0,0 +1,57 @@
++/*************************************************************************
++ *
++ *  OpenOffice.org - a multi-platform office productivity suite
++ *
++ *  $RCSfile: ModuleInfo.idl,v $
++ *
++ *  $Revision: 1.2 $
++ *
++ *  last change: $Author: rt $ $Date: 2006/05/05 10:14:46 $
++ *
++ *  The Contents of this file are made available subject to
++ *  the terms of GNU Lesser General Public License Version 2.1.
++ *
++ *
++ *    GNU Lesser General Public License Version 2.1
++ *    =============================================
++ *    Copyright 2005 by Sun Microsystems, Inc.
++ *    901 San Antonio Road, Palo Alto, CA 94303, USA
++ *
++ *    This library is free software; you can redistribute it and/or
++ *    modify it under the terms of the GNU Lesser General Public
++ *    License version 2.1, as published by the Free Software Foundation.
++ *
++ *    This library 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 for more details.
++ *
++ *    You should have received a copy of the GNU Lesser General Public
++ *    License along with this library; if not, write to the Free Software
++ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ *    MA  02111-1307  USA
++ *
++ ************************************************************************/
++
++#ifndef __com_sun_star_script_ModuleInfo_idl__
++#define __com_sun_star_script_ModuleInfo_idl__
++
++#ifndef __com_sun_star_uno_XInterface_idl__
++#include <com/sun/star/uno/XInterface.idl>
++#endif
++
++//=============================================================================
++module com {  module sun {  module star { module script {
++struct ModuleInfo
++{
++	string ModuleName; 
++	string ModuleSource; 
++	com::sun::star::uno::XInterface ModuleObject; 
++	short ModuleType; // string?
++};
++
++//=============================================================================
++
++}; }; }; };
++
++#endif
+diff --git udkapi/com/sun/star/script/ModuleType.idl udkapi/com/sun/star/script/ModuleType.idl
+new file mode 100644
+index 0000000..3295c52
+--- /dev/null
++++ udkapi/com/sun/star/script/ModuleType.idl
+@@ -0,0 +1,58 @@
++/*************************************************************************
++ *
++ *  OpenOffice.org - a multi-platform office productivity suite
++ *
++ *  $RCSfile: ModuleType.idl,v $
++ *
++ *  $Revision: 1.2 $
++ *
++ *  last change: $Author: rt $ $Date: 2006/05/05 10:14:46 $
++ *
++ *  The Contents of this file are made available subject to
++ *  the terms of GNU Lesser General Public License Version 2.1.
++ *
++ *
++ *    GNU Lesser General Public License Version 2.1
++ *    =============================================
++ *    Copyright 2005 by Sun Microsystems, Inc.
++ *    901 San Antonio Road, Palo Alto, CA 94303, USA
++ *
++ *    This library is free software; you can redistribute it and/or
++ *    modify it under the terms of the GNU Lesser General Public
++ *    License version 2.1, as published by the Free Software Foundation.
++ *
++ *    This library 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 for more details.
++ *
++ *    You should have received a copy of the GNU Lesser General Public
++ *    License along with this library; if not, write to the Free Software
++ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ *    MA  02111-1307  USA
++ *
++ ************************************************************************/
++
++#ifndef __com_sun_star_script_ModuleType_idl__
++#define __com_sun_star_script_ModuleType_idl__
++
++#ifndef __com_sun_star_uno_XInterface_idl__
++#include <com/sun/star/uno/XInterface.idl>
++#endif
++
++//=============================================================================
++module com {  module sun {  module star { module script {
++published constants ModuleType
++{
++    const long Unknown = 0;
++    const long Normal = 1;  
++    const long Class = 2;
++    const long Form = 3;
++    const long Document = 4;
++};
++
++//=============================================================================
++
++}; }; }; };
++
++#endif
+diff --git udkapi/com/sun/star/script/makefile.mk udkapi/com/sun/star/script/makefile.mk
+index 745df3e..69e06dd 100644
+--- udkapi/com/sun/star/script/makefile.mk
++++ udkapi/com/sun/star/script/makefile.mk
+@@ -85,6 +85,8 @@ IDLFILES=\
+ 	XScriptEventsAttacher.idl\
+ 	XDefaultMethod.idl\
+ 	XDefaultProperty.idl\
++    ModuleInfo.idl\
++    ModuleType.idl\
+ 
+ # ------------------------------------------------------------------
+ 
+--- basic/source/uno/scriptcont.cxx	2008-06-16 17:14:58.000000000 +0100
++++ basic/source/uno//scriptcont.cxx	2008-06-16 17:25:42.000000000 +0100
+@@ -214,7 +214,12 @@ void SAL_CALL SfxScriptLibraryContainer:
+ 	xmlscript::ModuleDescriptor aMod;
+ 	aMod.aName = aElementName;
+ 	aMod.aLanguage = maScriptLanguage;
+-	aElement >>= aMod.aCode;
++	// make sure we export source
++	::com::sun::star::script::ModuleInfo mInfo;
++	if ( aElement >>= mInfo )
++		aMod.aCode = mInfo.ModuleSource;
++	else
++		aElement >>= aMod.aCode;
+ 	xmlscript::exportScriptModule( xHandler, aMod );
+ }
+ 
+@@ -1171,7 +1176,11 @@ void SfxScriptLibrary::storeResourcesToS
+ bool SfxScriptLibrary::containsValidModule( const Any& aElement )
+ {
+ 	OUString sModuleText;
+-	aElement >>= sModuleText;
++	::com::sun::star::script::ModuleInfo mInfo;
++	if ( aElement >>= mInfo )
++		sModuleText = mInfo.ModuleSource;
++	else
++		aElement >>= sModuleText;
+ 	return ( sModuleText.getLength() > 0 );
+ }
+ 

Modified: trunk/patches/vba/ObjectModule.diff
==============================================================================
--- trunk/patches/vba/ObjectModule.diff	(original)
+++ trunk/patches/vba/ObjectModule.diff	Tue Jul 22 11:34:41 2008
@@ -2,7 +2,7 @@
 index aed5958..3d79067 100644
 --- basctl/source/basicide/basides1.cxx
 +++ basctl/source/basicide/basides1.cxx
-@@ -1201,10 +1201,16 @@ IDEBaseWindow* BasicIDEShell::FindWindow
+@@ -1201,10 +1201,16 @@ IDEBaseWindow* BasicIDEShell::FindWindow( const ScriptDocument& rDocument, const
                  // return any non-suspended window
                  return pWin;
              }
@@ -25,7 +25,7 @@
 index 76dcea0..90cec19 100644
 --- basctl/source/basicide/basides2.cxx
 +++ basctl/source/basicide/basides2.cxx
-@@ -251,9 +251,12 @@ ModulWindow* BasicIDEShell::CreateBasWin
+@@ -251,9 +251,12 @@ ModulWindow* BasicIDEShell::CreateBasWin( const ScriptDocument& rDocument, const
  
          if ( bSuccess )
          {
@@ -41,7 +41,7 @@
          }
  	}
  	else
-@@ -268,7 +271,8 @@ ModulWindow* BasicIDEShell::CreateBasWin
+@@ -268,7 +271,8 @@ ModulWindow* BasicIDEShell::CreateBasWin( const ScriptDocument& rDocument, const
  		}
  		DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
  	}
@@ -52,7 +52,7 @@
  	pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
  	if ( !pCurWin )
 diff --git basctl/source/basicide/basidesh.cxx basctl/source/basicide/basidesh.cxx
-index 666c4aa..2e854f8 100644
+index 03459cc..d921d99 100644
 --- basctl/source/basicide/basidesh.cxx
 +++ basctl/source/basicide/basidesh.cxx
 @@ -80,6 +80,9 @@
@@ -137,7 +137,7 @@
  
  TYPEINIT1( BasicIDEShell, SfxViewShell );
  
-@@ -124,6 +192,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFra
+@@ -124,6 +192,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFrame* pFrame_, SfxViewShell* /* pOldShell
          m_bAppBasicModified( FALSE ),
          m_aNotifier( *this )
  {
@@ -145,23 +145,7 @@
  	Init();
      GnBasicIDEShellCount++;
  }
-@@ -139,6 +208,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFra
-         m_aNotifier( *this )
- {
- 	DBG_ERROR( "Zweite Ansicht auf Debugger nicht moeglich!" );
-+    m_xLibListener = new ContainerListenerImpl( this );
-     GnBasicIDEShellCount++;
- }
- 
-@@ -153,6 +223,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFra
-         m_aNotifier( *this )
- {
- 	Init();
-+    m_xLibListener = new ContainerListenerImpl( this );
-     GnBasicIDEShellCount++;
- }
- 
-@@ -243,6 +314,12 @@ __EXPORT BasicIDEShell::~BasicIDEShell()
+@@ -215,6 +284,12 @@ __EXPORT BasicIDEShell::~BasicIDEShell()
  	delete pTabBar;
  	delete pObjectCatalog;
  	DestroyModulWindowLayout();
@@ -174,7 +158,7 @@
  	// MI: Das gab einen GPF im SDT beim Schliessen da dann der ViewFrame die
  	// ObjSh loslaesst. Es wusste auch keiner mehr wozu das gut war.
  	// GetViewFrame()->GetObjectShell()->Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
-@@ -968,7 +1045,15 @@ void BasicIDEShell::SetCurLib( const Scr
+@@ -935,7 +1010,15 @@ void BasicIDEShell::SetCurLib( const ScriptDocument& rDocument, String aLibName,
  {
      if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
      {
@@ -191,7 +175,7 @@
          if ( bUpdateWindows )
              UpdateWindows();
 diff --git basctl/source/basicide/scriptdocument.cxx basctl/source/basicide/scriptdocument.cxx
-index 5d22053..0483cce 100644
+index d5990a4..408f88d 100644
 --- basctl/source/basicide/scriptdocument.cxx
 +++ basctl/source/basicide/scriptdocument.cxx
 @@ -56,6 +56,7 @@
@@ -202,7 +186,7 @@
  /** === end UNO includes === **/
  
  #include <sfx2/objsh.hxx>
-@@ -141,6 +142,7 @@ namespace basctl
+@@ -142,6 +143,7 @@ namespace basctl
      using ::com::sun::star::uno::RuntimeException;
      using ::com::sun::star::document::XEventBroadcaster;
      using ::com::sun::star::document::XEmbeddedScripts;
@@ -210,7 +194,7 @@
      /** === end UNO using === **/
      namespace MacroExecMode = ::com::sun::star::document::MacroExecMode;
      namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag;
-@@ -673,6 +675,15 @@ namespace basctl
+@@ -674,6 +676,15 @@ namespace basctl
              }
  
  		    // insert element by new name in container
@@ -226,7 +210,7 @@
  		    xLib->insertByName( _rNewName, aElement );
              return true;
          }
-@@ -1431,7 +1442,15 @@ namespace basctl
+@@ -1392,7 +1403,15 @@ namespace basctl
          Any aCode;
          if ( !m_pImpl->getModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, aCode ) )
              return false;
@@ -244,40 +228,23 @@
      }
  
 diff --git basctl/source/inc/basidesh.hxx basctl/source/inc/basidesh.hxx
-index 109fedd..fa4cbe9 100644
+index 6b3690c..e34c58c 100644
 --- basctl/source/inc/basidesh.hxx
 +++ basctl/source/inc/basidesh.hxx
-@@ -48,7 +48,7 @@
- #ifndef _COM_SUN_STAR_IO_XINPUTSTREAMPROVIDER_HXX_
+@@ -49,6 +49,7 @@
  #include <com/sun/star/io/XInputStreamProvider.hpp>
  #endif
--
+ 
 +#include <com/sun/star/container/XContainerListener.hpp>
  
  //----------------------------------------------------------------------------
  
-@@ -76,13 +76,15 @@ DECLARE_TABLE( IDEWindowTable, IDEBaseWi
- typedef Table IDEWindowTable;
- #endif
- 
-+namespace css = ::com::sun::star;
-+
- class BasicIDEShell :public SfxViewShell
-                     ,public ::basctl::DocumentEventListener
- {
- friend class JavaDebuggingListenerImpl;
- friend class LocalizationMgr;
- friend class BasicIDE;
--
-+friend class ContainerListenerImpl;
- 	ObjectCatalog* 		pObjectCatalog;
- 
- 	IDEWindowTable		aIDEWindowTable;
-@@ -102,6 +104,7 @@ friend class BasicIDE;
+@@ -107,6 +108,8 @@ friend bool BasicIDE::RemoveDialog( const ScriptDocument& rDocument, const Strin
      BOOL                m_bAppBasicModified;
      ::basctl::DocumentEventNotifier
                          m_aNotifier;
-+	css::uno::Reference< css::container::XContainerListener > m_xLibListener; 	
++friend class ContainerListenerImpl;
++    ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener > m_xLibListener;
  
  #if _SOLAR__PRIVATE
  	void				Init();
@@ -327,6 +294,77 @@
  };
  
  #ifndef __SB_SBMODULEREF_HXX
+diff --git basic/inc/basic/sbobjmod.hxx basic/inc/basic/sbobjmod.hxx
+new file mode 100644
+index 0000000..7a8f096
+--- /dev/null
++++ basic/inc/basic/sbobjmod.hxx
+@@ -0,0 +1,65 @@
++/*************************************************************************
++ *
++ *  OpenOffice.org - a multi-platform office productivity suite
++ *
++ *  $RCSfile: sbobjmod.hxx,v $
++ *
++ *  $Revision: 1.4 $
++ *
++ *  last change: $Author:  $ $Date: 2007/08/27 16:31:39 $
++ *
++ *  The Contents of this file are made available subject to
++ *  the terms of GNU Lesser General Public License Version 2.1.
++ *
++ *
++ *    GNU Lesser General Public License Version 2.1
++ *    =============================================
++ *    Copyright 2005 by Sun Microsystems, Inc.
++ *    901 San Antonio Road, Palo Alto, CA 94303, USA
++ *
++ *    This library is free software; you can redistribute it and/or
++ *    modify it under the terms of the GNU Lesser General Public
++ *    License version 2.1, as published by the Free Software Foundation.
++ *
++ *    This library 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 for more details.
++ *
++ *    You should have received a copy of the GNU Lesser General Public
++ *    License along with this library; if not, write to the Free Software
++ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ *    MA  02111-1307  USA
++ *
++ ************************************************************************/
++
++#ifndef _SB_OBJMOD_HXX
++#define _SB_OBJMOD_HXX
++
++#include <basic/sbmod.hxx>
++#include <basic/sbstar.hxx>
++#include <com/sun/star/script/ModuleInfo.hpp>
++#include <com/sun/star/lang/XEventListener.hpp>
++#include <com/sun/star/awt/XDialog.hpp>
++
++namespace css = ::com::sun::star;
++
++// Basic-Module for excel object.
++
++class SbObjModule : public SbModule
++{
++public:
++    TYPEINFO();
++    SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible );
++    virtual SbxVariable* Find( const XubString& rName, SbxClassType t );
++    SbxVariable* GetObject();
++};
++
++#ifndef __SB_SBOBJMODULEREF_HXX
++#define __SB_SBOBJMODULEREF_HXX
++
++SV_DECL_IMPL_REF(SbObjModule);
++
++#endif
++#endif
++
 diff --git basic/inc/basic/sbstar.hxx basic/inc/basic/sbstar.hxx
 index ebd10ae..3c7e149 100644
 --- basic/inc/basic/sbstar.hxx
@@ -367,7 +405,7 @@
  	// #60175 TRUE: SFX-Resource wird bei Basic-Fehlern nicht angezogen
  	static void StaticSuppressSfxResource( BOOL bSuppress );
 diff --git basic/source/basmgr/basmgr.cxx basic/source/basmgr/basmgr.cxx
-index 54f6426..b5394ae 100644
+index 73eb4cb..931498e 100644
 --- basic/source/basmgr/basmgr.cxx
 +++ basic/source/basmgr/basmgr.cxx
 @@ -67,6 +67,8 @@
@@ -379,19 +417,11 @@
  
  #include <cppuhelper/implbase1.hxx>
  
-@@ -110,6 +112,7 @@ static const char* szScriptLanguage = "S
- static const String BasicStreamName( String::CreateFromAscii(szBasicStorage) );
- static const String ManagerStreamName( String::CreateFromAscii(szManagerStream) );
- 
-+//enum ModuleType { Unknown = 0, Normal, Class, Form, Document };
- 
- #define	DEFINE_CONST_UNICODE(CONSTASCII)    UniString(RTL_CONSTASCII_USTRINGPARAM(CONSTASCII))
- 
-@@ -244,9 +247,18 @@ void BasMgrContainerListenerImpl::addLib
+@@ -243,9 +245,18 @@ void BasMgrContainerListenerImpl::addLibraryModulesImpl( BasicManager* pMgr,
  		{
- 			OUString aModuleName = pNames[ j ];
+ 			::rtl::OUString aModuleName = pNames[ j ];
  			Any aElement = xLibNameAccess->getByName( aModuleName );
--			OUString aMod;
+-			::rtl::OUString aMod;
 -			aElement >>= aMod;
 -			pLib->MakeModule32( aModuleName, aMod );
 +            ModuleInfo mInfo;
@@ -402,23 +432,23 @@
 +            }
 +            else
 +            {
-+			    OUString aMod;
++			    ::rtl::OUString aMod;
 +			    aElement >>= aMod;
 +			    pLib->MakeModule32( aModuleName, aMod );
 +            }
  		}
  	}
  
-@@ -283,8 +295,6 @@ void SAL_CALL BasMgrContainerListenerImp
+@@ -282,8 +293,6 @@ void SAL_CALL BasMgrContainerListenerImpl::elementInserted( const ContainerEvent
  	}
  	else
  	{
--		OUString aMod;
+-		::rtl::OUString aMod;
 -		Event.Element >>= aMod;
  
  		StarBASIC* pLib = mpMgr->GetLib( maLibName );
  		DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::elementInserted: Unknown lib!");
-@@ -293,7 +303,17 @@ void SAL_CALL BasMgrContainerListenerImp
+@@ -292,7 +301,17 @@ void SAL_CALL BasMgrContainerListenerImpl::elementInserted( const ContainerEvent
      		SbModule* pMod = pLib->FindModule( aName );
              if( !pMod )
              {
@@ -430,19 +460,19 @@
 +                }
 +                else
 +                {
-+        		    OUString aMod;
++        		    ::rtl::OUString aMod;
 +        		    Event.Element >>= aMod;
 +			        pLib->MakeModule32( aName, aMod );
 +                }
  			    pLib->SetModified( FALSE );
              }
  		}
-@@ -319,13 +339,23 @@ void SAL_CALL BasMgrContainerListenerImp
+@@ -318,13 +337,23 @@ void SAL_CALL BasMgrContainerListenerImpl::elementReplaced( const ContainerEvent
  	StarBASIC* pLib = mpMgr->GetLib( maLibName );
  	if( pLib )
  	{
 -		SbModule* pMod = pLib->FindModule( aName );
--		OUString aMod;
+-		::rtl::OUString aMod;
 -		Event.Element >>= aMod;
 -		if( pMod )
 -			pMod->SetSource32( aMod );
@@ -458,7 +488,7 @@
 +        {
 +		    SbModule* pMod = pLib->FindModule( aName );
 +
-+		    OUString aMod;
++		    ::rtl::OUString aMod;
 +            Event.Element >>= aMod;
 +		    if( pMod )
 +		   	    pMod->SetSource32( aMod );
@@ -490,7 +520,7 @@
  // #pragma SW_SEGMENT_CLASS( SBASIC, SBASIC_CODE )
  
  SV_IMPL_VARARR(SbTextPortions,SbTextPortion)
-@@ -249,6 +254,8 @@ SbxObject* SbiFactory::CreateObject( con
+@@ -249,6 +254,8 @@ SbxObject* SbiFactory::CreateObject( const String& rClass )
  	else
  	if( rClass.EqualsIgnoreCaseAscii( "Collection" ) )
  	{
@@ -499,7 +529,7 @@
  		String aCollectionName( RTL_CONSTASCII_USTRINGPARAM("Collection") );
  		return new BasicCollection( aCollectionName );
  	}
-@@ -446,6 +453,7 @@ SbClassModuleObject::SbClassModuleObject
+@@ -446,6 +453,7 @@ SbClassModuleObject::SbClassModuleObject( SbModule* pClassModule )
  			}
  		}
  	}
@@ -507,7 +537,7 @@
  }
  
  SbClassModuleObject::~SbClassModuleObject()
-@@ -581,6 +589,7 @@ StarBASIC::StarBASIC( StarBASIC* p, BOOL
+@@ -581,6 +589,7 @@ StarBASIC::StarBASIC( StarBASIC* p, BOOL bIsDocBasic  )
  	SetParent( p );
  	pLibInfo = NULL;
  	bNoRtl = bBreak = FALSE;
@@ -515,7 +545,7 @@
  	pModules = new SbxArray;
  
  	if( !GetSbData()->nInst++ )
-@@ -683,12 +692,38 @@ SbModule* StarBASIC::MakeModule( const S
+@@ -683,12 +692,38 @@ SbModule* StarBASIC::MakeModule( const String& rName, const String& rSrc )
  
  SbModule* StarBASIC::MakeModule32( const String& rName, const ::rtl::OUString& rSrc )
  {
@@ -557,7 +587,7 @@
  }
  
  void StarBASIC::Insert( SbxVariable* pVar )
-@@ -862,6 +897,12 @@ SbxVariable* StarBASIC::Find( const Stri
+@@ -862,6 +897,12 @@ SbxVariable* StarBASIC::Find( const String& rName, SbxClassType t )
  				}
  				pNamed = p;
  			}
@@ -571,7 +601,7 @@
  			// GBLSEARCH-Flag rausnehmen (wg. Rekursion)
  			USHORT nGblFlag = p->GetFlags() & SBX_GBLSEARCH;
 diff --git basic/source/classes/sbxmod.cxx basic/source/classes/sbxmod.cxx
-index de94bf3..388f437 100644
+index d738539..0d6c647 100644
 --- basic/source/classes/sbxmod.cxx
 +++ basic/source/classes/sbxmod.cxx
 @@ -51,6 +51,8 @@
@@ -609,16 +639,7 @@
  
  SV_DECL_VARARR(SbiBreakpoints,USHORT,4,4)
  SV_IMPL_VARARR(SbiBreakpoints,USHORT)
-@@ -80,7 +94,7 @@ SV_IMPL_VARARR(SbiBreakpoints,USHORT)
- SV_IMPL_VARARR(HighlightPortions, HighlightPortion)
- 
- // ##########################################################################
--// ACHTUNG!!!  Alle Woerter dieser Tabelle müKLEIN geschrieben werden!!!
-+// ACHTUNG!!!  Alle Woerter dieser Tabelle mÃssen KLEIN geschrieben werden!!!
- // ##########################################################################
- static const char* strListBasicKeyWords[] = {
- 	"access",
-@@ -221,12 +235,13 @@ extern "C" int CDECL compare_strings( co
+@@ -221,12 +235,13 @@ extern "C" int CDECL compare_strings( const void *arg1, const void *arg2 )
  // Ein BASIC-Modul hat EXTSEARCH gesetzt, damit die im Modul enthaltenen
  // Elemente von anderen Modulen aus gefunden werden koennen.
  
@@ -645,7 +666,7 @@
  	if( !pRes && pImage )
  	{
  		SbiInstance* pInst = pINST;
-@@ -561,6 +579,7 @@ void SbModule::SetSource32( const ::rtl:
+@@ -561,6 +579,7 @@ void SbModule::SetSource32( const ::rtl::OUString& r )
  	aOUSource = r;
  	StartDefinitions();
  	SbiTokenizer aTok( r );
@@ -668,7 +689,7 @@
  			}
  			eLastTok = eCurTok;
  		}
-@@ -731,10 +742,19 @@ void ClearUnoObjectsInRTL_Impl( StarBASI
+@@ -731,10 +750,19 @@ void ClearUnoObjectsInRTL_Impl( StarBASIC* pBasic )
      if( ((StarBASIC*)p) != pBasic )
  	    ClearUnoObjectsInRTL_Impl_Rek( (StarBASIC*)p );
  }
@@ -688,7 +709,7 @@
  	static USHORT nMaxCallLevel = 0;
  	static String aMSOMacroRuntimeLibName = String::CreateFromAscii( "Launcher" );
  	static String aMSOMacroRuntimeAppSymbol = String::CreateFromAscii( "Application" );
-@@ -826,10 +846,10 @@ USHORT SbModule::Run( SbMethod* pMeth )
+@@ -826,10 +854,10 @@ USHORT SbModule::Run( SbMethod* pMeth )
  			if( pRt->pNext )
  				pRt->pNext->block();
  			pINST->pRun = pRt;
@@ -701,7 +722,7 @@
                          }
  			while( pRt->Step() ) {}
  			if( pRt->pNext )
-@@ -1404,7 +1424,6 @@ BOOL SbModule::LoadBinaryData( SvStream&
+@@ -1404,7 +1432,6 @@ BOOL SbModule::LoadBinaryData( SvStream& rStrm )
      return bRet;
  }
  
@@ -709,11 +730,10 @@
  BOOL SbModule::LoadCompleted()
  {
  	SbxArray* p = GetMethods();
-@@ -2223,3 +2242,44 @@ SbProcedureProperty::~SbProcedurePropert
- {}
+@@ -2207,6 +2234,47 @@ SbJScriptMethod::~SbJScriptMethod()
  
  
-+/////////////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////////////
 +SbObjModule::SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible )
 +    : SbModule( mInfo.ModuleName, bIsVbaCompatible )
 +{
@@ -754,8 +774,12 @@
 +        pVar = SbModule::Find( rName, t );
 +    return pVar;
 +}
++/////////////////////////////////////////////////////////////////////////
+ 
+ SbProperty::SbProperty( const String& r, SbxDataType t, SbModule* p )
+ 		: SbxProperty( r, t ), pMod( p )
 diff --git basic/source/comp/codegen.cxx basic/source/comp/codegen.cxx
-index 9f88fb6..46e0450 100644
+index 9f88fb6..4674134 100644
 --- basic/source/comp/codegen.cxx
 +++ basic/source/comp/codegen.cxx
 @@ -130,12 +130,12 @@ void SbiCodeGen::Save()
@@ -795,10 +819,10 @@
  				}
  				if( nPass == 1 )
 diff --git basic/source/comp/parser.cxx basic/source/comp/parser.cxx
-index 931b6c7..7bc712e 100644
+index 4d571fb..2fa8821 100644
 --- basic/source/comp/parser.cxx
 +++ basic/source/comp/parser.cxx
-@@ -144,7 +144,8 @@ SbiParser::SbiParser( StarBASIC* pb, SbM
+@@ -144,7 +144,8 @@ SbiParser::SbiParser( StarBASIC* pb, SbModule* pm )
  	bNewGblDefs =
  	bSingleLineIf =
  	bExplicit = FALSE;
@@ -808,7 +832,7 @@
  	pPool	 = &aPublics;
  	for( short i = 0; i < 26; i++ )
  		eDefTypes[ i ] = SbxVARIANT;    // Kein expliziter Defaulttyp
-@@ -157,6 +158,10 @@ SbiParser::SbiParser( StarBASIC* pb, SbM
+@@ -157,6 +158,10 @@ SbiParser::SbiParser( StarBASIC* pb, SbModule* pm )
  
  	rTypeArray = new SbxArray; // Array fuer Benutzerdefinierte Typen
  	rEnumArray = new SbxArray; // Array for Enum types
@@ -819,7 +843,7 @@
  }
  
  
-@@ -751,8 +756,9 @@ void SbiParser::Option()
+@@ -755,8 +760,9 @@ void SbiParser::Option()
  
  		case CLASSMODULE:
  			bClassModule = TRUE; 
@@ -830,7 +854,7 @@
  			if( Next() == NUMBER )
  			{
  				if ( nVal == 1 || nVal == 0 )
-@@ -760,6 +766,10 @@ void SbiParser::Option()
+@@ -764,6 +770,10 @@ void SbiParser::Option()
  					bVBASupportOn = ( nVal == 1 );
  					if ( bVBASupportOn )
  						EnableCompatibility();
@@ -841,74 +865,6 @@
  					break;
  				}
  			}
---- /dev/null	2007-05-04 11:54:36.000000000 +0100
-+++ basic/inc/basic/sbobjmod.hxx	2008-05-28 10:58:33.000000000 +0100
-@@ -0,0 +1,65 @@
-+/*************************************************************************
-+ *
-+ *  OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ *  $RCSfile: sbobjmod.hxx,v $
-+ *
-+ *  $Revision: 1.4 $
-+ *
-+ *  last change: $Author:  $ $Date: 2007/08/27 16:31:39 $
-+ *
-+ *  The Contents of this file are made available subject to
-+ *  the terms of GNU Lesser General Public License Version 2.1.
-+ *
-+ *
-+ *    GNU Lesser General Public License Version 2.1
-+ *    =============================================
-+ *    Copyright 2005 by Sun Microsystems, Inc.
-+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
-+ *
-+ *    This library is free software; you can redistribute it and/or
-+ *    modify it under the terms of the GNU Lesser General Public
-+ *    License version 2.1, as published by the Free Software Foundation.
-+ *
-+ *    This library 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 for more details.
-+ *
-+ *    You should have received a copy of the GNU Lesser General Public
-+ *    License along with this library; if not, write to the Free Software
-+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
-+ *    MA  02111-1307  USA
-+ *
-+ ************************************************************************/
-+
-+#ifndef _SB_OBJMOD_HXX
-+#define _SB_OBJMOD_HXX
-+
-+#include <basic/sbmod.hxx>
-+#include <basic/sbstar.hxx>
-+#include <com/sun/star/script/ModuleInfo.hpp>
-+#include <com/sun/star/lang/XEventListener.hpp>
-+#include <com/sun/star/awt/XDialog.hpp>
-+
-+namespace css = ::com::sun::star;
-+
-+// Basic-Module for excel object.
-+
-+class SbObjModule : public SbModule
-+{
-+public:
-+    TYPEINFO();
-+    SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible );
-+    virtual SbxVariable* Find( const XubString& rName, SbxClassType t );
-+    SbxVariable* GetObject();
-+};
-+
-+#ifndef __SB_SBOBJMODULEREF_HXX
-+#define __SB_SBOBJMODULEREF_HXX
-+
-+SV_DECL_IMPL_REF(SbObjModule);
-+
-+#endif
-+#endif
-+
 diff --git basic/source/inc/codegen.hxx basic/source/inc/codegen.hxx
 index ad11d02..a054af7 100644
 --- basic/source/inc/codegen.hxx
@@ -933,7 +889,7 @@
  
  #endif
 diff --git basic/source/runtime/methods1.cxx basic/source/runtime/methods1.cxx
-index 313bf17..c891643 100644
+index e72f78b..bb24705 100644
 --- basic/source/runtime/methods1.cxx
 +++ basic/source/runtime/methods1.cxx
 @@ -44,6 +44,7 @@
@@ -952,8 +908,8 @@
  
  #include "sbintern.hxx"
  #include "runtime.hxx"
-@@ -2585,13 +2587,13 @@ RTLFUNC(Me)
-     
+@@ -2594,14 +2596,14 @@ RTLFUNC(Me)
+ 
  	SbModule* pActiveModule = pINST->GetActiveModule();
  	SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pActiveModule);
 +    SbxVariableRef refVar = rPar.Get(0);
@@ -970,8 +926,9 @@
  		refVar->PutObject( pClassModuleObject );
 -	}
  }
+ 
 diff --git basic/source/runtime/runtime.cxx basic/source/runtime/runtime.cxx
-index 020b7e2..9de19fd 100644
+index a51624b..5cec3e2 100644
 --- basic/source/runtime/runtime.cxx
 +++ basic/source/runtime/runtime.cxx
 @@ -53,7 +53,8 @@ bool SbiRuntime::isVBAEnabled()
@@ -984,7 +941,7 @@
  	return result; 
  }
  
-@@ -64,6 +65,24 @@ void StarBASIC::StaticEnableReschedule( 
+@@ -64,6 +65,24 @@ void StarBASIC::StaticEnableReschedule( BOOL bReschedule )
  {
      bStaticGlobalEnableReschedule = bReschedule;
  }
@@ -1009,7 +966,7 @@
  
  
  struct SbiArgvStack {					// Argv stack:
-@@ -519,6 +538,7 @@ SbiRuntime::SbiRuntime( SbModule* pm, Sb
+@@ -520,6 +539,7 @@ SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, UINT32 nStart )
  	nForLvl   = 0;
  	nOps	  = 0;
  	refExprStk = new SbxArray;
@@ -1017,7 +974,7 @@
  #if defined GCC
  	SetParameters( pe ? pe->GetParameters() : (class SbxArray *)NULL );
  #else
-@@ -526,7 +546,6 @@ SbiRuntime::SbiRuntime( SbModule* pm, Sb
+@@ -527,7 +547,6 @@ SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, UINT32 nStart )
  #endif
  	pRefSaveList = NULL;
  	pItemStoreList = NULL;
@@ -1026,10 +983,10 @@
  
  SbiRuntime::~SbiRuntime()
 diff --git basic/source/uno/namecont.cxx basic/source/uno/namecont.cxx
-index 93ea95d..e5f37c7 100644
+index 12b1a67..5c9c44b 100644
 --- basic/source/uno/namecont.cxx
 +++ basic/source/uno/namecont.cxx
-@@ -72,6 +72,9 @@
+@@ -76,6 +76,9 @@
  #include <cppuhelper/exc_hlp.hxx>
  #include <basic/sbmod.hxx>
  
@@ -1039,7 +996,7 @@
  
  namespace basic
  {
-@@ -150,7 +153,7 @@ void NameContainer::replaceByName( const
+@@ -155,7 +158,7 @@ void NameContainer::replaceByName( const OUString& aName, const Any& aElement )
  	throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
  {
  	Type aAnyType = aElement.getValueType();
@@ -1048,7 +1005,7 @@
  		throw IllegalArgumentException();
  
  	NameContainerNameMap::iterator aIt = mHashMap.find( aName );
-@@ -192,7 +195,7 @@ void NameContainer::insertByName( const 
+@@ -197,7 +200,7 @@ void NameContainer::insertByName( const OUString& aName, const Any& aElement )
  	throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
  {
  	Type aAnyType = aElement.getValueType();
@@ -1057,6 +1014,37 @@
  		throw IllegalArgumentException();
  
  	NameContainerNameMap::iterator aIt = mHashMap.find( aName );
+diff --git basic/source/uno/scriptcont.cxx basic/source/uno/scriptcont.cxx
+index f47dc64..4a46e98 100644
+--- basic/source/uno/scriptcont.cxx
++++ basic/source/uno/scriptcont.cxx
+@@ -214,7 +214,12 @@ void SAL_CALL SfxScriptLibraryContainer::writeLibraryElement
+ 	xmlscript::ModuleDescriptor aMod;
+ 	aMod.aName = aElementName;
+ 	aMod.aLanguage = maScriptLanguage;
+-	aElement >>= aMod.aCode;
++	// make sure we export source
++	::com::sun::star::script::ModuleInfo mInfo;
++	if ( aElement >>= mInfo )
++		aMod.aCode = mInfo.ModuleSource;
++	else
++		aElement >>= aMod.aCode;
+ 	xmlscript::exportScriptModule( xHandler, aMod );
+ }
+ 
+@@ -1171,7 +1176,11 @@ void SfxScriptLibrary::storeResourcesToStorage( const ::com::sun::star::uno::Ref
+ bool SfxScriptLibrary::containsValidModule( const Any& aElement )
+ {
+ 	OUString sModuleText;
+-	aElement >>= sModuleText;
++	::com::sun::star::script::ModuleInfo mInfo;
++	if ( aElement >>= mInfo )
++		sModuleText = mInfo.ModuleSource;
++	else
++		aElement >>= sModuleText;
+ 	return ( sModuleText.getLength() > 0 );
+ }
+ 
 diff --git sc/inc/servuno.hxx sc/inc/servuno.hxx
 index c93cdb3..73fdec1 100644
 --- sc/inc/servuno.hxx
@@ -1073,10 +1061,10 @@
  
  
 diff --git sc/source/filter/excel/excimp8.cxx sc/source/filter/excel/excimp8.cxx
-index c7dac08..9fd0be4 100644
+index 0df678a..fa27688 100644
 --- sc/source/filter/excel/excimp8.cxx
 +++ sc/source/filter/excel/excimp8.cxx
-@@ -281,6 +281,7 @@ bool lcl_hasVBAEnabled()
+@@ -273,6 +273,7 @@ bool lcl_hasVBAEnabled()
  
  void ImportExcel8::ReadBasic( void )
  {
@@ -1084,7 +1072,7 @@
      bHasBasic = TRUE;
  
      SfxObjectShell* pShell = GetDocShell();
-@@ -308,6 +309,10 @@ void ImportExcel8::EndSheet( void )
+@@ -302,6 +303,10 @@ void ImportExcel8::EndSheet( void )
  
  void ImportExcel8::PostDocLoad( void )
  {
@@ -1096,10 +1084,10 @@
      if( pExcRoot->pAutoFilterBuffer )
          pExcRoot->pAutoFilterBuffer->Apply();
 diff --git sc/source/filter/excel/read.cxx sc/source/filter/excel/read.cxx
-index d65e496..403c0e2 100644
+index af1a2cc..2cc592c 100644
 --- sc/source/filter/excel/read.cxx
 +++ sc/source/filter/excel/read.cxx
-@@ -946,7 +946,8 @@ FltError ImportExcel8::Read( void )
+@@ -947,7 +947,8 @@ FltError ImportExcel8::Read( void )
  					case 0x22:	Rec1904(); break;		// 1904			[ 2345   ]
  					case 0x56:	Builtinfmtcnt(); break;	// BUILTINFMTCNT[  34    ]
  					case 0x8D:	Hideobj(); break;		// HIDEOBJ		[  345   ]
@@ -1109,10 +1097,11 @@
                      case 0xDE:  Olesize(); break;
  					case 0x01BA: Codename( TRUE ); break;
  
-diff -rup sc/source/filter/excel/xiescher.cxx sc/source/filter/excel/xiescher.cxx
---- sc/source/filter/excel/xiescher.cxx	2008-06-03 16:08:20.000000000 +0100
-+++ sc/source/filter/excel/xiescher.cxx	2008-06-03 16:36:05.000000000 +0100
-@@ -834,7 +834,7 @@ bool XclImpTbxControlObj::FillMacroDescr
+diff --git sc/source/filter/excel/xiescher.cxx sc/source/filter/excel/xiescher.cxx
+index ea6f221..e3e8b97 100644
+--- sc/source/filter/excel/xiescher.cxx
++++ sc/source/filter/excel/xiescher.cxx
+@@ -834,7 +834,7 @@ bool XclImpTbxControlObj::FillMacroDescriptor( ScriptEventDescriptor& rEvent ) c
          {
              // set the macro name
              rEvent.ScriptType = XclControlObjHelper::GetTbxScriptType();
@@ -1121,7 +1110,7 @@
              return true;
          }
      }
-@@ -1711,7 +1711,7 @@ SdrObject* XclImpDffManager::ProcessObj(
+@@ -1728,7 +1728,7 @@ SdrObject* XclImpDffManager::ProcessObj( SvStream& rEscherStrm,
              if( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( xSdrObj.get(), TRUE ) )
              {
                  if ( rMacro.Len() > 0 )
@@ -1130,9 +1119,10 @@
                  if ( aHlink.getLength() > 0 )
                  pInfo->SetHlink( aHlink );
              }
-diff -rup sc/source/filter/excel/xlescher.cxx sc/source/filter/excel/xlescher.cxx
---- sc/source/filter/excel/xlescher.cxx	2008-05-29 23:19:09.000000000 +0100
-+++ sc/source/filter/excel/xlescher.cxx	2008-06-03 15:38:21.000000000 +0100
+diff --git sc/source/filter/excel/xlescher.cxx sc/source/filter/excel/xlescher.cxx
+index 8e8e694..693a323 100644
+--- sc/source/filter/excel/xlescher.cxx
++++ sc/source/filter/excel/xlescher.cxx
 @@ -37,7 +37,10 @@
  #include "xistream.hxx"
  #include "xestream.hxx"
@@ -1145,7 +1135,7 @@
  using ::rtl::OUString;
  using ::com::sun::star::uno::Reference;
  using ::com::sun::star::uno::UNO_QUERY;
-@@ -405,9 +408,16 @@ OUString XclControlObjHelper::GetTbxScri
+@@ -405,9 +408,16 @@ OUString XclControlObjHelper::GetTbxScriptType()
  #define EXC_TBX_MACRONAME_PRE "vnd.sun.star.script:Standard."
  #define EXC_TBX_MACRONAME_SUF "?language=Basic&location=document"
  
@@ -1164,10 +1154,11 @@
  }
  
  String XclControlObjHelper::GetXclMacroName( const OUString& rScMacroName )
-diff -rup sc/source/filter/inc/xlescher.hxx sc/source/filter/inc/xlescher.hxx
---- sc/source/filter/inc/xlescher.hxx	2008-05-29 23:19:09.000000000 +0100
-+++ sc/source/filter/inc/xlescher.hxx	2008-06-03 15:28:12.000000000 +0100
-@@ -279,7 +279,7 @@ public:
+diff --git sc/source/filter/inc/xlescher.hxx sc/source/filter/inc/xlescher.hxx
+index e28b1c4..9263024 100644
+--- sc/source/filter/inc/xlescher.hxx
++++ sc/source/filter/inc/xlescher.hxx
+@@ -278,7 +278,7 @@ public:
      static ::rtl::OUString GetTbxScriptType();
  
      /** Returns the Calc macro name from an Excel macro name. */
@@ -1177,7 +1168,7 @@
      static String       GetXclMacroName( const ::rtl::OUString& rScMacroName );
  };
 diff --git sc/source/ui/docshell/docfunc.cxx sc/source/ui/docshell/docfunc.cxx
-index c0253ae..79e8eed 100644
+index 90c210e..105f743 100644
 --- sc/source/ui/docshell/docfunc.cxx
 +++ sc/source/ui/docshell/docfunc.cxx
 @@ -51,6 +51,12 @@
@@ -1193,15 +1184,15 @@
  #include <list>
  
  #include "docfunc.hxx"
-@@ -94,6 +100,7 @@
- #include "scui_def.hxx" //CHINA001
+@@ -99,6 +105,7 @@
  using namespace com::sun::star;
+ using ::com::sun::star::uno::Sequence;
  
 +
  // STATIC DATA -----------------------------------------------------------
  
  //========================================================================
-@@ -2016,6 +2023,85 @@ BOOL ScDocFunc::MoveBlock( const ScRange
+@@ -2021,6 +2028,85 @@ BOOL ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos,
  }
  
  //------------------------------------------------------------------------
@@ -1287,7 +1278,7 @@
  
  BOOL ScDocFunc::InsertTable( SCTAB nTab, const String& rName, BOOL bRecord, BOOL bApi )
  {
-@@ -2025,8 +2111,12 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
+@@ -2030,8 +2116,12 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab, const String& rName, BOOL bRecord, BOOL
  	ScDocShellModificator aModificator( rDocShell );
  
  	ScDocument* pDoc = rDocShell.GetDocument();
@@ -1300,7 +1291,7 @@
  	if (bRecord)
  		pDoc->BeginDrawUndo();							//	InsertTab erzeugt ein SdrUndoNewPage
  
-@@ -2041,6 +2131,11 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
+@@ -2046,6 +2136,11 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab, const String& rName, BOOL bRecord, BOOL
  			rDocShell.GetUndoManager()->AddUndoAction(
  						new ScUndoInsertTab( &rDocShell, nTab, bAppend, rName));
  		//	Views updaten:
@@ -1312,7 +1303,7 @@
  		rDocShell.Broadcast( ScTablesHint( SC_TAB_INSERTED, nTab ) );
  
  		rDocShell.PostPaintExtras();
-@@ -2062,8 +2157,12 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
+@@ -2067,8 +2162,12 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab, BOOL bRecord, BOOL /* bApi */ )
  
  	BOOL bSuccess = FALSE;
  	ScDocument* pDoc = rDocShell.GetDocument();
@@ -1325,7 +1316,7 @@
  	BOOL bWasLinked = pDoc->IsLinked(nTab);
  	ScDocument* pUndoDoc = NULL;
  	ScRefUndoData* pUndoData = NULL;
-@@ -2104,6 +2203,8 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
+@@ -2109,6 +2208,8 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab, BOOL bRecord, BOOL /* bApi */ )
  		pUndoData = new ScRefUndoData( pDoc );
  	}
  
@@ -1334,7 +1325,7 @@
  	if (pDoc->DeleteTab( nTab, pUndoDoc ))
  	{
  		if (bRecord)
-@@ -2114,6 +2215,13 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
+@@ -2119,6 +2220,13 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab, BOOL bRecord, BOOL /* bApi */ )
  						new ScUndoDeleteTab( &rDocShell, theTabs, pUndoDoc, pUndoData ));
  		}
  		//	Views updaten:
@@ -1464,7 +1455,7 @@
  
  //------------------------------------------------------------------------
  
-@@ -112,7 +208,8 @@ static const sal_Char* __FAR_DATA aProvN
+@@ -112,7 +208,8 @@ static const sal_Char* __FAR_DATA aProvNames[SC_SERVICE_COUNT] =
  
          SC_SERVICENAME_CHDATAPROV,                  // SC_SERVICE_CHDATAPROV
          SC_SERVICENAME_FORMULAPARS,                 // SC_SERVICE_FORMULAPARS
@@ -1474,7 +1465,7 @@
  	};
  
  //
-@@ -164,7 +261,8 @@ static const sal_Char* __FAR_DATA aOldNa
+@@ -164,7 +261,8 @@ static const sal_Char* __FAR_DATA aOldNames[SC_SERVICE_COUNT] =
          "",                                         // SC_SERVICE_SHEETDOCSET
          "",                                         // SC_SERVICE_CHDATAPROV
          "",                                         // SC_SERVICE_FORMULAPARS
@@ -1484,7 +1475,7 @@
  	};
  
  
-@@ -357,6 +455,9 @@ uno::Reference<uno::XInterface> ScServic
+@@ -357,6 +455,9 @@ uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
          case SC_SERVICE_OPCODEMAPPER:
              xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj));
              break;
@@ -1495,7 +1486,7 @@
  	return xRet;
  }
 diff --git sc/source/ui/view/viewfun2.cxx sc/source/ui/view/viewfun2.cxx
-index 674b835..dcbb8c6 100644
+index 1970245..7491061 100644
 --- sc/source/ui/view/viewfun2.cxx
 +++ sc/source/ui/view/viewfun2.cxx
 @@ -57,6 +57,11 @@
@@ -1510,7 +1501,7 @@
  #include "viewfunc.hxx"
  
  #include "sc.hrc"
-@@ -2092,15 +2097,42 @@ BOOL ScViewFunc::DeleteTable( SCTAB nTab
+@@ -2092,15 +2097,42 @@ BOOL ScViewFunc::DeleteTable( SCTAB nTab, BOOL bRecord )
  	return bSuccess;
  }
  
@@ -1553,7 +1544,7 @@
  
  	while ( nNewTab > 0 && !pDoc->IsVisible( nNewTab ) )
  		--nNewTab;
-@@ -2167,9 +2199,18 @@ BOOL ScViewFunc::DeleteTables(const SvSh
+@@ -2167,9 +2199,18 @@ BOOL ScViewFunc::DeleteTables(const SvShorts &TheTabs, BOOL bRecord )
  
  	for(i=TheTabs.Count()-1;i>=0;i--)
  	{
@@ -1572,7 +1563,7 @@
              pDocSh->Broadcast( ScTablesHint( SC_TAB_DELETED, TheTabs[sal::static_int_cast<USHORT>(i)] ) );
  		}
  	}
-@@ -2197,6 +2238,7 @@ BOOL ScViewFunc::DeleteTables(const SvSh
+@@ -2197,6 +2238,7 @@ BOOL ScViewFunc::DeleteTables(const SvShorts &TheTabs, BOOL bRecord )
  		pDocSh->PostPaintExtras();
  		pDocSh->SetDocumentModified();
  
@@ -1593,7 +1584,7 @@
  /*
  A few urls which may in the future be of some use
  http://www.virusbtn.com/vb2000/Programme/papers/bontchev.pdf
-@@ -432,7 +434,7 @@ int VBA_Impl::ReadVBAProject(const SvSto
+@@ -432,7 +434,7 @@ int VBA_Impl::ReadVBAProject(const SvStorageRef &rxVBAStorage)
   *
  */
  
@@ -1602,7 +1593,7 @@
  {
      ModuleTypeHash::iterator iter = mhModHash.find( rModuleName );
      ModuleTypeHash::iterator iterEnd = mhModHash.end();
-@@ -440,7 +442,7 @@ ModuleType VBA_Impl::GetModuleType( cons
+@@ -440,7 +442,7 @@ ModuleType VBA_Impl::GetModuleType( const UniString& rModuleName )
      {
          return iter->second;
      }
@@ -1611,7 +1602,7 @@
  }
  
  bool VBA_Impl::Open( const String &rToplevel, const String &rSublevel )
-@@ -483,7 +485,7 @@ bool VBA_Impl::Open( const String &rTopl
+@@ -483,7 +485,7 @@ bool VBA_Impl::Open( const String &rToplevel, const String &rSublevel )
          static const String sClass(     RTL_CONSTASCII_USTRINGPARAM( "Class" ) );
          static const String sBaseClass( RTL_CONSTASCII_USTRINGPARAM( "BaseClass" ) );
          static const String sDocument(  RTL_CONSTASCII_USTRINGPARAM( "Document" ) );
@@ -1620,7 +1611,7 @@
          while ( pStp->ReadByteStringLine( tmp, meCharSet ) )
          {
              xub_StrLen index = tmp.Search( '=' );
-@@ -493,14 +495,14 @@ bool VBA_Impl::Open( const String &rTopl
+@@ -493,14 +495,14 @@ bool VBA_Impl::Open( const String &rToplevel, const String &rSublevel )
                  String value = tmp.Copy( index + 1 );
                  if ( key == sClass )
                  {
@@ -1637,7 +1628,7 @@
                      OSL_TRACE("Module %s is of type Form",
                          ::rtl::OUStringToOString( value ,
                              RTL_TEXTENCODING_ASCII_US ).pData->buffer );
-@@ -513,14 +515,14 @@ bool VBA_Impl::Open( const String &rTopl
+@@ -513,14 +515,14 @@ bool VBA_Impl::Open( const String &rToplevel, const String &rSublevel )
                      // value is of form <name>/&H<identifier>, strip the identifier
                      value.Erase( value.Search( '/' ) );
  
@@ -1693,7 +1684,7 @@
      std::vector<String> maReferences;
  private:
 diff --git svx/source/msfilter/svxmsbas.cxx svx/source/msfilter/svxmsbas.cxx
-index 20840a8..27d8054 100644
+index d5878ad..441562a 100644
 --- svx/source/msfilter/svxmsbas.cxx
 +++ svx/source/msfilter/svxmsbas.cxx
 @@ -53,6 +53,7 @@ using namespace com::sun::star::awt;
@@ -1704,7 +1695,7 @@
  using namespace com::sun::star::container;
  using namespace com::sun::star::script;
  using namespace com::sun::star::uno;
-@@ -251,6 +252,20 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+@@ -268,6 +269,20 @@ BOOL SvxImportMSVBasic::ImportCode_Impl( const String& rStorageName,
          }
  		if( xLib.is() )
  		{
@@ -1725,7 +1716,7 @@
  			for( UINT16 i=0; i<nStreamCount;i++)
  			{
  				StringArray aDecompressed = aVBA.Decompress(i);
-@@ -284,7 +299,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+@@ -301,7 +316,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl( const String& rStorageName,
                  // is the same as the encoding for the names
                  // that are keys in the map used by GetModuleType method
                  const String &sOrigVBAModName = aVBA.GetStreamName( i );
@@ -1734,7 +1725,7 @@
  
                  rtl::OUString sClassRem( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=" ) );
  
-@@ -292,23 +307,23 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+@@ -309,23 +324,23 @@ BOOL SvxImportMSVBasic::ImportCode_Impl( const String& rStorageName,
  
                  switch( mType )
                  {
@@ -1763,7 +1754,7 @@
                          modeTypeComment = sClassRem +
                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAUnknown\n" ) );
                          break;
-@@ -318,10 +333,10 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+@@ -335,10 +350,10 @@ BOOL SvxImportMSVBasic::ImportCode_Impl( const String& rStorageName,
                  }
  				static ::rtl::OUString sVBAOption( RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n" ) ); 
  				static ::rtl::OUString sClassOption( RTL_CONSTASCII_USTRINGPARAM( "Option ClassModule\n" ) ); 
@@ -1776,7 +1767,7 @@
  						modeTypeComment = modeTypeComment + sClassOption;
  
  				}
-@@ -383,12 +398,24 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+@@ -405,12 +420,24 @@ BOOL SvxImportMSVBasic::ImportCode_Impl( const String& rStorageName,
  						aSource += rtl::OUString::createFromAscii("\nEnd Sub");
  				}
  				::rtl::OUString aModName( sModule );
@@ -1803,7 +1794,7 @@
  					if( xLib->hasByName( aModName ) )
  						xLib->replaceByName( aModName, aSourceAny );
  					else
-@@ -398,6 +425,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+@@ -420,6 +447,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl( const String& rStorageName,
  				bRet = true;
  			}
  		}
@@ -1951,32 +1942,3 @@
  
  # ------------------------------------------------------------------
  
---- basic/source/uno/scriptcont.cxx	2008-06-16 17:14:58.000000000 +0100
-+++ basic/source/uno//scriptcont.cxx	2008-06-16 17:25:42.000000000 +0100
-@@ -214,7 +214,12 @@ void SAL_CALL SfxScriptLibraryContainer:
- 	xmlscript::ModuleDescriptor aMod;
- 	aMod.aName = aElementName;
- 	aMod.aLanguage = maScriptLanguage;
--	aElement >>= aMod.aCode;
-+	// make sure we export source
-+	::com::sun::star::script::ModuleInfo mInfo;
-+	if ( aElement >>= mInfo )
-+		aMod.aCode = mInfo.ModuleSource;
-+	else
-+		aElement >>= aMod.aCode;
- 	xmlscript::exportScriptModule( xHandler, aMod );
- }
- 
-@@ -1171,7 +1176,11 @@ void SfxScriptLibrary::storeResourcesToS
- bool SfxScriptLibrary::containsValidModule( const Any& aElement )
- {
- 	OUString sModuleText;
--	aElement >>= sModuleText;
-+	::com::sun::star::script::ModuleInfo mInfo;
-+	if ( aElement >>= mInfo )
-+		sModuleText = mInfo.ModuleSource;
-+	else
-+		aElement >>= sModuleText;
- 	return ( sModuleText.getLength() > 0 );
- }
- 

Added: trunk/patches/vba/vba-userform-activate-fix-m22.diff
==============================================================================
--- (empty file)
+++ trunk/patches/vba/vba-userform-activate-fix-m22.diff	Tue Jul 22 11:34:41 2008
@@ -0,0 +1,52 @@
+--- basic/source/classes/sbxmod.cxx.bak	2008-07-03 15:35:16.000000000 +0800
++++ basic/source/classes/sbxmod.cxx	2008-07-03 15:48:45.000000000 +0800
+@@ -2296,10 +2296,12 @@ class FormObjEventListenerImpl : public 
+     SbUserFormModule* mpUserForm;
+     uno::Reference< lang::XComponent > mxComponent;
+     bool mbDisposed;
++    sal_Bool mbOpened;
++    sal_Bool mbActivated;
+     FormObjEventListenerImpl(); // not defined
+     FormObjEventListenerImpl(const FormObjEventListenerImpl&); // not defined
+ public:
+-    FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false )
++    FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false ), mbOpened( sal_False ), mbActivated( sal_False )
+     {
+         if ( mxComponent.is() );
+         {
+@@ -2328,7 +2330,18 @@ public:
+         }
+         catch( uno::Exception& ) {}
+     } 
+-    virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
++    virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
++    {
++        if ( mpUserForm  )
++        {
++            mbOpened = sal_True;
++            if ( mbActivated )
++            {
++                mbOpened = mbActivated = sal_False;
++                mpUserForm->triggerActivateEvent();
++            }
++        }
++    }
+     virtual void SAL_CALL windowClosing( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
+     virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
+     virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
+@@ -2336,7 +2349,14 @@ public:
+     virtual void SAL_CALL windowActivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
+     {
+         if ( mpUserForm  )
+-            mpUserForm->triggerActivateEvent();
++        {
++            mbActivated = sal_True;
++            if ( mbOpened )
++            {
++                mbOpened = mbActivated = sal_False;
++                mpUserForm->triggerActivateEvent();
++            }
++        }
+     }
+    
+     virtual void SAL_CALL windowDeactivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)

Modified: trunk/patches/vba/vba-userform-activate-fix.diff
==============================================================================
--- trunk/patches/vba/vba-userform-activate-fix.diff	(original)
+++ trunk/patches/vba/vba-userform-activate-fix.diff	Tue Jul 22 11:34:41 2008
@@ -1,52 +1,17 @@
---- basic/source/classes/sbxmod.cxx.bak	2008-07-03 15:35:16.000000000 +0800
-+++ basic/source/classes/sbxmod.cxx	2008-07-03 15:48:45.000000000 +0800
-@@ -2296,10 +2296,12 @@ class FormObjEventListenerImpl : public 
-     SbUserFormModule* mpUserForm;
-     uno::Reference< lang::XComponent > mxComponent;
-     bool mbDisposed;
-+    sal_Bool mbOpened;
-+    sal_Bool mbActivated;
-     FormObjEventListenerImpl(); // not defined
-     FormObjEventListenerImpl(const FormObjEventListenerImpl&); // not defined
- public:
--    FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false )
-+    FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false ), mbOpened( sal_False ), mbActivated( sal_False )
-     {
-         if ( mxComponent.is() );
-         {
-@@ -2328,7 +2330,18 @@ public:
+Index: vcl/win/source/window/salframe.cxx
+===================================================================
+RCS file: /cvs/gsl/vcl/win/source/window/salframe.cxx,v
+retrieving revision 1.157
+retrieving revision 1.157.12.1
+diff -u -p -u -p -b -w -B -r1.157 -r1.157.12.1
+--- vcl/win/source/window/salframe.cxx	2 Jul 2008 12:15:42 -0000	1.157
++++ vcl/win/source/window/salframe.cxx	17 Jul 2008 16:18:51 -0000	1.157.12.1
+@@ -2181,7 +2181,7 @@ static void ImplSalToTop( HWND hWnd, USH
          }
-         catch( uno::Exception& ) {}
-     } 
--    virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
-+    virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
-+    {
-+        if ( mpUserForm  )
-+        {
-+            mbOpened = sal_True;
-+            if ( mbActivated )
-+            {
-+                mbOpened = mbActivated = sal_False;
-+                mpUserForm->triggerActivateEvent();
-+            }
-+        }
-+    }
-     virtual void SAL_CALL windowClosing( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
-     virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
-     virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
-@@ -2336,7 +2349,14 @@ public:
-     virtual void SAL_CALL windowActivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
-     {
-         if ( mpUserForm  )
--            mpUserForm->triggerActivateEvent();
-+        {
-+            mbActivated = sal_True;
-+            if ( mbOpened )
-+            {
-+                mbOpened = mbActivated = sal_False;
-+                mpUserForm->triggerActivateEvent();
-+            }
-+        }
      }
-    
-     virtual void SAL_CALL windowDeactivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
+ 
+-    if ( !IsIconic( hWnd ) )
++    if ( !IsIconic( hWnd ) && IsWindowVisible( hWnd ) )
+     {
+         SetFocus( hWnd );
+ 

Added: trunk/patches/vba/vba-userform-m22.diff
==============================================================================
--- (empty file)
+++ trunk/patches/vba/vba-userform-m22.diff	Tue Jul 22 11:34:41 2008
@@ -0,0 +1,407 @@
+diff --git basic/inc/basic/sbmod.hxx basic/inc/basic/sbmod.hxx
+index e676a49..ab496bc 100644
+--- basic/inc/basic/sbmod.hxx
++++ basic/inc/basic/sbmod.hxx
+@@ -59,6 +59,8 @@ class SbModule : public SbxObject
+ 	friend class	SbClassModuleObject;
+ 
+ 	SbModuleImpl*	mpSbModuleImpl;		// Impl data
++	SbModule();
++	SbModule(const SbModule&);
+ 
+ protected:
+     ::rtl::OUString	aOUSource;
+diff --git basic/inc/basic/sbobjmod.hxx basic/inc/basic/sbobjmod.hxx
+index 7a8f096..bdc23d9 100644
+--- basic/inc/basic/sbobjmod.hxx
++++ basic/inc/basic/sbobjmod.hxx
+@@ -41,6 +41,7 @@
+ #include <com/sun/star/script/ModuleInfo.hpp>
+ #include <com/sun/star/lang/XEventListener.hpp>
+ #include <com/sun/star/awt/XDialog.hpp>
++#include <com/sun/star/frame/XModel.hpp>
+ 
+ namespace css = ::com::sun::star;
+ 
+@@ -48,6 +49,8 @@ namespace css = ::com::sun::star;
+ 
+ class SbObjModule : public SbModule
+ {
++    SbObjModule( const SbObjModule& );
++    SbObjModule();
+ public:
+     TYPEINFO();
+     SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible );
+@@ -55,6 +58,31 @@ public:
+     SbxVariable* GetObject();
+ };
+ 
++class SbUserFormModule : public SbObjModule
++{
++    css::uno::Reference<css::lang::XEventListener> m_DialogListener;
++    css::uno::Reference<css::awt::XDialog> m_xDialog;
++    css::uno::Reference<css::frame::XModel> m_xModel;
++    String sFormName;
++    SbUserFormModule( const SbUserFormModule& );
++    SbUserFormModule();
++
++protected:
++    virtual void InitObject();
++public:
++    TYPEINFO();
++    SbUserFormModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVBACompat );
++    virtual SbxVariable* Find( const XubString& rName, SbxClassType t );
++    void ResetApiObj();
++    void Unload();
++    void load();
++    void triggerMethod( const String& );
++    void triggerActivateEvent();
++    void triggerDeActivateEvent();
++    void triggerInitializeEvent();
++    void triggerTerminateEvent();
++};
++
+ #ifndef __SB_SBOBJMODULEREF_HXX
+ #define __SB_SBOBJMODULEREF_HXX
+ 
+diff --git basic/source/classes/sb.cxx basic/source/classes/sb.cxx
+index 5226d3f..e47234f 100644
+--- basic/source/classes/sb.cxx
++++ basic/source/classes/sb.cxx
+@@ -715,6 +715,9 @@ SbModule* StarBASIC::MakeModule32( const
+             p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
+ 			p->SetModuleType( com::sun::star::script::ModuleType::Class );	
+ 	    break;
++        case ModuleType::Form:
++            p = new SbUserFormModule( mInfo, isVBAEnabled() );
++	    break;
+         default:
+             p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
+             
+@@ -900,9 +903,8 @@ SbxVariable* StarBASIC::Find( const Stri
+ 			// Only variables qualified by the Module Name e.g. Sheet1.foo
+ 			// should work for Documant && Class type Modules
+ 			INT32 nType = p->GetModuleType();
+-            //if ( nType == com::sun::star::script::ModuleType::Class || nType == com::sun::star::script::ModuleType::Document )
+-            if ( nType == com::sun::star::script::ModuleType::Document )
+-                continue;
++			if ( nType == com::sun::star::script::ModuleType::Document || nType == com::sun::star::script::ModuleType::Form )
++				continue;
+ 			// Sonst testen, ob das Element vorhanden ist
+ 			// GBLSEARCH-Flag rausnehmen (wg. Rekursion)
+ 			USHORT nGblFlag = p->GetFlags() & SBX_GBLSEARCH;
+diff --git basic/source/classes/sbxmod.cxx basic/source/classes/sbxmod.cxx
+index 388f437..3f9e76c 100644
+--- basic/source/classes/sbxmod.cxx
++++ basic/source/classes/sbxmod.cxx
+@@ -73,7 +73,6 @@
+ #include <com/sun/star/awt/XDialogProvider.hpp>
+ #include <com/sun/star/awt/XTopWindow.hpp>
+ #include <com/sun/star/awt/XControl.hpp>
+-#include <com/sun/star/frame/XModel.hpp>
+ #include <cppuhelper/implbase1.hxx>
+ #include <comphelper/anytostring.hxx>
+ 
+@@ -86,6 +85,7 @@ TYPEINIT1(SbProcedureProperty,SbxPropert
+ TYPEINIT1(SbJScriptModule,SbModule)
+ TYPEINIT1(SbJScriptMethod,SbMethod)
+ TYPEINIT1(SbObjModule,SbModule)
++TYPEINIT1(SbUserFormModule,SbObjModule)
+ 
+ SV_DECL_VARARR(SbiBreakpoints,USHORT,4,4)
+ SV_IMPL_VARARR(SbiBreakpoints,USHORT)
+@@ -2247,6 +2247,11 @@ SbObjModule::SbObjModule( const com::sun
+     : SbModule( mInfo.ModuleName, bIsVbaCompatible )
+ {
+     SetModuleType( mInfo.ModuleType );
++    if ( mInfo.ModuleType == script::ModuleType::Form )
++    {
++        SetClassName( rtl::OUString::createFromAscii( "Form" ) );
++        return;
++    }
+     try
+     {
+         com::sun::star::uno::Any aObject( mInfo.ModuleObject );
+@@ -2283,3 +2288,201 @@ SbObjModule::Find( const XubString& rNam
+         pVar = SbModule::Find( rName, t );
+     return pVar;
+ }
++
++typedef ::cppu::WeakImplHelper1< awt::XTopWindowListener > EventListener_BASE;
++
++class FormObjEventListenerImpl : public EventListener_BASE
++{
++    SbUserFormModule* mpUserForm;
++    uno::Reference< lang::XComponent > mxComponent;
++    bool mbDisposed;
++    FormObjEventListenerImpl(); // not defined
++    FormObjEventListenerImpl(const FormObjEventListenerImpl&); // not defined
++public:
++    FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false )
++    {
++        if ( mxComponent.is() );
++        {
++	    uno::Reference< awt::XTopWindow > xList( mxComponent, uno::UNO_QUERY_THROW );;
++            //uno::Reference< awt::XWindow > xList( mxComponent, uno::UNO_QUERY_THROW );;
++            OSL_TRACE("*********** Registering the listener");
++            xList->addTopWindowListener( this );
++        }
++    }
++
++    ~FormObjEventListenerImpl()
++    {
++        removeListener();
++    }
++    void removeListener()
++    {
++        try
++        {
++            if ( mxComponent.is() && !mbDisposed )
++            {
++                uno::Reference< awt::XTopWindow > xList( mxComponent, uno::UNO_QUERY_THROW );;
++                OSL_TRACE("*********** Removing the listener");
++            	xList->removeTopWindowListener( this );
++                mxComponent = NULL;
++            }
++        }
++        catch( uno::Exception& ) {}
++    } 
++    virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
++    virtual void SAL_CALL windowClosing( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
++    virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
++    virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
++    virtual void SAL_CALL windowNormalized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException){}
++    virtual void SAL_CALL windowActivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
++    {
++        if ( mpUserForm  )
++            mpUserForm->triggerActivateEvent();
++    }
++   
++    virtual void SAL_CALL windowDeactivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
++    {
++        if ( mpUserForm  )
++            mpUserForm->triggerDeActivateEvent();
++    }
++
++
++    virtual void SAL_CALL disposing( const lang::EventObject& Source ) throw (uno::RuntimeException)
++    {
++        OSL_TRACE("** Userform/Dialog disposing");
++        mbDisposed = true;
++        uno::Any aSource;
++        aSource <<= Source;   
++        mxComponent = NULL;
++        if ( mpUserForm )
++            mpUserForm->ResetApiObj();
++    }
++};
++
++SbUserFormModule::SbUserFormModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsCompat )
++    :SbObjModule( mInfo, bIsCompat )
++{
++        m_xModel.set( mInfo.ModuleObject, uno::UNO_QUERY_THROW );
++}
++
++void SbUserFormModule::ResetApiObj()
++{
++        if (  m_xDialog.is() ) // probably someone close the dialog window
++	{
++            triggerTerminateEvent();
++        }
++        pDocObject = NULL;
++	m_xDialog = NULL;
++}
++
++void SbUserFormModule::triggerMethod( const String& aMethodToRun )
++{
++	OSL_TRACE("*** trigger %s ***", rtl::OUStringToOString( aMethodToRun, RTL_TEXTENCODING_UTF8 ).getStr() );
++	// Search method
++	SbxVariable* pMeth = SbObjModule::Find( aMethodToRun, SbxCLASS_METHOD );
++	if( pMeth )
++	{
++		SbxValues aVals;
++		pMeth->Get( aVals );
++	}
++}
++
++void SbUserFormModule::triggerActivateEvent( void )
++{
++        OSL_TRACE("**** entering SbUserFormModule::triggerActivate");
++	triggerMethod( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UserForm_activate") ) );
++        OSL_TRACE("**** leaving SbUserFormModule::triggerActivate");
++}
++
++void SbUserFormModule::triggerDeActivateEvent( void )
++{
++        OSL_TRACE("**** SbUserFormModule::triggerDeActivate");
++	triggerMethod( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Userform_DeActivate") ) );
++}
++
++void SbUserFormModule::triggerInitializeEvent( void )
++
++{
++        OSL_TRACE("**** SbUserFormModule::triggerInitializeEvent");
++	static String aInitMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Initialize") );
++	triggerMethod( aInitMethodName );
++
++}
++
++void SbUserFormModule::triggerTerminateEvent( void )
++{
++        OSL_TRACE("**** SbUserFormModule::triggerTerminateEvent");
++	static String aTermMethodName( RTL_CONSTASCII_USTRINGPARAM("Userform_Terminate") );
++	triggerMethod( aTermMethodName );
++}
++
++void SbUserFormModule::load()
++{
++    OSL_TRACE("** load() ");
++    // forces a load
++    if ( !pDocObject )
++        InitObject();
++}
++void SbUserFormModule::Unload()
++{
++    OSL_TRACE("** Unload() ");
++    if ( m_xDialog.is() )
++    {
++	triggerTerminateEvent();
++    }
++	// Search method
++	SbxVariable* pMeth = SbObjModule::Find( String( RTL_CONSTASCII_USTRINGPARAM( "UnloadObject" ) ), SbxCLASS_METHOD );
++	if( pMeth )
++	{
++		OSL_TRACE("Attempting too run the UnloadObjectMethod");
++                m_xDialog = NULL; //release ref to the uno object
++		SbxValues aVals;
++		pMeth->Get( aVals );
++	}
++}
++
++void SbUserFormModule::InitObject()
++{
++    try
++    {
++
++        if ( m_xModel.is() )
++        {
++            uno::Reference< lang::XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
++            uno::Sequence< uno::Any > aArgs(1);
++            aArgs[ 0 ] <<= m_xModel;
++            rtl::OUString sDialogUrl( RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.script:" ) );
++            sDialogUrl = sDialogUrl.concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ) ).concat( rtl::OUString( '.') ).concat( GetName() ).concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("?location=document") ) ); 
++
++            uno::Reference< awt::XDialogProvider > xProvider( xFactory->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.DialogProvider")), aArgs  ), uno::UNO_QUERY_THROW );
++            m_xDialog = xProvider->createDialog( sDialogUrl );
++
++            // create vba api object
++            aArgs.realloc( 3 );
++            aArgs[ 0 ] = uno::Any();
++            aArgs[ 1 ] <<= m_xDialog;
++            aArgs[ 2 ] <<= m_xModel;
++            pDocObject = new SbUnoObject( GetName(), uno::makeAny( xFactory->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.excel.UserForm")), aArgs  ) ) );
++            uno::Reference< lang::XComponent > xComponent( aArgs[ 1 ], uno::UNO_QUERY_THROW );
++            // remove old listener if it exists
++            FormObjEventListenerImpl* pFormListener = dynamic_cast< FormObjEventListenerImpl* >( m_DialogListener.get() );
++            if ( pFormListener )
++                pFormListener->removeListener();
++            m_DialogListener = new FormObjEventListenerImpl( this, xComponent );
++
++            // trigger initialise event
++            triggerInitializeEvent();
++        } 
++    }
++    catch( uno::Exception& e )
++    {
++    }
++
++}
++
++SbxVariable*
++SbUserFormModule::Find( const XubString& rName, SbxClassType t )
++{
++    if ( !pDocObject )
++        InitObject();
++    return SbObjModule::Find( rName, t );
++}
+diff --git basic/source/runtime/methods.cxx basic/source/runtime/methods.cxx
+index 2bbd6f1..a35a17a 100644
+--- basic/source/runtime/methods.cxx
++++ basic/source/runtime/methods.cxx
+@@ -124,6 +124,8 @@ using namespace com::sun::star::io;
+ #include <io.h>
+ #endif
+ 
++#include <basic/sbobjmod.hxx>
++
+ static void FilterWhiteSpace( String& rStr )
+ {
+ 	rStr.EraseAllChars( ' ' );
+@@ -4126,7 +4128,12 @@ RTLFUNC(Load)
+ 
+ 	// Diesen Call einfach an das Object weiterreichen
+ 	SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject();
+-	if( pObj && pObj->IsA( TYPE( SbxObject ) ) )
++	if( pObj && pObj->IsA( TYPE( SbUserFormModule ) ) )
++	{
++		SbUserFormModule* pFormModule = ( SbUserFormModule* )pObj;
++		pFormModule->load();
++	}
++	else if( pObj && pObj->IsA( TYPE( SbxObject ) ) )
+ 	{
+ 		SbxVariable* pVar = ((SbxObject*)pObj)->
+ 			Find( String( RTL_CONSTASCII_USTRINGPARAM("Load") ), SbxCLASS_METHOD );
+@@ -4149,7 +4156,12 @@ RTLFUNC(Unload)
+ 
+ 	// Diesen Call einfach an das Object weitereichen
+ 	SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject();
+-	if( pObj && pObj->IsA( TYPE( SbxObject ) ) )
++	if( pObj && pObj->IsA( TYPE( SbUserFormModule ) ) )
++	{
++		SbUserFormModule* pFormModule = ( SbUserFormModule* )pObj;
++		pFormModule->Unload();
++	}
++	else if( pObj && pObj->IsA( TYPE( SbxObject ) ) )
+ 	{
+ 		SbxVariable* pVar = ((SbxObject*)pObj)->
+ 			Find( String( RTL_CONSTASCII_USTRINGPARAM("Unload") ), SbxCLASS_METHOD );
+diff --git smoketestoo_native/smoketest.pl smoketestoo_native/smoketest.pl
+index 5fc4db2..376f871 100755
+--- smoketestoo_native/smoketest.pl
++++ smoketestoo_native/smoketest.pl
+@@ -486,6 +486,7 @@ sub doTest {
+ 
+ 	createPath ($LOGPATH, $error_copyExtension);  
+ 	$Command = "$COPY_FILE \"$ExtensionDir" . "TestExtension.oxt\" " . "\"$LOGPATH$PathSeparator\"";
++        print "***** $Command\n";
+ 	execute_Command ($Command, $error_copyExtension, $show_Message, $command_withoutOutput);
+ 
+ 
+diff --git svx/source/msfilter/svxmsbas.cxx svx/source/msfilter/svxmsbas.cxx
+index 27d8054..0d09b04 100644
+--- svx/source/msfilter/svxmsbas.cxx
++++ svx/source/msfilter/svxmsbas.cxx
+@@ -403,15 +403,20 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+ 
+ 					Any aSourceAny;
+                     OSL_TRACE("erm %d", mType );
+-                    if (  xVBAObjectForCodeName.is() && ( mType == ModuleType::Document || mType == ModuleType::Class ) )
++                    if (  xVBAObjectForCodeName.is() && ( mType == ModuleType::Document || mType == ModuleType::Class || mType == ModuleType::Form ) )
+                     {
+                         OSL_TRACE("vba processing  %d", mType );
+                         script::ModuleInfo sModuleInfo;
+                         sModuleInfo.ModuleName = aModName;
+                         sModuleInfo.ModuleSource = aSource;
+                         sModuleInfo.ModuleType = mType;
+-						if ( mType != ModuleType::Class )
+-                        	sModuleInfo.ModuleObject.set( xVBAObjectForCodeName->getByName( aModName ), UNO_QUERY );
++                        if ( mType == ModuleType::Form )
++                            // hack, the module ( in document basic should...
++                            // know the XModel... ) needs fixing in basic 
++                            // somewhere
++                            sModuleInfo.ModuleObject.set( rDocSh.GetModel(), UNO_QUERY );
++                        else if ( mType != ModuleType::Class )
++                            sModuleInfo.ModuleObject.set( xVBAObjectForCodeName->getByName( aModName ), UNO_QUERY );
+                         aSourceAny <<= sModuleInfo;
+                     }
+                     else

Modified: trunk/patches/vba/vba-userform.diff
==============================================================================
--- trunk/patches/vba/vba-userform.diff	(original)
+++ trunk/patches/vba/vba-userform.diff	Tue Jul 22 11:34:41 2008
@@ -68,7 +68,7 @@
 index 5226d3f..e47234f 100644
 --- basic/source/classes/sb.cxx
 +++ basic/source/classes/sb.cxx
-@@ -715,6 +715,9 @@ SbModule* StarBASIC::MakeModule32( const
+@@ -715,6 +715,9 @@ SbModule* StarBASIC::MakeModule32( const ModuleInfo& mInfo )
              p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
  			p->SetModuleType( com::sun::star::script::ModuleType::Class );	
  	    break;
@@ -78,7 +78,7 @@
          default:
              p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
              
-@@ -900,9 +903,8 @@ SbxVariable* StarBASIC::Find( const Stri
+@@ -900,9 +903,8 @@ SbxVariable* StarBASIC::Find( const String& rName, SbxClassType t )
  			// Only variables qualified by the Module Name e.g. Sheet1.foo
  			// should work for Documant && Class type Modules
  			INT32 nType = p->GetModuleType();
@@ -91,7 +91,7 @@
  			// GBLSEARCH-Flag rausnehmen (wg. Rekursion)
  			USHORT nGblFlag = p->GetFlags() & SBX_GBLSEARCH;
 diff --git basic/source/classes/sbxmod.cxx basic/source/classes/sbxmod.cxx
-index 388f437..3f9e76c 100644
+index 5ad04db..24921f8 100644
 --- basic/source/classes/sbxmod.cxx
 +++ basic/source/classes/sbxmod.cxx
 @@ -73,7 +73,6 @@
@@ -102,7 +102,7 @@
  #include <cppuhelper/implbase1.hxx>
  #include <comphelper/anytostring.hxx>
  
-@@ -86,6 +85,7 @@ TYPEINIT1(SbProcedureProperty,SbxPropert
+@@ -86,6 +85,7 @@ TYPEINIT1(SbProcedureProperty,SbxProperty)
  TYPEINIT1(SbJScriptModule,SbModule)
  TYPEINIT1(SbJScriptMethod,SbMethod)
  TYPEINIT1(SbObjModule,SbModule)
@@ -110,7 +110,7 @@
  
  SV_DECL_VARARR(SbiBreakpoints,USHORT,4,4)
  SV_IMPL_VARARR(SbiBreakpoints,USHORT)
-@@ -2247,6 +2247,11 @@ SbObjModule::SbObjModule( const com::sun
+@@ -2230,6 +2230,11 @@ SbObjModule::SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool
      : SbModule( mInfo.ModuleName, bIsVbaCompatible )
  {
      SetModuleType( mInfo.ModuleType );
@@ -122,7 +122,7 @@
      try
      {
          com::sun::star::uno::Any aObject( mInfo.ModuleObject );
-@@ -2283,3 +2288,201 @@ SbObjModule::Find( const XubString& rNam
+@@ -2266,6 +2271,224 @@ SbObjModule::Find( const XubString& rName, SbxClassType t )
          pVar = SbModule::Find( rName, t );
      return pVar;
  }
@@ -134,10 +134,12 @@
 +    SbUserFormModule* mpUserForm;
 +    uno::Reference< lang::XComponent > mxComponent;
 +    bool mbDisposed;
++    sal_Bool mbOpened;
++    sal_Bool mbActivated;
 +    FormObjEventListenerImpl(); // not defined
 +    FormObjEventListenerImpl(const FormObjEventListenerImpl&); // not defined
 +public:
-+    FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false )
++    FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false ), mbOpened( sal_False ), mbActivated( sal_False )
 +    {
 +        if ( mxComponent.is() );
 +        {
@@ -166,7 +168,18 @@
 +        }
 +        catch( uno::Exception& ) {}
 +    } 
-+    virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
++    virtual void SAL_CALL windowOpened( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
++    {
++        if ( mpUserForm  )
++        {
++            mbOpened = sal_True;
++            if ( mbActivated )
++            {
++                mbOpened = mbActivated = sal_False;
++                mpUserForm->triggerActivateEvent();
++            }
++        }
++    }
 +    virtual void SAL_CALL windowClosing( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
 +    virtual void SAL_CALL windowClosed( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
 +    virtual void SAL_CALL windowMinimized( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException) {}
@@ -174,7 +187,14 @@
 +    virtual void SAL_CALL windowActivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
 +    {
 +        if ( mpUserForm  )
-+            mpUserForm->triggerActivateEvent();
++        {
++            mbActivated = sal_True;
++            if ( mbOpened )
++            {
++                mbOpened = mbActivated = sal_False;
++                mpUserForm->triggerActivateEvent();
++            }
++        }
 +    }
 +   
 +    virtual void SAL_CALL windowDeactivated( const lang::EventObject& /*e*/ ) throw (uno::RuntimeException)
@@ -324,20 +344,23 @@
 +        InitObject();
 +    return SbObjModule::Find( rName, t );
 +}
+ /////////////////////////////////////////////////////////////////////////
+ 
+ SbProperty::SbProperty( const String& r, SbxDataType t, SbModule* p )
 diff --git basic/source/runtime/methods.cxx basic/source/runtime/methods.cxx
-index 2bbd6f1..a35a17a 100644
+index 7e7d42a..32cf5ad 100644
 --- basic/source/runtime/methods.cxx
 +++ basic/source/runtime/methods.cxx
-@@ -124,6 +124,8 @@ using namespace com::sun::star::io;
- #include <io.h>
- #endif
+@@ -126,6 +126,8 @@ using namespace com::sun::star::io;
+ 
+ using namespace rtl;
  
 +#include <basic/sbobjmod.hxx>
 +
  static void FilterWhiteSpace( String& rStr )
  {
  	rStr.EraseAllChars( ' ' );
-@@ -4126,7 +4128,12 @@ RTLFUNC(Load)
+@@ -4128,7 +4130,12 @@ RTLFUNC(Load)
  
  	// Diesen Call einfach an das Object weiterreichen
  	SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject();
@@ -351,7 +374,7 @@
  	{
  		SbxVariable* pVar = ((SbxObject*)pObj)->
  			Find( String( RTL_CONSTASCII_USTRINGPARAM("Load") ), SbxCLASS_METHOD );
-@@ -4149,7 +4156,12 @@ RTLFUNC(Unload)
+@@ -4151,7 +4158,12 @@ RTLFUNC(Unload)
  
  	// Diesen Call einfach an das Object weitereichen
  	SbxBase* pObj = (SbxObject*)rPar.Get(1)->GetObject();
@@ -366,10 +389,10 @@
  		SbxVariable* pVar = ((SbxObject*)pObj)->
  			Find( String( RTL_CONSTASCII_USTRINGPARAM("Unload") ), SbxCLASS_METHOD );
 diff --git smoketestoo_native/smoketest.pl smoketestoo_native/smoketest.pl
-index 5fc4db2..376f871 100755
+index b6381e2..757b212 100755
 --- smoketestoo_native/smoketest.pl
 +++ smoketestoo_native/smoketest.pl
-@@ -486,6 +486,7 @@ sub doTest {
+@@ -485,6 +485,7 @@ sub doTest {
  
  	createPath ($LOGPATH, $error_copyExtension);  
  	$Command = "$COPY_FILE \"$ExtensionDir" . "TestExtension.oxt\" " . "\"$LOGPATH$PathSeparator\"";
@@ -378,10 +401,10 @@
  
  
 diff --git svx/source/msfilter/svxmsbas.cxx svx/source/msfilter/svxmsbas.cxx
-index 27d8054..0d09b04 100644
+index 441562a..7acf7db 100644
 --- svx/source/msfilter/svxmsbas.cxx
 +++ svx/source/msfilter/svxmsbas.cxx
-@@ -403,15 +403,20 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+@@ -425,15 +425,20 @@ BOOL SvxImportMSVBasic::ImportCode_Impl( const String& rStorageName,
  
  					Any aSourceAny;
                      OSL_TRACE("erm %d", mType );



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]