diff options
-rw-r--r-- | sw/CppunitTest_sw_uibase_dochdl.mk | 73 | ||||
-rw-r--r-- | sw/Module_sw.mk | 1 | ||||
-rw-r--r-- | sw/qa/uibase/dochdl/dochdl.cxx | 75 | ||||
-rw-r--r-- | sw/source/uibase/dochdl/swdtflvr.cxx | 40 | ||||
-rw-r--r-- | sw/source/uibase/inc/swdtflvr.hxx | 3 |
5 files changed, 192 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_uibase_dochdl.mk b/sw/CppunitTest_sw_uibase_dochdl.mk new file mode 100644 index 000000000000..14cf57687a8f --- /dev/null +++ b/sw/CppunitTest_sw_uibase_dochdl.mk @@ -0,0 +1,73 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sw_uibase_dochdl)) + +$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_uibase_dochdl)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sw_uibase_dochdl, \ + sw/qa/uibase/dochdl/dochdl \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sw_uibase_dochdl, \ + comphelper \ + cppu \ + cppuhelper \ + editeng \ + sal \ + sfx \ + svl \ + svx \ + svxcore \ + sw \ + test \ + unotest \ + utl \ + vcl \ +)) + +$(eval $(call gb_CppunitTest_use_externals,sw_uibase_dochdl,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_set_include,sw_uibase_dochdl,\ + -I$(SRCDIR)/sw/inc \ + -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/source/uibase/inc \ + -I$(SRCDIR)/sw/qa/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sw_uibase_dochdl,\ + udkapi \ + offapi \ + oovbaapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sw_uibase_dochdl)) +$(eval $(call gb_CppunitTest_use_vcl,sw_uibase_dochdl)) + +$(eval $(call gb_CppunitTest_use_rdb,sw_uibase_dochdl,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,sw_uibase_dochdl,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sw_uibase_dochdl)) + +$(eval $(call gb_CppunitTest_use_uiconfigs,sw_uibase_dochdl, \ + modules/swriter \ +)) + +$(eval $(call gb_CppunitTest_use_more_fonts,sw_uibase_dochdl)) + +# vim: set noet sw=4 ts=4: diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk index 980f60d7a615..0a8ed36b4b7e 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -108,6 +108,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_core_text \ CppunitTest_sw_core_doc \ CppunitTest_sw_uibase_shells \ + CppunitTest_sw_uibase_dochdl \ CppunitTest_sw_core_accessibilitycheck \ CppunitTest_sw_core_layout \ CppunitTest_sw_core_frmedt \ diff --git a/sw/qa/uibase/dochdl/dochdl.cxx b/sw/qa/uibase/dochdl/dochdl.cxx new file mode 100644 index 000000000000..07e50a78df36 --- /dev/null +++ b/sw/qa/uibase/dochdl/dochdl.cxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <swmodeltestbase.hxx> + +#include <sfx2/dispatch.hxx> +#include <sfx2/viewfrm.hxx> +#include <vcl/GraphicObject.hxx> +#include <svx/svdpage.hxx> +#include <editeng/eeitem.hxx> +#include <editeng/adjustitem.hxx> +#include <editeng/outlobj.hxx> +#include <editeng/editobj.hxx> +#include <vcl/transfer.hxx> + +#include <IDocumentContentOperations.hxx> +#include <cmdid.h> +#include <fmtanchr.hxx> +#include <view.hxx> +#include <wrtsh.hxx> +#include <IDocumentDrawModelAccess.hxx> +#include <drawdoc.hxx> +#include <swdtflvr.hxx> + +/// Covers sw/source/uibase/dochdl/ fixes. +class SwUibaseDochdlTest : public SwModelTestBase +{ +public: + SwDoc* createDoc(); +}; + +SwDoc* SwUibaseDochdlTest::createDoc() +{ + loadURL("private:factory/swriter", nullptr); + + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + return pTextDoc->GetDocShell()->GetDoc(); +} + +CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testSelectPasteFormat) +{ + // Create a new document and cut a character. + SwDoc* pDoc = createDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + pWrtShell->Insert2("x"); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); + rtl::Reference<SwTransferable> pTransfer = new SwTransferable(*pWrtShell); + pTransfer->Cut(); + + // Decide what format to use when doing a Writer->Writer paste and both RTF and ODF is an + // available format. + TransferableDataHelper aHelper(pTransfer.get()); + sal_uInt8 nAction = EXCHG_OUT_ACTION_INSERT_STRING; + SotClipboardFormatId nFormat = SotClipboardFormatId::RICHTEXT; + SwTransferable::SelectPasteFormat(aHelper, nAction, nFormat); + + CPPUNIT_ASSERT_EQUAL(EXCHG_OUT_ACTION_INSERT_OLE, nAction); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 85 (EMBED_SOURCE) + // - Actual : 145 (RICHTEXT) + // i.e. RTF was selected for Writer->Writer out of process copying, which is worse than ODF. + CPPUNIT_ASSERT_EQUAL(SotClipboardFormatId::EMBED_SOURCE, nFormat); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index ea3dcf29db71..b4e91dcec5f0 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -126,6 +126,7 @@ #include <comphelper/lok.hxx> #include <sfx2/classificationhelper.hxx> #include <sfx2/sfxdlg.hxx> +#include <comphelper/classids.hxx> #include <memory> @@ -1352,6 +1353,41 @@ bool SwTransferable::IsPaste( const SwWrtShell& rSh, return bIsPaste; } +void SwTransferable::SelectPasteFormat(TransferableDataHelper& rData, sal_uInt8& nAction, + SotClipboardFormatId& nFormat) +{ + if (nFormat != SotClipboardFormatId::RICHTEXT) + { + return; + } + + if (!rData.HasFormat(SotClipboardFormatId::EMBED_SOURCE)) + { + return; + } + + if (!rData.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR)) + { + return; + } + + TransferableObjectDescriptor aObjDesc; + if (!rData.GetTransferableObjectDescriptor(SotClipboardFormatId::OBJECTDESCRIPTOR, aObjDesc)) + { + return; + } + + if (aObjDesc.maClassName != SvGlobalName(SO3_SW_CLASSID)) + { + return; + } + + // At this point we know that we paste from Writer to Writer and the clipboard has the content + // in both RTF and ODF formats. Prefer ODF in this case. + nAction = EXCHG_OUT_ACTION_INSERT_OLE; + nFormat = SotClipboardFormatId::EMBED_SOURCE; +} + bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndStdIds nAnchorType, bool bIgnoreComments, PasteTableType ePasteTable) { SwPasteContext aPasteContext(rSh); @@ -1531,6 +1567,10 @@ bool SwTransferable::Paste(SwWrtShell& rSh, TransferableDataHelper& rData, RndSt } } + // Tweak the format if necessary: the source application can be considered in this context, + // while not in sot/ code. + SwTransferable::SelectPasteFormat(rData, nAction, nFormat); + collectUIInformation("PASTE", "parameter"); return EXCHG_INOUT_ACTION_NONE != nAction && diff --git a/sw/source/uibase/inc/swdtflvr.hxx b/sw/source/uibase/inc/swdtflvr.hxx index fdb545311351..e231269e7297 100644 --- a/sw/source/uibase/inc/swdtflvr.hxx +++ b/sw/source/uibase/inc/swdtflvr.hxx @@ -237,6 +237,9 @@ public: static const css::uno::Sequence< sal_Int8 >& getUnoTunnelId(); virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& rId ) override; + + static void SelectPasteFormat(TransferableDataHelper& rData, sal_uInt8& nAction, + SotClipboardFormatId& nFormat); }; #endif |