sw/qa/uibase/dochdl/dochdl.cxx | 26 ++++++++++++++++++++++++++ sw/source/uibase/dochdl/swdtflvr.cxx | 9 +++++++++ 2 files changed, 35 insertions(+)
New commits: commit 1bca99617ad54d966625caadd71e52134c70ae44 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Mar 6 11:03:20 2024 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Mar 6 16:11:22 2024 +0100 cool#8465 sw lok: classify anchored images as complex selection Regression from commit 7a8dc25defee31edbb75a2f8c35f92ee2d3f3a83 (sw lok: simplify SwTransferable::isComplex(), 2021-02-23), in case as-char imagse were part of a selection, we considered that complex, but at-char was considered as simple, which is inconsistent. This was not intentional, simply the rework to avoid copying the selection to a temporary document lost this functionality. Fix the problem by using CollectFrameAtNode() to find at-char images, which tries to use the layout, so is not meant to be too slow. An alternative would be sw::GetFlysAnchoredAt(), but that doesn't try to use the layout, so avoid that. Change-Id: I647d0f3934f9553de69afbf2de059631e2b5619c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164453 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/uibase/dochdl/dochdl.cxx b/sw/qa/uibase/dochdl/dochdl.cxx index 95314b48be1f..2c209a65d3d9 100644 --- a/sw/qa/uibase/dochdl/dochdl.cxx +++ b/sw/qa/uibase/dochdl/dochdl.cxx @@ -18,6 +18,7 @@ #include <swdtflvr.hxx> #include <wrtsh.hxx> #include <view.hxx> +#include <fmtanchr.hxx> /// Covers sw/source/uibase/dochdl/ fixes. class SwUibaseDochdlTest : public SwModelTestBase @@ -76,6 +77,31 @@ CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testComplexSelection) CPPUNIT_ASSERT(!xTransfer->isComplex()); } +CPPUNIT_TEST_FIXTURE(SwUibaseDochdlTest, testComplexSelectionAtChar) +{ + // Given a document with an at-char anchored image: + createSwDoc(); + SwDoc* pDoc = getSwDoc(); + SwDocShell* pDocShell = pDoc->GetDocShell(); + SwWrtShell* pWrtShell = pDocShell->GetWrtShell(); + SfxItemSet aFrameSet(pDoc->GetAttrPool(), svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>); + SwFormatAnchor aAnchor(RndStdIds::FLY_AT_CHAR); + aFrameSet.Put(aAnchor); + Graphic aGrf; + pWrtShell->SwFEShell::Insert(OUString(), OUString(), &aGrf, &aFrameSet); + pWrtShell->UnSelectFrame(); + + // When checking if the selection is simple or complex: + pWrtShell->SelAll(); + uno::Reference<datatransfer::XTransferable2> xTransfer = new SwTransferable(*pWrtShell); + bool bComplex = xTransfer->isComplex(); + + // Then make sure it's complex: + // Without the accompanying fix in place, this test would have failed, a selection containing an + // image was considered simple. + CPPUNIT_ASSERT(bComplex); +} + 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 cb8748a73cd0..a862c7dd90b8 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -122,6 +122,7 @@ #include <unotextrange.hxx> #include <unoframe.hxx> #include <txatbase.hxx> +#include <unoparaframeenum.hxx> #include <vcl/uitest/logger.hxx> #include <vcl/uitest/eventdescription.hxx> @@ -459,6 +460,14 @@ sal_Bool SAL_CALL SwTransferable::isComplex() } } + FrameClientSortList_t vFrames; + ::CollectFrameAtNode(rNd, vFrames, true); + if (!vFrames.empty()) + { + // There is an at-char anchored object to this node, that's complex. + return true; + } + nTextLength += pTextNode->GetText().getLength(); if (nTextLength >= 1024 * 512) return true; // Complex