[Libreoffice-commits] .: Branch 'libreoffice-3-4' - sc/source

Noel Power noelp at kemper.freedesktop.org
Fri Apr 15 07:09:32 PDT 2011


 sc/source/ui/vba/vbaworksheet.cxx  |  117 +++++++++++++++++++++----------------
 sc/source/ui/vba/vbaworksheet.hxx  |    2 
 sc/source/ui/vba/vbaworksheets.cxx |   39 ++++++++++++
 sc/source/ui/vba/vbaworksheets.hxx |    1 
 4 files changed, 110 insertions(+), 49 deletions(-)

New commits:
commit f96c5afd276287d896760e11542918e679069b8c
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Apr 15 13:52:40 2011 +0100

    fix for fdo#34763 add method Copy to ScVbaWorksheets

diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx
index 9348f92..f3c5bb1 100644
--- a/sc/source/ui/vba/vbaworksheet.cxx
+++ b/sc/source/ui/vba/vbaworksheet.cxx
@@ -229,6 +229,72 @@ const uno::Sequence<sal_Int8>& ScVbaWorksheet::getUnoTunnelId()
     return aSeq;
 }
 
+uno::Reference< ov::excel::XWorksheet >
+ScVbaWorksheet::createSheetCopyInNewDoc(rtl::OUString aCurrSheetName)
+{
+    uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
+    uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
+    uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
+    uno::Reference<excel::XRange> xRange =  new ScVbaRange( this, mxContext, xRange1);
+    if (xRange.is())
+        xRange->Select();
+    excel::implnCopy(mxModel);
+    uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
+    if (xModel.is())
+    {
+        excel::implnPaste(xModel);
+    }
+    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> 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 );
+}
+
+css::uno::Reference< ov::excel::XWorksheet >
+ScVbaWorksheet::createSheetCopy(uno::Reference<excel::XWorksheet> xSheet, bool bAfter)
+{
+    rtl::OUString aCurrSheetName = getName();
+    ScVbaWorksheet* pDestSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
+
+    uno::Reference <sheet::XSpreadsheetDocument> xDestDoc( pDestSheet->getModel(), uno::UNO_QUERY );
+    uno::Reference <sheet::XSpreadsheetDocument> xSrcDoc( getModel(), uno::UNO_QUERY );
+
+    SCTAB nDest = 0;
+    SCTAB nSrc = 0;
+    rtl::OUString aSheetName = xSheet->getName();
+    bool bSameDoc = ( pDestSheet->getModel() == getModel() );
+    bool bDestSheetExists = ScVbaWorksheets::nameExists (xDestDoc, aSheetName, nDest );
+    bool bSheetExists = ScVbaWorksheets::nameExists (xSrcDoc, aCurrSheetName, nSrc );
+
+    // set sheet name to be newSheet name
+    aSheetName = aCurrSheetName;
+    if ( bSheetExists && bDestSheetExists )
+    {
+        SCTAB nDummy=0;
+        if(bAfter)
+              nDest++;
+        uno::Reference<sheet::XSpreadsheets> xSheets = xDestDoc->getSheets();
+        if ( bSameDoc || ScVbaWorksheets::nameExists( xDestDoc, aCurrSheetName, nDummy ) )
+            getNewSpreadsheetName(aSheetName,aCurrSheetName,xDestDoc);
+        if ( bSameDoc )
+            xSheets->copyByName(aCurrSheetName,aSheetName,nDest);
+        else
+        {
+            ScDocShell* pDestDocShell = excel::getDocShell( pDestSheet->getModel() );
+            ScDocShell* pSrcDocShell = excel::getDocShell( getModel() );
+            if ( pDestDocShell && pSrcDocShell )
+                pDestDocShell->TransferTab( *pSrcDocShell, static_cast<SCTAB>(nSrc), static_cast<SCTAB>(nDest), true, true );
+        }
+    }
+    // return new sheet
+    uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
+    uno::Reference< excel::XWorksheet > xNewSheet( xApplication->Worksheets( uno::makeAny( aSheetName ) ), uno::UNO_QUERY_THROW );
+    return xNewSheet;
+}
+
 ::rtl::OUString
 ScVbaWorksheet::getName() throw (uno::RuntimeException)
 {
@@ -571,60 +637,13 @@ void
 ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException)
 {
     uno::Reference<excel::XWorksheet> xSheet;
-    rtl::OUString aCurrSheetName =getName();
     if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
     {
-        uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
-        uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
-            uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
-        uno::Reference<excel::XRange> xRange =  new ScVbaRange( this, mxContext, xRange1);
-        if (xRange.is())
-            xRange->Select();
-        excel::implnCopy(mxModel);
-        uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
-        if (xModel.is())
-        {
-            excel::implnPaste(xModel);
-        }
+        createSheetCopyInNewDoc(getName());
         return;
     }
 
-    ScVbaWorksheet* pDestSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
-
-    uno::Reference <sheet::XSpreadsheetDocument> xDestDoc( pDestSheet->getModel(), uno::UNO_QUERY );
-    uno::Reference <sheet::XSpreadsheetDocument> xSrcDoc( getModel(), uno::UNO_QUERY );
-
-    SCTAB nDest = 0;
-    SCTAB nSrc = 0;
-    rtl::OUString aSheetName = xSheet->getName();
-    bool bSameDoc = ( pDestSheet->getModel() == getModel() );
-    bool bDestSheetExists = ScVbaWorksheets::nameExists (xDestDoc, aSheetName, nDest );
-    bool bSheetExists = ScVbaWorksheets::nameExists (xSrcDoc, aCurrSheetName, nSrc );
-
-    // set sheet name to be newSheet name
-    aSheetName = aCurrSheetName;
-    if ( bSheetExists && bDestSheetExists )
-    {
-        SCTAB nDummy=0;
-        sal_Bool bAfter = After.hasValue();
-        if(bAfter)
-              nDest++;
-        uno::Reference<sheet::XSpreadsheets> xSheets = xDestDoc->getSheets();
-        if ( bSameDoc || ScVbaWorksheets::nameExists( xDestDoc, aCurrSheetName, nDummy ) )
-            getNewSpreadsheetName(aSheetName,aCurrSheetName,xDestDoc);
-        if ( bSameDoc )
-            xSheets->copyByName(aCurrSheetName,aSheetName,nDest);
-        else
-        {
-            ScDocShell* pDestDocShell = excel::getDocShell( pDestSheet->getModel() );
-            ScDocShell* pSrcDocShell = excel::getDocShell( getModel() );
-            if ( pDestDocShell && pSrcDocShell )
-                pDestDocShell->TransferTab( *pSrcDocShell, static_cast<SCTAB>(nSrc), static_cast<SCTAB>(nDest), true, true );
-        }
-    }
-    // active the new sheet
-    uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
-    uno::Reference< excel::XWorksheet > xNewSheet( xApplication->Worksheets( uno::makeAny( aSheetName ) ), uno::UNO_QUERY_THROW );
+    uno::Reference<excel::XWorksheet> xNewSheet = createSheetCopy(xSheet, After.hasValue());
     xNewSheet->Activate();
 }
 
diff --git a/sc/source/ui/vba/vbaworksheet.hxx b/sc/source/ui/vba/vbaworksheet.hxx
index b852b60..c9a2425 100644
--- a/sc/source/ui/vba/vbaworksheet.hxx
+++ b/sc/source/ui/vba/vbaworksheet.hxx
@@ -91,6 +91,8 @@ public:
     virtual css::uno::Reference< css::sheet::XSpreadsheet > getSheet()
     { return mxSheet; }
     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
+    css::uno::Reference< ov::excel::XWorksheet > createSheetCopyInNewDoc( rtl::OUString);
+    css::uno::Reference< ov::excel::XWorksheet > createSheetCopy(css::uno::Reference< ov::excel::XWorksheet> xSheet, bool bAfter);
 
     // Attributes
     virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException);
diff --git a/sc/source/ui/vba/vbaworksheets.cxx b/sc/source/ui/vba/vbaworksheets.cxx
index 1a07848..be278b9 100644
--- a/sc/source/ui/vba/vbaworksheets.cxx
+++ b/sc/source/ui/vba/vbaworksheets.cxx
@@ -55,6 +55,8 @@
 #include "vbaworkbook.hxx"
 #include "unonames.hxx"
 
+#include <vector>
+
 using namespace ::ooo::vba;
 using namespace ::com::sun::star;
 
@@ -420,6 +422,43 @@ ScVbaWorksheets::Select( const uno::Any& Replace ) throw (uno::RuntimeException)
 
 }
 
+void SAL_CALL
+ScVbaWorksheets::Copy ( const uno::Any& Before, const uno::Any& After) throw (css::uno::RuntimeException)
+{
+    uno::Reference<excel::XWorksheet> xSheet;
+    sal_Int32 nElems = getCount();
+    bool bAfter = After.hasValue();
+    std::vector< uno::Reference< excel::XWorksheet > > Sheets;
+    sal_Int32 nItem = 0;
+
+    for ( nItem = 1; nItem <= nElems; ++nItem)
+    {
+        uno::Reference<excel::XWorksheet> xWorksheet(Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW );
+        Sheets.push_back(xWorksheet);
+    }
+    bool bNewDoc = (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()));
+
+    uno::Reference< excel::XWorksheet > xSrcSheet;
+    if ( bNewDoc )
+    {
+        bAfter = true;
+        xSrcSheet = Sheets.at(0);
+        ScVbaWorksheet* pSrcSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSrcSheet );
+        xSheet = pSrcSheet->createSheetCopyInNewDoc(xSrcSheet->getName());
+        nItem = 1;
+    }
+
+    for (nItem = 0; nItem < nElems; ++nItem )
+    {
+        xSrcSheet = Sheets[nItem];
+        ScVbaWorksheet* pSrcSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSrcSheet );
+        if ( bAfter )
+            xSheet = pSrcSheet->createSheetCopy(xSheet, bAfter);
+        else
+            pSrcSheet->createSheetCopy(xSheet, bAfter);
+    }
+}
+
 //ScVbaCollectionBaseImpl
 uno::Any SAL_CALL 
 ScVbaWorksheets::Item( const uno::Any& Index, const uno::Any& Index2  ) throw (uno::RuntimeException)
diff --git a/sc/source/ui/vba/vbaworksheets.hxx b/sc/source/ui/vba/vbaworksheets.hxx
index 82001c0..d215cfa 100644
--- a/sc/source/ui/vba/vbaworksheets.hxx
+++ b/sc/source/ui/vba/vbaworksheets.hxx
@@ -72,6 +72,7 @@ public:
     virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ) throw (css::uno::RuntimeException);
     virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); 
     virtual void SAL_CALL Select( const css::uno::Any& Replace ) throw (css::uno::RuntimeException);
+    virtual void SAL_CALL Copy ( const css::uno::Any& Before, const css::uno::Any& After) throw (css::uno::RuntimeException);
     // ScVbaWorksheets_BASE
     virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& Index2 ) throw
 (css::uno::RuntimeException);


More information about the Libreoffice-commits mailing list