Index: basic/source/classes/sb.cxx
===================================================================
RCS file: /cvs/script/basic/source/classes/sb.cxx,v
retrieving revision 1.23
diff -u -r1.23 sb.cxx
--- basic/source/classes/sb.cxx	13 Apr 2005 09:10:07 -0000	1.23
+++ basic/source/classes/sb.cxx	12 Aug 2005 09:50:30 -0000
@@ -97,6 +97,11 @@
 #include "stdobj.hxx"
 #include "filefmt.hxx"
 #include "sb.hrc"
+#ifdef ENABLE_VBA
+#include "sbx.hxx"
+#include "sbxvar.hxx"
+#include "sbxcore.hxx"
+#endif // ENABLE_VBA
 #include <basrid.hxx>
 
 #ifndef _VOS_MUTEX_HXX_
@@ -111,6 +117,48 @@
 
 #define RTLNAME "@SBRTL"
 
+#ifdef ENABLE_VBA
+SbxArray* getVBAGlobals(StarBASIC* pSBasic, const String &rForName )
+{
+	if ( !SbiRuntime::isVBAEnabled() || !pSBasic->IsSet( SBX_GBLSEARCH )  )
+	{
+		return NULL;
+	}
+	if( rForName == String( RTL_CONSTASCII_USTRINGPARAM( "ThisComponent" ) ) )
+		return NULL;
+
+	//OSL_TRACE("getVBAGlobals() for %s",
+	//	 (const sal_Char *) rtl::OUStringToOString( rForName, RTL_TEXTENCODING_UTF8 ) );
+
+	static String aThisComponent( RTL_CONSTASCII_USTRINGPARAM("ThisComponent") );
+	static String aVBAHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) );
+
+       SbxVariableRef pThisComp = pSBasic->Find( aThisComponent, SbxCLASS_OBJECT );
+       static SbxArrayRef pArray;
+       static bool isInitialised = false;
+       if ( isInitialised )
+               return pArray;
+
+	if (pThisComp && pThisComp->IsObject())
+	{
+//		fprintf( stderr, "Has valid 'This' ?!\n" );
+		SbxObject *pObj = static_cast<SbxObject *>(pThisComp->GetObject());
+		SbxVariable *vba;
+		if ((vba = pObj->Find( aVBAHook, SbxCLASS_DONTCARE/* SbxCLASS_PROPERTY */ ) ) &&
+			(vba->GetType() & SbxARRAY))
+		{
+			pArray = static_cast<SbxArray *>(vba->GetObject());
+//			fprintf( stderr, "Base Type %d Class %d IsObject %d IsDataObject %d Ptr %p Count: %d\n",
+//					 vba->SbxValue::GetType(), vba->GetType(),
+//					 vba->IsObject(), vba->IsDataObject(),
+//					 pArray, (int)pArray->Count() );
+                       isInitialised = true;
+			return pArray;
+		}
+	}
+	return NULL;
+}
+#endif // ENABLE_VBA
 
 //========================================================================
 // Array zur Umrechnung SFX <-> VB-Fehlercodes anlegen
@@ -923,9 +966,31 @@
 // benen Namen gefunden wurde, der Entrypoint "Main" gesucht. Wenn das
 // auch nicht klappt, laeuft die traditionelle Suche ueber Objekte an.
 
+
 SbxVariable* StarBASIC::Find( const String& rName, SbxClassType t )
 {
 	static String aMainStr( RTL_CONSTASCII_USTRINGPARAM("Main") );
+#ifdef ENABLE_VBA
+
+	//OSL_TRACE("StarBASIC::Find '%s' (%d)",
+	//		 (const sal_Char *) rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ), t );
+
+	SbxArray *pVBAGlobals = getVBAGlobals( this, rName );
+	for (USHORT i = 0; pVBAGlobals && i < pVBAGlobals->Count(); i++)
+	{
+		SbxVariable *pElem = pVBAGlobals->Get( i );
+		if (!pElem || !pElem->IsObject())
+			continue;
+		SbxObject *pVba = static_cast<SbxObject *>(pElem->GetObject());
+		SbxVariable *pVbaVar;
+		if( pVba && (pVbaVar = pVba->Find( rName, t ) ) )
+		{
+//			fprintf( stderr, "  Got VBA: call it !\n" );
+			return pVbaVar;
+		}
+	}
+//	fprintf( stderr, "  fall through\n" );
+#endif
 
 	SbxVariable* pRes = NULL;
 	SbModule* pNamed = NULL;
@@ -975,11 +1040,31 @@
 			pRes = pNamed->Find( aMainStr, SbxCLASS_METHOD );
 	if( !pRes )
 		pRes = SbxObject::Find( rName, t );
+
 	return pRes;
 }
 
 BOOL StarBASIC::Call( const String& rName, SbxArray* pParam )
 {
+#ifdef ENABLE_VBA
+//	fprintf( stderr, "StarBASIC::Call '%s'\n",
+//				 (const sal_Char *) rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ) );
+
+	SbxArray *pVBAGlobals = getVBAGlobals( this, rName );
+	for (USHORT i = 0; pVBAGlobals && i < pVBAGlobals->Count(); i++)
+	{
+		SbxVariable *pElem = pVBAGlobals->Get( i );
+		if (!pElem || !pElem->IsObject()) continue;
+		SbxObject *pVba = static_cast<SbxObject *>(pElem->GetObject());
+		SbxVariable *pVbaVar;
+		if( pVba && (pVbaVar = pVba->Find( rName, SbxCLASS_DONTCARE ) ) )
+		{
+//			fprintf( stderr, "  Got VBA: call it !\n" );
+			return pVba->Call( rName, pParam );
+		}
+	}
+//	fprintf( stderr, "  fall through\n" );
+#endif //ENABLE_VBA
 	BOOL bRes = SbxObject::Call( rName, pParam );
 	if( !bRes )
 	{
@@ -1501,7 +1586,6 @@
 	return FALSE;
 }
 
-
 //========================================================================
 // #118116 Implementation Collection object
 
Index: basic/source/classes/makefile.mk
===================================================================
RCS file: /cvs/script/basic/source/classes/makefile.mk,v
retrieving revision 1.11
diff -u -r1.11 makefile.mk
--- basic/source/classes/makefile.mk	25 Aug 2003 14:51:18 -0000	1.11
+++ basic/source/classes/makefile.mk	12 Aug 2005 09:51:08 -0000
@@ -46,6 +46,10 @@
 .INCLUDE :  settings.mk
 .INCLUDE : $(PRJ)$/util$/makefile.pmk
 
+.IF "$(ENABLE_VBA)"=="YES"
+	CDEFS+=-DENABLE_VBA
+.ENDIF
+
 # --- Allgemein -----------------------------------------------------------
 
 COMMON_SLOFILES=	\
