[Libreoffice-commits] core.git: sc/qa sc/source

Mike Kaganski mike.kaganski at collabora.com
Mon Feb 13 21:38:09 UTC 2017


 sc/qa/extras/anchor.cxx           |   37 +++++++++++++++++++++++++++++++++++++
 sc/source/ui/docshell/docfunc.cxx |    3 +++
 sc/source/ui/docshell/docsh5.cxx  |    5 +++++
 sc/source/ui/undo/undobase.cxx    |   11 ++++++++++-
 sc/source/ui/undo/undoblk.cxx     |    2 ++
 sc/source/ui/undo/undoblk3.cxx    |    6 +++++-
 sc/source/ui/view/viewfun2.cxx    |    7 +++++++
 7 files changed, 69 insertions(+), 2 deletions(-)

New commits:
commit 36ef9f8d077afe2c605e9d22588dc3f698440d89
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Sun Feb 12 01:58:23 2017 +0300

    tdf#76183: refresh objects' positions on optimal height recalc
    
    Since commit b10833d4db6046f2d32ea44a60cb19a626d80447, it's required
    to detect when objects' placement should be adjusted, and call
    SetDrawPageSize manually.
    Unit test included
    
    Change-Id: I933ba4802b212400cc47ed0fb7e1f8f44049bb81
    Reviewed-on: https://gerrit.libreoffice.org/34165
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx
index b5310ab..04e06cb 100644
--- a/sc/qa/extras/anchor.cxx
+++ b/sc/qa/extras/anchor.cxx
@@ -13,10 +13,15 @@
 #include <sfx2/dispatch.hxx>
 
 #include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/sheet/XSpreadsheet.hpp>
+#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
+#include <com/sun/star/text/XText.hpp>
 #include <unonames.hxx>
 
 #include "tabvwsh.hxx"
 #include "docsh.hxx"
+#include "svx/svdocirc.hxx"
+#include "scitems.hxx"
 
 #include "sc.hrc"
 
@@ -32,9 +37,11 @@ public:
     virtual void tearDown() override;
 
     void testUndoAnchor();
+    void testTdf76183();
 
     CPPUNIT_TEST_SUITE(ScAnchorTest);
     CPPUNIT_TEST(testUndoAnchor);
+    CPPUNIT_TEST(testTdf76183);
     CPPUNIT_TEST_SUITE_END();
 private:
 
@@ -148,6 +155,36 @@ void ScAnchorTest::testUndoAnchor()
     xComponent->dispose();
 }
 
+void ScAnchorTest::testTdf76183()
+{
+    uno::Reference< lang::XComponent > xComponent = loadFromDesktop("private:factory/scalc");
+    SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
+    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+    ScDocument& rDoc = pDocSh->GetDocument();
+    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+    SdrPage *pPage = pDrawLayer->GetPage(0);
+
+    // Add a circle somewhere below first row.
+    const Rectangle aOrigRect = Rectangle(1000, 1000, 1200, 1200);
+    SdrCircObj* pObj = new SdrCircObj(OBJ_CIRC, aOrigRect);
+    pPage->InsertObject(pObj);
+    // Anchor to cell
+    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 0);
+    const Rectangle& rNewRect = pObj->GetLogicRect();
+
+    // Set word wrap to true
+    rDoc.ApplyAttr(0, 0, 0, SfxBoolItem(ATTR_LINEBREAK, true));
+    // Add multi-line text to cell to initiate optimal height change
+    uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, uno::UNO_QUERY_THROW);
+    uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW);
+    uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
+    uno::Reference<text::XText> xText(xSheet->getCellByPosition(0, 0), uno::UNO_QUERY_THROW);
+    xText->setString("first\nsecond\nthird");
+
+    // The resize of first row must have moved the object down after its anchor cell
+    CPPUNIT_ASSERT(aOrigRect.Top() < rNewRect.Top());
+}
+
 void ScAnchorTest::tearDown()
 {
     if (mxComponent.is())
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 4677738..671b400 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -151,6 +151,9 @@ bool ScDocFunc::AdjustRowHeight( const ScRange& rRange, bool bPaint )
 
     sc::RowHeightContext aCxt(aProv.GetPPTX(), aProv.GetPPTY(), aOne, aOne, aProv.GetDevice());
     bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab);
+    // tdf#76183: recalculate objects' positions
+    if (bChanged)
+        rDoc.SetDrawPageSize(nTab);
 
     if ( bPaint && bChanged )
         rDocShell.PostPaint(ScRange(0, nStartRow, nTab, MAXCOL, MAXROW, nTab),
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index 8313311..9322a38 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -394,7 +394,12 @@ bool ScDocShell::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab )
     bool bChange = aDocument.SetOptimalHeight(aCxt, nStartRow,nEndRow, nTab);
 
     if (bChange)
+    {
+        // tdf#76183: recalculate objects' positions
+        aDocument.SetDrawPageSize(nTab);
+
         PostPaint( 0,nStartRow,nTab, MAXCOL,MAXROW,nTab, PaintPartFlags::Grid|PaintPartFlags::Left );
+    }
 
     return bChange;
 }
diff --git a/sc/source/ui/undo/undobase.cxx b/sc/source/ui/undo/undobase.cxx
index c2b4b69..036cdd9 100644
--- a/sc/source/ui/undo/undobase.cxx
+++ b/sc/source/ui/undo/undobase.cxx
@@ -313,10 +313,14 @@ bool ScBlockUndo::AdjustHeight()
         aCxt, aBlockRange.aStart.Row(), aBlockRange.aEnd.Row(), aBlockRange.aStart.Tab());
 
     if (bRet)
+    {
+        // tdf#76183: recalculate objects' positions
+        rDoc.SetDrawPageSize(aBlockRange.aStart.Tab());
+
         pDocShell->PostPaint( 0,      aBlockRange.aStart.Row(), aBlockRange.aStart.Tab(),
                               MAXCOL, MAXROW,                   aBlockRange.aEnd.Tab(),
                               PaintPartFlags::Grid | PaintPartFlags::Left );
-
+    }
     return bRet;
 }
 
@@ -413,9 +417,14 @@ void ScMultiBlockUndo::AdjustHeight()
         bool bRet = rDoc.SetOptimalHeight(aCxt, r.aStart.Row(), r.aEnd.Row(), r.aStart.Tab());
 
         if (bRet)
+        {
+            // tdf#76183: recalculate objects' positions
+            rDoc.SetDrawPageSize(r.aStart.Tab());
+
             pDocShell->PostPaint(
                 0, r.aStart.Row(), r.aStart.Tab(), MAXCOL, MAXROW, r.aEnd.Tab(),
                 PaintPartFlags::Grid | PaintPartFlags::Left);
+        }
     }
 }
 
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 39f604a..3bbe625 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1176,6 +1176,8 @@ void ScUndoDragDrop::PaintArea( ScRange aRange, sal_uInt16 nExtFlags ) const
 
         if (rDoc.SetOptimalHeight(aCxt, aRange.aStart.Row(), aRange.aEnd.Row(), aRange.aStart.Tab()))
         {
+            // tdf#76183: recalculate objects' positions
+            rDoc.SetDrawPageSize(aRange.aStart.Tab());
             aRange.aStart.SetCol(0);
             aRange.aEnd.SetCol(MAXCOL);
             aRange.aEnd.SetRow(MAXROW);
diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx
index 226e15d..7a6038b 100644
--- a/sc/source/ui/undo/undoblk3.cxx
+++ b/sc/source/ui/undo/undoblk3.cxx
@@ -875,7 +875,7 @@ void ScUndoAutoFormat::Redo()
                     rDoc.SetRowFlags( nRow, nTab, nOld & ~CRFlags::ManualSize );
             }
 
-            rDoc.SetOptimalHeight(aCxt, nStartY, nEndY, nTab);
+            bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartY, nEndY, nTab);
 
             for (SCCOL nCol=nStartX; nCol<=nEndX; nCol++)
                 if (!rDoc.ColHidden(nCol, nTab))
@@ -886,6 +886,10 @@ void ScUndoAutoFormat::Redo()
                     rDoc.SetColWidth( nCol, nTab, nThisSize );
                     rDoc.ShowCol( nCol, nTab, true );
                 }
+
+            // tdf#76183: recalculate objects' positions
+            if (bChanged)
+                rDoc.SetDrawPageSize(nTab);
         }
 
         pDocShell->PostPaint( 0,      0,      nStartZ,
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index fb1e859..0965e89 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -148,6 +148,9 @@ bool ScViewFunc::AdjustBlockHeight( bool bPaint, ScMarkData* pMarkData )
                 bAnyChanged = bChanged = true;
             }
         }
+        // tdf#76183: recalculate objects' positions
+        if (bChanged)
+            rDoc.SetDrawPageSize(nTab);
         if ( bPaint && bChanged )
             pDocSh->PostPaint( 0, nPaintY, nTab, MAXCOL, MAXROW, nTab,
                                                 PaintPartFlags::Grid | PaintPartFlags::Left );
@@ -182,6 +185,10 @@ bool ScViewFunc::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow )
     sc::RowHeightContext aCxt(nPPTX, nPPTY, aZoomX, aZoomY, aProv.GetDevice());
     bool bChanged = rDoc.SetOptimalHeight(aCxt, nStartRow, nEndRow, nTab);
 
+    // tdf#76183: recalculate objects' positions
+    if (bChanged)
+        rDoc.SetDrawPageSize(nTab);
+
     if (bChanged && ( nStartRow == nEndRow ))
     {
         sal_uInt16 nNewPixel = (sal_uInt16) (rDoc.GetRowHeight(nStartRow,nTab) * nPPTY);


More information about the Libreoffice-commits mailing list