summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2019-02-14 10:34:35 +0100
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2019-02-19 13:44:47 +0100
commit09a87abbb17bbfec2eeb8da71fa54052d1200a5d (patch)
tree3ad935c2c932cd4cd254bab0feca772f74c296f3 /sc
parent75992180c5a88a6b1faaa4676e1b348944a0f361 (diff)
tdf#122982 Remove image from cell when cutting the cell
Change-Id: Idd73dcc88a8cd76eb4011bb26efdd5c712d16e5e Reviewed-on: https://gerrit.libreoffice.org/67844 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> (cherry picked from commit e756b6f310f309ac29bb2bce92309bb74edd788d) Reviewed-on: https://gerrit.libreoffice.org/67852 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/extras/anchor.cxx61
-rw-r--r--sc/source/core/data/drwlayer.cxx15
2 files changed, 72 insertions, 4 deletions
diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx
index 35cd9a567d35..89b4c864dd32 100644
--- a/sc/qa/extras/anchor.cxx
+++ b/sc/qa/extras/anchor.cxx
@@ -41,12 +41,14 @@ public:
void testTdf76183();
void testODFAnchorTypes();
void testCopyColumnWithImages();
+ void testCutWithImages();
CPPUNIT_TEST_SUITE(ScAnchorTest);
CPPUNIT_TEST(testUndoAnchor);
CPPUNIT_TEST(testTdf76183);
CPPUNIT_TEST(testODFAnchorTypes);
CPPUNIT_TEST(testCopyColumnWithImages);
+ CPPUNIT_TEST(testCutWithImages);
CPPUNIT_TEST_SUITE_END();
private:
@@ -308,6 +310,65 @@ void ScAnchorTest::testCopyColumnWithImages()
pDocSh->DoClose();
}
+void ScAnchorTest::testCutWithImages()
+{
+ OUString aFileURL;
+ createFileURL("3AnchorTypes.ods", aFileURL);
+ // open the document with graphic included
+ uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
+ CPPUNIT_ASSERT(xComponent.is());
+
+ // Get the document model
+ SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
+ CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+
+ ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+ CPPUNIT_ASSERT(pDocSh);
+
+ ScDocument* pDoc = &(pDocSh->GetDocument());
+ ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
+ CPPUNIT_ASSERT(pDrawLayer);
+
+ // Get the document controller
+ ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false);
+ CPPUNIT_ASSERT(pViewShell != nullptr);
+
+ // Cut whole column
+ {
+ // Cut source range
+ ScRange aSrcRange;
+ aSrcRange.Parse("A1:A11", pDoc, pDoc->GetAddressConvention());
+ pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
+ pViewShell->GetViewData().GetView()->CutToClip();
+
+ std::map<SCROW, std::vector<SdrObject*>> aRowObjects
+ = pDrawLayer->GetObjectsAnchoredToRange(0, 0, 0, 11);
+
+ // Images should have been removed from the cells
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to A3", 0,
+ static_cast<int>(aRowObjects[2].size()));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to A11", 0,
+ static_cast<int>(aRowObjects[10].size()));
+ }
+
+ // Cut individual cells
+ {
+ // Cut source cells
+ ScRange aSrcRange;
+ aSrcRange.Parse("A3:B3", pDoc, pDoc->GetAddressConvention());
+ pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
+ pViewShell->GetViewData().GetView()->CutToClip();
+
+ // Image should have been removed from the cell
+ std::map<SCROW, std::vector<SdrObject*>> aRowObjects
+ = pDrawLayer->GetObjectsAnchoredToRange(0, 0, 2, 2);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to A3", 0,
+ static_cast<int>(aRowObjects[2].size()));
+ }
+
+ pDocSh->DoClose();
+}
+
void ScAnchorTest::tearDown()
{
if (mxComponent.is())
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 540e320d1999..1ee022fc8b25 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -1438,11 +1438,18 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
if (!IsNoteCaption( pObject ))
{
tools::Rectangle aObjRect = pObject->GetCurrentBoundRect();
- if ( aMarkBound.IsInside( aObjRect ) )
+ ScRange aRange = pDoc->GetRange(nTab, aObjRect);
+ bool bObjectInMarkArea
+ = aMarkBound.IsInside(aObjRect) && rMark.IsAllMarked(aRange);
+ const ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pObject);
+ ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType(*pObject);
+ bool bObjectAnchoredToMarkedCell
+ = ((aAnchorType == SCA_CELL || aAnchorType == SCA_CELL_RESIZE)
+ && rMark.IsCellMarked(pObjData->maStart.Col(),
+ pObjData->maStart.Row()));
+ if (bObjectInMarkArea || bObjectAnchoredToMarkedCell)
{
- ScRange aRange = pDoc->GetRange( nTab, aObjRect );
- if (rMark.IsAllMarked(aRange))
- ppObj[nDelCount++] = pObject;
+ ppObj[nDelCount++] = pObject;
}
}