sc/source/core/tool/editutil.cxx |    6 ++++--
 sc/source/ui/view/gridwin4.cxx   |   16 +++++++++++++++-
 sc/source/ui/view/viewdata.cxx   |   21 +++++++++++----------
 3 files changed, 30 insertions(+), 13 deletions(-)

New commits:
commit 09ed49ae42b7c5368d0ef2774ba4e04aeb9bafdb
Author:     Dennis Francis <[email protected]>
AuthorDate: Fri Nov 19 10:21:46 2021 +0530
Commit:     Dennis Francis <[email protected]>
CommitDate: Sat Jan 29 05:01:16 2022 +0100

    lokCalcRTL: fix editcell tile painting
    
    Don't use internal gridwindow width to invert the edit area coordinates.
    The gridwin width is not in sync with lok client width, and it seems
    making them in sync is non-trivial as it currently breaks other things.
    
    For tile-painting, always use the width of visible columns in the
    (combined-)tile area as the mirror width.
    
    In the case of LOK + RTL, because we avoid coordinate mirroring based on
    gridwin-width, any corresponding adjustments in edit engine paper-size,
    output area, visible area are done appropriately.
    
    Advantage of this approach is that the invalidation rectangles sent are
    in the document coordinates which is exactly what the client expects! So
    no additional coordinate reversal needed in core or in lok client for
    invalidation.
    
    Change-Id: I0b687a12dc9344fba9ee772111e7598888fa16bf
    (cherry picked from commit 8266f569c864ae309f362088d42dfb3b952c4267)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128896
    Tested-by: Jenkins
    Reviewed-by: Dennis Francis <[email protected]>

diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index 331f50af8b93..56ee97ab7bde 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -32,6 +32,7 @@
 #include <svl/numformat.hxx>
 #include <svl/inethist.hxx>
 #include <sfx2/objsh.hxx>
+#include <comphelper/lok.hxx>
 #include <osl/diagnose.h>
 
 #include <com/sun/star/text/textfield/Type.hpp>
@@ -327,9 +328,10 @@ tools::Rectangle ScEditUtil::GetEditArea( const 
ScPatternAttr* pPattern, bool bF
         pPattern = pDoc->GetPattern( nCol, nRow, nTab );
 
     Point aStartPos = aCellPos;
+    bool bIsTiledRendering = comphelper::LibreOfficeKit::isActive();
 
     bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
-    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
+    tools::Long nLayoutSign = (bLayoutRTL && !bIsTiledRendering) ? -1 : 1;
 
     const ScMergeAttr* pMerge = &pPattern->GetItem(ATTR_MERGE);
     tools::Long nCellX = pDoc->GetColWidth(nCol,nTab);
@@ -428,7 +430,7 @@ tools::Rectangle ScEditUtil::GetEditArea( const 
ScPatternAttr* pPattern, bool bF
     aStartPos.AdjustY(nDifY );
     nCellY      -= nDifY;
 
-    if ( bLayoutRTL )
+    if ( bLayoutRTL && !bIsTiledRendering )
         aStartPos.AdjustX( -(nCellX - 2) );    // excluding grid on both sides
 
                                                         //  -1 -> don't 
overwrite grid
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 4ae520a429fc..ddd1cff08964 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1146,6 +1146,18 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
         Point aStart = mrViewData.GetScrPos( nCol1, nRow1, eWhich );
         Point aEnd = mrViewData.GetScrPos( nCol2+1, nRow2+1, eWhich );
 
+        if (bIsTiledRendering && bLayoutRTL)
+        {
+            // Transform the cell range X coordinates such that the edit cell 
area is
+            // horizontally mirrored w.r.t the (combined-)tile.
+            tools::Long nStartTileX = 
-o3tl::convert(aOriginalMode.GetOrigin().X(), o3tl::Length::twip, 
o3tl::Length::px);
+            // Note: nStartTileX is scaled by 2 only to offset for the 
addition of
+            // the -ve of the same qty (and nScrX) few lines below.
+            tools::Long nMirrorX = 2 * nStartTileX + aOutputData.GetScrW();
+            aStart.setX(nMirrorX - 1 - aStart.X());
+            aEnd.setX(nMirrorX - 1 - aEnd.X());
+        }
+
         // don't overwrite grid
         tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
         aEnd.AdjustX( -(2 * nLayoutSign) );
@@ -1153,7 +1165,9 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
 
         // set the correct mapmode
         tools::Rectangle aBackground(aStart, aEnd);
-        tools::Rectangle aBGAbs(aStart, aEnd);
+        if (bIsTiledRendering && bLayoutRTL)
+            aBackground.Justify();
+        tools::Rectangle aBGAbs(aBackground);
 
         if (bIsTiledRendering)
         {
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 422b56074ae4..6f51cd24037d 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -1648,6 +1648,7 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich,
         //  (existing or started) with default alignment extend to the right.
         bool bGrowCentered = ( eJust == SvxCellHorJustify::Center );
         bool bGrowToLeft = ( eJust == SvxCellHorJustify::Right );      // 
visual left
+        bool bLOKRTLInvert = (bLOKActive && bLayoutRTL);
         if ( bAsianVertical )
             bGrowCentered = bGrowToLeft = false;   // keep old behavior for 
asian mode
 
@@ -1691,7 +1692,7 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich,
                     nSizeXPTwips = aPTwipsRect.GetWidth() + 2 * 
std::min(nLeftPTwips, nRightPTwips);
                 }
             }
-            else if ( bGrowToLeft )
+            else if ( (bGrowToLeft && !bLOKRTLInvert) || (!bGrowToLeft && 
bLOKRTLInvert) )
             {
                 nSizeXPix = aPixRect.Right();   // space that's available in 
the window when growing to the left
                 if (bLOKPrintTwips)
@@ -1928,12 +1929,12 @@ void ScViewData::EditGrowX()
                     nLogicRightPTwips = nColWidth;
             }
 
-            aArea.AdjustLeft( -(bLayoutRTL ? nLogicRight : nLogicLeft) );
-            aArea.AdjustRight(bLayoutRTL ? nLogicLeft : nLogicRight );
+            aArea.AdjustLeft( -((bLayoutRTL && !bLOKActive) ? nLogicRight : 
nLogicLeft) );
+            aArea.AdjustRight((bLayoutRTL && !bLOKActive) ? nLogicLeft : 
nLogicRight );
             if (bLOKPrintTwips)
             {
-                aAreaPTwips.AdjustLeft( -(bLayoutRTL ? nLogicRightPTwips : 
nLogicLeftPTwips) );
-                aAreaPTwips.AdjustRight(bLayoutRTL ? nLogicLeftPTwips : 
nLogicRightPTwips );
+                aAreaPTwips.AdjustLeft( -((bLayoutRTL && !bLOKActive) ? 
nLogicRightPTwips : nLogicLeftPTwips) );
+                aAreaPTwips.AdjustRight((bLayoutRTL && !bLOKActive) ? 
nLogicLeftPTwips : nLogicRightPTwips );
             }
 
             if ( aArea.Right() > aArea.Left() + aSize.Width() - 1 )
@@ -1967,7 +1968,7 @@ void ScViewData::EditGrowX()
             tools::Long nLogicWidth = pWin->PixelToLogic(Size(nPix,0)).Width();
             tools::Long& nLogicWidthPTwips = nColWidth;
 
-            if ( !bLayoutRTL )
+            if ( !bLayoutRTL || bLOKActive )
             {
                 aArea.AdjustLeft( -nLogicWidth );
                 if (bLOKPrintTwips)
@@ -1982,7 +1983,7 @@ void ScViewData::EditGrowX()
 
             if ( aArea.Right() > aArea.Left() + aSize.Width() - 1 )
             {
-                if ( !bLayoutRTL )
+                if ( !bLayoutRTL || bLOKActive )
                 {
                     aArea.SetLeft( aArea.Right() - aSize.Width() + 1 );
                     if (bLOKPrintTwips)
@@ -2008,7 +2009,7 @@ void ScViewData::EditGrowX()
             tools::Long nPix = ToPixel( nColWidth, nPPTX );
             tools::Long nLogicWidth = pWin->PixelToLogic(Size(nPix,0)).Width();
             tools::Long& nLogicWidthPTwips = nColWidth;
-            if ( bLayoutRTL )
+            if ( bLayoutRTL && !bLOKActive )
             {
                 aArea.AdjustLeft( -nLogicWidth );
                 if (bLOKPrintTwips)
@@ -2023,7 +2024,7 @@ void ScViewData::EditGrowX()
 
             if ( aArea.Right() > aArea.Left() + aSize.Width() - 1 )
             {
-                if ( bLayoutRTL )
+                if ( bLayoutRTL && !bLOKActive )
                 {
                     aArea.SetLeft( aArea.Right() - aSize.Width() + 1 );
                     if (bLOKPrintTwips)
@@ -2516,7 +2517,7 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW 
nWhereY, ScSplitPos eWhich,
         }
     }
 
-    if (mrDoc.IsLayoutRTL(nForTab))
+    if (mrDoc.IsLayoutRTL(nForTab) && !bIsTiledRendering)
     {
         //  mirror horizontal position
         nScrPosX = aScrSize.Width() - 1 - nScrPosX;

Reply via email to