summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornpower Developer <npower@openoffice.org>2010-03-02 12:39:31 +0000
committernpower Developer <npower@openoffice.org>2010-03-02 12:39:31 +0000
commitaac4d6a3a645d3c11e4094a2c5ca701810e6df07 (patch)
tree99c918949a02183882d34bef43fffeddb2c03ab2
parent22e99ad710239c0604f883f303d91b8c43a71f16 (diff)
npower13_objectmodule: #i109734# object module stuff
-rw-r--r--sc/inc/document.hxx2
-rw-r--r--sc/inc/servuno.hxx5
-rw-r--r--sc/source/core/data/documen2.cxx37
-rw-r--r--sc/source/core/data/document.cxx12
-rw-r--r--sc/source/filter/excel/excimp8.cxx9
-rw-r--r--sc/source/filter/excel/read.cxx2
-rw-r--r--sc/source/ui/docshell/docfunc.cxx139
-rw-r--r--sc/source/ui/docshell/docsh5.cxx40
-rw-r--r--sc/source/ui/unoobj/servuno.cxx123
-rw-r--r--sc/source/ui/view/viewfun2.cxx17
10 files changed, 376 insertions, 10 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 44bda96f8322..48b98a7551af 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1716,6 +1716,8 @@ public:
{ return eStorageGrammar; }
SfxUndoManager* GetUndoManager();
+ bool IsInVBAMode() const;
+
private: // CLOOK-Impl-Methoden
/**
diff --git a/sc/inc/servuno.hxx b/sc/inc/servuno.hxx
index 785e5e4049d0..a8159da5158f 100644
--- a/sc/inc/servuno.hxx
+++ b/sc/inc/servuno.hxx
@@ -90,9 +90,10 @@ class ScDocShell;
#define SC_SERVICE_FORMULAPARS 38
#define SC_SERVICE_OPCODEMAPPER 39
-#define SC_SERVICE_VBACODENAMEPROVIDER 40
+#define SC_SERVICE_VBAOBJECTPROVIDER 40
+#define SC_SERVICE_VBACODENAMEPROVIDER 41
-#define SC_SERVICE_COUNT 41
+#define SC_SERVICE_COUNT 42
#define SC_SERVICE_INVALID USHRT_MAX
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index c08fb7a10228..ce3bf4df3490 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -93,6 +93,7 @@
#include "tabprotection.hxx"
#include "formulaparserpool.hxx"
#include "clipparam.hxx"
+#include <basic/basmgr.hxx>
// pImpl because including lookupcache.hxx in document.hxx isn't wanted, and
// dtor plus helpers are convenient.
@@ -934,6 +935,8 @@ BOOL ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
return bValid;
}
+void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, String& sModuleName, String& sModuleSource );
+
ULONG ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
SCTAB nDestPos, BOOL bInsertNew,
BOOL bResultsOnly )
@@ -1104,6 +1107,40 @@ ULONG ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
}
if (!bValid)
nRetVal = 0;
+ SfxObjectShell* pDestShell = pSrcDoc ? pSrcDoc->GetDocumentShell() : NULL;
+ StarBASIC* pStarBASIC = pDestShell ? pDestShell->GetBasic() : NULL;
+ String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
+ if ( pDestShell && pDestShell->GetBasicManager()->GetName().Len() > 0 )
+ {
+ aLibName = pDestShell->GetBasicManager()->GetName();
+ pStarBASIC = pDestShell->GetBasicManager()->GetLib( aLibName );
+ }
+
+ BOOL bVbaEnabled = IsInVBAMode();
+
+ if ( bVbaEnabled && pDestShell )
+ {
+ String sCodeName;
+ String sSource;
+ com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibContainer = pDestShell->GetBasicContainer();
+ com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xLib;
+ if( xLibContainer.is() )
+ {
+ com::sun::star::uno::Any aLibAny = xLibContainer->getByName( aLibName );
+ aLibAny >>= xLib;
+ }
+
+ if( xLib.is() )
+ {
+ String sSrcCodeName;
+ pSrcDoc->GetCodeName( nSrcPos, sSrcCodeName );
+ rtl::OUString sRTLSource;
+ xLib->getByName( sSrcCodeName ) >>= sRTLSource;
+ sSource = sRTLSource;
+ }
+ VBA_InsertModule( *this, nDestPos, sCodeName, sSource );
+ }
+
return nRetVal;
}
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index fa4fb296d9a7..3424df4824af 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -51,6 +51,7 @@
#include <tools/tenccvt.hxx>
#include <com/sun/star/text/WritingMode2.hpp>
+#include <com/sun/star/script/XVBACompat.hpp>
#include "document.hxx"
#include "table.hxx"
@@ -4963,4 +4964,13 @@ void ScDocument::EnableUndo( bool bVal )
mbUndoEnabled = bVal;
}
-
+bool ScDocument::IsInVBAMode() const
+{
+ bool bResult = false;
+ if ( pShell )
+ {
+ com::sun::star::uno::Reference< com::sun::star::script::XVBACompat > xVBA( pShell->GetBasicContainer(), com::sun::star::uno::UNO_QUERY );
+ bResult = xVBA->getVBACompatModeOn();
+ }
+ return bResult;
+}
diff --git a/sc/source/filter/excel/excimp8.cxx b/sc/source/filter/excel/excimp8.cxx
index e424ad2d95fe..19df7c2520c1 100644
--- a/sc/source/filter/excel/excimp8.cxx
+++ b/sc/source/filter/excel/excimp8.cxx
@@ -104,7 +104,6 @@
#include <com/sun/star/container/XNameContainer.hpp>
#include <sfx2/app.hxx>
-
using namespace com::sun::star;
@@ -257,8 +256,6 @@ void ImportExcel8::SheetProtection( void )
void ImportExcel8::ReadBasic( void )
{
- bHasBasic = TRUE;
-
SfxObjectShell* pShell = GetDocShell();
SotStorageRef xRootStrg = GetRootStorage();
SvtFilterOptions* pFilterOpt = SvtFilterOptions::Get();
@@ -271,7 +268,7 @@ void ImportExcel8::ReadBasic( void )
{
SvxImportMSVBasic aBasicImport( *pShell, *xRootStrg, bLoadCode, bLoadStrg );
bool bAsComment = !bLoadExecutable;
- aBasicImport.Import( EXC_STORAGE_VBA_PROJECT, EXC_STORAGE_VBA, bAsComment );
+ aBasicImport.Import( EXC_STORAGE_VBA_PROJECT, EXC_STORAGE_VBA, bAsComment );
}
}
}
@@ -286,6 +283,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 a/sc/source/filter/excel/read.cxx b/sc/source/filter/excel/read.cxx
index 91b749030dd7..9c99c9a0a6c6 100644
--- a/sc/source/filter/excel/read.cxx
+++ b/sc/source/filter/excel/read.cxx
@@ -983,7 +983,7 @@ 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: bHasBasic = true; break;
case 0xDE: Olesize(); break;
case 0x01BA: Codename( TRUE ); break;
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index cd28daa99401..3b735c061cab 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -48,6 +48,12 @@
#include <svl/zforlist.hxx>
#include <svl/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/XVBAModuleInfo.hpp>
+#include <com/sun/star/script/ModuleType.hpp>
+
#include <list>
#include "docfunc.hxx"
@@ -94,6 +100,7 @@
#include "clipparam.hxx"
#include <memory>
+#include <basic/basmgr.hxx>
using namespace com::sun::star;
using ::com::sun::star::uno::Sequence;
@@ -2576,6 +2583,106 @@ BOOL ScDocFunc::MoveBlock( const ScRange& rSource, const ScAddress& rDestPos,
}
//------------------------------------------------------------------------
+uno::Reference< uno::XInterface > GetDocModuleObject( SfxObjectShell& rDocSh, String& sCodeName )
+{
+ uno::Reference< lang::XMultiServiceFactory> xSF(rDocSh.GetModel(), uno::UNO_QUERY);
+ uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess;
+ uno::Reference< uno::XInterface > xDocModuleApiObject;
+ if ( xSF.is() )
+ {
+ xVBACodeNamedObjectAccess.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY );
+ xDocModuleApiObject.set( xVBACodeNamedObjectAccess->getByName( sCodeName ), uno::UNO_QUERY );
+ }
+ return xDocModuleApiObject;
+
+}
+
+script::ModuleInfo lcl_InitModuleInfo( SfxObjectShell& rDocSh, String& sModule )
+{
+ ::rtl::OUString sVbaOption( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=VBADocumentModule\nOption VBASupport 1\n" ));
+ script::ModuleInfo sModuleInfo;
+ sModuleInfo.ModuleType = script::ModuleType::Document;
+ sModuleInfo.ModuleObject = GetDocModuleObject( rDocSh, sModule );
+ return sModuleInfo;
+}
+
+void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, String& sModuleName, String& sSource )
+{
+ SFX_APP()->EnterBasicCall();
+ SfxObjectShell& rDocSh = *rDoc.GetDocumentShell();
+ 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" ) );
+ if ( rDocSh.GetBasicManager() && rDocSh.GetBasicManager()->GetName().Len() )
+ aLibName = rDocSh.GetBasicManager()->GetName();
+ uno::Any aLibAny = xLibContainer->getByName( aLibName );
+ aLibAny >>= xLib;
+ }
+ if( xLib.is() )
+ {
+ // if the Module with codename exists then find a new name
+ sal_Int32 nNum = 0;
+ String genModuleName;
+ if ( sModuleName.Len() )
+ sModuleName = sModuleName;
+ else
+ {
+ genModuleName = String::CreateFromAscii( "Sheet1" );
+ nNum = 1;
+ }
+ while( xLib->hasByName( genModuleName ) )
+ genModuleName = rtl::OUString::createFromAscii( "Sheet" ) + rtl::OUString::valueOf( ++nNum );
+
+ uno::Any aSourceAny;
+ rtl::OUString sTmpSource = sSource;
+ if ( sTmpSource.getLength() == 0 )
+ sTmpSource = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=VBADocumentModule\nOption VBASupport 1\n" ));
+ aSourceAny <<= sTmpSource;
+ uno::Reference< script::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY );
+ if ( xVBAModuleInfo.is() )
+ {
+ String sCodeName( genModuleName );
+ rDoc.SetCodeName( nTab, sCodeName );
+ script::ModuleInfo sModuleInfo = lcl_InitModuleInfo( rDocSh, genModuleName );
+ xVBAModuleInfo->insertModuleInfo( genModuleName, sModuleInfo );
+ xLib->insertByName( genModuleName, aSourceAny );
+ }
+
+ }
+ SFX_APP()->LeaveBasicCall();
+}
+
+void VBA_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" ) );
+ if ( rDocSh.GetBasicManager() && rDocSh.GetBasicManager()->GetName().Len() )
+ aLibName = rDocSh.GetBasicManager()->GetName();
+ uno::Any aLibAny = xLibContainer->getByName( aLibName );
+ aLibAny >>= xLib;
+ }
+ if( xLib.is() )
+ {
+ uno::Reference< script::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY );
+ if( xLib->hasByName( sModuleName ) )
+ xLib->removeByName( sModuleName );
+ if ( xVBAModuleInfo.is() )
+ xVBAModuleInfo->removeModuleInfo( sModuleName );
+
+ }
+ SFX_APP()->LeaveBasicCall();
+}
+
BOOL ScDocFunc::InsertTable( SCTAB nTab, const String& rName, BOOL bRecord, BOOL bApi )
{
@@ -2585,8 +2692,19 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab, const String& rName, BOOL bRecord, BOOL
ScDocShellModificator aModificator( rDocShell );
ScDocument* pDoc = rDocShell.GetDocument();
- if (bRecord && !pDoc->IsUndoEnabled())
+
+
+ // Strange loop, also basic is loaded too early ( InsertTable )
+ // is called via the xml import for sheets in described in odf
+ BOOL bInsertDocModule = false;
+
+ if( !rDocShell.GetDocument()->IsImportingXML() )
+ {
+ bInsertDocModule = pDoc ? pDoc->IsInVBAMode() : false;
+ }
+ if ( bInsertDocModule || ( bRecord && !pDoc->IsUndoEnabled() ) )
bRecord = FALSE;
+
if (bRecord)
pDoc->BeginDrawUndo(); // InsertTab erzeugt ein SdrUndoNewPage
@@ -2597,10 +2715,17 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab, const String& rName, BOOL bRecord, BOOL
if (pDoc->InsertTab( nTab, rName ))
{
+ String sCodeName;
if (bRecord)
rDocShell.GetUndoManager()->AddUndoAction(
new ScUndoInsertTab( &rDocShell, nTab, bAppend, rName));
// Views updaten:
+ // Only insert vba modules if vba mode ( and not currently importing XML )
+ if( bInsertDocModule )
+ {
+ String sSource;
+ VBA_InsertModule( *pDoc, nTab, sCodeName, sSource );
+ }
rDocShell.Broadcast( ScTablesHint( SC_TAB_INSERTED, nTab ) );
rDocShell.PostPaintExtras();
@@ -2622,8 +2747,11 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab, BOOL bRecord, BOOL /* bApi */ )
BOOL bSuccess = FALSE;
ScDocument* pDoc = rDocShell.GetDocument();
+ BOOL bVbaEnabled = pDoc ? pDoc->IsInVBAMode() : false;
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = FALSE;
+ if ( bVbaEnabled )
+ bRecord = FALSE;
BOOL bWasLinked = pDoc->IsLinked(nTab);
ScDocument* pUndoDoc = NULL;
ScRefUndoData* pUndoData = NULL;
@@ -2664,6 +2792,8 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab, BOOL bRecord, BOOL /* bApi */ )
pUndoData = new ScRefUndoData( pDoc );
}
+ String sCodeName;
+ BOOL bHasCodeName = pDoc->GetCodeName( nTab, sCodeName );
if (pDoc->DeleteTab( nTab, pUndoDoc ))
{
if (bRecord)
@@ -2674,6 +2804,13 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab, BOOL bRecord, BOOL /* bApi */ )
new ScUndoDeleteTab( &rDocShell, theTabs, pUndoDoc, pUndoData ));
}
// Views updaten:
+ if( bVbaEnabled )
+ {
+ if( bHasCodeName )
+ {
+ VBA_DeleteModule( rDocShell, sCodeName );
+ }
+ }
rDocShell.Broadcast( ScTablesHint( SC_TAB_DELETED, nTab ) );
if (bWasLinked)
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index 6fa6a5ac7863..06d7cab0d14d 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -65,6 +65,11 @@
#include "sc.hrc"
#include "waitoff.hxx"
#include "sizedev.hxx"
+#include <basic/sbstar.hxx>
+#include <basic/basmgr.hxx>
+
+// defined in docfunc.cxx
+void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, String& sModuleName, String& sModuleSource );
// ---------------------------------------------------------------------------
@@ -846,6 +851,8 @@ BOOL ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, BOOL bCopy, BOOL bRec
if (bRecord)
aDocument.BeginDrawUndo(); // drawing layer must do its own undo actions
+ String sSrcCodeName;
+ aDocument.GetCodeName( nSrcTab, sSrcCodeName );
if (!aDocument.CopyTab( nSrcTab, nDestTab ))
{
//! EndDrawUndo?
@@ -869,6 +876,39 @@ BOOL ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, BOOL bCopy, BOOL bRec
GetUndoManager()->AddUndoAction(
new ScUndoCopyTab( this, aSrcList, aDestList ) );
}
+
+ StarBASIC* pStarBASIC = GetBasic();
+ String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
+ if ( GetBasicManager()->GetName().Len() > 0 )
+ {
+ aLibName = GetBasicManager()->GetName();
+ pStarBASIC = GetBasicManager()->GetLib( aLibName );
+ }
+ BOOL bVbaEnabled = aDocument.IsInVBAMode();
+ SCTAB nTabToUse = nDestTab;
+
+ if ( nDestTab == SC_TAB_APPEND )
+ nTabToUse = aDocument.GetMaxTableNumber() - 1;
+
+ if ( bVbaEnabled )
+ {
+ String sCodeName;
+ String sSource;
+ com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibContainer = GetBasicContainer();
+ com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xLib;
+ if( xLibContainer.is() )
+ {
+ com::sun::star::uno::Any aLibAny = xLibContainer->getByName( aLibName );
+ aLibAny >>= xLib;
+ }
+ if( xLib.is() )
+ {
+ rtl::OUString sRTLSource;
+ xLib->getByName( sSrcCodeName ) >>= sRTLSource;
+ sSource = sRTLSource;
+ }
+ VBA_InsertModule( aDocument, nTabToUse, sCodeName, sSource );
+ }
}
Broadcast( ScTablesHint( SC_TAB_COPIED, nSrcTab, nDestTab ) );
diff --git a/sc/source/ui/unoobj/servuno.cxx b/sc/source/ui/unoobj/servuno.cxx
index 0c57963a4f12..d69659b41f11 100644
--- a/sc/source/ui/unoobj/servuno.cxx
+++ b/sc/source/ui/unoobj/servuno.cxx
@@ -64,9 +64,121 @@
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/form/XFormsSupplier.hpp>
#include <svx/unomod.hxx>
-
using namespace ::com::sun::star;
+#ifndef CWS_NPOWER14MISCFIXES
+#include <basic/basmgr.hxx>
+uno::Reference< uno::XInterface > lcl_createVBAUnoAPIServiceWithArgs( SfxObjectShell* pShell, const sal_Char* _pAsciiName, const uno::Sequence< uno::Any >& aArgs ) throw (uno::RuntimeException)
+{
+ uno::Any aUnoVar;
+ if ( !pShell || !pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) )
+ throw lang::IllegalArgumentException();
+ uno::Reference< lang::XMultiServiceFactory > xVBAFactory( aUnoVar, uno::UNO_QUERY_THROW );
+ ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) );
+ uno::Reference< uno::XInterface > xIf = xVBAFactory->createInstanceWithArguments( sVarName, aArgs );
+ return xIf;
+}
+#endif
+
+class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
+{
+ uno::Any maWorkbook;
+ uno::Any maCachedObject;
+ ScDocShell* mpDocShell;
+public:
+ ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
+ {
+ 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() );
+#ifdef CWS_NPOWER14MISCFIXES
+ maWorkbook <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
+#else
+ maWorkbook <<= lcl_createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Workbook", aArgs );
+#endif
+ }
+
+ 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 ) );
+#ifdef CWS_NPOWER14MISCFIXES
+ // use the convience function
+ maCachedObject <<= ooo::vba::createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
+#else
+ // use the temp function
+ maCachedObject <<= lcl_createVBAUnoAPIServiceWithArgs( mpDocShell, "ooo.vba.excel.Worksheet", aArgs );
+#endif
+ 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; }
+
+};
+
class ScVbaCodeNameProvider : public ::cppu::WeakImplHelper1< document::XCodeNameQuery >
{
ScDocShell* mpDocShell;
@@ -172,6 +284,7 @@ static const ProvNamesId_Type __FAR_DATA aProvNamesId[] =
{ SC_SERVICENAME_CHDATAPROV, SC_SERVICE_CHDATAPROV },
{ SC_SERVICENAME_FORMULAPARS, SC_SERVICE_FORMULAPARS },
{ SC_SERVICENAME_OPCODEMAPPER, SC_SERVICE_OPCODEMAPPER },
+ { "ooo.vba.VBAObjectModuleObjectProvider", SC_SERVICE_VBAOBJECTPROVIDER }, // SC_SERVICE_VBAOBJECTPROVIDER
{ "ooo.vba.VBACodeNameProvider", SC_SERVICE_VBACODENAMEPROVIDER },
// case-correct versions of the service names (#i102468#)
@@ -235,6 +348,7 @@ static const sal_Char* __FAR_DATA aOldNames[SC_SERVICE_COUNT] =
"", // SC_SERVICE_CHDATAPROV
"", // SC_SERVICE_FORMULAPARS
"", // SC_SERVICE_OPCODEMAPPER
+ "", // SC_SERVICE_VBAOBJECTPROVIDER
"", // SC_SERVICE_VBACODENAMEPROVIDER
};
@@ -440,6 +554,13 @@ uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj(::std::auto_ptr<formula::FormulaCompiler> (pComp))));
break;
}
+ case SC_SERVICE_VBAOBJECTPROVIDER:
+ if ( pDocShell )
+ {
+ OSL_TRACE("**** creating VBA Object mapper");
+ xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
+ }
+ break;
case SC_SERVICE_VBACODENAMEPROVIDER:
{
// Only create the excel faking service for excel docs
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 627f214c4ec6..4c0d14d620bc 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -86,6 +86,13 @@
#include "funcdesc.hxx"
#include "docuno.hxx"
+#include <basic/sbstar.hxx>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/script/XLibraryContainer.hpp>
+using namespace com::sun::star;
+
+// helper func defined in docfunc.cxx
+void VBA_DeleteModule( ScDocShell& rDocSh, String& sModuleName );
// STATIC DATA ---------------------------------------------------------------
@@ -2140,6 +2147,7 @@ BOOL ScViewFunc::DeleteTables(const SvShorts &TheTabs, BOOL bRecord )
{
ScDocShell* pDocSh = GetViewData()->GetDocShell();
ScDocument* pDoc = pDocSh->GetDocument();
+ BOOL bVbaEnabled = pDoc ? pDoc->IsInVBAMode() : FALSE;
SCTAB nNewTab = TheTabs[0];
int i;
WaitObject aWait( GetFrameWin() );
@@ -2211,9 +2219,18 @@ BOOL ScViewFunc::DeleteTables(const SvShorts &TheTabs, BOOL bRecord )
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 )
+ {
+ VBA_DeleteModule( *pDocSh, sCodeName );
+ }
+ }
pDocSh->Broadcast( ScTablesHint( SC_TAB_DELETED, TheTabs[sal::static_int_cast<USHORT>(i)] ) );
}
}