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

135360
From 0964ec395a33e8299a5caebb122c73687d1b428e Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Fri, 13 Nov 2015 13:33:32 +0100
135360
Subject: [PATCH 323/398] sw lok: fix blinking cursor position of comments
135360
135360
With this, it is possible to click inside a comment (and get a blinking
135360
cursor inside a comment), and also possible to use the arrow keys to
135360
native around and still get correct blinking cursor position.
135360
135360
(cherry picked from commit 5fb91dfd804cd6f3d585bb4113b9a68083ac71ee)
135360
135360
Change-Id: I29eb1e60e4e571151f0b18bec8cf765ea09af09f
135360
---
135360
 sw/inc/SidebarWin.hxx                        |  5 ++--
135360
 sw/source/uibase/docvw/PostItMgr.cxx         |  4 ++--
135360
 sw/source/uibase/docvw/SidebarTxtControl.hxx |  2 +-
135360
 sw/source/uibase/docvw/SidebarWin.cxx        | 36 ++++++++++++++++++++++++----
135360
 sw/source/uibase/docvw/edtwin.cxx            |  7 ------
135360
 5 files changed, 38 insertions(+), 16 deletions(-)
135360
135360
diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
135360
index c41352749c28..e3899d5a1a8b 100644
135360
--- a/sw/inc/SidebarWin.hxx
135360
+++ b/sw/inc/SidebarWin.hxx
135360
@@ -179,9 +179,10 @@ class SwSidebarWin : public vcl::Window
135360
 
135360
         virtual void    Draw(OutputDevice* pDev, const Point&, const Size&, sal_uLong) override;
135360
         virtual void KeyInput(const KeyEvent& rKeyEvt) override;
135360
+        virtual void MouseButtonDown(const MouseEvent& rMouseEvent) override;
135360
         void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
135360
-        /// Get the matching sub-widget inside this sidebar widget for rPointLogic, if any.
135360
-        vcl::Window* IsHitWindow(const Point& rPointLogic);
135360
+        /// Is there a matching sub-widget inside this sidebar widget for rPointLogic?
135360
+        bool IsHitWindow(const Point& rPointLogic);
135360
 
135360
     protected:
135360
         virtual void    DataChanged( const DataChangedEvent& aEvent) SAL_OVERRIDE;
135360
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
135360
index 703a433a44ee..871a642d24da 100644
135360
--- a/sw/source/uibase/docvw/PostItMgr.cxx
135360
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
135360
@@ -1736,9 +1736,9 @@ vcl::Window* SwPostItMgr::IsHitSidebarWindow(const Point& rPointLogic)
135360
             if (!pPostIt)
135360
                 continue;
135360
 
135360
-            if (vcl::Window* pWindow = pPostIt->IsHitWindow(rPointLogic))
135360
+            if (pPostIt->IsHitWindow(rPointLogic))
135360
             {
135360
-                pRet = pWindow;
135360
+                pRet = pPostIt;
135360
                 break;
135360
             }
135360
         }
135360
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.hxx b/sw/source/uibase/docvw/SidebarTxtControl.hxx
135360
index 4f47ef4a2177..43d6b98d82c1 100644
135360
--- a/sw/source/uibase/docvw/SidebarTxtControl.hxx
135360
+++ b/sw/source/uibase/docvw/SidebarTxtControl.hxx
135360
@@ -41,7 +41,6 @@ class SidebarTextControl : public Control
135360
     protected:
135360
         virtual void    Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
135360
         virtual void    MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
135360
-        virtual void    MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
135360
         virtual void    MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
135360
         virtual void    Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
135360
         virtual void    LoseFocus() SAL_OVERRIDE;
135360
@@ -61,6 +60,7 @@ class SidebarTextControl : public Control
135360
 
135360
         virtual void GetFocus() override;
135360
         virtual void KeyInput( const KeyEvent& rKeyEvt ) override;
135360
+        virtual void MouseButtonDown(const MouseEvent& rMouseEvent) override;
135360
 
135360
         OutlinerView* GetTextView() const;
135360
 
135360
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
135360
index a40c82de5470..dd8d2a6003b9 100644
135360
--- a/sw/source/uibase/docvw/SidebarWin.cxx
135360
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
135360
@@ -280,12 +280,10 @@ void SwSidebarWin::PaintTile(vcl::RenderContext& rRenderContext, const Rectangle
135360
     rRenderContext.Push(PushFlags::NONE);
135360
 }
135360
 
135360
-vcl::Window* SwSidebarWin::IsHitWindow(const Point& rPointLogic)
135360
+bool SwSidebarWin::IsHitWindow(const Point& rPointLogic)
135360
 {
135360
     Rectangle aRectangleLogic(EditWin()->PixelToLogic(GetPosPixel()), EditWin()->PixelToLogic(GetSizePixel()));
135360
-    if (aRectangleLogic.IsInside(rPointLogic))
135360
-        return mpSidebarTextControl;
135360
-    return 0;
135360
+    return aRectangleLogic.IsInside(rPointLogic);
135360
 }
135360
 
135360
 void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, sal_uLong nInFlags)
135360
@@ -356,10 +354,40 @@ 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
+{
135360
+    Point aOffset(rChild.GetOutOffXPixel() - rParent.GetOutOffXPixel(), rChild.GetOutOffYPixel() - rParent.GetOutOffYPixel());
135360
+    MapMode aMapMode(rChild.GetMapMode());
135360
+    aMapMode.SetOrigin(rChild.PixelToLogic(aOffset));
135360
+    rChild.SetMapMode(aMapMode);
135360
+    rChild.EnableMapMode(false);
135360
+}
135360
+
135360
 void SwSidebarWin::KeyInput(const KeyEvent& rKeyEvent)
135360
 {
135360
     if (mpSidebarTextControl)
135360
+    {
135360
+        mpSidebarTextControl->Push(PushFlags::MAPMODE);
135360
+        lcl_setAbsoluteTwips(*EditWin(), *mpSidebarTextControl);
135360
+
135360
         mpSidebarTextControl->KeyInput(rKeyEvent);
135360
+
135360
+        mpSidebarTextControl->Pop();
135360
+    }
135360
+}
135360
+
135360
+void SwSidebarWin::MouseButtonDown(const MouseEvent& rMouseEvent)
135360
+{
135360
+    if (mpSidebarTextControl)
135360
+    {
135360
+        mpSidebarTextControl->Push(PushFlags::MAPMODE);
135360
+        lcl_setAbsoluteTwips(*EditWin(), *mpSidebarTextControl);
135360
+
135360
+        mpSidebarTextControl->MouseButtonDown(rMouseEvent);
135360
+
135360
+        mpSidebarTextControl->Pop();
135360
+    }
135360
 }
135360
 
135360
 void SwSidebarWin::SetPosSizePixelRect(long nX, long nY, long nWidth, long nHeight,
135360
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
135360
index 10cdc0dca561..53d0afd38f94 100644
135360
--- a/sw/source/uibase/docvw/edtwin.cxx
135360
+++ b/sw/source/uibase/docvw/edtwin.cxx
135360
@@ -2771,14 +2771,7 @@ void SwEditWin::MouseButtonDown(const MouseEvent& _rMEvt)
135360
     {
135360
         if (vcl::Window* pWindow = m_rView.GetPostItMgr()->IsHitSidebarWindow(rMEvt.GetPosPixel()))
135360
         {
135360
-            bool bDisableMapMode = pWindow->IsMapModeEnabled();
135360
-            if (bDisableMapMode)
135360
-                pWindow->EnableMapMode(false);
135360
-
135360
             pWindow->MouseButtonDown(rMEvt);
135360
-
135360
-            if (bDisableMapMode)
135360
-                pWindow->EnableMapMode();
135360
             return;
135360
         }
135360
     }
135360
-- 
135360
2.12.0
135360