sc/qa/unit/tiledrendering/tiledrendering.cxx |   47 +++++++++++++++++++++++++--
 sc/source/ui/view/tabview.cxx                |    8 ++--
 2 files changed, 49 insertions(+), 6 deletions(-)

New commits:
commit ac1cafad398b13a831de913e11143760fd6b822b
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Mon Jan 22 17:30:27 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Jan 23 20:26:21 2024 +0100

    produce non-overlapping invalidation rects on extending calc tiled area
    
    the intent is to create two rects, one for the area extended to the
    right and another for the area extended to the bottom, but they overlap
    so they end up merged and a single rect of the entire sheet is created
    which is defeats the original intention.
    
    Change-Id: Ie5b46ee1a36780d9f7a90ed11ebfd1264c17477a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162412
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162448
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index eeaabd962b5f..702194664eb5 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -1920,7 +1920,7 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testGetRowColumnHeadersInvalidation)
     Scheduler::ProcessEventsToIdle();
     CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
     CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidations.size());
-    CPPUNIT_ASSERT_EQUAL(tools::Rectangle(26775, 0, 49725, 13005), 
aView1.m_aInvalidations[0]);
+    CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(26775, 0), Size(22950, 
13005)), aView1.m_aInvalidations[0]);
 
     // Extend area top-to-bottom
     aView1.m_bInvalidateTiles = false;
@@ -1931,7 +1931,7 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testGetRowColumnHeadersInvalidation)
     Scheduler::ProcessEventsToIdle();
     CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
     CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidations.size());
-    CPPUNIT_ASSERT_EQUAL(tools::Rectangle(0, 13005, 49725, 19380), 
aView1.m_aInvalidations[0]);
+    CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(0, 13005), Size(49725, 6375)), 
aView1.m_aInvalidations[0]);
 
     // Extend area left-to-right
     aView1.m_bInvalidateTiles = false;
@@ -1942,7 +1942,7 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testGetRowColumnHeadersInvalidation)
     Scheduler::ProcessEventsToIdle();
     CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
     CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidations.size());
-    CPPUNIT_ASSERT_EQUAL(tools::Rectangle(49725, 0, 75225, 19380), 
aView1.m_aInvalidations[0]);
+    CPPUNIT_ASSERT_EQUAL(tools::Rectangle(Point(49725, 0), Size(25500, 
19380)), aView1.m_aInvalidations[0]);
 }
 
 CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testJumpHorizontallyInvalidation)
@@ -3706,6 +3706,47 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testLongFirstColumnMouseClick)
     CPPUNIT_ASSERT_EQUAL(SCROW(0), ScDocShell::GetViewData()->GetCurY());
 }
 
+// if we extend the tiled area to the right and bottom we want two resulting 
area
+// that don't overlap. If they overlap that typically creates an unnecessary 
full
+// screen invalidation.
+CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testExtendedAreasDontOverlap)
+{
+    comphelper::LibreOfficeKit::setCompatFlag(
+        comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs);
+
+    ScModelObj* pModelObj = createDoc("empty.ods");
+    CPPUNIT_ASSERT(pModelObj);
+    ScTabViewShell* pView = 
dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+    CPPUNIT_ASSERT(pView);
+
+    // Set an arbitrary initial size smaller than the final size
+    pModelObj->setClientVisibleArea(tools::Rectangle(0, 0, 1000, 1000));
+
+    Scheduler::ProcessEventsToIdle();
+
+    // register to track View #1 invalidations
+    ViewCallback aView1;
+
+    // extend to the right and bottom
+    pModelObj->setClientVisibleArea(tools::Rectangle(0, 0, 39750, 12780));
+
+    Scheduler::ProcessEventsToIdle();
+
+    // we should get two rectangles for the two new areas
+    CPPUNIT_ASSERT_EQUAL(size_t(2), aView1.m_aInvalidations.size());
+
+    // And those should not overlap, otherwise they would merge to form
+    // a mega rectangle, which defeats the purpose of creating two rects
+    // in the first place.
+    CPPUNIT_ASSERT_MESSAGE("Invalidations should not overlap",
+        !aView1.m_aInvalidations[0].Overlaps(aView1.m_aInvalidations[1]));
+
+    // But they should be adjacent
+    CPPUNIT_ASSERT_EQUAL(aView1.m_aInvalidations[0].Top() +
+                         aView1.m_aInvalidations[0].GetSize().Height(),
+                         aView1.m_aInvalidations[1].Top());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 1bf2b710ba01..a865acb71505 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -2735,10 +2735,12 @@ void lcl_ExtendTiledDimension(bool bColumn, const 
SCCOLROW nEnd, const SCCOLROW
         return;
 
     // New area extended to the right/bottom of the sheet after last col/row
+    tools::Rectangle aNewArea(Point(0, 0), aNewSize);
     // excluding overlapping area with aNewArea
-    tools::Rectangle aNewArea = bColumn ?
-        tools::Rectangle(aOldSize.getWidth(), 0, aNewSize.getWidth(), 
aNewSize.getHeight()):
-        tools::Rectangle(0, aOldSize.getHeight(), aNewSize.getWidth(), 
aNewSize.getHeight());
+    if (bColumn)
+        aNewArea.SetLeft(aOldSize.getWidth());
+    else
+        aNewArea.SetTop(aOldSize.getHeight());
 
     // Only invalidate if spreadsheet has extended to the right or bottom
     if ((bColumn && aNewArea.getOpenWidth()) || (!bColumn && 
aNewArea.getOpenHeight()))

Reply via email to