editeng/source/editeng/editview.cxx  |   27 ++++++-
 editeng/source/editeng/impedit.cxx   |   37 ++++++++-
 editeng/source/editeng/impedit.hxx   |    6 +
 include/editeng/editview.hxx         |    4 +
 include/sfx2/ipclient.hxx            |    4 +
 include/sfx2/lokcharthelper.hxx      |    3 
 include/svx/svdmrkv.hxx              |    6 +
 sc/source/core/tool/editutil.cxx     |    6 +
 sc/source/ui/cctrl/checklistmenu.cxx |   13 ++-
 sc/source/ui/cctrl/dpcontrol.cxx     |    7 +
 sc/source/ui/drawfunc/drawsh.cxx     |    5 +
 sc/source/ui/drawfunc/fusel.cxx      |   12 +++
 sc/source/ui/inc/gridwin.hxx         |    4 -
 sc/source/ui/unoobj/docuno.cxx       |   34 ++++++--
 sc/source/ui/view/drawvie3.cxx       |    2 
 sc/source/ui/view/drawview.cxx       |   16 ++--
 sc/source/ui/view/gridwin2.cxx       |    7 +
 sc/source/ui/view/gridwin4.cxx       |  135 ++++++++++++++++++++++++++++++++---
 sc/source/ui/view/tabview.cxx        |   16 +++-
 sc/source/ui/view/tabview3.cxx       |    7 +
 sc/source/ui/view/tabvwsh2.cxx       |    3 
 sc/source/ui/view/tabvwshb.cxx       |   14 +++
 sc/source/ui/view/viewdata.cxx       |   32 ++++----
 sfx2/source/view/ipclient.cxx        |   26 ++++++
 sfx2/source/view/lokcharthelper.cxx  |    6 +
 svx/source/svdraw/sdrpagewindow.cxx  |   13 ++-
 svx/source/svdraw/svdedxv.cxx        |    3 
 svx/source/svdraw/svdmrkv.cxx        |   36 ++++++++-
 svx/source/svdraw/svdview.cxx        |    8 ++
 vcl/source/gdi/bmpacc2.cxx           |    5 +
 30 files changed, 417 insertions(+), 80 deletions(-)

New commits:
commit f1ff0ec57914e8871f8563cd26ee1b87d562f1c8
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Mon Jan 10 12:03:54 2022 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:10 2022 +0100

    lokCalcRTL: fix chart insertion position
    
    Change-Id: I573cb19643d7a048f3313aba90fa9b5514c9cc74

diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index f1aa58eabaf3..4dda1b46aa50 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -1703,9 +1703,12 @@ Point ScTabView::GetChartInsertPos( const Size& rSize, 
const ScRange& rCellRange
         ActivatePart( eUsedPart );
 
         //  get the visible rectangle in logic units
-
+        bool bLOKActive = comphelper::LibreOfficeKit::isActive();
         MapMode aDrawMode = pWin->GetDrawMapMode();
-        tools::Rectangle aVisible( pWin->PixelToLogic( tools::Rectangle( 
Point(0,0), pWin->GetOutputSizePixel() ), aDrawMode ) );
+        tools::Rectangle aVisible(
+            bLOKActive ?
+            OutputDevice::LogicToLogic( aViewData.getLOKVisibleArea(), 
MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM) )
+            : pWin->PixelToLogic( tools::Rectangle( Point(0,0), 
pWin->GetOutputSizePixel() ), aDrawMode ) );
 
         ScDocument& rDoc = aViewData.GetDocument();
         SCTAB nTab = aViewData.GetTabNo();
@@ -1729,6 +1732,14 @@ Point ScTabView::GetChartInsertPos( const Size& rSize, 
const ScRange& rCellRange
         tools::Rectangle aSelection = rDoc.GetMMRect( rCellRange.aStart.Col(), 
rCellRange.aStart.Row(),
                                                 rCellRange.aEnd.Col(), 
rCellRange.aEnd.Row(), nTab );
 
+        if (bLOKActive && bLayoutRTL)
+        {
+            // In this case we operate in negative X coordinates. The 
rectangle aSelection already
+            // has negative X coordinates. So the x coordinates in the 
rectangle aVisible(from getLOKVisibleArea)
+            // need be negated to match.
+            aVisible = tools::Rectangle(-aVisible.Right(), aVisible.Top(), 
-aVisible.Left(), aVisible.Bottom());
+        }
+
         tools::Long nLeftSpace = aSelection.Left() - aVisible.Left();
         tools::Long nRightSpace = aVisible.Right() - aSelection.Right();
         tools::Long nTopSpace = aSelection.Top() - aVisible.Top();
@@ -1755,7 +1766,6 @@ Point ScTabView::GetChartInsertPos( const Size& rSize, 
const ScRange& rCellRange
         else if ( nTopSpace >= nNeededHeight || nBottomSpace >= nNeededHeight )
         {
             // second preference: completely above or below the selection
-
             if ( nBottomSpace > nNeededHeight )             // bottom is 
preferred
                 aInsertPos.setY( aSelection.Bottom() + 1 );
             else
commit c2cbe0dbe4c9e4ce8014e881ba3663add77f7aca
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Thu Jan 6 15:12:16 2022 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:10 2022 +0100

    lokCalcRTL: trim invalidation rect to ensure +ve X
    
    Change-Id: Ifecb52167e3cddee036e1e1e9bd5782a1138b654

diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index cb085fcc6e64..087f08271a5a 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1627,6 +1627,15 @@ void ScGridWindow::LogicInvalidate(const 
tools::Rectangle* pRectangle)
         pResultRectangle = &aRectangle;
     }
 
+    // Trim invalidation rectangle overlapping negative X region in RTL mode.
+    if (pResultRectangle && pResultRectangle->Left() < 0
+        && mrViewData.GetDocument().IsLayoutRTL(mrViewData.GetTabNo()))
+    {
+        pResultRectangle->SetLeft(0);
+        if (pResultRectangle->Right() < 0)
+            pResultRectangle->SetRight(0);
+    }
+
     ScTabViewShell* pViewShell = mrViewData.GetViewShell();
     SfxLokHelper::notifyInvalidation(pViewShell, pResultRectangle);
 }
commit 04bb404bffa9fe19568655e81bcd5db21f153cbc
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Thu Jan 6 14:52:56 2022 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:10 2022 +0100

    lok: setClientZoom: check PPTX/Y approx equality too
    
    This is needed because the initial PPTX/Y on document load does not
    match the implied PPTX/Y corresponding to the client requested zoomX/Y.
    
    For instance when document is loaded by LOK client and 100% zoom is
    requested, the correct PPTX/Y should be (1/15 = 0.0666667) but the
    initial PPTX/Y on the ScViewData is 0.0647702
    
    Change-Id: I996e9f003abd269df0994f3d114e42f84bb2bb20

diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index f18793734baf..86bd13cb5a16 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1028,7 +1028,11 @@ void ScModelObj::setClientZoom(int nTilePixelWidth_, int 
nTilePixelHeight_, int
     const Fraction newZoomX(nTilePixelWidth_ * TWIPS_PER_PIXEL, 
nTileTwipWidth_);
     const Fraction newZoomY(nTilePixelHeight_ * TWIPS_PER_PIXEL, 
nTileTwipHeight_);
 
-    if (pViewData->GetZoomX() == newZoomX && pViewData->GetZoomY() == newZoomY)
+    double fDeltaPPTX = std::abs(ScGlobal::nScreenPPTX * 
static_cast<double>(newZoomX) - pViewData->GetPPTX());
+    double fDeltaPPTY = std::abs(ScGlobal::nScreenPPTY * 
static_cast<double>(newZoomY) - pViewData->GetPPTY());
+    constexpr double fEps = 1E-08;
+
+    if (pViewData->GetZoomX() == newZoomX && pViewData->GetZoomY() == newZoomY 
&& fDeltaPPTX < fEps && fDeltaPPTY < fEps)
         return;
 
     pViewData->SetZoom(newZoomX, newZoomY, true);
commit 284068c7eb473bafd5cafeb30a78daab4538cff6
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Thu Jan 6 10:54:49 2022 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:09 2022 +0100

    lokCalcRTL: fix rendering of charts in edit mode
    
    Inform Sfx2InPlaceClient and LokChartHelper when negated X coordinates
    are used. Ensure that invalidation rectangles have positive coordinates
    in all cases.
    
    Change-Id: I8f5440718e288d8f0d379c8da5f49a29e51f6940

diff --git a/include/sfx2/ipclient.hxx b/include/sfx2/ipclient.hxx
index d3fead566486..208a1bf82e56 100644
--- a/include/sfx2/ipclient.hxx
+++ b/include/sfx2/ipclient.hxx
@@ -86,6 +86,10 @@ public:
     void                ResetObject();
     bool                IsUIActive() const;
 
+    /// To indicate that negated document X coordinates are used
+    void                SetNegativeX(bool bSet);
+    bool                IsNegativeX() const;
+
     virtual void        FormatChanged(); // object format was changed (used 
for StarMath formulas aligning)
 };
 
diff --git a/include/sfx2/lokcharthelper.hxx b/include/sfx2/lokcharthelper.hxx
index 020abad111f0..aa7cfb5867ac 100644
--- a/include/sfx2/lokcharthelper.hxx
+++ b/include/sfx2/lokcharthelper.hxx
@@ -47,7 +47,8 @@ public:
     static void PaintAllChartsOnTile(VirtualDevice& rDevice,
                                      int nOutputWidth, int nOutputHeight,
                                      int nTilePosX, int nTilePosY,
-                                     tools::Long nTileWidth, tools::Long 
nTileHeight);
+                                     tools::Long nTileWidth, tools::Long 
nTileHeight,
+                                     bool bNegativeX = false);
     bool postMouseEvent(int nType, int nX, int nY,
                         int nCount, int nButtons, int nModifier,
                         double fScaleX = 1.0, double fScaleY = 1.0);
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 3af00c03a404..f18793734baf 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -568,9 +568,6 @@ void ScModelObj::paintTile( VirtualDevice& rDevice,
     pGridWindow->PaintTile( rDevice, nOutputWidth, nOutputHeight,
                             nTilePosX, nTilePosY, nTileWidth, nTileHeight );
 
-    LokChartHelper::PaintAllChartsOnTile(rDevice, nOutputWidth, nOutputHeight,
-                                         nTilePosX, nTilePosY, nTileWidth, 
nTileHeight);
-
     // Draw Form controls
     ScDrawLayer* pDrawLayer = pDocShell->GetDocument().GetDrawLayer();
     SdrPage* pPage = pDrawLayer->GetPage(sal_uInt16(pViewData->GetTabNo()));
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 9de8604f2bfd..cb085fcc6e64 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -33,6 +33,7 @@
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <comphelper/lok.hxx>
 #include <sfx2/lokhelper.hxx>
+#include <sfx2/lokcharthelper.hxx>
 
 #include <svx/svdview.hxx>
 #include <svx/svdpagv.hxx>
@@ -1581,6 +1582,12 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
     DrawContent(rDevice, aTabInfo, aOutputData, true);
     rDevice.SetMapMode(aOriginalMode);
 
+    // Paint the chart(s) in edit mode.
+    LokChartHelper::PaintAllChartsOnTile(rDevice, nOutputWidth, nOutputHeight,
+        nTilePosX, nTilePosY, nTileWidth, nTileHeight, bLayoutRTL);
+
+    rDevice.SetMapMode(aOriginalMode);
+
     // Flag drawn formula cells "unchanged".
     rDoc.ResetChanged(ScRange(nTopLeftTileCol, nTopLeftTileRow, nTab, 
nBottomRightTileCol, nBottomRightTileRow, nTab));
     rDoc.PrepareFormulaCalc();
diff --git a/sc/source/ui/view/tabvwshb.cxx b/sc/source/ui/view/tabvwshb.cxx
index d0006564d53e..a62770067796 100644
--- a/sc/source/ui/view/tabvwshb.cxx
+++ b/sc/source/ui/view/tabvwshb.cxx
@@ -80,6 +80,13 @@ void ScTabViewShell::ConnectObject( const SdrOle2Obj* pObj )
         return;
 
     pClient = new ScClient( this, pWin, GetScDrawView()->GetModel(), pObj );
+    ScViewData& rViewData = GetViewData();
+    ScDocShell* pDocSh = rViewData.GetDocShell();
+    ScDocument& rDoc = pDocSh->GetDocument();
+    bool bNegativeX = comphelper::LibreOfficeKit::isActive() && 
rDoc.IsNegativePage(rViewData.GetTabNo());
+    if (bNegativeX)
+        pClient->SetNegativeX(true);
+
     tools::Rectangle aRect = pObj->GetLogicRect();
     Size aDrawSize = aRect.GetSize();
 
@@ -153,10 +160,17 @@ void ScTabViewShell::ActivateObject( SdrOle2Obj* pObj, 
tools::Long nVerb )
     bool bErrorShown = false;
 
     {
+        ScViewData& rViewData = GetViewData();
+        ScDocShell* pDocSh = rViewData.GetDocShell();
+        ScDocument& rDoc = pDocSh->GetDocument();
+        bool bNegativeX = comphelper::LibreOfficeKit::isActive() && 
rDoc.IsNegativePage(rViewData.GetTabNo());
         SfxInPlaceClient* pClient = FindIPClient( xObj, pWin );
         if ( !pClient )
             pClient = new ScClient( this, pWin, GetScDrawView()->GetModel(), 
pObj );
 
+        if (bNegativeX)
+            pClient->SetNegativeX(true);
+
         if ( (sal_uInt32(nErr) & ERRCODE_ERROR_MASK) == 0 && xObj.is() )
         {
             tools::Rectangle aRect = pObj->GetLogicRect();
diff --git a/sfx2/source/view/ipclient.cxx b/sfx2/source/view/ipclient.cxx
index fc594ff2e658..141e7f954e19 100644
--- a/sfx2/source/view/ipclient.cxx
+++ b/sfx2/source/view/ipclient.cxx
@@ -90,6 +90,15 @@ public:
     }
 };
 
+tools::Rectangle lcl_negateRectX(const tools::Rectangle& rRect)
+{
+    return tools::Rectangle(
+        std::max(0l, -rRect.Right()),
+        rRect.Top(),
+        std::max(0l, -rRect.Left()),
+        rRect.Bottom());
+}
+
 }
 
 // SfxInPlaceClient_Impl
@@ -111,6 +120,7 @@ public:
     bool                            m_bStoreObject;
     bool                            m_bUIActive;            // set and cleared 
when notification for UI (de)activation is sent
     bool                            m_bResizeNoScale;
+    bool                            m_bNegativeX;
 
     uno::Reference < embed::XEmbeddedObject > m_xObject;
 
@@ -121,6 +131,7 @@ public:
     , m_bStoreObject( true )
     , m_bUIActive( false )
     , m_bResizeNoScale( false )
+    , m_bNegativeX( false )
     {}
 
     void SizeHasChanged();
@@ -345,7 +356,7 @@ void SAL_CALL SfxInPlaceClient_Impl::activatingInplace()
                     aRect = OutputDevice::LogicToLogic(aRect, 
MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
             }
 
-            OString str = aRect.toString() + ", \"INPLACE\"";
+            OString str = (m_bNegativeX ? lcl_negateRectX(aRect) : 
aRect).toString() + ", \"INPLACE\"";
             pViewShell->libreOfficeKitViewCallback( 
LOK_CALLBACK_GRAPHIC_SELECTION, str.getStr() );
         }
     }
@@ -823,7 +834,8 @@ void SfxInPlaceClient::Invalidate()
     tools::Rectangle aRealObjArea( m_xImp->m_aObjArea );
     aRealObjArea.SetSize( Size( tools::Long( aRealObjArea.GetWidth()  * 
m_xImp->m_aScaleWidth ),
                                 tools::Long( aRealObjArea.GetHeight() * 
m_xImp->m_aScaleHeight ) ) );
-    m_pEditWin->Invalidate( aRealObjArea );
+
+    m_pEditWin->Invalidate( IsNegativeX() ? lcl_negateRectX(aRealObjArea) : 
aRealObjArea );
 
     ViewChanged();
 }
@@ -1120,4 +1132,14 @@ bool SfxInPlaceClient::IsUIActive() const
     return m_xImp->m_bUIActive;
 }
 
+void SfxInPlaceClient::SetNegativeX(bool bSet)
+{
+    m_xImp->m_bNegativeX = bSet;
+}
+
+bool SfxInPlaceClient::IsNegativeX() const
+{
+    return m_xImp->m_bNegativeX;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/view/lokcharthelper.cxx 
b/sfx2/source/view/lokcharthelper.cxx
index d5995e33ba8d..b0b71aaa0353 100644
--- a/sfx2/source/view/lokcharthelper.cxx
+++ b/sfx2/source/view/lokcharthelper.cxx
@@ -236,7 +236,8 @@ void LokChartHelper::PaintTile(VirtualDevice& 
rRenderContext, const tools::Recta
 void LokChartHelper::PaintAllChartsOnTile(VirtualDevice& rDevice,
                                           int nOutputWidth, int nOutputHeight,
                                           int nTilePosX, int nTilePosY,
-                                          tools::Long nTileWidth, tools::Long 
nTileHeight)
+                                          tools::Long nTileWidth, tools::Long 
nTileHeight,
+                                          bool bNegativeX)
 {
     if (comphelper::LibreOfficeKit::isTiledAnnotations())
         return;
@@ -257,7 +258,8 @@ void LokChartHelper::PaintAllChartsOnTile(VirtualDevice& 
rDevice,
 
     SfxViewShell* pCurView = SfxViewShell::Current();
     int nPartForCurView = pCurView ? pCurView->getPart() : -1;
-    tools::Rectangle aTileRect(Point(nTilePosX, nTilePosY), Size(nTileWidth, 
nTileHeight));
+    tools::Long nTileRectLeft = bNegativeX ? -nTilePosX - nTileWidth : 
nTilePosX;
+    tools::Rectangle aTileRect(Point(nTileRectLeft, nTilePosY), 
Size(nTileWidth, nTileHeight));
     SfxViewShell* pViewShell = SfxViewShell::GetFirst();
     while (pViewShell)
     {
commit 0f2208a43861ebe94c4a2482a0cf7e5c63bb186e
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Tue Jan 4 14:20:41 2022 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:09 2022 +0100

    lokCalcRTL: negate mouse event X for chart and controls
    
    Change-Id: I389047140d1a3d2c67a861a3e20f799206d937b6

diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 9f89e3be6af8..3af00c03a404 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -735,8 +735,14 @@ void ScModelObj::postMouseEvent(int nType, int nX, int nY, 
int nCount, int nButt
 
     // check if user hit a chart which is being edited by him
     ScTabViewShell * pTabViewShell = pViewData->GetViewShell();
+    SCTAB nTab = pViewData->GetTabNo();
     LokChartHelper aChartHelper(pTabViewShell);
-    if (aChartHelper.postMouseEvent(nType, nX, nY,
+    const ScDocument& rDoc = pDocShell->GetDocument();
+    // In LOK RTL mode draw/svx operates in negative X coordinates
+    // But the coordinates from client is always positive, so negate nX for 
draw.
+    bool bDrawNegativeX = rDoc.IsNegativePage(nTab);
+    int nDrawX = bDrawNegativeX ? -nX : nX;
+    if (aChartHelper.postMouseEvent(nType, nDrawX, nY,
                                     nCount, nButtons, nModifier,
                                     pViewData->GetPPTX(), 
pViewData->GetPPTY()))
     {
@@ -744,21 +750,23 @@ void ScModelObj::postMouseEvent(int nType, int nX, int 
nY, int nCount, int nButt
     }
 
     Point aPointTwip(nX, nY);
+    Point aPointTwipDraw(nDrawX, nY);
 
     // check if the user hit a chart which is being edited by someone else
     // and, if so, skip current mouse event
     if (nType != LOK_MOUSEEVENT_MOUSEMOVE)
     {
-        if (LokChartHelper::HitAny(aPointTwip))
+        if (LokChartHelper::HitAny(aPointTwipDraw))
             return;
     }
 
     // Check if a control is hit
     Point aPointHMM = LokControlHandler::convertTwipToMm100(aPointTwip);
+    Point aPointHMMDraw(bDrawNegativeX ? -aPointHMM.X() : aPointHMM.X(), 
aPointHMM.Y());
     ScDrawLayer* pDrawLayer = pDocShell->GetDocument().GetDrawLayer();
-    SdrPage* pPage = pDrawLayer->GetPage(sal_uInt16(pViewData->GetTabNo()));
+    SdrPage* pPage = pDrawLayer->GetPage(sal_uInt16(nTab));
     SdrView* pDrawView = pViewData->GetViewShell()->GetScDrawView();
-    if (LokControlHandler::postMouseEvent(pPage, pDrawView, *pGridWindow, 
nType, aPointHMM, nCount, nButtons, nModifier))
+    if (LokControlHandler::postMouseEvent(pPage, pDrawView, *pGridWindow, 
nType, aPointHMMDraw, nCount, nButtons, nModifier))
         return;
 
     if (!pGridWindow->HasChildPathFocus(true))
commit 0fe02bb99e5dfa8379a49de75683fc350e4c4dbd
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Tue Jan 4 12:55:45 2022 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:09 2022 +0100

    lokCalcRTL: fix editing of shape text
    
    Inform editeng that negated document x coordinates are used in this case
    and ensure that editeng generated invalidation rectangles always have
    positive X coordinates.
    
    Change-Id: I2e450707ce02f7bcd8e4d299f857c37ebbd5e2c6

diff --git a/editeng/source/editeng/editview.cxx 
b/editeng/source/editeng/editview.cxx
index 98a5da7c93e7..15743ad73c68 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -201,20 +201,30 @@ tools::Rectangle EditView::GetInvalidateRect() const
     }
 }
 
+namespace {
+
+tools::Rectangle lcl_negateRectX(const tools::Rectangle& rRect)
+{
+    return tools::Rectangle(-rRect.Right(), rRect.Top(), -rRect.Left(), 
rRect.Bottom());
+}
+
+}
+
 void EditView::InvalidateWindow(const tools::Rectangle& rClipRect)
 {
+    bool bNegativeX = IsNegativeX();
     if (EditViewCallbacks* pEditViewCallbacks = 
pImpEditView->getEditViewCallbacks())
     {
         // do not invalidate and trigger a global repaint, but forward
         // the need for change to the applied EditViewCallback, can e.g.
         // be used to visualize the active edit text in an OverlayObject
-        pEditViewCallbacks->EditViewInvalidate(rClipRect);
+        pEditViewCallbacks->EditViewInvalidate(bNegativeX ? 
lcl_negateRectX(rClipRect) : rClipRect);
     }
     else
     {
         // classic mode: invalidate and trigger full repaint
         // of the changed area
-        GetWindow()->Invalidate(rClipRect);
+        GetWindow()->Invalidate(bNegativeX ? lcl_negateRectX(rClipRect) : 
rClipRect);
     }
 }
 
@@ -222,10 +232,11 @@ void EditView::InvalidateOtherViewWindows( const 
tools::Rectangle& rInvRect )
 {
     if (comphelper::LibreOfficeKit::isActive())
     {
+        bool bNegativeX = IsNegativeX();
         for (auto& pWin : pImpEditView->aOutWindowSet)
         {
             if (pWin)
-                pWin->Invalidate( rInvRect );
+                pWin->Invalidate( bNegativeX ? lcl_negateRectX(rInvRect) : 
rInvRect );
         }
     }
 }
@@ -1688,4 +1699,14 @@ bool EditView::IsSuppressLOKMessages() const
     return pImpEditView->IsSuppressLOKMessages();
 }
 
+void EditView::SetNegativeX(bool bSet)
+{
+    pImpEditView->SetNegativeX(bSet);
+}
+
+bool EditView::IsNegativeX() const
+{
+    return pImpEditView->IsNegativeX();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/source/editeng/impedit.cxx 
b/editeng/source/editeng/impedit.cxx
index f37d0456cf77..bb1a1ae00d47 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -197,7 +197,8 @@ ImpEditView::ImpEditView( EditView* pView, EditEngine* 
pEng, vcl::Window* pWindo
     eAnchorMode(EEAnchorMode::TopLeft),
     mpEditViewCallbacks(nullptr),
     mbBroadcastLOKViewCursor(comphelper::LibreOfficeKit::isActive()),
-    mbSuppressLOKMessages(false)
+    mbSuppressLOKMessages(false),
+    mbNegativeX(false)
 {
     aEditSelection.Min() = pEng->GetEditDoc().GetStartPaM();
     aEditSelection.Max() = pEng->GetEditDoc().GetEndPaM();
@@ -868,6 +869,15 @@ void ImpEditView::SetOutputArea( const tools::Rectangle& 
rRect )
     SetScrollDiffX( static_cast<sal_uInt16>(aOutArea.GetWidth()) * 2 / 10 );
 }
 
+namespace {
+
+tools::Rectangle lcl_negateRectX(const tools::Rectangle& rRect)
+{
+    return tools::Rectangle(-rRect.Right(), rRect.Top(), -rRect.Left(), 
rRect.Bottom());
+}
+
+}
+
 void ImpEditView::InvalidateAtWindow(const tools::Rectangle& rRect)
 {
     if (EditViewCallbacks* pCallbacks = getEditViewCallbacks())
@@ -875,13 +885,13 @@ void ImpEditView::InvalidateAtWindow(const 
tools::Rectangle& rRect)
         // do not invalidate and trigger a global repaint, but forward
         // the need for change to the applied EditViewCallback, can e.g.
         // be used to visualize the active edit text in an OverlayObject
-        pCallbacks->EditViewInvalidate(rRect);
+        pCallbacks->EditViewInvalidate(mbNegativeX ? lcl_negateRectX(rRect) : 
rRect);
     }
     else
     {
         // classic mode: invalidate and trigger full repaint
         // of the changed area
-        GetWindow()->Invalidate(rRect);
+        GetWindow()->Invalidate(mbNegativeX ? lcl_negateRectX(rRect) : rRect);
     }
 }
 
diff --git a/editeng/source/editeng/impedit.hxx 
b/editeng/source/editeng/impedit.hxx
index b9f5628b1881..753ce82a1f4b 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -301,6 +301,7 @@ private:
     std::unique_ptr<LOKSpecialPositioning> mpLOKSpecialPositioning;
     bool mbBroadcastLOKViewCursor:1;
     bool mbSuppressLOKMessages:1;
+    bool mbNegativeX:1;
 
     EditViewCallbacks* getEditViewCallbacks() const
     {
@@ -469,6 +470,9 @@ public:
 
     void SuppressLOKMessages(bool bSet) { mbSuppressLOKMessages = bSet; }
     bool IsSuppressLOKMessages() const { return mbSuppressLOKMessages; }
+
+    void SetNegativeX(bool bSet) { mbNegativeX = bSet; }
+    bool IsNegativeX() const { return mbNegativeX; }
 };
 
 
diff --git a/include/editeng/editview.hxx b/include/editeng/editview.hxx
index 117cc68b7c99..2c073de906f4 100644
--- a/include/editeng/editview.hxx
+++ b/include/editeng/editview.hxx
@@ -361,6 +361,10 @@ public:
 
     void SuppressLOKMessages(bool bSet);
     bool IsSuppressLOKMessages() const;
+
+    /// To inform editeng that negated x document coordinates are in use.
+    void SetNegativeX(bool bSet);
+    bool IsNegativeX() const;
 };
 
 #endif // INCLUDED_EDITENG_EDITVIEW_HXX
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 8aae4a10b6d9..9de8604f2bfd 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1027,7 +1027,11 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
             if (bIsTiledRendering)
             {
                 Point aOrigin = aOriginalMode.GetOrigin();
-                aOrigin.setX(aOrigin.getX() / TWIPS_PER_PIXEL + 
aOutputData.nScrX);
+                if (bLayoutRTL)
+                    aOrigin.setX(-aOrigin.getX() / TWIPS_PER_PIXEL + 
aOutputData.nScrX + aOutputData.GetScrW());
+                else
+                    aOrigin.setX(aOrigin.getX() / TWIPS_PER_PIXEL + 
aOutputData.nScrX);
+
                 aOrigin.setY(aOrigin.getY() / TWIPS_PER_PIXEL + 
aOutputData.nScrY);
                 const double twipFactor = 15 * 1.76388889; // 26.45833335
                 aOrigin = Point(aOrigin.getX() * twipFactor,
diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx
index a4d43f97b8c6..c6af7e8c409e 100644
--- a/svx/source/svdraw/svdedxv.cxx
+++ b/svx/source/svdraw/svdedxv.cxx
@@ -868,6 +868,9 @@ OutlinerView* 
SdrObjEditView::ImpMakeOutlinerView(vcl::Window* pWin, OutlinerVie
         pOutlView->SetWindow(pWin);
     }
 
+    if (mbNegativeX)
+        pOutlView->GetEditView().SetNegativeX(mbNegativeX);
+
     // disallow scrolling
     EVControlBits nStat = pOutlView->GetControlWord();
     nStat &= ~EVControlBits::AUTOSCROLL;
commit bb37b46182bcff2f10edcc590cedbc4bb5820c4b
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Mon Dec 6 13:55:43 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:09 2022 +0100

    lokCalcRTL: shapes: negate mouse-event x coordinate
    
    Change-Id: I153334940b41859e6fd9dee64217925627f0f292

diff --git a/svx/source/svdraw/svdview.cxx b/svx/source/svdraw/svdview.cxx
index 0018233533f2..2a1a27f70ee3 100644
--- a/svx/source/svdraw/svdview.cxx
+++ b/svx/source/svdraw/svdview.cxx
@@ -264,6 +264,14 @@ SdrHitKind SdrView::PickAnything(const MouseEvent& rMEvt, 
SdrMouseEventKind nEve
     }
     Point aPnt(rMEvt.GetPosPixel());
     if (pOut!=nullptr) aPnt=pOut->PixelToLogic(aPnt);
+
+    if (mbNegativeX)
+    {
+        // Shape's x coordinates are all negated,
+        // Hence negate mouse event's x coord to match.
+        aPnt.setX(-aPnt.X());
+    }
+
     rVEvt.aLogicPos=aPnt;
     return PickAnything(aPnt,rVEvt);
 }
commit 5e37acbaaa0b0891829907331ecacd2d3b67526d
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Mon Dec 6 13:42:27 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:09 2022 +0100

    lokCalcRTL: shapes: do not send negative(X) invalidations
    
    LOK client expects tile invalidations in positive document coordinates
    irrespective of RTL flags.
    
    For this introduce a flag mbNegativeX in svx class SdrMarkView to
    indicate the case when all x coordinates are negated (this happens only
    for the LOK + Calc + RTL mode). Use this flag to counter negate the
    x coordinates before sending invalidation rectangles.
    
    Change-Id: I35d8142718b538e55b668a8ee18f3dd1fe433951

diff --git a/include/svx/svdmrkv.hxx b/include/svx/svdmrkv.hxx
index bbe0e8eb2446..80402527615d 100644
--- a/include/svx/svdmrkv.hxx
+++ b/include/svx/svdmrkv.hxx
@@ -131,6 +131,9 @@ protected:
     // flag to completely disable handles at the view
     bool                        mbMarkHandlesHidden : 1;
 
+    // flag indicating whether all x coordinates are negated or not
+    bool                        mbNegativeX : 1;
+
     // Helper to get a possible GridOffset from SdrObject
     bool getPossibleGridOffsetForSdrObject(
         basegfx::B2DVector& rOffset,
@@ -240,6 +243,9 @@ public:
 
     bool HasMarkableObj() const { return MarkableObjectsExceed(0); };
 
+    /// whether all x coordinates in use are negated or not
+    void SetNegativeX(bool bOn) { mbNegativeX = bOn; }
+    bool IsNegativeX() const { return mbNegativeX; }
 
 // migrate selections
 
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index bb3870ad4e3e..9f89e3be6af8 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -586,7 +586,13 @@ void ScModelObj::setPart( int nPart, bool 
/*bAllowChangeFocus*/ )
     ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
 
     if (pTabView)
+    {
+        if (SdrView* pDrawView = pViewData->GetViewShell()->GetScDrawView())
+            pDrawView->SetNegativeX(comphelper::LibreOfficeKit::isActive() &&
+                pViewData->GetDocument().IsLayoutRTL(nPart));
+
         pTabView->SelectTabPage(nPart + 1);
+    }
 }
 
 int ScModelObj::getParts()
diff --git a/sc/source/ui/view/drawvie3.cxx b/sc/source/ui/view/drawvie3.cxx
index 4e2928b0569d..36476e8150b6 100644
--- a/sc/source/ui/view/drawvie3.cxx
+++ b/sc/source/ui/view/drawvie3.cxx
@@ -25,6 +25,7 @@
 #include <svx/svdoole2.hxx>
 #include <svx/ImageMapInfo.hxx>
 #include <sfx2/viewfrm.hxx>
+#include <comphelper/lok.hxx>
 
 #include <strings.hrc>
 #include <scresid.hxx>
@@ -48,6 +49,7 @@ ScDrawView::ScDrawView(
     pDropMarkObj( nullptr ),
     bInConstruct( true )
 {
+    SetNegativeX(comphelper::LibreOfficeKit::isActive() && 
rDoc.IsLayoutRTL(nTab));
     // #i73602# Use default from the configuration
     SetBufferedOverlayAllowed(getOptionsDrawinglayer().IsOverlayBuffer_Calc());
 
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 83cb7459afa9..8aae4a10b6d9 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1566,6 +1566,8 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
             new FmFormView(
                 *pModel,
                 &rDevice));
+
+        mpLOKDrawView->SetNegativeX(bLayoutRTL);
         mpLOKDrawView->ShowSdrPage(mpLOKDrawView->GetModel()->GetPage(nTab));
         aOutputData.SetDrawView(mpLOKDrawView.get());
         aOutputData.SetSpellCheckContext(mpSpellCheckCxt.get());
diff --git a/svx/source/svdraw/sdrpagewindow.cxx 
b/svx/source/svdraw/sdrpagewindow.cxx
index 8fd16e1eb02c..2a4b3b4d708b 100644
--- a/svx/source/svdraw/sdrpagewindow.cxx
+++ b/svx/source/svdraw/sdrpagewindow.cxx
@@ -428,7 +428,8 @@ void SdrPageWindow::RedrawLayer(const SdrLayerID* pId,
 // Invalidate call, used from ObjectContact(OfPageView) in 
InvalidatePartOfView(...)
 void SdrPageWindow::InvalidatePageWindow(const basegfx::B2DRange& rRange)
 {
-    if (GetPageView().IsVisible() && GetPaintWindow().OutputToWindow())
+    bool bLOKActive = comphelper::LibreOfficeKit::isActive();
+    if (!bLOKActive && GetPageView().IsVisible() && 
GetPaintWindow().OutputToWindow())
     {
         const SvtOptionsDrawinglayer aDrawinglayerOpt;
         OutputDevice& rWindow(GetPaintWindow().GetOutputDevice());
@@ -453,15 +454,19 @@ void SdrPageWindow::InvalidatePageWindow(const 
basegfx::B2DRange& rRange)
         GetPageView().GetView().InvalidateOneWin(rWindow, 
aVCLDiscreteRectangle);
         rWindow.EnableMapMode(bWasMapModeEnabled);
     }
-    else if (comphelper::LibreOfficeKit::isActive())
+    else if (bLOKActive)
     {
         // we don't really have to have a paint window with LOK; OTOH we know
         // that the drawinglayer units are 100ths of mm, so they are easy to
         // convert to twips
+
+        // If the shapes use negative X coordinates, make them positive before 
sending
+        // the invalidation rectangle.
+        bool bNegativeX = mpImpl->mrPageView.GetView().IsNegativeX();
         const tools::Rectangle aRect100thMM(
-            static_cast<tools::Long>(floor(rRange.getMinX())),
+            static_cast<tools::Long>(bNegativeX ? std::max(0.0, 
ceil(-rRange.getMaxX())) : floor(rRange.getMinX())),
             static_cast<tools::Long>(floor(rRange.getMinY())),
-            static_cast<tools::Long>(ceil(rRange.getMaxX())),
+            static_cast<tools::Long>(bNegativeX ? std::max(0.0, 
floor(-rRange.getMinX())) : ceil(rRange.getMaxX())),
             static_cast<tools::Long>(ceil(rRange.getMaxY())));
 
         const tools::Rectangle aRectTwips = 
OutputDevice::LogicToLogic(aRect100thMM, MapMode(MapUnit::Map100thMM), 
MapMode(MapUnit::MapTwip));
diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index ba6a8d586d69..57ab32e44f81 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -177,6 +177,7 @@ SdrMarkView::SdrMarkView(SdrModel& rSdrModel, OutputDevice* 
pOut)
     , mbMrkPntDirty(false)
     , mbMarkedPointsRectsDirty(false)
     , mbMarkHandlesHidden(false)
+    , mbNegativeX(false)
 {
 
     BrkMarkObj();
@@ -264,6 +265,14 @@ void SdrMarkView::ModelHasChanged()
         }
 
         pResultSelection = &aSelection;
+
+        if (mbNegativeX)
+        {
+            // Convert to positive X doc-coordinates
+            tools::Long nTmp = aSelection.Left();
+            aSelection.SetLeft(-aSelection.Right());
+            aSelection.SetRight(-nTmp);
+        }
     }
 
     if(SfxViewShell* pViewShell = GetSfxViewShell())
commit 3df583520ee03bad42df09db7dde4c0c683a228b
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Tue Nov 30 16:06:51 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:09 2022 +0100

    lokCalcRTL: negate the +ve shape handle X coordinate...
    
    ...from lok client as all shape X coordinates are negative in lok-RTL
    mode.
    
    Change-Id: Ic4ba064888901109c85760bb0afda609b5d5942c

diff --git a/sc/source/ui/drawfunc/drawsh.cxx b/sc/source/ui/drawfunc/drawsh.cxx
index a0bcc3a78a3b..278a063c6c7b 100644
--- a/sc/source/ui/drawfunc/drawsh.cxx
+++ b/sc/source/ui/drawfunc/drawsh.cxx
@@ -60,6 +60,7 @@
 #include <svx/xflgrit.hxx>
 #include <editeng/colritem.hxx>
 #include <tools/UnitConversion.hxx>
+#include <comphelper/lok.hxx>
 
 SFX_IMPL_INTERFACE(ScDrawShell, SfxShell)
 
@@ -216,7 +217,9 @@ void ScDrawShell::ExecDrawAttr( SfxRequest& rReq )
                 const sal_uLong handleNum = handleNumItem->GetValue();
                 const sal_uLong newPosX = 
convertTwipToMm100(newPosXTwips->GetValue());
                 const sal_uLong newPosY = 
convertTwipToMm100(newPosYTwips->GetValue());
-                pView->MoveShapeHandle(handleNum, Point(newPosX, newPosY), 
OrdNum ? OrdNum->GetValue() : -1);
+
+                bool bNegateX = comphelper::LibreOfficeKit::isActive() && 
rViewData.GetDocument().IsLayoutRTL(rViewData.GetTabNo());
+                pView->MoveShapeHandle(handleNum, Point(bNegateX ? -newPosX : 
newPosX, newPosY), OrdNum ? OrdNum->GetValue() : -1);
             }
         }
         break;
commit 18038bd35c01abf1aad69932c4a7e75988921289
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Tue Nov 30 13:42:33 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:08 2022 +0100

    lokCalcRTL: RTL negation for shape insertion
    
    Change-Id: I8e3bb21fadd05a7b67acce34bfdc354fefba076b

diff --git a/sc/source/ui/view/tabvwsh2.cxx b/sc/source/ui/view/tabvwsh2.cxx
index 66265311f56a..6644c28098d5 100644
--- a/sc/source/ui/view/tabvwsh2.cxx
+++ b/sc/source/ui/view/tabvwsh2.cxx
@@ -333,12 +333,13 @@ void ScTabViewShell::ExecDraw(SfxRequest& rReq)
     {
         GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, 
SfxCallMode::ASYNCHRON);
         ScViewData& rViewData = GetViewData();
+        tools::Long nLayoutSign = 
rViewData.GetDocument().IsLayoutRTL(rViewData.GetTabNo()) ? -1 : 1;
         aInsertPos = rViewData.getLOKVisibleArea().Center();
         if (comphelper::LibreOfficeKit::isCompatFlagSet(
                 comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
             aInsertPos = rViewData.GetPrintTwipsPosFromTileTwips(aInsertPos);
 
-        aInsertPos.setX(sc::TwipsToHMM(aInsertPos.X()));
+        aInsertPos.setX(nLayoutSign * sc::TwipsToHMM(aInsertPos.X()));
         aInsertPos.setY(sc::TwipsToHMM(aInsertPos.Y()));
 
         aInsertPos.AdjustX( -sal_Int32(nDefaultObjectSizeWidth / 2) );
commit d423a86b3e063da02cfdb302eaa996ca54eed9d0
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Thu Nov 25 17:38:14 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:08 2022 +0100

    lokCalcRTL: shape selection: negate mouse X...
    
    as in LOK RTL mode draw objects have negated document X coordinate.
    
    Change-Id: Ie4c00fc0d1aa458a0aa6dd502be227cd6f82be3e

diff --git a/sc/source/ui/drawfunc/fusel.cxx b/sc/source/ui/drawfunc/fusel.cxx
index 164332f060d6..20d785a7221a 100644
--- a/sc/source/ui/drawfunc/fusel.cxx
+++ b/sc/source/ui/drawfunc/fusel.cxx
@@ -31,6 +31,7 @@
 #include <sfx2/app.hxx>
 #include <sfx2/ipclient.hxx>
 #include <sfx2/viewfrm.hxx>
+#include <comphelper/lok.hxx>
 
 #include <fusel.hxx>
 #include <sc.hrc>
@@ -84,6 +85,14 @@ bool FuSelection::MouseButtonDown(const MouseEvent& rMEvt)
     else
         aMDPos = pWindow->PixelToLogic(rMEvt.GetPosPixel());
 
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        ScViewData& rViewData = rViewShell.GetViewData();
+        ScDocument& rDocument = rViewData.GetDocument();
+        if (rDocument.IsNegativePage(rViewData.GetTabNo()))
+            aMDPos.setX(-aMDPos.X());
+    }
+
     if ( rMEvt.IsLeft() )
     {
         SdrHdl* pHdl = pView->PickHandle(aMDPos);
@@ -350,6 +359,9 @@ bool FuSelection::MouseButtonUp(const MouseEvent& rMEvt)
     ::std::vector< OUString > aExcludedChartNames;
     ScRangeListVector aProtectedChartRangesVector;
 
+    if (comphelper::LibreOfficeKit::isActive() && 
rDocument.IsNegativePage(rViewData.GetTabNo()))
+        aPnt.setX(-aPnt.X());
+
     if (pView && rMEvt.IsLeft())
     {
         if ( pView->IsDragObj() )
commit 316b7f90cb06b41e186a1a5a868e49693ba010cc
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Mon Dec 13 11:36:53 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:08 2022 +0100

    lokCalcRTL: ensure +ve X coords in shape handles/selections msgs
    
    LOK client expects all coordinates to be in +ve document coordinates, so
    negate the negative X coordinates of LOK RTL shapes before sending the
    selection/handles messages.
    
    Change-Id: I683581370c5b115efbe315224d6218ec2e74c7f1

diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index 6ca400399f5c..ba6a8d586d69 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -686,6 +686,7 @@ OUString lcl_getDragParameterString( const OUString& rCID )
 bool SdrMarkView::dumpGluePointsToJSON(boost::property_tree::ptree& rTree)
 {
     bool result = false;
+    tools::Long nSignX = mbNegativeX ? -1 : 1;
     if (OutputDevice* rOutDev = mpMarkedPV->GetView().GetFirstOutputDevice())
     {
         bool bConvertUnit = false;
@@ -716,7 +717,7 @@ bool 
SdrMarkView::dumpGluePointsToJSON(boost::property_tree::ptree& rTree)
                 Point rPoint = rGP.GetAbsolutePos(*pObj);
                 if (bConvertUnit)
                     rPoint = OutputDevice::LogicToLogic(rPoint, 
MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
-                point.put("x", rPoint.getX());
+                point.put("x", nSignX * rPoint.getX());
                 point.put("y", rPoint.getY());
                 node.add_child("point", point);
                 points.push_back(std::make_pair("", node));
@@ -729,7 +730,7 @@ bool 
SdrMarkView::dumpGluePointsToJSON(boost::property_tree::ptree& rTree)
                 if (bConvertUnit)
                     p = OutputDevice::LogicToLogic(p, 
MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
                 boost::property_tree::ptree gridOffset;
-                gridOffset.put("x", p.getX());
+                gridOffset.put("x", nSignX * p.getX());
                 gridOffset.put("y", p.getY());
                 object.add_child("gridoffset", gridOffset);
             }
@@ -748,6 +749,7 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle 
const & rRect, const S
     SfxViewShell* pViewShell = GetSfxViewShell();
 
     tools::Rectangle aSelection(rRect);
+    tools::Long nSignX = mbNegativeX ? -1 : 1;
     bool bIsChart = false;
     Point addLogicOffset(0, 0);
     bool convertMapMode = false;
@@ -845,7 +847,7 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle 
const & rRect, const S
                 if (convertMapMode)
                     p = OutputDevice::LogicToLogic(p, 
MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip));
                 aExtraInfo.append(",\"gridOffsetX\":");
-                aExtraInfo.append(OString::number(p.getX()));
+                aExtraInfo.append(OString::number(nSignX * p.getX()));
                 aExtraInfo.append(",\"gridOffsetY\":");
                 aExtraInfo.append(OString::number(p.getY()));
             }
@@ -948,6 +950,8 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle 
const & rRect, const S
                                                     const basegfx::B2DPoint 
aB2Point = aPolygon.getB2DPoint(nIndex);
                                                     Point 
aPoint(aB2Point.getX(), aB2Point.getY());
                                                     
aPoint.Move(aLogicOffset.getX(), aLogicOffset.getY());
+                                                    if (mbNegativeX)
+                                                        
aPoint.setX(-aPoint.X());
                                                     if (nIndex > 0)
                                                         sPolygonElem += " ";
                                                     sPolygonElem += 
aPoint.toString();
@@ -1058,8 +1062,21 @@ void 
SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle const & rRect, const S
                     handleArrayStr = handleArrayStr + aStream.str().c_str();
                 }
             }
-            sSelectionText = aSelection.toString() +
-                ", " + OString::number(nRotAngle);
+
+            if (mbNegativeX)
+            {
+                tools::Rectangle aNegatedRect(aSelection);
+                aNegatedRect.SetLeft(-aNegatedRect.Left());
+                aNegatedRect.SetRight(-aNegatedRect.Right());
+                aNegatedRect.Justify();
+                sSelectionText = aNegatedRect.toString() +
+                    ", " + OString::number(nRotAngle);
+            }
+            else
+            {
+                sSelectionText = aSelection.toString() +
+                    ", " + OString::number(nRotAngle);
+            }
             if (!aExtraInfo.isEmpty())
             {
                 sSelectionTextView = sSelectionText + ", " + 
aExtraInfo.toString() + "}";
commit 2e7d02ab55754ffbc9e799c98cb7c8e37394a420
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Thu Nov 25 16:02:35 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:08 2022 +0100

    lokCalcRTL: adjustments for shapes rendering
    
    In LOK-RTL mode GetScrPos() always returns document pixel coordinates
    and not something mirrored w.r.t gridwindow width.
    
    * Grid offset must have the opposite sign since the SdrObjects/ranges
      have negative coordinates with no offset.
    
    * Drawing area rectangle and the pixel-offset for tile rendering device
      also needs adjustments when painting the drawing layers.
    
    Change-Id: I987a6876983aee129c06b3577918dbc62d6e7c4c

diff --git a/sc/source/ui/view/drawview.cxx b/sc/source/ui/view/drawview.cxx
index 43704c80e17d..86042772f399 100644
--- a/sc/source/ui/view/drawview.cxx
+++ b/sc/source/ui/view/drawview.cxx
@@ -965,7 +965,7 @@ void ScDrawView::SyncForGrid( SdrObject* pObj )
     Point aCurPosHmm = pGridWin->PixelToLogic(aCurPos, aDrawMode );
     Point aGridOff = aCurPosHmm - aOldPos;
     // fdo#63878 Fix the X position for RTL Sheet
-    if( rDoc.IsNegativePage( GetTab() ) )
+    if( rDoc.IsNegativePage( GetTab() ) && 
!comphelper::LibreOfficeKit::isActive() )
         aGridOff.setX( aCurPosHmm.getX() + aOldPos.getX() );
 }
 
@@ -1044,13 +1044,16 @@ bool ScDrawView::calculateGridOffsetForSdrObject(
     Point aCurPosHmm(pGridWin->PixelToLogic(aCurPos, aDrawMode));
     Point aGridOff(aCurPosHmm - aOldPos);
 
+    bool bLOKActive = comphelper::LibreOfficeKit::isActive();
+    bool bNegativePage = rDoc.IsNegativePage(GetTab());
+
     // fdo#63878 Fix the X position for RTL Sheet
-    if(rDoc.IsNegativePage(GetTab()))
+    if(bNegativePage && !bLOKActive)
     {
         aGridOff.setX(aCurPosHmm.getX() + aOldPos.getX());
     }
 
-    rTarget.setX(aGridOff.X());
+    rTarget.setX(bNegativePage && bLOKActive ? -aGridOff.X() : aGridOff.X());
     rTarget.setY(aGridOff.Y());
     return true;
 }
@@ -1092,13 +1095,16 @@ bool ScDrawView::calculateGridOffsetForB2DRange(
     Point aCurPosHmm(pGridWin->PixelToLogic(aCurPos, aDrawMode));
     Point aGridOff(aCurPosHmm - aOldPos);
 
+    bool bLOKActive = comphelper::LibreOfficeKit::isActive();
+    bool bNegativePage = rDoc.IsNegativePage(GetTab());
+
     // fdo#63878 Fix the X position for RTL Sheet
-    if(rDoc.IsNegativePage(GetTab()))
+    if(bNegativePage && !bLOKActive)
     {
         aGridOff.setX(aCurPosHmm.getX() + aOldPos.getX());
     }
 
-    rTarget.setX(aGridOff.X());
+    rTarget.setX(bLOKActive && bNegativePage ? -aGridOff.X() : aGridOff.X());
     rTarget.setY(aGridOff.Y());
     return true;
 }
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 827ae1074175..83cb7459afa9 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -729,17 +729,20 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
     }
     tools::Rectangle aDrawingRectLogic;
     bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
+    bool bLokRTL = bLayoutRTL && bIsTiledRendering;
     std::unique_ptr<ScLokRTLContext> pLokRTLCtxt(
-        bIsTiledRendering && bLayoutRTL ?
+        bLokRTL ?
             new ScLokRTLContext(aOutputData, aOriginalMode.GetOrigin().X() / 
TWIPS_PER_PIXEL) :
             nullptr);
 
     {
         // get drawing pixel rect
-        tools::Rectangle aDrawingRectPixel(Point(nScrX, nScrY), 
Size(aOutputData.GetScrW(), aOutputData.GetScrH()));
+        tools::Rectangle aDrawingRectPixel(
+            bLokRTL ? Point(-(nScrX + aOutputData.GetScrW()), nScrY) : 
Point(nScrX, nScrY),
+            Size(aOutputData.GetScrW(), aOutputData.GetScrH()));
 
         // correct for border (left/right)
-        if(rDoc.MaxCol() == nX2)
+        if(rDoc.MaxCol() == nX2 && !bLokRTL)
         {
             if(bLayoutRTL)
             {
@@ -960,7 +963,8 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const 
ScTableInfo& rTableI
     if (bIsTiledRendering)
     {
         Point aOrigin = aOriginalMode.GetOrigin();
-        Size aPixelOffset(aOrigin.getX() / TWIPS_PER_PIXEL, aOrigin.getY() / 
TWIPS_PER_PIXEL);
+        tools::Long nXOffset = bLayoutRTL ? (-aOrigin.getX() / TWIPS_PER_PIXEL 
+ aOutputData.GetScrW()) : aOrigin.getX() / TWIPS_PER_PIXEL;
+        Size aPixelOffset(nXOffset, aOrigin.getY() / TWIPS_PER_PIXEL);
         pContentDev->SetPixelOffset(aPixelOffset);
         comphelper::LibreOfficeKit::setLocalRendering();
     }
@@ -1081,7 +1085,7 @@ 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 && bLayoutRTL)
+                            if (bLokRTL)
                             {
                                 // Transform the cell range X coordinates such 
that the edit cell area is
                                 // horizontally mirrored w.r.t the 
(combined-)tile.
@@ -1095,7 +1099,7 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
                             aEnd.AdjustY( -2 );
 
                             tools::Rectangle aBackground(aStart, aEnd);
-                            if (bIsTiledRendering && bLayoutRTL)
+                            if (bLokRTL)
                                 aBackground.Justify();
 
                             // Need to draw the background in absolute coords.
@@ -1171,7 +1175,7 @@ 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)
+        if (bLokRTL)
         {
             // Transform the cell range X coordinates such that the edit cell 
area is
             // horizontally mirrored w.r.t the (combined-)tile.
@@ -1186,7 +1190,7 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
 
         // set the correct mapmode
         tools::Rectangle aBackground(aStart, aEnd);
-        if (bIsTiledRendering && bLayoutRTL)
+        if (bLokRTL)
             aBackground.Justify();
         tools::Rectangle aBGAbs(aBackground);
 
commit be329f241ee4953a039ab4bb22f46a5ac0ad5859
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Wed Nov 24 17:44:30 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:08 2022 +0100

    lokCalcRTL: fix autofilter popup position
    
    Change-Id: Iecf41c286e28f849f77da47a0c5f73cbbc02986a

diff --git a/sc/source/ui/cctrl/checklistmenu.cxx 
b/sc/source/ui/cctrl/checklistmenu.cxx
index efd8688dc649..c80c896f832f 100644
--- a/sc/source/ui/cctrl/checklistmenu.cxx
+++ b/sc/source/ui/cctrl/checklistmenu.cxx
@@ -1381,8 +1381,17 @@ void ScCheckListMenuControl::launch(const 
tools::Rectangle& rRect)
     if (maConfig.mbRTL)
     {
         // In RTL mode, the logical "left" is visual "right".
-        tools::Long nLeft = aRect.Left() - aRect.GetWidth();
-        aRect.SetLeft( nLeft );
+        if (!comphelper::LibreOfficeKit::isActive())
+        {
+            tools::Long nLeft = aRect.Left() - aRect.GetWidth();
+            aRect.SetLeft( nLeft );
+        }
+        else
+        {
+            // in LOK mode, rRect is in document pixel coordinates, so width 
has to be added
+            // to place the popup next to the (visual) left aligned button.
+            aRect.Move(aRect.GetWidth(), 0);
+        }
     }
     else if (mnWndWidth < aRect.GetWidth())
     {
commit 2eb5f597c3b1c5a680d6e0f9d0719f9f6977e1a3
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Wed Nov 24 16:59:47 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:08 2022 +0100

    lokCalcRTL: fix autofilter button hit detection
    
    No mirroring needed when not in tile painting mode. All positions are
    in document coordinates.
    
    Change-Id: I45425e2ddce7f5ddc5086dcdce31bb6d081edc41

diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx
index 839c0fc6b6d9..0b0044cefc4b 100644
--- a/sc/source/ui/view/gridwin2.cxx
+++ b/sc/source/ui/view/gridwin2.cxx
@@ -109,8 +109,9 @@ bool ScGridWindow::DoAutoFilterButton( SCCOL nCol, SCROW 
nRow, const MouseEvent&
     Point aDiffPix = rMEvt.GetPosPixel();
 
     aDiffPix -= aScrPos;
+    bool bLOKActive = comphelper::LibreOfficeKit::isActive();
     bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
-    if ( bLayoutRTL )
+    if ( bLayoutRTL && !bLOKActive )
         aDiffPix.setX( -aDiffPix.X() );
 
     tools::Long nSizeX, nSizeY;
@@ -121,8 +122,8 @@ bool ScGridWindow::DoAutoFilterButton( SCCOL nCol, SCROW 
nRow, const MouseEvent&
 
     // Check if the mouse cursor is clicking on the popup arrow box.
     mpFilterButton.reset(new ScDPFieldButton(this, 
&GetSettings().GetStyleSettings(), &mrViewData.GetZoomY(), &rDoc));
-    mpFilterButton->setBoundingBox(aScrPos, aScrSize, bLayoutRTL);
-    mpFilterButton->setPopupLeft(bLayoutRTL);   // #i114944# AutoFilter button 
is left-aligned in RTL
+    mpFilterButton->setBoundingBox(aScrPos, aScrSize, bLayoutRTL && 
!bLOKActive);
+    mpFilterButton->setPopupLeft(bLayoutRTL && bLOKActive ? false : 
bLayoutRTL);   // #i114944# AutoFilter button is left-aligned in RTL
     Point aPopupPos;
     Size aPopupSize;
     mpFilterButton->getPopupBoundingBox(aPopupPos, aPopupSize);
commit 85a986f25956518978381df097b1f7d88477fd3d
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Wed Nov 24 16:12:32 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:07 2022 +0100

    lokCalcRTL: Workaround to avoid DrawPoly ghost drawings
    
    Change-Id: Ib6c794766fe68305566a293892c9123d64a2fc47

diff --git a/sc/source/ui/cctrl/dpcontrol.cxx b/sc/source/ui/cctrl/dpcontrol.cxx
index d7dd13dd5c4e..3c0600c76550 100644
--- a/sc/source/ui/cctrl/dpcontrol.cxx
+++ b/sc/source/ui/cctrl/dpcontrol.cxx
@@ -21,6 +21,7 @@
 
 #include <vcl/outdev.hxx>
 #include <vcl/settings.hxx>
+#include <comphelper/lok.hxx>
 #include <scitems.hxx>
 #include <document.hxx>
 #include <docpool.hxx>
@@ -181,7 +182,11 @@ void ScDPFieldButton::drawPopupButton()
 
     // the arrowhead
     Color aArrowColor = mbHasHiddenMember ? mpStyle->GetHighlightLinkColor() : 
mpStyle->GetButtonTextColor();
-    mpOutDev->SetLineColor(aArrowColor);
+    // FIXME: HACK: The following DrawPolygon draws twice in lok rtl mode for 
some reason.
+    // => one at the correct location with fill (possibly no outline)
+    // => and the other at an x offset with outline and without fill
+    // eg. Replacing this with a DrawRect() does not have any such problems.
+    comphelper::LibreOfficeKit::isActive() ? mpOutDev->SetLineColor() : 
mpOutDev->SetLineColor(aArrowColor);
     mpOutDev->SetFillColor(aArrowColor);
 
     Point aCenter(aPos.X() + (aSize.Width() / 2), aPos.Y() + (aSize.Height() / 
2));
commit 0145c2c0e4c69d486693488fa24490ee4458349a
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Wed Nov 24 16:09:29 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:07 2022 +0100

    lokCalcRTL: draw autofilter buttons at correct coordinates
    
    Factor out the transformation from document coordinates to tile device
    coordinates in ScLokRTLContext.
    
    Change-Id: I426a179bff253233f6d45b67ddfde8b3bb1344a1

diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index b4c9c619d072..2b4d60a53b30 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -54,6 +54,7 @@ class ScNoteMarker;
 class SdrHdlList;
 class ScTransferObj;
 struct SpellCallbackInfo;
+class ScLokRTLContext;
 
         //  mouse status (nMouseStatus)
 
@@ -398,7 +399,8 @@ public:
     void DPLaunchFieldPopupMenu(const Point& rScrPos, const Size& rScrSize,
                                 tools::Long nDimIndex, ScDPObject* pDPObj);
 
-    void DrawButtons(SCCOL nX1, SCCOL nX2, const ScTableInfo& rTabInfo, 
OutputDevice* pContentDev);
+    void DrawButtons(SCCOL nX1, SCCOL nX2, const ScTableInfo& rTabInfo, 
OutputDevice* pContentDev,
+                     ScLokRTLContext* pLokRTLContext);
 
     using Window::Draw;
     void            Draw( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2,
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index fac0f60b41a0..827ae1074175 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -620,6 +620,34 @@ private:
 
 }
 
+/**
+ * Used to store the necessary information about the (combined-)tile
+ * area relevant to coordinate transformations in RTL mode.
+ */
+class ScLokRTLContext
+{
+public:
+    ScLokRTLContext(const ScOutputData& rOutputData, const tools::Long 
nTileDeviceOriginPixelX):
+        mrOutputData(rOutputData),
+        mnTileDevOriginX(nTileDeviceOriginPixelX)
+    {}
+
+    /**
+     * Converts from document x pixel position to the
+     * corresponding pixel position w.r.t the tile device origin.
+     */
+    tools::Long docToTilePos(tools::Long nPosX) const
+    {
+        tools::Long nMirrorX = (-2 * mnTileDevOriginX) + 
mrOutputData.GetScrW();
+        return nMirrorX - 1 - nPosX;
+    }
+
+
+private:
+    const ScOutputData& mrOutputData;
+    const tools::Long mnTileDevOriginX;
+};
+
 void ScGridWindow::DrawContent(OutputDevice &rDevice, const ScTableInfo& 
rTableInfo, ScOutputData& aOutputData,
         bool bLogicText)
 {
@@ -701,6 +729,10 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
     }
     tools::Rectangle aDrawingRectLogic;
     bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
+    std::unique_ptr<ScLokRTLContext> pLokRTLCtxt(
+        bIsTiledRendering && bLayoutRTL ?
+            new ScLokRTLContext(aOutputData, aOriginalMode.GetOrigin().X() / 
TWIPS_PER_PIXEL) :
+            nullptr);
 
     {
         // get drawing pixel rect
@@ -889,9 +921,8 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, const 
ScTableInfo& rTableI
     else
         pContentDev->SetMapMode(MapMode(MapUnit::MapPixel));
 
-        // Autofilter- and Pivot-Buttons
-
-    DrawButtons(nX1, nX2, rTableInfo, pContentDev);          // Pixel
+    // Autofilter- and Pivot-Buttons
+    DrawButtons(nX1, nX2, rTableInfo, pContentDev, pLokRTLCtxt.get());         
 // Pixel
 
     pContentDev->SetMapMode(MapMode(MapUnit::MapPixel));
 
@@ -1054,12 +1085,8 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
                             {
                                 // Transform the cell range X coordinates such 
that the edit cell area is
                                 // horizontally mirrored w.r.t the 
(combined-)tile.
-                                tools::Long nStartTileX = 
-aOriginalMode.GetOrigin().X() / TWIPS_PER_PIXEL;
-                                // 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());
+                                
aStart.setX(pLokRTLCtxt->docToTilePos(aStart.X()));
+                                aEnd.setX(pLokRTLCtxt->docToTilePos(aEnd.X()));
                             }
 
                             // don't overwrite grid
@@ -1148,12 +1175,8 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
         {
             // Transform the cell range X coordinates such that the edit cell 
area is
             // horizontally mirrored w.r.t the (combined-)tile.
-            tools::Long nStartTileX = -aOriginalMode.GetOrigin().X() / 
TWIPS_PER_PIXEL;
-            // 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());
+            aStart.setX(pLokRTLCtxt->docToTilePos(aStart.X()));
+            aEnd.setX(pLokRTLCtxt->docToTilePos(aEnd.X()));
         }
 
         // don't overwrite grid
@@ -1882,7 +1905,7 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, 
SCCOL nX2, SCROW nY2,
     }
 }
 
-void ScGridWindow::DrawButtons(SCCOL nX1, SCCOL nX2, const ScTableInfo& 
rTabInfo, OutputDevice* pContentDev)
+void ScGridWindow::DrawButtons(SCCOL nX1, SCCOL nX2, const ScTableInfo& 
rTabInfo, OutputDevice* pContentDev, ScLokRTLContext* pLokRTLContext)
 {
     aComboButton.SetOutputDevice( pContentDev );
 
@@ -1978,6 +2001,8 @@ void ScGridWindow::DrawButtons(SCCOL nX1, SCCOL nX2, 
const ScTableInfo& rTabInfo
                     mrViewData.GetMergeSizePixel( nStartCol, nStartRow, 
nSizeX, nSizeY );//get nSizeX
                     nSizeY = ScViewData::ToPixel(rDoc.GetRowHeight(nRow, 
nTab), mrViewData.GetPPTY());
                     Point aScrPos = mrViewData.GetScrPos( nCol, nRow, eWhich );
+                    if (pLokRTLContext)
+                        
aScrPos.setX(pLokRTLContext->docToTilePos(aScrPos.X()));
 
                     aCellBtn.setBoundingBox(aScrPos, Size(nSizeX-1, nSizeY-1), 
bLayoutRTL);
                     aCellBtn.setPopupLeft(bLayoutRTL);   // #i114944# 
AutoFilter button is left-aligned in RTL
commit 04a48ea15b9e692ded4f3012b41e765451669e46
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Mon Nov 22 16:34:32 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:07 2022 +0100

    lokCalcRTL: selection coords should be mirrored w.r.t output area
    
    Change-Id: I52bbbd4ca69a599c90c00d25513064b025f72bf4

diff --git a/editeng/source/editeng/impedit.cxx 
b/editeng/source/editeng/impedit.cxx
index 55486adf6ac4..f37d0456cf77 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -518,6 +518,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, 
vcl::Region* pRegion,
 
     bool bStartHandleVisible = false;
     bool bEndHandleVisible = false;
+    bool bLOKCalcRTL = mpLOKSpecialPositioning && 
pEditEngine->IsRightToLeft(nStartPara);
 
     auto DrawHighlight = [&, nStartLine = sal_Int32(0), nEndLine = 
sal_Int32(0)](
                              const ImpEditEngine::LineAreaInfo& rInfo) mutable 
{
@@ -594,7 +595,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, 
vcl::Region* pRegion,
                 aTmpRect.SetRight(aLineXPosStartEnd.Max());
                 aTmpRect.Move(aLineOffset.Width(), 0);
                 ImplDrawHighlightRect(pTarget, aTmpRect.TopLeft(), 
aTmpRect.BottomRight(),
-                                      pPolyPoly.get());
+                                      pPolyPoly.get(), bLOKCalcRTL);
             }
             else
             {
@@ -620,7 +621,7 @@ void ImpEditView::DrawSelectionXOR( EditSelection aTmpSel, 
vcl::Region* pRegion,
                     aTmpRect.Move(aLineOffset.Width(), 0);
 
                     ImplDrawHighlightRect(pTarget, aTmpRect.TopLeft(), 
aTmpRect.BottomRight(),
-                                          pPolyPoly.get());
+                                          pPolyPoly.get(), bLOKCalcRTL);
                     nTmpStartIndex = nTmpEndIndex;
                 }
             }
@@ -657,7 +658,7 @@ void ImpEditView::GetSelectionRectangles(EditSelection 
aTmpSel, std::vector<tool
     aRegion.GetRegionRectangles(rLogicRects);
 }
 
-void ImpEditView::ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& 
rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly )
+void ImpEditView::ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& 
rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly, 
bool bLOKCalcRTL )
 {
     if ( rDocPosTopLeft.X() == rDocPosBottomRight.X() )
         return;
@@ -670,6 +671,13 @@ void ImpEditView::ImplDrawHighlightRect( OutputDevice* 
_pTarget, const Point& rD
         Point aRefPointLogical = GetOutputArea().TopLeft();
         // Get the relative coordinates w.r.t refpoint in display units.
         aSelRect.Move(-aRefPointLogical.X(), -aRefPointLogical.Y());
+        if (bLOKCalcRTL)
+        {
+            tools::Long nMirrorW = GetOutputArea().GetWidth();
+            tools::Long nLeft = aSelRect.Left(), nRight = aSelRect.Right();
+            aSelRect.SetLeft(nMirrorW - nRight);
+            aSelRect.SetRight(nMirrorW - nLeft);
+        }
         // Convert from display unit to twips.
         aSelRect = OutputDevice::LogicToLogic(aSelRect, MapMode(eDevUnit), 
MapMode(MapUnit::MapTwip));
 
diff --git a/editeng/source/editeng/impedit.hxx 
b/editeng/source/editeng/impedit.hxx
index 362df78817cc..b9f5628b1881 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -337,7 +337,7 @@ protected:
     void ShowDDCursor( const tools::Rectangle& rRect );
     void HideDDCursor();
 
-    void ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& 
rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly 
);
+    void ImplDrawHighlightRect( OutputDevice* _pTarget, const Point& 
rDocPosTopLeft, const Point& rDocPosBottomRight, tools::PolyPolygon* pPolyPoly, 
bool bLOKCalcRTL );
     tools::Rectangle ImplGetEditCursor(EditPaM& aPaM, GetCursorFlags 
nShowCursorFlags,
             sal_Int32& nTextPortionStart, const ParaPortion* pParaPortion) 
const;
 
commit 455d4047487396c3c70d6113ac5d07deecb1d3a1
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Mon Nov 22 14:29:05 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:07 2022 +0100

    lokCalcRTL: fix editcell painting from other views as well
    
    Change-Id: Iac431996570f1f7eb091809442d8781ea60aa9b5

diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 4770c183324f..fac0f60b41a0 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1050,12 +1050,26 @@ 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 && 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 = 
-aOriginalMode.GetOrigin().X() / TWIPS_PER_PIXEL;
+                                // 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) );
                             aEnd.AdjustY( -2 );
 
                             tools::Rectangle aBackground(aStart, aEnd);
+                            if (bIsTiledRendering && bLayoutRTL)
+                                aBackground.Justify();
 
                             // Need to draw the background in absolute coords.
                             Point aOrigin = aOriginalMode.GetOrigin();
commit 48e6ef20c6bab7029e46d985d67a907147dd2adf
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Mon Nov 22 14:14:10 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:07 2022 +0100

    lokCalcRTL: edit cell painting: avoid indent...
    
    to match the behaviour in desktop Calc.
    
    Change-Id: I615255635500edf375b237abcab0a21ba6153cce

diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index ded37621e12f..4770c183324f 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -287,7 +287,8 @@ static void lcl_GetEditAreaTLOffset(tools::Long& nOffsetX, 
tools::Long& nOffsetY
         rViewData.GetPPTY(), Fraction(1.0), Fraction(1.0),
         false /* bPrintTwips */);
     const ScPatternAttr* pPattern = rDoc.GetPattern(rAddr);
-    nIndent = aEUtil.GetIndent(pPattern);
+    if (!rDoc.IsLayoutRTL(rAddr.Tab()))
+        nIndent = aEUtil.GetIndent(pPattern);
     aEUtil.GetMargins(pPattern, nLeftMargin, nTopMargin, nDummy, nDummy);
     nOffsetX = nIndent + nLeftMargin;
     nOffsetY = nTopMargin;
commit 92d2035acc9d13fea46003a2b2650439d6a2f2fb
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Mon Nov 22 14:12:32 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:07 2022 +0100

    lokCalcRTL: text cursor pos should be mirrored w.r.t output area
    
    Change-Id: Ied4e02d2dd30b7132ea1bc5f0d5b717355ed8b4f

diff --git a/editeng/source/editeng/impedit.cxx 
b/editeng/source/editeng/impedit.cxx
index c485b8d64174..55486adf6ac4 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -1332,6 +1332,13 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool 
bForceVisCursor )
                 Point aRefPointLogical = GetOutputArea().TopLeft();
                 // Get the relative coordinates w.r.t refpoint in display hmm.
                 aCursorRectPureLogical.Move(-aRefPointLogical.X(), 
-aRefPointLogical.Y());
+                if (pEditEngine->IsRightToLeft(nPara))
+                {
+                    tools::Long nMirrorW = GetOutputArea().GetWidth();
+                    tools::Long nLeft = aCursorRectPureLogical.Left(), nRight 
= aCursorRectPureLogical.Right();
+                    aCursorRectPureLogical.SetLeft(nMirrorW - nRight);
+                    aCursorRectPureLogical.SetRight(nMirrorW - nLeft);
+                }
                 // Convert to twips.
                 aCursorRectPureLogical = 
OutputDevice::LogicToLogic(aCursorRectPureLogical, MapMode(eDevUnit), 
MapMode(MapUnit::MapTwip));
                 // "refpoint" in print twips.
commit 8266f569c864ae309f362088d42dfb3b952c4267
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Fri Nov 19 10:21:46 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:06 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

diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index be3f6a5e9d2e..2167cbbc971a 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -35,6 +35,7 @@
 #include <svl/inethist.hxx>
 #include <unotools/syslocale.hxx>
 #include <sfx2/objsh.hxx>
+#include <comphelper/lok.hxx>
 #include <osl/diagnose.h>
 
 #include <com/sun/star/text/textfield/Type.hpp>
@@ -324,9 +325,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);
@@ -425,7 +427,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 6a644786906d..ded37621e12f 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1129,6 +1129,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 = -aOriginalMode.GetOrigin().X() / 
TWIPS_PER_PIXEL;
+            // 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) );
@@ -1136,7 +1148,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 a2bf70ff6199..6e2bf8ee0aa4 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -1647,6 +1647,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
 
@@ -1690,7 +1691,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)
@@ -1925,12 +1926,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 )
@@ -1964,7 +1965,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)
@@ -1979,7 +1980,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)
@@ -2005,7 +2006,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)
@@ -2020,7 +2021,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)
@@ -2513,7 +2514,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;
commit d819e543c13f85bd9c18fbe61c7983efab9d21c5
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Thu Nov 18 12:32:26 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:06 2022 +0100

    lokCalcRTL: incorrect invalidation rectangle for...
    
    cell properties change. LOK client expects invalidation rectangle in
    document coordinates so ensure we don't mirror the x coordinate.
    
    Change-Id: I27bdd29a0d56c7a7b838b7669e3edde805dd1504

diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index bd34fd5d7520..4994231f7b2b 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -2373,10 +2373,11 @@ void ScTabView::PaintArea( SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol, SCRO
             continue;
 
         bool bLayoutRTL = aViewData.GetDocument().IsLayoutRTL( 
aViewData.GetTabNo() );
-        tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
+        tools::Long nLayoutSign = (!bIsTiledRendering && bLayoutRTL) ? -1 : 1;
 
         Point aStart = aViewData.GetScrPos( nCol1, nRow1, 
static_cast<ScSplitPos>(i) );
         Point aEnd   = aViewData.GetScrPos( nCol2+1, nRow2+1, 
static_cast<ScSplitPos>(i) );
+
         if ( eMode == ScUpdateMode::All )
         {
             if (bIsTiledRendering)
@@ -2388,11 +2389,11 @@ void ScTabView::PaintArea( SCCOL nStartCol, SCROW 
nStartRow, SCCOL nEndCol, SCRO
                 // Remember that wsd expects int and that aEnd.X() is
                 // in pixels and will be converted in twips, before performing
                 // the lok callback, so we need to avoid that an overflow 
occurs.
-                aEnd.setX( bLayoutRTL ? 0 : std::numeric_limits<int>::max() / 
1000 );
+                aEnd.setX( (!bIsTiledRendering && bLayoutRTL) ? 0 : 
std::numeric_limits<int>::max() / 1000 );
             }
             else
             {
-                aEnd.setX( bLayoutRTL ? 0 : 
pGridWin[i]->GetOutputSizePixel().Width() );
+                aEnd.setX( (!bIsTiledRendering && bLayoutRTL) ? 0 : 
pGridWin[i]->GetOutputSizePixel().Width() );
             }
         }
         aEnd.AdjustX( -nLayoutSign );
commit 241909beda0d8985667435127e16bdf902850932
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Wed Nov 17 17:13:16 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:06 2022 +0100

    lokCalcRTL: selections: lokclients need exact document coordinates
    
    so do not do horizontal mirroring.
    
    Change-Id: I93432002810dacfeb609268f436bdf2cfecb3a60

diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 7dbbd94fc82a..6a644786906d 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -2119,7 +2119,8 @@ void ScGridWindow::GetRectsAnyFor(const ScMarkData 
&rMarkData,
     double nPPTX = mrViewData.GetPPTX();
     double nPPTY = mrViewData.GetPPTY();
     bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
-    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
+    // LOK clients needs exact document coordinates, so don't horizontally 
mirror them.
+    tools::Long nLayoutSign = (!comphelper::LibreOfficeKit::isActive() && 
bLayoutRTL) ? -1 : 1;
 
     ScMarkData aMultiMark( rMarkData );
     aMultiMark.SetMarking( false );
commit ef3c67beb96df80179b46bb6d5116d4a5cab7f77
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Wed Nov 17 16:28:43 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:06 2022 +0100

    lokCalcRTL: no internal width based mirroring in GetPosFromPixel
    
    The gridwindow width is historically not synced with the visible area in
    client. Mirroring is not necessary when the client is already sending
    the true document coordinates of the mouse events etc.
    
    Change-Id: I74573be406c512324f4c5db0c53fbc12374b88c8

diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 1d4451b9b2d0..a2bf70ff6199 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -2772,10 +2772,13 @@ void ScViewData::GetPosFromPixel( tools::Long nClickX, 
tools::Long nClickY, ScSp
 
     if (mrDoc.IsLayoutRTL(nForTab))
     {
-        //  mirror horizontal position
-        if (pView)
-            aScrSize.setWidth( pView->GetGridWidth(eHWhich) );
-        nClickX = aScrSize.Width() - 1 - nClickX;
+        if (!comphelper::LibreOfficeKit::isActive())
+        {
+            //  mirror horizontal position
+            if (pView)
+                aScrSize.setWidth( pView->GetGridWidth(eHWhich) );
+            nClickX = aScrSize.Width() - 1 - nClickX;
+        }
     }
 
     SCCOL nStartPosX = GetPosX(eHWhich, nForTab);
commit 1ebd27ac521f78f9cc2124573d85b03b533e8653
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Thu Nov 11 16:23:43 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:06 2022 +0100

    lokCalcRTL: provide sheet RTL flags to client
    
    Change-Id: If881fdea1c6bae10735cfde624ad6f4f3a34e389

diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 0eb5f1fd73e1..bb3870ad4e3e 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -607,11 +607,14 @@ OUString ScModelObj::getPartInfo( int nPart )
     const bool bIsVisible = pViewData->GetDocument().IsVisible(nPart);
     //FIXME: Implement IsSelected().
     const bool bIsSelected = false; 
//pViewData->GetDocument()->IsSelected(nPart);
+    const bool bIsRTLLayout = pViewData->GetDocument().IsLayoutRTL(nPart);
 
     OUString aPartInfo = "{ \"visible\": \"" +
         OUString::number(static_cast<unsigned int>(bIsVisible)) +
         "\", \"selected\": \"" +
         OUString::number(static_cast<unsigned int>(bIsSelected)) +
+        "\", \"rtllayout\": \"" +
+        OUString::number(static_cast<unsigned int>(bIsRTLLayout)) +
         "\" }";
     return aPartInfo;
 }
commit a9c473c3306e28462f9a1898a94277cf0adcbe5e
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Thu Nov 11 15:22:28 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:05 2022 +0100

    lok: copy over the alpha channel too for cairo...
    
    ...based svp-graphics
    
    Change-Id: I653a8e4048c712911f44f610e13c7f6c3e323de2

diff --git a/vcl/source/gdi/bmpacc2.cxx b/vcl/source/gdi/bmpacc2.cxx
index 88f0c7f7482b..64dadadd5f8f 100644
--- a/vcl/source/gdi/bmpacc2.cxx
+++ b/vcl/source/gdi/bmpacc2.cxx
@@ -19,6 +19,7 @@
 
 #include <vcl/bitmapaccess.hxx>
 #include <vcl/BitmapTools.hxx>
+#include <comphelper/lok.hxx>
 
 BitmapColor BitmapReadAccess::GetPixelForN1BitMsbPal(ConstScanline pScanline, 
tools::Long nX, const ColorMask&)
 {
@@ -262,6 +263,8 @@ BitmapColor 
BitmapReadAccess::GetPixelForN32BitTcBgrx(ConstScanline pScanline, t
     aBitmapColor.SetBlue( *pScanline++ );
     aBitmapColor.SetGreen( *pScanline++ );
     aBitmapColor.SetRed( *pScanline );
+    if (comphelper::LibreOfficeKit::isActive())
+        aBitmapColor.SetAlpha(0xFF - *(++pScanline));
 
     return aBitmapColor;
 }
@@ -283,7 +286,7 @@ void BitmapReadAccess::SetPixelForN32BitTcBgrx(Scanline 
pScanline, tools::Long n
     *pScanline++ = rBitmapColor.GetBlue();
     *pScanline++ = rBitmapColor.GetGreen();
     *pScanline++ = rBitmapColor.GetRed();
-    *pScanline = 0xFF;
+    *pScanline = (comphelper::LibreOfficeKit::isActive()) ? 0xFF - 
rBitmapColor.GetAlpha() : 0xFF;
 }
 
 BitmapColor BitmapReadAccess::GetPixelForN32BitTcRgba(ConstScanline pScanline, 
tools::Long nX, const ColorMask&)
commit b3ca461871a92d8d2bd1d4ee713046ee74abbcf0
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Wed Nov 10 18:53:14 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:05 2022 +0100

    lokCalcRTL: h-flip the "combined" tile
    
    This h-flip is needed because the tile containing cell A1 will have the
    coordinates (0, 0). Further aim is to have document coordinates for all
    tile messages and tile invalidation messages. The LOK client should be
    able to map the document coordinates to the correct view coordinates.
    
    In the lok client we also need to h-flip the "regular" tiles at the tile
    position.
    
    Change-Id: Iaf89afeb89f916cb490800ee5d34c4780125f3a0

diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 12323ed0e2aa..7dbbd94fc82a 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1529,6 +1529,13 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
         if (ScDrawView* pDrawView = mrViewData.GetScDrawView())
             pDrawView->resetGridOffsetsForAllSdrPageViews();
     }
+
+    if (bLayoutRTL)
+    {
+        Bitmap aCellBMP = rDevice.GetBitmap(Point(0, 0), Size(nOutputWidth, 
nOutputHeight));
+        aCellBMP.Mirror(BmpMirrorFlags::Horizontal);
+        rDevice.DrawBitmap(Point(0, 0), Size(nOutputWidth, nOutputHeight), 
aCellBMP);
+    }
 }
 
 void ScGridWindow::LogicInvalidate(const tools::Rectangle* pRectangle)
commit 250aeac7434f924c82927a9de8a089e42a4fec00
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Wed Nov 10 18:51:59 2021 +0530
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jan 11 11:18:05 2022 +0100

    lokCalcRTL: Fix the tile offsets
    
    Change-Id: Id0db3d422c8c47ed6fbbc505ca9a857ac54c033a

diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 4128a8ca596a..12323ed0e2aa 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1289,6 +1289,22 @@ namespace
         nBottomRightTileIndex = nEndIndex;
     }
 
+    void lcl_RTLAdjustTileColOffset(ScViewData& rViewData, sal_Int32& 
nTileColOffset,
+        tools::Long nTileEndPx, sal_Int32 nEndCol, SCTAB nTab,
+        const ScDocument& rDoc, double fPPTX)
+    {
+        auto GetColWidthPx = [&rDoc, nTab, fPPTX](SCCOL nCol) {
+            const sal_uInt16 nSize = rDoc.GetColWidth(nCol, nTab);
+            const tools::Long nSizePx = ScViewData::ToPixel(nSize, fPPTX);
+            return nSizePx;
+        };
+
+        ScPositionHelper rHelper = rViewData.GetLOKWidthHelper();
+        tools::Long nEndColPos = rHelper.computePosition(nEndCol, 
GetColWidthPx);
+
+        nTileColOffset += (nEndColPos - nTileEndPx - nTileColOffset);
+    }
+
     class ScLOKProxyObjectContact final : public 
sdr::contact::ObjectContactOfPageView
     {
     private:
@@ -1431,6 +1447,15 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
     if (nBottomRightTileRow > MAXTILEDROW)
         nBottomRightTileRow = MAXTILEDROW;
 
+    bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
+
+    if (bLayoutRTL)
+    {
+        lcl_RTLAdjustTileColOffset(mrViewData, nTopLeftTileColOffset,
+            fTileRightPixel, nBottomRightTileCol, nTab,
+            rDoc, fPPTX);
+    }
+
     // size of the document including drawings, charts, etc.
     SCCOL nEndCol = 0;
     SCROW nEndRow = 0;

Reply via email to