summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-03-06 11:03:20 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-03-07 09:36:56 +0100
commit5e2e6b44e2496977397ca79b1599d07ffc4a969f (patch)
treed3037bb6725eebf6e5d551fa68bbf467887b064e /sw
parent0cc4ed1a0323356cc91192a9097be0aa08857efd (diff)
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. (cherry picked from commit 1bca99617ad54d966625caadd71e52134c70ae44) Change-Id: I647d0f3934f9553de69afbf2de059631e2b5619c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164521 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/uibase/dochdl/dochdl.cxx26
-rw-r--r--sw/source/uibase/dochdl/swdtflvr.cxx9
2 files changed, 35 insertions, 0 deletions
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 ea419d2326f7..65f68e27d8c3 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