Blame SOURCES/0326-sw-lok-comments-fix-position-of-blinking-cursor-afte.patch

135360
From 4bd7e435c3476b7d267755b9e53ed7d35ce78220 Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Fri, 13 Nov 2015 17:30:22 +0100
135360
Subject: [PATCH 326/398] sw lok comments: fix position of blinking cursor
135360
 after mouse click
135360
135360
LOK always works in absolute twips (origo being the top left corner of
135360
SwEditWin), so not only the callbacks have to translate relative twips
135360
to absolute ones, but the opposite have to be done for mouse event
135360
coordinates.
135360
135360
With this, clicking at a random position inside a comment places the
135360
blinking cursor at a reasonable position, not always at 0,0.
135360
135360
(cherry picked from commit 57972554b58a680f47a05f4d6711c99106f80523)
135360
135360
Change-Id: Ic8d20f177acd9e1908acf17698c53a1470bd4aec
135360
---
135360
 sw/source/uibase/docvw/SidebarWin.cxx | 24 ++++++++++++++++++------
135360
 1 file changed, 18 insertions(+), 6 deletions(-)
135360
135360
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
135360
index 47f5022e8044..71b763b84224 100644
135360
--- a/sw/source/uibase/docvw/SidebarWin.cxx
135360
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
135360
@@ -358,14 +358,25 @@ void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, s
135360
     }
135360
 }
135360
 
135360
-/// We want to work in absolute twips: so set delta between rChild and rParent as origin on rChild, then disable map mode on rChild.
135360
-static void lcl_setAbsoluteTwips(vcl::Window& rParent, vcl::Window& rChild)
135360
+/// Translate absolute <-> relative twips: LOK wants absolute coordinates as output and gives absolute coordinates as input.
135360
+static void lcl_translateTwips(vcl::Window& rParent, vcl::Window& rChild, MouseEvent* pMouseEvent)
135360
 {
135360
+    // Set map mode, so that callback payloads will contain absolute coordinates instead of relative ones.
135360
     Point aOffset(rChild.GetOutOffXPixel() - rParent.GetOutOffXPixel(), rChild.GetOutOffYPixel() - rParent.GetOutOffYPixel());
135360
+    aOffset = rChild.PixelToLogic(aOffset);
135360
     MapMode aMapMode(rChild.GetMapMode());
135360
-    aMapMode.SetOrigin(rChild.PixelToLogic(aOffset));
135360
+    aMapMode.SetOrigin(aOffset);
135360
     rChild.SetMapMode(aMapMode);
135360
     rChild.EnableMapMode(false);
135360
+
135360
+    if (pMouseEvent)
135360
+    {
135360
+        // Set event coordinates, so they contain relative coordinates instead of absolute ones.
135360
+        Point aPos = pMouseEvent->GetPosPixel();
135360
+        aPos.Move(-aOffset.getX(), -aOffset.getY());
135360
+        MouseEvent aMouseEvent(aPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(), pMouseEvent->GetButtons(), pMouseEvent->GetModifier());
135360
+        *pMouseEvent = aMouseEvent;
135360
+    }
135360
 }
135360
 
135360
 void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent)
135360
@@ -373,7 +384,7 @@ void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent)
135360
     if (mpSidebarTextControl)
135360
     {
135360
         mpSidebarTextControl->Push(PushFlags::MAPMODE);
135360
-        lcl_setAbsoluteTwips(*EditWin(), *mpSidebarTextControl);
135360
+        lcl_translateTwips(*EditWin(), *mpSidebarTextControl, nullptr);
135360
 
135360
         mpSidebarTextControl->KeyInput(rKeyEvent);
135360
 
135360
@@ -386,9 +397,10 @@ void SwSidebarWin::MouseButtonDown(const MouseEvent& rMouseEvent)
135360
     if (mpSidebarTextControl)
135360
     {
135360
         mpSidebarTextControl->Push(PushFlags::MAPMODE);
135360
-        lcl_setAbsoluteTwips(*EditWin(), *mpSidebarTextControl);
135360
+        MouseEvent aMouseEvent(rMouseEvent);
135360
+        lcl_translateTwips(*EditWin(), *mpSidebarTextControl, &aMouseEvent);
135360
 
135360
-        mpSidebarTextControl->MouseButtonDown(rMouseEvent);
135360
+        mpSidebarTextControl->MouseButtonDown(aMouseEvent);
135360
 
135360
         mpSidebarTextControl->Pop();
135360
     }
135360
-- 
135360
2.12.0
135360