[Libreoffice-commits] core.git: Branch 'distro/vector/vector-5.4' - offapi/com sw/qa sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Jan 25 08:58:00 UTC 2019
offapi/com/sun/star/text/XPasteListener.idl | 1
sw/qa/extras/unowriter/unowriter.cxx | 35 ++++++++++++++
sw/source/uibase/dochdl/swdtflvr.cxx | 70 +++++++++++++++++++---------
3 files changed, 84 insertions(+), 22 deletions(-)
New commits:
commit 37720fba5cecb8c640d2f003916b27910d0ddf61
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Jan 24 17:01:14 2019 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jan 25 09:44:50 2019 +0100
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).
Reviewed-on: https://gerrit.libreoffice.org/66879
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
(cherry picked from commit 2a054445f09e8ba66e7cfb9f1d598554b555772d)
Conflicts:
sw/qa/extras/unowriter/unowriter.cxx
Change-Id: I717e1358428daba842309260b54f82b62a0aaec1
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 afdc9bb16988..b218b0fc2c26 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -9,9 +9,11 @@
#include <swmodeltestbase.hxx>
#include <com/sun/star/awt/FontSlant.hpp>
+#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;
@@ -25,11 +27,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)
@@ -41,10 +45,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.
@@ -209,6 +227,23 @@ void SwUnoWriter::testPasteListener()
// Make sure that paste overwrote "BC".
CPPUNIT_ASSERT_EQUAL(OUString("ADEDEF"), xBodyText->getString());
+ // Test image paste.
+#if 0
+ // Pre-image-handling-rework image insertion works differently so this
+ // would fail, but manual testing shows the functionality itself is OK.
+ 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());
+#endif
+
// 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 5c732ae22c82..5ec56114b9fd 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -126,6 +126,7 @@
#include <calbck.hxx>
#include <fmtmeta.hxx>
#include <unotextrange.hxx>
+#include <unoframe.hxx>
#include <vcl/GraphicNativeTransform.hxx>
#include <vcl/GraphicNativeMetadata.hxx>
@@ -1143,35 +1144,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());
More information about the Libreoffice-commits
mailing list