sc/qa/unit/tiledrendering/data/cell-edit-300zoom-settings.ods |binary
 sc/qa/unit/tiledrendering/tiledrendering.cxx                  |   39 ++++++++++
 sc/source/ui/unoobj/docuno.cxx                                |    3 
 3 files changed, 42 insertions(+)

New commits:
commit 553ec20aade8184bd6753fdcfb78bfa84b8090c5
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Feb 13 17:19:59 2024 +0000
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Feb 28 11:51:28 2024 +0100

    sync InputHandler zoom on setClientZoom
    
    analogous to what SetZoom and ScTabViewShell::Activate do.
    
    Otherwise the InputHandler editengine ref device used for cell editing
    stays at the MapMode stored in the document and doesn't update to stay
    in sync with the desired rendering so there is a visible mismatch
    between normal rendering and cell editing rendering.
    
    Change-Id: Ifd9b21ab15cc123e0747fcebfdd55f2ddc44bd31
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163315
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sc/qa/unit/tiledrendering/data/cell-edit-300zoom-settings.ods 
b/sc/qa/unit/tiledrendering/data/cell-edit-300zoom-settings.ods
new file mode 100644
index 000000000000..8cfbc4d227bc
Binary files /dev/null and 
b/sc/qa/unit/tiledrendering/data/cell-edit-300zoom-settings.ods differ
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index 1b6cf11d4211..61671dac0215 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -176,6 +176,7 @@ public:
     void testNoInvalidateOnSave();
     void testCellMinimalInvalidations();
     void testCellInvalidationDocWithExistingZoom();
+    void testInputHandlerSyncedZoom();
     void testOptimalRowHeight();
     void testExtendedAreasDontOverlap();
     void testEditShapeText();
@@ -256,6 +257,7 @@ public:
     CPPUNIT_TEST(testNoInvalidateOnSave);
     CPPUNIT_TEST(testCellMinimalInvalidations);
     CPPUNIT_TEST(testCellInvalidationDocWithExistingZoom);
+    CPPUNIT_TEST(testInputHandlerSyncedZoom);
     CPPUNIT_TEST(testOptimalRowHeight);
     CPPUNIT_TEST(testExtendedAreasDontOverlap);
     CPPUNIT_TEST(testEditShapeText);
@@ -3881,6 +3883,43 @@ void 
ScTiledRenderingTest::testCellInvalidationDocWithExistingZoom()
                                           50);
 }
 
+void ScTiledRenderingTest::testInputHandlerSyncedZoom()
+{
+    ScModelObj* pModelObj = createDoc("cell-edit-300zoom-settings.ods");
+
+    // Set View #1 to initial 150%
+    pModelObj->setClientVisibleArea(tools::Rectangle(0, 0, 17933, 4853));
+    // Before the fix, this zoom would leave the EditEngine reference device
+    // at the zoom level stored in the document, so normal rendering and
+    // editing rendering happened with different MapModes
+    pModelObj->setClientZoom(256, 256, 1333, 1333);
+
+    ScTabViewShell* pView = 
dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+    CPPUNIT_ASSERT(pView);
+    pView->SetCursor(0, 4); // A5
+
+    Scheduler::ProcessEventsToIdle();
+
+    // Activate edit mode in that A5 cell
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::F2);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::F2);
+    Scheduler::ProcessEventsToIdle();
+
+    const ScViewData* pViewData = ScDocShell::GetViewData();
+    CPPUNIT_ASSERT(pViewData);
+
+    // Get that active EditView
+    EditView* pEditView = pViewData->GetEditView(SC_SPLIT_BOTTOMLEFT);
+    CPPUNIT_ASSERT(pEditView);
+    EditEngine* pEditEngine = pEditView->GetEditEngine();
+    CPPUNIT_ASSERT(pEditEngine);
+    // These must match, if they don't then text will have a different width 
in edit and view modes
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("EditEngine Ref Dev Zoom and ViewData Zoom 
should match",
+                                 pViewData->GetZoomX(), 
pEditEngine->GetRefMapMode().GetScaleX());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("EditEngine Ref Dev Zoom and ViewData Zoom 
should match",
+                                 pViewData->GetZoomY(), 
pEditEngine->GetRefMapMode().GetScaleY());
+}
+
 void ScTiledRenderingTest::testOptimalRowHeight()
 {
     ScModelObj* pModelObj = createDoc("rowheight.ods");
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 832b2015c2b2..1520b183beb9 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1077,6 +1077,9 @@ void ScModelObj::setClientZoom(int nTilePixelWidth_, int 
nTilePixelHeight_, int
     pViewData->SetZoom(newZoomX, newZoomY, true);
     if (ScTabViewShell* pViewShell = pViewData->GetViewShell())
         pViewShell->SyncGridWindowMapModeFromDrawMapMode();
+    // sync zoom to Input Handler like ScTabViewShell::Activate does
+    if (ScInputHandler* pHdl = SC_MOD()->GetInputHdl())
+        pHdl->SetRefScale(pViewData->GetZoomX(), pViewData->GetZoomY());
 
     // refresh our view's take on other view's cursors & selections
     pViewData->GetActiveWin()->updateKitOtherCursors();

Reply via email to