[Libreoffice-commits] core.git: include/sfx2 include/vcl sc/source sd/source sfx2/source sw/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Wed Jan 29 13:49:26 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 82196472291c4ccbcacb5c2513d1961ba9460cdf
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: Wed Jan 29 14:48:38 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.
    
    Change-Id: I26f6466085baf613850b5861e368f22cad7c1d26
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87681
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 53c6010f2a74..3689b0086b58 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -17,6 +17,27 @@
 #include <sfx2/viewsh.hxx>
 #include <cstddef>
 #include <rtl/string.hxx>
+#include <o3tl/optional.hxx>
+
+struct SFX2_DLLPUBLIC LokMouseEventData
+{
+    int mnType;
+    Point maPosition;
+    int mnCount;
+    MouseEventModifiers meModifiers;
+    int mnButtons;
+    int mnModifier;
+    o3tl::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 SFX2_DLLPUBLIC SfxLokHelper
 {
@@ -72,10 +93,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 bd0b5589f375..900838d11b5c 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 <o3tl/optional.hxx>
 
 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
+    o3tl::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;
+    }
+
+    o3tl::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 caffb9c1410b..bb82aa3459bd 100644
--- a/sc/source/ui/drawfunc/fusel.cxx
+++ b/sc/source/ui/drawfunc/fusel.cxx
@@ -78,8 +78,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 a79540c7a20b..a28f9a2eabae 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -672,9 +672,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 9cd67ac8afc9..67660e4919ac 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2510,10 +2510,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 f0f12f1cab2e..cd62c9360451 100644
--- a/sfx2/source/view/lokcharthelper.cxx
+++ b/sfx2/source/view/lokcharthelper.cxx
@@ -287,9 +287,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 c3a72154eddb..5556caa26be3 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -526,13 +526,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;
@@ -548,10 +545,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 d8f54b5817e7..f5eee610dbc2 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3500,10 +3500,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