[Libreoffice-commits] core.git: include/sfx2 include/vcl sc/source sd/source sfx2/source sw/source vcl/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Mar 14 09:14:37 UTC 2019
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 efef0583c62be4aeb5c360621cb3072ff336eb6b
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Wed Mar 13 17:18:11 2019 +0100
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Thu Mar 14 10:14:11 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.meeks at collabora.com>
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index be68f2e91044..62c024508de1 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -57,6 +57,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 d0118e2d809a..0b31f60e04ad 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -40,56 +40,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();
@@ -318,7 +268,6 @@ public:
{
return OUString();
}
-
};
} // namespace vcl
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 2856aba00cc9..5487a4629a27 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -639,27 +639,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)
@@ -694,29 +674,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 41cd4ad24a27..06a91d3df357 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -46,6 +46,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>
@@ -2476,27 +2477,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)
@@ -2524,28 +2505,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 b17fbb28fdcf..d0d37e4865a4 100644
--- a/sfx2/source/view/lokcharthelper.cxx
+++ b/sfx2/source/view/lokcharthelper.cxx
@@ -284,33 +284,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 374abf900936..016ca841a263 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>
@@ -237,4 +238,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 0a7c3d09b721..345fcba8ef11 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3512,27 +3512,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)
@@ -3560,29 +3540,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 eac1d72cbb6b..e2a639decacd 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>
More information about the Libreoffice-commits
mailing list