summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-01-24 17:01:14 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-01-24 20:57:29 +0100
commit2a054445f09e8ba66e7cfb9f1d598554b555772d (patch)
tree9684a7832bc672ce23813fb67a0a4e7bb65823cd
parent78317bc663a0c33bef536b3db98380e64ce32b28 (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
-rw-r--r--offapi/com/sun/star/text/XPasteListener.idl1
-rw-r--r--sw/qa/extras/unowriter/unowriter.cxx31
-rw-r--r--sw/source/uibase/dochdl/swdtflvr.cxx70
3 files changed, 80 insertions, 22 deletions
diff --git a/offapi/com/sun/star/text/XPasteListener.idl b/offapi/com/sun/star/text/XPasteListener.idl
index ce5d663f4ccd..b1a98cae5b12 100644
--- a/offapi/com/sun/star/text/XPasteListener.idl
+++ b/offapi/com/sun/star/text/XPasteListener.idl
@@ -29,6 +29,7 @@ interface XPasteListener : com::sun::star::uno::XInterface
<p>The following keys may be used:
<ul>
<li>TextRange</li>
+ <li>TextGraphicObject</li>
</ul></p>
*/
void notifyPasteEvent([in] sequence< ::com::sun::star::beans::PropertyValue > aEvent);
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();
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index c7aa43238729..0c99d8424688 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -126,6 +126,7 @@
#include <itabenum.hxx>
#include <iodetect.hxx>
#include <unotextrange.hxx>
+#include <unoframe.hxx>
#include <vcl/GraphicNativeTransform.hxx>
#include <vcl/GraphicNativeMetadata.hxx>
@@ -1125,35 +1126,60 @@ SwPasteContext::~SwPasteContext()
if (m_rWrtShell.GetPasteListeners().getLength() == 0)
return;
- if (!m_pPaM)
- return;
+ beans::PropertyValue aPropertyValue;
- SwPaM* pCursor = m_rWrtShell.GetCursor();
- if (!pCursor)
- return;
+ switch (m_rWrtShell.GetView().GetShellMode())
+ {
+ case ShellMode::Graphic:
+ {
+ SwFrameFormat* pFormat = m_rWrtShell.GetFlyFrameFormat();
+ if (!pFormat)
+ return;
- if (!pCursor->GetPoint()->nNode.GetNode().IsTextNode())
- // Non-text was pasted.
- return;
+ aPropertyValue.Name = "TextGraphicObject";
+ aPropertyValue.Value
+ <<= SwXTextGraphicObject::CreateXTextGraphicObject(*pFormat->GetDoc(), pFormat);
+ break;
+ }
- // Update mark after paste.
- *m_pPaM->GetMark() = *pCursor->GetPoint();
+ default:
+ {
+ if (!m_pPaM)
+ return;
- // Restore point.
- ++m_pPaM->GetPoint()->nNode;
- SwNode& rNode = m_pPaM->GetNode();
- if (!rNode.IsTextNode())
- // Starting point is no longer text.
- return;
+ SwPaM* pCursor = m_rWrtShell.GetCursor();
+ if (!pCursor)
+ return;
- m_pPaM->GetPoint()->nContent.Assign(static_cast<SwContentNode*>(&rNode), m_nStartContent);
+ if (!pCursor->GetPoint()->nNode.GetNode().IsTextNode())
+ // Non-text was pasted.
+ return;
+
+ // Update mark after paste.
+ *m_pPaM->GetMark() = *pCursor->GetPoint();
+
+ // Restore point.
+ ++m_pPaM->GetPoint()->nNode;
+ SwNode& rNode = m_pPaM->GetNode();
+ if (!rNode.IsTextNode())
+ // Starting point is no longer text.
+ return;
+
+ m_pPaM->GetPoint()->nContent.Assign(static_cast<SwContentNode*>(&rNode),
+ m_nStartContent);
+
+ aPropertyValue.Name = "TextRange";
+ const uno::Reference<text::XTextRange> xTextRange = SwXTextRange::CreateXTextRange(
+ *m_pPaM->GetDoc(), *m_pPaM->GetPoint(), m_pPaM->GetMark());
+ aPropertyValue.Value <<= xTextRange;
+ break;
+ }
+ }
+
+ if (aPropertyValue.Name.isEmpty())
+ return;
// Invoke the listeners.
- beans::PropertyValue aPropertyValue;
- aPropertyValue.Name = "TextRange";
- const uno::Reference<text::XTextRange> xTextRange = SwXTextRange::CreateXTextRange(
- *m_pPaM->GetDoc(), *m_pPaM->GetPoint(), m_pPaM->GetMark());
- aPropertyValue.Value <<= xTextRange;
uno::Sequence<beans::PropertyValue> aEvent{ aPropertyValue };
comphelper::OInterfaceIteratorHelper2 it(m_rWrtShell.GetPasteListeners());