include/sfx2/lokhelper.hxx          |   10 +++
 include/vcl/ITiledRenderable.hxx    |   51 ---------------
 sc/source/ui/unoobj/docuno.cxx      |   42 ------------
 sd/source/ui/unoidl/unomodel.cxx    |   44 +------------
 sfx2/source/view/lokcharthelper.cxx |   24 -------
 sfx2/source/view/lokhelper.cxx      |  118 ++++++++++++++++++++++++++++++++++++
 sw/source/uibase/uno/unotxdoc.cxx   |   45 -------------
 vcl/source/app/ITiledRenderable.cxx |    1 
 8 files changed, 140 insertions(+), 195 deletions(-)

New commits:
commit 41b22ebcb480e1e4a78e83b7bc211f73ad62ab31
Author:     Michael Meeks <michael.me...@collabora.com>
AuthorDate: Wed Mar 13 17:18:11 2019 +0100
Commit:     Jan Holesovsky <ke...@collabora.com>
CommitDate: Fri Mar 15 09:53:12 2019 +0100

    LOK: re-factor async key & mouse event re-posting.
    
    A fairly pure re-factor, although adding disposed window
    checking to a number of sites with a warning.
    
    Moves the event emission helpers from VCL into SfxLokHelper: we're
    going to need more view / integration here next anyway.
    
    Removes lots of copy/paste horror.
    
    Change-Id: I279c11a1d8093b4feeeb6b7850f500806fff80dd
    Reviewed-on: https://gerrit.libreoffice.org/69218
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/69268
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Tested-by: Jan Holesovsky <ke...@collabora.com>

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 9f68c6d7dd60..5ef2b3f7d182 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -58,6 +58,16 @@ public:
     /// Notify about the editing context change.
     static void notifyContextChange(SfxViewShell const* pViewShell, const 
OUString& aApplication, const OUString& aContext);
 
+    /// Helper for posting async key event
+    static void postKeyEventAsync(const VclPtr<vcl::Window> &xWindow,
+                                  int nType, int nCharCode, int nKeyCode);
+
+    /// 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);
+
     /// A special value to signify 'infinity'.
     /// This value is chosen such that sal_Int32 will not overflow when 
manipulated.
     static const long MaxTwips = 1e9;
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 7f8f7ce4c332..db95bfd81de5 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -90,56 +90,6 @@ protected:
     int mnTilePixelWidth, mnTilePixelHeight;
     int mnTileTwipWidth, mnTileTwipHeight;
 public:
-    struct LOKAsyncEventData
-    {
-        VclPtr<vcl::Window> mpWindow;
-        VclEventId mnEvent;
-        MouseEvent maMouseEvent;
-        KeyEvent maKeyEvent;
-    };
-
-    static void LOKPostAsyncEvent(void* pEv, void*)
-    {
-        LOKAsyncEventData* pLOKEv = static_cast<LOKAsyncEventData*>(pEv);
-        if (pLOKEv->mpWindow->IsDisposed())
-            return;
-
-        switch (pLOKEv->mnEvent)
-        {
-        case VclEventId::WindowKeyInput:
-            pLOKEv->mpWindow->KeyInput(pLOKEv->maKeyEvent);
-            break;
-        case VclEventId::WindowKeyUp:
-            pLOKEv->mpWindow->KeyUp(pLOKEv->maKeyEvent);
-            break;
-        case VclEventId::WindowMouseButtonDown:
-            pLOKEv->mpWindow->LogicMouseButtonDown(pLOKEv->maMouseEvent);
-            // Invoke the context menu
-            if (pLOKEv->maMouseEvent.GetButtons() & MOUSE_RIGHT)
-            {
-                const CommandEvent aCEvt(pLOKEv->maMouseEvent.GetPosPixel(), 
CommandEventId::ContextMenu, true, nullptr);
-                pLOKEv->mpWindow->Command(aCEvt);
-            }
-            break;
-        case VclEventId::WindowMouseButtonUp:
-            pLOKEv->mpWindow->LogicMouseButtonUp(pLOKEv->maMouseEvent);
-
-            // sometimes MouseButtonDown captures mouse and starts tracking, 
and VCL
-            // will not take care of releasing that with tiled rendering
-            if (pLOKEv->mpWindow->IsTracking())
-                pLOKEv->mpWindow->EndTracking();
-
-            break;
-        case VclEventId::WindowMouseMove:
-            pLOKEv->mpWindow->LogicMouseMove(pLOKEv->maMouseEvent);
-            break;
-        default:
-            assert(false);
-            break;
-        }
-
-        delete pLOKEv;
-    }
 
     virtual ~ITiledRenderable();
 
@@ -368,7 +318,6 @@ public:
     {
         return OUString();
     }
-
 };
 } // namespace vcl
 
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 021f316c6236..05ad2d5e186c 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -633,27 +633,7 @@ Size ScModelObj::getDocumentSize()
 void ScModelObj::postKeyEvent(int nType, int nCharCode, int nKeyCode)
 {
     SolarMutexGuard aGuard;
-
-    VclPtr<vcl::Window> pWindow = getDocWindow();
-    if (!pWindow)
-        return;
-
-    LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
-    pLOKEv->mpWindow = pWindow;
-    switch (nType)
-    {
-    case LOK_KEYEVENT_KEYINPUT:
-        pLOKEv->mnEvent = VclEventId::WindowKeyInput;
-        break;
-    case LOK_KEYEVENT_KEYUP:
-        pLOKEv->mnEvent = VclEventId::WindowKeyUp;
-        break;
-    default:
-        assert(false);
-    }
-
-    pLOKEv->maKeyEvent = KeyEvent(nCharCode, nKeyCode, 0);
-    Application::PostUserEvent(Link<void*, void>(pLOKEv, 
ITiledRenderable::LOKPostAsyncEvent));
+    SfxLokHelper::postKeyEventAsync(getDocWindow(), nType, nCharCode, 
nKeyCode);
 }
 
 void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount, int 
nButtons, int nModifier)
@@ -688,29 +668,11 @@ void ScModelObj::postMouseEvent(int nType, int nX, int 
nY, int nCount, int nButt
             return;
     }
 
-    LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
-    pLOKEv->mpWindow = pGridWindow;
-    switch (nType)
-    {
-    case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
-        pLOKEv->mnEvent = VclEventId::WindowMouseButtonDown;
-        break;
-    case LOK_MOUSEEVENT_MOUSEBUTTONUP:
-        pLOKEv->mnEvent = VclEventId::WindowMouseButtonUp;
-        break;
-    case LOK_MOUSEEVENT_MOUSEMOVE:
-        pLOKEv->mnEvent = VclEventId::WindowMouseMove;
-        break;
-    default:
-        assert(false);
-    }
-
     // Calc operates in pixels...
     const Point aPos(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY());
-    pLOKEv->maMouseEvent = MouseEvent(aPos, nCount,
+    SfxLokHelper::postMouseEventAsync(pGridWindow, nType, aPos, nCount,
                                       MouseEventModifiers::SIMPLECLICK,
                                       nButtons, nModifier);
-    Application::PostUserEvent(Link<void*, void>(pLOKEv, 
ITiledRenderable::LOKPostAsyncEvent));
 }
 
 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 fd22e09ecd03..5eb8192a4e5b 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -45,6 +45,7 @@
 #include "unopool.hxx"
 #include <sfx2/dispatch.hxx>
 #include <sfx2/bindings.hxx>
+#include <sfx2/lokhelper.hxx>
 #include <vcl/commandevent.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/settings.hxx>
@@ -2481,27 +2482,7 @@ void 
SdXImpressDocument::initializeForTiledRendering(const css::uno::Sequence<cs
 void SdXImpressDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
 {
     SolarMutexGuard aGuard;
-
-    VclPtr<vcl::Window> pWindow = getDocWindow();
-    if (!pWindow)
-        return;
-
-    LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
-    pLOKEv->mpWindow = pWindow;
-    switch (nType)
-    {
-    case LOK_KEYEVENT_KEYINPUT:
-        pLOKEv->mnEvent = VclEventId::WindowKeyInput;
-        break;
-    case LOK_KEYEVENT_KEYUP:
-        pLOKEv->mnEvent = VclEventId::WindowKeyUp;
-        break;
-    default:
-        assert(false);
-    }
-
-    pLOKEv->maKeyEvent = KeyEvent(nCharCode, nKeyCode, 0);
-    Application::PostUserEvent(Link<void*, void>(pLOKEv, 
ITiledRenderable::LOKPostAsyncEvent));
+    SfxLokHelper::postKeyEventAsync(getDocWindow(), nType, nCharCode, 
nKeyCode);
 }
 
 void SdXImpressDocument::postMouseEvent(int nType, int nX, int nY, int nCount, 
int nButtons, int nModifier)
@@ -2529,28 +2510,11 @@ void SdXImpressDocument::postMouseEvent(int nType, int 
nX, int nY, int nCount, i
             return;
     }
 
-    LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
-    pLOKEv->mpWindow = pViewShell->GetActiveWindow();
-    switch (nType)
-    {
-    case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
-        pLOKEv->mnEvent = VclEventId::WindowMouseButtonDown;
-        break;
-    case LOK_MOUSEEVENT_MOUSEBUTTONUP:
-        pLOKEv->mnEvent = VclEventId::WindowMouseButtonUp;
-        break;
-    case LOK_MOUSEEVENT_MOUSEMOVE:
-        pLOKEv->mnEvent = VclEventId::WindowMouseMove;
-        break;
-    default:
-        assert(false);
-    }
-
     const Point aPos(Point(convertTwipToMm100(nX), convertTwipToMm100(nY)));
-    pLOKEv->maMouseEvent = MouseEvent(aPos, nCount,
+    SfxLokHelper::postMouseEventAsync(pViewShell->GetActiveWindow(), nType,
+                                      aPos, nCount,
                                       MouseEventModifiers::SIMPLECLICK,
                                       nButtons, nModifier);
-    Application::PostUserEvent(Link<void*, void>(pLOKEv, 
ITiledRenderable::LOKPostAsyncEvent));
 }
 
 void SdXImpressDocument::setTextSelection(int nType, int nX, int nY)
diff --git a/sfx2/source/view/lokcharthelper.cxx 
b/sfx2/source/view/lokcharthelper.cxx
index 05e9b206ef11..2f9224259858 100644
--- a/sfx2/source/view/lokcharthelper.cxx
+++ b/sfx2/source/view/lokcharthelper.cxx
@@ -286,33 +286,15 @@ bool LokChartHelper::postMouseEvent(int nType, int nX, 
int nY,
         tools::Rectangle rChartBBox = GetChartBoundingBox();
         if (rChartBBox.IsInside(aMousePos))
         {
-            vcl::ITiledRenderable::LOKAsyncEventData* pLOKEv = new 
vcl::ITiledRenderable::LOKAsyncEventData;
-            pLOKEv->mpWindow = pChartWindow;
-            switch (nType)
-            {
-                case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
-                    pLOKEv->mnEvent = VclEventId::WindowMouseButtonDown;
-                    break;
-                case LOK_MOUSEEVENT_MOUSEBUTTONUP:
-                    pLOKEv->mnEvent = VclEventId::WindowMouseButtonUp;
-                    break;
-                case LOK_MOUSEEVENT_MOUSEMOVE:
-                    pLOKEv->mnEvent = VclEventId::WindowMouseMove;
-                    break;
-                default:
-                    assert(false);
-            }
-
             int nChartWinX = nX - rChartBBox.Left();
             int nChartWinY = nY - rChartBBox.Top();
 
             // chart window expects pixels, but the conversion factor
             // can depend on the client zoom
             Point aPos(nChartWinX * fScaleX, nChartWinY * fScaleY);
-            pLOKEv->maMouseEvent = MouseEvent(aPos, nCount,
-                    MouseEventModifiers::SIMPLECLICK, nButtons, nModifier);
-
-            Application::PostUserEvent(Link<void*, void>(pLOKEv, 
vcl::ITiledRenderable::LOKPostAsyncEvent));
+            SfxLokHelper::postMouseEventAsync(pChartWindow, nType, aPos, 
nCount,
+                                              MouseEventModifiers::SIMPLECLICK,
+                                              nButtons, nModifier);
 
             return true;
         }
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 475317158158..4dbc5220ccea 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -12,6 +12,7 @@
 #include <com/sun/star/frame/Desktop.hpp>
 
 #include <comphelper/processfactory.hxx>
+#include <vcl/svapp.hxx>
 #include <sfx2/viewsh.hxx>
 #include <sfx2/request.hxx>
 #include <sfx2/viewfrm.hxx>
@@ -235,4 +236,121 @@ void SfxLokHelper::notifyContextChange(SfxViewShell 
const* pViewShell, const OUS
     pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_CHANGED, 
aBuffer.makeStringAndClear().getStr());
 }
 
+
+namespace
+{
+    struct LOKAsyncEventData
+    {
+        VclPtr<vcl::Window> mpWindow;
+        VclEventId mnEvent;
+        MouseEvent maMouseEvent;
+        KeyEvent maKeyEvent;
+    };
+
+    void LOKPostAsyncEvent(void* pEv, void*)
+    {
+        LOKAsyncEventData* pLOKEv = static_cast<LOKAsyncEventData*>(pEv);
+        if (pLOKEv->mpWindow->IsDisposed())
+            return;
+
+        switch (pLOKEv->mnEvent)
+        {
+        case VclEventId::WindowKeyInput:
+            pLOKEv->mpWindow->KeyInput(pLOKEv->maKeyEvent);
+            break;
+        case VclEventId::WindowKeyUp:
+            pLOKEv->mpWindow->KeyUp(pLOKEv->maKeyEvent);
+            break;
+        case VclEventId::WindowMouseButtonDown:
+            pLOKEv->mpWindow->LogicMouseButtonDown(pLOKEv->maMouseEvent);
+            // Invoke the context menu
+            if (pLOKEv->maMouseEvent.GetButtons() & MOUSE_RIGHT)
+            {
+                const CommandEvent aCEvt(pLOKEv->maMouseEvent.GetPosPixel(), 
CommandEventId::ContextMenu, true, nullptr);
+                pLOKEv->mpWindow->Command(aCEvt);
+            }
+            break;
+        case VclEventId::WindowMouseButtonUp:
+            pLOKEv->mpWindow->LogicMouseButtonUp(pLOKEv->maMouseEvent);
+
+            // sometimes MouseButtonDown captures mouse and starts tracking, 
and VCL
+            // will not take care of releasing that with tiled rendering
+            if (pLOKEv->mpWindow->IsTracking())
+                pLOKEv->mpWindow->EndTracking();
+
+            break;
+        case VclEventId::WindowMouseMove:
+            pLOKEv->mpWindow->LogicMouseMove(pLOKEv->maMouseEvent);
+            break;
+        default:
+            assert(false);
+            break;
+        }
+
+        delete pLOKEv;
+    }
+
+    void postEventAsync(LOKAsyncEventData *pEvent)
+    {
+        if (!pEvent->mpWindow || pEvent->mpWindow->IsDisposed())
+        {
+            SAL_WARN("vcl", "Async event post - but no valid window as 
destination " << pEvent->mpWindow.get());
+            delete pEvent;
+            return;
+        }
+
+        Application::PostUserEvent(Link<void*, void>(pEvent, 
LOKPostAsyncEvent));
+    }
+}
+
+void SfxLokHelper::postKeyEventAsync(const VclPtr<vcl::Window> &xWindow,
+                                     int nType, int nCharCode, int nKeyCode)
+{
+    LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
+    switch (nType)
+    {
+    case LOK_KEYEVENT_KEYINPUT:
+        pLOKEv->mnEvent = VclEventId::WindowKeyInput;
+        break;
+    case LOK_KEYEVENT_KEYUP:
+        pLOKEv->mnEvent = VclEventId::WindowKeyUp;
+        break;
+    default:
+        assert(false);
+    }
+    pLOKEv->maKeyEvent = KeyEvent(nCharCode, nKeyCode, 0);
+    pLOKEv->mpWindow = xWindow;
+    postEventAsync(pLOKEv);
+}
+
+void SfxLokHelper::postMouseEventAsync(const VclPtr<vcl::Window> &xWindow,
+                                       int nType, const Point &rPos,
+                                       int nCount, MouseEventModifiers 
aModifiers,
+                                       int nButtons, int nModifier)
+{
+    LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
+    switch (nType)
+    {
+    case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
+        pLOKEv->mnEvent = VclEventId::WindowMouseButtonDown;
+        break;
+    case LOK_MOUSEEVENT_MOUSEBUTTONUP:
+        pLOKEv->mnEvent = VclEventId::WindowMouseButtonUp;
+        break;
+    case LOK_MOUSEEVENT_MOUSEMOVE:
+        pLOKEv->mnEvent = VclEventId::WindowMouseMove;
+        break;
+    default:
+        assert(false);
+    }
+
+    // no reason - just always true so far.
+    assert (aModifiers == MouseEventModifiers::SIMPLECLICK);
+
+    pLOKEv->maMouseEvent = MouseEvent(rPos, nCount,
+                                      aModifiers, nButtons, nModifier);
+    pLOKEv->mpWindow = xWindow;
+    postEventAsync(pLOKEv);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index 789c7a5308b7..d58c8ac5e1dc 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3502,27 +3502,7 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::Sequence<css::
 void SwXTextDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
 {
     SolarMutexGuard aGuard;
-
-    VclPtr<vcl::Window> pWindow = getDocWindow();
-    if (!pWindow || pWindow->IsDisposed())
-        return;
-
-    LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
-    pLOKEv->mpWindow = pWindow;
-    switch (nType)
-    {
-    case LOK_KEYEVENT_KEYINPUT:
-        pLOKEv->mnEvent = VclEventId::WindowKeyInput;
-        break;
-    case LOK_KEYEVENT_KEYUP:
-        pLOKEv->mnEvent = VclEventId::WindowKeyUp;
-        break;
-    default:
-        assert(false);
-    }
-
-    pLOKEv->maKeyEvent = KeyEvent(nCharCode, nKeyCode, 0);
-    Application::PostUserEvent(Link<void*, void>(pLOKEv, 
ITiledRenderable::LOKPostAsyncEvent));
+    SfxLokHelper::postKeyEventAsync(getDocWindow(), nType, nCharCode, 
nKeyCode);
 }
 
 void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, 
int nButtons, int nModifier)
@@ -3550,29 +3530,10 @@ void SwXTextDocument::postMouseEvent(int nType, int nX, 
int nY, int nCount, int
     }
 
     SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
-
-
-    LOKAsyncEventData* pLOKEv = new LOKAsyncEventData;
-    pLOKEv->mpWindow = &rEditWin;
-    switch (nType)
-    {
-    case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
-        pLOKEv->mnEvent = VclEventId::WindowMouseButtonDown;
-        break;
-    case LOK_MOUSEEVENT_MOUSEBUTTONUP:
-        pLOKEv->mnEvent = VclEventId::WindowMouseButtonUp;
-        break;
-    case LOK_MOUSEEVENT_MOUSEMOVE:
-        pLOKEv->mnEvent = VclEventId::WindowMouseMove;
-        break;
-    default:
-        assert(false);
-    }
-
-    pLOKEv->maMouseEvent = MouseEvent(Point(nX, nY), nCount,
+    SfxLokHelper::postMouseEventAsync(&rEditWin, nType,
+                                      Point(nX, nY), nCount,
                                       MouseEventModifiers::SIMPLECLICK,
                                       nButtons, nModifier);
-    Application::PostUserEvent(Link<void*, void>(pLOKEv, 
ITiledRenderable::LOKPostAsyncEvent));
 }
 
 void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
diff --git a/vcl/source/app/ITiledRenderable.cxx 
b/vcl/source/app/ITiledRenderable.cxx
index 3eb5dcd2da6e..fcac030c136b 100644
--- a/vcl/source/app/ITiledRenderable.cxx
+++ b/vcl/source/app/ITiledRenderable.cxx
@@ -5,7 +5,6 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
  */
 
 #include <vcl/ITiledRenderable.hxx>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to