tdf#124565: calc: copy/paste manual row height
Row height being pasted is not sufficient without knowing
if it is auto height or was set manually.
Change-Id: I3c892fbe3ea5a54e7468fb23b993fa19370f85af
Reviewed-on: https://gerrit.libreoffice.org/71706
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
diff --git a/sc/qa/unit/copy_paste_test.cxx b/sc/qa/unit/copy_paste_test.cxx
index ac14129..967faaa 100644
--- a/sc/qa/unit/copy_paste_test.cxx
+++ b/sc/qa/unit/copy_paste_test.cxx
@@ -32,10 +32,12 @@ public:
void testCopyPasteXLS();
void testTdf84411();
void testTdf124565();
CPPUNIT_TEST_SUITE(ScCopyPasteTest);
CPPUNIT_TEST(testCopyPasteXLS);
CPPUNIT_TEST(testTdf84411);
CPPUNIT_TEST(testTdf124565);
CPPUNIT_TEST_SUITE_END();
private:
@@ -224,6 +226,69 @@ void ScCopyPasteTest::testTdf84411()
xComponent->dispose();
}
void ScCopyPasteTest::testTdf124565()
{
// Create new document
ScDocShell* xDocSh = new ScDocShell(
SfxModelFlags::EMBEDDED_OBJECT |
SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
xDocSh->DoInitNew();
uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
CPPUNIT_ASSERT( xDesktop.is() );
Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame( "_blank", 0 );
CPPUNIT_ASSERT( xTargetFrame.is() );
uno::Reference< frame::XModel2 > xModel2 ( xDocSh->GetModel(), UNO_QUERY );
CPPUNIT_ASSERT( xModel2.is() );
Reference< frame::XController2 > xController ( xModel2->createDefaultViewController( xTargetFrame ), UNO_QUERY );
CPPUNIT_ASSERT( xController.is() );
// introduce model/view/controller to each other
xController->attachModel( xModel2.get() );
xModel2->connectController( xController.get() );
xTargetFrame->setComponent( xController->getComponentWindow(), xController.get() );
xController->attachFrame( xTargetFrame );
xModel2->setCurrentController( xController.get() );
ScDocument& rDoc = xDocSh->GetDocument();
ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
CPPUNIT_ASSERT(pViewShell != nullptr);
// Set content and height of first row
rDoc.SetString(ScAddress(0, 0, 0), "Test");
rDoc.SetRowHeight(0, 0, 500);
rDoc.SetManualHeight(0, 0, 0, true);
// Copy first row
ScDocument aClipDoc(SCDOCMODE_CLIP);
ScRange aCopyRange(0, 0, 0, MAXCOL, 0, 0);
pViewShell->GetViewData().GetMarkData().SetMarkArea(aCopyRange);
pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, false, false);
// Paste to second row
SCTAB nTab = 0;
SCCOL nCol = 0;
SCROW nRow = 1;
ScRange aPasteRange(nCol, nRow, nTab, MAXCOL, nRow, nTab);
pViewShell->GetViewData().GetMarkData().SetMarkArea(aPasteRange);
pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc);
// Copy-pasted?
CPPUNIT_ASSERT_EQUAL_MESSAGE("String was not pasted!", OUString("Test"), rDoc.GetString(nCol, nRow, nTab));
// And height same as in source?
CPPUNIT_ASSERT_EQUAL_MESSAGE("Row#2 height is invalid!", sal_uInt16(500), rDoc.GetRowHeight(nRow, nTab));
CPPUNIT_ASSERT_MESSAGE("Row#2 must be manual height!", rDoc.IsManualRowHeight(nRow, nTab));
xDocSh->DoClose();
}
ScCopyPasteTest::ScCopyPasteTest()
: ScBootstrapFixture( "sc/qa/unit/data" )
{
diff --git a/sc/source/core/data/table7.cxx b/sc/source/core/data/table7.cxx
index ae67c31..7b67a09 100644
--- a/sc/source/core/data/table7.cxx
+++ b/sc/source/core/data/table7.cxx
@@ -18,6 +18,7 @@
#include <tabprotection.hxx>
#include <columniterator.hxx>
#include <drwlayer.hxx>
#include <compressedarray.hxx>
bool ScTable::IsMerged( SCCOL nCol, SCROW nRow ) const
{
@@ -139,8 +140,17 @@ void ScTable::CopyOneCellFromClip(
}
if (nCol1 == 0 && nCol2 == MAXCOL && mpRowHeights)
{
mpRowHeights->setValue(nRow1, nRow2, pSrcTab->GetOriginalHeight(nSrcRow));
if (pRowFlags && pSrcTab->pRowFlags) {
if (pSrcTab->pRowFlags->GetValue(nSrcRow) & CRFlags::ManualSize)
pRowFlags->OrValue(nRow1, CRFlags::ManualSize);
else
pRowFlags->AndValue(nRow1, ~CRFlags::ManualSize);
}
}
// Copy graphics over too
bool bCopyGraphics
= (rCxt.getInsertFlag() & InsertDeleteFlags::OBJECTS) != InsertDeleteFlags::NONE;