sc/source/ui/view/gridwin4.cxx |   85 +++++++++++++++++++++++++++++++++--------
 1 file changed, 69 insertions(+), 16 deletions(-)

New commits:
commit 9257486636dfe95b73e5690462ba6e8408a12166
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Tue Oct 25 10:40:05 2022 +0200
Commit:     Gökay ŞATIR <gokaysa...@collabora.com>
CommitDate: Fri Nov 4 10:22:50 2022 +0100

    lok: sc: render expanded EditEngine when editing in-place
    
    It's regression from:
    commit 5a0839e60ac75869ad49685ca74ad6c6b49ef925
    sc: lok: fix offset edit output area
    
    When we use two views and one is editing multiline cell
    after pressing F2 (in in-place mode) by adding new lines
    (ctrl + enter) - we need to expand rendering area and
    show additional content (which covers next cells).
    
    This patch makes possible to render expanded are in all the
    views, not only for one used for rendering.
    
    Change-Id: Ief2cd391a23e65b3eb7eaf89f2a9f6471b87299f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139924
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Dennis Francis <dennis.fran...@collabora.com>

diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index ddafacfac577..970a4591411f 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -654,6 +654,24 @@ private:
     const tools::Long mnTileDevOriginX;
 };
 
+namespace
+{
+int lcl_GetMultiLineHeight(EditEngine* pEditEngine)
+{
+    int nHeight = 0;
+    int nParagraphs = pEditEngine->GetParagraphCount();
+    if (nParagraphs > 1 || (nParagraphs > 0 && pEditEngine->GetLineCount(0) > 
1))
+    {
+        for (int nPara = 0; nPara < nParagraphs; nPara++)
+        {
+            nHeight += pEditEngine->GetLineCount(nPara) * 
pEditEngine->GetLineHeight(nPara);
+        }
+    }
+
+    return nHeight;
+}
+}
+
 void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& 
rTableInfo, ScOutputData& aOutputData,
         bool bLogicText)
 {
@@ -1070,7 +1088,7 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
         }
     }
 
-    // paint in-place editing on other views
+    // paint in-place editing
     if (bIsTiledRendering)
     {
         ScTabViewShell* pThisViewShell = mrViewData.GetViewShell();
@@ -1078,7 +1096,8 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
 
         while (pViewShell)
         {
-            if (pViewShell != pThisViewShell && pViewShell->GetDocId() == 
pThisViewShell->GetDocId())
+            bool bEnterLoop = bIsTiledRendering || pViewShell != 
pThisViewShell;
+            if (bEnterLoop && pViewShell->GetDocId() == 
pThisViewShell->GetDocId())
             {
                 ScTabViewShell* pTabViewShell = 
dynamic_cast<ScTabViewShell*>(pViewShell);
                 if (pTabViewShell)
@@ -1106,6 +1125,13 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
                             Point aStart = mrViewData.GetScrPos( nCol1, nRow1, 
eOtherWhich );
                             Point aEnd = mrViewData.GetScrPos( nCol2+1, 
nRow2+1, eOtherWhich );
 
+                            if (bIsTiledRendering)
+                            {
+                                EditEngine* pEditEngine = 
pOtherEditView->GetEditEngine();
+                                if (pEditEngine)
+                                    
aEnd.AdjustY(lcl_GetMultiLineHeight(pEditEngine));
+                            }
+
                             if (bLokRTL)
                             {
                                 // Transform the cell range X coordinates such 
that the edit cell area is
@@ -1145,6 +1171,7 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
 
                             // paint the background
                             
rDevice.DrawRect(rDevice.PixelToLogic(aBackground));
+                            tools::Rectangle aBGAbs(aBackground);
 
                             tools::Rectangle aEditRect(aBackground);
                             tools::Long nOffsetX = 0, nOffsetY = 0;
@@ -1167,12 +1194,42 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
                             SuppressEditViewMessagesGuard 
aGuard(*pOtherEditView);
 
                             aEditRect = rDevice.PixelToLogic(aEditRect);
-                            
aEditRect.Intersection(pOtherEditView->GetOutputArea());
+                            if (bIsTiledRendering)
+                                pOtherEditView->SetOutputArea(aEditRect);
+                            else
+                                
aEditRect.Intersection(pOtherEditView->GetOutputArea());
                             pOtherEditView->Paint(aEditRect, &rDevice);
 
+                            // EditView will do the cursor notifications 
correctly if we're in
+                            // print-twips messaging mode.
+                            if (bIsTiledRendering && 
!comphelper::LibreOfficeKit::isCompatFlagSet(
+                                    
comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
+                            {
+                                // Now we need to get relative cursor position 
within the editview.
+                                // This is for sending the pixel-aligned twips 
position of the cursor to the specific views with
+                                // the same given zoom level.
+                                tools::Rectangle aCursorRect = 
pOtherEditView->GetEditCursor();
+                                Point aCursPos = 
OutputDevice::LogicToLogic(aCursorRect.TopLeft(),
+                                        MapMode(MapUnit::Map100thMM), 
MapMode(MapUnit::MapTwip));
+
+                                const MapMode& rDevMM = rDevice.GetMapMode();
+                                MapMode aMM(MapUnit::MapTwip);
+                                aMM.SetScaleX(rDevMM.GetScaleX());
+                                aMM.SetScaleY(rDevMM.GetScaleY());
+
+                                aBGAbs.AdjustLeft(1);
+                                aBGAbs.AdjustTop(1);
+                                aCursorRect = 
GetOutDev()->PixelToLogic(aBGAbs, aMM);
+                                aCursorRect.setWidth(0);
+                                aCursorRect.Move(aCursPos.getX(), 0);
+                                // Sends view cursor position to views of all 
matching zooms if needed (avoids duplicates).
+                                InvalidateLOKViewCursor(aCursorRect, 
aMM.GetScaleX(), aMM.GetScaleY());
+                            }
+
                             // Rollback the mapmode and 'output area'.
                             rOtherWin.SetMapMode(aOrigMapMode);
-                            pOtherEditView->SetOutputArea(aOrigOutputArea);
+                            if (!bIsTiledRendering)
+                                pOtherEditView->SetOutputArea(aOrigOutputArea);
                             rDevice.SetMapMode(MapMode(MapUnit::MapPixel));
                         }
                     }
@@ -1250,14 +1307,6 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
             rDevice.SetMapMode(aNew);
         }
 
-        // paint the background
-        tools::Rectangle aLogicRect(rDevice.PixelToLogic(aBackground));
-        //tdf#100925, rhbz#1283420, Draw some text here, to get
-        //X11CairoTextRender::getCairoContext called, so that the forced read
-        //from the underlying X Drawable gets it to sync.
-        rDevice.DrawText(aLogicRect.BottomLeft(), " ");
-        rDevice.DrawRect(aLogicRect);
-
         // paint the editeng text
         if (bIsTiledRendering)
         {
@@ -1280,10 +1329,6 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
             // cursor-messaging done in the non print-twips mode)
             SuppressEditViewMessagesGuard aGuard(*pEditView);
 
-            aEditRect = rDevice.PixelToLogic(aEditRect);
-            aEditRect.Intersection(pEditView->GetOutputArea());
-            pEditView->Paint(aEditRect, &rDevice);
-
             // EditView will do the cursor notifications correctly if we're in
             // print-twips messaging mode.
             if (!comphelper::LibreOfficeKit::isCompatFlagSet(
@@ -1315,6 +1360,14 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
         }
         else
         {
+            // paint the background
+            tools::Rectangle aLogicRect(rDevice.PixelToLogic(aBackground));
+            //tdf#100925, rhbz#1283420, Draw some text here, to get
+            //X11CairoTextRender::getCairoContext called, so that the forced 
read
+            //from the underlying X Drawable gets it to sync.
+            rDevice.DrawText(aLogicRect.BottomLeft(), " ");
+            rDevice.DrawRect(aLogicRect);
+
             tools::Rectangle aEditRect(Point(nScrX, nScrY), 
Size(aOutputData.GetScrW(), aOutputData.GetScrH()));
             pEditView->Paint(rDevice.PixelToLogic(aEditRect), &rDevice);
         }

Reply via email to