diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-01-24 17:01:14 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-01-24 20:57:29 +0100 |
commit | 2a054445f09e8ba66e7cfb9f1d598554b555772d (patch) | |
tree | 9684a7832bc672ce23813fb67a0a4e7bb65823cd /sw/qa/extras/unowriter | |
parent | 78317bc663a0c33bef536b3db98380e64ce32b28 (diff) |
sw paste listener: expose pasted images as well
Do it similar to SwXTextView::getSelection(), so that
SwView::GetShellMode() determines when an image is selected (and
otherwise assume text selection).
Change-Id: I717e1358428daba842309260b54f82b62a0aaec1
Reviewed-on: https://gerrit.libreoffice.org/66879
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa/extras/unowriter')
-rw-r--r-- | sw/qa/extras/unowriter/unowriter.cxx | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index 77186c1d9350..abe80e2ccaf8 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -18,9 +18,11 @@ #include <com/sun/star/awt/XToolkit.hpp> #include <comphelper/propertyvalue.hxx> #include <toolkit/helper/vclunohelper.hxx> +#include <vcl/graphicfilter.hxx> #include <wrtsh.hxx> #include <ndtxt.hxx> #include <swdtflvr.hxx> +#include <view.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -34,11 +36,13 @@ char const DATA_DIRECTORY[] = "/sw/qa/extras/unowriter/data/"; class PasteListener : public cppu::WeakImplHelper<text::XPasteListener> { OUString m_aString; + uno::Reference<text::XTextContent> m_xTextGraphicObject; public: void SAL_CALL notifyPasteEvent(const uno::Sequence<beans::PropertyValue>& rEvent) override; OUString& GetString(); + uno::Reference<text::XTextContent>& GetTextGraphicObject(); }; void PasteListener::notifyPasteEvent(const uno::Sequence<beans::PropertyValue>& rEvent) @@ -50,10 +54,24 @@ void PasteListener::notifyPasteEvent(const uno::Sequence<beans::PropertyValue>& auto xTextRange = it->second.get<uno::Reference<text::XTextRange>>(); if (xTextRange.is()) m_aString = xTextRange->getString(); + return; + } + + it = aMap.find("TextGraphicObject"); + if (it != aMap.end()) + { + auto xTextGraphicObject = it->second.get<uno::Reference<text::XTextContent>>(); + if (xTextGraphicObject.is()) + m_xTextGraphicObject = xTextGraphicObject; } } OUString& PasteListener::GetString() { return m_aString; } + +uno::Reference<text::XTextContent>& PasteListener::GetTextGraphicObject() +{ + return m_xTextGraphicObject; +} } /// Test to assert UNO API call results of Writer. @@ -533,6 +551,19 @@ DECLARE_UNOAPI_TEST(testPasteListener) // Make sure that paste overwrote "BC". CPPUNIT_ASSERT_EQUAL(OUString("ADEDEF"), xBodyText->getString()); + // Test image paste. + SwView& rView = pWrtShell->GetView(); + OUString aGraphicURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "test.jpg"; + rView.InsertGraphic(aGraphicURL, OUString(), /*bAsLink=*/false, + &GraphicFilter::GetGraphicFilter()); + pTransfer->Cut(); + pListener->GetString().clear(); + SwTransferable::Paste(*pWrtShell, aHelper); + // Without the working image listener in place, this test would have + // failed, the listener was not invoked in case of a graphic paste. + CPPUNIT_ASSERT(pListener->GetTextGraphicObject().is()); + CPPUNIT_ASSERT(pListener->GetString().isEmpty()); + // Deregister paste listener, make sure it's not invoked. xBroadcaster->removePasteEventListener(xListener); pListener->GetString().clear(); |