[Libreoffice-commits] core.git: sc/CppunitTest_sc_tiledrendering.mk sc/inc sc/qa sc/source

Henry Castro hcastro at collabora.com
Sun May 27 22:04:02 UTC 2018


 sc/CppunitTest_sc_tiledrendering.mk               |    2 
 sc/inc/scmod.hxx                                  |    8 ---
 sc/qa/unit/tiledrendering/data/RangeCopyPaste.ods |binary
 sc/qa/unit/tiledrendering/tiledrendering.cxx      |   24 +++++++++++
 sc/source/ui/docshell/docsh.cxx                   |   48 ++++++++++++++++++++++
 sc/source/ui/inc/docsh.hxx                        |   11 +++++
 sc/source/ui/vba/excelvbahelper.cxx               |   15 ++++--
 sc/source/ui/vba/vbarange.cxx                     |    3 -
 8 files changed, 97 insertions(+), 14 deletions(-)

New commits:
commit 5f1ce0a77c63df597fba9d4cbd45be3a266343c3
Author: Henry Castro <hcastro at collabora.com>
Date:   Thu May 17 11:12:56 2018 -0400

    sc: release XTransferable2 when used with VBA compatibility helpers
    
    Copy, Cut, PasteSpecial and Insert is used by Range excel object,
    so after finishing executing the VBA script ensure to release XTransferable2
    interface
    
    Change-Id: I967a7ba1a1d101282f7a1b9d4b2e2ac3004f1c07
    Reviewed-on: https://gerrit.libreoffice.org/54497
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Henry Castro <hcastro at collabora.com>

diff --git a/sc/CppunitTest_sc_tiledrendering.mk b/sc/CppunitTest_sc_tiledrendering.mk
index ac70a06453ad..03e33652a69c 100644
--- a/sc/CppunitTest_sc_tiledrendering.mk
+++ b/sc/CppunitTest_sc_tiledrendering.mk
@@ -30,6 +30,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_tiledrendering, \
     scui \
     test \
     unotest \
+    vbahelper \
     vcl \
     tl \
     utl \
@@ -47,6 +48,7 @@ $(eval $(call gb_CppunitTest_set_include,sc_tiledrendering,\
 ))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,sc_tiledrendering))
+$(eval $(call gb_CppunitTest_use_api,sc_tiledrendering,oovbaapi))
 
 $(eval $(call gb_CppunitTest_use_ure,sc_tiledrendering))
 $(eval $(call gb_CppunitTest_use_vcl,sc_tiledrendering))
diff --git a/sc/inc/scmod.hxx b/sc/inc/scmod.hxx
index b2742ddba9a0..1ef0eed7b936 100644
--- a/sc/inc/scmod.hxx
+++ b/sc/inc/scmod.hxx
@@ -82,8 +82,7 @@ class ScModule: public SfxModule, public SfxListener, public utl::ConfigurationL
     ScDragData*         m_pDragData;
     ScSelectionTransferObj* m_pSelTransfer;
     ScMessagePool*      m_pMessagePool;
-    css::uno::Reference<css::datatransfer::XTransferable2> m_xClipData; // Only used by Vba helper functions
-    // there is no global InputHandler anymore, each View has its own
+    // there is no global InputHandler anymore, each View has it's own
     ScInputHandler*     m_pRefInputHandler;
     ScViewCfg*          m_pViewCfg;
     ScDocCfg*           m_pDocCfg;
@@ -175,11 +174,6 @@ public:
     void                SetPrintOptions ( const ScPrintOptions& rOpt );
     void                InsertEntryToLRUList(sal_uInt16 nFIndex);
 
-    SC_DLLPUBLIC const css::uno::Reference<css::datatransfer::XTransferable2> &
-        GetClipData() { return m_xClipData; }
-    SC_DLLPUBLIC void SetClipData(
-        const css::uno::Reference<css::datatransfer::XTransferable2>& xTransferable) { m_xClipData = xTransferable; }
-
     static void         GetSpellSettings( LanguageType& rDefLang, LanguageType& rCjkLang, LanguageType& rCtlLang,
                                           bool& rAutoSpell );
     static void         SetAutoSpellProperty( bool bSet );
diff --git a/sc/qa/unit/tiledrendering/data/RangeCopyPaste.ods b/sc/qa/unit/tiledrendering/data/RangeCopyPaste.ods
new file mode 100644
index 000000000000..9d5e2495a22b
Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/RangeCopyPaste.ods differ
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index cdd9af6df92f..84c8ed3b7ed0 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -94,6 +94,7 @@ public:
     void testMultiViewCopyPaste();
     void testIMESupport();
     void testFilterDlg();
+    void testVbaRangeCopyPaste();
 
     CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
     CPPUNIT_TEST(testRowColumnSelections);
@@ -126,6 +127,7 @@ public:
     CPPUNIT_TEST(testMultiViewCopyPaste);
     CPPUNIT_TEST(testIMESupport);
     CPPUNIT_TEST(testFilterDlg);
+    CPPUNIT_TEST(testVbaRangeCopyPaste);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1651,6 +1653,28 @@ void ScTiledRenderingTest::testFilterDlg()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void ScTiledRenderingTest::testVbaRangeCopyPaste()
+{
+    comphelper::LibreOfficeKit::setActive();
+    ScModelObj* pModelObj = createDoc("RangeCopyPaste.ods");
+    ScDocShell* pDocShell = dynamic_cast< ScDocShell* >( pModelObj->GetEmbeddedObject() );
+    CPPUNIT_ASSERT(pDocShell);
+
+    uno::Any aRet;
+    uno::Sequence< uno::Any > aOutParam;
+    uno::Sequence< uno::Any > aParams;
+    uno::Sequence< sal_Int16 > aOutParamIndex;
+
+    SfxObjectShell::CallXScript(
+        mxComponent,
+        "vnd.sun.Star.script:Standard.Module1.Test_RangeCopyPaste?language=Basic&location=document",
+        aParams, aRet, aOutParamIndex, aOutParam);
+
+    CPPUNIT_ASSERT(!pDocShell->GetClipData().is());
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index b814ddceb6b9..d2ae9a945c18 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -48,7 +48,10 @@
 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
 #include <com/sun/star/document/UpdateDocMode.hpp>
 #include <com/sun/star/script/vba/VBAEventId.hpp>
+#include <com/sun/star/script/vba/VBAScriptEventId.hpp>
 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
+#include <com/sun/star/script/vba/XVBAScriptListener.hpp>
+#include <com/sun/star/script/vba/XVBACompatibility.hpp>
 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
 #include <com/sun/star/task/XJob.hpp>
 #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
@@ -441,6 +444,32 @@ public:
     bool get_active() const { return m_xWarningOnBox->get_active(); }
 };
 
+
+class VBAScriptListener : public ::cppu::WeakImplHelper< css::script::vba::XVBAScriptListener >
+{
+private:
+    ScDocShell* m_pDocSh;
+public:
+    VBAScriptListener(ScDocShell* pDocSh) : m_pDocSh(pDocSh)
+    {
+    }
+
+    // XVBAScriptListener
+    virtual void SAL_CALL notifyVBAScriptEvent( const ::css::script::vba::VBAScriptEvent& aEvent ) override
+    {
+        if (aEvent.Identifier == script::vba::VBAScriptEventId::SCRIPT_STOPPED &&
+            m_pDocSh->GetClipData().is())
+        {
+            m_pDocSh->SetClipData(uno::Reference<datatransfer::XTransferable2>());
+        }
+    }
+
+    // XEventListener
+    virtual void SAL_CALL disposing( const ::css::lang::EventObject& /*Source*/ ) override
+    {
+    }
+};
+
 }
 
 bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const css::uno::Reference< css::embed::XStorage >& xStor )
@@ -688,6 +717,7 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
     else if ( dynamic_cast<const SfxEventHint*>(&rHint) )
     {
         SfxEventHintId nEventId = static_cast<const SfxEventHint*>(&rHint)->GetEventId();
+
         switch ( nEventId )
         {
             case SfxEventHintId::LoadFinished:
@@ -717,6 +747,15 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
                 break;
             case SfxEventHintId::ViewCreated:
                 {
+ #if HAVE_FEATURE_SCRIPTING
+                    uno::Reference<script::vba::XVBACompatibility> xVBACompat(GetBasicContainer(), uno::UNO_QUERY);
+                    if ( !m_xVBAListener.is() && xVBACompat.is() )
+                    {
+                        m_xVBAListener.set(new VBAScriptListener(this));
+                        xVBACompat->addVBAScriptListener(m_xVBAListener);
+                    }
+#endif
+
 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
                     if ( IsDocShared() && !SC_MOD()->IsInSharedDocLoading() )
                     {
@@ -1020,6 +1059,15 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
     }
     else if (rHint.GetId() == SfxHintId::Deinitializing)
     {
+
+#if HAVE_FEATURE_SCRIPTING
+        uno::Reference<script::vba::XVBACompatibility> xVBACompat(GetBasicContainer(), uno::UNO_QUERY);
+        if (m_xVBAListener.is() && xVBACompat.is())
+        {
+            xVBACompat->removeVBAScriptListener(m_xVBAListener);
+        }
+#endif
+
         if (aDocument.IsClipboardSource())
         {
             // Notes copied to the clipboard have a raw SdrCaptionObj pointer
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 2a87e865413b..29fe6de0873d 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -65,6 +65,10 @@ class ScFlatBoolRowSegments;
 class HelperModelObj;
 struct ScColWidthParam;
 
+namespace com { namespace sun { namespace star { namespace script { namespace vba {
+    class XVBAScriptListener;
+} } } } }
+
 namespace sfx2 { class FileDialogHelper; }
 struct DocShell_Impl;
 
@@ -110,6 +114,10 @@ class SC_DLLPUBLIC ScDocShell final: public SfxObjectShell, public SfxListener
 
     ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
 
+    // Only used by Vba helper functions
+    css::uno::Reference<css::script::vba::XVBAScriptListener>   m_xVBAListener;
+    css::uno::Reference<css::datatransfer::XTransferable2>      m_xClipData;
+
     SAL_DLLPRIVATE void          InitItems();
     SAL_DLLPRIVATE void          DoEnterHandler();
     SAL_DLLPRIVATE void          InitOptions(bool bForLoading);
@@ -216,6 +224,9 @@ public:
     ScDocument&     GetDocument()   { return aDocument; }
     ScDocFunc&      GetDocFunc()    { return *pDocFunc; }
 
+    css::uno::Reference<css::datatransfer::XTransferable2> GetClipData() { return m_xClipData; }
+    void SetClipData(const css::uno::Reference<css::datatransfer::XTransferable2>& xTransferable) { m_xClipData = xTransferable; }
+
     SfxPrinter*     GetPrinter( bool bCreateIfNotExist = true );
     sal_uInt16      SetPrinter( VclPtr<SfxPrinter> const & pNewPrinter, SfxPrinterChangeFlags nDiffFlags = SFX_PRINTER_ALL );
 
diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx
index e4cb64b60afa..0bcd3fb9aa0f 100644
--- a/sc/source/ui/vba/excelvbahelper.cxx
+++ b/sc/source/ui/vba/excelvbahelper.cxx
@@ -165,7 +165,8 @@ void
 implnCopy( const uno::Reference< frame::XModel>& xModel )
 {
     ScTabViewShell* pViewShell = getBestViewShell( xModel );
-    if ( pViewShell )
+    ScDocShell* pDocShell = getDocShell( xModel );
+    if ( pViewShell && pDocShell )
     {
         pViewShell->CopyToClip(nullptr,false,false,true);
 
@@ -175,7 +176,7 @@ implnCopy( const uno::Reference< frame::XModel>& xModel )
         if (pClipObj)
         {
             pClipObj->SetUseInApi( true );
-            SC_MOD()->SetClipData(xTransferable);
+            pDocShell->SetClipData(xTransferable);
         }
     }
 }
@@ -184,7 +185,8 @@ void
 implnCut( const uno::Reference< frame::XModel>& xModel )
 {
     ScTabViewShell* pViewShell =  getBestViewShell( xModel );
-    if ( pViewShell )
+    ScDocShell* pDocShell = getDocShell( xModel );
+    if ( pViewShell && pDocShell )
     {
         pViewShell->CutToClip();
 
@@ -194,7 +196,7 @@ implnCut( const uno::Reference< frame::XModel>& xModel )
         if (pClipObj)
         {
             pClipObj->SetUseInApi( true );
-            SC_MOD()->SetClipData(xTransferable);
+            pDocShell->SetClipData(xTransferable);
         }
     }
 }
@@ -204,13 +206,14 @@ void implnPasteSpecial( const uno::Reference< frame::XModel>& xModel, InsertDele
     PasteCellsWarningReseter resetWarningBox;
 
     ScTabViewShell* pTabViewShell = getBestViewShell( xModel );
-    if ( pTabViewShell )
+    ScDocShell* pDocShell = getDocShell( xModel );
+    if ( pTabViewShell && pDocShell )
     {
         ScViewData& rView = pTabViewShell->GetViewData();
         vcl::Window* pWin = rView.GetActiveWin();
         if (pWin)
         {
-            const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(SC_MOD()->GetClipData());
+            const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(pDocShell->GetClipData());
             ScDocument* pDoc = nullptr;
             if ( pOwnClip )
                 pDoc = pOwnClip->GetDocument();
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index acfc39dd4e60..0dfd848a1d8f 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -4687,7 +4687,8 @@ ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& /*CopyOrigin*/ )
 
     // Paste from clipboard only if the clipboard content was copied via VBA, and not already pasted via VBA again.
     // "Insert" behavior should not depend on random clipboard content previously copied by the user.
-    const ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard(SC_MOD()->GetClipData());
+    ScDocShell* pDocShell = getDocShellFromRange( mxRange );
+    const ScTransferObj* pClipObj = pDocShell ? ScTransferObj::GetOwnClipboard(pDocShell->GetClipData()) : nullptr;
     if ( pClipObj && pClipObj->GetUseInApi() )
     {
         // After the insert ( this range ) actually has moved


More information about the Libreoffice-commits mailing list