Kaydet (Commit) e06e2cb1 authored tarafından Miklos Vajna's avatar Miklos Vajna

tdf#90575 sw: fix pasting DDE links

Regression from commit 0761f816 (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.

Change-Id: I2b7a07c18b641ac991f3227812a609dedc960e08
üst 16f3ef52
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <com/sun/star/awt/FontWeight.hpp> #include <com/sun/star/awt/FontWeight.hpp>
#include <com/sun/star/drawing/GraphicExportFilter.hpp> #include <com/sun/star/drawing/GraphicExportFilter.hpp>
#include <com/sun/star/i18n/TextConversionOption.hpp> #include <com/sun/star/i18n/TextConversionOption.hpp>
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <swmodeltestbase.hxx> #include <swmodeltestbase.hxx>
#include <ndtxt.hxx> #include <ndtxt.hxx>
#include <wrtsh.hxx> #include <wrtsh.hxx>
...@@ -66,6 +67,7 @@ ...@@ -66,6 +67,7 @@
#include "com/sun/star/text/XTextField.hpp" #include "com/sun/star/text/XTextField.hpp"
#include "com/sun/star/text/TextMarkupType.hpp" #include "com/sun/star/text/TextMarkupType.hpp"
#include <osl/file.hxx> #include <osl/file.hxx>
#include <comphelper/propertysequence.hxx>
static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/"; static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";
...@@ -133,6 +135,7 @@ public: ...@@ -133,6 +135,7 @@ public:
void testUnoCursorPointer(); void testUnoCursorPointer();
void testTextTableCellNames(); void testTextTableCellNames();
void testShapeAnchorUndo(); void testShapeAnchorUndo();
void testDde();
CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward); CPPUNIT_TEST(testReplaceForward);
...@@ -193,6 +196,7 @@ public: ...@@ -193,6 +196,7 @@ public:
CPPUNIT_TEST(testUnoCursorPointer); CPPUNIT_TEST(testUnoCursorPointer);
CPPUNIT_TEST(testTextTableCellNames); CPPUNIT_TEST(testTextTableCellNames);
CPPUNIT_TEST(testShapeAnchorUndo); CPPUNIT_TEST(testShapeAnchorUndo);
CPPUNIT_TEST(testDde);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
...@@ -1999,6 +2003,44 @@ void SwUiWriterTest::testShapeAnchorUndo() ...@@ -1999,6 +2003,44 @@ void SwUiWriterTest::testShapeAnchorUndo()
CPPUNIT_ASSERT(aOrigLogicRect == pObject->GetLogicRect()); CPPUNIT_ASSERT(aOrigLogicRect == pObject->GetLogicRect());
} }
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 = comphelper::InitPropertySequence(
{
{"SelectedFormat", uno::makeAny(static_cast<sal_uInt32>(SotClipboardFormatId::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_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -95,9 +95,8 @@ namespace ...@@ -95,9 +95,8 @@ namespace
ppMark != rMarkAccess.getAllMarksEnd(); ppMark != rMarkAccess.getAllMarksEnd();
++ppMark) ++ppMark)
{ {
if ( IDocumentMarkAccess::GetType( *(ppMark->get()) ) == IDocumentMarkAccess::MarkType::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) if (!pBkmk)
return NULL; return NULL;
if ( if (
......
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