From 29d4ecf32392bc94ab0ba9e73fd79eba65c23fdb Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 29 Mar 2018 18:27:13 +0200 Subject: tdf#115574 sot: fix Excel -> Writer paste Reported problem is that nothing happens for paste. Direct cause is that BITMAP is selected as the format, and Excel advertises BITMAP, but when we try to import that, it fails. There are 3 interesting commits in the recent history for this topic: - commit c47db038f98aaf7aec3cbe57c4e5683591afa23e (fdo#52547 SOT: Prefer embedding image data to embedding linked image., 2014-02-07) was a bugfix due to newer firefox - commit 538c13f3d1756f2d105115f64ab1bc0b7426eebc (fdo#78801 fdo#52547 Paste preference is image, then html, then text., 2014-05-28) was a regression fix from the previous fix - commit a96a7ce51aa98fb9ee97ea3803e2b7e648611008 (fdo#81835 Don't prefer GDI Metafiles to RTF/HTML, 2014-08-05), was a regression fix from the previous fixes Going back to the original state shows that the Excel -> Writer use-case used to be RTF. Restore the old Excel -> Writer (RTF) behavior by: - going back to the original state, ignoring the enum class conversions - re-fix fdo#52547: prefer bitmap over html, but leave everything else unchanged - fdo#78801 needs no fix in this case - fdo#81835 needs no fix in this case - tdf#115574 selects RTF -> table shows up After all these complications, the actual fix is surprisingly simple. Change-Id: I2d728afa7d1dd7888fa43525366c197d806eea6c Reviewed-on: https://gerrit.libreoffice.org/52120 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sot/CppunitTest_sot_test_sot.mk | 5 +++++ sot/inc/sysformats.hxx | 20 ++++++++++++++++++++ sot/qa/cppunit/test_sot.cxx | 37 +++++++++++++++++++++++++++++++++++++ sot/source/base/formats.cxx | 23 ++++++++--------------- 4 files changed, 70 insertions(+), 15 deletions(-) (limited to 'sot') diff --git a/sot/CppunitTest_sot_test_sot.mk b/sot/CppunitTest_sot_test_sot.mk index 7fb75975f1b4..1f550759d86d 100644 --- a/sot/CppunitTest_sot_test_sot.mk +++ b/sot/CppunitTest_sot_test_sot.mk @@ -25,6 +25,11 @@ $(eval $(call gb_CppunitTest_use_libraries,sot_test_sot, \ unotest \ )) +$(eval $(call gb_CppunitTest_set_include,sot_test_sot,\ + -I$(SRCDIR)/sot/inc \ + $$(INCLUDE) \ +)) + $(eval $(call gb_CppunitTest_use_sdk_api,sot_test_sot,)) $(eval $(call gb_CppunitTest_use_ure,sot_test_sot)) diff --git a/sot/inc/sysformats.hxx b/sot/inc/sysformats.hxx index d744be74cfae..c04f8bb8be95 100644 --- a/sot/inc/sysformats.hxx +++ b/sot/inc/sysformats.hxx @@ -24,6 +24,26 @@ #include #endif +#include + +struct SotAction_Impl +{ + SotClipboardFormatId nFormatId; // Clipboard Id + sal_uInt16 nAction; // Action Id + SotExchangeActionFlags nFlags; // Action Id + sal_uInt8 nContextCheckId; // additional check of content in clipboard + + constexpr SotAction_Impl(SotClipboardFormatId _nFormatId, sal_uInt16 _nAction, SotExchangeActionFlags _nFlags, sal_uInt8 _nContextCheckId) + : nFormatId(_nFormatId), nAction(_nAction), nFlags(_nFlags), nContextCheckId(_nContextCheckId) {} + constexpr SotAction_Impl(SotClipboardFormatId _nFormatId, sal_uInt16 _nAction) + : nFormatId(_nFormatId), nAction(_nAction), nFlags(SotExchangeActionFlags::NONE), nContextCheckId(0) {} +}; + +namespace sot +{ +SOT_DLLPUBLIC const SotAction_Impl* GetExchangeDestinationWriterFreeAreaCopy(); +} + #endif // INCLUDED_SOT_SYSFORMATS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sot/qa/cppunit/test_sot.cxx b/sot/qa/cppunit/test_sot.cxx index 0ffbe758a1ec..62fa4b1b5b3b 100644 --- a/sot/qa/cppunit/test_sot.cxx +++ b/sot/qa/cppunit/test_sot.cxx @@ -14,11 +14,30 @@ #include #include #include +#include using namespace ::com::sun::star; namespace { + size_t FindFormatIndex(const SotAction_Impl* pFormats, SotClipboardFormatId eFormat) + { + size_t nRet = 0; + SotClipboardFormatId nId = pFormats->nFormatId; + + while (nId != static_cast(0xffff)) + { + if (nId == eFormat) + break; + + ++pFormats; + ++nRet; + nId = pFormats->nFormatId; + } + + return nRet; + } + class SotTest : public test::FiltersTest , public test::BootstrapFixtureBase @@ -37,10 +56,12 @@ namespace void test(); void testSize(); + void testClipboard(); CPPUNIT_TEST_SUITE(SotTest); CPPUNIT_TEST(test); CPPUNIT_TEST(testSize); + CPPUNIT_TEST(testClipboard); CPPUNIT_TEST_SUITE_END(); }; @@ -144,6 +165,22 @@ namespace CPPUNIT_ASSERT_EQUAL_MESSAGE("stream not at beginning", static_cast(0), xStream->Tell()); } + void SotTest::testClipboard() + { + const SotAction_Impl* pFormats = sot::GetExchangeDestinationWriterFreeAreaCopy(); + // tdf#52547 prefer BITMAP over HTML + CPPUNIT_ASSERT(FindFormatIndex(pFormats, SotClipboardFormatId::BITMAP) < FindFormatIndex(pFormats, SotClipboardFormatId::HTML)); + // tdf#78801 prefer imager over html over text + CPPUNIT_ASSERT(FindFormatIndex(pFormats, SotClipboardFormatId::BITMAP) < FindFormatIndex(pFormats, SotClipboardFormatId::HTML)); + CPPUNIT_ASSERT(FindFormatIndex(pFormats, SotClipboardFormatId::HTML) < FindFormatIndex(pFormats, SotClipboardFormatId::STRING)); + // tdf#81835 prefer RTF/HTML over GDI Metafile + CPPUNIT_ASSERT(FindFormatIndex(pFormats, SotClipboardFormatId::RTF) < FindFormatIndex(pFormats, SotClipboardFormatId::GDIMETAFILE)); + CPPUNIT_ASSERT(FindFormatIndex(pFormats, SotClipboardFormatId::HTML) < FindFormatIndex(pFormats, SotClipboardFormatId::GDIMETAFILE)); + // tdf#115574 prefer RTF over BITMAP (Excel provides a BITMAP we can't + // read, also Excel paste result used to be an editable table) + CPPUNIT_ASSERT(FindFormatIndex(pFormats, SotClipboardFormatId::RTF) < FindFormatIndex(pFormats, SotClipboardFormatId::BITMAP)); + } + CPPUNIT_TEST_SUITE_REGISTRATION(SotTest); } diff --git a/sot/source/base/formats.cxx b/sot/source/base/formats.cxx index afdb25674f0c..692798b5f19e 100644 --- a/sot/source/base/formats.cxx +++ b/sot/source/base/formats.cxx @@ -34,20 +34,6 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::datatransfer; -struct SotAction_Impl -{ - SotClipboardFormatId nFormatId; // Clipboard Id - sal_uInt16 nAction; // Action Id - SotExchangeActionFlags nFlags; // Action Id - sal_uInt8 nContextCheckId; // additional check of content in clipboard - - constexpr SotAction_Impl(SotClipboardFormatId _nFormatId, sal_uInt16 _nAction, SotExchangeActionFlags _nFlags, sal_uInt8 _nContextCheckId) - : nFormatId(_nFormatId), nAction(_nAction), nFlags(_nFlags), nContextCheckId(_nContextCheckId) {} - constexpr SotAction_Impl(SotClipboardFormatId _nFormatId, sal_uInt16 _nAction) - : nFormatId(_nFormatId), nAction(_nAction), nFlags(SotExchangeActionFlags::NONE), nContextCheckId(0) {} -}; - - // define a context check Id for every formatid #define FILEGRPDSC_ONLY_URL 1 @@ -894,13 +880,13 @@ SotAction_Impl const aEXCHG_DEST_SWDOC_FREE_AREA_Copy[] = { SotClipboardFormatId::SD_OLE, EXCHG_OUT_ACTION_INSERT_OLE, SotExchangeActionFlags::InsertImageMap | SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::EMBED_SOURCE, EXCHG_OUT_ACTION_INSERT_OLE, SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::EMBEDDED_OBJ, EXCHG_OUT_ACTION_INSERT_OLE, SotExchangeActionFlags::InsertTargetUrl, 0 }, + { SotClipboardFormatId::RTF, EXCHG_IN_ACTION_COPY, SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::PNG, EXCHG_OUT_ACTION_INSERT_BITMAP, SotExchangeActionFlags::InsertImageMap | SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::JPEG, EXCHG_OUT_ACTION_INSERT_BITMAP, SotExchangeActionFlags::InsertImageMap | SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::BITMAP, EXCHG_OUT_ACTION_INSERT_BITMAP, SotExchangeActionFlags::InsertImageMap | SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::HTML, EXCHG_OUT_ACTION_INSERT_HTML, SotExchangeActionFlags::InsertImageMap | SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::HTML_NO_COMMENT, EXCHG_OUT_ACTION_INSERT_HTML, SotExchangeActionFlags::InsertImageMap | SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::HTML_SIMPLE, EXCHG_OUT_ACTION_INSERT_HTML, SotExchangeActionFlags::InsertImageMap | SotExchangeActionFlags::InsertTargetUrl, 0 }, - { SotClipboardFormatId::RTF, EXCHG_IN_ACTION_COPY, SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::NETSCAPE_IMAGE, EXCHG_IN_ACTION_COPY, SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::STRING, EXCHG_OUT_ACTION_INSERT_STRING, SotExchangeActionFlags::InsertTargetUrl, 0 }, { SotClipboardFormatId::NETSCAPE_BOOKMARK, EXCHG_OUT_ACTION_INSERT_HYPERLINK, SotExchangeActionFlags::InsertImageMap | SotExchangeActionFlags::InsertTargetUrl, 0 }, @@ -1314,6 +1300,13 @@ SotDestinationEntry_Impl const aDestinationArray[] = } // namespace +namespace sot +{ +const SotAction_Impl* GetExchangeDestinationWriterFreeAreaCopy() +{ + return aEXCHG_DEST_SWDOC_FREE_AREA_Copy; +} +} // - new style GetExchange methods - -- cgit v1.2.3