Kaydet (Commit) 5f1ce0a7 authored tarafından Henry Castro's avatar Henry Castro

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/54497Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarHenry Castro <hcastro@collabora.com>
üst 539e8f1d
......@@ -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))
......
......@@ -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 );
......
......@@ -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);
......
......@@ -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
......
......@@ -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 );
......
......@@ -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();
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment