[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - include/sfx2 include/vcl sc/source sd/source sfx2/source sw/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 30 11:43:02 UTC 2020


 include/sfx2/lokhelper.hxx          |   26 ++++++++++++++++++++++----
 include/vcl/event.hxx               |   15 ++++++++++++++-
 sc/source/ui/drawfunc/fusel.cxx     |    7 +++++--
 sc/source/ui/unoobj/docuno.cxx      |    6 ++++--
 sd/source/ui/unoidl/unomodel.cxx    |    5 ++---
 sfx2/source/view/lokcharthelper.cxx |    5 +++--
 sfx2/source/view/lokhelper.cxx      |   18 ++++++++++--------
 sw/source/uibase/uno/unotxdoc.cxx   |    4 ++--
 8 files changed, 62 insertions(+), 24 deletions(-)

New commits:
commit 14e306efae35f01fa63237ce005ad4067ca16909
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Wed Jan 29 12:44:30 2020 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Thu Jan 30 12:42:29 2020 +0100

    lok: preserve mouse event logic position and use in calc
    
    When clicking in online Calc any of the  charts, shapes (and
    other objects), sometimes the cell underneath is selected
    instead. The problem is that the object is not correctly
    recognised to be hit.
    
    From lok we get the mouse event position in logic coordinates,
    which we usually can just use in writer and impress. In calc
    however we need the coordinates in pixels, so we transform them
    before sending the mouse event to calc. Still calc also uses
    common SdrObjects (chart, shapes,...), which operate in logic
    coordinates. So in case of SdrObject we need to convert the
    coordniates back from pixel to logic again, which causes
    problems because conversion doesn't have access to the displaying
    conditions on an stateless online client.
    OTOH we already had the correct logic coordinates, and we can just
    send them along. This is what this change does. It adds an optional
    maLogicPosition to MouseEvent, which is filled with logic position
    if those is known.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87681
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit 82196472291c4ccbcacb5c2513d1961ba9460cdf)
    
    Change-Id: I26f6466085baf613850b5861e368f22cad7c1d26
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87708
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 8dbd43277ff1..aa2ceee950ba 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -16,6 +16,27 @@
 #include <sfx2/viewsh.hxx>
 #include <cstddef>
 #include <rtl/string.hxx>
+#include <boost/optional.hpp>
+
+struct SFX2_DLLPUBLIC LokMouseEventData
+{
+    int mnType;
+    Point maPosition;
+    int mnCount;
+    MouseEventModifiers meModifiers;
+    int mnButtons;
+    int mnModifier;
+    boost::optional<Point> maLogicPosition;
+
+    LokMouseEventData(int nType, Point aPosition, int nCount, MouseEventModifiers eModifiers, int nButtons, int nModifier)
+        : mnType(nType)
+        , maPosition(aPosition)
+        , mnCount(nCount)
+        , meModifiers(eModifiers)
+        , mnButtons(nButtons)
+        , mnModifier(nModifier)
+    {}
+};
 
 class SfxViewShell;
 
@@ -73,10 +94,7 @@ public:
                                       int nType, const OUString &rText);
 
     /// Helper for posting async mouse event
-    static void postMouseEventAsync(const VclPtr<vcl::Window> &xWindow,
-                                    int nType, const Point &rPos,
-                                    int nCount, MouseEventModifiers aModifiers,
-                                    int nButtons, int nModifier);
+    static void postMouseEventAsync(const VclPtr<vcl::Window> &xWindow, LokMouseEventData const & rLokMouseEventData);
 
     /// A special value to signify 'infinity'.
     /// This value is chosen such that sal_Int32 will not overflow when manipulated.
diff --git a/include/vcl/event.hxx b/include/vcl/event.hxx
index f160a27c4cd1..9d1ffdba1f5d 100644
--- a/include/vcl/event.hxx
+++ b/include/vcl/event.hxx
@@ -27,6 +27,7 @@
 #include <vcl/vclptr.hxx>
 #include <vcl/outdev.hxx>
 #include <vcl/window.hxx>
+#include <boost/optional.hpp>
 
 class CommandEvent;
 
@@ -99,7 +100,6 @@ namespace o3tl
 #define MOUSE_MIDDLE            (sal_uInt16(0x0002))
 #define MOUSE_RIGHT             (sal_uInt16(0x0004))
 
-
 class VCL_DLLPUBLIC MouseEvent
 {
 private:
@@ -108,6 +108,9 @@ private:
     sal_uInt16          mnClicks;
     sal_uInt16          mnCode;
 
+    // Set, if the document relative logic position are available
+    boost::optional<Point> maLogicPosition;
+
 public:
     explicit        MouseEvent();
     explicit        MouseEvent( const Point& rPos, sal_uInt16 nClicks = 1,
@@ -119,6 +122,16 @@ public:
 
     sal_uInt16      GetClicks() const       { return mnClicks; }
 
+    void setLogicPosition(Point aLogicPosition)
+    {
+        maLogicPosition = aLogicPosition;
+    }
+
+    boost::optional<Point> getLogicPosition() const
+    {
+        return maLogicPosition;
+    }
+
     bool            IsEnterWindow() const
                         { return bool(mnMode & MouseEventModifiers::ENTERWINDOW); }
     bool            IsLeaveWindow() const
diff --git a/sc/source/ui/drawfunc/fusel.cxx b/sc/source/ui/drawfunc/fusel.cxx
index 2c450ea7a3d2..3c30cc026c6c 100644
--- a/sc/source/ui/drawfunc/fusel.cxx
+++ b/sc/source/ui/drawfunc/fusel.cxx
@@ -81,8 +81,11 @@ bool FuSelection::MouseButtonDown(const MouseEvent& rMEvt)
     bIsInDragMode = false;      //  somewhere it has to be reset (#50033#)
 
     bool bReturn = FuDraw::MouseButtonDown(rMEvt);
-
-    aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
+    auto aLogicPosition = rMEvt.getLogicPosition();
+    if (aLogicPosition)
+        aMDPos = *aLogicPosition;
+    else
+        aMDPos = pWindow->PixelToLogic(rMEvt.GetPosPixel());
 
     if ( rMEvt.IsLeft() )
     {
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index eb6957a0a5c1..abee12a7def1 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -677,9 +677,11 @@ void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount, int nButt
 
     // Calc operates in pixels...
     const Point aPos(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY());
-    SfxLokHelper::postMouseEventAsync(pGridWindow, nType, aPos, nCount,
-                                      MouseEventModifiers::SIMPLECLICK,
+
+    LokMouseEventData aMouseEventData(nType, aPos, nCount, MouseEventModifiers::SIMPLECLICK,
                                       nButtons, nModifier);
+    aMouseEventData.maLogicPosition = Point(convertTwipToMm100(nX), convertTwipToMm100(nY));
+    SfxLokHelper::postMouseEventAsync(pGridWindow, aMouseEventData);
 }
 
 void ScModelObj::setTextSelection(int nType, int nX, int nY)
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 723adf7ab7d5..a1fda6f82652 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2541,10 +2541,9 @@ void SdXImpressDocument::postMouseEvent(int nType, int nX, int nY, int nCount, i
     }
 
     const Point aPos(Point(convertTwipToMm100(nX), convertTwipToMm100(nY)));
-    SfxLokHelper::postMouseEventAsync(pViewShell->GetActiveWindow(), nType,
-                                      aPos, nCount,
-                                      MouseEventModifiers::SIMPLECLICK,
+    LokMouseEventData aMouseEventData(nType, aPos, nCount, MouseEventModifiers::SIMPLECLICK,
                                       nButtons, nModifier);
+    SfxLokHelper::postMouseEventAsync(pViewShell->GetActiveWindow(), aMouseEventData);
 }
 
 void SdXImpressDocument::setTextSelection(int nType, int nX, int nY)
diff --git a/sfx2/source/view/lokcharthelper.cxx b/sfx2/source/view/lokcharthelper.cxx
index 9d3db7a58c03..903e4727eb62 100644
--- a/sfx2/source/view/lokcharthelper.cxx
+++ b/sfx2/source/view/lokcharthelper.cxx
@@ -290,9 +290,10 @@ bool LokChartHelper::postMouseEvent(int nType, int nX, int nY,
             // chart window expects pixels, but the conversion factor
             // can depend on the client zoom
             Point aPos(nChartWinX * fScaleX, nChartWinY * fScaleY);
-            SfxLokHelper::postMouseEventAsync(pChartWindow, nType, aPos, nCount,
-                                              MouseEventModifiers::SIMPLECLICK,
+
+            LokMouseEventData aMouseEventData(nType, aPos, nCount, MouseEventModifiers::SIMPLECLICK,
                                               nButtons, nModifier);
+            SfxLokHelper::postMouseEventAsync(pChartWindow, aMouseEventData);
 
             return true;
         }
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index f478b667f407..1ba7d96268d9 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -522,13 +522,10 @@ void SfxLokHelper::postExtTextEventAsync(const VclPtr<vcl::Window> &xWindow,
     postEventAsync(pLOKEv);
 }
 
-void SfxLokHelper::postMouseEventAsync(const VclPtr<vcl::Window> &xWindow,
-                                       int nType, const Point &rPos,
-                                       int nCount, MouseEventModifiers aModifiers,
-                                       int nButtons, int nModifier)
+void SfxLokHelper::postMouseEventAsync(const VclPtr<vcl::Window> &xWindow, LokMouseEventData const & rLokMouseEventData)
 {
     LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
-    switch (nType)
+    switch (rLokMouseEventData.mnType)
     {
     case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
         pLOKEv->mnEvent = VclEventId::WindowMouseButtonDown;
@@ -544,10 +541,15 @@ void SfxLokHelper::postMouseEventAsync(const VclPtr<vcl::Window> &xWindow,
     }
 
     // no reason - just always true so far.
-    assert (aModifiers == MouseEventModifiers::SIMPLECLICK);
+    assert (rLokMouseEventData.meModifiers == MouseEventModifiers::SIMPLECLICK);
 
-    pLOKEv->maMouseEvent = MouseEvent(rPos, nCount,
-                                      aModifiers, nButtons, nModifier);
+    pLOKEv->maMouseEvent = MouseEvent(rLokMouseEventData.maPosition, rLokMouseEventData.mnCount,
+                                      rLokMouseEventData.meModifiers, rLokMouseEventData.mnButtons,
+                                      rLokMouseEventData.mnModifier);
+    if (rLokMouseEventData.maLogicPosition)
+    {
+        pLOKEv->maMouseEvent.setLogicPosition(*rLokMouseEventData.maLogicPosition);
+    }
     pLOKEv->mpWindow = xWindow;
     postEventAsync(pLOKEv);
 }
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index aa1db2bf3c4e..4cc7d317bd47 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3558,10 +3558,10 @@ void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int
     }
 
     SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
-    SfxLokHelper::postMouseEventAsync(&rEditWin, nType,
-                                      Point(nX, nY), nCount,
+    LokMouseEventData aMouseEventData(nType, Point(nX, nY), nCount,
                                       MouseEventModifiers::SIMPLECLICK,
                                       nButtons, nModifier);
+    SfxLokHelper::postMouseEventAsync(&rEditWin, aMouseEventData);
 }
 
 void SwXTextDocument::setTextSelection(int nType, int nX, int nY)


More information about the Libreoffice-commits mailing list