diff options
author | Kurt Zenker <kz@openoffice.org> | 2010-05-21 16:13:20 +0200 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2010-05-21 16:13:20 +0200 |
commit | ca70505c0f9779abdc3623a136ffde96ffaff354 (patch) | |
tree | 0f9a9c63bae9c118b417062342d0d26c5c961c0d | |
parent | 6c2daaedbf5861683e62e3f979b7ea91b5ee35da (diff) | |
parent | 6910da13d5cac23ee289ae6e46b57c875d95def8 (diff) |
CWS-TOOLING: integrate CWS npower13_objectmodulesooo/DEV300_m79
24 files changed, 580 insertions, 120 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index da56aaa8a..20ac3b834 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1749,6 +1749,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 232ed43de..a09b1c354 100644 --- a/sc/inc/servuno.hxx +++ b/sc/inc/servuno.hxx @@ -88,12 +88,16 @@ class ScDocShell; // BM #define SC_SERVICE_CHDATAPROV 37 +// formula parser #define SC_SERVICE_FORMULAPARS 38 #define SC_SERVICE_OPCODEMAPPER 39 -#define SC_SERVICE_VBACODENAMEPROVIDER 40 -#define SC_SERVICE_VBAGLOBALS 41 -#define SC_SERVICE_COUNT 42 +// VBA specific +#define SC_SERVICE_VBAOBJECTPROVIDER 40 +#define SC_SERVICE_VBACODENAMEPROVIDER 41 +#define SC_SERVICE_VBAGLOBALS 42 + +#define SC_SERVICE_COUNT 43 #define SC_SERVICE_INVALID USHRT_MAX diff --git a/sc/inc/unonames.hxx b/sc/inc/unonames.hxx index e022231b1..6f7c773d9 100644 --- a/sc/inc/unonames.hxx +++ b/sc/inc/unonames.hxx @@ -484,6 +484,7 @@ #define SC_UNO_ISEXECUTELINKENABLED "IsExecuteLinkEnabled" #define SC_UNO_ISCHANGEREADONLYENABLED "IsChangeReadOnlyEnabled" #define SC_UNO_REFERENCEDEVICE "ReferenceDevice" +#define SC_UNO_CODENAME "CodeName" // document properties from FormModel #define SC_UNO_APPLYFMDES "ApplyFormDesignMode" diff --git a/sc/inc/unowids.hxx b/sc/inc/unowids.hxx index f7802a986..b0f4bbefd 100644 --- a/sc/inc/unowids.hxx +++ b/sc/inc/unowids.hxx @@ -77,7 +77,8 @@ #define SC_WID_UNO_TABLAYOUT ( SC_WID_UNO_START + 37 ) #define SC_WID_UNO_AUTOPRINT ( SC_WID_UNO_START + 38 ) #define SC_WID_UNO_ABSNAME ( SC_WID_UNO_START + 39 ) -#define SC_WID_UNO_END ( SC_WID_UNO_START + 39 ) +#define SC_WID_UNO_CODENAME ( SC_WID_UNO_START + 40 ) +#define SC_WID_UNO_END ( SC_WID_UNO_START + 40 ) inline BOOL IsScUnoWid( USHORT nWid ) diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index f9f2933ce..0f2c7bda9 100644..100755 --- 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,43 @@ ULONG ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos, } if (!bValid) nRetVal = 0; + BOOL bVbaEnabled = IsInVBAMode(); + + if ( bVbaEnabled ) + { + SfxObjectShell* pSrcShell = pSrcDoc ? pSrcDoc->GetDocumentShell() : NULL; + if ( pSrcShell ) + { + StarBASIC* pStarBASIC = pSrcShell ? pSrcShell->GetBasic() : NULL; + String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); + if ( pSrcShell && pSrcShell->GetBasicManager()->GetName().Len() > 0 ) + { + aLibName = pSrcShell->GetBasicManager()->GetName(); + pStarBASIC = pSrcShell->GetBasicManager()->GetLib( aLibName ); + } + + String sCodeName; + String sSource; + com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibContainer = pSrcShell->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 d443a579e..eeb1a4eda 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" @@ -4972,4 +4973,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 389e4cfc7..d4facf965 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(); @@ -270,14 +267,14 @@ void ImportExcel8::ReadBasic( void ) if( bLoadCode || bLoadStrg ) { SvxImportMSVBasic aBasicImport( *pShell, *xRootStrg, bLoadCode, bLoadStrg ); - bool bAsComment = !bLoadExecutable; + bool bAsComment = !bLoadExecutable; if ( !bAsComment ) { - uno::Any aGlobs; + uno::Any aGlobs; uno::Sequence< uno::Any > aArgs(1); aArgs[ 0 ] <<= pShell->GetModel(); - aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs ); - pShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs ); + aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs ); + pShell->GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs ); BasicManager* pAppMgr = SFX_APP()->GetBasicManager(); if ( pAppMgr ) pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] ); @@ -297,6 +294,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 7aa540e3f..af7e86614 100644 --- a/sc/source/filter/excel/read.cxx +++ b/sc/source/filter/excel/read.cxx @@ -986,7 +986,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/filter/excel/xiescher.cxx b/sc/source/filter/excel/xiescher.cxx index 784b29b56..e44a1c77b 100644 --- a/sc/source/filter/excel/xiescher.cxx +++ b/sc/source/filter/excel/xiescher.cxx @@ -478,14 +478,14 @@ void XclImpDrawObjBase::PreProcessSdrObject( XclImpDffConverter& rDffConv, SdrOb { if( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( &rSdrObj, TRUE ) ) { - pInfo->SetMacro( XclControlHelper::GetScMacroName( maMacroName ) ); + pInfo->SetMacro( XclControlHelper::GetScMacroName( maMacroName, GetDocShell() ) ); pInfo->SetHlink( maHyperlink ); } } #else if( mbSimpleMacro && (maMacroName.Len() > 0) ) if( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( &rSdrObj, TRUE ) ) - pInfo->SetMacro( XclControlHelper::GetScMacroName( maMacroName ) ); + pInfo->SetMacro( XclControlHelper::GetScMacroName( maMacroName, GetDocShell() ) ); #endif // call virtual function for object type specific processing @@ -1947,7 +1947,7 @@ void XclImpTbxObjBase::SetDffProperties( const DffPropSet& rDffPropSet ) bool XclImpTbxObjBase::FillMacroDescriptor( ScriptEventDescriptor& rDescriptor ) const { - return XclControlHelper::FillMacroDescriptor( rDescriptor, DoGetEventType(), GetMacroName() ); + return XclControlHelper::FillMacroDescriptor( rDescriptor, DoGetEventType(), GetMacroName(), GetDocShell() ); } void XclImpTbxObjBase::ConvertFont( ScfPropertySet& rPropSet ) const diff --git a/sc/source/filter/excel/xlescher.cxx b/sc/source/filter/excel/xlescher.cxx index 026673e5c..840a22a38 100644 --- a/sc/source/filter/excel/xlescher.cxx +++ b/sc/source/filter/excel/xlescher.cxx @@ -35,6 +35,7 @@ #include "document.hxx" #include "xistream.hxx" #include "xlescher.hxx" +#include <filter/msfilter/msvbahelper.hxx> using ::rtl::OUString; using ::com::sun::star::uno::Reference; @@ -328,10 +329,16 @@ Reference< XControlModel > XclControlHelper::GetControlModel( Reference< XShape #define EXC_MACRONAME_PRE "vnd.sun.star.script:Standard." #define EXC_MACRONAME_SUF "?language=Basic&location=document" -OUString XclControlHelper::GetScMacroName( const String& rXclMacroName ) +OUString XclControlHelper::GetScMacroName( const String& rXclMacroName, SfxObjectShell* pDocShell ) { + String sTmp( rXclMacroName ); if( rXclMacroName.Len() > 0 ) - return CREATE_OUSTRING( EXC_MACRONAME_PRE ) + rXclMacroName + CREATE_OUSTRING( EXC_MACRONAME_SUF ); + { + ooo::vba::VBAMacroResolvedInfo aMacro = ooo::vba::resolveVBAMacro( pDocShell, rXclMacroName, false ); + if ( aMacro.IsResolved() ) + return ooo::vba::makeMacroURL( aMacro.ResolvedMacro() ); + + } return OUString(); } @@ -365,14 +372,14 @@ spTbxListenerData[] = #define EXC_MACROSCRIPT "Script" bool XclControlHelper::FillMacroDescriptor( ScriptEventDescriptor& rDescriptor, - XclTbxEventType eEventType, const String& rXclMacroName ) + XclTbxEventType eEventType, const String& rXclMacroName, SfxObjectShell* pShell ) { if( rXclMacroName.Len() > 0 ) { rDescriptor.ListenerType = OUString::createFromAscii( spTbxListenerData[ eEventType ].mpcListenerType ); rDescriptor.EventMethod = OUString::createFromAscii( spTbxListenerData[ eEventType ].mpcEventMethod ); rDescriptor.ScriptType = CREATE_OUSTRING( EXC_MACROSCRIPT ); - rDescriptor.ScriptCode = GetScMacroName( rXclMacroName ); + rDescriptor.ScriptCode = GetScMacroName( rXclMacroName, pShell ); return true; } return false; diff --git a/sc/source/filter/inc/xlescher.hxx b/sc/source/filter/inc/xlescher.hxx index d2b551d55..6af42051a 100644 --- a/sc/source/filter/inc/xlescher.hxx +++ b/sc/source/filter/inc/xlescher.hxx @@ -432,7 +432,7 @@ public: GetControlModel( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape ); /** Returns the Calc macro name from an Excel macro name. */ - static ::rtl::OUString GetScMacroName( const String& rXclMacroName ); + static ::rtl::OUString GetScMacroName( const String& rXclMacroName, SfxObjectShell* pShell = NULL ); /** Returns the Excel macro name from a Calc macro name. */ static String GetXclMacroName( const ::rtl::OUString& rScMacroName ); @@ -440,7 +440,7 @@ public: static bool FillMacroDescriptor( ::com::sun::star::script::ScriptEventDescriptor& rDescriptor, XclTbxEventType eEventType, - const String& rXclMacroName ); + const String& rXclMacroName, SfxObjectShell* pShell = NULL ); /** Tries to extract an Excel macro name from the passed macro descriptor. */ static String ExtractFromMacroDescriptor( const ::com::sun::star::script::ScriptEventDescriptor& rDescriptor, diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 47d67df26..1db212026 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 f5f40fe57..aa3ca3e66 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 ); // --------------------------------------------------------------------------- @@ -866,6 +871,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? @@ -889,8 +896,38 @@ BOOL ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, BOOL bCopy, BOOL bRec GetUndoManager()->AddUndoAction( new ScUndoCopyTab( this, aSrcList, aDestList ) ); } - } - + + BOOL bVbaEnabled = aDocument.IsInVBAMode(); + if ( bVbaEnabled ) + { + StarBASIC* pStarBASIC = GetBasic(); + String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); + if ( GetBasicManager()->GetName().Len() > 0 ) + { + aLibName = GetBasicManager()->GetName(); + pStarBASIC = GetBasicManager()->GetLib( aLibName ); + } + SCTAB nTabToUse = nDestTab; + if ( nDestTab == SC_TAB_APPEND ) + nTabToUse = aDocument.GetMaxTableNumber() - 1; + 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 ) ); } else diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index d5652bae2..145e6b3ab 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -769,6 +769,7 @@ const SfxItemPropertySet* lcl_GetSheetPropertySet() {MAP_CHAR_LEN(SC_UNONAME_VALIXML), SC_WID_UNO_VALIXML, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &getCppuType((table::CellVertJustify*)0), 0, 0 }, {MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_CODENAME), SC_WID_UNO_CODENAME, &getCppuType(static_cast< const rtl::OUString * >(0)), 0, 0}, {0,0,0,0,0,0} }; static SfxItemPropertySet aSheetPropertySet( aSheetPropertyMap_Impl ); @@ -8468,6 +8469,15 @@ void ScTableSheetObj::SetOnePropertyValue( const SfxItemPropertySimpleEntry* pEn pDoc->ClearPrintRanges( nTab ); // if this flag is true, there are no PrintRanges, so Clear clears only the flag. } } + else if ( pEntry->nWID == SC_WID_UNO_CODENAME ) + { + rtl::OUString aCodeName; + if ( pDocSh && ( aValue >>= aCodeName ) ) + { + String sNewName( aCodeName ); + pDocSh->GetDocument()->SetCodeName( GetTab_Impl(), sNewName ); + } + } else ScCellRangeObj::SetOnePropertyValue(pEntry, aValue); // base class, no Item WID } @@ -8606,6 +8616,13 @@ void ScTableSheetObj::GetOnePropertyValue( const SfxItemPropertySimpleEntry* pEn BOOL bAutoPrint = pDoc->IsPrintEntireSheet( nTab ); ScUnoHelpFunctions::SetBoolInAny( rAny, bAutoPrint ); } + else if ( pEntry->nWID == SC_WID_UNO_CODENAME ) + { + String aCodeName; + if ( pDocSh ) + pDocSh->GetDocument()->GetCodeName( GetTab_Impl(), aCodeName ); + rAny <<= rtl::OUString( aCodeName ); + } else ScCellRangeObj::GetOnePropertyValue(pEntry, rAny); } diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 72983606b..2ccb981ee 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -152,6 +152,7 @@ const SfxItemPropertyMapEntry* lcl_GetDocOptPropertyMap() {MAP_CHAR_LEN(SC_UNO_ISCHANGEREADONLYENABLED), 0, &getBooleanCppuType(), 0, 0}, {MAP_CHAR_LEN(SC_UNO_REFERENCEDEVICE), 0, &getCppuType((uno::Reference<awt::XDevice>*)0), beans::PropertyAttribute::READONLY, 0}, {MAP_CHAR_LEN("BuildId"), 0, &::getCppuType(static_cast< const rtl::OUString * >(0)), 0, 0}, + {MAP_CHAR_LEN(SC_UNO_CODENAME), 0, &getCppuType(static_cast< const rtl::OUString * >(0)), 0, 0}, {0,0,0,0,0,0} }; @@ -1652,6 +1653,12 @@ void SAL_CALL ScModelObj::setPropertyValue( pDoc->SetLanguage( eLatin, eCjk, eCtl ); } } + else if ( aString.EqualsAscii( SC_UNO_CODENAME ) ) + { + rtl::OUString sCodeName; + if ( aValue >>= sCodeName ) + pDoc->SetCodeName( sCodeName ); + } else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) ) { lang::Locale aLocale; @@ -1784,6 +1791,12 @@ uno::Any SAL_CALL ScModelObj::getPropertyValue( const rtl::OUString& aPropertyNa ScUnoConversion::FillLocale( aLocale, eLatin ); aRet <<= aLocale; } + else if ( aString.EqualsAscii( SC_UNO_CODENAME ) ) + { + rtl::OUString sCodeName = pDoc->GetCodeName(); + aRet <<= sCodeName; + } + else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) ) { LanguageType eLatin, eCjk, eCtl; diff --git a/sc/source/ui/unoobj/servuno.cxx b/sc/source/ui/unoobj/servuno.cxx index 8f42d89a4..b28c401c5 100644 --- a/sc/source/ui/unoobj/servuno.cxx +++ b/sc/source/ui/unoobj/servuno.cxx @@ -37,6 +37,7 @@ #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> #include "servuno.hxx" +#include "unoguard.hxx" #include "unonames.hxx" #include "cellsuno.hxx" #include "fielduno.hxx" @@ -71,6 +72,121 @@ using namespace ::com::sun::star; +#ifndef CWS_NPOWER14MISCFIXES +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 ) + { + ScUnoGuard aGuard; + 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) + { + ScUnoGuard aGuard; + 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) + { + ScUnoGuard aGuard; + 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; @@ -79,6 +195,7 @@ public: // XCodeNameQuery rtl::OUString SAL_CALL getCodeNameForObject( const uno::Reference< uno::XInterface >& xIf ) throw( uno::RuntimeException ) { + ScUnoGuard aGuard; rtl::OUString sCodeName; if ( mpDocShell ) { @@ -176,7 +293,9 @@ 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 }, { "ooo.vba.VBACodeNameProvider", SC_SERVICE_VBACODENAMEPROVIDER }, + { "ooo.vba.VBAGlobals", SC_SERVICE_VBAGLOBALS }, // case-correct versions of the service names (#i102468#) { "com.sun.star.text.textfield.URL", SC_SERVICE_URLFIELD }, @@ -186,8 +305,7 @@ static const ProvNamesId_Type __FAR_DATA aProvNamesId[] = { "com.sun.star.text.textfield.Time", SC_SERVICE_TIMEFIELD }, { "com.sun.star.text.textfield.DocumentTitle", SC_SERVICE_TITLEFIELD }, { "com.sun.star.text.textfield.FileName", SC_SERVICE_FILEFIELD }, - { "com.sun.star.text.textfield.SheetName", SC_SERVICE_SHEETFIELD }, - { "ooo.vba.VBAGlobals", SC_SERVICE_VBAGLOBALS }, + { "com.sun.star.text.textfield.SheetName", SC_SERVICE_SHEETFIELD } }; // @@ -240,6 +358,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 "", // SC_SERVICE_VBAGLOBALS }; @@ -446,6 +565,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/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx index b28cb6cc9..272278171 100644 --- a/sc/source/ui/vba/excelvbahelper.cxx +++ b/sc/source/ui/vba/excelvbahelper.cxx @@ -208,12 +208,11 @@ getViewFrame( const uno::Reference< frame::XModel >& xModel ) } SfxItemSet* -ScVbaCellRangeAccess::GetDataSet( ScCellRangeObj* pRangeObj ) +ScVbaCellRangeAccess::GetDataSet( ScCellRangesBase* pRangeObj ) { - SfxItemSet* pDataSet = pRangeObj ? pRangeObj->GetCurrentDataSet( true ) : NULL ; - return pDataSet; - + return pRangeObj ? pRangeObj->GetCurrentDataSet( true ) : 0; } + } //excel } //vba } //ooo diff --git a/sc/source/ui/vba/excelvbahelper.hxx b/sc/source/ui/vba/excelvbahelper.hxx index 5630af5ff..ce6ba352c 100644 --- a/sc/source/ui/vba/excelvbahelper.hxx +++ b/sc/source/ui/vba/excelvbahelper.hxx @@ -30,7 +30,7 @@ #include<vbahelper/vbahelper.hxx> #include <docsh.hxx> -class ScCellRangeObj; +class ScCellRangesBase; namespace ooo { @@ -51,7 +51,7 @@ namespace ooo class ScVbaCellRangeAccess { public: - static SfxItemSet* GetDataSet( ScCellRangeObj* pRangeObj ); + static SfxItemSet* GetDataSet( ScCellRangesBase* pRangeObj ); }; } } diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx index e78260155..228ca64e5 100644 --- a/sc/source/ui/vba/vbaapplication.cxx +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -132,10 +132,16 @@ ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException) { return new ActiveWorkbook( this, mxContext ); } + uno::Reference< excel::XWorkbook > SAL_CALL ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException) { - return getActiveWorkbook(); + uno::Reference< frame::XModel > xModel = getThisExcelDoc(mxContext); + if( !xModel.is() ) + return uno::Reference< excel::XWorkbook >(); + + ScVbaWorkbook *pWb = new ScVbaWorkbook( this, mxContext, xModel ); + return uno::Reference< excel::XWorkbook > (pWb); } uno::Reference< XAssistant > SAL_CALL @@ -769,46 +775,74 @@ bool lcl_canJoin( ScRange& r1, ScRange& r2 ) void lcl_strip_containedRanges( Ranges& vRanges ) { // get rid of ranges that are surrounded by other ranges - for( Ranges::iterator it = vRanges.begin(); it != vRanges.end(); ++it ) + Ranges::iterator it_outer = vRanges.begin(); + while( it_outer != vRanges.end() ) { - for( Ranges::iterator it_inner = vRanges.begin(); it_inner != vRanges.end(); ++it_inner ) + bool it_outer_erased = false; // true = it_outer erased from vRanges + Ranges::iterator it_inner = vRanges.begin(); + /* Exit the inner loop if outer iterator has been erased in its last + iteration (this means it has been joined to last it_inner, or that + the it_inner contains it completely). The inner loop will restart + with next element of the outer loop, and all elements (from the + beginning of the list) will be checked against that new element. */ + while( !it_outer_erased && (it_inner != vRanges.end()) ) { - if ( it != it_inner ) + bool it_inner_erased = false; // true = it_inner erased from vRanges + if ( it_outer != it_inner ) { #ifdef DEBUG - String r1; - String r2; - it->Format( r1, SCA_VALID ) ; - it_inner->Format( r2, SCA_VALID ) ; - OSL_TRACE( "try strip/join address %s with %s ", - rtl::OUStringToOString( r1, RTL_TEXTENCODING_UTF8 ).getStr(), - rtl::OUStringToOString( r2, RTL_TEXTENCODING_UTF8 ).getStr() ); + String r1; + String r2; + it_outer->Format( r1, SCA_VALID ) ; + it_inner->Format( r2, SCA_VALID ) ; + OSL_TRACE( "try strip/join address %s with %s ", + rtl::OUStringToOString( r1, RTL_TEXTENCODING_UTF8 ).getStr(), + rtl::OUStringToOString( r2, RTL_TEXTENCODING_UTF8 ).getStr() ); #endif - if ( it->In( *it_inner ) ) + if ( it_outer->In( *it_inner ) ) + { it_inner = vRanges.erase( it_inner ); - else if ( it_inner->In( *it ) ) - it = vRanges.erase( it ); + it_inner_erased = true; + } + else if ( it_inner->In( *it_outer ) ) + { + it_outer = vRanges.erase( it_outer ); + it_outer_erased = true; + } #ifndef OWN_JOIN - else if ( (*it_inner).aStart.Row() == (*it).aStart.Row() - && (*it_inner).aEnd.Row() == (*it).aEnd.Row() ) + else if ( (*it_inner).aStart.Row() == (*it_outer).aStart.Row() + && (*it_inner).aEnd.Row() == (*it_outer).aEnd.Row() ) { - it->ExtendTo( *it_inner ); + it_outer->ExtendTo( *it_inner ); it_inner = vRanges.erase( it_inner ); + it_inner_erased = true; } #else - else if ( lcl_canJoin( *it, *it_inner ) ) + else if ( lcl_canJoin( *it_outer, *it_inner ) ) { - it->ExtendTo( *it_inner ); + it_outer->ExtendTo( *it_inner ); it_inner = vRanges.erase( it_inner ); + it_inner_erased = true; } - else if ( lcl_canJoin( *it_inner, *it) ) + else if ( lcl_canJoin( *it_inner, *it_outer) ) { - it_inner->ExtendTo( *it ); - it = vRanges.erase( it ); + it_inner->ExtendTo( *it_outer ); + it_outer = vRanges.erase( it_outer ); + it_outer_erased = true; } #endif } + /* If it_inner has not been erased from vRanges, continue inner + loop with next element. Otherwise, it_inner already points to + the next element (return value of list::erase()). */ + if( !it_inner_erased ) + ++it_inner; } + /* If it_outer has not been erased from vRanges, continue outer loop + with next element. Otherwise, it_outer already points to the next + element (return value of list::erase()). */ + if( !it_outer_erased ) + ++it_outer; } } diff --git a/sc/source/ui/vba/vbaformat.cxx b/sc/source/ui/vba/vbaformat.cxx index f9b54a0bb..d8ca111e6 100644 --- a/sc/source/ui/vba/vbaformat.cxx +++ b/sc/source/ui/vba/vbaformat.cxx @@ -45,7 +45,10 @@ #include "vbafont.hxx" #include "vbainterior.hxx" -#include "unonames.hxx" +#include <unonames.hxx> +#include <cellsuno.hxx> +#include <scitems.hxx> +#include <attrib.hxx> using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -571,14 +574,24 @@ ScVbaFormat<Ifc1>::getLocked( ) throw (script::BasicErrorException, uno::Runtim uno::Any aCellProtection = aNULL(); try { - rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) ); + if (!isAmbiguous(sCellProt)) { - util::CellProtection cellProtection; - mxPropertySet->getPropertyValue(sCellProt) >>= cellProtection; - - aCellProtection = uno::makeAny( cellProtection.IsLocked ); + SfxItemSet* pDataSet = getCurrentDataSet(); + if ( pDataSet ) + { + const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &) pDataSet->Get(ATTR_PROTECTION, TRUE); + SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, TRUE, NULL); + if(eState != SFX_ITEM_DONTCARE) + aCellProtection = uno::makeAny(rProtAttr.GetProtection()); + } + else // fallback to propertyset + { + util::CellProtection cellProtection; + mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection; + aCellProtection = uno::makeAny( cellProtection.IsLocked ); + } } } catch (uno::Exception& ) @@ -598,9 +611,20 @@ ScVbaFormat<Ifc1>::getFormulaHidden( ) throw (script::BasicErrorException, uno: rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) ); if (!isAmbiguous(sCellProt)) { - util::CellProtection aCellProtection; - mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection; - aBoolRet = uno::makeAny( aCellProtection.IsFormulaHidden ); + SfxItemSet* pDataSet = getCurrentDataSet(); + if ( pDataSet ) + { + const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &) pDataSet->Get(ATTR_PROTECTION, TRUE); + SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, TRUE, NULL); + if(eState != SFX_ITEM_DONTCARE) + aBoolRet = uno::makeAny(rProtAttr.GetHideFormula()); + } + else + { + util::CellProtection aCellProtection; + mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection; + aBoolRet = uno::makeAny( aCellProtection.IsFormulaHidden ); + } } } catch (uno::Exception e) @@ -794,6 +818,24 @@ ScVbaFormat<Ifc1>::getServiceNames() return aServiceNames; } +template< typename Ifc1 > +ScCellRangesBase* +ScVbaFormat<Ifc1>::getCellRangesBase() throw ( ::uno::RuntimeException ) +{ + return ScCellRangesBase::getImplementation( mxPropertySet ); +} + +template< typename Ifc1 > +SfxItemSet* +ScVbaFormat<Ifc1>::getCurrentDataSet( ) throw ( uno::RuntimeException ) +{ + SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() ); + if ( !pDataSet ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't access Itemset for XPropertySet" ) ), uno::Reference< uno::XInterface >() ); + return pDataSet; +} + + template class ScVbaFormat< excel::XStyle >; template class ScVbaFormat< excel::XRange >; diff --git a/sc/source/ui/vba/vbaformat.hxx b/sc/source/ui/vba/vbaformat.hxx index 1f3413160..7b57df42f 100644 --- a/sc/source/ui/vba/vbaformat.hxx +++ b/sc/source/ui/vba/vbaformat.hxx @@ -38,6 +38,8 @@ #include <com/sun/star/beans/XPropertyState.hpp> #include <vbahelper/vbahelperinterface.hxx> +class ScCellRangesBase; + template< typename Ifc1 > class ScVbaFormat : public InheritedHelperInterfaceImpl1< Ifc1 > { @@ -60,6 +62,9 @@ protected: css::uno::Reference< css::beans::XPropertyState > getXPropertyState() throw ( css::uno::RuntimeException ); void initializeNumberFormats() throw ( css::script::BasicErrorException ); void setNumberFormat( css::lang::Locale _aLocale, const rtl::OUString& _sFormatString) throw( css::script::BasicErrorException ); + SfxItemSet* getCurrentDataSet( ) throw ( css::uno::RuntimeException ); +protected: + virtual ScCellRangesBase* getCellRangesBase() throw ( css::uno::RuntimeException ); public: ScVbaFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet, const css::uno::Reference< css::frame::XModel >& xModel, bool bCheckAmbiguoity ) throw ( css::script::BasicErrorException ); virtual ~ScVbaFormat() {} diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index cec0626f0..acf9e61aa 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -238,21 +238,28 @@ uno::Reference< excel::XRange > lcl_makeXRangeFromSheetCellRanges( const uno::Re return xRange; } -ScCellRangeObj* ScVbaRange::getCellRangeObj() throw ( uno::RuntimeException ) +ScCellRangesBase* ScVbaRange::getCellRangesBase() throw ( uno::RuntimeException ) { - uno::Reference< uno::XInterface > xIf; - if ( mxRanges.is() ) - xIf.set( mxRanges, uno::UNO_QUERY_THROW ); - else - xIf.set( mxRange, uno::UNO_QUERY_THROW ); - ScCellRangeObj* pUnoCellRange = dynamic_cast< ScCellRangeObj* >( xIf.get() ); - return pUnoCellRange; + if( mxRanges.is() ) + return ScCellRangesBase::getImplementation( mxRanges ); + if( mxRange.is() ) + return ScCellRangesBase::getImplementation( mxRange ); + throw uno::RuntimeException( rtl::OUString::createFromAscii("General Error creating range - Unknown" ), uno::Reference< uno::XInterface >() ); +} + +ScCellRangeObj* ScVbaRange::getCellRangeObj() throw ( uno::RuntimeException ) +{ + return dynamic_cast< ScCellRangeObj* >( getCellRangesBase() ); +} + +ScCellRangesObj* ScVbaRange::getCellRangesObj() throw ( uno::RuntimeException ) +{ + return dynamic_cast< ScCellRangesObj* >( getCellRangesBase() ); } SfxItemSet* ScVbaRange::getCurrentDataSet( ) throw ( uno::RuntimeException ) { - ScCellRangeObj* pUnoCellRange = getCellRangeObj(); - SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( pUnoCellRange ); + SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() ); if ( !pDataSet ) throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't access Itemset for range" ) ), uno::Reference< uno::XInterface >() ); return pDataSet; @@ -2711,7 +2718,7 @@ ScVbaRange::setHidden( const uno::Any& _hidden ) throw (uno::RuntimeException) } } -::sal_Bool SAL_CALL +::sal_Bool SAL_CALL ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replacement, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& MatchCase, const uno::Any& MatchByte, const uno::Any& SearchFormat, const uno::Any& ReplaceFormat ) throw (uno::RuntimeException) { if ( m_Areas->getCount() > 1 ) @@ -3852,25 +3859,6 @@ ScVbaRange::getWorksheet() throw (uno::RuntimeException) return xSheet; } -ScCellRangesBase* -ScVbaRange::getCellRangesBase() throw( uno::RuntimeException ) -{ - ScCellRangesBase* pUnoRangesBase = NULL; - if ( mxRanges.is() ) - { - uno::Reference< uno::XInterface > xIf( mxRanges, uno::UNO_QUERY_THROW ); - pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() ); - } - else if ( mxRange.is() ) - { - uno::Reference< uno::XInterface > xIf( mxRange, uno::UNO_QUERY_THROW ); - pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() ); - } - else - throw uno::RuntimeException( rtl::OUString::createFromAscii("General Error creating range - Unknown" ), uno::Reference< uno::XInterface >() ); - return pUnoRangesBase; -} - // #TODO remove this ugly application processing // Process an application Range request e.g. 'Range("a1,b2,a4:b6") uno::Reference< excel::XRange > @@ -4589,26 +4577,6 @@ ScVbaRange::getValidation() throw (css::uno::RuntimeException) return m_xValidation; } -uno::Any ScVbaRange::getFormulaHidden() throw ( script::BasicErrorException, css::uno::RuntimeException) -{ - SfxItemSet* pDataSet = getCurrentDataSet(); - const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &) - pDataSet->Get(ATTR_PROTECTION, TRUE); - SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, TRUE, NULL); - if(eState == SFX_ITEM_DONTCARE) - return aNULL(); - return uno::makeAny(rProtAttr.GetHideFormula()); - -} -void ScVbaRange::setFormulaHidden(const uno::Any& Hidden) throw ( script::BasicErrorException, css::uno::RuntimeException) -{ - uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY_THROW); - util::CellProtection rCellAttr; - xProps->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLPRO))) >>= rCellAttr; - Hidden >>= rCellAttr.IsFormulaHidden; - xProps->setPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLPRO)), uno::makeAny(rCellAttr)); -} - uno::Any ScVbaRange::getShowDetail() throw ( css::uno::RuntimeException) { // #FIXME, If the specified range is in a PivotTable report diff --git a/sc/source/ui/vba/vbarange.hxx b/sc/source/ui/vba/vbarange.hxx index a40b0f390..b405589ae 100644 --- a/sc/source/ui/vba/vbarange.hxx +++ b/sc/source/ui/vba/vbarange.hxx @@ -57,6 +57,7 @@ class ScTableSheetsObj; class ScCellRangesBase; class ScCellRangeObj; +class ScCellRangesObj; class ScDocShell; class ScDocument; @@ -111,14 +112,16 @@ class ScVbaRange : public ScVbaRange_BASE virtual css::uno::Any getFormulaValue( formula::FormulaGrammar::Grammar ) throw (css::uno::RuntimeException); virtual void setFormulaValue( const css::uno::Any& aValue, formula::FormulaGrammar::Grammar ) throw ( css::uno::RuntimeException); css::uno::Reference< ov::excel::XRange > getArea( sal_Int32 nIndex ) throw( css::uno::RuntimeException ); - ScCellRangesBase* getCellRangesBase() throw ( css::uno::RuntimeException ); ScCellRangeObj* getCellRangeObj( ) throw ( css::uno::RuntimeException ); - SfxItemSet* getCurrentDataSet( ) throw ( css::uno::RuntimeException ); + ScCellRangesObj* getCellRangesObj() throw ( css::uno::RuntimeException ); css::uno::Reference< ov::XCollection >& getBorders(); void groupUnGroup( bool bUnGroup = false ) throw ( css::script::BasicErrorException, css::uno::RuntimeException ); css::uno::Reference< ov::excel::XRange > PreviousNext( bool bIsPrevious ); css::uno::Reference< ov::excel::XRange > SpecialCellsImpl( sal_Int32 nType, const css::uno::Any& _oValue) throw ( css::script::BasicErrorException ); css::awt::Point getPosition() throw ( css::uno::RuntimeException ); +protected: + virtual ScCellRangesBase* getCellRangesBase() throw ( css::uno::RuntimeException ); + virtual SfxItemSet* getCurrentDataSet( ) throw ( css::uno::RuntimeException ); public: ScVbaRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::table::XCellRange >& xRange, sal_Bool bIsRows = false, sal_Bool bIsColumns = false ) throw ( css::lang::IllegalArgumentException ); ScVbaRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges, sal_Bool bIsRows = false, sal_Bool bIsColumns = false ) throw ( css::lang::IllegalArgumentException ); @@ -170,10 +173,6 @@ public: virtual css::uno::Any SAL_CALL getPageBreak() throw (css::uno::RuntimeException); virtual void SAL_CALL setPageBreak( const css::uno::Any& _pagebreak ) throw (css::uno::RuntimeException); virtual css::uno::Reference< ov::excel::XValidation > SAL_CALL getValidation() throw (css::uno::RuntimeException); - virtual css::uno::Any SAL_CALL getFormulaHidden() throw (css::script::BasicErrorException, css::uno::RuntimeException); - virtual void SAL_CALL setFormulaHidden(const css::uno::Any& aHidden) throw (css::script::BasicErrorException, css::uno::RuntimeException); - //virtual css::uno::Any SAL_CALL getLocked() throw (css::script::BasicErrorException, css::uno::RuntimeException); - //virtual void SAL_CALL setLocked(const css::uno::Any& aLocked) throw (css::script::BasicErrorException, css::uno::RuntimeException); virtual css::uno::Any SAL_CALL getShowDetail() throw (css::uno::RuntimeException); virtual void SAL_CALL setShowDetail(const css::uno::Any& aShowDetail) throw (css::uno::RuntimeException); // Methods diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 2f956e670..77b8117c4 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -87,6 +87,13 @@ #include "docuno.hxx" #include "charthelper.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 --------------------------------------------------------------- @@ -2141,6 +2148,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() ); @@ -2212,9 +2220,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)] ) ); } } |