sc/qa/unit/tiledrendering/tiledrendering.cxx |   46 ++++++++++++++++++++++-----
 sc/source/ui/app/inputhdl.cxx                |   10 +++++
 2 files changed, 48 insertions(+), 8 deletions(-)

New commits:
commit 9d3366f5b392418dc83bc0adbe3d215cff4b3605
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Feb 27 19:49:41 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Feb 28 10:10:44 2024 +0100

    don't use EEControlBits::FORMAT100 in inline editengine for kit mode
    
    With multiple users the EditEngine for the first user is created during
    load of the document, before ScModelObj::initializeForTiledRendering is
    called, and that sets SetTextWysiwyg(true)
    
    ScInputHandler::UpdateRefDevice has...
    if ( bTextWysiwyg ... ) mpEditEngine->SetControlWord( ... | 
EEControlBits::FORMAT100 );
    
    That FORMAT100 means that layout for such edit engines is done at a X/Y
    Scaling of 1
    
    The first users editengine doesn't get any of that set, because
    TextWysiwyg is not true yet when it's created, and so matches the normal
    document rendering, but later joiners have TextWysiwyg set, so trigger
    this alternative path and so the mapmode doesn't match the other case
    and the two users have different results for the width of text in an
    active editengine.
    
    As it turns out, the results without FORMAT100 are the preferred ones,
    so make that explicit for kit.
    
    Change-Id: I76a78be1fca4af84c493d32bdd43f968ba072452
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164059
    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 c9a005fd5136..d6eab7cafea2 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -3562,18 +3562,50 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testInputHandlerSyncedZoom)
     pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::F2);
     Scheduler::ProcessEventsToIdle();
 
-    const ScViewData* pViewData = ScDocShell::GetViewData();
-    CPPUNIT_ASSERT(pViewData);
+    const ScViewData* pViewData1 = ScDocShell::GetViewData();
+    CPPUNIT_ASSERT(pViewData1);
 
     // Get that active EditView
-    EditView* pEditView = pViewData->GetEditView(SC_SPLIT_BOTTOMLEFT);
-    CPPUNIT_ASSERT(pEditView);
-    EditEngine& rEditEngine = pEditView->getEditEngine();
+    EditView* pEditView1 = pViewData1->GetEditView(SC_SPLIT_BOTTOMLEFT);
+    CPPUNIT_ASSERT(pEditView1);
+    EditEngine& rEditEngine1 = pEditView1->getEditEngine();
     // 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(), 
rEditEngine.GetRefMapMode().GetScaleX());
+                                 pViewData1->GetZoomX(), 
rEditEngine1.GetRefMapMode().GetScaleX());
     CPPUNIT_ASSERT_EQUAL_MESSAGE("EditEngine Ref Dev Zoom and ViewData Zoom 
should match",
-                                 pViewData->GetZoomY(), 
rEditEngine.GetRefMapMode().GetScaleY());
+                                 pViewData1->GetZoomY(), 
rEditEngine1.GetRefMapMode().GetScaleY());
+
+    // Create a View #2
+    SfxLokHelper::createView();
+    
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+
+    // Set View #2 to the same zoom as View #1
+    pModelObj->setClientVisibleArea(tools::Rectangle(0, 0, 17933, 4853));
+    pModelObj->setClientZoom(256, 256, 1333, 1333);
+
+    ScTabViewShell* pView2 = 
dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+    CPPUNIT_ASSERT(pView2);
+    pView2->SetCursor(0, 5); // A6
+
+    Scheduler::ProcessEventsToIdle();
+
+    // Activate edit mode in that A6 cell
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::F2);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::F2);
+    Scheduler::ProcessEventsToIdle();
+
+    const ScViewData* pViewData2 = ScDocShell::GetViewData();
+    CPPUNIT_ASSERT(pViewData2);
+
+    // Get the View #2 EditView
+    EditView* pEditView2 = pViewData2->GetEditView(SC_SPLIT_BOTTOMLEFT);
+    CPPUNIT_ASSERT(pEditView2);
+    EditEngine& rEditEngine2 = pEditView2->getEditEngine();
+    CPPUNIT_ASSERT(&rEditEngine1 != &rEditEngine2);
+    // Before the fix, these had different settings, resulting in the text
+    // dancing for the second user as they toggle in and out of edit mode, but
+    // each user should have the same settings.
+    CPPUNIT_ASSERT_EQUAL(rEditEngine1.GetControlWord(), 
rEditEngine2.GetControlWord());
 }
 
 CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testStatusBarLocale)
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 8ea3f33157a9..1b261ac46d77 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -908,7 +908,15 @@ void ScInputHandler::UpdateRefDevice()
     bool bTextWysiwyg = SC_MOD()->GetInputOptions().GetTextWysiwyg();
     bool bInPlace = pActiveViewSh && 
pActiveViewSh->GetViewFrame().GetFrame().IsInPlace();
     EEControlBits nCtrl = mpEditEngine->GetControlWord();
-    if ( bTextWysiwyg || bInPlace )
+    bool bFormat100Percent = bTextWysiwyg || bInPlace;
+    // FORMAT100 is an odd thing only used by calc since #i51508# and possibly
+    // redundant at this stage by resolution independent text layout and
+    // rendering, at least for the kit case we want the text layout to be done
+    // accurately at the provided scaling of the reference device
+    if (comphelper::LibreOfficeKit::isActive())
+        bFormat100Percent = false;
+
+    if (bFormat100Percent)
         nCtrl |= EEControlBits::FORMAT100;    // EditEngine default: always 
format for 100%
     else
         nCtrl &= ~EEControlBits::FORMAT100;   // when formatting for screen, 
use the actual MapMode

Reply via email to