summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-07-27 09:16:16 +0200
committerCaolán McNamara <caolanm@redhat.com>2015-08-17 20:15:03 +0000
commitc7498f49e981e91ae45da12bbc2823da254b9c5d (patch)
treefd0d4c6734595b79ec08f6e08795ccbf98f45434
parentfe1792bd24b45f6b2e5dc21cbf2a8744f8c42f17 (diff)
tdf#90575 sw: fix pasting DDE links
Regression from commit 0761f81643a6890457e9ef7d913ab5c88c2593a4 (123792: complete annotations on text ranges feature, 2013-12-19), the problem was that the added additional IDocumentMarkAccess::GetType() check in lcl_FindDdeBookmark(), which means that the function no longer finds bookmarks with the matching name, only real DDE marks. This is a problem, as SwTrnsfrDdeLink::WriteData() depends on the fact that sw::mark::Bookmark inherits from sw::mark::DdeBookmark. As a result, the fast IDocumentMarkAccess::GetType() (that intentionally doesn't handle inheritance for performance reasons) can't be used here. (cherry picked from commit e06e2cb18874987d2dafd4faa0a8b71fc0aa6453) Conflicts: sw/qa/extras/uiwriter/uiwriter.cxx sw/source/core/doc/DocumentLinksAdministrationManager.cxx Change-Id: I2b7a07c18b641ac991f3227812a609dedc960e08 Reviewed-on: https://gerrit.libreoffice.org/17809 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx40
-rw-r--r--sw/source/core/doc/DocumentLinksAdministrationManager.cxx3
2 files changed, 41 insertions, 2 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 512095ec4da8..b7d0157149a8 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -7,6 +7,7 @@
*/
#include <com/sun/star/i18n/TextConversionOption.hpp>
+#include <com/sun/star/frame/DispatchHelper.hpp>
#include <swmodeltestbase.hxx>
#include <ndtxt.hxx>
#include <wrtsh.hxx>
@@ -59,6 +60,7 @@ public:
void testFdo85554();
void testBookmarkUndo();
void testCp1000115();
+ void testDde();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -84,6 +86,7 @@ public:
CPPUNIT_TEST(testFdo85554);
CPPUNIT_TEST(testBookmarkUndo);
CPPUNIT_TEST(testCp1000115);
+ CPPUNIT_TEST(testDde);
CPPUNIT_TEST_SUITE_END();
@@ -639,6 +642,43 @@ void SwUiWriterTest::testCp1000115()
xmlXPathFreeObject(pXmlObj);
}
+void lcl_dispatchCommand(const uno::Reference<lang::XComponent>& xComponent, const OUString& rCommand, const uno::Sequence<beans::PropertyValue>& rPropertyValues)
+{
+ uno::Reference<frame::XController> xController = uno::Reference<frame::XModel>(xComponent, uno::UNO_QUERY)->getCurrentController();
+ CPPUNIT_ASSERT(xController.is());
+ uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xFrame.is());
+
+ uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
+ uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext));
+ CPPUNIT_ASSERT(xDispatchHelper.is());
+
+ xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
+}
+
+void SwUiWriterTest::testDde()
+{
+ // Type asdf and copy it.
+ SwDoc* pDoc = createDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->Insert("asdf");
+ pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 4, /*bBasicCall=*/false);
+ uno::Sequence<beans::PropertyValue> aPropertyValues;
+ lcl_dispatchCommand(mxComponent, ".uno:Copy", aPropertyValues);
+
+ // Go before the selection and paste as a DDE link.
+ pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false);
+ aPropertyValues = uno::Sequence<beans::PropertyValue>(1);
+ aPropertyValues[0].Name = "SelectedFormat";
+ aPropertyValues[0].Value = uno::makeAny(static_cast<sal_uInt32>(SOT_FORMATSTR_ID_LINK));
+ lcl_dispatchCommand(mxComponent, ".uno:ClipboardFormatItems", aPropertyValues);
+
+ // Make sure that the document starts with a field now, and its expanded string value contains asdf.
+ const uno::Reference< text::XTextRange > xField = getRun(getParagraph(1), 1);
+ CPPUNIT_ASSERT_EQUAL(OUString("TextField"), getProperty<OUString>(xField, "TextPortionType"));
+ CPPUNIT_ASSERT(xField->getString().endsWith("asdf"));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
index 086dd42e5492..17f2d3385f4a 100644
--- a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
+++ b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx
@@ -98,9 +98,8 @@ namespace
ppMark != rMarkAccess.getAllMarksEnd();
++ppMark)
{
- if ( IDocumentMarkAccess::GetType( *(ppMark->get()) ) == IDocumentMarkAccess::DDE_BOOKMARK)
+ if (::sw::mark::DdeBookmark* const pBkmk = dynamic_cast< ::sw::mark::DdeBookmark*>(ppMark->get()))
{
- ::sw::mark::DdeBookmark* const pBkmk = dynamic_cast< ::sw::mark::DdeBookmark*>(ppMark->get());
if (!pBkmk)
return NULL;
if (