include/vcl/GestureEventRotate.hxx | 46 ++++++++++++++++++++++++ include/vcl/GestureEventZoom.hxx | 46 ++++++++++++++++++++++++ include/vcl/commandevent.hxx | 41 +++++++++++++++++++++ vcl/inc/salwtype.hxx | 20 ++++++++++ vcl/source/window/commandevent.cxx | 15 +++++++ vcl/source/window/winproc.cxx | 70 +++++++++++++++++++++++++++++++++++++ 6 files changed, 238 insertions(+)
New commits: commit 85b65b90ac10d39190097af87a2de609e87eea9c Author: Povilas Kanapickas <povi...@radix.lt> AuthorDate: Thu Aug 25 00:18:29 2022 +0300 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Fri Aug 26 09:12:54 2022 +0200 vcl: implement rotate gesture infrastructure This change implements internal infrastructure to pass rotate gestures from low-level sources to the consuming GUI widgets. The API follows the established begin-update-update-...-end event convention that is used on various platforms. The API should be enough to support bouth touchpad and touchscreen gestures, as long as the underlying low-level source exposes enough information. The hardware drivers usually expose touchpad gestures already recognized whereas touchscreen gestures come as a set of moving touchpoints and application needs to figure out their meaning itself. Many toolkits recognize both and offer a unified higher-level interface that can be used by us. Change-Id: Iae667b3248d6f78bfb1eef755af6bc996432b6a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138788 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/vcl/GestureEventRotate.hxx b/include/vcl/GestureEventRotate.hxx new file mode 100644 index 000000000000..39f4b310f973 --- /dev/null +++ b/include/vcl/GestureEventRotate.hxx @@ -0,0 +1,46 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <vcl/dllapi.h> + +enum class GestureEventRotateType +{ + Begin, + Update, + End +}; + +class VCL_DLLPUBLIC GestureEventRotate +{ +public: + sal_Int32 mnX = 0; + sal_Int32 mnY = 0; + + GestureEventRotateType meEventType = GestureEventRotateType::Begin; + + // The difference of between the current gesture scale and the scale at the beginning of the + // gesture. + double mfAngleDelta = 0; + + GestureEventRotate() = default; + + GestureEventRotate(sal_Int32 nInitialX, sal_Int32 nInitialY, GestureEventRotateType eEventType, + double fAngleDelta) + : mnX(nInitialX) + , mnY(nInitialY) + , meEventType(eEventType) + , mfAngleDelta(fAngleDelta) + { + } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/commandevent.hxx b/include/vcl/commandevent.hxx index 71694cc6f087..7b3199b18ccd 100644 --- a/include/vcl/commandevent.hxx +++ b/include/vcl/commandevent.hxx @@ -29,6 +29,7 @@ #include <rtl/ustring.hxx> #include <vcl/GestureEvent.hxx> #include <vcl/GestureEventZoom.hxx> +#include <vcl/GestureEventRotate.hxx> class CommandExtTextInputData; class CommandWheelData; @@ -41,6 +42,7 @@ class CommandSwipeData; class CommandLongPressData; class CommandGestureData; class CommandGestureZoomData; +class CommandGestureRotateData; enum class CommandEventId; @@ -93,6 +95,7 @@ public: const CommandLongPressData* GetLongPressData() const; const CommandGestureData* GetGestureData() const; const CommandGestureZoomData* GetGestureZoomData() const; + const CommandGestureRotateData* GetGestureRotateData() const; }; class VCL_DLLPUBLIC CommandExtTextInputData @@ -341,6 +344,23 @@ public: {} }; +class VCL_DLLPUBLIC CommandGestureRotateData +{ +public: + const double mfX = 0; + const double mfY = 0; + const GestureEventRotateType meEventType = GestureEventRotateType::Begin; + const double mfAngleDelta = 0; + + CommandGestureRotateData(double fX, double fY, GestureEventRotateType eEventType, + double fAngleDelta) + : mfX(fX) + , mfY(fY) + , meEventType(eEventType) + , mfAngleDelta(fAngleDelta) + {} +}; + enum class CommandEventId { NONE = 0, @@ -366,6 +386,7 @@ enum class CommandEventId LongPress = 22, Gesture = 23, GestureZoom = 24, + GestureRotate = 25, }; #endif // INCLUDED_VCL_COMMANDEVENT_HXX diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx index d920a16dc5d4..7b66ef5a2d45 100644 --- a/vcl/inc/salwtype.hxx +++ b/vcl/inc/salwtype.hxx @@ -27,6 +27,7 @@ #include <tools/long.hxx> #include <vcl/GestureEvent.hxx> #include <vcl/GestureEventZoom.hxx> +#include <vcl/GestureEventRotate.hxx> class LogicalFontInstance; class SalGraphics; @@ -93,6 +94,7 @@ enum class SalEvent { ExternalGesture, Gesture, GestureZoom, + GestureRotate, }; struct SalAbstractMouseEvent @@ -273,6 +275,14 @@ struct SalGestureZoomEvent double mfScaleDelta = 0; }; +struct SalGestureRotateEvent +{ + GestureEventRotateType meEventType = GestureEventRotateType::Begin; + tools::Long mnX = 0; + tools::Long mnY = 0; + double mfAngleDelta = 0; +}; + typedef void (*SALTIMERPROC)(); #endif // INCLUDED_VCL_INC_SALWTYPE_HXX diff --git a/vcl/source/window/commandevent.cxx b/vcl/source/window/commandevent.cxx index aeedcc79c197..5fdb5e9e41a1 100644 --- a/vcl/source/window/commandevent.cxx +++ b/vcl/source/window/commandevent.cxx @@ -203,5 +203,12 @@ const CommandGestureZoomData* CommandEvent::GetGestureZoomData() const return nullptr; } +const CommandGestureRotateData* CommandEvent::GetGestureRotateData() const +{ + if (mnCommand == CommandEventId::GestureRotate) + return static_cast<const CommandGestureRotateData*>(mpData); + else + return nullptr; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index 945cae89e76e..d98b8c2fae42 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -33,6 +33,7 @@ #include <vcl/event.hxx> #include <vcl/GestureEvent.hxx> #include <vcl/GestureEventZoom.hxx> +#include <vcl/GestureEventRotate.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> #include <vcl/cursor.hxx> @@ -1848,6 +1849,34 @@ static bool ImplHandleGestureZoomEvent(vcl::Window* pWindow, const SalGestureZoo return aHandler.HandleEvent(); } +namespace { + +class HandleGestureRotateEvent : public HandleGestureEvent +{ +private: + CommandGestureRotateData m_aGestureData; + +public: + HandleGestureRotateEvent(vcl::Window* pWindow, const SalGestureRotateEvent& rEvent) + : HandleGestureEvent(pWindow, Point(rEvent.mnX, rEvent.mnY)) + , m_aGestureData(rEvent.mnX, rEvent.mnY, rEvent.meEventType, rEvent.mfAngleDelta) + { + } + + virtual bool CallCommand(vcl::Window* pWindow, const Point& /*rMousePos*/) override + { + return ImplCallCommand(pWindow, CommandEventId::GestureRotate, &m_aGestureData); + } +}; + +} + +static bool ImplHandleGestureRotateEvent(vcl::Window* pWindow, const SalGestureRotateEvent& rEvent) +{ + HandleGestureRotateEvent aHandler(pWindow, rEvent); + return aHandler.HandleEvent(); +} + static void ImplHandlePaint( vcl::Window* pWindow, const tools::Rectangle& rBoundRect, bool bImmediateUpdate ) { // system paint events must be checked for re-mirroring @@ -2908,6 +2937,12 @@ bool ImplWindowFrameProc( vcl::Window* _pWindow, SalEvent nEvent, const void* pE bRet = ImplHandleGestureZoomEvent(pWindow, *pGestureEvent); } break; + case SalEvent::GestureRotate: + { + const auto * pGestureEvent = static_cast<SalGestureRotateEvent const *>(pEvent); + bRet = ImplHandleGestureRotateEvent(pWindow, *pGestureEvent); + } + break; default: SAL_WARN( "vcl.layout", "ImplWindowFrameProc(): unknown event (" << static_cast<int>(nEvent) << ")" ); break; commit 474414919c102f2973d2ed9815f997fdb1f30d9c Author: Povilas Kanapickas <povi...@radix.lt> AuthorDate: Thu Aug 25 00:18:28 2022 +0300 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Fri Aug 26 09:12:35 2022 +0200 vcl: implement zoom gesture infrastructure This change implements internal infrastructure to pass zoom gestures from low-level sources to the consuming GUI widgets. The API follows the established begin-update-update-...-end event convention that is used on various platforms. The API should be enough to support bouth touchpad and touchscreen gestures, as long as the underlying low-level source exposes enough information. The hardware drivers usually expose touchpad gestures already recognized whereas touchscreen gestures come as a set of moving touchpoints and application needs to figure out their meaning itself. Many toolkits recognize both and offer a unified higher-level interface that can be used by us. Change-Id: I529afcc60459455616de0145fe20077a4dcf3983 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138787 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/vcl/GestureEventZoom.hxx b/include/vcl/GestureEventZoom.hxx new file mode 100644 index 000000000000..3c4e637acaf2 --- /dev/null +++ b/include/vcl/GestureEventZoom.hxx @@ -0,0 +1,46 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <vcl/dllapi.h> + +enum class GestureEventZoomType +{ + Begin, + Update, + End +}; + +class VCL_DLLPUBLIC GestureEventZoom +{ +public: + sal_Int32 mnX = 0; + sal_Int32 mnY = 0; + + GestureEventZoomType meEventType = GestureEventZoomType::Begin; + + // The difference of between the current gesture scale and the scale at the beginning of the + // gesture. + double mfScaleDelta = 0; + + GestureEventZoom() = default; + + GestureEventZoom(sal_Int32 nX, sal_Int32 nY, GestureEventZoomType eEventType, + double fScaleDelta) + : mnX(nX) + , mnY(nY) + , meEventType(eEventType) + , mfScaleDelta(fScaleDelta) + { + } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/commandevent.hxx b/include/vcl/commandevent.hxx index 5d40cefc661d..71694cc6f087 100644 --- a/include/vcl/commandevent.hxx +++ b/include/vcl/commandevent.hxx @@ -28,6 +28,7 @@ #include <o3tl/typed_flags_set.hxx> #include <rtl/ustring.hxx> #include <vcl/GestureEvent.hxx> +#include <vcl/GestureEventZoom.hxx> class CommandExtTextInputData; class CommandWheelData; @@ -39,6 +40,7 @@ class CommandSelectionChangeData; class CommandSwipeData; class CommandLongPressData; class CommandGestureData; +class CommandGestureZoomData; enum class CommandEventId; @@ -90,6 +92,7 @@ public: const CommandSwipeData* GetSwipeData() const; const CommandLongPressData* GetLongPressData() const; const CommandGestureData* GetGestureData() const; + const CommandGestureZoomData* GetGestureZoomData() const; }; class VCL_DLLPUBLIC CommandExtTextInputData @@ -322,6 +325,22 @@ public: {} }; +class VCL_DLLPUBLIC CommandGestureZoomData +{ +public: + const double mfX = 0; + const double mfY = 0; + const GestureEventZoomType meEventType = GestureEventZoomType::Begin; + const double mfScaleDelta = 0; + + CommandGestureZoomData(double fX, double fY, GestureEventZoomType eEventType, double fScale) + : mfX(fX) + , mfY(fY) + , meEventType(eEventType) + , mfScaleDelta(fScale) + {} +}; + enum class CommandEventId { NONE = 0, @@ -346,6 +365,7 @@ enum class CommandEventId Swipe = 21, LongPress = 22, Gesture = 23, + GestureZoom = 24, }; #endif // INCLUDED_VCL_COMMANDEVENT_HXX diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx index 41e4e04e9a50..d920a16dc5d4 100644 --- a/vcl/inc/salwtype.hxx +++ b/vcl/inc/salwtype.hxx @@ -26,6 +26,7 @@ #include <tools/solar.h> #include <tools/long.hxx> #include <vcl/GestureEvent.hxx> +#include <vcl/GestureEventZoom.hxx> class LogicalFontInstance; class SalGraphics; @@ -91,6 +92,7 @@ enum class SalEvent { LongPress, ExternalGesture, Gesture, + GestureZoom, }; struct SalAbstractMouseEvent @@ -263,6 +265,14 @@ struct SalGestureEvent tools::Long mnY; }; +struct SalGestureZoomEvent +{ + GestureEventZoomType meEventType = GestureEventZoomType::Begin; + tools::Long mnX = 0; + tools::Long mnY = 0; + double mfScaleDelta = 0; +}; + typedef void (*SALTIMERPROC)(); #endif // INCLUDED_VCL_INC_SALWTYPE_HXX diff --git a/vcl/source/window/commandevent.cxx b/vcl/source/window/commandevent.cxx index e38b526a623d..aeedcc79c197 100644 --- a/vcl/source/window/commandevent.cxx +++ b/vcl/source/window/commandevent.cxx @@ -195,5 +195,13 @@ const CommandGestureData* CommandEvent::GetGestureData() const return nullptr; } +const CommandGestureZoomData* CommandEvent::GetGestureZoomData() const +{ + if (mnCommand == CommandEventId::GestureZoom) + return static_cast<const CommandGestureZoomData*>(mpData); + else + return nullptr; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index ea365890744b..945cae89e76e 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -32,6 +32,7 @@ #include <vcl/timer.hxx> #include <vcl/event.hxx> #include <vcl/GestureEvent.hxx> +#include <vcl/GestureEventZoom.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> #include <vcl/cursor.hxx> @@ -1819,6 +1820,34 @@ static bool ImplHandleGestureEvent(vcl::Window* pWindow, const SalGestureEvent& return aHandler.HandleEvent(); } +namespace { + +class HandleGestureZoomEvent : public HandleGestureEvent +{ +private: + CommandGestureZoomData m_aGestureData; + +public: + HandleGestureZoomEvent(vcl::Window* pWindow, const SalGestureZoomEvent& rEvent) + : HandleGestureEvent(pWindow, Point(rEvent.mnX, rEvent.mnY)) + , m_aGestureData(rEvent.mnX, rEvent.mnY, rEvent.meEventType, rEvent.mfScaleDelta) + { + } + + virtual bool CallCommand(vcl::Window* pWindow, const Point& /*rMousePos*/) override + { + return ImplCallCommand(pWindow, CommandEventId::GestureZoom, &m_aGestureData); + } +}; + +} + +static bool ImplHandleGestureZoomEvent(vcl::Window* pWindow, const SalGestureZoomEvent& rEvent) +{ + HandleGestureZoomEvent aHandler(pWindow, rEvent); + return aHandler.HandleEvent(); +} + static void ImplHandlePaint( vcl::Window* pWindow, const tools::Rectangle& rBoundRect, bool bImmediateUpdate ) { // system paint events must be checked for re-mirroring @@ -2873,6 +2902,12 @@ bool ImplWindowFrameProc( vcl::Window* _pWindow, SalEvent nEvent, const void* pE bRet = ImplHandleGestureEvent(pWindow, *aSalGestureEvent); } break; + case SalEvent::GestureZoom: + { + const auto * pGestureEvent = static_cast<SalGestureZoomEvent const *>(pEvent); + bRet = ImplHandleGestureZoomEvent(pWindow, *pGestureEvent); + } + break; default: SAL_WARN( "vcl.layout", "ImplWindowFrameProc(): unknown event (" << static_cast<int>(nEvent) << ")" ); break;