[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - sc/qa sc/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 23 09:12:57 UTC 2019


 sc/qa/unit/copy_paste_test.cxx |   59 +++++++++++++++++++++++++++++++++++++++++
 sc/source/ui/inc/impex.hxx     |    4 +-
 sc/source/ui/undo/undoblk.cxx  |    6 ++--
 3 files changed, 65 insertions(+), 4 deletions(-)

New commits:
commit 472679b00da5de87a76587bb5d7c0e0a607a5bba
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jul 24 14:40:21 2019 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Fri Aug 23 11:12:10 2019 +0200

    tdf#107394 sc ui: fix lack of row height update on undo of paste
    
    This is a problem since commit df9243626b39742a9a148bea95796f8824fee68a
    (fdo#73606: Avoid excessive and unnecessary heap allocation of array
    objects., 2014-01-14), though it seems this uncovered a problem that was
    introduced earlier.
    
    Reading ScViewFunc::AdjustBlockHeight(), commit
    64a36fd4f4085ed05e4c0ee40ac109452ff81a78 (ScUndoPaste to handle multiple
    ranges., 2011-09-09) changed ScUndoPaste::DoChange(), so that
    AdjustBlockHeight() is invoked in a loop, but always with the same
    arguments. In case AdjustBlockHeight() doesn't get a mark data, the
    function takes the mark data from the view data, which is empty in the
    "undo of paste" case, so no row height gets updated.
    
    Fix the problem by explicitly providing the mark data to
    AdjustBlockHeight(), probably that was the intention in the second
    commit.
    
    [ Testing this from CppunitTest_sc_copypaste means ScImportExport has to
    be dllpublic, but that seems still better than having a view shell in
    CppunitTest_sc_ucalc. ]
    
    (cherry picked from commit 4840880148318dc384e28f9a8df9990b8690a4b6)
    
    Change-Id: I140b53588d59d231772152c0e820e5fdedf6894c
    Reviewed-on: https://gerrit.libreoffice.org/76318
    Tested-by: Jenkins
    Reviewed-by: Kohei Yoshida <kohei at libreoffice.org>
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/sc/qa/unit/copy_paste_test.cxx b/sc/qa/unit/copy_paste_test.cxx
index a31312c6fe6f..32cdd333f3f2 100644
--- a/sc/qa/unit/copy_paste_test.cxx
+++ b/sc/qa/unit/copy_paste_test.cxx
@@ -13,6 +13,7 @@
 
 #include <docsh.hxx>
 #include <tabvwsh.hxx>
+#include <impex.hxx>
 
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/XModel2.hpp>
@@ -34,12 +35,14 @@ public:
     void testTdf84411();
     void testTdf124565();
     void testTdf126421();
+    void testTdf107394();
 
     CPPUNIT_TEST_SUITE(ScCopyPasteTest);
     CPPUNIT_TEST(testCopyPasteXLS);
     CPPUNIT_TEST(testTdf84411);
     CPPUNIT_TEST(testTdf124565);
     CPPUNIT_TEST(testTdf126421);
+    CPPUNIT_TEST(testTdf107394);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -363,6 +366,62 @@ void ScCopyPasteTest::testTdf126421()
     xDocSh->DoClose();
 }
 
+void ScCopyPasteTest::testTdf107394()
+{
+    uno::Reference<frame::XDesktop2> xDesktop
+        = frame::Desktop::create(::comphelper::getProcessComponentContext());
+    CPPUNIT_ASSERT(xDesktop.is());
+
+    uno::Reference<lang::XComponent> xComponent
+        = xDesktop->loadComponentFromURL("private:factory/scalc", "_blank", 0, {});
+    CPPUNIT_ASSERT(xComponent.is());
+
+    auto pModelObj = dynamic_cast<ScModelObj*>(xComponent.get());
+    CPPUNIT_ASSERT(pModelObj);
+    CPPUNIT_ASSERT(pModelObj->GetDocument());
+
+    ScDocument& rDoc = *pModelObj->GetDocument();
+
+    sal_uInt16 nFirstRowHeight = rDoc.GetRowHeight(0, 0);
+    sal_uInt16 nSecondRowHeight = rDoc.GetRowHeight(1, 0);
+    CPPUNIT_ASSERT_EQUAL(nFirstRowHeight, nSecondRowHeight);
+
+    // Import values to A1:A2.
+    ScImportExport aObj(&rDoc, ScAddress(0,0,0));
+    aObj.SetImportBroadcast(true);
+
+    OString aHTML("<pre>First\nVery long sentence.</pre>");
+    SvMemoryStream aStream;
+    aStream.WriteOString(aHTML);
+    aStream.Seek(0);
+    CPPUNIT_ASSERT(aObj.ImportStream(aStream, OUString(), SotClipboardFormatId::HTML));
+
+    CPPUNIT_ASSERT_EQUAL(OUString("First"), rDoc.GetString(ScAddress(0,0,0)));
+    CPPUNIT_ASSERT_EQUAL(OUString("Very long sentence."), rDoc.GetString(ScAddress(0,1,0)));
+
+    nFirstRowHeight = rDoc.GetRowHeight(0, 0);
+    nSecondRowHeight = rDoc.GetRowHeight(1, 0);
+    CPPUNIT_ASSERT_GREATER(nFirstRowHeight, nSecondRowHeight);
+
+    // Undo, and check the result.
+    SfxUndoManager* pUndoMgr = rDoc.GetUndoManager();
+    CPPUNIT_ASSERT_MESSAGE("Failed to get the undo manager.", pUndoMgr);
+    pUndoMgr->Undo();
+
+    CPPUNIT_ASSERT(rDoc.GetString(ScAddress(0,0,0)).isEmpty());
+    CPPUNIT_ASSERT(rDoc.GetString(ScAddress(0,1,0)).isEmpty());
+
+    nFirstRowHeight = rDoc.GetRowHeight(0, 0);
+    nSecondRowHeight = rDoc.GetRowHeight(1, 0);
+    // Without the accompanying fix in place, this test would have failed:
+    // - Expected: 256
+    // - Actual  : 477
+    // i.e. the increased height of the second row remained after undo.
+    CPPUNIT_ASSERT_EQUAL(nFirstRowHeight, nSecondRowHeight);
+
+    xComponent->dispose();
+}
+
 ScCopyPasteTest::ScCopyPasteTest()
       : ScBootstrapFixture( "sc/qa/unit/data" )
 {
diff --git a/sc/source/ui/inc/impex.hxx b/sc/source/ui/inc/impex.hxx
index 1b703d821373..3ddba5d9b89a 100644
--- a/sc/source/ui/inc/impex.hxx
+++ b/sc/source/ui/inc/impex.hxx
@@ -44,7 +44,7 @@ struct ScExportTextOptions
     bool mbAddQuotes;
 };
 
-class ScImportExport
+class SC_DLLPUBLIC ScImportExport
 {
     ScDocShell* pDocSh;
     ScDocument* pDoc;
@@ -101,7 +101,7 @@ public:
 
     const ScRange& GetRange() const { return aRange; }
 
-    SC_DLLPUBLIC static void EmbeddedNullTreatment( OUString & rStr );
+    static void EmbeddedNullTreatment( OUString & rStr );
 
     static bool  IsFormatSupported( SotClipboardFormatId nFormat );
     static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index a24ff8558d31..df5d0c45b2cc 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1079,6 +1079,8 @@ void ScUndoPaste::DoChange(bool bUndo)
     {
         ScRange& rDrawRange = aDrawRanges[i];
         rDoc.ExtendMerge(rDrawRange, true);      // only needed for single sheet (text/rtf etc.)
+        ScRangeList aRangeList(rDrawRange);
+        ScMarkData aData(aRangeList);
         if (bPaintAll)
         {
             rDrawRange.aStart.SetCol(0);
@@ -1087,7 +1089,7 @@ void ScUndoPaste::DoChange(bool bUndo)
             rDrawRange.aEnd.SetRow(MAXROW);
             nPaint |= PaintPartFlags::Top | PaintPartFlags::Left;
             if (pViewShell)
-                pViewShell->AdjustBlockHeight(false);
+                pViewShell->AdjustBlockHeight(false, &aData);
         }
         else
         {
@@ -1101,7 +1103,7 @@ void ScUndoPaste::DoChange(bool bUndo)
                 nPaint |= PaintPartFlags::Left;
                 rDrawRange.aEnd.SetRow(MAXROW);
             }
-            if (pViewShell && pViewShell->AdjustBlockHeight(false))
+            if (pViewShell && pViewShell->AdjustBlockHeight(false, &aData))
             {
                 rDrawRange.aStart.SetCol(0);
                 rDrawRange.aStart.SetRow(0);


More information about the Libreoffice-commits mailing list