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

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