sc/qa/extras/anchor.cxx | 75 +++++++++++++++++++++++++++++++++++++++++ sc/source/core/data/table7.cxx | 22 ++++++++++++ 2 files changed, 97 insertions(+)
New commits: commit 53e39ecdcdb352cb3b60b6948f000324130b252e Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> Date: Wed Apr 4 16:24:27 2018 +0200 tdf#116510 Unit test for copying graphics from individual cells Change-Id: I2471650a50a980129672f3a5f0439753b25eebd6 Reviewed-on: https://gerrit.libreoffice.org/52391 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> (cherry picked from commit 6a2e5833f97890ad3b980955626d53622d57377d) diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx index 6aaab3e6db32..942e9a467209 100644 --- a/sc/qa/extras/anchor.cxx +++ b/sc/qa/extras/anchor.cxx @@ -124,25 +124,49 @@ void ScAnchorTest::testCopyColumnWithImages() ScDocument aClipDoc(SCDOCMODE_CLIP); - // 1. Copy source range - ScRange aSrcRange; - aSrcRange.Parse("A1:A11", pDoc, pDoc->GetAddressConvention()); - pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); - pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, true, false); - - // 2. Paste to target range - ScRange aDstRange; - aDstRange.Parse("D1:D11", pDoc, pDoc->GetAddressConvention()); - pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange); - pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc); - - // 3. Make sure the images have been copied too - std::map<SCROW, std::vector<SdrObject*>> aRowObjects - = pDrawLayer->GetObjectsAnchoredToRange(0, 3, 0, 11); - CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D:3", 1, - static_cast<int>(aRowObjects[2].size())); - CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D:11", 1, - static_cast<int>(aRowObjects[10].size())); + // Copy whole column + { + // 1. Copy source range + ScRange aSrcRange; + aSrcRange.Parse("A1:A11", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, true, false); + + // 2. Paste to target range + ScRange aDstRange; + aDstRange.Parse("D1:D11", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange); + pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc); + + // 3. Make sure the images have been copied too + std::map<SCROW, std::vector<SdrObject*>> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 3, 0, 11); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D3", 1, + static_cast<int>(aRowObjects[2].size())); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D11", 1, + static_cast<int>(aRowObjects[10].size())); + } + + // Copy individual cells + { + // 1. Copy source cells + ScRange aSrcRange; + aSrcRange.Parse("A3:B3", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, true, false); + + // 2. Paste to target cells + ScRange aDstRange; + aDstRange.Parse("G3:H3", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange); + pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc); + + // 3. Make sure the image has been copied too + std::map<SCROW, std::vector<SdrObject*>> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 6, 2, 2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to G3", 1, + static_cast<int>(aRowObjects[2].size())); + } pDocSh->DoClose(); } commit 3ca992b17fd06c7d068d4d647e303ad2d09fbf0d Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> Date: Mon Mar 26 11:24:07 2018 +0200 tdf#116510 Unit test for copying columns with images anchored to cells Change-Id: I194252bb07842dbc0376da5a143e93b557bcc04d Reviewed-on: https://gerrit.libreoffice.org/51860 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Jenkins <c...@libreoffice.org> (cherry picked from commit 8766bb000afceb4a070ef310b939f7250e5c3a8a) diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx index fb50fab9243a..6aaab3e6db32 100644 --- a/sc/qa/extras/anchor.cxx +++ b/sc/qa/extras/anchor.cxx @@ -37,10 +37,12 @@ public: virtual void tearDown() override; void testODFAnchorTypes(); + void testCopyColumnWithImages(); CPPUNIT_TEST_SUITE(ScAnchorTest); CPPUNIT_TEST(testODFAnchorTypes); + CPPUNIT_TEST(testCopyColumnWithImages); CPPUNIT_TEST_SUITE_END(); private: @@ -96,6 +98,55 @@ void ScAnchorTest::testODFAnchorTypes() pDocSh->DoClose(); } +/// Test that copying a column with an image anchored to it also copies the image +void ScAnchorTest::testCopyColumnWithImages() +{ + 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); + + ScDocument aClipDoc(SCDOCMODE_CLIP); + + // 1. Copy source range + ScRange aSrcRange; + aSrcRange.Parse("A1:A11", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange); + pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, true, false); + + // 2. Paste to target range + ScRange aDstRange; + aDstRange.Parse("D1:D11", pDoc, pDoc->GetAddressConvention()); + pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange); + pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc); + + // 3. Make sure the images have been copied too + std::map<SCROW, std::vector<SdrObject*>> aRowObjects + = pDrawLayer->GetObjectsAnchoredToRange(0, 3, 0, 11); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D:3", 1, + static_cast<int>(aRowObjects[2].size())); + CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to D:11", 1, + static_cast<int>(aRowObjects[10].size())); + + pDocSh->DoClose(); +} + void ScAnchorTest::tearDown() { if (mxComponent.is()) commit 5a11b48d582b7cd06d6d706210eae658de4b743e Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> Date: Tue Apr 3 09:31:34 2018 +0200 tdf#116510 Copy graphics too when copying cells/rows Before this worked only for columns Reviewed-on: https://gerrit.libreoffice.org/52380 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> (cherry picked from commit 8e49269f794f6eae193fa9af8846a470baab0c1b) Change-Id: I0e2c54aa85455d5fe3ec7ae78638e1b1157e4a9c diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx index 067cbdcd648b..81aa6dde3a4a 100644 --- a/sc/source/core/data/table7.cxx +++ b/sc/source/core/data/table7.cxx @@ -16,6 +16,7 @@ #include <sharedformula.hxx> #include <cellvalues.hxx> #include "olinetab.hxx" +#include <drwlayer.hxx> bool ScTable::IsMerged( SCCOL nCol, SCROW nRow ) const { @@ -68,6 +69,27 @@ void ScTable::CopyOneCellFromClip( if (nCol1 == 0 && nCol2 == MAXCOL && mpRowHeights) mpRowHeights->setValue(nRow1, nRow2, pSrcTab->GetOriginalHeight(nSrcRow)); + + // Copy graphics over too + bool bCopyGraphics + = (rCxt.getInsertFlag() & InsertDeleteFlags::OBJECTS) != InsertDeleteFlags::NONE; + if (bCopyGraphics && rCxt.getClipDoc()->pDrawLayer) + { + ScDrawLayer* pDrawLayer = GetDoc().GetDrawLayer(); + OSL_ENSURE(pDrawLayer, "No drawing layer"); + if (pDrawLayer) + { + const ScAddress& rSrcStartPos + = rCxt.getClipDoc()->GetClipParam().getWholeRange().aStart; + const ScAddress& rSrcEndPos = rCxt.getClipDoc()->GetClipParam().getWholeRange().aEnd; + Rectangle aSourceRect = rCxt.getClipDoc()->GetMMRect( + rSrcStartPos.Col(), rSrcStartPos.Row(), rSrcEndPos.Col(), rSrcEndPos.Row(), + rSrcStartPos.Tab()); + Rectangle aDestRect = GetDoc().GetMMRect(nCol1, nRow1, nCol2, nRow2, nTab); + pDrawLayer->CopyFromClip(rCxt.getClipDoc()->pDrawLayer, rSrcStartPos.Tab(), + aSourceRect, ScAddress(nCol1, nRow1, nTab), aDestRect); + } + } } void ScTable::SetValues( SCCOL nCol, SCROW nRow, const std::vector<double>& rVals ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits