Blob Blame History Raw
From 72385a1ddf68d7c30813b7ca964850c96850a8de Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Fri, 13 Nov 2015 14:42:35 +0100
Subject: [PATCH 324/398] editeng lok: respect origin of map mode for
 TEXT_SELECTION

With this, selections of Writer comment text show up at the correct
position, not at the top left corner of the window.

(cherry picked from commit 22e97c130868fe7d7529cfcfb2a240f775bd8916)

Change-Id: If865503d9a02a27730e382d65c42c706dd533a93
---
 editeng/source/editeng/impedit.cxx | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx
index 8038ac6d3d41..0207155e4d75 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -24,6 +24,7 @@
 #include <vcl/settings.hxx>
 
 #include <impedit.hxx>
+#include <comphelper/string.hxx>
 #include <editeng/editeng.hxx>
 #include <editeng/editview.hxx>
 #include <tools/poly.hxx>
@@ -327,6 +328,12 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou
         if (isTiledRendering() && !pOldRegion)
         {
             bool bMm100ToTwip = pOutWin->GetMapMode().GetMapUnit() == MAP_100TH_MM;
+
+            Point aOrigin;
+            if (pOutWin->GetMapMode().GetMapUnit() == MAP_TWIP)
+                // Writer comments: they use editeng, but are separate widgets.
+                aOrigin = pOutWin->GetMapMode().GetOrigin();
+
             OString sRectangle;
             // If we are not in selection mode, then the exported selection should be empty.
             if (pEditEngine->pImpEditEngine->IsInSelectionMode())
@@ -340,26 +347,27 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou
                     Rectangle aStart = Rectangle(rStart.Left(), rStart.Top(), rStart.Left() + 1, rStart.Bottom());
                     if (bMm100ToTwip)
                         aStart = OutputDevice::LogicToLogic(aStart, MAP_100TH_MM, MAP_TWIP);
+                    aStart.Move(aOrigin.getX(), aOrigin.getY());
                     libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_START, aStart.toString().getStr());
 
                     Rectangle& rEnd = aRectangles.back();
                     Rectangle aEnd = Rectangle(rEnd.Right() - 1, rEnd.Top(), rEnd.Right(), rEnd.Bottom());
                     if (bMm100ToTwip)
                         aEnd = OutputDevice::LogicToLogic(aEnd, MAP_100TH_MM, MAP_TWIP);
+                    aEnd.Move(aOrigin.getX(), aOrigin.getY());
                     libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_END, aEnd.toString().getStr());
                 }
 
-                std::stringstream ss;
+                std::vector<OString> v;
                 for (size_t i = 0; i < aRectangles.size(); ++i)
                 {
                     Rectangle& rRectangle = aRectangles[i];
-                    if (i)
-                        ss << "; ";
                     if (bMm100ToTwip)
                         rRectangle = OutputDevice::LogicToLogic(rRectangle, MAP_100TH_MM, MAP_TWIP);
-                    ss << rRectangle.toString().getStr();
+                    rRectangle.Move(aOrigin.getX(), aOrigin.getY());
+                    v.push_back(rRectangle.toString().getStr());
                 }
-                sRectangle = ss.str().c_str();
+                sRectangle = comphelper::string::join("; ", v);
             }
             libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, sRectangle.getStr());
         }
-- 
2.12.0