Kaydet (Commit) 6b476080 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

tdf#124146 add (general) gesture event support to VCL

Change-Id: I766930bb35071442e132b91477cd3d55e8f00f48
Reviewed-on: https://gerrit.libreoffice.org/69655
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst d3922a93
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* 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/.
*
*/
#ifndef INCLUDED_VCL_GESTUREEVENT_HXX
#define INCLUDED_VCL_GESTUREEVENT_HXX
#include <vcl/dllapi.h>
enum class GestureEventType
{
PanningBegin,
PanningUpdate,
PanningEnd
};
enum class PanningOrientation
{
Horizontal,
Vertical
};
class VCL_DLLPUBLIC GestureEvent
{
public:
sal_Int32 mnX;
sal_Int32 mnY;
GestureEventType meEventType;
sal_Int32 mnOffset;
PanningOrientation meOrientation;
};
#endif // INCLUDED_VCL_GESTUREEVENT_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <vcl/keycodes.hxx> #include <vcl/keycodes.hxx>
#include <o3tl/typed_flags_set.hxx> #include <o3tl/typed_flags_set.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <vcl/GestureEvent.hxx>
class CommandExtTextInputData; class CommandExtTextInputData;
class CommandWheelData; class CommandWheelData;
...@@ -37,6 +38,8 @@ class CommandMediaData; ...@@ -37,6 +38,8 @@ class CommandMediaData;
class CommandSelectionChangeData; class CommandSelectionChangeData;
class CommandSwipeData; class CommandSwipeData;
class CommandLongPressData; class CommandLongPressData;
class CommandGestureData;
enum class CommandEventId; enum class CommandEventId;
enum class ExtTextInputAttr { enum class ExtTextInputAttr {
...@@ -86,6 +89,7 @@ public: ...@@ -86,6 +89,7 @@ public:
const CommandSelectionChangeData* GetSelectionChangeData() const; const CommandSelectionChangeData* GetSelectionChangeData() const;
const CommandSwipeData* GetSwipeData() const; const CommandSwipeData* GetSwipeData() const;
const CommandLongPressData* GetLongPressData() const; const CommandLongPressData* GetLongPressData() const;
const CommandGestureData* GetGestureData() const;
}; };
class VCL_DLLPUBLIC CommandExtTextInputData class VCL_DLLPUBLIC CommandExtTextInputData
...@@ -300,6 +304,25 @@ public: ...@@ -300,6 +304,25 @@ public:
double getY() const { return mnY; } double getY() const { return mnY; }
}; };
class VCL_DLLPUBLIC CommandGestureData
{
public:
double const mfX;
double const mfY;
GestureEventType const meEventType;
double const mfOffset;
PanningOrientation const meOrientation;
CommandGestureData(double fX, double fY, GestureEventType eEventType, double fOffset, PanningOrientation eOrientation)
: mfX(fX)
, mfY(fY)
, meEventType(eEventType)
, mfOffset(fOffset)
, meOrientation(eOrientation)
{}
};
enum class CommandEventId enum class CommandEventId
{ {
NONE = 0, NONE = 0,
...@@ -323,6 +346,7 @@ enum class CommandEventId ...@@ -323,6 +346,7 @@ enum class CommandEventId
QueryCharPosition = 20, QueryCharPosition = 20,
Swipe = 21, Swipe = 21,
LongPress = 22, LongPress = 22,
Gesture = 23,
}; };
#endif // INCLUDED_VCL_COMMANDEVENT_HXX #endif // INCLUDED_VCL_COMMANDEVENT_HXX
......
...@@ -63,6 +63,7 @@ class WorkWindow; ...@@ -63,6 +63,7 @@ class WorkWindow;
class NotifyEvent; class NotifyEvent;
class KeyEvent; class KeyEvent;
class MouseEvent; class MouseEvent;
class GestureEvent;
struct ImplSVEvent; struct ImplSVEvent;
struct ConvertData; struct ConvertData;
...@@ -747,6 +748,8 @@ public: ...@@ -747,6 +748,8 @@ public:
*/ */
static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent ); static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent );
static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin, GestureEvent const * pGestureEvent);
/** Remove mouse and keypress events from a window... any also zoom and scroll events /** Remove mouse and keypress events from a window... any also zoom and scroll events
if the platform supports it. if the platform supports it.
......
...@@ -170,6 +170,7 @@ enum class VclEventId ...@@ -170,6 +170,7 @@ enum class VclEventId
WindowShow, WindowShow,
WindowStartDocking, // pData = DockingData WindowStartDocking, // pData = DockingData
WindowToggleFloating, WindowToggleFloating,
WindowGestureEvent,
}; };
class VCL_DLLPUBLIC VclSimpleEvent class VCL_DLLPUBLIC VclSimpleEvent
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <rtl/ref.hxx> #include <rtl/ref.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <tools/solar.h> #include <tools/solar.h>
#include <vcl/GestureEvent.hxx>
class LogicalFontInstance; class LogicalFontInstance;
class SalGraphics; class SalGraphics;
...@@ -82,7 +83,9 @@ enum class SalEvent { ...@@ -82,7 +83,9 @@ enum class SalEvent {
StartReconversion, StartReconversion,
QueryCharPosition, QueryCharPosition,
Swipe, Swipe,
LongPress LongPress,
ExternalGesture,
Gesture,
}; };
// MOUSELEAVE must send, when the pointer leave the client area and // MOUSELEAVE must send, when the pointer leave the client area and
...@@ -255,6 +258,15 @@ struct SalLongPressEvent ...@@ -255,6 +258,15 @@ struct SalLongPressEvent
long mnY; long mnY;
}; };
struct SalGestureEvent
{
GestureEventType meEventType;
PanningOrientation meOrientation;
double mfOffset;
long mnX;
long mnY;
};
typedef void (*SALTIMERPROC)(); typedef void (*SALTIMERPROC)();
#endif // INCLUDED_VCL_INC_SALWTYPE_HXX #endif // INCLUDED_VCL_INC_SALWTYPE_HXX
......
...@@ -133,11 +133,26 @@ struct ImplPostEventData ...@@ -133,11 +133,26 @@ struct ImplPostEventData
ImplSVEvent * mnEventId; ImplSVEvent * mnEventId;
KeyEvent maKeyEvent; KeyEvent maKeyEvent;
MouseEvent maMouseEvent; MouseEvent maMouseEvent;
GestureEvent maGestureEvent;
ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const KeyEvent& rKeyEvent ) :
mnEvent( nEvent ), mpWin( pWin ), mnEventId( nullptr ), maKeyEvent( rKeyEvent ) {} ImplPostEventData(VclEventId nEvent, vcl::Window* pWin, const KeyEvent& rKeyEvent)
ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const MouseEvent& rMouseEvent ) : : mnEvent(nEvent)
mnEvent( nEvent ), mpWin( pWin ), mnEventId( nullptr ), maMouseEvent( rMouseEvent ) {} , mpWin(pWin)
, mnEventId(nullptr)
, maKeyEvent(rKeyEvent)
{}
ImplPostEventData(VclEventId nEvent, vcl::Window* pWin, const MouseEvent& rMouseEvent)
: mnEvent(nEvent)
, mpWin(pWin)
, mnEventId(nullptr)
, maMouseEvent(rMouseEvent)
{}
ImplPostEventData(VclEventId nEvent, vcl::Window* pWin, const GestureEvent& rGestureEvent)
: mnEvent(nEvent)
, mpWin(pWin)
, mnEventId(nullptr)
, maGestureEvent(rGestureEvent)
{}
}; };
Application* GetpApp() Application* GetpApp()
...@@ -829,7 +844,43 @@ ImplSVEvent * Application::PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, K ...@@ -829,7 +844,43 @@ ImplSVEvent * Application::PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, K
return nEventId; return nEventId;
} }
ImplSVEvent * Application::PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent ) ImplSVEvent* Application::PostGestureEvent(VclEventId nEvent, vcl::Window* pWin, GestureEvent const * pGestureEvent)
{
const SolarMutexGuard aGuard;
ImplSVEvent * nEventId = nullptr;
if (pWin && pGestureEvent)
{
Point aTransformedPosition(pGestureEvent->mnX, pGestureEvent->mnY);
aTransformedPosition.AdjustX(pWin->GetOutOffXPixel());
aTransformedPosition.AdjustY(pWin->GetOutOffYPixel());
const GestureEvent aGestureEvent{
sal_Int32(aTransformedPosition.X()),
sal_Int32(aTransformedPosition.Y()),
pGestureEvent->meEventType,
pGestureEvent->mnOffset,
pGestureEvent->meOrientation
};
std::unique_ptr<ImplPostEventData> pPostEventData(new ImplPostEventData(nEvent, pWin, aGestureEvent));
nEventId = PostUserEvent(
LINK( nullptr, Application, PostEventHandler ),
pPostEventData.get());
if (nEventId)
{
pPostEventData->mnEventId = nEventId;
ImplGetSVData()->maAppData.maPostedEventList.emplace_back(pWin, pPostEventData.release());
}
}
return nEventId;
}
ImplSVEvent* Application::PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent )
{ {
const SolarMutexGuard aGuard; const SolarMutexGuard aGuard;
ImplSVEvent * nEventId = nullptr; ImplSVEvent * nEventId = nullptr;
...@@ -896,6 +947,11 @@ IMPL_STATIC_LINK( Application, PostEventHandler, void*, pCallData, void ) ...@@ -896,6 +947,11 @@ IMPL_STATIC_LINK( Application, PostEventHandler, void*, pCallData, void )
pEventData = &pData->maKeyEvent; pEventData = &pData->maKeyEvent;
break; break;
case VclEventId::WindowGestureEvent:
nEvent = SalEvent::ExternalGesture;
pEventData = &pData->maGestureEvent;
break;
default: default:
nEvent = SalEvent::NONE; nEvent = SalEvent::NONE;
pEventData = nullptr; pEventData = nullptr;
......
...@@ -186,4 +186,13 @@ const CommandLongPressData* CommandEvent::GetLongPressData() const ...@@ -186,4 +186,13 @@ const CommandLongPressData* CommandEvent::GetLongPressData() const
return nullptr; return nullptr;
} }
const CommandGestureData* CommandEvent::GetGestureData() const
{
if (mnCommand == CommandEventId::Gesture)
return static_cast<const CommandGestureData*>(mpData);
else
return nullptr;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <vcl/unohelp.hxx> #include <vcl/unohelp.hxx>
#include <vcl/timer.hxx> #include <vcl/timer.hxx>
#include <vcl/event.hxx> #include <vcl/event.hxx>
#include <vcl/GestureEvent.hxx>
#include <vcl/settings.hxx> #include <vcl/settings.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/cursor.hxx> #include <vcl/cursor.hxx>
...@@ -1550,6 +1551,30 @@ static bool ImplHandleLongPress(vcl::Window *pWindow, const SalLongPressEvent& r ...@@ -1550,6 +1551,30 @@ static bool ImplHandleLongPress(vcl::Window *pWindow, const SalLongPressEvent& r
return aHandler.HandleEvent(); return aHandler.HandleEvent();
} }
class HandleGeneralGestureEvent : public HandleGestureEvent
{
private:
CommandGestureData m_aGestureData;
public:
HandleGeneralGestureEvent(vcl::Window* pWindow, const SalGestureEvent& rEvent)
: HandleGestureEvent(pWindow, Point(rEvent.mnX, rEvent.mnY))
, m_aGestureData(rEvent.mnX, rEvent.mnY, rEvent.meEventType, rEvent.mfOffset, rEvent.meOrientation)
{
}
virtual bool CallCommand(vcl::Window* pWindow, const Point& /*rMousePos*/) override
{
return ImplCallCommand(pWindow, CommandEventId::Gesture, &m_aGestureData);
}
};
static bool ImplHandleGestureEvent(vcl::Window* pWindow, const SalGestureEvent& rEvent)
{
HandleGeneralGestureEvent aHandler(pWindow, rEvent);
return aHandler.HandleEvent();
}
static void ImplHandlePaint( vcl::Window* pWindow, const tools::Rectangle& rBoundRect, bool bImmediateUpdate ) static void ImplHandlePaint( vcl::Window* pWindow, const tools::Rectangle& rBoundRect, bool bImmediateUpdate )
{ {
// system paint events must be checked for re-mirroring // system paint events must be checked for re-mirroring
...@@ -2537,7 +2562,26 @@ bool ImplWindowFrameProc( vcl::Window* _pWindow, SalEvent nEvent, const void* pE ...@@ -2537,7 +2562,26 @@ bool ImplWindowFrameProc( vcl::Window* _pWindow, SalEvent nEvent, const void* pE
bRet = ImplHandleLongPress(pWindow, *static_cast<const SalLongPressEvent*>(pEvent)); bRet = ImplHandleLongPress(pWindow, *static_cast<const SalLongPressEvent*>(pEvent));
break; break;
case SalEvent::ExternalGesture:
{
auto const * pGestureEvent = static_cast<GestureEvent const *>(pEvent);
SalGestureEvent aSalGestureEvent;
aSalGestureEvent.mfOffset = pGestureEvent->mnOffset;
aSalGestureEvent.mnX = pGestureEvent->mnX;
aSalGestureEvent.mnY = pGestureEvent->mnY;
aSalGestureEvent.meEventType = pGestureEvent->meEventType;
aSalGestureEvent.meOrientation = pGestureEvent->meOrientation;
bRet = ImplHandleGestureEvent(pWindow, aSalGestureEvent);
}
break;
case SalEvent::Gesture:
{
auto const * aSalGestureEvent = static_cast<SalGestureEvent const *>(pEvent);
bRet = ImplHandleGestureEvent(pWindow, *aSalGestureEvent);
}
break;
default: default:
SAL_WARN( "vcl.layout", "ImplWindowFrameProc(): unknown event (" << static_cast<int>(nEvent) << ")" ); SAL_WARN( "vcl.layout", "ImplWindowFrameProc(): unknown event (" << static_cast<int>(nEvent) << ")" );
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment