Blame SOURCES/0328-sw-lok-comments-implement-setTextSelection-API.patch

135360
From 03db067b74739dabe787dbce6af1f4b776ce888a Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Sat, 14 Nov 2015 10:37:45 +0100
135360
Subject: [PATCH 328/398] sw lok comments: implement setTextSelection() API
135360
135360
So that it's possible to drag the text selection start/end handles in
135360
comment text when there is an existing selection.
135360
135360
(cherry picked from commit e320d070bb0d4dd0ceb696f2c7cc5afb7c4273c3)
135360
135360
Change-Id: I3acc4770928d4f385f0ca09a2484a9e112409907
135360
---
135360
 sw/inc/SidebarWin.hxx                 |  2 ++
135360
 sw/source/uibase/docvw/SidebarWin.cxx | 60 +++++++++++++++++++++++------------
135360
 sw/source/uibase/docvw/edtwin.cxx     | 10 ++++++
135360
 3 files changed, 51 insertions(+), 21 deletions(-)
135360
135360
diff --git a/sw/inc/SidebarWin.hxx b/sw/inc/SidebarWin.hxx
135360
index e3899d5a1a8b..503f8f8a9771 100644
135360
--- a/sw/inc/SidebarWin.hxx
135360
+++ b/sw/inc/SidebarWin.hxx
135360
@@ -183,6 +183,8 @@ class SwSidebarWin : public vcl::Window
135360
         void PaintTile(vcl::RenderContext& rRenderContext, const Rectangle& rRect);
135360
         /// Is there a matching sub-widget inside this sidebar widget for rPointLogic?
135360
         bool IsHitWindow(const Point& rPointLogic);
135360
+        /// Allows adjusting the point or mark of the selection to a document coordinate.
135360
+        void SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark);
135360
 
135360
     protected:
135360
         virtual void    DataChanged( const DataChangedEvent& aEvent) SAL_OVERRIDE;
135360
diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx
135360
index 71b763b84224..721ef95e4acf 100644
135360
--- a/sw/source/uibase/docvw/SidebarWin.cxx
135360
+++ b/sw/source/uibase/docvw/SidebarWin.cxx
135360
@@ -83,6 +83,32 @@
135360
 #include <memory>
135360
 #include <comphelper/lok.hxx>
135360
 
135360
+namespace
135360
+{
135360
+
135360
+/// Translate absolute <-> relative twips: LOK wants absolute coordinates as output and gives absolute coordinates as input.
135360
+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(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
+}
135360
+
135360
 namespace sw { namespace sidebarwindows {
135360
 
135360
 #define METABUTTON_WIDTH        16
135360
@@ -290,6 +316,19 @@ bool SwSidebarWin::IsHitWindow(const Point& rPointLogic)
135360
     return aRectangleLogic.IsInside(rPointLogic);
135360
 }
135360
 
135360
+void SwSidebarWin::SetCursorLogicPosition(const Point& rPosition, bool bPoint, bool bClearMark)
135360
+{
135360
+    mpSidebarTextControl->Push(PushFlags::MAPMODE);
135360
+    MouseEvent aMouseEvent(rPosition);
135360
+    lcl_translateTwips(*EditWin(), *mpSidebarTextControl, &aMouseEvent);
135360
+    Point aPosition(aMouseEvent.GetPosPixel());
135360
+
135360
+    EditView& rEditView = GetOutlinerView()->GetEditView();
135360
+    rEditView.SetCursorLogicPosition(aPosition, bPoint, bClearMark);
135360
+
135360
+    mpSidebarTextControl->Pop();
135360
+}
135360
+
135360
 void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, sal_uLong nInFlags)
135360
 {
135360
     if (mpMetadataAuthor->IsVisible() )
135360
@@ -358,27 +397,6 @@ void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, s
135360
     }
135360
 }
135360
 
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(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
 {
135360
     if (mpSidebarTextControl)
135360
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
135360
index 53d0afd38f94..b9777914c5b4 100644
135360
--- a/sw/source/uibase/docvw/edtwin.cxx
135360
+++ b/sw/source/uibase/docvw/edtwin.cxx
135360
@@ -6299,6 +6299,16 @@ void SwEditWin::SetCursorTwipPosition(const Point& rPosition, bool bPoint, bool
135360
         }
135360
     }
135360
 
135360
+    if (m_rView.GetPostItMgr())
135360
+    {
135360
+        if (sw::sidebarwindows::SwSidebarWin* pWin = m_rView.GetPostItMgr()->GetActiveSidebarWin())
135360
+        {
135360
+            // Editing postit text.
135360
+            pWin->SetCursorLogicPosition(rPosition, bPoint, bClearMark);
135360
+            return;
135360
+        }
135360
+    }
135360
+
135360
     // Not an SwWrtShell, as that would make SwCrsrShell::GetCrsr() inaccessible.
135360
     SwEditShell& rShell = m_rView.GetWrtShell();
135360
 
135360
-- 
135360
2.12.0
135360