[Libreoffice-commits] .: Branch 'libreoffice-3-4' - sc/source
Noel Power
noelp at kemper.freedesktop.org
Tue Apr 26 01:34:26 PDT 2011
sc/source/ui/vba/excelvbahelper.cxx | 87 ++++++++++++++++++++++++++++++++++++
sc/source/ui/vba/excelvbahelper.hxx | 2
sc/source/ui/vba/vbaworkbooks.cxx | 82 ---------------------------------
sc/source/ui/vba/vbaworksheet.cxx | 16 +++++-
sc/source/ui/vba/vbaworksheets.cxx | 6 ++
5 files changed, 108 insertions(+), 85 deletions(-)
New commits:
commit 88a31c7413d151bc4206624c4bd14b0c5d2cab17
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Tue Apr 26 09:32:22 2011 +0100
fixed problem with return value in ScVbaWorksheet::createSheetCopyInNewDoc
diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx
index 4f49aab..d98f1ac 100644
--- a/sc/source/ui/vba/excelvbahelper.cxx
+++ b/sc/source/ui/vba/excelvbahelper.cxx
@@ -39,6 +39,13 @@
#include "token.hxx"
#include "tokenarray.hxx"
+#include <com/sun/star/script/vba/VBAEventId.hpp>
+#include <com/sun/star/script/vba/XVBACompatibility.hpp>
+#include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
+#include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
+#include <com/sun/star/script/ModuleInfo.hpp>
+#include <com/sun/star/script/ModuleType.hpp>
+
using namespace ::com::sun::star;
using namespace ::ooo::vba;
@@ -460,6 +467,86 @@ getUnoSheetModuleObj( const uno::Reference< frame::XModel >& xModel, SCTAB nTab
return getUnoSheetModuleObj( xSheet );
}
+void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& xDoc )
+{
+ uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY );
+ ScDocShell* pShell = excel::getDocShell( xModel );
+ if ( pShell )
+ {
+ String aPrjName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
+ pShell->GetBasicManager()->SetName( aPrjName );
+
+ /* Set library container to VBA compatibility mode. This will create
+ the VBA Globals object and store it in the Basic manager of the
+ document. */
+ uno::Reference<script::XLibraryContainer> xLibContainer = pShell->GetBasicContainer();
+ uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW );
+ xVBACompat->setVBACompatibilityMode( sal_True );
+
+ if( xLibContainer.is() )
+ {
+ if( !xLibContainer->hasByName( aPrjName ) )
+ xLibContainer->createLibrary( aPrjName );
+ uno::Any aLibAny = xLibContainer->getByName( aPrjName );
+ uno::Reference< container::XNameContainer > xLib;
+ aLibAny >>= xLib;
+ if( xLib.is() )
+ {
+ uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW );
+ uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY_THROW);
+ uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY_THROW );
+ // set up the module info for the workbook and sheets in the nealy created
+ // spreadsheet
+ ScDocument* pDoc = pShell->GetDocument();
+ String sCodeName = pDoc->GetCodeName();
+ if ( sCodeName.Len() == 0 )
+ {
+ sCodeName = String( RTL_CONSTASCII_USTRINGPARAM("ThisWorkbook") );
+ pDoc->SetCodeName( sCodeName );
+ }
+
+ std::vector< rtl::OUString > sDocModuleNames;
+ sDocModuleNames.push_back( sCodeName );
+
+ for ( SCTAB index = 0; index < pDoc->GetTableCount(); index++)
+ {
+ String aName;
+ pDoc->GetCodeName( index, aName );
+ sDocModuleNames.push_back( aName );
+ }
+
+ std::vector<rtl::OUString>::iterator it_end = sDocModuleNames.end();
+
+ for ( std::vector<rtl::OUString>::iterator it = sDocModuleNames.begin(); it != it_end; ++it )
+ {
+ script::ModuleInfo sModuleInfo;
+
+ uno::Any aName= xVBACodeNamedObjectAccess->getByName( *it );
+ sModuleInfo.ModuleObject.set( aName, uno::UNO_QUERY );
+ sModuleInfo.ModuleType = script::ModuleType::DOCUMENT;
+ xVBAModuleInfo->insertModuleInfo( *it, sModuleInfo );
+ if( xLib->hasByName( *it ) )
+ xLib->replaceByName( *it, uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n") ) ) );
+ else
+ xLib->insertByName( *it, uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n" ) ) ) );
+ }
+ }
+ }
+
+ /* Trigger the Workbook_Open event, event processor will register
+ itself as listener for specific events. */
+ try
+ {
+ uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pShell->GetDocument()->GetVbaEventProcessor(), uno::UNO_SET_THROW );
+ uno::Sequence< uno::Any > aArgs;
+ xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs );
+ }
+ catch( uno::Exception& )
+ {
+ }
+ }
+}
+
SfxItemSet*
ScVbaCellRangeAccess::GetDataSet( ScCellRangesBase* pRangeObj )
{
diff --git a/sc/source/ui/vba/excelvbahelper.hxx b/sc/source/ui/vba/excelvbahelper.hxx
index e8014fe..bf8ae56 100644
--- a/sc/source/ui/vba/excelvbahelper.hxx
+++ b/sc/source/ui/vba/excelvbahelper.hxx
@@ -35,6 +35,7 @@
#include <com/sun/star/table/XCellRange.hpp>
#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
+#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <ooo/vba/XHelperInterface.hpp>
#include <formula/grammar.hxx>
@@ -76,6 +77,7 @@ ScDocShell* GetDocShellFromRange( const css::uno::Reference< css::uno::XInterfac
ScDocShell* GetDocShellFromRanges( const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges ) throw ( css::uno::RuntimeException );
ScDocument* GetDocumentFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException );
css::uno::Reference< css::frame::XModel > GetModelFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException );
+void setUpDocumentModules( const css::uno::Reference< css::sheet::XSpreadsheetDocument >& xDoc );
// ============================================================================
diff --git a/sc/source/ui/vba/vbaworkbooks.cxx b/sc/source/ui/vba/vbaworkbooks.cxx
index 977c334..1e6d0c0 100644
--- a/sc/source/ui/vba/vbaworkbooks.cxx
+++ b/sc/source/ui/vba/vbaworkbooks.cxx
@@ -70,86 +70,6 @@ using namespace ::com::sun::star;
const sal_Int16 CUSTOM_CHAR = 5;
-void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& xDoc )
-{
- uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY );
- ScDocShell* pShell = excel::getDocShell( xModel );
- if ( pShell )
- {
- String aPrjName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
- pShell->GetBasicManager()->SetName( aPrjName );
-
- /* Set library container to VBA compatibility mode. This will create
- the VBA Globals object and store it in the Basic manager of the
- document. */
- uno::Reference<script::XLibraryContainer> xLibContainer = pShell->GetBasicContainer();
- uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW );
- xVBACompat->setVBACompatibilityMode( sal_True );
-
- if( xLibContainer.is() )
- {
- if( !xLibContainer->hasByName( aPrjName ) )
- xLibContainer->createLibrary( aPrjName );
- uno::Any aLibAny = xLibContainer->getByName( aPrjName );
- uno::Reference< container::XNameContainer > xLib;
- aLibAny >>= xLib;
- if( xLib.is() )
- {
- uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW );
- uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY_THROW);
- uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY_THROW );
- // set up the module info for the workbook and sheets in the nealy created
- // spreadsheet
- ScDocument* pDoc = pShell->GetDocument();
- String sCodeName = pDoc->GetCodeName();
- if ( sCodeName.Len() == 0 )
- {
- sCodeName = String( RTL_CONSTASCII_USTRINGPARAM("ThisWorkbook") );
- pDoc->SetCodeName( sCodeName );
- }
-
- std::vector< rtl::OUString > sDocModuleNames;
- sDocModuleNames.push_back( sCodeName );
-
- uno::Reference<container::XNameAccess > xSheets( xDoc->getSheets(), uno::UNO_QUERY_THROW );
- uno::Sequence< rtl::OUString > sSheets( xSheets->getElementNames() );
-
- for ( sal_Int32 index=0; index < sSheets.getLength() ; ++index )
- {
- sDocModuleNames.push_back( sSheets[ index ] );
- }
-
- std::vector<rtl::OUString>::iterator it_end = sDocModuleNames.end();
-
- for ( std::vector<rtl::OUString>::iterator it = sDocModuleNames.begin(); it != it_end; ++it )
- {
- script::ModuleInfo sModuleInfo;
-
- sModuleInfo.ModuleObject.set( xVBACodeNamedObjectAccess->getByName( *it ), uno::UNO_QUERY );
- sModuleInfo.ModuleType = script::ModuleType::DOCUMENT;
- xVBAModuleInfo->insertModuleInfo( *it, sModuleInfo );
- if( xLib->hasByName( *it ) )
- xLib->replaceByName( *it, uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n") ) ) );
- else
- xLib->insertByName( *it, uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n" ) ) ) );
- }
- }
- }
-
- /* Trigger the Workbook_Open event, event processor will register
- itself as listener for specific events. */
- try
- {
- uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents( pShell->GetDocument()->GetVbaEventProcessor(), uno::UNO_SET_THROW );
- uno::Sequence< uno::Any > aArgs;
- xVbaEvents->processVbaEvent( script::vba::VBAEventId::WORKBOOK_OPEN, aArgs );
- }
- catch( uno::Exception& )
- {
- }
- }
-}
-
static uno::Any
getWorkbook( uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSpreadsheetDocument > &xDoc, const uno::Reference< XHelperInterface >& xParent )
{
@@ -254,7 +174,7 @@ ScVbaWorkbooks::Add( const uno::Any& Template ) throw (uno::RuntimeException)
}
// need to set up the document modules ( and vba mode ) here
- setUpDocumentModules( xSpreadDoc );
+ excel::setUpDocumentModules( xSpreadDoc );
if( xSpreadDoc.is() )
return getWorkbook( mxContext, xSpreadDoc, mxParent );
return uno::Any();
diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx
index f3c5bb1..87fb2e9 100644
--- a/sc/source/ui/vba/vbaworksheet.cxx
+++ b/sc/source/ui/vba/vbaworksheet.cxx
@@ -72,6 +72,13 @@
#include <comphelper/processfactory.hxx>
#include <vbahelper/vbashapes.hxx>
+#include <com/sun/star/script/vba/VBAEventId.hpp>
+#include <com/sun/star/script/vba/XVBACompatibility.hpp>
+#include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
+#include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
+#include <com/sun/star/script/ModuleInfo.hpp>
+#include <com/sun/star/script/ModuleType.hpp>
+
#include <tools/string.hxx>
//zhangyun showdataform
@@ -245,12 +252,15 @@ ScVbaWorksheet::createSheetCopyInNewDoc(rtl::OUString aCurrSheetName)
excel::implnPaste(xModel);
}
uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
+ excel::setUpDocumentModules(xSpreadDoc);
uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
- //#TODO #FIXME
- //get proper parent for Worksheet
- return new ScVbaWorksheet( NULL, mxContext, xSheet, xModel );
+
+ ScDocShell* pShell = excel::getDocShell( xModel );
+ String aCodeName;
+ pShell->GetDocument()->GetCodeName( 0, aCodeName );
+ return uno::Reference< excel::XWorksheet >( getUnoDocModule( aCodeName, pShell ), uno::UNO_QUERY_THROW );
}
css::uno::Reference< ov::excel::XWorksheet >
diff --git a/sc/source/ui/vba/vbaworksheets.cxx b/sc/source/ui/vba/vbaworksheets.cxx
index be278b9..2fabece 100644
--- a/sc/source/ui/vba/vbaworksheets.cxx
+++ b/sc/source/ui/vba/vbaworksheets.cxx
@@ -447,8 +447,12 @@ ScVbaWorksheets::Copy ( const uno::Any& Before, const uno::Any& After) throw (cs
xSheet = pSrcSheet->createSheetCopyInNewDoc(xSrcSheet->getName());
nItem = 1;
}
+ else
+ {
+ nItem=0;
+ }
- for (nItem = 0; nItem < nElems; ++nItem )
+ for (; nItem < nElems; ++nItem )
{
xSrcSheet = Sheets[nItem];
ScVbaWorksheet* pSrcSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSrcSheet );
More information about the Libreoffice-commits
mailing list