ooo-build r12873 - trunk/patches/test/vba
- From: noelpwer svn gnome org
- To: svn-commits-list gnome org
- Subject: ooo-build r12873 - trunk/patches/test/vba
- Date: Thu, 12 Jun 2008 16:28:25 +0000 (UTC)
Author: noelpwer
Date: Thu Jun 12 16:28:25 2008
New Revision: 12873
URL: http://svn.gnome.org/viewvc/ooo-build?rev=12873&view=rev
Log:
backup my very rough git patches for codename/vbamode/moduletype hackery
Modified:
trunk/patches/test/vba/ObjectModule.diff
Modified: trunk/patches/test/vba/ObjectModule.diff
==============================================================================
--- trunk/patches/test/vba/ObjectModule.diff (original)
+++ trunk/patches/test/vba/ObjectModule.diff Thu Jun 12 16:28:25 2008
@@ -1,791 +1,1223 @@
---- svx/source/msfilter/svxmsbas.cxx.bak 2007-09-03 13:31:10.000000000 +0800
-+++ svx/source/msfilter/svxmsbas.cxx 2007-08-31 01:39:01.000000000 +0800
-@@ -88,6 +88,7 @@ using namespace com::sun::star::awt;
+diff --git .gitignore .gitignore
+index 71145e6..7f99c80 100644
+--- .gitignore
++++ .gitignore
+@@ -6,3 +6,5 @@ unxlng*.pro
+ localize.sdf
+ /solver
+ *.orig
++*.swp
++/sc.nodebug
+diff --git basic/inc/basic/basmgr.hxx basic/inc/basic/basmgr.hxx
+index 2674c59..3c4f364 100644
+--- basic/inc/basic/basmgr.hxx
++++ basic/inc/basic/basmgr.hxx
+@@ -113,9 +113,10 @@ struct LibraryContainerInfo
+ ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > mxScriptCont;
+ ::com::sun::star::uno::Reference< com::sun::star::script::XPersistentLibraryContainer > mxDialogCont;
+ OldBasicPassword* mpOldBasicPassword;
++ bool mbVBACompatOn;
+
+ LibraryContainerInfo()
+- :mpOldBasicPassword( NULL )
++ :mpOldBasicPassword( NULL ), mbVBACompatOn( false )
+ {
+ }
+
+@@ -127,7 +128,7 @@ struct LibraryContainerInfo
+ )
+ : mxScriptCont( xScriptCont )
+ , mxDialogCont( xDialogCont )
+- , mpOldBasicPassword( pOldBasicPassword )
++ , mpOldBasicPassword( pOldBasicPassword ), mbVBACompatOn( false )
+ {}
+ };
+
+diff --git basic/source/basmgr/basmgr.cxx basic/source/basmgr/basmgr.cxx
+index b5394ae..eb68578 100644
+--- basic/source/basmgr/basmgr.cxx
++++ basic/source/basmgr/basmgr.cxx
+@@ -60,6 +60,7 @@
+
+ // Library API, implemented for XML import/export
++#include <com/sun/star/script/XVBACompat.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
- #include <com/sun/star/script/XLibraryContainer.hpp>
-+#include <com/sun/star/beans/StringPair.hpp>
- using namespace com::sun::star::container;
- using namespace com::sun::star::script;
- using namespace com::sun::star::uno;
-@@ -341,6 +342,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
- rtl::OUString sClassRem( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=" ) );
-
- rtl::OUString modeTypeComment;
-+ beans::StringPair sPair;
-
- switch( mType )
- {
-@@ -375,6 +377,8 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
- modeTypeComment = modeTypeComment + sVBAOption;
- if ( mType == Class )
- modeTypeComment = modeTypeComment + sClassOption;
-+ else if ( mType == Document )
-+ sPair.First = rtl::OUString::createFromAscii( "Document" );
-
- }
-
-@@ -435,12 +439,19 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
- aSource += rtl::OUString::createFromAscii("\nEnd Sub");
- }
- ::rtl::OUString aModName( sModule );
-- if ( aSource.getLength() )
-+ //if ( aSource.getLength() )
- {
- aSource = modeTypeComment + aSource;
+ #include <com/sun/star/container/XContainer.hpp>
+ #include <com/sun/star/script/XStarBasicAccess.hpp>
+@@ -208,10 +209,11 @@ void BasMgrContainerListenerImpl::insert
+ if( !pMgr->GetLib( aLibName ) )
+ {
+ BasicManager* pBasMgr = static_cast< BasicManager* >( pMgr );
+-#ifdef DBG_UTIL
+ StarBASIC* pLib =
+-#endif
+ pBasMgr->CreateLibForLibContainer( aLibName, xScriptCont );
++ if ( pLib )
++ pLib->SetVBAEnabled( pMgr->mpImpl->maContainerInfo.mbVBACompatOn );
++
+ DBG_ASSERT( pLib, "XML Import: Basic library could not be created");
+ }
- Any aSourceAny;
-- aSourceAny <<= aSource;
-+ if ( sPair.First.getLength() )
-+ {
-+ sPair.Second = aSource;
-+ aSourceAny <<= sPair;
-+ }
-+ else
-+ aSourceAny <<= aSource;
-+
- if( xLib->hasByName( aModName ) )
- xLib->replaceByName( aModName, aSourceAny );
- else
---- basctl/source/basicide/scriptdocument.cxx.bak 2007-09-03 13:50:05.000000000 +0800
-+++ basctl/source/basicide/scriptdocument.cxx 2007-09-04 16:59:01.000000000 +0800
-@@ -62,6 +62,9 @@
- #ifndef _COM_SUN_STAR_DOCUMENT_MACROEXECMODE_HPP_
- #include <com/sun/star/document/MacroExecMode.hpp>
- #endif
-+#ifndef _COM_SUN_STAR_BEAMS_STRINGPAIR_HPP_
-+#include <com/sun/star/beans/StringPair.hpp>
-+#endif
- /** === end UNO includes === **/
-
- #include <sfx2/objsh.hxx>
-@@ -99,6 +102,7 @@ namespace basctl
- using ::com::sun::star::script::XLibraryContainer;
- using ::com::sun::star::uno::UNO_QUERY_THROW;
- using ::com::sun::star::beans::XPropertySetInfo;
-+ using ::com::sun::star::beans::StringPair;
- using ::com::sun::star::uno::Exception;
- using ::com::sun::star::container::XNameContainer;
- using ::com::sun::star::container::NoSuchElementException;
-@@ -1102,7 +1106,20 @@ namespace basctl
- Any aCode;
- if ( !m_pImpl->getModuleOrDialog( E_SCRIPTS, _rLibName, _rModName, aCode ) )
- return false;
-- OSL_VERIFY( aCode >>= _out_rModuleSource );
-+ StringPair sPair;
-+ rtl::OUString sMod;
-+ rtl::OUString sModType;
-+ if ( aCode >>= sPair )
-+ {
-+ sModType = sPair.First;
-+ sMod = sPair.Second;
-+ }
-+ else
-+ {
-+ aCode >>= sMod;
-+ }
-+ Any aMod(sMod);
-+ OSL_VERIFY( aMod >>= _out_rModuleSource );
- return true;
+@@ -292,6 +294,12 @@ void SAL_CALL BasMgrContainerListenerImp
+ {
+ Reference< XLibraryContainer > xScriptCont( Event.Source, UNO_QUERY );
+ insertLibraryImpl( xScriptCont, mpMgr, Event.Element, aName );
++ Reference< XVBACompat > xCompat( xScriptCont, UNO_QUERY );
++ if ( xCompat.is() )
++ {
++ StarBASIC* pLib = mpMgr->GetLib( aName );
++ pLib->SetVBAEnabled( xCompat->getVBACompatModeOn() );
++ }
+ }
+ else
+ {
+@@ -822,6 +830,12 @@ void BasicManager::SetLibraryContainerIn
+
+ Reference< XLibraryContainer > xScriptCont( mpImpl->maContainerInfo.mxScriptCont.get() );
+ StarBASIC* pStdLib = GetStdLib();
++ Reference< XVBACompat > xCompat( GetScriptLibraryContainer(), UNO_QUERY );
++ if ( xCompat.is() )
++ mpImpl->maContainerInfo.mbVBACompatOn = xCompat->getVBACompatModeOn();
++ // Std is created regardless of any persisted Libraries, so.. we need
++ // to make sure we set its compat mode here
++ pStdLib->SetVBAEnabled( mpImpl->maContainerInfo.mbVBACompatOn );
+ String aLibName = pStdLib->GetName();
+ if( xScriptCont.is() )
+ {
+diff --git basic/source/classes/sbxmod.cxx basic/source/classes/sbxmod.cxx
+index 3f9e76c..e51fb8f 100644
+--- basic/source/classes/sbxmod.cxx
++++ basic/source/classes/sbxmod.cxx
+@@ -2250,26 +2250,31 @@ SbObjModule::SbObjModule( const com::sun
+ if ( mInfo.ModuleType == script::ModuleType::Form )
+ {
+ SetClassName( rtl::OUString::createFromAscii( "Form" ) );
+- return;
+ }
+- try
++ else
+ {
+- 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" ) ) )
++ try
+ {
+- SetClassName( rtl::OUString::createFromAscii( "Worksheet" ) );
++ uno::Reference< lang::XMultiServiceFactory > xSF( mInfo.ModuleObject, uno::UNO_QUERY_THROW );
++ uno::Reference< container::XNameAccess > xVBAObjectForCodeName( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.vba.VBAObjectModuleObjectProvider"))), UNO_QUERY_THROW );
++
++ com::sun::star::uno::Any aObject( xVBAObjectForCodeName->getByName( mInfo.ModuleName ) );
++ 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" ) );
++ }
+ }
+- else if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "org.openoffice.excel.Workbook" ) ) )
++ catch( com::sun::star::uno::RuntimeException e )
+ {
+- SetClassName( rtl::OUString::createFromAscii( "Workbook" ) );
++ OSL_TRACE("***** Failed to initialise API Object." );
+ }
}
+- catch( com::sun::star::uno::RuntimeException e )
+- {
+- OSL_TRACE("***** Failed to initialise API Object." );
+- }
+ }
---- basic/source/uno/namecont.cxx.bak 2007-08-28 14:36:26.000000000 +0800
-+++ basic/source/uno/namecont.cxx 2007-08-28 14:38:43.000000000 +0800
-@@ -137,8 +137,9 @@
- #ifndef _CPPUHELPER_EXC_HLP_HXX_
- #include <cppuhelper/exc_hlp.hxx>
- #endif
-+#include <com/sun/star/beans/StringPair.hpp>
- #include <basic/sbmod.hxx>
--
-+#include <comphelper/anytostring.hxx>
+ SbxVariable*
+@@ -2301,7 +2306,7 @@ class FormObjEventListenerImpl : public
+ public:
+ FormObjEventListenerImpl( SbUserFormModule* pUserForm, const uno::Reference< lang::XComponent >& xComponent ) : mpUserForm( pUserForm ), mxComponent( xComponent) , mbDisposed( false )
+ {
+- if ( mxComponent.is() );
++ if ( mxComponent.is() )
+ {
+ uno::Reference< awt::XTopWindow > xList( mxComponent, uno::UNO_QUERY_THROW );;
+ //uno::Reference< awt::XWindow > xList( mxComponent, uno::UNO_QUERY_THROW );;
+diff --git basic/source/inc/namecont.hxx basic/source/inc/namecont.hxx
+index e5b3d76..4f1d26a 100644
+--- basic/source/inc/namecont.hxx
++++ basic/source/inc/namecont.hxx
+@@ -62,20 +62,23 @@
+ #include <cppuhelper/implbase2.hxx>
+ #include <cppuhelper/compbase6.hxx>
+ #include <cppuhelper/compbase7.hxx>
++#include <cppuhelper/compbase8.hxx>
+ #include <cppuhelper/interfacecontainer.hxx>
++#include <com/sun/star/script/XVBACompat.hpp>
+
+ class BasicManager;
namespace basic
{
-@@ -217,10 +218,10 @@ void NameContainer::replaceByName( const
- throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
- {
- Type aAnyType = aElement.getValueType();
-- if( mType != aAnyType )
-+ if( mType != aAnyType && aAnyType != getCppuType( static_cast< StringPair* >( NULL ) ) )
- throw IllegalArgumentException();
-
-- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
-+ NameContainerNameMap::iterator aIt = mHashMap.find( aName );
- if( aIt == mHashMap.end() )
- {
- throw NoSuchElementException();
-@@ -259,7 +260,7 @@ void NameContainer::insertByName( const
- throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
- {
- Type aAnyType = aElement.getValueType();
-- if( mType != aAnyType )
-+ if( mType != aAnyType && aAnyType != getCppuType( static_cast< StringPair* >( NULL ) ) )
- throw IllegalArgumentException();
-
- NameContainerNameMap::iterator aIt = mHashMap.find( aName );
---- basic/source/runtime/step2.cxx.bak 2007-08-28 14:11:17.000000000 +0800
-+++ basic/source/runtime/step2.cxx 2007-08-28 14:13:21.000000000 +0800
-@@ -61,56 +61,6 @@ using com::sun::star::uno::Reference;
-
- SbxVariable* getVBAConstant( const String& rName );
-
--const static String aThisComponent( RTL_CONSTASCII_USTRINGPARAM("ThisComponent") );
--const static String aVBAHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) );
--// i#i68894#
--SbxArray* getVBAGlobals( )
--{
-- static SbxArrayRef pArray;
-- static bool isInitialised = false;
-- if ( isInitialised )
-- return pArray;
-- Reference < XComponentContext > xCtx;
-- Reference < XPropertySet > xProps(
-- ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
-- xCtx.set( xProps->getPropertyValue( rtl::OUString(
-- RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))),
-- UNO_QUERY_THROW );
-- SbUnoObject dGlobs( String( RTL_CONSTASCII_USTRINGPARAM("ExcelGlobals") ), xCtx->getValueByName( ::rtl::OUString::createFromAscii( "/singletons/org.openoffice.vba.theGlobals") ) );
--
-- SbxVariable *vba = dGlobs.Find( String( RTL_CONSTASCII_USTRINGPARAM("getGlobals") ) , SbxCLASS_DONTCARE );
--
-- if ( vba )
-- {
-- pArray = static_cast<SbxArray *>(vba->GetObject());
-- isInitialised = true;
-- return pArray;
-- }
-- return NULL;
--}
--
--// i#i68894#
--SbxVariable* VBAFind( const String& rName, SbxClassType t )
--{
-- if( rName == aThisComponent )
-- return NULL;
--
-- SbxArray *pVBAGlobals = getVBAGlobals( );
-- 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 = pVba ? pVba->Find( rName, t ) : NULL;
-- if( pVbaVar )
-- {
-- return pVbaVar;
-- }
-- }
-- return NULL;
--
--}
-
- // Suchen eines Elements
- // Die Bits im String-ID:
-@@ -130,6 +80,7 @@ SbxVariable* SbiRuntime::FindElement
- BOOL bFatalError = FALSE;
- SbxDataType t = (SbxDataType) nOp2;
- String aName( pImg->GetString( static_cast<short>( nOp1 & 0x7FFF ) ) );
-+ OSL_TRACE("FindElement %s, bLocal %d", rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr(), bLocal );
- bool bIsVBAInterOp = SbiRuntime::isVBAEnabled();
- if( bIsVBAInterOp )
- {
-@@ -187,7 +138,7 @@ SbxVariable* SbiRuntime::FindElement
- if ( bVBAEnabled )
- {
- // Try Find in VBA symbols space
-- pElem = VBAFind( aName, SbxCLASS_DONTCARE );
-+ pElem = rBasic.VBAFind( aName, SbxCLASS_DONTCARE );
- if ( pElem )
- bSetName = false; // don't overwrite uno name
- else
---- basic/source/classes/sbxmod.cxx.bak 2007-08-28 12:01:38.000000000 +0800
-+++ basic/source/classes/sbxmod.cxx 2007-09-05 23:56:14.000000000 +0800
-@@ -51,6 +51,7 @@
- #include <tools/shl.hxx>
- #endif
- #include <basic/sbx.hxx>
-+#include <basic/sbobjmod.hxx>
- #include "sb.hxx"
- #include <sbjsmeth.hxx>
- #include "sbjsmod.hxx"
-@@ -88,6 +89,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)
-@@ -1902,7 +1904,144 @@ void SyntaxHighlighter::getHighlightPort
- m_pSimpleTokenizer->getHighlightPortions( nLine, rLine, portions );
- }
-
-+#include <org/openoffice/vba/XGlobals.hpp>
-+#include <org/openoffice/excel/XWorksheets.hpp>
-+#include <com/sun/star/beans/XPropertySet.hpp>
-+#include <comphelper/processfactory.hxx>
-+com::sun::star::uno::Reference< org::openoffice::vba::XGlobals > getVBAGlob()
-+{
-+ com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > xCtx;
-+ com::sun::star::uno::Reference < com::sun::star::beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), com::sun::star::uno::UNO_QUERY_THROW );
-+
-+ com::sun::star::uno::Reference< com::sun::star::lang::XMultiComponentFactory > xSMgr( xProps, com::sun::star::uno::UNO_QUERY_THROW );
-+
-+ xCtx.set( xProps->getPropertyValue( rtl::OUString(
-+ RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))),
-+ com::sun::star::uno::UNO_QUERY_THROW );
-+ com::sun::star::uno::Reference< org::openoffice::vba::XGlobals > xGlobs( xSMgr->createInstanceWithContext( ::rtl::OUString::createFromAscii( "org.openoffice.vba.Globals"), xCtx ), com::sun::star::uno::UNO_QUERY_THROW );
-+ return xGlobs;
-+}
-+/////////////////////////////////////////////////////////////////////////
-+SbObjModule::SbObjModule( const String& rName, StarBASIC* pBasic )
-+ :SbModule( rName ), pDocObject( NULL )
-+{
-+ InitObject( rName );
-+}
-+/*
-+SbObjModule::~SbObjModule()
-+{
-+ if ( pDocObject )
-+ delete pDocObject;
-+}
-+*/
-+/*
-+BOOL SbObjModule::LoadData( SvStream&, USHORT )
-+{
-+ return FALSE;
-+}
-+
-+BOOL SbObjModule::StoreData( SvStream& ) const
-+{
-+ return FALSE;
-+}
-+*/
-+SbxVariable*
-+SbObjModule::GetObject()
-+{
-+ return Find( GetName(), SbxCLASS_DONTCARE );
-+}
-+SbxVariable*
-+SbObjModule::Find( const XubString& rName, SbxClassType t )
-+{
-+ OSL_TRACE("SbObjectModule find for %s", rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr() );
-+ // should init pDocObject when first search.
-+ SbxVariable* pVar = SbModule::Find( rName, t );
-+ if ( !pDocObject )
-+ InitObject( );
-+ if ( !pVar )
-+ {
-+ OSL_TRACE("Not found in derived module " );
-+ if ( !pVar && pDocObject)
-+ {
-+ OSL_TRACE("!!!!try to find in derived module " );
-+ pVar = pDocObject->Find( rName, t );
-+ // make private
-+ if ( pVar )
-+ {
-+ OSL_TRACE("found in uno (psuedo-base) object" );
-+ pVar->SetFlag( SBX_PRIVATE );
-+ }
-+ else
-+ OSL_TRACE("NOT found in uno (psuedo-base) object" );
-+ }
-+ }
-+ else
-+ OSL_TRACE("! found in (normal) module " );
-+ return pVar;
-+}
-+void
-+SbObjModule::InitObject( )
-+{
-+ InitObject( GetName() );
-+}
-+void
-+SbObjModule::InitObject( const XubString& rName )
-+{
-+ try
-+ {
-+ com::sun::star::uno::Reference< org::openoffice::vba::XGlobals > xGlobs = getVBAGlob();
-+ com::sun::star::uno::Reference< org::openoffice::excel::XWorkbook > xWorkbook = xGlobs->getActiveWorkbook();
-+ String sGlobCodeName = xWorkbook->getCodeName();
-+ OSL_TRACE("globcodename is %s", rtl::OUStringToOString( sGlobCodeName, RTL_TEXTENCODING_UTF8 ).getStr() );
-+ if ( sGlobCodeName == rName )
-+ {
-+ pDocObject = new SbUnoObject( rName, com::sun::star::uno::makeAny( xWorkbook ) );
-+ return;
-+ }
-+ com::sun::star::uno::Any aIndex;
-+ com::sun::star::uno::Reference< org::openoffice::excel::XWorksheets > xWorksheets( xWorkbook->Sheets( aIndex ), com::sun::star::uno::UNO_QUERY_THROW );
-+ sal_Int32 nCount = xWorksheets->getCount();
-+ for ( sal_Int32 i = 1; i <= nCount; i++ )
-+ {
-+ com::sun::star::uno::Reference< org::openoffice::excel::XWorksheet > xWorksheet( xWorkbook->Sheets( com::sun::star::uno::makeAny( i ) ), com::sun::star::uno::UNO_QUERY_THROW );
-+ String sCodeName = xWorksheet->getCodeName();
-+ OSL_TRACE("sheet %s 's codename is %s", rtl::OUStringToOString( xWorksheet->getName(), RTL_TEXTENCODING_UTF8 ).getStr(), rtl::OUStringToOString( sCodeName, RTL_TEXTENCODING_UTF8 ).getStr() );
-+ if ( sCodeName == rName )
-+ {
-+ pDocObject = new SbUnoObject( rName, com::sun::star::uno::makeAny( xWorksheet ) );
-+ return;
-+ }
-+ }
-+ }catch( com::sun::star::uno::RuntimeException e )
-+ {
-+ OSL_TRACE("Object is not exist." );
-+ }
-+}
-+void
-+SbObjModule::SetCodeName( const XubString& rName )
-+{
-+ if ( rName == GetName() )
-+ return;
-+ if ( !pDocObject )
-+ InitObject( );
-+ if ( pDocObject )
-+ {
-+ SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,(SbxObject*)pDocObject);
-+ com::sun::star::uno::Reference< org::openoffice::excel::XWorksheet > xWorksheet( pUnoObj->getUnoAny(), com::sun::star::uno::UNO_QUERY );
-+ if ( xWorksheet.is() )
-+ {
-+ OSL_TRACE("Worksheet's new codename is %s", rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr() );
-+ return;
-+ }
-+ com::sun::star::uno::Reference< org::openoffice::excel::XWorkbook > xWorkbook( pUnoObj->getUnoAny(), com::sun::star::uno::UNO_QUERY );
-+ if ( xWorkbook.is() )
-+ {
-+ OSL_TRACE("Workbook's new codename is %s", rtl::OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr() );
-+ return;
-+ }
-+ }
-+}
- /////////////////////////////////////////////////////////////////////////
- // Implementation SbJScriptModule (Basic-Modul fuer JavaScript-Sourcen)
- SbJScriptModule::SbJScriptModule( const String& rName )
---- basic/source/classes/sb.cxx.bak 2007-08-28 14:05:01.000000000 +0800
-+++ basic/source/classes/sb.cxx 2007-09-05 21:23:24.000000000 +0800
-@@ -70,6 +70,7 @@
- #include "disas.hxx"
- #include "runtime.hxx"
- #include <basic/sbuno.hxx>
-+#include <basic/sbobjmod.hxx>
- #include "stdobj.hxx"
- #include "filefmt.hxx"
- #include "sb.hrc"
-@@ -78,6 +79,10 @@
- #ifndef _VOS_MUTEX_HXX_
- #include <vos/mutex.hxx>
- #endif
-+#include <com/sun/star/beans/XPropertySet.hpp>
-+#include <comphelper/processfactory.hxx>
-+using namespace com::sun::star::uno;
-+using namespace com::sun::star::beans;
+-typedef ::cppu::WeakComponentImplHelper7<
++typedef ::cppu::WeakComponentImplHelper8<
+ ::com::sun::star::lang::XInitialization,
+ ::com::sun::star::script::XStorageBasedLibraryContainer,
+ ::com::sun::star::script::XLibraryContainerPassword,
+ ::com::sun::star::script::XLibraryContainerExport,
+ ::com::sun::star::container::XContainer,
+ ::com::sun::star::script::XLibraryQueryExecutable,
++ ::com::sun::star::script::XVBACompat,
+ ::com::sun::star::lang::XServiceInfo > LibraryContainerHelper;
+
+ typedef ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameContainer,
+@@ -248,7 +251,7 @@ protected:
+ sal_Bool mbOwnBasMgr;
- // #pragma SW_SEGMENT_CLASS( SBASIC, SBASIC_CODE )
+ InitMode meInitMode;
+-
++ bool mbVBACompatModeOn;
+ void implStoreLibrary( SfxLibrary* pLib,
+ const ::rtl::OUString& aName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
+@@ -497,6 +500,8 @@ public:
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
+ throw (::com::sun::star::uno::RuntimeException) = 0;
++ virtual ::sal_Bool SAL_CALL getVBACompatModeOn() throw (::com::sun::star::uno::RuntimeException);
++ virtual void SAL_CALL setVBACompatModeOn( ::sal_Bool _vbacompatmodeon ) throw (::com::sun::star::uno::RuntimeException);
+ };
+
+ class LibraryContainerMethodGuard
+@@ -556,7 +561,7 @@ private:
+ ::rtl::OUString maPassword;
-@@ -767,9 +772,15 @@ SbModule* StarBASIC::MakeModule( const S
- return MakeModule32( rName, rSrc );
- }
+ sal_Bool mbSharedIndexFile;
+-
++ ::xmlscript::ObjectModuleDescHash mhCodeNameToObjDesc;
+ // Additional functionality for localisation
+ // Provide modify state including resources
+ virtual sal_Bool isModified( void ) = 0;
+diff --git basic/source/uno/namecont.cxx basic/source/uno/namecont.cxx
+index e5f37c7..bdf9bbf 100644
+--- basic/source/uno/namecont.cxx
++++ basic/source/uno/namecont.cxx
+@@ -75,6 +75,7 @@
+ #ifndef _COM_SUN_STAR_SCRIPT_MODULEINFO_HPP_
+ #include <com/sun/star/script/ModuleInfo.hpp>
+ #endif
++#include <com/sun/star/script/XCodeNameBinder.hpp>
--SbModule* StarBASIC::MakeModule32( const String& rName, const ::rtl::OUString& rSrc )
-+SbModule* StarBASIC::MakeModule32( const String& rName, const ::rtl::OUString& rSrc, UINT16 nSbxId )
+ namespace basic
{
-- SbModule* p = new SbModule( rName );
-+ SbModule* p = NULL;
-+
-+ if ( nSbxId == SBXID_DOCUMENTMOD)
-+ p = new SbObjModule( rName, this );
-+ else
-+ p = new SbModule( rName );
-+
- p->SetSource32( rSrc );
- p->SetParent( this );
- pModules->Insert( p, pModules->Count() );
-@@ -931,6 +942,13 @@ SbxVariable* StarBASIC::Find( const Stri
- if( pRes )
- pRes->SetFlag( SBX_EXTFOUND );
- }
-+/*
-+ // Hack for helperapi
-+ bool bVBA = SbiRuntime::isVBAEnabled()
-+ if ( bVBA && !bDocBasic )
-+ return NULL;
-+*/
-+
- // Module durchsuchen
- if( !pRes )
- for( USHORT i = 0; i < pModules->Count(); i++ )
-@@ -1491,6 +1509,65 @@ BOOL StarBASIC::LoadOldModules( SvStream
- return FALSE;
- }
+@@ -325,6 +326,17 @@ void ModifiableHelper::setModified( sal_
+ // Implementation class SfxLibraryContainer
+ DBG_NAME( SfxLibraryContainer )
-+const static String aThisComponent( RTL_CONSTASCII_USTRINGPARAM("ThisComponent") );
-+const static String aVBAHook( RTL_CONSTASCII_USTRINGPARAM( "VBAGlobals" ) );
-+// i#i68894#
-+SbxArray*
-+StarBASIC::getVBAGlobals( )
++::sal_Bool SAL_CALL
++SfxLibraryContainer::getVBACompatModeOn() throw (RuntimeException)
+{
-+ if ( !bDocBasic )
-+ return NULL; // VBA only valid for Document basic
-+
-+ if ( pVBAArray )
-+ return pVBAArray;
-+
-+ Reference < XComponentContext > xCtx;
-+ Reference < XPropertySet > xProps(
-+
-+ ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
-+
-+ Reference< XMultiComponentFactory > xSMgr( xProps, UNO_QUERY_THROW );
-+
-+ xCtx.set( xProps->getPropertyValue( rtl::OUString(
-+ RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))),
-+ UNO_QUERY_THROW );
-+ SbUnoObject* dGlobs = new SbUnoObject( aVBAHook , makeAny( xSMgr->createInstanceWithContext( ::rtl::OUString::createFromAscii( "org.openoffice.vba.Globals"), xCtx ) ));
-+ Insert( dGlobs );
-+
-+ SbxVariable *vba = dGlobs->Find( String( RTL_CONSTASCII_USTRINGPARAM("getGlobals") ) , SbxCLASS_DONTCARE );
-+
-+ if ( vba )
-+ {
-+ pVBAArray = static_cast<SbxArray *>(vba->GetObject());
-+ return pVBAArray;
-+ }
-+ return NULL;
++ return mbVBACompatModeOn;
+}
-+
-+// i#i68894#
-+SbxVariable*
-+StarBASIC::VBAFind( const String& rName, SbxClassType t )
++void SAL_CALL
++SfxLibraryContainer::setVBACompatModeOn( ::sal_Bool _vbacompatmodeon ) throw (RuntimeException)
+{
-+ if( rName == aThisComponent )
-+ return NULL;
-+
-+ SbxArray *pVBAGlobals = getVBAGlobals( );
-+ 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 = pVba ? pVba->Find( rName, t ) : NULL;
-+ if( pVbaVar )
-+ {
-+ return pVbaVar;
-+ }
-+ }
-+ return NULL;
-+
++ // will need to trigger event so that basicmanager can get it
++ mbVBACompatModeOn = ( _vbacompatmodeon == sal_True );
+}
+ // Ctor
+ SfxLibraryContainer::SfxLibraryContainer( void )
+ : LibraryContainerHelper( maMutex )
+@@ -334,6 +346,7 @@ SfxLibraryContainer::SfxLibraryContainer
+ , mbOasis2OOoFormat( sal_False )
+ , mpBasMgr( NULL )
+ , mbOwnBasMgr( sal_False )
++ , mbVBACompatModeOn( sal_False )
+ {
+ DBG_CTOR( SfxLibraryContainer, NULL );
+
+@@ -790,7 +803,7 @@ sal_Bool SfxLibraryContainer::init_Impl(
+ OSL_ENSURE( 0, OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
+ return sal_False;
+ }
+-
++ mbVBACompatModeOn = pLibArray->mbVBAMode;
+ sal_Int32 nLibCount = pLibArray->mnLibCount;
+ for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
+ {
+@@ -1620,16 +1633,35 @@ void SfxLibraryContainer::implImportLibD
+ sal_Int32 nElementCount = rLib.aElementNames.getLength();
+ const OUString* pElementNames = rLib.aElementNames.getConstArray();
+ Any aDummyElement = createEmptyLibraryElement();
++ // push code name associations
++ Reference< XMultiServiceFactory > xDocumentFac( mxOwnerDocument.get(), UNO_QUERY );
++ Reference< XCodeNameBinder > xBind;
++ if ( xDocumentFac.is() )
++ xBind.set( xDocumentFac->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.vba.VBAObjectModuleObjectProvider"))), UNO_QUERY );
++ ::xmlscript::ObjectModuleDescHash::iterator it_end = rLib.hCodeNameToObjDesc.end();
+ for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
+ {
++ ::xmlscript::ObjectModuleDescHash::iterator it = rLib.hCodeNameToObjDesc.find( pElementNames[i] );
++
++ if ( it != it_end && xBind.is() )
++ {
++ // for all other types set up the ModuleInfo structure
++ com::sun::star::script::ModuleInfo mInfo;
++ mInfo.ModuleName = pElementNames[i];
++ mInfo.ModuleType = it->second.mnModuleType;
++ mInfo.ModuleObject = mxOwnerDocument;
++ aDummyElement <<= mInfo;
++ }
+ pLib->maNameContainer.insertByName( pElementNames[i], aDummyElement );
+- }
++ }
+ pLib->mbPasswordProtected = rLib.bPasswordProtected;
+ pLib->mbReadOnly = rLib.bReadOnly;
+ pLib->mbPreload = rLib.bPreload;
+ pLib->implSetModified( sal_False );
+
+ pLib->mbInitialised = sal_True;
++ pLib->mhCodeNameToObjDesc = rLib.hCodeNameToObjDesc;
+
+ }
+ }
- //========================================================================
- // #118116 Implementation Collection object
---- basic/source/basmgr/basmgr.cxx.bak 2007-08-28 14:00:38.000000000 +0800
-+++ basic/source/basmgr/basmgr.cxx 2007-08-31 01:00:51.000000000 +0800
-@@ -86,6 +86,7 @@
- #include "sbintern.hxx"
- #include <sb.hrc>
-
-+#include <com/sun/star/beans/StringPair.hpp>
-
- #define LIB_SEP 0x01
- #define LIBINFO_SEP 0x02
-@@ -105,6 +106,7 @@
-
- #include <cppuhelper/implbase1.hxx>
-
-+using namespace com::sun::star::beans;
- using com::sun::star::uno::Reference;
- using namespace com::sun::star::container;
- using namespace com::sun::star::uno;
-@@ -280,9 +282,21 @@ void BasMgrContainerListenerImpl::addLib
- {
- OUString aModuleName = pNames[ j ];
- Any aElement = xLibNameAccess->getByName( aModuleName );
-+ StringPair sPair;
- OUString aMod;
-- aElement >>= aMod;
-- pLib->MakeModule32( aModuleName, aMod );
-+ OUString aModType;
-+ if ( aElement >>= sPair )
-+ {
-+ aModType = sPair.First;
-+ aMod = sPair.Second;
-+ OSL_TRACE("#1 - aMod");
-+ pLib->MakeModule32( aModuleName, aMod, SBXID_DOCUMENTMOD );
-+ }
-+ else
+@@ -2177,10 +2209,26 @@ void SAL_CALL SfxLibraryContainer::loadL
+ }
+
+ Any aAny = importLibraryElement( aFile, xInStream );
++ // perhaps the ModuleInfo stuff might be better done in scriptcont
++ // ( via importLibraryElement, probably would need to pass pImplLib though, which
++ // defeats the purpose of the pImpl )
++ ::xmlscript::ObjectModuleDescHash::iterator it = pImplLib->mhCodeNameToObjDesc.find( aElementName );
++ if ( it != pImplLib->mhCodeNameToObjDesc.end() )
+ {
-+ aElement >>= aMod;
-+ pLib->MakeModule32( aModuleName, aMod );
++ // Replace the aAny with one containing ModuleInfo
++ com::sun::star::script::ModuleInfo mInfo;
++ mInfo.ModuleName = aElementName;
++ mInfo.ModuleType = it->second.mnModuleType;
++ mInfo.ModuleObject = mxOwnerDocument;
++ aAny >>= mInfo.ModuleSource;
++ aAny <<= mInfo;
+ }
- }
- }
-
-@@ -319,9 +333,17 @@ void SAL_CALL BasMgrContainerListenerImp
- }
- else
- {
-+ StringPair sPair;
- OUString aMod;
-- Event.Element >>= aMod;
--
-+ OUString aModType;
-+
-+ if ( Event.Element >>= sPair )
-+ {
-+ aModType = sPair.First;
-+ aMod = sPair.Second;
-+ }
-+ else
-+ Event.Element >>= aMod;
- StarBASIC* pLib = mpMgr->GetLib( maLibName );
- DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::elementInserted: Unknown lib!");
- if( pLib )
-@@ -329,7 +351,12 @@ void SAL_CALL BasMgrContainerListenerImp
- SbModule* pMod = pLib->FindModule( aName );
- if( !pMod )
+ if( pImplLib->hasByName( aElementName ) )
{
-- pLib->MakeModule32( aName, aMod );
-+ if ( aModType.getLength() && aModType.equalsAscii( "Document" ) )
+ if( aAny.hasValue() )
+ {
-+ pLib->MakeModule32( aName, aMod, SBXID_DOCUMENTMOD );
+ pImplLib->maNameContainer.replaceByName( aElementName, aAny );
+ }
-+ else
-+ pLib->MakeModule32( aName, aMod );
- pLib->SetModified( FALSE );
}
- }
-@@ -356,13 +383,29 @@ void SAL_CALL BasMgrContainerListenerImp
- if( pLib )
- {
- SbModule* pMod = pLib->FindModule( aName );
-+ StringPair sPair;
- OUString aMod;
-+ OUString aModType;
-+
-+ if ( Event.Element >>= sPair )
-+ {
-+ aModType = sPair.First;
-+ aMod = sPair.Second;
-+ }
-+ else
-+ Event.Element >>= aMod;
- Event.Element >>= aMod;
- if( pMod )
- pMod->SetSource32( aMod );
- else
-- pLib->MakeModule32( aName, aMod );
--
+ else
+ {
+diff --git basic/source/uno/sbservices.cxx basic/source/uno/sbservices.cxx
+index a2a4ded..aa076ea 100644
+--- basic/source/uno/sbservices.cxx
++++ basic/source/uno/sbservices.cxx
+@@ -43,6 +43,7 @@ namespace basic
+ //--------------------------------------------------------------------
+ extern void createRegistryInfo_SfxDialogLibraryContainer();
+ extern void createRegistryInfo_SfxScriptLibraryContainer();
++ extern void createRegistryInfo_PersistedReadOnlyCodeNames();
+
+ static void initializeModule()
+ {
+@@ -54,6 +55,7 @@ namespace basic
+ {
+ createRegistryInfo_SfxDialogLibraryContainer();
+ createRegistryInfo_SfxScriptLibraryContainer();
++ createRegistryInfo_PersistedReadOnlyCodeNames();
+ }
+ }
+ }
+diff --git basic/source/uno/scriptcont.cxx basic/source/uno/scriptcont.cxx
+index 7480f7c..6d72850 100644
+--- basic/source/uno/scriptcont.cxx
++++ basic/source/uno/scriptcont.cxx
+@@ -1056,6 +1056,11 @@ SfxScriptLibraryContainer:: HasExecutabl
+
+ //============================================================================
+ // Service
++class PersistedReadOnlyCodeNames;
++void createRegistryInfo_PersistedReadOnlyCodeNames()
++{
++ static OAutoRegistration< PersistedReadOnlyCodeNames > aAutoRegistration;
++}
+ void createRegistryInfo_SfxScriptLibraryContainer()
+ {
+ static OAutoRegistration< SfxScriptLibraryContainer > aAutoRegistration;
+@@ -1160,6 +1165,124 @@ void SfxScriptLibrary::storeResourcesToS
+ // No resources
+ (void)xStorage;
+ }
++typedef ::cppu::WeakImplHelper3< container::XNameAccess, lang::XInitialization, lang::XServiceInfo > ReadOnlyCodeNames_BASE;
++
++// XNameAccess, codename to/from objectnames
++class PersistedReadOnlyCodeNames : ReadOnlyCodeNames_BASE
++{
++ ::xmlscript::CodeNameHash mCodeNameToObjectNames;
++public:
++ PersistedReadOnlyCodeNames()
++ {
++ }
++ // Methods - XInitialise
++ virtual void SAL_CALL initialize( const uno::Sequence< uno::Any >& aArguments ) throw (uno::Exception, uno::RuntimeException)
++ {
++ if ( !aArguments.getLength() )
++ throw RuntimeException();
++ Reference< document::XStorageBasedDocument > xDocument( aArguments[ 0 ], uno::UNO_QUERY_THROW );
++ Reference< embed::XStorage > xDocStorage;
++ try
+ {
-+ if ( aModType.getLength() && aModType.equalsAscii( "Document" ) )
++ Reference< XMultiServiceFactory > xMSF = comphelper::getProcessServiceFactory();
++ Reference< XServiceInfo > xSI( xDocument, UNO_QUERY_THROW );
++ if ( xSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.OfficeDocument" ) ) ) )
++ xDocStorage.set( xDocument->getDocumentStorage(), UNO_QUERY_THROW );
++ if ( xDocStorage.is() ) // not a 'real' document
+ {
-+ pLib->MakeModule32( aName, aMod, SBXID_DOCUMENTMOD );
++ rtl::OUString codeNameDir( RTL_CONSTASCII_USTRINGPARAM("Basic") );
++ rtl::OUString codeNameFile( RTL_CONSTASCII_USTRINGPARAM("script-lc.xml") );
++
++ uno::Reference< embed::XStorage > xLibrariesStor( xDocStorage->openStorageElement( codeNameDir, embed::ElementModes::READ ), UNO_QUERY_THROW );
++ uno::Reference< io::XStream > xStream( xLibrariesStor->openStreamElement( codeNameFile, embed::ElementModes::READ ), UNO_QUERY_THROW );
++ uno::Reference< io::XInputStream > xInput( xStream->getInputStream(), UNO_QUERY_THROW );
++ ::xmlscript::LibDescriptorArray* pLibArray = new ::xmlscript::LibDescriptorArray();
++ InputSource source;
++ source.aInputStream = xInput;
++
++ Reference< XParser > xParser( xMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY_THROW );
++ xParser->setDocumentHandler( ::xmlscript::importLibraryCodeNames( pLibArray ) );
++ xParser->parseStream( source );
++ mCodeNameToObjectNames = pLibArray->mCodeNames;
+ }
-+ else
-+ pLib->MakeModule32( aName, aMod );
+ }
- pLib->SetModified( FALSE );
- }
- }
---- basic/inc/basic/sbstar.hxx.bak 2007-08-28 13:57:02.000000000 +0800
-+++ basic/inc/basic/sbstar.hxx 2007-08-28 14:00:10.000000000 +0800
-@@ -94,6 +94,8 @@ private:
- virtual BOOL LoadData( SvStream&, USHORT );
- virtual BOOL StoreData( SvStream& ) const;
++ catch ( Exception& e )
++ {
++ OSL_TRACE("Urk, should never get here, help!!");
++ }
++ }
++ // Methods - XNameAccess
++ virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
++ {
++ ::xmlscript::CodeNameHash::iterator it = mCodeNameToObjectNames.find( aName );
++ if ( it == mCodeNameToObjectNames.end() )
++ throw container::NoSuchElementException();
++ return uno::makeAny( it->second );
++ }
++ virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException)
++ {
++ uno::Sequence< ::rtl::OUString > sNames( mCodeNameToObjectNames.size() );
++ ::rtl::OUString* pStr = sNames.getArray();
++ ::xmlscript::CodeNameHash::iterator it = mCodeNameToObjectNames.begin();
++ ::xmlscript::CodeNameHash::iterator it_end = mCodeNameToObjectNames.end();
++ for ( ; it != it_end ; ++it, ++pStr )
++ *pStr = it->first;
++ return sNames;
++ }
++ virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
++ {
++ return ( mCodeNameToObjectNames.find( aName ) != mCodeNameToObjectNames.end() );
++ }
++ // Methods - XElementAccess
++ virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
++ {
++ return ::getCppuType( (const rtl::OUString *)0 );
++ }
++ virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
++ {
++ return ( mCodeNameToObjectNames.size() > 0 );
++ }
++ // Methods XServiceInfo
++ virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException)
++ {
++ return getImplementationName_static();
++ }
++ virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException)
++ {
++ uno::Sequence< rtl::OUString > sNames( getSupportedServiceNames() );
++ rtl::OUString* pStr = sNames.getArray();
++ rtl::OUString* pEnd = ( sNames.getArray() + sNames.getLength() );
++ for ( ; pStr != pEnd ; ++pStr )
++ {
++ if ( (*pStr).equals( ServiceName ) )
++ return sal_True;
++ }
++ return sal_False;
++ }
++ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException)
++ {
++ return getSupportedServiceNames_static();
++ }
++ // Service
++ static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static()
++ {
++ uno::Sequence< rtl::OUString > sServiceNames(1);
++ sServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.vba.PersistedCodeNames"));
++ return sServiceNames;
++ }
++ static ::rtl::OUString getImplementationName_static()
++ {
++ static OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("PersistedReadOnlyCodeNames") );
++ return sImplName;
++ }
++
++ static Reference< XInterface > SAL_CALL Create ( const Reference< XComponentContext >& xServiceManager ) throw( Exception )
++ {
++ Reference< XInterface > xRet =
++ static_cast< XInterface* >( static_cast< OWeakObject* >( new PersistedReadOnlyCodeNames() ));
++ return xRet;
++ }
++};
-+ SbxArrayRef pVBAArray;
-+ SbxArray* getVBAGlobals( );
- protected:
+ //============================================================================
- virtual BOOL ErrorHdl();
-@@ -124,7 +126,7 @@ public:
+diff --git offapi/com/sun/star/document/XVbaEventsHelper.idl offapi/com/sun/star/document/XVbaEventsHelper.idl
+index 718e68d..fd0e2db 100644
+--- offapi/com/sun/star/document/XVbaEventsHelper.idl
++++ offapi/com/sun/star/document/XVbaEventsHelper.idl
+@@ -45,6 +45,7 @@ module com { module sun { module star
- // 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, UINT16 nSbxId = SBXID_BASICMOD);
- BOOL Compile( SbModule* );
- BOOL Disassemble( SbModule*, String& rText );
- static void Stop();
-@@ -191,6 +193,7 @@ public:
-
- SbxArrayRef getUnoListeners( void );
-
-+ SbxVariable* VBAFind( const String& rName, SbxClassType t );
- static SbxBase* FindSBXInCurrentScope( const String& rName );
- static SbxVariable* FindVarInCurrentScopy
- ( const String& rName, USHORT& rStatus );
---- basic/inc/basic/sbdef.hxx.bak 2007-08-28 13:50:38.000000000 +0800
-+++ basic/inc/basic/sbdef.hxx 2007-08-28 13:50:42.000000000 +0800
-@@ -100,6 +100,7 @@ void setBasicWatchMode( bool bOn );
-
- #define SBXID_BASIC 0x6273 // sb: StarBASIC
- #define SBXID_BASICMOD 0x6d62 // bm: StarBASIC-Modul
-+#define SBXID_DOCUMENTMOD 0x6d63 // Special document Module
- #define SBXID_BASICPROP 0x7262 // pr: StarBASIC-Property
- #define SBXID_BASICMETHOD 0x6d65 // me: StarBASIC-Methode
- #define SBXID_JSCRIPTMOD 0x6a62 // jm: JavaScript-Modul
---- /dev/null 2006-11-25 20:17:37.000000000 +0800
-+++ basic/inc/basic/sbobjmod.hxx 2007-09-05 21:39:59.000000000 +0800
-@@ -0,0 +1,66 @@
+ interface XVbaEventsHelper
+ {
++ [attribute ] boolean IgnoreEvents;
+ // nTab -1 for workbook.
+ boolean ProcessCompatibleVbaEvent( [in] long VbaEvent, [in] sequence< any > aArgs );
+ };
+diff --git offapi/com/sun/star/script/XCodeNameBinder.idl offapi/com/sun/star/script/XCodeNameBinder.idl
+new file mode 100644
+index 0000000..58e3606
+--- /dev/null
++++ offapi/com/sun/star/script/XCodeNameBinder.idl
+@@ -0,0 +1,49 @@
+/*************************************************************************
+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ *
++ * Copyright 2008 by Sun Microsystems, Inc.
+ *
-+ * $RCSfile: sbobjmod.hxx,v $
++ * OpenOffice.org - a multi-platform office productivity suite
+ *
-+ * $Revision: 1.4 $
++ * $RCSfile: XLibraryContainer.idl,v $
++ * $Revision: 1.4 $
+ *
-+ * last change: $Author: $ $Date: 2007/08/27 16:31:39 $
++ * This file is part of OpenOffice.org.
+ *
-+ * The Contents of this file are made available subject to
-+ * the terms of GNU Lesser General Public License Version 2.1.
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
+ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
+ *
-+ * GNU Lesser General Public License Version 2.1
-+ * =============================================
-+ * Copyright 2005 by Sun Microsystems, Inc.
-+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org. If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
+ *
-+ * 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.
++ ************************************************************************/
++#ifndef __com_sun_star_script_XCodeNameBinder_idl__
++#define __com_sun_star_script_XCodeNameBinder_idl__
++
++#ifndef __com_sun_star_uno_XInterface_idl__
++#include <com/sun/star/uno/XInterface.idl>
++#endif
++
++//=============================================================================
++
++module com { module sun { module star { module script {
++
++interface XCodeNameBinder: com::sun::star::uno::XInterface
++{
++
++ void bindCodeName( [in] string codename, [in] string objectname );
++//=============================================================================
++
++}; }; }; };
++};
++#endif
+diff --git offapi/com/sun/star/script/XVBACompat.idl offapi/com/sun/star/script/XVBACompat.idl
+new file mode 100644
+index 0000000..e1b2d28
+--- /dev/null
++++ offapi/com/sun/star/script/XVBACompat.idl
+@@ -0,0 +1,49 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ *
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
+ *
-+ * 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.
++ * $RCSfile: XLibraryContainer.idl,v $
++ * $Revision: 1.4 $
+ *
-+ * 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
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org. If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
++#ifndef __com_sun_star_script_XVBACompat_idl__
++#define __com_sun_star_script_XVBACompat_idl__
++
++#ifndef __com_sun_star_uno_XInterface_idl__
++#include <com/sun/star/uno/XInterface.idl>
++#endif
++
++//=============================================================================
++
++module com { module sun { module star { module script {
++
++interface XVBACompat: com::sun::star::uno::XInterface
++{
+
-+#ifndef _SB_OBJMOD_HXX
-+#define _SB_OBJMOD_HXX
-+
-+#include <basic/sbmod.hxx>
-+#include <basic/sbstar.hxx>
-+
-+// Basic-Module for excel object.
++//=============================================================================
++ [attribute ] boolean VBACompatModeOn;
++
++}; }; }; };
++};
++#endif
+diff --git offapi/com/sun/star/script/makefile.mk offapi/com/sun/star/script/makefile.mk
+index 113d4c9..f9e3208 100644
+--- offapi/com/sun/star/script/makefile.mk
++++ offapi/com/sun/star/script/makefile.mk
+@@ -51,6 +51,8 @@ IDLFILES=\
+ XPersistentLibraryContainer.idl\
+ XStorageBasedLibraryContainer.idl\
+ XLibraryQueryExecutable.idl \
++ XVBACompat.idl\
++ XCodeNameBinder.idl\
+ ModuleSizeExceededRequest.idl\
+
+ # ------------------------------------------------------------------
+diff --git sc/inc/document.hxx sc/inc/document.hxx
+index d32e28c..e23cbfd 100644
+--- sc/inc/document.hxx
++++ sc/inc/document.hxx
+@@ -34,6 +34,7 @@
+
+ #include <vcl/prntypes.hxx>
+ #include <vcl/timer.hxx>
++#include <com/sun/star/container/XNameAccess.hpp>
+ #include <com/sun/star/uno/Reference.hxx>
+ #include <vos/ref.hxx>
+ #include "scdllapi.h"
+@@ -316,7 +317,7 @@ private:
+
+ //ScVbaEventsHelper* pVbaEventsHelper;
+ com::sun::star::uno::Reference< com::sun::star::document::XVbaEventsHelper > rVbaEventsHelper;
+-
++ com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > mxCodeNames;
+ public:
+ ScTabOpList aTableOpList; // list of ScInterpreterTableOpParams currently in use
+ ScInterpreterTableOpParams aLastTableOpParams; // remember last params
+@@ -434,6 +435,7 @@ public:
+ SfxObjectShell* pDocShell = NULL );
+ ~ScDocument();
+
++ com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > GetPersistedCodeNames() throw( com::sun::star::uno::RuntimeException );
+ inline ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
+ GetServiceManager() const { return xServiceManager; }
+
+diff --git sc/source/core/data/documen2.cxx sc/source/core/data/documen2.cxx
+index e506a03..feb8746 100644
+--- sc/source/core/data/documen2.cxx
++++ sc/source/core/data/documen2.cxx
+@@ -248,6 +248,7 @@ ScDocument::ScDocument( ScDocumentMode e
+
+ aTrackTimer.SetTimeoutHdl( LINK( this, ScDocument, TrackTimeHdl ) );
+ aTrackTimer.SetTimeout( 100 );
++ aDocCodeName = String( RTL_CONSTASCII_USTRINGPARAM("ThisWorkbook") );
+ }
+
+
+diff --git sc/source/core/data/document.cxx sc/source/core/data/document.cxx
+index b123ad7..7ee3b4a 100644
+--- sc/source/core/data/document.cxx
++++ sc/source/core/data/document.cxx
+@@ -91,6 +91,9 @@
+ #include "bcaslot.hxx"
+ #include "postit.hxx"
+ #include "tabprotection.hxx"
++#include <comphelper/processfactory.hxx>
+
-+class SbObjModule : public SbModule
++using namespace ::com::sun::star;
+
+ struct ScDefaultAttr
+ {
+@@ -4830,5 +4833,30 @@ BOOL ScDocument::NeedPageResetAfterTab(
+ return FALSE; // sonst nicht
+ }
+
++uno::Reference< container::XNameAccess >
++ScDocument::GetPersistedCodeNames() throw( uno::RuntimeException )
+{
-+ SbxObjectRef pDocObject; // a excel object.
-+protected:
-+ //virtual ~SbObjModule();
-+ void InitObject( const XubString& rName );
-+ void InitObject( );
-+public:
-+ TYPEINFO();
-+ SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_DOCUMENTMOD,2);
-+ SbObjModule( const String&, StarBASIC* pBasic );
-+ virtual SbxVariable* Find( const XubString& rName, SbxClassType t );
-+ virtual SbxVariable* GetObject();
-+ virtual void SetCodeName( const XubString& rName );
-+};
-+#ifndef __SB_SBOBJMODULEREF_HXX
-+#define __SB_SBOBJMODULEREF_HXX
++ SfxObjectShell* pObjShell = GetDocumentShell();
++ if ( pShell && !mxCodeNames.is() )
++ {
++ uno::Sequence< uno::Any > aArgs( 1 );
++ aArgs[ 0 ] = uno::makeAny( pObjShell->GetModel() );
++ mxCodeNames.set( ::comphelper::getProcessServiceFactory()->createInstanceWithArguments(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.vba.PersistedCodeNames")), aArgs), uno::UNO_QUERY );
++ if ( mxCodeNames.is() )
++ {
++ rtl::OUString sWorkbook( RTL_CONSTASCII_USTRINGPARAM("ThisWorkbook") );
++ if ( mxCodeNames->hasByName( sWorkbook ) )
++ {
++
++ rtl::OUString sCodeName;
++ mxCodeNames->getByName( sWorkbook ) >>= sCodeName;
++ SetCodeName( sCodeName );
++ }
++ }
++ }
++ return mxCodeNames;
++}
+
-+SV_DECL_IMPL_REF(SbObjModule);
+
-+#endif
-+#endif
+
+
+diff --git sc/source/filter/xml/xmlsubti.cxx sc/source/filter/xml/xmlsubti.cxx
+index ab00932..d03592f 100644
+--- sc/source/filter/xml/xmlsubti.cxx
++++ sc/source/filter/xml/xmlsubti.cxx
+@@ -238,6 +238,20 @@ void ScMyTables::NewSheet(const rtl::OUS
+ if ( xNamed.is() )
+ try
+ {
++ ScDocument *pDoc = ScXMLConverter::GetScDocument(rImport.GetModel());
++ if ( pDoc && nCurrentSheet == 0 ) // can it be < 0 ?
++ {
++ uno::Reference< container::XNameAccess > xCodeNames( pDoc->GetPersistedCodeNames() );
++ if( xCodeNames->hasByName( sTableName ) )
++ {
++ rtl::OUString sOUSCodeName;
++ xCodeNames->getByName( sTableName ) >>= sOUSCodeName;
++ rImport.LockSolarMutex();
++ String sCodeName( sOUSCodeName );
++ pDoc->SetCodeName( nCurrentSheet, sCodeName );
++ rImport.UnlockSolarMutex();
++ }
++ }
+ xNamed->setName(sTableName);
+ }
+ catch ( uno::RuntimeException& )
+diff --git sc/source/filter/xml/xmltabi.cxx sc/source/filter/xml/xmltabi.cxx
+diff --git sc/source/ui/docshell/docfunc.cxx sc/source/ui/docshell/docfunc.cxx
+index 105f743..9b1443c 100644
+--- sc/source/ui/docshell/docfunc.cxx
++++ sc/source/ui/docshell/docfunc.cxx
+@@ -2116,8 +2116,11 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
+ ScDocShellModificator aModificator( rDocShell );
+
+ ScDocument* pDoc = rDocShell.GetDocument();
+- StarBASIC* pStarBASIC = rDocShell.GetBasic();
+- BOOL bVbaEnabled = pStarBASIC->isVBAEnabled();
++ // Strange loop, also basic is loaded too early ( InsertTable )
++ // is called via the xml import for sheets in described in odf
++ //StarBASIC* pStarBASIC = rDocShell.GetBasic();
++ StarBASIC* pStarBASIC = NULL;
++ BOOL bVbaEnabled = pStarBASIC ? pStarBASIC->isVBAEnabled() : false;
+ if (bRecord && !pDoc->IsUndoEnabled())
+ bRecord = FALSE;
+ if ( bVbaEnabled )
+@@ -2136,6 +2139,17 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
+ rDocShell.GetUndoManager()->AddUndoAction(
+ new ScUndoInsertTab( &rDocShell, nTab, bAppend, rName));
+ // Views updaten:
++ if ( pDoc )
++ {
++ uno::Reference< container::XNameAccess > xCodeNames( pDoc->GetPersistedCodeNames() );
++ if( xCodeNames->hasByName( rName ) )
++ {
++ rtl::OUString sOUSCodeName;
++ xCodeNames->getByName( rName ) >>= sOUSCodeName;
++ String sCodeName( sOUSCodeName );
++ pDoc->SetCodeName( nTab, sCodeName );
++ }
++ }
+ if( bVbaEnabled )
+ {
+ String sCodeName( rName );
+diff --git sc/source/ui/docshell/docsh.cxx sc/source/ui/docshell/docsh.cxx
+index da54daa..3e3d8cd 100644
+--- sc/source/ui/docshell/docsh.cxx
++++ sc/source/ui/docshell/docsh.cxx
+@@ -516,7 +516,11 @@ sal_uInt16 ScDocShell::GetHiddenInformat
+ void ScDocShell::BeforeXMLLoading()
+ {
+ aDocument.DisableIdle( TRUE );
+-
++ // suppress VBA events when loading the xml
++ uno::Reference< document::XVbaEventsHelper > xEvt( aDocument.GetVbaEventsHelper() );
++ if ( xEvt.is() )
++ xEvt->setIgnoreEvents( sal_True );
++
+ // prevent unnecessary broadcasts and updates
+ DBG_ASSERT(pModificator == NULL, "The Modificator should not exist");
+ pModificator = new ScDocShellModificator( *this );
+@@ -602,6 +606,11 @@ void ScDocShell::AfterXMLLoading(sal_Boo
+ aDocument.SetInsertingFromOtherDoc( FALSE );
+
+ aDocument.SetImportingXML( FALSE );
++ // suppress VBA events when loading the xml
++ uno::Reference< document::XVbaEventsHelper > xEvt( aDocument.GetVbaEventsHelper() );
++ if ( xEvt.is() )
++ xEvt->setIgnoreEvents( sal_False );
++
+ aDocument.EnableUndo( TRUE );
+ bIsEmpty = FALSE;
+
+diff --git sc/source/ui/unoobj/docuno.cxx sc/source/ui/unoobj/docuno.cxx
+index 1dcc337..55e67bd 100644
+--- sc/source/ui/unoobj/docuno.cxx
++++ sc/source/ui/unoobj/docuno.cxx
+@@ -1693,6 +1693,7 @@ uno::Sequence<rtl::OUString> SAL_CALL Sc
+
+ return concatServiceNames( aMyServices, aDrawServices );
+ }
+
---- basic/prj/d.lst.bak 2007-09-05 21:12:53.000000000 +0800
-+++ basic/prj/d.lst 2007-09-05 21:16:18.000000000 +0800
-@@ -27,6 +27,7 @@ mkdir: %_DEST%\inc%_EXT%\basic
-
- ..\inc\basic\sbdef.hxx %_DEST%\inc%_EXT%\basic\sbdef.hxx
- ..\inc\basic\sbmod.hxx %_DEST%\inc%_EXT%\basic\sbmod.hxx
-+..\inc\basic\sbobjmod.hxx %_DEST%\inc%_EXT%\basic\sbobjmod.hxx
- ..\inc\basic\sbjsmod.hxx %_DEST%\inc%_EXT%\basic\sbjsmod.hxx
- ..\inc\basic\sbmeth.hxx %_DEST%\inc%_EXT%\basic\sbmeth.hxx
- ..\inc\basic\sbprop.hxx %_DEST%\inc%_EXT%\basic\sbprop.hxx
---- basctl/source/basicide/basobj2.cxx.bak 2007-09-05 20:38:21.000000000 +0800
-+++ basctl/source/basicide/basobj2.cxx 2007-09-05 21:38:46.000000000 +0800
-@@ -46,6 +46,9 @@
- #ifndef _SBXCLASS_HXX //autogen
- #include <basic/sbx.hxx>
- #endif
-+#ifndef _SB_OBJMOD_HXX
-+#include <basic/sbobjmod.hxx>
-+#endif
- #ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX
- #include <svtools/moduleoptions.hxx>
- #endif
-@@ -245,20 +248,29 @@ bool BasicIDE::RenameModule( Window* pEr
- return false;
- }
+ // XCodeNameQuery
+ rtl::OUString SAL_CALL
+ ScModelObj::getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException )
+@@ -1700,7 +1701,6 @@ ScModelObj::getCodeNameForObject( const
+ rtl::OUString sCodeName;
+ if ( pDocShell )
+ {
+- OSL_TRACE( "*** In ScModelObj::getCodeNameForObject");
+ // need to find the page ( and index ) for this control
+ uno::Reference< drawing::XDrawPagesSupplier > xSupplier( pDocShell->GetModel(), uno::UNO_QUERY_THROW );
+ uno::Reference< container::XIndexAccess > xIndex( xSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
+diff --git sc/source/ui/unoobj/servuno.cxx sc/source/ui/unoobj/servuno.cxx
+index b1a8a85..33a6dcd 100644
+--- sc/source/ui/unoobj/servuno.cxx
++++ sc/source/ui/unoobj/servuno.cxx
+@@ -63,7 +63,6 @@
+ #include <svx/xmlgrhlp.hxx>
-- if ( !rDocument.renameModule( rLibName, rOldName, rNewName ) )
-- return false;
+ #include <comphelper/processfactory.hxx>
-
- BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
- if ( pIDEShell )
- {
- IDEBaseWindow* pWin = pIDEShell->FindWindow( rDocument, rLibName, rOldName, BASICIDE_TYPE_MODULE, FALSE );
- if ( pWin )
- {
-+ ModulWindow* pModWin = (ModulWindow*)pWin;
-+ // Object Module
-+ SbModule* pMod = pModWin->GetBasic()->FindModule( rOldName );
-+ SbObjModule* pObjMod = dynamic_cast< SbObjModule* > (pMod);
-+ if ( pObjMod != NULL )
-+ pObjMod->SetCodeName( rNewName );
-+ if ( !rDocument.renameModule( rLibName, rOldName, rNewName ) )
+ using namespace ::com::sun::star;
+
+ class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
+@@ -89,6 +88,32 @@ public:
+ maWorkbook <<= mxSF->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.excel.Workbook") ), aArgs );
+ }
+ }
++ virtual void SAL_CALL bindCodeName( const ::rtl::OUString& codename, const ::rtl::OUString& objectname ) throw (::com::sun::star::uno::RuntimeException)
++ {
++ ScDocument* pDoc = mpDocShell->GetDocument();
++ String sObjName( objectname );
++ String sCodeName( codename );
++ if ( pDoc )
++ {
++ if ( sObjName == String( RTL_CONSTASCII_USTRINGPARAM("ThisWorkbook") ) )
++ pDoc->SetCodeName( sCodeName );
++ else
+ {
-+ if ( pObjMod != NULL )
-+ pObjMod->SetCodeName( rOldName );
-+ return false;
++ String sSheetObjName;
++ SCTAB nCount = pDoc->GetTableCount();
++ for( SCTAB i = 0; i < nCount; i++ )
++ {
++ pDoc->GetName( i, sSheetObjName );
++ if ( sObjName == sSheetObjName )
++ {
++ pDoc->SetCodeName( i, sCodeName );
++ break;
++ }
++ }
+ }
++ }
++
++ }
+
+ virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
+ {
+diff --git sc/source/ui/vba/vbaeventshelper.cxx sc/source/ui/vba/vbaeventshelper.cxx
+index 6c11c73..31664d0 100644
+--- sc/source/ui/vba/vbaeventshelper.cxx
++++ sc/source/ui/vba/vbaeventshelper.cxx
+@@ -307,7 +307,7 @@ void ImplVbaEventNameInfo::InitImplVbaEv
+ }
+
+ ScVbaEventsHelper::ScVbaEventsHelper( uno::Sequence< css::uno::Any > const& aArgs, uno::Reference< uno::XComponentContext > const& xContext )
+- : m_xContext( xContext ), mpWindowListener( NULL ), mbOpened( sal_False )
++ : m_xContext( xContext ), mpWindowListener( NULL ), mbOpened( sal_False ), mbIgnoreEvents( sal_False )
+ {
+ OSL_TRACE( "ScVbaEventsHelper::ScVbaEventsHelper" );
+ uno::Reference< frame::XModel > xModel ( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ), uno::UNO_QUERY );
+@@ -524,7 +524,7 @@ String ScVbaEventsHelper::getSheetModule
+ {
+ ScExtDocOptions* pExtOptions = pDoc->GetExtDocOptions();
+ String aCodeName;
+- pDoc->GetName( nTab, aCodeName);
++ pDoc->GetCodeName( nTab, aCodeName);
+ // Use code name if that exists
+ if ( pExtOptions )
+ aCodeName = pExtOptions->GetCodeName( nTab );
+@@ -580,17 +580,14 @@ ScVbaEventsHelper::getMacroPath( const s
+ case VBAEVENT_WORKBOOK_SHEET_SELECTIONCHANGE :
+ {
+ ScExtDocOptions* pExtOptions = pDoc->GetExtDocOptions();
++ String sWorkbookModuleName = pDoc->GetCodeName();
+ if( pExtOptions )
+ {
+ ScExtDocSettings aExtDocSettings = pExtOptions->GetDocSettings();
+ String sWorkbookModuleName = aExtDocSettings.maGlobCodeName;
+- sMacroPath = workbookMacroExists( pShell, sWorkbookModuleName, sMacroName );
+- }
+- else
+- {
+- // TODO need this?
+- sMacroPath = workbookMacroExists( pShell, rtl::OUString(), sMacroName );
+ }
++
++ sMacroPath = workbookMacroExists( pShell, sWorkbookModuleName, sMacroName );
+ break;
+ }
+ default:
+@@ -793,11 +790,28 @@ ScVbaEventsHelper::getTabFromArgs( const
+ return nTab;
+ }
+
++::sal_Bool SAL_CALL
++ScVbaEventsHelper::getIgnoreEvents() throw (uno::RuntimeException)
++{
++ return mbIgnoreEvents;
++}
+
- // set new name in window
- pWin->SetName( rNewName );
++void SAL_CALL
++ScVbaEventsHelper::setIgnoreEvents( ::sal_Bool _ignoreevents ) throw (uno::RuntimeException)
++{
++ mbIgnoreEvents = _ignoreevents;
++}
++
+ #define INVALID_TAB -1
+
+ sal_Bool SAL_CALL
+ ScVbaEventsHelper::ProcessCompatibleVbaEvent( sal_Int32 VbaEvent, const uno::Sequence< uno::Any >& aArgs ) throw (uno::RuntimeException)
+ {
++ if ( mbIgnoreEvents )
++ {
++ OSL_TRACE("** Ignoring event %s [%d]", rtl::OUStringToOString( GetEventName( VbaEvent ), RTL_TEXTENCODING_UTF8 ).getStr(), VbaEvent );
++ return sal_False; // return True or False, to me returning False sorta makes sense but...
++ }
+ SfxObjectShell* pShell = pDoc->GetDocumentShell();
+ if( !pShell )
+ return sal_False;
+@@ -966,13 +980,12 @@ ScVbaEventsHelper::ProcessCompatibleVbaE
+ {
+ // if workbook open event do not be fired. fired it before
+ // workbook activate event to compatible with MSO.
+- if( !mbOpened )
++ if( mbOpened )
+ {
+- ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_OPEN, aArgs );
++ processVbaEventMacro_noreturn( VBAEVENT_WORKBOOK_ACTIVATE );
++ // workbook window activate event same as this one
++ ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_WINDOWACTIVATE, aArgs );
+ }
+- processVbaEventMacro_noreturn( VBAEVENT_WORKBOOK_ACTIVATE );
+- // workbook window activate event same as this one
+- ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_WINDOWACTIVATE, aArgs );
+ break;
+ }
+ case VBAEVENT_WORKBOOK_DEACTIVATE :
+@@ -991,6 +1004,7 @@ ScVbaEventsHelper::ProcessCompatibleVbaE
+ {
+ processVbaEventMacro_noreturn( VBAEVENT_WORKBOOK_OPEN );
+ mbOpened = sal_True;
++ ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_ACTIVATE, aArgs );
+ }
+ // register the window listener.
+ if( !mpWindowListener )
+diff --git sc/source/ui/vba/vbaeventshelper.hxx sc/source/ui/vba/vbaeventshelper.hxx
+index fe556be..4ac8b76 100644
+--- sc/source/ui/vba/vbaeventshelper.hxx
++++ sc/source/ui/vba/vbaeventshelper.hxx
+@@ -44,7 +44,6 @@
+ #include <com/sun/star/document/XVbaEventsHelper.hpp>
+ #include "vbahelper.hxx"
+
+-using namespace com::sun::star;
+
+ typedef ::cppu::WeakImplHelper1< com::sun::star::document::XVbaEventsHelper > VBAWorkbookEvent_BASE;
+
+@@ -59,21 +58,21 @@ private:
+ css::uno::Reference< css::uno::XComponentContext > m_xContext;
+ VbaWindowListener* mpWindowListener;
+ sal_Bool mbOpened;
+-
++ sal_Bool mbIgnoreEvents;
+ String getSheetModuleName( SCTAB nTab );
+ String workbookMacroExists( SfxObjectShell* pShell, const String& sMod, const String& sMacro );
+
+- uno::Any createWorkSheet( SfxObjectShell* pShell, SCTAB nTab );
+- uno::Any createRange( const uno::Any& aRange );
+- uno::Any createHyperlink( const uno::Any& rCell );
+- uno::Any createWindow( SfxObjectShell* pShell );
+- sal_Bool executeWorkBookMacro( SfxObjectShell* pShell, const String& sMacroName, uno::Sequence< uno::Any >& aArgs, uno::Any& aRet );
++ css::uno::Any createWorkSheet( SfxObjectShell* pShell, SCTAB nTab );
++ css::uno::Any createRange( const css::uno::Any& aRange );
++ css::uno::Any createHyperlink( const css::uno::Any& rCell );
++ css::uno::Any createWindow( SfxObjectShell* pShell );
++ sal_Bool executeWorkBookMacro( SfxObjectShell* pShell, const String& sMacroName, css::uno::Sequence< css::uno::Any >& aArgs, css::uno::Any& aRet );
+ sal_Bool processVbaEventWithCancel( const sal_Int32 nEventId );
+ sal_Bool processDocBeforeSaveMacro( sal_Bool bSaveAsUI );
+ void processVbaEventMacro_noreturn( const sal_Int32 nEventId );
+- void processVbaEventMacroWithArgs( const sal_Int32 nEventId, uno::Sequence< uno::Any >& rArgs );
++ void processVbaEventMacroWithArgs( const sal_Int32 nEventId, css::uno::Sequence< css::uno::Any >& rArgs );
+ void WorkbookWindowMacro( const sal_Int32 nHint );
+- SCTAB getTabFromArgs( const uno::Sequence< uno::Any > aArgs, const sal_Int32 nPos );
++ SCTAB getTabFromArgs( const css::uno::Sequence< css::uno::Any > aArgs, const sal_Int32 nPos );
+ protected:
+ rtl::OUString GetEventName( const sal_Int32 nId );
+ rtl::OUString getMacroPath( const sal_Int32 nEventId, const SCTAB nTab );
+@@ -83,9 +82,11 @@ public:
+ ScVbaEventsHelper( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext > const& xContext );
+ ~ScVbaEventsHelper();
+ ScDocument* getDocument() { return pDoc; };
+- sal_Bool executeSheetMacro( USHORT nEvent, SCTAB nTab, uno::Sequence< uno::Any >& rArgs );
++ sal_Bool executeSheetMacro( USHORT nEvent, SCTAB nTab, css::uno::Sequence< css::uno::Any >& rArgs );
+ // XVBAWorkbookEventHelper
+- virtual sal_Bool SAL_CALL ProcessCompatibleVbaEvent( sal_Int32 VbaEvent, const uno::Sequence< uno::Any >& aArgs ) throw (uno::RuntimeException);
++ virtual ::sal_Bool SAL_CALL getIgnoreEvents() throw (css::uno::RuntimeException);
++ virtual void SAL_CALL setIgnoreEvents( ::sal_Bool _ignoreevents ) throw (css::uno::RuntimeException);
++ virtual sal_Bool SAL_CALL ProcessCompatibleVbaEvent( sal_Int32 VbaEvent, const css::uno::Sequence< css::uno::Any >& aArgs ) throw (css::uno::RuntimeException);
+ };
- // set new module in module window
-- ModulWindow* pModWin = (ModulWindow*)pWin;
- pModWin->SetSbModule( (SbModule*)pModWin->GetBasic()->FindModule( rNewName ) );
-
- // update tabwriter
---- basic/source/runtime/methods1.cxx.bak 2007-09-06 11:44:25.000000000 +0800
-+++ basic/source/runtime/methods1.cxx 2007-09-05 21:23:47.000000000 +0800
-@@ -60,6 +60,9 @@
- #ifndef _SBX_HXX
- #include <basic/sbx.hxx>
- #endif
-+#ifndef _SBSTAR_HXX
-+#include <basic/sbstar.hxx>
-+#endif
- #ifndef _ZFORLIST_HXX //autogen
- #include <svtools/zforlist.hxx>
#endif
-@@ -81,6 +84,7 @@
+diff --git svx/source/msfilter/svxmsbas.cxx svx/source/msfilter/svxmsbas.cxx
+index e647cf8..d78c1e4 100644
+--- svx/source/msfilter/svxmsbas.cxx
++++ svx/source/msfilter/svxmsbas.cxx
+@@ -403,20 +403,23 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
- #include <vcl/jobset.hxx>
+ Any aSourceAny;
+ OSL_TRACE("erm %d", mType );
+- if ( xVBAObjectForCodeName.is() && ( mType == ModuleType::Document || mType == ModuleType::Class || mType == ModuleType::Form ) )
++ 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::Form )
++// ok, try always passing the model to basic, should fit
++// 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
+diff --git xmlscript/inc/xmlscript/xmllib_imexp.hxx xmlscript/inc/xmlscript/xmllib_imexp.hxx
+index 9a3048f..81d8d43 100644
+--- xmlscript/inc/xmlscript/xmllib_imexp.hxx
++++ xmlscript/inc/xmlscript/xmllib_imexp.hxx
+@@ -34,11 +34,21 @@
+ #include <com/sun/star/uno/Sequence.hxx>
-+#include <basic/sbobjmod.hxx>
- #include "sbintern.hxx"
- #include "runtime.hxx"
- #include "stdobj.hxx"
-@@ -2605,7 +2609,14 @@ RTLFUNC(Me)
- SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pActiveModule);
- if( pClassModuleObject == NULL )
- {
-- StarBASIC::Error( SbERR_INVALID_USAGE_OBJECT );
-+ SbObjModule* pMod = PTR_CAST(SbObjModule,pActiveModule);
-+ if ( pMod == NULL )
-+ StarBASIC::Error( SbERR_INVALID_USAGE_OBJECT );
-+ else
-+ {
-+ SbxVariableRef refVar = rPar.Get(0);
-+ refVar->PutObject( pMod->GetObject() );
-+ }
- }
- else
- {
+ #include "xmlscript/xmlns.h"
+-
++#include <hash_map>
++#include <com/sun/star/script/ModuleType.hpp>
+
+ namespace xmlscript
+ {
++struct ObjectModuleDesc
++{
++ rtl::OUString msObjectName;
++ sal_Int32 mnModuleType;
++ObjectModuleDesc() : mnModuleType( ::com::sun::star::script::ModuleType::Normal ) {}
++};
+
++typedef std::hash_map< rtl::OUString,
++ObjectModuleDesc, ::rtl::OUStringHash,
++::std::equal_to< ::rtl::OUString > > ObjectModuleDescHash;
+ //==============================================================================
+ // Library container export
+ // HACK C++ struct to transport info. Later the container
+@@ -53,14 +63,19 @@ struct LibDescriptor
+ sal_Bool bPasswordProtected;
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > aElementNames;
+ sal_Bool bPreload;
++ ObjectModuleDescHash hCodeNameToObjDesc;
+ };
+
++typedef std::hash_map< rtl::OUString, rtl::OUString, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > CodeNameHash;
++
+ struct LibDescriptorArray
+ {
+ LibDescriptor* mpLibs;
+ sal_Int32 mnLibCount;
+
+- LibDescriptorArray( void ) { mpLibs = NULL; mnLibCount = 0; }
++ CodeNameHash mCodeNames;
++ bool mbVBAMode;
++ LibDescriptorArray( void ) { mpLibs = NULL; mnLibCount = 0; mbVBAMode = false; }
+ LibDescriptorArray( sal_Int32 nLibCount );
+
+ ~LibDescriptorArray();
+@@ -79,6 +94,11 @@ SAL_CALL exportLibraryContainer(
+ SAL_CALL importLibraryContainer( LibDescriptorArray* pLibArray )
+ SAL_THROW( (::com::sun::star::uno::Exception) );
+
++::com::sun::star::uno::Reference<
++ ::com::sun::star::xml::sax::XDocumentHandler >
++SAL_CALL importLibraryCodeNames( LibDescriptorArray* pLibArray )
++ SAL_THROW( (::com::sun::star::uno::Exception) );
++
+
+ void
+ SAL_CALL exportLibrary(
+diff --git xmlscript/source/xmllib_imexp/imp_share.hxx xmlscript/source/xmllib_imexp/imp_share.hxx
+index d602103..fdc0536 100644
+--- xmlscript/source/xmllib_imexp/imp_share.hxx
++++ xmlscript/source/xmllib_imexp/imp_share.hxx
+@@ -220,7 +220,6 @@ class LibrariesElement : public LibEleme
+
+ protected:
+ vector< LibDescriptor > mLibDescriptors;
+-
+ public:
+ virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
+ sal_Int32 nUid, OUString const & rLocalName,
+@@ -244,7 +243,7 @@ class LibraryElement : public LibElement
+ {
+ protected:
+ vector< OUString > mElements;
+-
++ ObjectModuleDescHash mObjectDescs;
+ public:
+
+ virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
+diff --git xmlscript/source/xmllib_imexp/xmllib_import.cxx xmlscript/source/xmllib_imexp/xmllib_import.cxx
+index b533d37..b04fb4e 100644
+--- xmlscript/source/xmllib_imexp/xmllib_import.cxx
++++ xmlscript/source/xmllib_imexp/xmllib_import.cxx
+@@ -44,7 +44,20 @@ namespace xmlscript
+ {
+
+ //##################################################################################################
+-
++sal_Int32 lcl_getModuleTypeForStringType( const rtl::OUString& rsType )
++{
++ // default to normal unknown
++ sal_Int32 nType = com::sun::star::script::ModuleType::Unknown;
++ if ( rsType.equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("class") ) ) )
++ nType = com::sun::star::script::ModuleType::Class;
++ else if ( rsType.equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("form") ) ) )
++ nType = com::sun::star::script::ModuleType::Form;
++ else if ( rsType.equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("document") ) ) )
++ nType = com::sun::star::script::ModuleType::Document;
++ else if ( rsType.equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("normal") ) ) )
++ nType = com::sun::star::script::ModuleType::Normal;
++ return nType;
++}
+ //__________________________________________________________________________________________________
+ Reference< xml::input::XElement > LibElementBase::getParent()
+ throw (RuntimeException)
+@@ -185,6 +198,13 @@ Reference< xml::input::XElement > Librar
+ }
+ else if (mpLibArray && rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("libraries") ))
+ {
++ rtl::OUString sVbaCompatMode;
++ sVbaCompatMode = xAttributes->getValueByUidName(
++ XMLNS_LIBRARY_UID,
++ OUString( RTL_CONSTASCII_USTRINGPARAM("vbaenabled") ) );
++
++ if ( sVbaCompatMode.equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("true") ) ) )
++ mpLibArray->mbVBAMode = true;
+ return new LibrariesElement( rLocalName, xAttributes, 0, this );
+ }
+ else if (mpLibDesc && rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("library") ))
+@@ -269,6 +289,19 @@ Reference< xml::input::XElement > Librar
+ mLibDescriptors.push_back( aDesc );
+ return new LibraryElement( rLocalName, xAttributes, this, _pImport );
+ }
++ // CodeNames are only relevant for the container ( e.g. the document )
++ else if (rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("codename") ))
++ {
++ rtl::OUString sCodeName = xAttributes->getValueByUidName(
++ _pImport->XMLNS_LIBRARY_UID,
++ OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) );
++ rtl::OUString sObjectName = xAttributes->getValueByUidName(
++ _pImport->XMLNS_LIBRARY_UID,
++ OUString( RTL_CONSTASCII_USTRINGPARAM("objectname") ) );
++ if ( ( sCodeName.getLength() > 0 ) && ( sObjectName.getLength() > 0 ) )
++ _pImport->mpLibArray->mCodeNames[ sObjectName ] = sCodeName;
++ return new LibElementBase( rLocalName, xAttributes, this, _pImport );
++ }
+ else
+ {
+ throw xml::sax::SAXException(
+@@ -311,7 +344,13 @@ Reference< xml::input::XElement > Librar
+ OUString( RTL_CONSTASCII_USTRINGPARAM("name") ) ) );
+ if (aValue.getLength())
+ mElements.push_back( aValue );
+-
++ ObjectModuleDesc aDesc;
++ aDesc.mnModuleType = lcl_getModuleTypeForStringType(
++ xAttributes->getValueByUidName(
++ _pImport->XMLNS_LIBRARY_UID,
++ OUString( RTL_CONSTASCII_USTRINGPARAM("moduletype") ) ) );
++ if ( aValue.getLength() && aDesc.mnModuleType != ::com::sun::star::script::ModuleType::Unknown )
++ mObjectDescs[ aValue ] = aDesc;
+ return new LibElementBase( rLocalName, xAttributes, this, _pImport );
+ }
+ else
+@@ -335,6 +374,7 @@ void LibraryElement::endElement()
+ if( !pLib )
+ pLib = &static_cast< LibrariesElement* >( _pParent )->mLibDescriptors.back();
+ pLib->aElementNames = aElementNames;
++ pLib->hCodeNameToObjDesc = mObjectDescs;
+ }
+
+
+@@ -348,6 +388,16 @@ SAL_CALL importLibraryContainer( LibDesc
+ static_cast< xml::input::XRoot * >( new LibraryImport( pLibArray ) ) );
+ }
+
++
++Reference< ::com::sun::star::xml::sax::XDocumentHandler >
++SAL_CALL importLibraryCodeNames( LibDescriptorArray* pLibArray )
++ SAL_THROW( (Exception) )
++{
++ return ::xmlscript::createDocumentHandler(
++ static_cast< xml::input::XRoot * >( new LibraryImport( pLibArray ) ) );
++}
++
++
+ //##################################################################################################
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >
+@@ -365,6 +415,7 @@ LibDescriptorArray::LibDescriptorArray(
+ {
+ mnLibCount = nLibCount;
+ mpLibs = new LibDescriptor[ mnLibCount ];
++ mbVBAMode = false;
+ }
+
+ LibDescriptorArray::~LibDescriptorArray()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]