From fc74a72bc99bfa11ed13a893d7723eca1f210e29 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 15:48:40 +0200 Subject: [PATCH 001/319] start mouse wheel event refactoring --- vstgui/lib/CMakeLists.txt | 5 +- vstgui/lib/cframe.cpp | 53 ++-- vstgui/lib/cframe.h | 7 +- vstgui/lib/cview.cpp | 49 +++ vstgui/lib/cview.h | 10 +- vstgui/lib/cviewcontainer.cpp | 55 ++-- vstgui/lib/cviewcontainer.h | 2 +- vstgui/lib/events.cpp | 21 ++ vstgui/lib/events.h | 280 ++++++++++++++++++ vstgui/lib/finally.h | 47 +++ vstgui/lib/platform/iplatformframecallback.h | 2 +- vstgui/lib/platform/linux/x11frame.cpp | 29 +- .../lib/platform/mac/carbon/hiviewframe.cpp | 28 +- vstgui/lib/platform/mac/cocoa/nsviewframe.mm | 43 ++- vstgui/lib/platform/win32/win32frame.cpp | 41 ++- vstgui/lib/vstguifwd.h | 11 + 16 files changed, 581 insertions(+), 102 deletions(-) create mode 100644 vstgui/lib/events.cpp create mode 100644 vstgui/lib/events.h create mode 100644 vstgui/lib/finally.h diff --git a/vstgui/lib/CMakeLists.txt b/vstgui/lib/CMakeLists.txt index 3e6784dff..a138b14f8 100644 --- a/vstgui/lib/CMakeLists.txt +++ b/vstgui/lib/CMakeLists.txt @@ -128,6 +128,9 @@ set(${target}_common_sources cvstguitimer.h dragging.h dispatchlist.h + events.cpp + events.h + finally.h genericstringlistdatabrowsersource.cpp genericstringlistdatabrowsersource.h idatabrowserdelegate.h @@ -311,7 +314,7 @@ endif() add_library(${target} STATIC ${${target}_sources}) target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS}) -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) vstgui_source_group_by_folder(${target}) if(LINUX) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index a6383b438..f6861e969 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -3,6 +3,7 @@ // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE #include "cframe.h" +#include "events.h" #include "coffscreencontext.h" #include "ctooltipsupport.h" #include "cinvalidrectlist.h" @@ -698,23 +699,33 @@ int32_t CFrame::onKeyUp (VstKeyCode& keyCode) return result; } -//------------------------------------------------------------------------ -bool CFrame::onWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons) +//----------------------------------------------------------------------------- +void CFrame::dispatchEvent (Event& event) { - if (auto modalView = getModalView ()) - { - CPoint where2 (where); - getTransform ().inverse ().transform (where2); - return modalView->onWheel (where2, axis, distance, buttons); - } + Impl::PostEventHandler peh (*pImpl); + CollectInvalidRects cir (this); - bool result = false; - if (getMouseDownView () == nullptr) + auto modalView = getModalView (); + auto mousePosEvent = asMousePositionEvent (event); + CPoint mousePosition; + if (mousePosEvent) + mousePosition = mousePosEvent->mousePosition; + + if (modalView && mousePosEvent) + getTransform ().inverse ().transform (mousePosEvent->mousePosition); + + if (modalView) + modalView->dispatchEvent (event); + else + CViewContainer::dispatchEvent (event); + + if (mousePosEvent) { - result = CViewContainer::onWheel (where, axis, distance, buttons); - checkMouseViews (where, buttons); + CButtonState buttons; + if (auto modifierEvent = asModifierEvent (event)) + buttons = buttonStateFromEventModifiers (modifierEvent->modifiers); + checkMouseViews (mousePosition, buttons); } - return result; } //----------------------------------------------------------------------------- @@ -1643,6 +1654,12 @@ bool CFrame::platformDrawRect (CDrawContext* context, const CRect& rect) return true; } +//----------------------------------------------------------------------------- +void CFrame::platformOnEvent (Event& event) +{ + dispatchEvent (event); +} + //----------------------------------------------------------------------------- CMouseEventResult CFrame::platformOnMouseDown (CPoint& where, const CButtonState& buttons) { @@ -1683,16 +1700,6 @@ CMouseEventResult CFrame::platformOnMouseExited (CPoint& where, const CButtonSta return onMouseExited (where, buttons); } -//----------------------------------------------------------------------------- -bool CFrame::platformOnMouseWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons) -{ - if (!getMouseEnabled ()) - return false; - Impl::PostEventHandler peh (*pImpl); - CollectInvalidRects cir (this); - return onWheel (where, axis, distance, buttons); -} - //----------------------------------------------------------------------------- DragOperation CFrame::platformOnDragEnter (DragEventData data) { diff --git a/vstgui/lib/cframe.h b/vstgui/lib/cframe.h index 01309797d..1ca76c897 100644 --- a/vstgui/lib/cframe.h +++ b/vstgui/lib/cframe.h @@ -214,7 +214,6 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override; - bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override; int32_t onKeyDown (VstKeyCode& keyCode) override; int32_t onKeyUp (VstKeyCode& keyCode) override; void setViewSize (const CRect& rect, bool invalid = true) override; @@ -234,7 +233,9 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback ~CFrame () noexcept override = default; void beforeDelete () override; - + + void dispatchEvent (Event& event) override; + void checkMouseViews (const CPoint& where, const CButtonState& buttons); void clearMouseViews (const CPoint& where, const CButtonState& buttons, bool callMouseExit = true); void removeFromMouseViews (CView* view); @@ -258,7 +259,7 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback CMouseEventResult platformOnMouseMoved (CPoint& where, const CButtonState& buttons) override; CMouseEventResult platformOnMouseUp (CPoint& where, const CButtonState& buttons) override; CMouseEventResult platformOnMouseExited (CPoint& where, const CButtonState& buttons) override; - bool platformOnMouseWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override; + void platformOnEvent (Event& event) override; DragOperation platformOnDragEnter (DragEventData data) override; DragOperation platformOnDragMove (DragEventData data) override; void platformOnDragLeave (DragEventData data) override; diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index 7c2546a88..ed31b62eb 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -12,6 +12,7 @@ #include "idatapackage.h" #include "iviewlistener.h" #include "malloc.h" +#include "events.h" #include "animation/animator.h" #include "../uidescription/icontroller.h" #include "platform/iplatformframe.h" @@ -463,6 +464,54 @@ bool CView::removed (CView* parent) return true; } +//------------------------------------------------------------------------ +void CView::onMouseWheelEvent (MouseWheelEvent& event) +{ +#if VSTGUI_ENABLE_DEPRECATED_METHODS + auto buttons = buttonStateFromEventModifiers (event.modifiers); + if (event.flags | MouseWheelEvent::DirectionInvertedFromDevice) + buttons |= kMouseWheelInverted; + if (event.deltaX != 0.) + { + if (onWheel (event.mousePosition, kMouseWheelAxisX, event.deltaX, buttons)) + event.consumed = true; + } + if (event.deltaY != 0.) + { + if (onWheel (event.mousePosition, kMouseWheelAxisY, event.deltaY, buttons)) + event.consumed = true; + } +#endif +} + +//------------------------------------------------------------------------ +void CView::dispatchEvent (Event& event) +{ + switch (event.type) + { + case EventType::MouseWheel: + { + auto wheelEvent = castMouseWheelEvent (event); + onMouseWheelEvent (wheelEvent); + break; + } + case EventType::KeyUp: + { + break; + } + case EventType::KeyRepeat: + { + break; + } + case EventType::KeyDown: + { + break; + } + case EventType::Unknown: assert (false); break; + } + +} + //----------------------------------------------------------------------------- /** * @param where mouse location of mouse down diff --git a/vstgui/lib/cview.h b/vstgui/lib/cview.h index 7b5d7b7e9..eedc41e97 100644 --- a/vstgui/lib/cview.h +++ b/vstgui/lib/cview.h @@ -81,6 +81,9 @@ class CView : public CBaseObject bool isVisible () const { return hasViewFlag (kVisible) && getAlphaValue () > 0.f; } //@} + virtual void onMouseWheelEvent (MouseWheelEvent& event); + + virtual void dispatchEvent (Event& event); //----------------------------------------------------------------------------- /// @name Mouse Methods //----------------------------------------------------------------------------- @@ -104,10 +107,11 @@ class CView : public CBaseObject virtual bool hitTest (const CPoint& where, const CButtonState& buttons = -1); VSTGUI_DEPRECATED( - /** \deprecated never called anymore, please override the method below for wheel handling */ + /** \deprecated never called anymore, please use onMouseWheelEvent instead */ virtual bool onWheel (const CPoint& where, const float& distance, const CButtonState& buttons) final { return false; }) - /** called if a mouse wheel event is happening over this view */ - virtual bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons); + VSTGUI_DEPRECATED( + /** \deprecated please use onMouseWheelEvent instead */ + virtual bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons);) /** turn on/off mouse usage for this view */ virtual void setMouseEnabled (bool bEnable = true); diff --git a/vstgui/lib/cviewcontainer.cpp b/vstgui/lib/cviewcontainer.cpp index 558ee2aee..85283988d 100644 --- a/vstgui/lib/cviewcontainer.cpp +++ b/vstgui/lib/cviewcontainer.cpp @@ -15,6 +15,8 @@ #include "controls/ccontrol.h" #include "dragging.h" #include "dispatchlist.h" +#include "events.h" +#include "finally.h" #include #include @@ -977,6 +979,39 @@ bool CViewContainer::hitTest (const CPoint& where, const CButtonState& buttons) return CView::hitTest (where2, buttons); } +//------------------------------------------------------------------------ +void CViewContainer::dispatchEvent (Event& event) +{ + CView::dispatchEvent (event); + if (event.consumed) + return; + switch (event.type) + { + case EventType::MouseWheel: + { + auto& wheelEvent = castMouseWheelEvent (event); + auto pos = wheelEvent.mousePosition; + auto f = finally ([&] () { wheelEvent.mousePosition = pos; }); + CPoint where2 (pos); + wheelEvent.mousePosition.offset (-getViewSize ().left, -getViewSize ().top); + getTransform ().inverse ().transform (wheelEvent.mousePosition); + for (auto it = pImpl->children.rbegin (), end = pImpl->children.rend (); it != end; + ++it) + { + const auto& pV = *it; + if (pV && pV->isVisible () && pV->getMouseEnabled () && + pV->getMouseableArea ().pointInside (wheelEvent.mousePosition)) + { + pV->dispatchEvent (wheelEvent); + if (!pV->getTransparency () || event.consumed) + return; + } + } + } + default: break; + } +} + //----------------------------------------------------------------------------- CMouseEventResult CViewContainer::onMouseDown (CPoint &where, const CButtonState& buttons) { @@ -1082,26 +1117,6 @@ CMouseEventResult CViewContainer::onMouseCancel () return kMouseEventHandled; } -//----------------------------------------------------------------------------- -bool CViewContainer::onWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons) -{ - for (auto it = pImpl->children.rbegin (), end = pImpl->children.rend (); it != end; ++it) - { - const auto& pV = *it; - CPoint where2 (where); - where2.offset (-getViewSize ().left, -getViewSize ().top); - getTransform ().inverse ().transform (where2); - if (pV && pV->isVisible () && pV->getMouseEnabled () && pV->getMouseableArea ().pointInside (where2)) - { - if (pV->onWheel (where2, axis, distance, buttons)) - return true; - if (!pV->getTransparency ()) - return false; - } - } - return false; -} - //----------------------------------------------------------------------------- SharedPointer CViewContainer::getDropTarget () { diff --git a/vstgui/lib/cviewcontainer.h b/vstgui/lib/cviewcontainer.h index 6e474d67b..ad95d3fbd 100644 --- a/vstgui/lib/cviewcontainer.h +++ b/vstgui/lib/cviewcontainer.h @@ -136,11 +136,11 @@ class CViewContainer : public CView // CView void draw (CDrawContext* pContext) override; void drawRect (CDrawContext* pContext, const CRect& updateRect) override; + void dispatchEvent (Event& event) override; CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseCancel () override; - bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override; bool hitTest (const CPoint& where, const CButtonState& buttons = -1) override; CMessageResult notify (CBaseObject* sender, IdStringPtr message) override; diff --git a/vstgui/lib/events.cpp b/vstgui/lib/events.cpp new file mode 100644 index 000000000..d47378661 --- /dev/null +++ b/vstgui/lib/events.cpp @@ -0,0 +1,21 @@ +// This file is part of VSTGUI. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this +// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE + +#include "events.h" +#include "platform/platformfactory.h" + +//------------------------------------------------------------------------ +namespace VSTGUI { +namespace EventPrivate { +static uint64_t counter = 0; +} // EventPrivate + +//------------------------------------------------------------------------ +Event::Event () noexcept +: id (++EventPrivate::counter), timestamp (getPlatformFactory ().getTicks ()) +{ +} + +//------------------------------------------------------------------------ +} // VSTGUI diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h new file mode 100644 index 000000000..172d07704 --- /dev/null +++ b/vstgui/lib/events.h @@ -0,0 +1,280 @@ +// This file is part of VSTGUI. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this +// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE + +#pragma once + +#include "vstguifwd.h" +#include "cbuttonstate.h" +#include "cpoint.h" + +//------------------------------------------------------------------------ +namespace VSTGUI { + +//------------------------------------------------------------------------ +/** EventType + * @ingroup new_in_4_11 + */ +enum class EventType : uint32_t +{ + Unknown, + KeyUp, + KeyRepeat, + KeyDown, + MouseWheel, +}; + +//------------------------------------------------------------------------ +/** Event + * @ingroup new_in_4_11 + */ +struct Event +{ + Event () noexcept; + + /** Type */ + EventType type {EventType::Unknown}; + /** Unique ID*/ + uint64_t id; + /** Timestamp */ + uint64_t timestamp; + /** Consumed? If this is true, event dispatching is stopped. */ + bool consumed {false}; +}; + +//------------------------------------------------------------------------ +/** Modifiers + * @ingroup new_in_4_11 + */ +struct Modifiers +{ + explicit Modifiers (uint32_t data = 0) : data (data) {} + Modifiers (const Modifiers&) = default; + + bool has (ModifierKey modifier) const { return data & cast (modifier); } + bool is (ModifierKey modifier) const { return data == cast (modifier); } + + bool operator| (ModifierKey modifier) const { return has (modifier); } + bool operator== (ModifierKey modifier) const { return is (modifier); } + + void add (ModifierKey modifier) { data |= cast (modifier); } + void remove (ModifierKey modifier) { data &= ~cast (modifier); } + Modifiers& operator= (ModifierKey modifier) + { + data = cast (modifier); + return *this; + } + +private: + static uint32_t cast (ModifierKey mod) { return static_cast (mod); } + uint32_t data {0}; +}; + +//------------------------------------------------------------------------ +/** ModifierEvent + * @ingroup new_in_4_11 + */ +struct ModifierEvent : Event +{ + /** pressed modifiers */ + Modifiers modifiers {}; +}; + +//------------------------------------------------------------------------ +/** MousePositionEvent + * @ingroup new_in_4_11 + */ +struct MousePositionEvent : ModifierEvent +{ + CPoint mousePosition; +}; + +//------------------------------------------------------------------------ +/** MouseWheelEvent + * @ingroup new_in_4_11 + */ +struct MouseWheelEvent : MousePositionEvent +{ + enum Flags + { + /** deltaX and deltaY are inverted */ + DirectionInvertedFromDevice = 1 << 0, + /** indicates a precise scroll event where deltaX and deltaY are multiplied by 0.1. If you + * divide the deltas by 0.1 you will get exact pixel movement. + */ + PreciseDeltas = 1 << 1, + }; + CCoord deltaX {0.}; + CCoord deltaY {0.}; + + uint32_t flags {0}; + + MouseWheelEvent () { type = EventType::MouseWheel; } +}; + +//------------------------------------------------------------------------ +// Keyboard Events +//------------------------------------------------------------------------ +/** VirtualKey + * @ingroup new_in_4_11 + */ +enum class VirtualKey : uint32_t +{ + Unknown = 0, + + Back, + Tab, + Clear, + Return, + Pause, + Escape, + Space, + Next, + End, + Home, + + Left, + Up, + Right, + Down, + PageUp, + PageDown, + + Select, + Print, + Enter, + Snapshot, + Insert, + Delete, + Help, + + NumPad0, + NumPad1, + NumPad2, + NumPad3, + NumPad4, + NumPad5, + NumPad6, + NumPad7, + NumPad8, + NumPad9, + + Multiply, + Add, + Separator, + Subtract, + Decimal, + Divide, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + NumLock, + Scroll, + + ShiftModifier, + ControlModifier, + AltModifier, + + Equals + +}; + +//------------------------------------------------------------------------ +/** ModifierKey + * @ingroup new_in_4_11 + */ +enum class ModifierKey : uint32_t +{ + /** the left or right shift key */ + Shift = 1 << 0, + /** the alternate key */ + Alt = 1 << 1, + /** the control key (Command key on macOS and control key on other platforms) */ + Control = 1 << 2, + /** the super key (Control key on macOS, Windows key on Windows and Super key on other platforms)*/ + Super = 1 << 3, +}; + +//------------------------------------------------------------------------ +/** KeyboardEvent + * @ingroup new_in_4_11 + */ +struct KeyboardEvent : ModifierEvent +{ + /** UTF-16 character */ + uint32_t character {0}; + /** virtual key */ + VirtualKey virt {VirtualKey::Unknown}; +}; + +//------------------------------------------------------------------------ +/** event as mouse position event or nullpointer if not a mouse position event + * @ingroup new_in_4_11 + */ +inline MousePositionEvent* asMousePositionEvent (Event& event) +{ + switch (event.type) + { + case EventType::MouseWheel: + return static_cast (&event); + default: break; + } + return nullptr; +} + +//------------------------------------------------------------------------ +/** event as modifier event or nullpointer if not a modifier event + * @ingroup new_in_4_11 + */ +inline ModifierEvent* asModifierEvent (Event& event) +{ + switch (event.type) + { + case EventType::KeyDown: + case EventType::KeyRepeat: + case EventType::KeyUp: + case EventType::MouseWheel: + return static_cast (&event); + default: break; + } + return nullptr; +} + +//------------------------------------------------------------------------ +/** cast to a mouse wheel event + * @ingroup new_in_4_11 + */ +inline MouseWheelEvent& castMouseWheelEvent (Event& event) +{ + vstgui_assert (event.type == EventType::MouseWheel); + return static_cast (event); +} + +//------------------------------------------------------------------------ +/** + * @ingroup new_in_4_11 + */ +inline CButtonState buttonStateFromEventModifiers (const Modifiers& mods) +{ + CButtonState state; + if (mods.has (ModifierKey::Control)) + state |= kControl; + if (mods.has (ModifierKey::Shift)) + state |= kShift; + if (mods.has (ModifierKey::Alt)) + state |= kAlt; + return state; +} + + +//------------------------------------------------------------------------ +} // VSTGUI diff --git a/vstgui/lib/finally.h b/vstgui/lib/finally.h new file mode 100644 index 000000000..745278f7b --- /dev/null +++ b/vstgui/lib/finally.h @@ -0,0 +1,47 @@ +// This file is part of VSTGUI. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this +// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE + +#pragma once + +#include "vstguifwd.h" + +//------------------------------------------------------------------------ +namespace VSTGUI { + +//------------------------------------------------------------------------ +template +class FinalAction +{ +public: + explicit FinalAction (Proc action) noexcept : action (std::move (action)) {} + FinalAction (FinalAction&& other) noexcept + { + action = std::move (other.action); + other.invoke (false); + return *this; + } + FinalAction (const FinalAction&) = delete; + FinalAction& operator= (const FinalAction&) = delete; + FinalAction& operator= (FinalAction&&) = delete; + + ~FinalAction () noexcept + { + if (invoke) + action (); + } + +private: + Proc action; + bool invoke {true}; +}; + +//------------------------------------------------------------------------ +template +auto finally (F&& f) noexcept +{ + return FinalAction::type>::type> ( + std::forward (f)); +} +//------------------------------------------------------------------------ +} // VSTGUI diff --git a/vstgui/lib/platform/iplatformframecallback.h b/vstgui/lib/platform/iplatformframecallback.h index 3bb64bcdb..dcb53514d 100644 --- a/vstgui/lib/platform/iplatformframecallback.h +++ b/vstgui/lib/platform/iplatformframecallback.h @@ -37,7 +37,7 @@ class IPlatformFrameCallback virtual CMouseEventResult platformOnMouseMoved (CPoint& where, const CButtonState& buttons) = 0; virtual CMouseEventResult platformOnMouseUp (CPoint& where, const CButtonState& buttons) = 0; virtual CMouseEventResult platformOnMouseExited (CPoint& where, const CButtonState& buttons) = 0; - virtual bool platformOnMouseWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons) = 0; + virtual void platformOnEvent (Event& event) = 0; virtual DragOperation platformOnDragEnter (DragEventData data) = 0; virtual DragOperation platformOnDragMove (DragEventData data) = 0; diff --git a/vstgui/lib/platform/linux/x11frame.cpp b/vstgui/lib/platform/linux/x11frame.cpp index 8fe3525a4..2d61c73b3 100644 --- a/vstgui/lib/platform/linux/x11frame.cpp +++ b/vstgui/lib/platform/linux/x11frame.cpp @@ -11,6 +11,7 @@ #include "../../dragging.h" #include "../../vstkeycode.h" #include "../../cinvalidrectlist.h" +#include "../../events.h" #include "../iplatformopenglview.h" #include "../iplatformviewlayer.h" #include "../iplatformtextedit.h" @@ -80,6 +81,21 @@ inline uint32_t translateModifiers (int state) return buttons; } +//------------------------------------------------------------------------ +inline Modifiers toModifiers (int state) +{ + Modifiers mods; + if (state & XCB_MOD_MASK_CONTROL) + mods.add (ModifierKey::Control); + if (state & XCB_MOD_MASK_SHIFT) + mods.add (ModifierKey::Shift); + if (state & (XCB_MOD_MASK_1 | XCB_MOD_MASK_5)) + mods.add (ModifierKey::Alt); + if (state & XCB_MOD_MASK_4) + mods.add (ModifierKey::Super); + return mods; +} + //------------------------------------------------------------------------ } // anonymous @@ -382,30 +398,33 @@ struct Frame::Impl : IFrameEventHandler { if (event.detail >= 4 && event.detail <= 7) // mouse wheel { - auto buttons = translateModifiers (event.state); + MouseWheelEvent event; + event.mousePosition = where; + event.modifiers = toModifiers (event.state); switch (event.detail) { case 4: // up { - frame->platformOnMouseWheel (where, kMouseWheelAxisY, 1, buttons); + event.deltaY = 1; break; } case 5: // down { - frame->platformOnMouseWheel (where, kMouseWheelAxisY, -1, buttons); + event.deltaY = -1; break; } case 6: // left { - frame->platformOnMouseWheel (where, kMouseWheelAxisX, -1, buttons); + event.deltaX = -1; break; } case 7: // right { - frame->platformOnMouseWheel (where, kMouseWheelAxisX, 1, buttons); + event.deltaX = 1; break; } } + frame->platformOnEvent (event); } else // mouse down { diff --git a/vstgui/lib/platform/mac/carbon/hiviewframe.cpp b/vstgui/lib/platform/mac/carbon/hiviewframe.cpp index 895e60ec7..c8677d846 100644 --- a/vstgui/lib/platform/mac/carbon/hiviewframe.cpp +++ b/vstgui/lib/platform/mac/carbon/hiviewframe.cpp @@ -13,6 +13,7 @@ #include "../../../cbitmap.h" #include "../../../cdrawcontext.h" #include "../../../cdropsource.h" +#include "../../../events.h" #include "hiviewtextedit.h" #include "hiviewoptionmenu.h" #include "../cgdrawcontext.h" @@ -1082,6 +1083,8 @@ pascal OSStatus HIViewFrame::carbonEventHandler (EventHandlerCallRef inHandlerCa { case kEventMouseWheelMoved: { + MouseWheelEvent event; + UInt32 modifiers; HIPoint windowHIPoint; SInt32 wheelDelta; @@ -1092,15 +1095,14 @@ pascal OSStatus HIViewFrame::carbonEventHandler (EventHandlerCallRef inHandlerCa GetEventParameter (inEvent, kEventParamMouseWheelDelta, typeSInt32, NULL, sizeof (SInt32), NULL, &wheelDelta); GetEventParameter (inEvent, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof (HIPoint), NULL, &windowHIPoint); GetEventParameter (inEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof (UInt32), NULL, &modifiers); - CButtonState buttons = 0; if (modifiers & cmdKey) - buttons |= kControl; + event.modifiers.add (ModifierKey::Control); if (modifiers & shiftKey) - buttons |= kShift; + event.modifiers.add (ModifierKey::Shift); if (modifiers & optionKey) - buttons |= kAlt; + event.modifiers.add (ModifierKey::Alt); if (modifiers & controlKey) - buttons |= kApple; + event.modifiers.add (ModifierKey::Super); HIPointConvert (&windowHIPoint, kHICoordSpaceWindow, windowRef, kHICoordSpaceView, hiviewframe->controlRef); @@ -1112,14 +1114,16 @@ pascal OSStatus HIViewFrame::carbonEventHandler (EventHandlerCallRef inHandlerCa windowHIPoint.x -= viewRect.origin.x; windowHIPoint.y -= viewRect.origin.y; } - - CPoint p ((CCoord)windowHIPoint.x, (CCoord)windowHIPoint.y); - float distance = wheelDelta; - CMouseWheelAxis axis = kMouseWheelAxisY; + + event.mousePosition = {(CCoord)windowHIPoint.x, (CCoord)windowHIPoint.y}; if (wheelAxis == kEventMouseWheelAxisX) - axis = kMouseWheelAxisX; - frame->platformOnMouseWheel (p, axis, distance, buttons); - result = noErr; + event.deltaX = distance; + else + event.deltaY = distance; + + frame->platformOnEvent (event); + result = event.consumed ? noErr: eventPassToNextTargetErr; + break; } } diff --git a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm index 807d82362..94fb7aecd 100644 --- a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm +++ b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm @@ -20,6 +20,7 @@ #import "../../../cvstguitimer.h" #import "../../common/genericoptionmenu.h" #import "../../../cframe.h" +#import "../../../events.h" #if MAC_CARBON #import "../carbon/hiviewframe.h" @@ -95,6 +96,21 @@ static void mapModifiers (NSUInteger nsEventModifiers, CButtonState& buttonState buttonState |= kApple; } +//------------------------------------------------------------------------------------ +static Modifiers modifiersFromModifierFlags (NSUInteger nsEventModifiers) +{ + Modifiers mods; + if (nsEventModifiers & MacEventModifier::ShiftKeyMask) + mods.add (ModifierKey::Shift); + if (nsEventModifiers & MacEventModifier::CommandKeyMask) + mods.add (ModifierKey::Control); + if (nsEventModifiers & MacEventModifier::AlternateKeyMask) + mods.add (ModifierKey::Alt); + if (nsEventModifiers & MacEventModifier::ControlKeyMask) + mods.add (ModifierKey::Super); + return mods; +} + //------------------------------------------------------------------------------------ static bool nsViewGetCurrentMouseLocation (void* nsView, CPoint& where) { @@ -358,29 +374,36 @@ static void VSTGUI_NSView_scrollWheel (id self, SEL _cmd, NSEvent* theEvent) if (!_vstguiframe) return; - CButtonState buttons = 0; + auto distanceX = [theEvent scrollingDeltaX]; + auto distanceY = [theEvent scrollingDeltaY]; + if (std::abs (distanceX) == 0. && std::abs (distanceY) == 0.) + return; + + MouseWheelEvent event; + NSUInteger modifiers = [theEvent modifierFlags]; NSPoint nsPoint = [theEvent locationInWindow]; nsPoint = [self convertPoint:nsPoint fromView:nil]; - mapModifiers (modifiers, buttons); - auto distanceX = [theEvent scrollingDeltaX]; - auto distanceY = [theEvent scrollingDeltaY]; + if ([theEvent hasPreciseScrollingDeltas]) { distanceX *= 0.1; distanceY *= 0.1; + event.flags |= MouseWheelEvent::PreciseDeltas; } if ([theEvent isDirectionInvertedFromDevice]) { distanceX *= -1; distanceY *= -1; - buttons |= kMouseWheelInverted; + event.flags |= MouseWheelEvent::DirectionInvertedFromDevice; } - CPoint p = pointFromNSPoint (nsPoint); - if (distanceX != 0.) - _vstguiframe->platformOnMouseWheel (p, kMouseWheelAxisX, static_cast (distanceX), buttons); - if (distanceY != 0.) - _vstguiframe->platformOnMouseWheel (p, kMouseWheelAxisY, static_cast (distanceY), buttons); + + event.mousePosition = pointFromNSPoint (nsPoint); + event.modifiers = modifiersFromModifierFlags ([theEvent modifierFlags]); + event.deltaX = distanceX; + event.deltaY = distanceY; + + _vstguiframe->platformOnEvent (event); } //------------------------------------------------------------------------------------ diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index aea65d28b..235569199 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -23,6 +23,7 @@ #include "../../cdropsource.h" #include "../../cgradient.h" #include "../../cinvalidrectlist.h" +#include "../../events.h" #if VSTGUI_OPENGL_SUPPORT #include "win32openglview.h" @@ -683,36 +684,30 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM switch (message) { case WM_MOUSEWHEEL: - { - CButtonState buttons = 0; - if (GetAsyncKeyState (VK_SHIFT) < 0) - buttons |= kShift; - if (GetAsyncKeyState (VK_CONTROL) < 0) - buttons |= kControl; - if (GetAsyncKeyState (VK_MENU) < 0) - buttons |= kAlt; - short zDelta = (short) GET_WHEEL_DELTA_WPARAM(wParam); - POINT p {GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)}; - ScreenToClient (windowHandle, &p); - CPoint where (p.x, p.y); - if (pFrame->platformOnMouseWheel (where, kMouseWheelAxisY, ((float)zDelta / WHEEL_DELTA), buttons)) - return 0; - break; - } case WM_MOUSEHWHEEL: // new since vista { + MouseWheelEvent event; + CButtonState buttons = 0; - if (GetAsyncKeyState (VK_SHIFT) < 0) - buttons |= kShift; + if (GetAsyncKeyState (VK_SHIFT) < 0) + event.modifiers.add (ModifierKey::Shift) if (GetAsyncKeyState (VK_CONTROL) < 0) - buttons |= kControl; - if (GetAsyncKeyState (VK_MENU) < 0) - buttons |= kAlt; + event.modifiers.add (ModifierKey::Control) + if (GetAsyncKeyState (VK_MENU) < 0) + event.modifiers.add (ModifierKey::Alt) + if (GetAsyncKeyState (VK_LWIN) < 0 || GetAsyncKeyState (VK_RWIN) < 0) + event.modifiers.add (ModifierKey::Super) + short zDelta = (short) GET_WHEEL_DELTA_WPARAM(wParam); POINT p {GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)}; ScreenToClient (windowHandle, &p); - CPoint where (p.x, p.y); - if (pFrame->platformOnMouseWheel (where, kMouseWheelAxisX, ((float)-zDelta / WHEEL_DELTA), buttons)) + event.mousePosition = {p.x, p.y}; + if (message == WM_MOUSEWHEEL) + event.deltaY = static_cast (zDelta); + else + event.deltaX = static_cast (zDelta); + pFrame->platformOnEvent (event); + if (event.consumed) return 0; break; } diff --git a/vstgui/lib/vstguifwd.h b/vstgui/lib/vstguifwd.h index 3aff5f203..a551e7bbe 100644 --- a/vstgui/lib/vstguifwd.h +++ b/vstgui/lib/vstguifwd.h @@ -243,6 +243,17 @@ class CVuMeter; class CXYPad; class CListControl; +// events +struct Event; +struct ModifierEvent; +struct MousePositionEvent; +struct MouseWheelEvent; +struct KeyboardEvent; +struct Modifiers; +enum class EventType : uint32_t; +enum class VirtualKey : uint32_t; +enum class ModifierKey : uint32_t; + // animation namespace Animation { class IAnimationTarget; From f3d10c519548b351d8c2837e352308e51d2fe692 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 15:51:39 +0200 Subject: [PATCH 002/319] fix: remove returning value from constructor --- vstgui/lib/finally.h | 1 - 1 file changed, 1 deletion(-) diff --git a/vstgui/lib/finally.h b/vstgui/lib/finally.h index 745278f7b..f2ad292f7 100644 --- a/vstgui/lib/finally.h +++ b/vstgui/lib/finally.h @@ -19,7 +19,6 @@ class FinalAction { action = std::move (other.action); other.invoke (false); - return *this; } FinalAction (const FinalAction&) = delete; FinalAction& operator= (const FinalAction&) = delete; From a08dc5fe812c94942cca8647f9533c5238de808c Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 15:55:08 +0200 Subject: [PATCH 003/319] fix var naming --- vstgui/lib/platform/linux/x11frame.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vstgui/lib/platform/linux/x11frame.cpp b/vstgui/lib/platform/linux/x11frame.cpp index 2d61c73b3..410e46460 100644 --- a/vstgui/lib/platform/linux/x11frame.cpp +++ b/vstgui/lib/platform/linux/x11frame.cpp @@ -398,33 +398,33 @@ struct Frame::Impl : IFrameEventHandler { if (event.detail >= 4 && event.detail <= 7) // mouse wheel { - MouseWheelEvent event; - event.mousePosition = where; - event.modifiers = toModifiers (event.state); + MouseWheelEvent wheelEvent; + wheelEvent.mousePosition = where; + wheelEvent.modifiers = toModifiers (event.state); switch (event.detail) { case 4: // up { - event.deltaY = 1; + wheelEvent.deltaY = 1; break; } case 5: // down { - event.deltaY = -1; + wheelEvent.deltaY = -1; break; } case 6: // left { - event.deltaX = -1; + wheelEvent.deltaX = -1; break; } case 7: // right { - event.deltaX = 1; + wheelEvent.deltaX = 1; break; } } - frame->platformOnEvent (event); + frame->platformOnEvent (wheelEvent); } else // mouse down { From a5cd0a56ed196eb0a3bb130f2445054bfbef9d1a Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 15:57:12 +0200 Subject: [PATCH 004/319] fix compile errors --- vstgui/lib/platform/win32/win32frame.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index 235569199..43fea99e7 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -686,28 +686,28 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM case WM_MOUSEWHEEL: case WM_MOUSEHWHEEL: // new since vista { - MouseWheelEvent event; + MouseWheelEvent wheelEvent; CButtonState buttons = 0; if (GetAsyncKeyState (VK_SHIFT) < 0) - event.modifiers.add (ModifierKey::Shift) + wheelEvent.modifiers.add (ModifierKey::Shift); if (GetAsyncKeyState (VK_CONTROL) < 0) - event.modifiers.add (ModifierKey::Control) + wheelEvent.modifiers.add (ModifierKey::Control); if (GetAsyncKeyState (VK_MENU) < 0) - event.modifiers.add (ModifierKey::Alt) + wheelEvent.modifiers.add (ModifierKey::Alt); if (GetAsyncKeyState (VK_LWIN) < 0 || GetAsyncKeyState (VK_RWIN) < 0) - event.modifiers.add (ModifierKey::Super) + wheelEvent.modifiers.add (ModifierKey::Super); short zDelta = (short) GET_WHEEL_DELTA_WPARAM(wParam); POINT p {GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)}; ScreenToClient (windowHandle, &p); - event.mousePosition = {p.x, p.y}; + wheelEvent.mousePosition = {p.x, p.y}; if (message == WM_MOUSEWHEEL) - event.deltaY = static_cast (zDelta); + wheelEvent.deltaY = static_cast (zDelta); else - event.deltaX = static_cast (zDelta); - pFrame->platformOnEvent (event); - if (event.consumed) + wheelEvent.deltaX = static_cast (zDelta); + pFrame->platformOnEvent (wheelEvent); + if (wheelEvent.consumed) return 0; break; } From 32c3c75af43a3e60530a42b81bdecf13ce48aed6 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 16:08:33 +0200 Subject: [PATCH 005/319] make sure everything is compiled with c++17 --- vstgui/standalone/CMakeLists.txt | 2 +- vstgui/standalone/examples/mandelbrot/CMakeLists.txt | 2 +- vstgui/standalone/examples/minesweeper/CMakeLists.txt | 2 +- vstgui/standalone/examples/simple_standalone/CMakeLists.txt | 2 +- vstgui/standalone/examples/standalone/CMakeLists.txt | 2 +- vstgui/tests/base64codecspeed/CMakeLists.txt | 2 +- vstgui/tests/gfxtest/CMakeLists.txt | 2 +- vstgui/tests/unittest/CMakeLists.txt | 2 +- vstgui/tools/imagestitcher/CMakeLists.txt | 2 +- vstgui/tools/uidesccompressor/CMakeLists.txt | 2 +- vstgui/uidescription/CMakeLists.txt | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/vstgui/standalone/CMakeLists.txt b/vstgui/standalone/CMakeLists.txt index 44da317b1..7946e22c3 100644 --- a/vstgui/standalone/CMakeLists.txt +++ b/vstgui/standalone/CMakeLists.txt @@ -122,7 +122,7 @@ endif() add_library(${target} STATIC ${${target}_sources}) target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS}) -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) vstgui_source_group_by_folder(${target}) if(VSTGUI_STANDALONE_EXAMPLES) diff --git a/vstgui/standalone/examples/mandelbrot/CMakeLists.txt b/vstgui/standalone/examples/mandelbrot/CMakeLists.txt index f99203cc3..2447d4bd9 100644 --- a/vstgui/standalone/examples/mandelbrot/CMakeLists.txt +++ b/vstgui/standalone/examples/mandelbrot/CMakeLists.txt @@ -30,6 +30,6 @@ vstgui_add_executable(${target} "${${target}_sources}") vstgui_add_resources(${target} "${mandelbrot_resources}") vstgui_set_target_infoplist(${target} "resource/Info.plist") vstgui_set_target_rcfile(${target} "resource/mandelbrot.rc") -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) target_include_directories(${target} PRIVATE ../../../../) set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} ${VSTGUI_STANDALONE_EXAMPLES_FOLDER}) diff --git a/vstgui/standalone/examples/minesweeper/CMakeLists.txt b/vstgui/standalone/examples/minesweeper/CMakeLists.txt index 1801c8bf0..558424ba5 100644 --- a/vstgui/standalone/examples/minesweeper/CMakeLists.txt +++ b/vstgui/standalone/examples/minesweeper/CMakeLists.txt @@ -37,7 +37,7 @@ vstgui_add_resources(${target} "${Minesweeper_resources}") vstgui_add_resources(${target} "${Minesweeper_font}" "Fonts") vstgui_set_target_infoplist(${target} "resource/Info.plist") vstgui_set_target_rcfile(${target} "resource/Minesweeper.rc") -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) target_include_directories(${target} PRIVATE ../../../../) set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} ${VSTGUI_STANDALONE_EXAMPLES_FOLDER}) diff --git a/vstgui/standalone/examples/simple_standalone/CMakeLists.txt b/vstgui/standalone/examples/simple_standalone/CMakeLists.txt index 723ff1cbf..7975464da 100644 --- a/vstgui/standalone/examples/simple_standalone/CMakeLists.txt +++ b/vstgui/standalone/examples/simple_standalone/CMakeLists.txt @@ -16,7 +16,7 @@ vstgui_add_executable(${target} "${${target}_sources}" ) vstgui_add_resources(${target} "${simple_standalone_resources}") vstgui_set_target_infoplist(${target} "resource/Info.plist") vstgui_set_target_rcfile(${target} "resource/simple_standalone.rc") -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) target_include_directories(${target} PRIVATE ../../../../) set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} ${VSTGUI_STANDALONE_EXAMPLES_FOLDER}) diff --git a/vstgui/standalone/examples/standalone/CMakeLists.txt b/vstgui/standalone/examples/standalone/CMakeLists.txt index 151c76032..d6155fcad 100644 --- a/vstgui/standalone/examples/standalone/CMakeLists.txt +++ b/vstgui/standalone/examples/standalone/CMakeLists.txt @@ -32,6 +32,6 @@ vstgui_add_resources(${target} "${standalone_resources}") vstgui_add_resources(${target} "${standalone_font}" "Fonts") vstgui_set_target_infoplist(${target} "resource/Info.plist") vstgui_set_target_rcfile(${target} "resource/standalone.rc") -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) target_include_directories(${target} PRIVATE ../../../../) set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} ${VSTGUI_STANDALONE_EXAMPLES_FOLDER}) diff --git a/vstgui/tests/base64codecspeed/CMakeLists.txt b/vstgui/tests/base64codecspeed/CMakeLists.txt index 354bb3e95..6a7fb8e37 100644 --- a/vstgui/tests/base64codecspeed/CMakeLists.txt +++ b/vstgui/tests/base64codecspeed/CMakeLists.txt @@ -17,6 +17,6 @@ target_link_libraries(${target} ${${target}_PLATFORM_LIBS} ) -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} FOLDER Tests) target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS}) diff --git a/vstgui/tests/gfxtest/CMakeLists.txt b/vstgui/tests/gfxtest/CMakeLists.txt index 0bb923d37..67f07c19d 100644 --- a/vstgui/tests/gfxtest/CMakeLists.txt +++ b/vstgui/tests/gfxtest/CMakeLists.txt @@ -63,6 +63,6 @@ target_link_libraries(${target} ${${target}_PLATFORM_LIBS} ) -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) set_target_properties(${target} PROPERTIES ${APP_PROPERTIES} FOLDER Tests) target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS}) diff --git a/vstgui/tests/unittest/CMakeLists.txt b/vstgui/tests/unittest/CMakeLists.txt index 159f6b7c7..760fec5de 100644 --- a/vstgui/tests/unittest/CMakeLists.txt +++ b/vstgui/tests/unittest/CMakeLists.txt @@ -131,7 +131,7 @@ target_link_libraries(${target} ${${target}_PLATFORM_LIBS} ) -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS} ENABLE_UNIT_TESTS=1 VSTGUI_LIVE_EDITING=1) vstgui_source_group_by_folder(${target}) diff --git a/vstgui/tools/imagestitcher/CMakeLists.txt b/vstgui/tools/imagestitcher/CMakeLists.txt index 7d158826e..09460d51d 100644 --- a/vstgui/tools/imagestitcher/CMakeLists.txt +++ b/vstgui/tools/imagestitcher/CMakeLists.txt @@ -36,7 +36,7 @@ vstgui_add_executable(${TargetName} "${${TargetName}_sources}") vstgui_add_resources(${TargetName} "${${TargetName}_RESOURCES}") vstgui_set_target_infoplist(${TargetName} "resource/Info.plist") vstgui_set_target_rcfile(${TargetName} "resource/imagestitcher.rc") -vstgui_set_cxx_version(${TargetName} 14) +vstgui_set_cxx_version(${TargetName} 17) target_include_directories(${TargetName} PRIVATE ../../../) set_target_properties(${TargetName} PROPERTIES ${APP_PROPERTIES} ${VSTGUI_TOOLS_FOLDER}) diff --git a/vstgui/tools/uidesccompressor/CMakeLists.txt b/vstgui/tools/uidesccompressor/CMakeLists.txt index d0a26721d..4ba3a5f9d 100644 --- a/vstgui/tools/uidesccompressor/CMakeLists.txt +++ b/vstgui/tools/uidesccompressor/CMakeLists.txt @@ -26,6 +26,6 @@ target_link_libraries(${TargetName} ) target_include_directories(${TargetName} PRIVATE ../../../) -vstgui_set_cxx_version(${TargetName} 14) +vstgui_set_cxx_version(${TargetName} 17) set_target_properties(${TargetName} PROPERTIES ${APP_PROPERTIES} ${VSTGUI_TOOLS_FOLDER}) target_compile_definitions(${TargetName} ${VSTGUI_COMPILE_DEFINITIONS}) diff --git a/vstgui/uidescription/CMakeLists.txt b/vstgui/uidescription/CMakeLists.txt index c6fe55813..0d512416a 100644 --- a/vstgui/uidescription/CMakeLists.txt +++ b/vstgui/uidescription/CMakeLists.txt @@ -178,7 +178,7 @@ add_library(${target} STATIC ${${target}_sources}) add_dependencies(${target} vstgui) target_link_libraries(${target} PRIVATE vstgui) target_compile_definitions(${target} ${VSTGUI_COMPILE_DEFINITIONS}) -vstgui_set_cxx_version(${target} 14) +vstgui_set_cxx_version(${target} 17) vstgui_source_group_by_folder(${target}) ########################################################################################## From 547e262abc65dab63d6e3ed9deecdf106c361b4d Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 16:08:48 +0200 Subject: [PATCH 006/319] fix unit tests --- vstgui/lib/platform/win32/win32frame.cpp | 2 +- vstgui/tests/unittest/lib/cviewcontainer_test.cpp | 13 +++++++++++-- vstgui/vstgui.cpp | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index 43fea99e7..015856100 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -701,7 +701,7 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM short zDelta = (short) GET_WHEEL_DELTA_WPARAM(wParam); POINT p {GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)}; ScreenToClient (windowHandle, &p); - wheelEvent.mousePosition = {p.x, p.y}; + wheelEvent.mousePosition = {static_cast (p.x), static_cast (p.y)}; if (message == WM_MOUSEWHEEL) wheelEvent.deltaY = static_cast (zDelta); else diff --git a/vstgui/tests/unittest/lib/cviewcontainer_test.cpp b/vstgui/tests/unittest/lib/cviewcontainer_test.cpp index 6162543e5..7dbe65983 100644 --- a/vstgui/tests/unittest/lib/cviewcontainer_test.cpp +++ b/vstgui/tests/unittest/lib/cviewcontainer_test.cpp @@ -6,6 +6,7 @@ #include "../../../lib/iviewlistener.h" #include "../../../lib/ccolor.h" #include "../../../lib/dragging.h" +#include "../../../lib/events.h" #include "../unittests.h" #include @@ -376,7 +377,12 @@ TESTCASE(CViewContainerTest, EXPECT(container->onMouseMoved (p, kLButton) == kMouseEventNotHandled); EXPECT(container->onMouseUp (p, kLButton) == kMouseEventNotHandled); EXPECT(container->onMouseCancel () == kMouseEventHandled); - EXPECT(container->onWheel (p, kMouseWheelAxisX, 1.f, 0) == false); + + MouseWheelEvent event; + event.mousePosition = p; + event.deltaX = 1.; + container->dispatchEvent (event); + EXPECT(event.consumed == false); ); TEST(mouseEvents, @@ -403,7 +409,10 @@ TESTCASE(CViewContainerTest, EXPECT(v2->mouseUpCalled == false); p (60, 10); - EXPECT(container->onWheel (p, kMouseWheelAxisX, 0.5f, 0)); + MouseWheelEvent event; + event.mousePosition = p; + event.deltaX = 0.5; + container->dispatchEvent (event); EXPECT(v1->onWheelCalled == false); EXPECT(v2->onWheelCalled); ); diff --git a/vstgui/vstgui.cpp b/vstgui/vstgui.cpp index c64cf1766..52b101b03 100644 --- a/vstgui/vstgui.cpp +++ b/vstgui/vstgui.cpp @@ -30,6 +30,7 @@ #include "lib/cview.cpp" #include "lib/cviewcontainer.cpp" #include "lib/cvstguitimer.cpp" +#include "lib/events.cpp" #include "lib/genericstringlistdatabrowsersource.cpp" #include "lib/pixelbuffer.cpp" #include "lib/vstguidebug.cpp" From ecbb13badee976716a509c6082cd81cfccfc6f96 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 16:38:29 +0200 Subject: [PATCH 007/319] add empty method and prevent unwanted copies of events --- vstgui/lib/cview.cpp | 5 ++++- vstgui/lib/events.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index ed31b62eb..6d429004f 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -468,6 +468,9 @@ bool CView::removed (CView* parent) void CView::onMouseWheelEvent (MouseWheelEvent& event) { #if VSTGUI_ENABLE_DEPRECATED_METHODS + if (!getMouseEnabled ()) + return; + auto buttons = buttonStateFromEventModifiers (event.modifiers); if (event.flags | MouseWheelEvent::DirectionInvertedFromDevice) buttons |= kMouseWheelInverted; @@ -491,7 +494,7 @@ void CView::dispatchEvent (Event& event) { case EventType::MouseWheel: { - auto wheelEvent = castMouseWheelEvent (event); + auto& wheelEvent = castMouseWheelEvent (event); onMouseWheelEvent (wheelEvent); break; } diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index 172d07704..94e9cdc82 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -31,6 +31,7 @@ enum class EventType : uint32_t struct Event { Event () noexcept; + Event (const Event&) = delete; /** Type */ EventType type {EventType::Unknown}; @@ -51,6 +52,7 @@ struct Modifiers explicit Modifiers (uint32_t data = 0) : data (data) {} Modifiers (const Modifiers&) = default; + bool empty () const { return data == 0;} bool has (ModifierKey modifier) const { return data & cast (modifier); } bool is (ModifierKey modifier) const { return data == cast (modifier); } From 74c6c9d563f3178895fd01a93b669ec25d5bd013 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 16:39:39 +0200 Subject: [PATCH 008/319] refactor scroll view mouse wheel event handling --- vstgui/lib/cscrollview.cpp | 19 +++++++++---------- vstgui/lib/cscrollview.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/vstgui/lib/cscrollview.cpp b/vstgui/lib/cscrollview.cpp index c638b663b..810372f2b 100644 --- a/vstgui/lib/cscrollview.cpp +++ b/vstgui/lib/cscrollview.cpp @@ -8,6 +8,7 @@ #include "cframe.h" #include "dragging.h" #include "controls/cscrollbar.h" +#include "events.h" #include /// @cond ignore @@ -746,17 +747,15 @@ void CScrollView::drawBackgroundRect (CDrawContext *pContext, const CRect& _upda } //----------------------------------------------------------------------------- -bool CScrollView::onWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons) +void CScrollView::onMouseWheelEvent (MouseWheelEvent& event) { - bool result = CViewContainer::onWheel (where, axis, distance, buttons); - if (!result) - { - if (vsb && axis == kMouseWheelAxisY) - result = vsb->onWheel (where, axis, distance, buttons); - else if (hsb && axis == kMouseWheelAxisX) - result = hsb->onWheel (where, axis, distance, buttons); - } - return result; + CViewContainer::onMouseWheelEvent (event); + if (event.consumed) + return; + if (vsb && event.deltaY != 0.) + vsb->onMouseWheelEvent (event); + if (hsb && event.deltaX != 0.) + hsb->onMouseWheelEvent (event); } //----------------------------------------------------------------------------- diff --git a/vstgui/lib/cscrollview.h b/vstgui/lib/cscrollview.h index 93a09ba98..6281b13ae 100644 --- a/vstgui/lib/cscrollview.h +++ b/vstgui/lib/cscrollview.h @@ -92,7 +92,7 @@ class CScrollView : public CViewContainer, public IControlListener, public ViewL CView* getView (uint32_t index) const override; bool changeViewZOrder (CView* view, uint32_t newIndex) override; void drawBackgroundRect (CDrawContext* pContext, const CRect& _updateRect) override; - bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override; + void onMouseWheelEvent (MouseWheelEvent& event) override; void valueChanged (CControl* pControl) override; void setTransparency (bool val) override; void setBackgroundColor (const CColor& color) override; From 04baa37848d16ada0cd126c7b3c81e395af9d636 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 17:01:16 +0200 Subject: [PATCH 009/319] refactor scrollbar mouse wheel event handling --- vstgui/lib/controls/cscrollbar.cpp | 30 ++++++++++++++++-------------- vstgui/lib/controls/cscrollbar.h | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/vstgui/lib/controls/cscrollbar.cpp b/vstgui/lib/controls/cscrollbar.cpp index e82a99cf6..969525395 100644 --- a/vstgui/lib/controls/cscrollbar.cpp +++ b/vstgui/lib/controls/cscrollbar.cpp @@ -9,6 +9,7 @@ #include "../cframe.h" #include "../cgraphicspath.h" #include "../cdrawcontext.h" +#include "../events.h" namespace VSTGUI { @@ -304,27 +305,28 @@ void CScrollbar::onVisualChange () } //------------------------------------------------------------------------ -bool CScrollbar::onWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &_distance, const CButtonState &buttons) +void CScrollbar::onMouseWheelEvent (MouseWheelEvent& event) { if (scrollerLength == 0 || !getMouseEnabled ()) - return false; + return; - if (buttons != 0 && !(buttons & (kShift|kMouseWheelInverted))) - return false; + if (!event.modifiers.empty () && !(event.modifiers.has (ModifierKey::Shift) && + event.flags & MouseWheelEvent::DirectionInvertedFromDevice)) + return; - if (direction == kHorizontal && axis == kMouseWheelAxisY) - return false; + float distance = 0.f; + if (direction == kHorizontal) + distance = event.deltaX; + else + distance = event.deltaY; - if (direction == kVertical && axis == kMouseWheelAxisX) - return false; + if (distance == 0.f) + return; - float distance = _distance; - if (direction == kHorizontal && axis == kMouseWheelAxisY) - distance *= -1; - if (buttons & kMouseWheelInverted) + if (event.flags & MouseWheelEvent::DirectionInvertedFromDevice) distance *= -1; - if (buttons & kShift) + if (event.modifiers.has (ModifierKey::Shift)) value -= 0.1f * distance * getWheelInc (); else value -= distance * getWheelInc (); @@ -336,7 +338,7 @@ bool CScrollbar::onWheel (const CPoint &where, const CMouseWheelAxis &axis, cons valueChanged (); invalid (); } - return true; + event.consumed = true; } //----------------------------------------------------------------------------- diff --git a/vstgui/lib/controls/cscrollbar.h b/vstgui/lib/controls/cscrollbar.h index d9916b0ca..2a20ede6e 100644 --- a/vstgui/lib/controls/cscrollbar.h +++ b/vstgui/lib/controls/cscrollbar.h @@ -53,7 +53,7 @@ class CScrollbar : public CControl // overwrite void draw (CDrawContext* pContext) override; - bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override; + void onMouseWheelEvent (MouseWheelEvent& event) override; CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; From 9ec5f9720ce8f18bb0ecb07516e9b196c54061cd Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 19:11:56 +0200 Subject: [PATCH 010/319] move mouse position code so that other mouse position events can use it --- vstgui/lib/cviewcontainer.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/vstgui/lib/cviewcontainer.cpp b/vstgui/lib/cviewcontainer.cpp index 85283988d..ae9ef4179 100644 --- a/vstgui/lib/cviewcontainer.cpp +++ b/vstgui/lib/cviewcontainer.cpp @@ -985,16 +985,20 @@ void CViewContainer::dispatchEvent (Event& event) CView::dispatchEvent (event); if (event.consumed) return; + CPoint mousePos; + auto mouseEvent = asMousePositionEvent (event); + if (mouseEvent) + { + mousePos = mouseEvent->mousePosition; + mouseEvent->mousePosition.offset (-getViewSize ().left, -getViewSize ().top); + getTransform ().inverse ().transform (mouseEvent->mousePosition); + } + auto f = finally ([&] () { if (mouseEvent) mouseEvent->mousePosition = mousePos; }); switch (event.type) { case EventType::MouseWheel: { auto& wheelEvent = castMouseWheelEvent (event); - auto pos = wheelEvent.mousePosition; - auto f = finally ([&] () { wheelEvent.mousePosition = pos; }); - CPoint where2 (pos); - wheelEvent.mousePosition.offset (-getViewSize ().left, -getViewSize ().top); - getTransform ().inverse ().transform (wheelEvent.mousePosition); for (auto it = pImpl->children.rbegin (), end = pImpl->children.rend (); it != end; ++it) { From 716838f369a07d0bb90d75794c291d28cd12f7a2 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 19:18:16 +0200 Subject: [PATCH 011/319] adopt new mouse wheel event handling for CXYPad --- vstgui/lib/controls/cxypad.cpp | 28 +++++++++++++++++----------- vstgui/lib/controls/cxypad.h | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/vstgui/lib/controls/cxypad.cpp b/vstgui/lib/controls/cxypad.cpp index b38643176..9bb2073c1 100644 --- a/vstgui/lib/controls/cxypad.cpp +++ b/vstgui/lib/controls/cxypad.cpp @@ -4,6 +4,7 @@ #include "cxypad.h" #include "../cdrawcontext.h" +#include "../events.h" namespace VSTGUI { @@ -145,20 +146,25 @@ CMouseEventResult CXYPad::onMouseMoved (CPoint& where, const CButtonState& butto } //------------------------------------------------------------------------ -bool CXYPad::onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& _distance, - const CButtonState& buttons) +void CXYPad::onMouseWheelEvent (MouseWheelEvent& event) { float x, y; calculateXY (getValue (), x, y); - auto distance = _distance * getWheelInc (); - if (buttons & kMouseWheelInverted) - distance = -distance; - if (buttons & kShift) - distance *= 0.1f; - if (axis == kMouseWheelAxisX) - x += distance; - else - y += distance; + + auto distanceX = event.deltaX * getWheelInc (); + auto distanceY = event.deltaY * getWheelInc (); + if (event.flags & MouseWheelEvent::DirectionInvertedFromDevice) + { + distanceX *= -1.; + distanceY *= -1.; + } + if (event.modifiers.has (ModifierKey::Shift)) + { + distanceX *= 0.1; + distanceY *= 0.1; + } + x += distanceX; + y += distanceY; boundValues (x, y); onMouseWheelEditing (this); setValue (calculateValue (x, y)); diff --git a/vstgui/lib/controls/cxypad.h b/vstgui/lib/controls/cxypad.h index d5798f549..e2c3aec6b 100644 --- a/vstgui/lib/controls/cxypad.h +++ b/vstgui/lib/controls/cxypad.h @@ -29,7 +29,7 @@ class CXYPad : public CParamDisplay, protected CMouseWheelEditingSupport CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseCancel () override; - bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override; + void onMouseWheelEvent (MouseWheelEvent& event) override; int32_t onKeyDown (VstKeyCode& keyCode) override; static float calculateValue (float x, float y) From 0dd81a46699f7ff9577327418536eb41c0fb7c84 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 19:24:30 +0200 Subject: [PATCH 012/319] adopt new mouse wheel event handling for CKnobBase --- vstgui/lib/controls/cknob.cpp | 14 ++++++-------- vstgui/lib/controls/cknob.h | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/vstgui/lib/controls/cknob.cpp b/vstgui/lib/controls/cknob.cpp index d3a962683..d06356aa9 100644 --- a/vstgui/lib/controls/cknob.cpp +++ b/vstgui/lib/controls/cknob.cpp @@ -8,6 +8,7 @@ #include "../cframe.h" #include "../cgraphicspath.h" #include "../cvstguitimer.h" +#include "../events.h" #include namespace VSTGUI { @@ -232,18 +233,15 @@ CMouseEventResult CKnobBase::onMouseMoved (CPoint& where, const CButtonState& bu } //------------------------------------------------------------------------ -bool CKnobBase::onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float &distance, const CButtonState &buttons) +void CKnobBase::onMouseWheelEvent (MouseWheelEvent& event) { - if (!getMouseEnabled ()) - return false; - onMouseWheelEditing (this); float v = getValueNormalized (); - if (buttons & kZoomModifier) - v += 0.1f * distance * getWheelInc (); + if (buttonStateFromEventModifiers (event.modifiers) & kZoomModifier) + v += 0.1f * event.deltaY * getWheelInc (); else - v += distance * getWheelInc (); + v += event.deltaY * getWheelInc (); setValueNormalized (v); if (isDirty ()) @@ -251,7 +249,7 @@ bool CKnobBase::onWheel (const CPoint& where, const CMouseWheelAxis& axis, const invalid (); valueChanged (); } - return true; + event.consumed = true; } //------------------------------------------------------------------------ diff --git a/vstgui/lib/controls/cknob.h b/vstgui/lib/controls/cknob.h index 45b16a42b..22756080f 100644 --- a/vstgui/lib/controls/cknob.h +++ b/vstgui/lib/controls/cknob.h @@ -35,7 +35,7 @@ class CKnobBase : public CControl, protected CMouseWheelEditingSupport //@} // overrides - bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override; + void onMouseWheelEvent (MouseWheelEvent& event) override; int32_t onKeyDown (VstKeyCode& keyCode) override; void setViewSize (const CRect &rect, bool invalid = true) override; bool sizeToFit () override; From 16174d681159f6658f11ee58f2cbc5027dfcc310 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 19:33:28 +0200 Subject: [PATCH 013/319] adopt new mouse wheel event handling for CSliderBase --- vstgui/lib/controls/cslider.cpp | 26 +++++++++++--------------- vstgui/lib/controls/cslider.h | 3 +-- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/vstgui/lib/controls/cslider.cpp b/vstgui/lib/controls/cslider.cpp index 12fe21139..98d547ae3 100644 --- a/vstgui/lib/controls/cslider.cpp +++ b/vstgui/lib/controls/cslider.cpp @@ -6,6 +6,7 @@ #include "../cdrawcontext.h" #include "../cgraphicspath.h" #include "../cvstguitimer.h" +#include "../events.h" #include "cslider.h" #include @@ -504,28 +505,23 @@ CMouseEventResult CSliderBase::onMouseMoved (CPoint& where, const CButtonState& } //------------------------------------------------------------------------ -bool CSliderBase::onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, - const CButtonState& buttons) +void CSliderBase::onMouseWheelEvent (MouseWheelEvent& event) { - if (!getMouseEnabled ()) - return false; - - if ((isStyleHorizontal () && axis == kMouseWheelAxisY) || - (!isStyleHorizontal () && axis == kMouseWheelAxisX)) - return false; + auto distance = isStyleHorizontal () ? event.deltaX : event.deltaY; + if (distance == 0.) + return; onMouseWheelEditing (this); - float _distance = distance; if (isStyleHorizontal ()) - _distance *= -1.f; + distance *= -1.; if (isInverseStyle ()) - _distance *= -1.f; + distance *= -1.; float normValue = getValueNormalized (); - if (buttons & kZoomModifier) - normValue += 0.1f * _distance * getWheelInc (); + if (buttonStateFromEventModifiers (event.modifiers) & kZoomModifier) + normValue += 0.1 * distance * getWheelInc (); else - normValue += _distance * getWheelInc (); + normValue += distance * getWheelInc (); setValueNormalized (normValue); @@ -536,7 +532,7 @@ bool CSliderBase::onWheel (const CPoint& where, const CMouseWheelAxis& axis, con valueChanged (); } - return true; + event.consumed = true; } //------------------------------------------------------------------------ diff --git a/vstgui/lib/controls/cslider.h b/vstgui/lib/controls/cslider.h index 009a75aa7..65c528f8f 100644 --- a/vstgui/lib/controls/cslider.h +++ b/vstgui/lib/controls/cslider.h @@ -63,8 +63,7 @@ class CSliderBase : public CControl, protected CMouseWheelEditingSupport CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseCancel () override; - bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, - const CButtonState& buttons) override; + void onMouseWheelEvent (MouseWheelEvent& event) override; int32_t onKeyDown (VstKeyCode& keyCode) override; void setViewSize (const CRect& rect, bool invalid) override; From 8fa53af6a0bda2ebacabb8c18fb6508230080bac Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 19:33:47 +0200 Subject: [PATCH 014/319] adopt new mouse wheel event handling for CRockerSwitch --- vstgui/lib/controls/cswitch.cpp | 11 ++++++----- vstgui/lib/controls/cswitch.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/vstgui/lib/controls/cswitch.cpp b/vstgui/lib/controls/cswitch.cpp index c4d9515de..2fa6c4727 100644 --- a/vstgui/lib/controls/cswitch.cpp +++ b/vstgui/lib/controls/cswitch.cpp @@ -6,6 +6,7 @@ #include "../cdrawcontext.h" #include "../cbitmap.h" #include "../cvstguitimer.h" +#include "../events.h" namespace VSTGUI { @@ -558,11 +559,11 @@ int32_t CRockerSwitch::onKeyUp (VstKeyCode& keyCode) } //------------------------------------------------------------------------ -bool CRockerSwitch::onWheel (const CPoint& where, const CMouseWheelAxis& axis, - const float& distance, const CButtonState& buttons) +void CRockerSwitch::onMouseWheelEvent (MouseWheelEvent& event) { - if (!getMouseEnabled ()) - return false; + auto distance = event.deltaY; + if (distance == 0.) + return; if (distance > 0) value = getMin (); @@ -582,7 +583,7 @@ bool CRockerSwitch::onWheel (const CPoint& where, const CMouseWheelAxis& axis, resetValueTimer->stop (); resetValueTimer->start (); - return true; + event.consumed = true; } //------------------------------------------------------------------------ diff --git a/vstgui/lib/controls/cswitch.h b/vstgui/lib/controls/cswitch.h index 20c7ce172..171d3ea50 100644 --- a/vstgui/lib/controls/cswitch.h +++ b/vstgui/lib/controls/cswitch.h @@ -136,7 +136,7 @@ class CRockerSwitch : public CControl, public IMultiBitmapControl CRockerSwitch (const CRockerSwitch& rswitch); void draw (CDrawContext*) override; - bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override; + void onMouseWheelEvent (MouseWheelEvent& event) override; CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override; From 782914b7b69c6fd997294f080d9735f5afb96e53 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 19:59:49 +0200 Subject: [PATCH 015/319] adopt test to new mouse wheel event handling --- vstgui/tests/unittest/lib/controls/cxypad_test.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vstgui/tests/unittest/lib/controls/cxypad_test.cpp b/vstgui/tests/unittest/lib/controls/cxypad_test.cpp index 3c45c507b..cb6d51b1a 100644 --- a/vstgui/tests/unittest/lib/controls/cxypad_test.cpp +++ b/vstgui/tests/unittest/lib/controls/cxypad_test.cpp @@ -3,6 +3,7 @@ // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE #include "../../../../lib/controls/cxypad.h" +#include "../../../../lib/events.h" #include "../../unittests.h" namespace VSTGUI { @@ -108,10 +109,15 @@ TESTCASE(CXYPadTest, float y = 1.f; CXYPad::calculateXY (pad.getValue (), x, y); EXPECT(x == 0.f && y == 0.f); - pad.onWheel (CPoint (1, 1), CMouseWheelAxis::kMouseWheelAxisX, 1.f, 0); + MouseWheelEvent event; + event.mousePosition = CPoint (1, 1); + event.deltaX = 1.; + pad.onMouseWheelEvent (event); CXYPad::calculateXY (pad.getValue (), x, y); EXPECT(x == pad.getWheelInc () && y == 0.f); - pad.onWheel (CPoint (1, 1), CMouseWheelAxis::kMouseWheelAxisY, 1.f, 0); + event.deltaX = 0.; + event.deltaY = 1.; + pad.onMouseWheelEvent (event); CXYPad::calculateXY (pad.getValue (), x, y); EXPECT(x == pad.getWheelInc () && y == pad.getWheelInc ()); From 3c53ddcf07e9fe357d549911ab54dd8102e2b7d5 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 20:00:05 +0200 Subject: [PATCH 016/319] adopt new mouse wheel event handling for UIEditView --- vstgui/uidescription/editing/uieditview.cpp | 10 ++++++---- vstgui/uidescription/editing/uieditview.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/vstgui/uidescription/editing/uieditview.cpp b/vstgui/uidescription/editing/uieditview.cpp index e6386aac7..f06922dd8 100644 --- a/vstgui/uidescription/editing/uieditview.cpp +++ b/vstgui/uidescription/editing/uieditview.cpp @@ -25,6 +25,7 @@ #include "../../lib/coffscreencontext.h" #include "../../lib/clayeredviewcontainer.h" #include "../../lib/dragging.h" +#include "../../lib/events.h" #include "../../lib/idatapackage.h" #include "../../lib/controls/ctextedit.h" #include @@ -481,11 +482,12 @@ bool UIEditView::advanceNextFocusView (CView* oldFocus, bool reverse) } //---------------------------------------------------------------------------------------------------- -bool UIEditView::onWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons) +void UIEditView::onMouseWheelEvent (MouseWheelEvent& event) { - if (editing == false) - return CViewContainer::onWheel (where, axis, distance, buttons); - return false; + if (editing) + event.consumed = true; + else + CViewContainer::onMouseWheelEvent (event); } //---------------------------------------------------------------------------------------------------- diff --git a/vstgui/uidescription/editing/uieditview.h b/vstgui/uidescription/editing/uieditview.h index e9c5d6d59..eb6a204ed 100644 --- a/vstgui/uidescription/editing/uieditview.h +++ b/vstgui/uidescription/editing/uieditview.h @@ -106,7 +106,7 @@ class UIEditView : public CViewContainer, public IDropTarget CView* getViewAt (const CPoint& p, const GetViewOptions& options = GetViewOptions ()) const override; CViewContainer* getContainerAt (const CPoint& p, const GetViewOptions& options = GetViewOptions ().deep ()) const override; bool advanceNextFocusView (CView* oldFocus, bool reverse) override; - bool onWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons) override; + void onMouseWheelEvent (MouseWheelEvent& event) override; void looseFocus () override; void takeFocus () override; From 99bacb960e5aec9f2c15f7ddb47c7dc7a199ebef Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 20:04:03 +0200 Subject: [PATCH 017/319] adopt tests to use new mouse event handling method --- vstgui/tests/unittest/lib/cview_test.cpp | 6 ++++-- vstgui/tests/unittest/lib/cviewcontainer_test.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/vstgui/tests/unittest/lib/cview_test.cpp b/vstgui/tests/unittest/lib/cview_test.cpp index 45d286a4b..bc71ccd16 100644 --- a/vstgui/tests/unittest/lib/cview_test.cpp +++ b/vstgui/tests/unittest/lib/cview_test.cpp @@ -7,6 +7,7 @@ #include "../../../lib/cview.h" #include "../../../lib/cviewcontainer.h" #include "../../../lib/dragging.h" +#include "../../../lib/events.h" #include "../../../lib/iviewlistener.h" #include "../../../lib/idatapackage.h" @@ -252,8 +253,9 @@ TESTCASE(CViewTest, VstKeyCode key; EXPECT(v.onKeyDown (key) == -1); EXPECT(v.onKeyUp (key) == -1); - EXPECT(v.onWheel (CPoint (0, 0), kMouseWheelAxisX, 1.f, 0) == false); - EXPECT(v.onWheel (CPoint (0, 0), kMouseWheelAxisY, 1.f, 0) == false); + MouseWheelEvent event; + v.onMouseWheelEvent (event); + EXPECT(event.consumed == false); CPoint p (0, 0); EXPECT(v.onMouseDown (p, kLButton) == kMouseEventNotImplemented); EXPECT(v.onMouseUp (p, kLButton) == kMouseEventNotImplemented); diff --git a/vstgui/tests/unittest/lib/cviewcontainer_test.cpp b/vstgui/tests/unittest/lib/cviewcontainer_test.cpp index 7dbe65983..0cec6b5ad 100644 --- a/vstgui/tests/unittest/lib/cviewcontainer_test.cpp +++ b/vstgui/tests/unittest/lib/cviewcontainer_test.cpp @@ -100,10 +100,10 @@ class MouseEventCheckView : public CView, public DropTargetAdapter return DragOperation::None; } - bool onWheel (const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons) override + void onMouseWheelEvent (MouseWheelEvent& event) override { onWheelCalled = true; - return true; + event.consumed = true; } }; From dbe43587ece7fdcc50055ed52cbc34006ddf1d56 Mon Sep 17 00:00:00 2001 From: scheffle Date: Mon, 5 Apr 2021 20:31:43 +0200 Subject: [PATCH 018/319] fix error --- vstgui/lib/controls/cxypad.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vstgui/lib/controls/cxypad.cpp b/vstgui/lib/controls/cxypad.cpp index 9bb2073c1..264548a2b 100644 --- a/vstgui/lib/controls/cxypad.cpp +++ b/vstgui/lib/controls/cxypad.cpp @@ -173,7 +173,7 @@ void CXYPad::onMouseWheelEvent (MouseWheelEvent& event) invalid (); valueChanged (); } - return true; + event.consumed = true; } //------------------------------------------------------------------------ From 5d4408e0459c9a56046dbdb33f504db7fff59c1a Mon Sep 17 00:00:00 2001 From: scheffle Date: Tue, 6 Apr 2021 10:11:47 +0200 Subject: [PATCH 019/319] make sure that overrides of onWheel for CViewContainer will generate an error One need to adopt to the new onMouseWheelEvent method to get mouse wheel message for an inherited CViewContainer class. --- vstgui/lib/cviewcontainer.cpp | 9 +++++++++ vstgui/lib/cviewcontainer.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/vstgui/lib/cviewcontainer.cpp b/vstgui/lib/cviewcontainer.cpp index ae9ef4179..58d15f7c2 100644 --- a/vstgui/lib/cviewcontainer.cpp +++ b/vstgui/lib/cviewcontainer.cpp @@ -979,6 +979,15 @@ bool CViewContainer::hitTest (const CPoint& where, const CButtonState& buttons) return CView::hitTest (where2, buttons); } +#if VSTGUI_ENABLE_DEPRECATED_METHODS +//------------------------------------------------------------------------ +bool CViewContainer::onWheel (const CPoint& where, const CMouseWheelAxis& axis, + const float& distance, const CButtonState& buttons) +{ + return false; +} +#endif + //------------------------------------------------------------------------ void CViewContainer::dispatchEvent (Event& event) { diff --git a/vstgui/lib/cviewcontainer.h b/vstgui/lib/cviewcontainer.h index ad95d3fbd..d8936492c 100644 --- a/vstgui/lib/cviewcontainer.h +++ b/vstgui/lib/cviewcontainer.h @@ -144,6 +144,10 @@ class CViewContainer : public CView bool hitTest (const CPoint& where, const CButtonState& buttons = -1) override; CMessageResult notify (CBaseObject* sender, IdStringPtr message) override; +#if VSTGUI_ENABLE_DEPRECATED_METHODS + bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, + const CButtonState& buttons) final; +#endif #if VSTGUI_TOUCH_EVENT_HANDLING virtual void onTouchEvent (ITouchEvent& event) override; virtual bool wantsMultiTouchEvents () const override { return true; } From 998608fe4c991499ca8194bcd2044535394b3c7e Mon Sep 17 00:00:00 2001 From: scheffle Date: Tue, 6 Apr 2021 10:49:29 +0200 Subject: [PATCH 020/319] do not warn on deprecated messages in cases where we support the transition to the new API --- vstgui/lib/cview.cpp | 3 +++ vstgui/lib/private/disabledeprecatedmessage.h | 12 ++++++++++++ vstgui/lib/private/enbledeprecatedmessage.h | 11 +++++++++++ .../tests/unittest/lib/animation/animator_test.cpp | 2 ++ vstgui/tests/unittest/lib/cframe_test.cpp | 2 ++ vstgui/tests/unittest/lib/idependency_test.cpp | 2 ++ 6 files changed, 32 insertions(+) create mode 100644 vstgui/lib/private/disabledeprecatedmessage.h create mode 100644 vstgui/lib/private/enbledeprecatedmessage.h diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index 6d429004f..e4d1a84c3 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -468,6 +468,8 @@ bool CView::removed (CView* parent) void CView::onMouseWheelEvent (MouseWheelEvent& event) { #if VSTGUI_ENABLE_DEPRECATED_METHODS +#include "private/disabledeprecatedmessage.h" + if (!getMouseEnabled ()) return; @@ -484,6 +486,7 @@ void CView::onMouseWheelEvent (MouseWheelEvent& event) if (onWheel (event.mousePosition, kMouseWheelAxisY, event.deltaY, buttons)) event.consumed = true; } +#include "private/enbledeprecatedmessage.h" #endif } diff --git a/vstgui/lib/private/disabledeprecatedmessage.h b/vstgui/lib/private/disabledeprecatedmessage.h new file mode 100644 index 000000000..ceab11557 --- /dev/null +++ b/vstgui/lib/private/disabledeprecatedmessage.h @@ -0,0 +1,12 @@ +// This file is part of VSTGUI. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this +// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated" +#elif _MSVC +#pragma warning(disabled : 4995) // deprecated +#else +#endif + diff --git a/vstgui/lib/private/enbledeprecatedmessage.h b/vstgui/lib/private/enbledeprecatedmessage.h new file mode 100644 index 000000000..2257a4294 --- /dev/null +++ b/vstgui/lib/private/enbledeprecatedmessage.h @@ -0,0 +1,11 @@ +// This file is part of VSTGUI. It is subject to the license terms +// in the LICENSE file found in the top-level directory of this +// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE + +#ifdef __clang__ +#pragma clang diagnostic pop +#elif _MSVC +#pragma warning(3 : 4995) // deprecated +#else +#endif + diff --git a/vstgui/tests/unittest/lib/animation/animator_test.cpp b/vstgui/tests/unittest/lib/animation/animator_test.cpp index 968bd0cd1..9a586446f 100644 --- a/vstgui/tests/unittest/lib/animation/animator_test.cpp +++ b/vstgui/tests/unittest/lib/animation/animator_test.cpp @@ -48,6 +48,7 @@ struct MessageReceiver : public CBaseObject } // anonymous +#include "../../../../lib/private/disabledeprecatedmessage.h" //----------------------------------------------------------------------------- TESTCASE(AnimatorTest, CFRunLoopGetMain (); @@ -91,6 +92,7 @@ TESTCASE(AnimatorTest, ); #endif ); +#include "../../../../lib/private/enbledeprecatedmessage.h" } // VSTGUI diff --git a/vstgui/tests/unittest/lib/cframe_test.cpp b/vstgui/tests/unittest/lib/cframe_test.cpp index cf6d1d1c9..7f3ceb069 100644 --- a/vstgui/tests/unittest/lib/cframe_test.cpp +++ b/vstgui/tests/unittest/lib/cframe_test.cpp @@ -612,6 +612,7 @@ TESTCASE(CFrameTest, ); #if VSTGUI_ENABLE_DEPRECATED_METHODS +#include "../../../lib/private/disabledeprecatedmessage.h" TESTCASE(CFrameLegacyTest, TEST(setModalView, auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr)); @@ -628,6 +629,7 @@ TESTCASE(CFrameLegacyTest, EXPECT (frame->getModalView () == nullptr); ); ); +#include "../../../lib/private/enbledeprecatedmessage.h" #endif } // VSTGUI diff --git a/vstgui/tests/unittest/lib/idependency_test.cpp b/vstgui/tests/unittest/lib/idependency_test.cpp index 380f02cda..b6b3ccf8a 100644 --- a/vstgui/tests/unittest/lib/idependency_test.cpp +++ b/vstgui/tests/unittest/lib/idependency_test.cpp @@ -5,6 +5,7 @@ #include "../unittests.h" #if VSTGUI_ENABLE_DEPRECATED_METHODS +#include "../../../lib/private/disabledeprecatedmessage.h" #include "../../../lib/idependency.h" @@ -78,4 +79,5 @@ TESTCASE(IDependencyTest, } // VSTGUI +#include "../../../lib/private/enbledeprecatedmessage.h" #endif // VSTGUI_ENABLE_DEPRECATED_METHODS From a2d4e00155b608002b10ae92ad3a19af5bfaa3b5 Mon Sep 17 00:00:00 2001 From: scheffle Date: Tue, 6 Apr 2021 12:27:54 +0200 Subject: [PATCH 021/319] first part of new keyboard event handling --- vstgui/lib/cframe.cpp | 60 +++++++- vstgui/lib/cframe.h | 1 + vstgui/lib/cview.cpp | 43 ++++-- vstgui/lib/cview.h | 1 + vstgui/lib/cviewcontainer.cpp | 7 + vstgui/lib/events.h | 72 +++++++++- vstgui/lib/platform/mac/cocoa/cocoahelpers.h | 3 +- vstgui/lib/platform/mac/cocoa/cocoahelpers.mm | 135 ++++++++++-------- vstgui/lib/platform/mac/cocoa/nsviewframe.mm | 49 ++++--- 9 files changed, 271 insertions(+), 100 deletions(-) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index f6861e969..aca496aba 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -699,18 +699,76 @@ int32_t CFrame::onKeyUp (VstKeyCode& keyCode) return result; } +//----------------------------------------------------------------------------- +void CFrame::dispatchKeyboardEvent (KeyboardEvent& event) +{ +#if VSTGUI_ENABLE_DEPRECATED_METHODS + VstKeyCode vstKeyCode = toVstKeyCode (event); + int32_t result = 0; + if (event.type == EventType::KeyUp) + result = keyboardHooksOnKeyUp (vstKeyCode); + else + result = keyboardHooksOnKeyDown (vstKeyCode); + if (result != -1) + { + event.consumed = true; + return; + } +#endif + if (pImpl->focusView) + { + CBaseObjectGuard og (pImpl->focusView); + if (pImpl->focusView->getMouseEnabled ()) + pImpl->focusView->onKeyboardEvent (event); + if (event.consumed) + return; + CView* parent = pImpl->focusView->getParentView (); + while (parent && parent != this) + { + if (parent->getMouseEnabled ()) + { + parent->onKeyboardEvent (event); + if (event.consumed) + return; + } + parent = parent->getParentView (); + } + } + if (auto modalView = getModalView ()) + { + CBaseObjectGuard og (modalView); + modalView->onKeyboardEvent (event); + if (event.consumed) + return; + } + if (event.type != EventType::KeyUp) + { + if (event.modifiers.empty () || event.modifiers.is (ModifierKey::Shift)) + { + if (advanceNextFocusView (pImpl->focusView, event.modifiers.is (ModifierKey::Shift))) + event.consumed = true; + } + } +} + //----------------------------------------------------------------------------- void CFrame::dispatchEvent (Event& event) { Impl::PostEventHandler peh (*pImpl); CollectInvalidRects cir (this); - auto modalView = getModalView (); + if (auto keyEvent = asKeyboardEvent (event)) + { + dispatchKeyboardEvent (*keyEvent); + return; + } + auto mousePosEvent = asMousePositionEvent (event); CPoint mousePosition; if (mousePosEvent) mousePosition = mousePosEvent->mousePosition; + auto modalView = getModalView (); if (modalView && mousePosEvent) getTransform ().inverse ().transform (mousePosEvent->mousePosition); diff --git a/vstgui/lib/cframe.h b/vstgui/lib/cframe.h index 1ca76c897..aed8e1ac7 100644 --- a/vstgui/lib/cframe.h +++ b/vstgui/lib/cframe.h @@ -279,6 +279,7 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback #endif void initModalViewSession (const ModalViewSession& session); void clearModalViewSessions (); + void dispatchKeyboardEvent (KeyboardEvent& event); struct Impl; Impl* pImpl {nullptr}; diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index e4d1a84c3..ebe3b2c6b 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -469,10 +469,6 @@ void CView::onMouseWheelEvent (MouseWheelEvent& event) { #if VSTGUI_ENABLE_DEPRECATED_METHODS #include "private/disabledeprecatedmessage.h" - - if (!getMouseEnabled ()) - return; - auto buttons = buttonStateFromEventModifiers (event.modifiers); if (event.flags | MouseWheelEvent::DirectionInvertedFromDevice) buttons |= kMouseWheelInverted; @@ -491,31 +487,56 @@ void CView::onMouseWheelEvent (MouseWheelEvent& event) } //------------------------------------------------------------------------ -void CView::dispatchEvent (Event& event) +void CView::onKeyboardEvent (KeyboardEvent& event) { +#if VSTGUI_ENABLE_DEPRECATED_METHODS + auto keyCode = toVstKeyCode (event); + switch (event.type) { - case EventType::MouseWheel: + case EventType::KeyDown: [[fallthrough]]; + case EventType::KeyRepeat: { - auto& wheelEvent = castMouseWheelEvent (event); - onMouseWheelEvent (wheelEvent); + if (onKeyDown (keyCode) == 1) + event.consumed = true; break; } case EventType::KeyUp: { + if (onKeyUp (keyCode) == 1) + event.consumed = true; break; } - case EventType::KeyRepeat: + default: + { + vstgui_assert (false); + break; + } + } +#endif +} + +//------------------------------------------------------------------------ +void CView::dispatchEvent (Event& event) +{ + switch (event.type) + { + case EventType::MouseWheel: { + auto& wheelEvent = castMouseWheelEvent (event); + onMouseWheelEvent (wheelEvent); break; } + case EventType::KeyUp: [[fallthrough]]; + case EventType::KeyRepeat: [[fallthrough]]; case EventType::KeyDown: { + auto& keyEvent = castKeyboardEvent (event); + onKeyboardEvent (keyEvent); break; } - case EventType::Unknown: assert (false); break; + case EventType::Unknown: vstgui_assert (false); break; } - } //----------------------------------------------------------------------------- diff --git a/vstgui/lib/cview.h b/vstgui/lib/cview.h index eedc41e97..ad3a66693 100644 --- a/vstgui/lib/cview.h +++ b/vstgui/lib/cview.h @@ -82,6 +82,7 @@ class CView : public CBaseObject //@} virtual void onMouseWheelEvent (MouseWheelEvent& event); + virtual void onKeyboardEvent (KeyboardEvent& event); virtual void dispatchEvent (Event& event); //----------------------------------------------------------------------------- diff --git a/vstgui/lib/cviewcontainer.cpp b/vstgui/lib/cviewcontainer.cpp index 58d15f7c2..d34f0d317 100644 --- a/vstgui/lib/cviewcontainer.cpp +++ b/vstgui/lib/cviewcontainer.cpp @@ -1021,6 +1021,13 @@ void CViewContainer::dispatchEvent (Event& event) } } } + case EventType::KeyUp: + case EventType::KeyRepeat: + case EventType::KeyDown: + { + vstgui_assert (false); + break; + } default: break; } } diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index 94e9cdc82..6c209c30f 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -8,6 +8,10 @@ #include "cbuttonstate.h" #include "cpoint.h" +#if VSTGUI_ENABLE_DEPRECATED_METHODS +#include "vstkeycode.h" +#endif + //------------------------------------------------------------------------ namespace VSTGUI { @@ -122,7 +126,7 @@ struct MouseWheelEvent : MousePositionEvent */ enum class VirtualKey : uint32_t { - Unknown = 0, + None = 0, Back, Tab, @@ -186,7 +190,8 @@ enum class VirtualKey : uint32_t ControlModifier, AltModifier, - Equals + Equals, + // DO NOT CHANGE THE ORDER ABOVE }; @@ -215,7 +220,7 @@ struct KeyboardEvent : ModifierEvent /** UTF-16 character */ uint32_t character {0}; /** virtual key */ - VirtualKey virt {VirtualKey::Unknown}; + VirtualKey virt {VirtualKey::None}; }; //------------------------------------------------------------------------ @@ -251,6 +256,23 @@ inline ModifierEvent* asModifierEvent (Event& event) return nullptr; } +//------------------------------------------------------------------------ +/** event as keyboard event or nullpointer if not a keyboard event + * @ingroup new_in_4_11 + */ +inline KeyboardEvent* asKeyboardEvent (Event& event) +{ + switch (event.type) + { + case EventType::KeyDown: + case EventType::KeyRepeat: + case EventType::KeyUp: + return static_cast (&event); + default: break; + } + return nullptr; +} + //------------------------------------------------------------------------ /** cast to a mouse wheel event * @ingroup new_in_4_11 @@ -262,7 +284,18 @@ inline MouseWheelEvent& castMouseWheelEvent (Event& event) } //------------------------------------------------------------------------ -/** +/** cast to a mouse wheel event + * @ingroup new_in_4_11 + */ +inline KeyboardEvent& castKeyboardEvent (Event& event) +{ + vstgui_assert (event.type == EventType::KeyDown || event.type == EventType::KeyUp || + event.type == EventType::KeyRepeat); + return static_cast (event); +} + +//------------------------------------------------------------------------ +/** helper function to convert from new Modifiers to old CButtonState * @ingroup new_in_4_11 */ inline CButtonState buttonStateFromEventModifiers (const Modifiers& mods) @@ -277,6 +310,37 @@ inline CButtonState buttonStateFromEventModifiers (const Modifiers& mods) return state; } +//------------------------------------------------------------------------ +/** helper function to convert from new VirtualKey to old VstVirtualKey + * + * returns 0 if key cannot be mapped + * @ingroup new_in_4_11 + */ +inline unsigned char toVstVirtualKey (VirtualKey key) +{ + auto k = static_cast (key); + if (k <= static_cast (VirtualKey::Equals)) + return static_cast (k); + return 0; +} + +#if VSTGUI_ENABLE_DEPRECATED_METHODS +inline VstKeyCode toVstKeyCode (const KeyboardEvent& event) +{ + VstKeyCode keyCode {}; + keyCode.character = event.character; + keyCode.virt = toVstVirtualKey (event.virt); + if (event.modifiers.has (ModifierKey::Shift)) + keyCode.modifier |= MODIFIER_SHIFT; + if (event.modifiers.has (ModifierKey::Alt)) + keyCode.modifier |= MODIFIER_ALTERNATE; + if (event.modifiers.has (ModifierKey::Control)) + keyCode.modifier |= MODIFIER_CONTROL; + if (event.modifiers.has (ModifierKey::Super)) + keyCode.modifier |= MODIFIER_COMMAND; + return keyCode; +} +#endif //------------------------------------------------------------------------ } // VSTGUI diff --git a/vstgui/lib/platform/mac/cocoa/cocoahelpers.h b/vstgui/lib/platform/mac/cocoa/cocoahelpers.h index d2b76c743..8b53d609b 100644 --- a/vstgui/lib/platform/mac/cocoa/cocoahelpers.h +++ b/vstgui/lib/platform/mac/cocoa/cocoahelpers.h @@ -14,7 +14,6 @@ #import #import #import -struct VstKeyCode; #define HIDDEN __attribute__((__visibility__("hidden"))) @@ -65,7 +64,7 @@ static void (*SuperViewWillRedraw) (id, SEL) = SuperDealloc; //------------------------------------------------------------------------------------ extern HIDDEN Class generateUniqueClass (NSMutableString* className, Class baseClass); -extern HIDDEN VstKeyCode CreateVstKeyCodeFromNSEvent (NSEvent* theEvent); +extern HIDDEN bool CreateKeyboardEventFromNSEvent (NSEvent* theEvent, VSTGUI::KeyboardEvent& event); extern HIDDEN NSString* GetVirtualKeyCodeString (int32_t virtualKeyCode); extern HIDDEN int32_t eventButton (NSEvent* theEvent); extern HIDDEN void convertPointToGlobal (NSView* view, NSPoint& p); diff --git a/vstgui/lib/platform/mac/cocoa/cocoahelpers.mm b/vstgui/lib/platform/mac/cocoa/cocoahelpers.mm index 33752cd61..f655c9858 100644 --- a/vstgui/lib/platform/mac/cocoa/cocoahelpers.mm +++ b/vstgui/lib/platform/mac/cocoa/cocoahelpers.mm @@ -7,6 +7,7 @@ #if MAC_COCOA #include "../../../vstkeycode.h" +#include "../../../events.h" #include "../../../cview.h" #include "../../../cbitmap.h" #include "../cgbitmap.h" @@ -30,81 +31,91 @@ HIDDEN Class generateUniqueClass (NSMutableString* className, Class baseClass) //------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------ -HIDDEN VstKeyCode CreateVstKeyCodeFromNSEvent (NSEvent* theEvent) +HIDDEN bool CreateKeyboardEventFromNSEvent (NSEvent* theEvent, KeyboardEvent& event) { - VstKeyCode kc = {}; + if (theEvent.type == NSEventTypeKeyUp) + event.type = EventType::KeyUp; + else if (theEvent.type == NSEventTypeKeyDown || theEvent.type == NSEventTypeFlagsChanged) + { + if (theEvent.ARepeat) + event.type = EventType::KeyRepeat; + else + event.type = EventType::KeyDown; + } + else + return false; NSString *s = [theEvent charactersIgnoringModifiers]; if ([s length] == 1) { unichar c = [s characterAtIndex:0]; switch (c) { - case 8: case 0x7f: kc.virt = VKEY_BACK; break; - case 9: case 0x19: kc.virt = VKEY_TAB; break; - case NSClearLineFunctionKey: kc.virt = VKEY_CLEAR; break; - case 0xd: kc.virt = VKEY_RETURN; break; - case NSPauseFunctionKey: kc.virt = VKEY_PAUSE; break; - case 0x1b: kc.virt = VKEY_ESCAPE; break; - case ' ': kc.virt = VKEY_SPACE; break; - case NSNextFunctionKey: kc.virt = VKEY_NEXT; break; - case NSEndFunctionKey: kc.virt = VKEY_END; break; - case NSHomeFunctionKey: kc.virt = VKEY_HOME; break; - - case NSLeftArrowFunctionKey: kc.virt = VKEY_LEFT; break; - case NSUpArrowFunctionKey: kc.virt = VKEY_UP; break; - case NSRightArrowFunctionKey: kc.virt = VKEY_RIGHT; break; - case NSDownArrowFunctionKey: kc.virt = VKEY_DOWN; break; - case NSPageUpFunctionKey: kc.virt = VKEY_PAGEUP; break; - case NSPageDownFunctionKey: kc.virt = VKEY_PAGEDOWN; break; + case 8: case 0x7f: event.virt = VirtualKey::Back; break; + case 9: case 0x19: event.virt = VirtualKey::Tab; break; + case NSClearLineFunctionKey: event.virt = VirtualKey::Clear; break; + case 0xd: event.virt = VirtualKey::Return; break; + case NSPauseFunctionKey: event.virt = VirtualKey::Pause; break; + case 0x1b: event.virt = VirtualKey::Escape; break; + case ' ': event.virt = VirtualKey::Space; break; + case NSNextFunctionKey: event.virt = VirtualKey::Next; break; + case NSEndFunctionKey: event.virt = VirtualKey::End; break; + case NSHomeFunctionKey: event.virt = VirtualKey::Home; break; + + case NSLeftArrowFunctionKey: event.virt = VirtualKey::Left; break; + case NSUpArrowFunctionKey: event.virt = VirtualKey::Up; break; + case NSRightArrowFunctionKey: event.virt = VirtualKey::Right; break; + case NSDownArrowFunctionKey: event.virt = VirtualKey::Down; break; + case NSPageUpFunctionKey: event.virt = VirtualKey::PageUp; break; + case NSPageDownFunctionKey: event.virt = VirtualKey::PageDown; break; - case NSSelectFunctionKey: kc.virt = VKEY_SELECT; break; - case NSPrintFunctionKey: kc.virt = VKEY_PRINT; break; - // VKEY_ENTER - // VKEY_SNAPSHOT - case NSInsertFunctionKey: kc.virt = VKEY_INSERT; break; - case NSDeleteFunctionKey: kc.virt = VKEY_DELETE; break; - case NSHelpFunctionKey: kc.virt = VKEY_HELP; break; - - - case NSF1FunctionKey: kc.virt = VKEY_F1; break; - case NSF2FunctionKey: kc.virt = VKEY_F2; break; - case NSF3FunctionKey: kc.virt = VKEY_F3; break; - case NSF4FunctionKey: kc.virt = VKEY_F4; break; - case NSF5FunctionKey: kc.virt = VKEY_F5; break; - case NSF6FunctionKey: kc.virt = VKEY_F6; break; - case NSF7FunctionKey: kc.virt = VKEY_F7; break; - case NSF8FunctionKey: kc.virt = VKEY_F8; break; - case NSF9FunctionKey: kc.virt = VKEY_F9; break; - case NSF10FunctionKey: kc.virt = VKEY_F10; break; - case NSF11FunctionKey: kc.virt = VKEY_F11; break; - case NSF12FunctionKey: kc.virt = VKEY_F12; break; + case NSSelectFunctionKey: event.virt = VirtualKey::Select; break; + case NSPrintFunctionKey: event.virt = VirtualKey::Print; break; + // VirtualKey::ENTER + // VirtualKey::SNAPSHOT + case NSInsertFunctionKey: event.virt = VirtualKey::Insert; break; + case NSDeleteFunctionKey: event.virt = VirtualKey::Delete; break; + case NSHelpFunctionKey: event.virt = VirtualKey::Help; break; + + + case NSF1FunctionKey: event.virt = VirtualKey::F1; break; + case NSF2FunctionKey: event.virt = VirtualKey::F2; break; + case NSF3FunctionKey: event.virt = VirtualKey::F3; break; + case NSF4FunctionKey: event.virt = VirtualKey::F4; break; + case NSF5FunctionKey: event.virt = VirtualKey::F5; break; + case NSF6FunctionKey: event.virt = VirtualKey::F6; break; + case NSF7FunctionKey: event.virt = VirtualKey::F7; break; + case NSF8FunctionKey: event.virt = VirtualKey::F8; break; + case NSF9FunctionKey: event.virt = VirtualKey::F9; break; + case NSF10FunctionKey: event.virt = VirtualKey::F10; break; + case NSF11FunctionKey: event.virt = VirtualKey::F11; break; + case NSF12FunctionKey: event.virt = VirtualKey::F12; break; default: { switch ([theEvent keyCode]) { - case 82: kc.virt = VKEY_NUMPAD0; break; - case 83: kc.virt = VKEY_NUMPAD1; break; - case 84: kc.virt = VKEY_NUMPAD2; break; - case 85: kc.virt = VKEY_NUMPAD3; break; - case 86: kc.virt = VKEY_NUMPAD4; break; - case 87: kc.virt = VKEY_NUMPAD5; break; - case 88: kc.virt = VKEY_NUMPAD6; break; - case 89: kc.virt = VKEY_NUMPAD7; break; - case 91: kc.virt = VKEY_NUMPAD8; break; - case 92: kc.virt = VKEY_NUMPAD9; break; - case 67: kc.virt = VKEY_MULTIPLY; break; - case 69: kc.virt = VKEY_ADD; break; - case 78: kc.virt = VKEY_SUBTRACT; break; - case 65: kc.virt = VKEY_DECIMAL; break; - case 75: kc.virt = VKEY_DIVIDE; break; - case 76: kc.virt = VKEY_ENTER; break; + case 82: event.virt = VirtualKey::NumPad0; break; + case 83: event.virt = VirtualKey::NumPad1; break; + case 84: event.virt = VirtualKey::NumPad2; break; + case 85: event.virt = VirtualKey::NumPad3; break; + case 86: event.virt = VirtualKey::NumPad4; break; + case 87: event.virt = VirtualKey::NumPad5; break; + case 88: event.virt = VirtualKey::NumPad6; break; + case 89: event.virt = VirtualKey::NumPad7; break; + case 91: event.virt = VirtualKey::NumPad8; break; + case 92: event.virt = VirtualKey::NumPad9; break; + case 67: event.virt = VirtualKey::Multiply; break; + case 69: event.virt = VirtualKey::Add; break; + case 78: event.virt = VirtualKey::Subtract; break; + case 65: event.virt = VirtualKey::Decimal; break; + case 75: event.virt = VirtualKey::Divide; break; + case 76: event.virt = VirtualKey::Enter; break; default: { if ((c >= 'A') && (c <= 'Z')) c += ('a' - 'A'); else c = static_cast (tolower (c)); - kc.character = c; + event.character = c; break; } } @@ -114,15 +125,15 @@ HIDDEN VstKeyCode CreateVstKeyCodeFromNSEvent (NSEvent* theEvent) NSUInteger modifiers = [theEvent modifierFlags]; if (modifiers & MacEventModifier::ShiftKeyMask) - kc.modifier |= MODIFIER_SHIFT; + event.modifiers.add (ModifierKey::Shift); if (modifiers & MacEventModifier::CommandKeyMask) - kc.modifier |= MODIFIER_CONTROL; + event.modifiers.add (ModifierKey::Control); if (modifiers & MacEventModifier::AlternateKeyMask) - kc.modifier |= MODIFIER_ALTERNATE; + event.modifiers.add (ModifierKey::Alt); if (modifiers & MacEventModifier::ControlKeyMask) - kc.modifier |= MODIFIER_COMMAND; + event.modifiers.add (ModifierKey::Super); - return kc; + return true; } //------------------------------------------------------------------------------------ diff --git a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm index 94fb7aecd..70937bf59 100644 --- a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm +++ b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm @@ -470,12 +470,14 @@ static BOOL VSTGUI_NSView_performKeyEquivalent (id self, SEL _cmd, NSEvent* theE firstResponder = [firstResponder superview]; if (firstResponder == self) { - IPlatformFrameCallback* frame = getFrame (self); - if (frame) + if (auto _vstguiframe = getFrame (self)) { - VstKeyCode keyCode = CreateVstKeyCodeFromNSEvent (theEvent); - if (frame->platformOnKeyDown (keyCode)) - return YES; + KeyboardEvent keyEvent; + if (CreateKeyboardEventFromNSEvent (theEvent, keyEvent)) + { + _vstguiframe->platformOnEvent (keyEvent); + return keyEvent.consumed ? YES: NO; + } } } } @@ -489,18 +491,22 @@ static void VSTGUI_NSView_keyDown (id self, SEL _cmd, NSEvent* theEvent) if (!_vstguiframe) return; - VstKeyCode keyCode = CreateVstKeyCodeFromNSEvent (theEvent); - - bool res = _vstguiframe->platformOnKeyDown (keyCode); - if (!res&& keyCode.virt == VKEY_TAB) + KeyboardEvent keyEvent; + if (CreateKeyboardEventFromNSEvent (theEvent, keyEvent)) { - if (keyCode.modifier & kShift) - [[self window] selectKeyViewPrecedingView:self]; - else - [[self window] selectKeyViewFollowingView:self]; + _vstguiframe->platformOnEvent (keyEvent); + if (keyEvent.consumed) + return; + if (keyEvent.virt == VirtualKey::Tab) + { + if (keyEvent.modifiers.has (ModifierKey::Shift)) + [[self window] selectKeyViewPrecedingView:self]; + else + [[self window] selectKeyViewFollowingView:self]; + return; + } } - else if (!res) - [[self nextResponder] keyDown:theEvent]; + [[self nextResponder] keyDown:theEvent]; } //------------------------------------------------------------------------------------ @@ -510,11 +516,14 @@ static void VSTGUI_NSView_keyUp (id self, SEL _cmd, NSEvent* theEvent) if (!_vstguiframe) return; - VstKeyCode keyCode = CreateVstKeyCodeFromNSEvent (theEvent); - - bool res = _vstguiframe->platformOnKeyUp (keyCode); - if (!res) - [[self nextResponder] keyUp:theEvent]; + KeyboardEvent keyEvent; + if (CreateKeyboardEventFromNSEvent (theEvent, keyEvent)) + { + _vstguiframe->platformOnEvent (keyEvent); + if (keyEvent.consumed) + return; + } + [[self nextResponder] keyUp:theEvent]; } //------------------------------------------------------------------------------------ From 4f71a9353f126713fbceb416c5f87c68083e7ad1 Mon Sep 17 00:00:00 2001 From: scheffle Date: Tue, 6 Apr 2021 14:22:47 +0200 Subject: [PATCH 022/319] check for tab key when doing focus changes --- vstgui/lib/cframe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index aca496aba..72aa50ba1 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -741,7 +741,7 @@ void CFrame::dispatchKeyboardEvent (KeyboardEvent& event) if (event.consumed) return; } - if (event.type != EventType::KeyUp) + if (event.type != EventType::KeyUp && event.virt == VirtualKey::Tab) { if (event.modifiers.empty () || event.modifiers.is (ModifierKey::Shift)) { From dd1b475f4d82c33faf699966a79fa384e99bc4e2 Mon Sep 17 00:00:00 2001 From: scheffle Date: Tue, 6 Apr 2021 14:24:02 +0200 Subject: [PATCH 023/319] add documentation and a few more methods to the Modifiers struct --- vstgui/lib/events.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index 6c209c30f..9f62c5e18 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -53,18 +53,35 @@ struct Event */ struct Modifiers { - explicit Modifiers (uint32_t data = 0) : data (data) {} + Modifiers () = default; Modifiers (const Modifiers&) = default; + /** test if no modifier key is set */ bool empty () const { return data == 0;} + /** test if modifier key is set */ bool has (ModifierKey modifier) const { return data & cast (modifier); } + /** test if modifier key is set exclusively */ bool is (ModifierKey modifier) const { return data == cast (modifier); } - + /** test if the modifier keys are set exclusively */ + bool is (const std::initializer_list& modifiers) const + { + uint32_t d = 0; + for (auto& mod : modifiers) + d |= cast (mod); + return data == d; + } + /** test if modifier key is set */ bool operator| (ModifierKey modifier) const { return has (modifier); } + /** test if modifier key is set exclusively */ bool operator== (ModifierKey modifier) const { return is (modifier); } + /** add a modifier key */ void add (ModifierKey modifier) { data |= cast (modifier); } + /** remove a modifier key */ void remove (ModifierKey modifier) { data &= ~cast (modifier); } + /** clear all modifiers */ + void clear () { data = 0; } + /** set to one modifier key */ Modifiers& operator= (ModifierKey modifier) { data = cast (modifier); From f5f3ad05613d45b46809fc668b9addaff583a580 Mon Sep 17 00:00:00 2001 From: scheffle Date: Tue, 6 Apr 2021 19:10:54 +0200 Subject: [PATCH 024/319] add zoom gesture event --- vstgui/lib/cview.cpp | 11 +++++ vstgui/lib/cview.h | 1 + vstgui/lib/cviewcontainer.cpp | 12 +++--- vstgui/lib/events.h | 42 ++++++++++++++++++++ vstgui/lib/platform/mac/cocoa/nsviewframe.mm | 29 ++++++++++++++ vstgui/lib/vstguifwd.h | 2 + vstgui/uidescription/editing/uieditview.cpp | 13 ++++++ vstgui/uidescription/editing/uieditview.h | 1 + 8 files changed, 106 insertions(+), 5 deletions(-) diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index ebe3b2c6b..0f37f0e78 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -516,6 +516,11 @@ void CView::onKeyboardEvent (KeyboardEvent& event) #endif } +//------------------------------------------------------------------------ +void CView::onZoomGestureEvent (ZoomGestureEvent& event) +{ +} + //------------------------------------------------------------------------ void CView::dispatchEvent (Event& event) { @@ -527,6 +532,12 @@ void CView::dispatchEvent (Event& event) onMouseWheelEvent (wheelEvent); break; } + case EventType::ZoomGesture: + { + auto& zoomGesture = castZoomGestureEvent (event); + onZoomGestureEvent (zoomGesture); + break; + } case EventType::KeyUp: [[fallthrough]]; case EventType::KeyRepeat: [[fallthrough]]; case EventType::KeyDown: diff --git a/vstgui/lib/cview.h b/vstgui/lib/cview.h index ad3a66693..acfaba6f0 100644 --- a/vstgui/lib/cview.h +++ b/vstgui/lib/cview.h @@ -83,6 +83,7 @@ class CView : public CBaseObject virtual void onMouseWheelEvent (MouseWheelEvent& event); virtual void onKeyboardEvent (KeyboardEvent& event); + virtual void onZoomGestureEvent (ZoomGestureEvent& event); virtual void dispatchEvent (Event& event); //----------------------------------------------------------------------------- diff --git a/vstgui/lib/cviewcontainer.cpp b/vstgui/lib/cviewcontainer.cpp index d34f0d317..e43ea472b 100644 --- a/vstgui/lib/cviewcontainer.cpp +++ b/vstgui/lib/cviewcontainer.cpp @@ -1005,24 +1005,26 @@ void CViewContainer::dispatchEvent (Event& event) auto f = finally ([&] () { if (mouseEvent) mouseEvent->mousePosition = mousePos; }); switch (event.type) { + case EventType::ZoomGesture: case EventType::MouseWheel: { - auto& wheelEvent = castMouseWheelEvent (event); + auto& mousePosEvent = castMousePositionEvent (event); for (auto it = pImpl->children.rbegin (), end = pImpl->children.rend (); it != end; ++it) { const auto& pV = *it; if (pV && pV->isVisible () && pV->getMouseEnabled () && - pV->getMouseableArea ().pointInside (wheelEvent.mousePosition)) + pV->getMouseableArea ().pointInside (mousePosEvent.mousePosition)) { - pV->dispatchEvent (wheelEvent); + pV->dispatchEvent (event); if (!pV->getTransparency () || event.consumed) return; } } + break; } - case EventType::KeyUp: - case EventType::KeyRepeat: + case EventType::KeyUp: [[fallthrough]]; + case EventType::KeyRepeat: [[fallthrough]]; case EventType::KeyDown: { vstgui_assert (false); diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index 9f62c5e18..132df7234 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -26,6 +26,7 @@ enum class EventType : uint32_t KeyRepeat, KeyDown, MouseWheel, + ZoomGesture, }; //------------------------------------------------------------------------ @@ -135,6 +136,27 @@ struct MouseWheelEvent : MousePositionEvent MouseWheelEvent () { type = EventType::MouseWheel; } }; +//------------------------------------------------------------------------ +struct GestureEvent : MousePositionEvent +{ + enum class Phase { + Unknown, + Begin, + Changed, + End, + }; + + Phase phase {Phase::Unknown}; +}; + +//------------------------------------------------------------------------ +struct ZoomGestureEvent : GestureEvent +{ + double zoom; + + ZoomGestureEvent () { type = EventType::ZoomGesture; } +}; + //------------------------------------------------------------------------ // Keyboard Events //------------------------------------------------------------------------ @@ -290,6 +312,16 @@ inline KeyboardEvent* asKeyboardEvent (Event& event) return nullptr; } +//------------------------------------------------------------------------ +/** cast to a mouse position event + * @ingroup new_in_4_11 + */ +inline MousePositionEvent& castMousePositionEvent (Event& event) +{ + vstgui_assert (event.type == EventType::MouseWheel || event.type == EventType::ZoomGesture); + return static_cast (event); +} + //------------------------------------------------------------------------ /** cast to a mouse wheel event * @ingroup new_in_4_11 @@ -300,6 +332,16 @@ inline MouseWheelEvent& castMouseWheelEvent (Event& event) return static_cast (event); } +//------------------------------------------------------------------------ +/** cast to a zoom gesture event + * @ingroup new_in_4_11 + */ +inline ZoomGestureEvent& castZoomGestureEvent (Event& event) +{ + vstgui_assert (event.type == EventType::ZoomGesture); + return static_cast (event); +} + //------------------------------------------------------------------------ /** cast to a mouse wheel event * @ingroup new_in_4_11 diff --git a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm index 70937bf59..6b52c6911 100644 --- a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm +++ b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm @@ -526,6 +526,33 @@ static void VSTGUI_NSView_keyUp (id self, SEL _cmd, NSEvent* theEvent) [[self nextResponder] keyUp:theEvent]; } +//------------------------------------------------------------------------------------ +static void VSTGUI_NSView_magnifyWithEvent (id self, SEL _cmd, NSEvent* theEvent) +{ + IPlatformFrameCallback* _vstguiframe = getFrame (self); + if (!_vstguiframe) + return; + + NSPoint nsPoint = [theEvent locationInWindow]; + nsPoint = [self convertPoint:nsPoint fromView:nil]; + + ZoomGestureEvent event; + switch (theEvent.phase) + { + case NSEventPhaseBegan: event.phase = ZoomGestureEvent::Phase::Begin; break; + case NSEventPhaseChanged: event.phase = ZoomGestureEvent::Phase::Changed; break; + case NSEventPhaseCancelled: [[fallthrough]]; + case NSEventPhaseEnded: event.phase = ZoomGestureEvent::Phase::End; break; + default: return; + } + + event.mousePosition = pointFromNSPoint (nsPoint); + event.modifiers = modifiersFromModifierFlags (theEvent.modifierFlags); + event.zoom = theEvent.magnification; + + _vstguiframe->platformOnEvent (event); +} + //------------------------------------------------------------------------------------ static NSDragOperation VSTGUI_NSView_draggingEntered (id self, SEL _cmd, id sender) { @@ -796,6 +823,8 @@ static id VSTGUI_NSView_makeTouchbar (id self) VSTGUI_CHECK_YES(class_addMethod (viewClass, @selector(keyDown:), IMP (VSTGUI_NSView_keyDown), "v@:@:^:")) VSTGUI_CHECK_YES(class_addMethod (viewClass, @selector(keyUp:), IMP (VSTGUI_NSView_keyUp), "v@:@:^:")) + VSTGUI_CHECK_YES(class_addMethod (viewClass, @selector(magnifyWithEvent:), IMP (VSTGUI_NSView_magnifyWithEvent), "v@:@:^:")) + sprintf (funcSig, "%s@:@:", @encode(NSFocusRingType)); VSTGUI_CHECK_YES(class_addMethod (viewClass, @selector(focusRingType), IMP (VSTGUI_NSView_focusRingType), funcSig)) VSTGUI_CHECK_YES(class_addMethod (viewClass, @selector(makeSubViewFirstResponder:), IMP (VSTGUI_NSView_makeSubViewFirstResponder), "v@:@:^:")) diff --git a/vstgui/lib/vstguifwd.h b/vstgui/lib/vstguifwd.h index a551e7bbe..dd3ecbdb6 100644 --- a/vstgui/lib/vstguifwd.h +++ b/vstgui/lib/vstguifwd.h @@ -247,7 +247,9 @@ class CListControl; struct Event; struct ModifierEvent; struct MousePositionEvent; +struct GestureEvent; struct MouseWheelEvent; +struct ZoomGestureEvent; struct KeyboardEvent; struct Modifiers; enum class EventType : uint32_t; diff --git a/vstgui/uidescription/editing/uieditview.cpp b/vstgui/uidescription/editing/uieditview.cpp index f06922dd8..72f18dfe1 100644 --- a/vstgui/uidescription/editing/uieditview.cpp +++ b/vstgui/uidescription/editing/uieditview.cpp @@ -490,6 +490,19 @@ void UIEditView::onMouseWheelEvent (MouseWheelEvent& event) CViewContainer::onMouseWheelEvent (event); } +//------------------------------------------------------------------------ +void UIEditView::onZoomGestureEvent (ZoomGestureEvent& event) +{ + if (editing) + { + auto scale = getTransform ().m11; + auto newScale = scale + scale * event.zoom; + setScale (newScale); + } + else + CViewContainer::onZoomGestureEvent (event); +} + //---------------------------------------------------------------------------------------------------- void UIEditView::invalidSelection () { diff --git a/vstgui/uidescription/editing/uieditview.h b/vstgui/uidescription/editing/uieditview.h index eb6a204ed..a42519aa7 100644 --- a/vstgui/uidescription/editing/uieditview.h +++ b/vstgui/uidescription/editing/uieditview.h @@ -107,6 +107,7 @@ class UIEditView : public CViewContainer, public IDropTarget CViewContainer* getContainerAt (const CPoint& p, const GetViewOptions& options = GetViewOptions ().deep ()) const override; bool advanceNextFocusView (CView* oldFocus, bool reverse) override; void onMouseWheelEvent (MouseWheelEvent& event) override; + void onZoomGestureEvent (ZoomGestureEvent& event) override; void looseFocus () override; void takeFocus () override; From fe694655fba5486b3c13738274090839dacba779 Mon Sep 17 00:00:00 2001 From: scheffle Date: Tue, 6 Apr 2021 23:16:36 +0200 Subject: [PATCH 025/319] add zoom gesture event to mouse position event --- vstgui/lib/events.h | 1 + 1 file changed, 1 insertion(+) diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index 132df7234..7cd39ed46 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -270,6 +270,7 @@ inline MousePositionEvent* asMousePositionEvent (Event& event) { switch (event.type) { + case EventType::ZoomGesture: [[fallthrough]]; case EventType::MouseWheel: return static_cast (&event); default: break; From 3e016bf4a733b405f17959cc17059b68065d2927 Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 12:08:00 +0200 Subject: [PATCH 026/319] more keyboard event handling rework --- vstgui/doxygen/page_changes.h | 22 +++ vstgui/lib/cframe.cpp | 134 ++---------------- vstgui/lib/cframe.h | 15 +- vstgui/lib/controls/ctextedit.cpp | 17 +-- vstgui/lib/controls/ctextedit.h | 2 +- vstgui/lib/cview.cpp | 2 + vstgui/lib/cview.h | 6 +- .../lib/platform/common/generictextedit.cpp | 70 ++++----- vstgui/lib/platform/iplatformframecallback.h | 3 - vstgui/lib/platform/iplatformtextedit.h | 2 +- .../lib/platform/mac/cocoa/cocoatextedit.mm | 44 +++--- .../editing/uidialogcontroller.cpp | 30 ++-- .../editing/uidialogcontroller.h | 3 +- .../editing/uieditcontroller.cpp | 16 +-- .../uidescription/editing/uieditcontroller.h | 3 +- .../editing/uieditmenucontroller.cpp | 26 ++-- .../editing/uieditmenucontroller.h | 4 +- 17 files changed, 145 insertions(+), 254 deletions(-) diff --git a/vstgui/doxygen/page_changes.h b/vstgui/doxygen/page_changes.h index bfecc133f..e28846823 100644 --- a/vstgui/doxygen/page_changes.h +++ b/vstgui/doxygen/page_changes.h @@ -23,6 +23,10 @@ It's recommended to start new projects with version 4 while old projects should @section new_stuff New Stuff +@subsection version4_11 Version 4.11 + +- Reworked event handling, please see @ref code_changes_4_10_to_4_11 + @subsection version4_10 Version 4.10 - VSTGUI now needs to be initialized and terminated explicitly. See VSTGUI::init() and VSTGUI::exit(). @@ -110,6 +114,24 @@ Note: All current deprecated methods will be removed in the next version. So mak @section code_changes Changes for existing VSTGUI code +@subsection code_changes_4_10_to_4_11 VSTGUI 4.10 -> VSTGUI 4.11 + +Changes due to event handling rework: +- IKeyboardHook changed its methods. If you inherit from it, you need to adopt to the new methods +- CViewContainer::onWheel is now marked final, you cannot inherit this method, please use the new CView::onMouseWheelEvent instead + +CView has the following new methods: +- dispatchEvent +- onKeyboardEvent +- onMouseWheelEvent +- onZoomGestureEvent +- ... +Which replaces the following old methods: +- onKeyDown +- onKeyUp +- onWheel +- ... + @subsection code_changes_4_9_to_4_10 VSTGUI 4.9 -> VSTGUI 4.10 - one has to use VSTGUI::init() before using VSTGUI and VSTGUI::exit() after use diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index 72aa50ba1..4a5734283 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -629,92 +629,13 @@ CMouseEventResult CFrame::onMouseExited (CPoint &where, const CButtonState& butt return kMouseEventHandled; } -//----------------------------------------------------------------------------- -int32_t CFrame::onKeyDown (VstKeyCode& keyCode) -{ - int32_t result = keyboardHooksOnKeyDown (keyCode); - - if (result == -1 && pImpl->focusView) - { - CBaseObjectGuard og (pImpl->focusView); - if (pImpl->focusView->getMouseEnabled ()) - result = pImpl->focusView->onKeyDown (keyCode); - if (result == -1) - { - CView* parent = pImpl->focusView->getParentView (); - while (parent && parent != this && result == -1) - { - if (parent->getMouseEnabled ()) - result = parent->onKeyDown (keyCode); - parent = parent->getParentView (); - } - } - } - - if (result == -1) - { - if (auto modalView = getModalView ()) - { - CBaseObjectGuard og (modalView); - result = modalView->onKeyDown (keyCode); - } - } - - if (result == -1 && keyCode.virt == VKEY_TAB) - { - if (keyCode.modifier == 0 || keyCode.modifier == MODIFIER_SHIFT) - result = advanceNextFocusView (pImpl->focusView, (keyCode.modifier & MODIFIER_SHIFT) ? true : false) ? 1 : -1; - } - - return result; -} - -//----------------------------------------------------------------------------- -int32_t CFrame::onKeyUp (VstKeyCode& keyCode) -{ - int32_t result = keyboardHooksOnKeyUp (keyCode); - - if (result == -1 && pImpl->focusView) - { - if (pImpl->focusView->getMouseEnabled ()) - result = pImpl->focusView->onKeyUp (keyCode); - if (result == -1) - { - CView* parent = pImpl->focusView->getParentView (); - while (parent && parent != this && result == -1) - { - if (parent->getMouseEnabled ()) - result = parent->onKeyUp (keyCode); - parent = parent->getParentView (); - } - } - } - - if (result == -1) - { - if (auto modalView = getModalView ()) - result = modalView->onKeyUp (keyCode); - } - - return result; -} - //----------------------------------------------------------------------------- void CFrame::dispatchKeyboardEvent (KeyboardEvent& event) { -#if VSTGUI_ENABLE_DEPRECATED_METHODS - VstKeyCode vstKeyCode = toVstKeyCode (event); - int32_t result = 0; - if (event.type == EventType::KeyUp) - result = keyboardHooksOnKeyUp (vstKeyCode); - else - result = keyboardHooksOnKeyDown (vstKeyCode); - if (result != -1) - { - event.consumed = true; + dispatchKeyboardEventToHooks (event); + if (event.consumed) return; - } -#endif + if (pImpl->focusView) { CBaseObjectGuard og (pImpl->focusView); @@ -1552,29 +1473,14 @@ void CFrame::unregisterKeyboardHook (IKeyboardHook* hook) } //----------------------------------------------------------------------------- -int32_t CFrame::keyboardHooksOnKeyDown (const VstKeyCode& key) +void CFrame::dispatchKeyboardEventToHooks (KeyboardEvent& event) { - int32_t result = -1; - pImpl->keyboardHooks.forEachReverse ([&] (IKeyboardHook* hook) { - if (result <= 0) - { - result = hook->onKeyDown (key, this); - } - }); - return result; -} - -//----------------------------------------------------------------------------- -int32_t CFrame::keyboardHooksOnKeyUp (const VstKeyCode& key) -{ - int32_t result = -1; - pImpl->keyboardHooks.forEachReverse ([&] (IKeyboardHook* hook) { - if (result <= 0) - { - result = hook->onKeyUp (key, this); - } - }); - return result; + pImpl->keyboardHooks.forEachReverse ( + [&] (IKeyboardHook* hook) { + hook->onKeyboardEvent (event, this); + return !event.consumed; + }, + [] (bool consumed) { return consumed; }); } //----------------------------------------------------------------------------- @@ -1802,26 +1708,6 @@ bool CFrame::platformOnDrop (DragEventData data) return getDropTarget ()->onDrop (data); } -//----------------------------------------------------------------------------- -bool CFrame::platformOnKeyDown (VstKeyCode& keyCode) -{ - if (!getMouseEnabled ()) - return false; - Impl::PostEventHandler peh (*pImpl); - CollectInvalidRects cir (this); - return onKeyDown (keyCode) == 1; -} - -//----------------------------------------------------------------------------- -bool CFrame::platformOnKeyUp (VstKeyCode& keyCode) -{ - if (!getMouseEnabled ()) - return false; - Impl::PostEventHandler peh (*pImpl); - CollectInvalidRects cir (this); - return onKeyUp (keyCode) == 1; -} - //----------------------------------------------------------------------------- void CFrame::platformOnActivate (bool state) { diff --git a/vstgui/lib/cframe.h b/vstgui/lib/cframe.h index aed8e1ac7..a3d56474e 100644 --- a/vstgui/lib/cframe.h +++ b/vstgui/lib/cframe.h @@ -214,8 +214,6 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override; - int32_t onKeyDown (VstKeyCode& keyCode) override; - int32_t onKeyUp (VstKeyCode& keyCode) override; void setViewSize (const CRect& rect, bool invalid = true) override; VSTGUIEditorInterface* getEditor () const override; @@ -242,8 +240,7 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback void setCollectInvalidRects (CollectInvalidRects* collectInvalidRects); // keyboard hooks - int32_t keyboardHooksOnKeyDown (const VstKeyCode& key); - int32_t keyboardHooksOnKeyUp (const VstKeyCode& key); + void dispatchKeyboardEventToHooks (KeyboardEvent& event); // mouse observers void callMouseObserverMouseEntered (CView* view); @@ -264,8 +261,6 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback DragOperation platformOnDragMove (DragEventData data) override; void platformOnDragLeave (DragEventData data) override; bool platformOnDrop (DragEventData data) override; - bool platformOnKeyDown (VstKeyCode& keyCode) override; - bool platformOnKeyUp (VstKeyCode& keyCode) override; void platformOnActivate (bool state) override; void platformOnWindowActivate (bool state) override; void platformScaleFactorChanged (double newScaleFactor) override; @@ -331,11 +326,9 @@ class IKeyboardHook { public: virtual ~IKeyboardHook () noexcept = default; - - /** should return 1 if no further key down processing should apply, otherwise -1 */ - virtual int32_t onKeyDown (const VstKeyCode& code, CFrame* frame) = 0; - /** should return 1 if no further key up processing should apply, otherwise -1 */ - virtual int32_t onKeyUp (const VstKeyCode& code, CFrame* frame) = 0; + + /** the event will not be dispatched further if it is consumed. */ + virtual void onKeyboardEvent (KeyboardEvent& event, CFrame* frame) = 0; }; //----------------------------------------------------------------------------- diff --git a/vstgui/lib/controls/ctextedit.cpp b/vstgui/lib/controls/ctextedit.cpp index b3320e67a..110467ea3 100644 --- a/vstgui/lib/controls/ctextedit.cpp +++ b/vstgui/lib/controls/ctextedit.cpp @@ -5,6 +5,7 @@ #include "ctextedit.h" #include "itexteditlistener.h" #include "../cframe.h" +#include "../events.h" #include "../platform/iplatformframe.h" #include @@ -296,21 +297,21 @@ void CTextEdit::platformLooseFocus (bool returnPressed) } //------------------------------------------------------------------------ -bool CTextEdit::platformOnKeyDown (const VstKeyCode& key) +void CTextEdit::platformOnKeyboardEvent (KeyboardEvent& event) { - if (dynamic_cast (getFrame ())->platformOnKeyDown (const_cast (key)) == 1) - return true; - if (key.virt == VKEY_RETURN) + dynamic_cast (getFrame ())->platformOnEvent (event); + if (event.consumed) + return; + if (event.virt == VirtualKey::Return) { platformLooseFocus (true); - return true; + event.consumed = true; } - else if (key.virt == VKEY_ESCAPE) + else if (event.virt == VirtualKey::Escape) { platformLooseFocus (false); - return true; + event.consumed = true; } - return false; } //------------------------------------------------------------------------ diff --git a/vstgui/lib/controls/ctextedit.h b/vstgui/lib/controls/ctextedit.h index a8f9a4421..05b11d821 100644 --- a/vstgui/lib/controls/ctextedit.h +++ b/vstgui/lib/controls/ctextedit.h @@ -104,7 +104,7 @@ class CTextEdit : public CTextLabel, public IPlatformTextEditCallback CRect platformGetVisibleSize () const override; CPoint platformGetTextInset () const override { return getTextInset (); } void platformLooseFocus (bool returnPressed) override; - bool platformOnKeyDown (const VstKeyCode& key) override; + void platformOnKeyboardEvent (KeyboardEvent& event) override; void platformTextDidChange () override; bool platformIsSecureTextEdit () override; diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index 0f37f0e78..3245b1df9 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -490,6 +490,7 @@ void CView::onMouseWheelEvent (MouseWheelEvent& event) void CView::onKeyboardEvent (KeyboardEvent& event) { #if VSTGUI_ENABLE_DEPRECATED_METHODS +#include "private/disabledeprecatedmessage.h" auto keyCode = toVstKeyCode (event); switch (event.type) @@ -513,6 +514,7 @@ void CView::onKeyboardEvent (KeyboardEvent& event) break; } } +#include "private/enbledeprecatedmessage.h" #endif } diff --git a/vstgui/lib/cview.h b/vstgui/lib/cview.h index acfaba6f0..6cc1eb865 100644 --- a/vstgui/lib/cview.h +++ b/vstgui/lib/cview.h @@ -158,10 +158,12 @@ class CView : public CBaseObject /// @name Keyboard Methods //----------------------------------------------------------------------------- //@{ + VSTGUI_DEPRECATED( /** called if a key down event occurs and this view has focus */ - virtual int32_t onKeyDown (VstKeyCode& keyCode); + virtual int32_t onKeyDown (VstKeyCode& keyCode);) + VSTGUI_DEPRECATED( /** called if a key up event occurs and this view has focus */ - virtual int32_t onKeyUp (VstKeyCode& keyCode); + virtual int32_t onKeyUp (VstKeyCode& keyCode);) //@} //----------------------------------------------------------------------------- diff --git a/vstgui/lib/platform/common/generictextedit.cpp b/vstgui/lib/platform/common/generictextedit.cpp index 37ed76ea6..247fcd295 100644 --- a/vstgui/lib/platform/common/generictextedit.cpp +++ b/vstgui/lib/platform/common/generictextedit.cpp @@ -13,6 +13,7 @@ #include "../../cframe.h" #include "../../cvstguitimer.h" #include "../../cdropsource.h" +#include "../../events.h" #include #include @@ -54,8 +55,7 @@ class STBTextEditView void drawBack (CDrawContext* pContext, CBitmap* newBack = nullptr) override; void setText (const UTF8String& txt) override; - int32_t onKeyDown (const VstKeyCode& code, CFrame* frame) override; - int32_t onKeyUp (const VstKeyCode& code, CFrame* frame) override; + void onKeyboardEvent (KeyboardEvent& event, CFrame* frame) override; void onMouseEntered (CView* view, CFrame* frame) override; void onMouseExited (CView* view, CFrame* frame) override; @@ -264,49 +264,54 @@ bool STBTextEditView::callSTB (Proc proc) } //----------------------------------------------------------------------------- -int32_t STBTextEditView::onKeyDown (const VstKeyCode& code, CFrame* frame) +void STBTextEditView::onKeyboardEvent (KeyboardEvent& event, CFrame* frame) { + if (event.type == EventType::KeyUp) + return; + if (isRecursiveKeyEventGuard ()) - return -1; + return; auto selfGuard = SharedPointer (this); BitScopeToggleT br (flags, BitRecursiveKeyGuard); - if (callback->platformOnKeyDown (code)) - return 1; + callback->platformOnKeyboardEvent (event); + if (event.consumed) + return; - if (code.character == 0 && code.virt == 0) - return -1; + if (event.character == 0 && event.virt == VirtualKey::None) + return; - if (code.modifier == MODIFIER_CONTROL) + if (event.modifiers.is (ModifierKey::Control)) { - switch (code.character) + switch (event.character) { case 'a': { selectAll (); - return 1; + event.consumed = true; + return; } case 'x': { if (doCut ()) - return 1; - return -1; + event.consumed = true; + return; } case 'c': { if (doCopy ()) - return 1; - return -1; + event.consumed = true; + return; } case 'v': { if (doPaste ()) - return 1; - return -1; + event.consumed = true; + return; } } } - auto key = code.character; + auto key = event.character; if (key) { if (auto text = getFrame ()->getPlatformFrame ()->convertCurrentKeyEventToText ()) @@ -316,44 +321,39 @@ int32_t STBTextEditView::onKeyDown (const VstKeyCode& code, CFrame* frame) key = tmp[0]; #else if (text->length () != 1) - return -1; + return; key = text->getString ()[0]; #endif } } - if (code.virt) + if (event.virt != VirtualKey::None) { - switch (code.virt) + switch (event.virt) { - case VKEY_SPACE: + case VirtualKey::Space: { key = 0x20; break; } - case VKEY_TAB: + case VirtualKey::Tab: { - return -1; + return; } default: { - key = code.virt | VIRTUAL_KEY_BIT; + key = static_cast (event.virt) | VIRTUAL_KEY_BIT; break; } } } - if (code.modifier & MODIFIER_CONTROL) + if (event.modifiers.has (ModifierKey::Control)) key |= STB_TEXTEDIT_K_CONTROL; - if (code.modifier & MODIFIER_ALTERNATE) + if (event.modifiers.has (ModifierKey::Alt)) key |= STB_TEXTEDIT_K_ALT; - if (code.modifier & MODIFIER_SHIFT) + if (event.modifiers.has (ModifierKey::Shift)) key |= STB_TEXTEDIT_K_SHIFT; - return callSTB ([&]() { stb_textedit_key (this, &editState, key); }) ? 1 : -1; -} - -//----------------------------------------------------------------------------- -int32_t STBTextEditView::onKeyUp (const VstKeyCode& code, CFrame* frame) -{ - return -1; + if (callSTB ([&]() { stb_textedit_key (this, &editState, key); })) + event.consumed = true; } //----------------------------------------------------------------------------- diff --git a/vstgui/lib/platform/iplatformframecallback.h b/vstgui/lib/platform/iplatformframecallback.h index dcb53514d..798e7f3b6 100644 --- a/vstgui/lib/platform/iplatformframecallback.h +++ b/vstgui/lib/platform/iplatformframecallback.h @@ -44,9 +44,6 @@ class IPlatformFrameCallback virtual void platformOnDragLeave (DragEventData data) = 0; virtual bool platformOnDrop (DragEventData data) = 0; - virtual bool platformOnKeyDown (VstKeyCode& keyCode) = 0; - virtual bool platformOnKeyUp (VstKeyCode& keyCode) = 0; - virtual void platformOnActivate (bool state) = 0; virtual void platformOnWindowActivate (bool state) = 0; diff --git a/vstgui/lib/platform/iplatformtextedit.h b/vstgui/lib/platform/iplatformtextedit.h index f34c28827..224ce2a1c 100644 --- a/vstgui/lib/platform/iplatformtextedit.h +++ b/vstgui/lib/platform/iplatformtextedit.h @@ -29,7 +29,7 @@ class IPlatformTextEditCallback virtual CRect platformGetVisibleSize () const = 0; virtual CPoint platformGetTextInset () const = 0; virtual void platformLooseFocus (bool returnPressed) = 0; - virtual bool platformOnKeyDown (const VstKeyCode& key) = 0; + virtual void platformOnKeyboardEvent (KeyboardEvent& event) = 0; virtual void platformTextDidChange () = 0; virtual bool platformIsSecureTextEdit () = 0; diff --git a/vstgui/lib/platform/mac/cocoa/cocoatextedit.mm b/vstgui/lib/platform/mac/cocoa/cocoatextedit.mm index b4ddc346f..92e49c915 100644 --- a/vstgui/lib/platform/mac/cocoa/cocoatextedit.mm +++ b/vstgui/lib/platform/mac/cocoa/cocoatextedit.mm @@ -10,7 +10,7 @@ #import "autoreleasepool.h" #import "../cfontmac.h" #import "../macstring.h" -#import "../../../vstkeycode.h" +#import "../../../events.h" using namespace VSTGUI; @@ -218,40 +218,40 @@ static BOOL VSTGUI_NSTextField_DoCommandBySelector (id self, SEL _cmd, NSControl IPlatformTextEditCallback* tec = te->getTextEdit (); if (commandSelector == @selector (insertNewline:)) { - VstKeyCode keyCode = {}; - keyCode.virt = VKEY_RETURN; - if (tec->platformOnKeyDown (keyCode)) - { + KeyboardEvent event; + event.type = EventType::KeyDown; + event.virt = VirtualKey::Return; + tec->platformOnKeyboardEvent (event); + if (event.consumed) return YES; - } } else if (commandSelector == @selector (insertTab:)) { - VstKeyCode keyCode = {}; - keyCode.virt = VKEY_TAB; - if (tec->platformOnKeyDown (keyCode)) - { + KeyboardEvent event; + event.type = EventType::KeyDown; + event.virt = VirtualKey::Tab; + tec->platformOnKeyboardEvent (event); + if (event.consumed) return YES; - } } else if (commandSelector == @selector (insertBacktab:)) { - VstKeyCode keyCode = {}; - keyCode.virt = VKEY_TAB; - keyCode.modifier = MODIFIER_SHIFT; - if (tec->platformOnKeyDown (keyCode)) - { + KeyboardEvent event; + event.type = EventType::KeyDown; + event.virt = VirtualKey::Tab; + event.modifiers.add (ModifierKey::Shift); + tec->platformOnKeyboardEvent (event); + if (event.consumed) return YES; - } } else if (commandSelector == @selector (cancelOperation:)) { - VstKeyCode keyCode = {}; - keyCode.virt = VKEY_ESCAPE; - if (tec->platformOnKeyDown (keyCode)) - { + KeyboardEvent event; + event.type = EventType::KeyDown; + event.virt = VirtualKey::Escape; + tec->platformOnKeyboardEvent (event); + if (event.consumed) return YES; - } } return NO; } diff --git a/vstgui/uidescription/editing/uidialogcontroller.cpp b/vstgui/uidescription/editing/uidialogcontroller.cpp index beff564a2..d4712dece 100644 --- a/vstgui/uidescription/editing/uidialogcontroller.cpp +++ b/vstgui/uidescription/editing/uidialogcontroller.cpp @@ -11,6 +11,7 @@ #include "../../lib/coffscreencontext.h" #include "../../lib/cbitmapfilter.h" #include "../../lib/clayeredviewcontainer.h" +#include "../../lib/events.h" #include "../../lib/controls/ctextlabel.h" #include "../../lib/controls/cbuttons.h" #include "../../lib/animation/animations.h" @@ -255,38 +256,31 @@ void UIDialogController::layoutButtons () } //---------------------------------------------------------------------------------------------------- -int32_t UIDialogController::onKeyDown (const VstKeyCode& code, CFrame* inFrame) +void UIDialogController::onKeyboardEvent (KeyboardEvent& event, CFrame* inFrame) { auto guard = shared (this); - int32_t result = -1; CView* focusView = inFrame->getFocusView (); if (focusView) - result = focusView->onKeyDown (const_cast (code)); - if (result == -1) { - if (code.virt == VKEY_RETURN && code.modifier == 0) + focusView->onKeyboardEvent (event); + if (event.consumed) + return; + } + if (event.type != EventType::KeyUp) + { + if (event.virt == VirtualKey::Return && event.modifiers.empty ()) { button1->setValue (button1->getMax ()); button1->valueChanged (); - return 1; + event.consumed = true; } - if (code.virt == VKEY_ESCAPE && code.modifier == 0 && button2->isVisible ()) + else if (event.virt == VirtualKey::Escape && event.modifiers.empty () && button2->isVisible ()) { button2->setValue (button2->getMax ()); button2->valueChanged (); - return 1; + event.consumed = true; } } - return result; -} - -//---------------------------------------------------------------------------------------------------- -int32_t UIDialogController::onKeyUp (const VstKeyCode& code, CFrame* inFrame) -{ - CView* focusView = inFrame->getFocusView (); - if (focusView) - return focusView->onKeyUp (const_cast (code)); - return -1; } //---------------------------------------------------------------------------------------------------- diff --git a/vstgui/uidescription/editing/uidialogcontroller.h b/vstgui/uidescription/editing/uidialogcontroller.h index 65c52a897..046d7fdb2 100644 --- a/vstgui/uidescription/editing/uidialogcontroller.h +++ b/vstgui/uidescription/editing/uidialogcontroller.h @@ -54,8 +54,7 @@ class UIDialogController : public NonAtomicReferenceCounted, void collectOpenGLViews (CViewContainer* container); void setOpenGLViewsVisible (bool state); - int32_t onKeyDown (const VstKeyCode& code, CFrame* frame) override; - int32_t onKeyUp (const VstKeyCode& code, CFrame* frame) override; + void onKeyboardEvent (KeyboardEvent& event, CFrame* frame) override; CFrame* frame; Optional modalSession; diff --git a/vstgui/uidescription/editing/uieditcontroller.cpp b/vstgui/uidescription/editing/uieditcontroller.cpp index fcc70a954..4be235fc2 100644 --- a/vstgui/uidescription/editing/uieditcontroller.cpp +++ b/vstgui/uidescription/editing/uieditcontroller.cpp @@ -37,6 +37,7 @@ #include "../../lib/coffscreencontext.h" #include "../../lib/iviewlistener.h" #include "../../lib/cvstguitimer.h" +#include "../../lib/events.h" #include #include @@ -1344,25 +1345,20 @@ void UIEditController::resetScrollViewOffsets (CViewContainer* view) } //---------------------------------------------------------------------------------------------------- -int32_t UIEditController::onKeyDown (const VstKeyCode& code, CFrame* frame) +void UIEditController::onKeyboardEvent (KeyboardEvent& event, CFrame* frame) { + if (event.type == EventType::KeyUp) + return; if (frame->getModalView () == nullptr) { if (frame->getFocusView ()) { auto* edit = dynamic_cast(frame->getFocusView ()); if (edit && edit->getPlatformTextEdit ()) - return -1; + return; } - return menuController->processKeyCommand (code); + menuController->processKeyCommand (event); } - return -1; -} - -//---------------------------------------------------------------------------------------------------- -int32_t UIEditController::onKeyUp (const VstKeyCode& code, CFrame* frame) -{ - return -1; } //---------------------------------------------------------------------------------------------------- diff --git a/vstgui/uidescription/editing/uieditcontroller.h b/vstgui/uidescription/editing/uieditcontroller.h index dca4c8680..58f2d9fa9 100644 --- a/vstgui/uidescription/editing/uieditcontroller.h +++ b/vstgui/uidescription/editing/uieditcontroller.h @@ -130,8 +130,7 @@ class UIEditController : public CBaseObject, void finishGroupAction () override; // IKeyboardHook - int32_t onKeyDown (const VstKeyCode& code, CFrame* frame) override; - int32_t onKeyUp (const VstKeyCode& code, CFrame* frame) override; + void onKeyboardEvent (KeyboardEvent& event, CFrame* frame) override; // CommandMenuItemTargetAdapter bool validateCommandMenuItem (CCommandMenuItem* item) override; diff --git a/vstgui/uidescription/editing/uieditmenucontroller.cpp b/vstgui/uidescription/editing/uieditmenucontroller.cpp index 8f62a37f8..464a971b6 100644 --- a/vstgui/uidescription/editing/uieditmenucontroller.cpp +++ b/vstgui/uidescription/editing/uieditmenucontroller.cpp @@ -12,6 +12,7 @@ #include "../uiviewfactory.h" #include "../uiattributes.h" #include "../../lib/cvstguitimer.h" +#include "../../lib/events.h" #include "../../lib/controls/coptionmenu.h" #include "../../lib/controls/ctextlabel.h" #include "../detail/uiviewcreatorattributes.h" @@ -372,14 +373,14 @@ bool UIEditMenuController::validateMenuItem (CCommandMenuItem& item) } //---------------------------------------------------------------------------------------------------- -CCommandMenuItem* UIEditMenuController::findKeyCommandItem (COptionMenu* menu, const VstKeyCode& key) +CCommandMenuItem* UIEditMenuController::findKeyCommandItem (COptionMenu* menu, const KeyboardEvent& event) { for (auto& item : *menu->getItems ()) { COptionMenu* subMenu = item->getSubmenu (); if (subMenu) { - CCommandMenuItem* result = findKeyCommandItem (subMenu, key); + CCommandMenuItem* result = findKeyCommandItem (subMenu, event); if (result) return result; } @@ -387,19 +388,19 @@ CCommandMenuItem* UIEditMenuController::findKeyCommandItem (COptionMenu* menu, c if (result) { int32_t modifier = 0; - if (key.modifier & MODIFIER_SHIFT) + if (event.modifiers.has (ModifierKey::Shift)) modifier |= kShift; - if (key.modifier & MODIFIER_ALTERNATE) + if (event.modifiers.has (ModifierKey::Alt)) modifier |= kAlt; - if (key.modifier & MODIFIER_CONTROL) + if (event.modifiers.has (ModifierKey::Control)) modifier |= kControl; - if (key.modifier & MODIFIER_COMMAND) + if (event.modifiers.has (ModifierKey::Super)) modifier |= kApple; if (result->getKeyModifiers () == modifier) { - if (key.virt && key.virt == result->getVirtualKeyCode ()) + if (event.virt != VirtualKey::None && toVstVirtualKey (event.virt) == result->getVirtualKeyCode ()) return result; - else if (!result->getKeycode ().empty () && result->getKeycode ().getString ()[0] == key.character) + else if (!result->getKeycode ().empty () && result->getKeycode ().getString ()[0] == event.character) return result; } } @@ -550,14 +551,14 @@ bool UIEditMenuController::canHandleCommand (const UTF8StringPtr category, const } //---------------------------------------------------------------------------------------------------- -int32_t UIEditMenuController::processKeyCommand (const VstKeyCode& key) +void UIEditMenuController::processKeyCommand (KeyboardEvent& event) { COptionMenu* baseMenu = editMenu; - CCommandMenuItem* item = baseMenu ? findKeyCommandItem (baseMenu, key) : nullptr; + CCommandMenuItem* item = baseMenu ? findKeyCommandItem (baseMenu, event) : nullptr; if (item == nullptr && fileMenu) { baseMenu = fileMenu; - item = findKeyCommandItem (baseMenu, key); + item = findKeyCommandItem (baseMenu, event); } if (item && item->getItemTarget ()) { @@ -590,10 +591,9 @@ int32_t UIEditMenuController::processKeyCommand (const VstKeyCode& key) { highlightTimer = makeOwned (this, 90u, true); } - return 1; + event.consumed = true; } } - return -1; } //---------------------------------------------------------------------------------------------------- diff --git a/vstgui/uidescription/editing/uieditmenucontroller.h b/vstgui/uidescription/editing/uieditmenucontroller.h index 6833c9455..d3ef1322c 100644 --- a/vstgui/uidescription/editing/uieditmenucontroller.h +++ b/vstgui/uidescription/editing/uieditmenucontroller.h @@ -150,7 +150,7 @@ class UIEditMenuController : public CBaseObject, public DelegationController, pu COptionMenu* getFileMenu () const { return fileMenu; } COptionMenu* getEditMenu () const { return editMenu; } - int32_t processKeyCommand (const VstKeyCode& key); + void processKeyCommand (KeyboardEvent& event); bool handleCommand (const UTF8StringPtr category, const UTF8StringPtr name); bool canHandleCommand (const UTF8StringPtr category, const UTF8StringPtr name) const; @@ -163,7 +163,7 @@ class UIEditMenuController : public CBaseObject, public DelegationController, pu bool onCommandMenuItemSelected (CCommandMenuItem* item) override; bool validateMenuItem (CCommandMenuItem& item); - CCommandMenuItem* findKeyCommandItem (COptionMenu* menu, const VstKeyCode& key); + CCommandMenuItem* findKeyCommandItem (COptionMenu* menu, const KeyboardEvent& event); void createEditMenu (COptionMenu* menu); void createFileMenu (COptionMenu* menu); From b1670cfa0168fc34aee66b3d2db8149e8d75b391 Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 12:15:33 +0200 Subject: [PATCH 027/319] use new onKeyboardEvent method for COptionMenu --- vstgui/lib/controls/coptionmenu.cpp | 22 +++++++++++++--------- vstgui/lib/controls/coptionmenu.h | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/vstgui/lib/controls/coptionmenu.cpp b/vstgui/lib/controls/coptionmenu.cpp index 042a62e26..2af12039e 100644 --- a/vstgui/lib/controls/coptionmenu.cpp +++ b/vstgui/lib/controls/coptionmenu.cpp @@ -6,6 +6,7 @@ #include "../cbitmap.h" #include "../cframe.h" #include "../cstring.h" +#include "../events.h" #include "../platform/iplatformoptionmenu.h" #include "../platform/iplatformframe.h" @@ -313,21 +314,22 @@ void COptionMenu::unregisterOptionMenuListener (IOptionMenuListener* listener) } //------------------------------------------------------------------------ -int32_t COptionMenu::onKeyDown (VstKeyCode& keyCode) +void COptionMenu::onKeyboardEvent (KeyboardEvent& event) { - if (keyCode.modifier == 0 && keyCode.character == 0) + if (event.type != EventType::KeyUp && event.modifiers.empty () && event.character == 0) { - if (keyCode.virt == VKEY_RETURN) + if (event.virt == VirtualKey::Return) { auto self = shared (this); getFrame ()->doAfterEventProcessing ([self] () { self->doPopup (); }); - return 1; + event.consumed = true; + return; } if (!(style & (kMultipleCheckStyle & ~kCheckStyle))) { - if (keyCode.virt == VKEY_UP) + if (event.virt == VirtualKey::Up) { int32_t value = (int32_t)getValue ()-1; if (value >= 0) @@ -345,9 +347,10 @@ int32_t COptionMenu::onKeyDown (VstKeyCode& keyCode) invalid (); } } - return 1; + event.consumed = true; + return; } - if (keyCode.virt == VKEY_DOWN) + if (event.virt == VirtualKey::Down) { int32_t value = (int32_t)getValue ()+1; if (value < getNbEntries ()) @@ -365,11 +368,12 @@ int32_t COptionMenu::onKeyDown (VstKeyCode& keyCode) invalid (); } } - return 1; + event.consumed = true; + return; } } } - return CParamDisplay::onKeyDown (keyCode); + CParamDisplay::onKeyboardEvent (event); } //------------------------------------------------------------------------ diff --git a/vstgui/lib/controls/coptionmenu.h b/vstgui/lib/controls/coptionmenu.h index 115bbd19a..de0aa36ae 100644 --- a/vstgui/lib/controls/coptionmenu.h +++ b/vstgui/lib/controls/coptionmenu.h @@ -312,7 +312,7 @@ class COptionMenu : public CParamDisplay void draw (CDrawContext* pContext) override; CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override; - int32_t onKeyDown (VstKeyCode& keyCode) override; + void onKeyboardEvent (KeyboardEvent& event) override; void takeFocus () override; void looseFocus () override; From 5c0af69f2371dead6c16f449477eb63195990cf8 Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 12:19:56 +0200 Subject: [PATCH 028/319] update to use new keyboard event methods in UIEditView --- vstgui/uidescription/editing/uieditview.cpp | 10 ++++++---- vstgui/uidescription/editing/uieditview.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/vstgui/uidescription/editing/uieditview.cpp b/vstgui/uidescription/editing/uieditview.cpp index 72f18dfe1..61da1703e 100644 --- a/vstgui/uidescription/editing/uieditview.cpp +++ b/vstgui/uidescription/editing/uieditview.cpp @@ -846,9 +846,10 @@ CMouseEventResult UIEditView::onMouseMoved (CPoint &where, const CButtonState& b } //------------------------------------------------------------------------ -int32_t UIEditView::onKeyDown (VstKeyCode& keyCode) +void UIEditView::onKeyboardEvent (KeyboardEvent& event) { - if (mouseEditMode != MouseEditMode::NoEditing && keyCode.virt == VKEY_ESCAPE) + if (mouseEditMode != MouseEditMode::NoEditing && event.virt == VirtualKey::Escape && + event.type == EventType::KeyDown) { if (lines) { @@ -863,9 +864,10 @@ int32_t UIEditView::onKeyDown (VstKeyCode& keyCode) } mouseEditMode = MouseEditMode::NoEditing; getFrame ()->setCursor (kCursorDefault); - return 1; + event.consumed = true; + return; } - return CViewContainer::onKeyDown (keyCode); + CViewContainer::onKeyboardEvent (event); } //----------------------------------------------------------------------------- diff --git a/vstgui/uidescription/editing/uieditview.h b/vstgui/uidescription/editing/uieditview.h index a42519aa7..90dac11af 100644 --- a/vstgui/uidescription/editing/uieditview.h +++ b/vstgui/uidescription/editing/uieditview.h @@ -84,7 +84,7 @@ class UIEditView : public CViewContainer, public IDropTarget CMouseEventResult onMouseMoved (CPoint &where, const CButtonState& buttons) override; CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override; CMessageResult notify (CBaseObject* sender, IdStringPtr message) override; - int32_t onKeyDown (VstKeyCode& keyCode) override; + void onKeyboardEvent (KeyboardEvent& event) override; std::vector findChildsInArea (CViewContainer* view, CRect r) const; From 55338332a03baeb002149db6bdb1ce56c7a5c855 Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 12:24:26 +0200 Subject: [PATCH 029/319] Simplify KeyDown and KeyRepeat handling --- vstgui/lib/cview.cpp | 4 +--- vstgui/lib/cviewcontainer.cpp | 1 - vstgui/lib/events.h | 14 ++++++-------- vstgui/lib/platform/mac/cocoa/cocoahelpers.mm | 5 ++--- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index 3245b1df9..fa2f5a349 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -495,8 +495,7 @@ void CView::onKeyboardEvent (KeyboardEvent& event) switch (event.type) { - case EventType::KeyDown: [[fallthrough]]; - case EventType::KeyRepeat: + case EventType::KeyDown: { if (onKeyDown (keyCode) == 1) event.consumed = true; @@ -541,7 +540,6 @@ void CView::dispatchEvent (Event& event) break; } case EventType::KeyUp: [[fallthrough]]; - case EventType::KeyRepeat: [[fallthrough]]; case EventType::KeyDown: { auto& keyEvent = castKeyboardEvent (event); diff --git a/vstgui/lib/cviewcontainer.cpp b/vstgui/lib/cviewcontainer.cpp index e43ea472b..beec522d4 100644 --- a/vstgui/lib/cviewcontainer.cpp +++ b/vstgui/lib/cviewcontainer.cpp @@ -1024,7 +1024,6 @@ void CViewContainer::dispatchEvent (Event& event) break; } case EventType::KeyUp: [[fallthrough]]; - case EventType::KeyRepeat: [[fallthrough]]; case EventType::KeyDown: { vstgui_assert (false); diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index 7cd39ed46..4db5edd93 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -23,7 +23,6 @@ enum class EventType : uint32_t { Unknown, KeyUp, - KeyRepeat, KeyDown, MouseWheel, ZoomGesture, @@ -260,6 +259,8 @@ struct KeyboardEvent : ModifierEvent uint32_t character {0}; /** virtual key */ VirtualKey virt {VirtualKey::None}; + /** indicates for a key down event if this is a repeated key down */ + bool isRepeat {false}; }; //------------------------------------------------------------------------ @@ -286,9 +287,8 @@ inline ModifierEvent* asModifierEvent (Event& event) { switch (event.type) { - case EventType::KeyDown: - case EventType::KeyRepeat: - case EventType::KeyUp: + case EventType::KeyDown: [[fallthrough]]; + case EventType::KeyUp: [[fallthrough]]; case EventType::MouseWheel: return static_cast (&event); default: break; @@ -304,8 +304,7 @@ inline KeyboardEvent* asKeyboardEvent (Event& event) { switch (event.type) { - case EventType::KeyDown: - case EventType::KeyRepeat: + case EventType::KeyDown: [[fallthrough]]; case EventType::KeyUp: return static_cast (&event); default: break; @@ -349,8 +348,7 @@ inline ZoomGestureEvent& castZoomGestureEvent (Event& event) */ inline KeyboardEvent& castKeyboardEvent (Event& event) { - vstgui_assert (event.type == EventType::KeyDown || event.type == EventType::KeyUp || - event.type == EventType::KeyRepeat); + vstgui_assert (event.type == EventType::KeyDown || event.type == EventType::KeyUp); return static_cast (event); } diff --git a/vstgui/lib/platform/mac/cocoa/cocoahelpers.mm b/vstgui/lib/platform/mac/cocoa/cocoahelpers.mm index f655c9858..6ddaa3f23 100644 --- a/vstgui/lib/platform/mac/cocoa/cocoahelpers.mm +++ b/vstgui/lib/platform/mac/cocoa/cocoahelpers.mm @@ -37,10 +37,9 @@ HIDDEN bool CreateKeyboardEventFromNSEvent (NSEvent* theEvent, KeyboardEvent& ev event.type = EventType::KeyUp; else if (theEvent.type == NSEventTypeKeyDown || theEvent.type == NSEventTypeFlagsChanged) { + event.type = EventType::KeyDown; if (theEvent.ARepeat) - event.type = EventType::KeyRepeat; - else - event.type = EventType::KeyDown; + event.isRepeat = true; } else return false; From ae1c2ef36ff8f384acfa9d2a8c21de45695cd780 Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 14:50:34 +0200 Subject: [PATCH 030/319] adopt unit tests --- vstgui/lib/cframe.h | 3 +- vstgui/tests/unittest/lib/cframe_test.cpp | 78 ++++++++++++++--------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/vstgui/lib/cframe.h b/vstgui/lib/cframe.h index a3d56474e..80b5edb3d 100644 --- a/vstgui/lib/cframe.h +++ b/vstgui/lib/cframe.h @@ -215,6 +215,7 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override; void setViewSize (const CRect& rect, bool invalid = true) override; + void dispatchEvent (Event& event) override; VSTGUIEditorInterface* getEditor () const override; IPlatformFrame* getPlatformFrame () const; @@ -232,8 +233,6 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback ~CFrame () noexcept override = default; void beforeDelete () override; - void dispatchEvent (Event& event) override; - void checkMouseViews (const CPoint& where, const CButtonState& buttons); void clearMouseViews (const CPoint& where, const CButtonState& buttons, bool callMouseExit = true); void removeFromMouseViews (CView* view); diff --git a/vstgui/tests/unittest/lib/cframe_test.cpp b/vstgui/tests/unittest/lib/cframe_test.cpp index 7f3ceb069..7e75308f7 100644 --- a/vstgui/tests/unittest/lib/cframe_test.cpp +++ b/vstgui/tests/unittest/lib/cframe_test.cpp @@ -4,6 +4,7 @@ #include "../../../lib/cframe.h" #include "../../../lib/ccolor.h" +#include "../../../lib/events.h" #include "../unittests.h" #include "platform_helper.h" #include @@ -93,18 +94,18 @@ class KeyboardHook : public IKeyboardHook bool keyDownCalled {false}; bool keyUpCalled {false}; - int32_t onKeyDown (const VstKeyCode& code, CFrame* frame) override + void onKeyboardEvent (KeyboardEvent& event, CFrame* frame) override { - keyDownCalled = true; - return -1; + if (event.type == EventType::KeyDown) + { + keyDownCalled = true; + } + else if (event.type == EventType::KeyUp) + { + keyUpCalled = true; + } + event.consumed = true; } - - int32_t onKeyUp (const VstKeyCode& code, CFrame* frame) override - { - keyUpCalled = true; - return -1; - } - }; class CollectInvalidRectView : public CView @@ -329,16 +330,20 @@ TESTCASE(CFrameTest, EXPECT (frame->getModalView () == nullptr); ); - TEST(onKeyDown, + TEST(keyDownEvent, auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr)); auto view = new View (); frame->addView (view); frame->attached (frame); frame->onActivate (true); - VstKeyCode key {}; - EXPECT (frame->onKeyDown (key) == -1); + KeyboardEvent event; + event.type = EventType::KeyDown; + frame->dispatchEvent (event); + EXPECT (event.consumed == false); frame->setFocusView (view); - EXPECT (frame->onKeyDown (key) == 1); + frame->dispatchEvent (event); + EXPECT (event.consumed == true); + event.consumed = false; EXPECT (view->onKeyDownCalled); frame->removeAll (); auto container = new Container (); @@ -346,31 +351,40 @@ TESTCASE(CFrameTest, container->addView (view2); frame->addView (container); frame->setFocusView (view2); - EXPECT (frame->onKeyDown (key) == 1); + frame->dispatchEvent (event); + EXPECT (event.consumed == true); + event.consumed = false; EXPECT (container->onKeyDownCalled); frame->setFocusView (nullptr); view2->setWantsFocus (true); EXPECT (frame->getFocusView () == nullptr); - key.virt = VKEY_TAB; - EXPECT (frame->onKeyDown (key) == 1); - EXPECT (frame->getFocusView() == view2); + event.virt = VirtualKey::Tab; + frame->dispatchEvent (event); + EXPECT (event.consumed == true); + event.consumed = false; + EXPECT (frame->getFocusView () == view2); auto view3 = shared (new View ()); auto modalSession = frame->beginModalViewSession (view3); - EXPECT (frame->onKeyDown (key) == 1); + frame->dispatchEvent (event); + EXPECT (event.consumed == true); EXPECT (view3->onKeyDownCalled); frame->endModalViewSession (*modalSession); ); - TEST(onKeyUp, + TEST(keyUpEvent, auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr)); auto view = new View (); frame->addView (view); frame->attached (frame); frame->onActivate (true); - VstKeyCode key {}; - EXPECT (frame->onKeyUp (key) == -1); + KeyboardEvent event; + event.type = EventType::KeyUp; + frame->dispatchEvent (event); + EXPECT (event.consumed == false); frame->setFocusView (view); - EXPECT (frame->onKeyUp (key) == 1); + frame->dispatchEvent (event); + EXPECT (event.consumed == true); + event.consumed = false; EXPECT (view->onKeyUpCalled); frame->removeAll (); auto container = new Container (); @@ -378,11 +392,14 @@ TESTCASE(CFrameTest, container->addView (view2); frame->addView (container); frame->setFocusView (view2); - EXPECT (frame->onKeyUp (key) == 1); + frame->dispatchEvent (event); + EXPECT (event.consumed == true); + event.consumed = false; EXPECT (container->onKeyUpCalled); auto view3 = shared (new View ()); auto modalSession = frame->beginModalViewSession (view3); - EXPECT (frame->onKeyUp (key) == 1); + frame->dispatchEvent (event); + EXPECT (event.consumed == true); EXPECT (view3->onKeyUpCalled); frame->endModalViewSession (*modalSession); ); @@ -558,12 +575,13 @@ TESTCASE(CFrameTest, auto frame = owned (new CFrame (CRect (0, 0, 100, 100), nullptr)); frame->attached (frame); frame->registerKeyboardHook (&hook); - - VstKeyCode key; - frame->onKeyDown (key); + KeyboardEvent event; + event.type = EventType::KeyDown; + frame->dispatchEvent (event); EXPECT (hook.keyDownCalled); EXPECT (hook.keyUpCalled == false); - frame->onKeyUp (key); + event.type = EventType::KeyUp; + frame->dispatchEvent (event); EXPECT (hook.keyUpCalled); frame->unregisterKeyboardHook (&hook); @@ -591,7 +609,7 @@ TESTCASE(CFrameTest, ); // TEST(collectInvalidRectsOnMouseDown, -// // It is expected that this test failes on Mac OS X 10.11 because of OS changes +// // It is expected that this test failes on Mac OS X 10.11 because of OS changes // auto platformHandle = UnitTest::PlatformParentHandle::create (); // auto frame = new CFrame (CRect (0, 0, 100, 100), nullptr); // auto view = new CollectInvalidRectView (); From 01b2c9c818fc73a237a22253d8ea1bf2ac26e212 Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 15:02:50 +0200 Subject: [PATCH 031/319] refactor win32 keyboard handling to use new event handling --- vstgui/lib/platform/win32/win32frame.cpp | 127 +++------------- vstgui/lib/platform/win32/win32support.cpp | 151 +++++++++++--------- vstgui/lib/platform/win32/win32support.h | 6 +- vstgui/lib/platform/win32/win32textedit.cpp | 7 +- 4 files changed, 108 insertions(+), 183 deletions(-) diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index 015856100..bbba129a7 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -607,70 +607,6 @@ void Win32Frame::paint (HWND hwnd) inPaint = false; } -static unsigned char translateWinVirtualKey (WPARAM winVKey) -{ - switch (winVKey) - { - case VK_BACK: return VKEY_BACK; - case VK_TAB: return VKEY_TAB; - case VK_CLEAR: return VKEY_CLEAR; - case VK_RETURN: return VKEY_RETURN; - case VK_PAUSE: return VKEY_PAUSE; - case VK_ESCAPE: return VKEY_ESCAPE; - case VK_SPACE: return VKEY_SPACE; -// TODO: case VK_NEXT: return VKEY_NEXT; - case VK_END: return VKEY_END; - case VK_HOME: return VKEY_HOME; - case VK_LEFT: return VKEY_LEFT; - case VK_RIGHT: return VKEY_RIGHT; - case VK_UP: return VKEY_UP; - case VK_DOWN: return VKEY_DOWN; - case VK_PRIOR: return VKEY_PAGEUP; - case VK_NEXT: return VKEY_PAGEDOWN; - case VK_SELECT: return VKEY_SELECT; - case VK_PRINT: return VKEY_PRINT; - case VK_SNAPSHOT: return VKEY_SNAPSHOT; - case VK_INSERT: return VKEY_INSERT; - case VK_DELETE: return VKEY_DELETE; - case VK_HELP: return VKEY_HELP; - case VK_NUMPAD0: return VKEY_NUMPAD0; - case VK_NUMPAD1: return VKEY_NUMPAD1; - case VK_NUMPAD2: return VKEY_NUMPAD2; - case VK_NUMPAD3: return VKEY_NUMPAD3; - case VK_NUMPAD4: return VKEY_NUMPAD4; - case VK_NUMPAD5: return VKEY_NUMPAD5; - case VK_NUMPAD6: return VKEY_NUMPAD6; - case VK_NUMPAD7: return VKEY_NUMPAD7; - case VK_NUMPAD8: return VKEY_NUMPAD8; - case VK_NUMPAD9: return VKEY_NUMPAD9; - case VK_MULTIPLY: return VKEY_MULTIPLY; - case VK_ADD: return VKEY_ADD; - case VK_SEPARATOR: return VKEY_SEPARATOR; - case VK_SUBTRACT: return VKEY_SUBTRACT; - case VK_DECIMAL: return VKEY_DECIMAL; - case VK_DIVIDE: return VKEY_DIVIDE; - case VK_F1: return VKEY_F1; - case VK_F2: return VKEY_F2; - case VK_F3: return VKEY_F3; - case VK_F4: return VKEY_F4; - case VK_F5: return VKEY_F5; - case VK_F6: return VKEY_F6; - case VK_F7: return VKEY_F7; - case VK_F8: return VKEY_F8; - case VK_F9: return VKEY_F9; - case VK_F10: return VKEY_F10; - case VK_F11: return VKEY_F11; - case VK_F12: return VKEY_F12; - case VK_NUMLOCK: return VKEY_NUMLOCK; - case VK_SCROLL: return VKEY_SCROLL; - case VK_SHIFT: return VKEY_SHIFT; - case VK_CONTROL: return VKEY_CONTROL; - case VK_MENU: return VKEY_ALT; - case VKEY_EQUALS: return VKEY_EQUALS; - } - return 0; -} - //----------------------------------------------------------------------------- LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -687,16 +623,7 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM case WM_MOUSEHWHEEL: // new since vista { MouseWheelEvent wheelEvent; - - CButtonState buttons = 0; - if (GetAsyncKeyState (VK_SHIFT) < 0) - wheelEvent.modifiers.add (ModifierKey::Shift); - if (GetAsyncKeyState (VK_CONTROL) < 0) - wheelEvent.modifiers.add (ModifierKey::Control); - if (GetAsyncKeyState (VK_MENU) < 0) - wheelEvent.modifiers.add (ModifierKey::Alt); - if (GetAsyncKeyState (VK_LWIN) < 0 || GetAsyncKeyState (VK_RWIN) < 0) - wheelEvent.modifiers.add (ModifierKey::Super); + updateModifiers (wheelEvent.modifiers); short zDelta = (short) GET_WHEEL_DELTA_WPARAM(wParam); POINT p {GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)}; @@ -844,52 +771,34 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM ReleaseCapture (); return 0; } + case WM_KEYUP: [[fallthrough]]; case WM_KEYDOWN: { - VstKeyCode key {}; - if (GetAsyncKeyState (VK_SHIFT) < 0) - key.modifier |= MODIFIER_SHIFT; - if (GetAsyncKeyState (VK_CONTROL) < 0) - key.modifier |= MODIFIER_CONTROL; - if (GetAsyncKeyState (VK_MENU) < 0) - key.modifier |= MODIFIER_ALTERNATE; - key.virt = translateWinVirtualKey (wParam); - key.character = MapVirtualKey (static_cast (wParam), MAPVK_VK_TO_CHAR); - if (key.virt || key.character) + KeyboardEvent keyEvent; + if (message == WM_KEYDOWN) { - key.character = std::tolower (key.character); - if (pFrame->platformOnKeyDown (key)) - return 0; + keyEvent.type = EventType::KeyDown; + if (lParam & 0xFFFF) + keyEvent.isRepeat = true; } + else + keyEvent.type = EventType::KeyUp; + updateModifiers (keyEvent.modifiers); - if (IsWindow (oldFocusWindow)) - { - auto oldProc = reinterpret_cast (GetWindowLongPtr (oldFocusWindow, GWLP_WNDPROC)); - if (oldProc && oldProc != WindowProc) - return CallWindowProc (oldProc, oldFocusWindow, message, wParam, lParam); - } - break; - } - case WM_KEYUP: - { - VstKeyCode key {}; - if (GetAsyncKeyState (VK_SHIFT) < 0) - key.modifier |= MODIFIER_SHIFT; - if (GetAsyncKeyState (VK_CONTROL) < 0) - key.modifier |= MODIFIER_CONTROL; - if (GetAsyncKeyState (VK_MENU) < 0) - key.modifier |= MODIFIER_ALTERNATE; - key.virt = translateWinVirtualKey (wParam); - key.character = MapVirtualKey (static_cast (wParam), MAPVK_VK_TO_CHAR); - if (key.virt || key.character) + keyEvent.virt = translateWinVirtualKey (wParam); + keyEvent.character = MapVirtualKey (static_cast (wParam), MAPVK_VK_TO_CHAR); + if (keyEvent.virt != VirtualKey::None || keyEvent.character) { - if (pFrame->platformOnKeyUp (key)) + keyEvent.character = std::tolower (keyEvent.character); + pFrame->platformOnEvent (keyEvent); + if (keyEvent.consumed) return 0; } if (IsWindow (oldFocusWindow)) { - auto oldProc = reinterpret_cast (GetWindowLongPtr (oldFocusWindow, GWLP_WNDPROC)); + auto oldProc = + reinterpret_cast (GetWindowLongPtr (oldFocusWindow, GWLP_WNDPROC)); if (oldProc && oldProc != WindowProc) return CallWindowProc (oldProc, oldFocusWindow, message, wParam, lParam); } diff --git a/vstgui/lib/platform/win32/win32support.cpp b/vstgui/lib/platform/win32/win32support.cpp index 47afe0687..8e865b9e8 100644 --- a/vstgui/lib/platform/win32/win32support.cpp +++ b/vstgui/lib/platform/win32/win32support.cpp @@ -6,7 +6,7 @@ #if WINDOWS -#include "../../vstkeycode.h" +#include "../../events.h" #include "../common/fileresourceinputstream.h" #include "../platform_win32.h" #include "win32factory.h" @@ -169,76 +169,91 @@ CDrawContext* createDrawContext (HWND window, HDC device, const CRect& surfaceRe //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- - -//----------------------------------------------------------------------------- -Optional keyMessageToKeyCode (WPARAM wParam, LPARAM lParam) +VirtualKey translateWinVirtualKey (WPARAM winVKey) { - static std::map vMap = { - {VK_BACK, VKEY_BACK}, - {VK_TAB, VKEY_TAB}, - {VK_CLEAR, VKEY_CLEAR}, - {VK_RETURN, VKEY_RETURN}, - {VK_PAUSE, VKEY_PAUSE}, - {VK_ESCAPE, VKEY_ESCAPE}, - {VK_SPACE, VKEY_SPACE}, - {VK_NEXT, VKEY_NEXT}, - {VK_END, VKEY_END}, - {VK_HOME, VKEY_HOME}, - {VK_LEFT, VKEY_LEFT}, - {VK_UP, VKEY_UP}, - {VK_RIGHT, VKEY_RIGHT}, - {VK_DOWN, VKEY_DOWN}, - // {VK_PAGEUP, VKEY_PAGEUP}, - // {VK_PAGEDOWN, VKEY_PAGEDOWN}, - {VK_SELECT, VKEY_SELECT}, - {VK_PRINT, VKEY_PRINT}, - // {VK_ENTER, VKEY_ENTER}, - {VK_SNAPSHOT, VKEY_SNAPSHOT}, - {VK_INSERT, VKEY_INSERT}, - {VK_DELETE, VKEY_DELETE}, - {VK_HELP, VKEY_HELP}, - {VK_NUMPAD0, VKEY_NUMPAD0}, - {VK_NUMPAD1, VKEY_NUMPAD1}, - {VK_NUMPAD2, VKEY_NUMPAD2}, - {VK_NUMPAD3, VKEY_NUMPAD3}, - {VK_NUMPAD4, VKEY_NUMPAD4}, - {VK_NUMPAD5, VKEY_NUMPAD5}, - {VK_NUMPAD6, VKEY_NUMPAD6}, - {VK_NUMPAD7, VKEY_NUMPAD7}, - {VK_NUMPAD8, VKEY_NUMPAD8}, - {VK_NUMPAD9, VKEY_NUMPAD9}, - {VK_MULTIPLY, VKEY_MULTIPLY}, - {VK_ADD, VKEY_ADD}, - {VK_SEPARATOR, VKEY_SEPARATOR}, - {VK_SUBTRACT, VKEY_SUBTRACT}, - {VK_DECIMAL, VKEY_DECIMAL}, - {VK_DIVIDE, VKEY_DIVIDE}, - {VK_F1, VKEY_F1}, - {VK_F2, VKEY_F2}, - {VK_F3, VKEY_F3}, - {VK_F4, VKEY_F4}, - {VK_F5, VKEY_F5}, - {VK_F6, VKEY_F6}, - {VK_F7, VKEY_F7}, - {VK_F8, VKEY_F8}, - {VK_F9, VKEY_F9}, - {VK_F10, VKEY_F10}, - {VK_F11, VKEY_F11}, - {VK_F12, VKEY_F12}, - {VK_NUMLOCK, VKEY_NUMLOCK}, - {VK_SCROLL, VKEY_SCROLL}, - {VK_SHIFT, VKEY_SHIFT}, - {VK_CONTROL, VKEY_CONTROL}, - // {VK_ALT, VKEY_ALT}, - {VK_OEM_NEC_EQUAL, VKEY_EQUALS} // TODO: verify - }; - auto it = vMap.find (wParam); - if (it != vMap.end ()) + switch (winVKey) { - VstKeyCode res {}; - res.virt = it->second; - return Optional (res); + case VK_BACK: return VirtualKey::Back; + case VK_TAB: return VirtualKey::Tab; + case VK_CLEAR: return VirtualKey::Clear; + case VK_RETURN: return VirtualKey::Return; + case VK_PAUSE: return VirtualKey::Pause; + case VK_ESCAPE: return VirtualKey::Escape; + case VK_SPACE: return VirtualKey::Space; +// TODO: case VK_NEXT: return VirtualKey::Next; + case VK_END: return VirtualKey::End; + case VK_HOME: return VirtualKey::Home; + case VK_LEFT: return VirtualKey::Left; + case VK_RIGHT: return VirtualKey::Right; + case VK_UP: return VirtualKey::Up; + case VK_DOWN: return VirtualKey::Down; + case VK_PRIOR: return VirtualKey::PageUp; + case VK_NEXT: return VirtualKey::PageDown; + case VK_SELECT: return VirtualKey::Select; + case VK_PRINT: return VirtualKey::Print; + case VK_SNAPSHOT: return VirtualKey::Snapshot; + case VK_INSERT: return VirtualKey::Insert; + case VK_DELETE: return VirtualKey::Delete; + case VK_HELP: return VirtualKey::Help; + case VK_NUMPAD0: return VirtualKey::NumPad0; + case VK_NUMPAD1: return VirtualKey::NumPad1; + case VK_NUMPAD2: return VirtualKey::NumPad2; + case VK_NUMPAD3: return VirtualKey::NumPad3; + case VK_NUMPAD4: return VirtualKey::NumPad4; + case VK_NUMPAD5: return VirtualKey::NumPad5; + case VK_NUMPAD6: return VirtualKey::NumPad6; + case VK_NUMPAD7: return VirtualKey::NumPad7; + case VK_NUMPAD8: return VirtualKey::NumPad8; + case VK_NUMPAD9: return VirtualKey::NumPad9; + case VK_MULTIPLY: return VirtualKey::Multiply; + case VK_ADD: return VirtualKey::Add; + case VK_SEPARATOR: return VirtualKey::Separator; + case VK_SUBTRACT: return VirtualKey::Subtract; + case VK_DECIMAL: return VirtualKey::Decimal; + case VK_DIVIDE: return VirtualKey::Divide; + case VK_F1: return VirtualKey::F1; + case VK_F2: return VirtualKey::F2; + case VK_F3: return VirtualKey::F3; + case VK_F4: return VirtualKey::F4; + case VK_F5: return VirtualKey::F5; + case VK_F6: return VirtualKey::F6; + case VK_F7: return VirtualKey::F7; + case VK_F8: return VirtualKey::F8; + case VK_F9: return VirtualKey::F9; + case VK_F10: return VirtualKey::F10; + case VK_F11: return VirtualKey::F11; + case VK_F12: return VirtualKey::F12; + case VK_NUMLOCK: return VirtualKey::NumLock; + case VK_SCROLL: return VirtualKey::Scroll; + case VK_SHIFT: return VirtualKey::ShiftModifier; + case VK_CONTROL: return VirtualKey::ControlModifier; + case VK_MENU: return VirtualKey::AltModifier; + case VK_OEM_PLUS: return VirtualKey::Equals; } + return VirtualKey::None; +} + +//----------------------------------------------------------------------------- +void updateModifiers (Modifiers& modifiers) +{ + if (GetAsyncKeyState (VK_SHIFT) < 0) + modifiers.add (ModifierKey::Shift); + if (GetAsyncKeyState (VK_CONTROL) < 0) + modifiers.add (ModifierKey::Control); + if (GetAsyncKeyState (VK_MENU) < 0) + modifiers.add (ModifierKey::Alt); + if (GetAsyncKeyState (VK_LWIN) < 0 || GetAsyncKeyState (VK_RWIN) < 0) + modifiers.add (ModifierKey::Super); +} + +//----------------------------------------------------------------------------- +Optional keyMessageToKeyboardEvent (WPARAM wParam, LPARAM lParam) +{ + KeyboardEvent event; + updateModifiers (event.modifiers); + event.virt = translateWinVirtualKey (wParam); + if (event.virt != VirtualKey::None) + return Optional (std::move (event)); return {}; } diff --git a/vstgui/lib/platform/win32/win32support.h b/vstgui/lib/platform/win32/win32support.h index 31666232a..c3363b30c 100644 --- a/vstgui/lib/platform/win32/win32support.h +++ b/vstgui/lib/platform/win32/win32support.h @@ -21,8 +21,6 @@ interface ID2D1Factory; interface IDWriteFactory; interface IWICImagingFactory; -struct VstKeyCode; - namespace VSTGUI { #define VSTGUI_STRCMP wcscmp @@ -42,7 +40,9 @@ extern void useD2D (); extern void unuseD2D (); extern IDWriteFactory* getDWriteFactory (); extern CDrawContext* createDrawContext (HWND window, HDC device, const CRect& surfaceRect); -extern Optional keyMessageToKeyCode (WPARAM wParam, LPARAM lParam); +extern VirtualKey translateWinVirtualKey (WPARAM winVKey); +extern void updateModifiers (Modifiers& modifiers); +extern Optional keyMessageToKeyboardEvent (WPARAM wParam, LPARAM lParam); class UTF8StringHelper { diff --git a/vstgui/lib/platform/win32/win32textedit.cpp b/vstgui/lib/platform/win32/win32textedit.cpp index 992470d4e..dec7d2272 100644 --- a/vstgui/lib/platform/win32/win32textedit.cpp +++ b/vstgui/lib/platform/win32/win32textedit.cpp @@ -8,7 +8,7 @@ #include "win32support.h" #include "direct2d/d2dfont.h" -#include "../../vstkeycode.h" +#include "../../events.h" namespace VSTGUI { @@ -200,10 +200,11 @@ LONG_PTR WINAPI Win32TextEdit::procEdit (HWND hwnd, UINT message, WPARAM wParam, { if (win32TextEdit->textEdit) { - if (auto keyCode = keyMessageToKeyCode (wParam, lParam)) + if (auto keyEvent = keyMessageToKeyboardEvent (wParam, lParam)) { + keyEvent->eventType = EventType::KeyDown; // for now only dispatch virtual keys - if (keyCode->character == 0 && win32TextEdit->textEdit->platformOnKeyDown (*keyCode)) + if (keyEvent->character == 0 && win32TextEdit->textEdit->platformOnKeyboardEvent (*keyEvent)) return 0; } } From b5b42800f7d8cd38a00621a9cac97f36308f96fc Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 15:25:05 +0200 Subject: [PATCH 032/319] fix errors --- vstgui/lib/events.h | 1 + vstgui/lib/platform/win32/win32textedit.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index 4db5edd93..64a38098c 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -36,6 +36,7 @@ struct Event { Event () noexcept; Event (const Event&) = delete; + Event (Event&&) = default; /** Type */ EventType type {EventType::Unknown}; diff --git a/vstgui/lib/platform/win32/win32textedit.cpp b/vstgui/lib/platform/win32/win32textedit.cpp index dec7d2272..41cabdb58 100644 --- a/vstgui/lib/platform/win32/win32textedit.cpp +++ b/vstgui/lib/platform/win32/win32textedit.cpp @@ -202,10 +202,14 @@ LONG_PTR WINAPI Win32TextEdit::procEdit (HWND hwnd, UINT message, WPARAM wParam, { if (auto keyEvent = keyMessageToKeyboardEvent (wParam, lParam)) { - keyEvent->eventType = EventType::KeyDown; + keyEvent->type = EventType::KeyDown; // for now only dispatch virtual keys - if (keyEvent->character == 0 && win32TextEdit->textEdit->platformOnKeyboardEvent (*keyEvent)) - return 0; + if (keyEvent->character == 0) + { + win32TextEdit->textEdit->platformOnKeyboardEvent (*keyEvent); + if (keyEvent->consumed) + return 0; + } } } break; From 4ea9425495e7da84ff9a378583b30b8c8a9344e2 Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 15:38:30 +0200 Subject: [PATCH 033/319] fix double float conversion warning --- vstgui/lib/controls/cknob.cpp | 4 ++-- vstgui/lib/controls/cscrollbar.cpp | 4 ++-- vstgui/lib/controls/cslider.cpp | 4 ++-- vstgui/lib/controls/cxypad.cpp | 12 ++++++------ vstgui/lib/cview.cpp | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/vstgui/lib/controls/cknob.cpp b/vstgui/lib/controls/cknob.cpp index d06356aa9..417158a39 100644 --- a/vstgui/lib/controls/cknob.cpp +++ b/vstgui/lib/controls/cknob.cpp @@ -239,9 +239,9 @@ void CKnobBase::onMouseWheelEvent (MouseWheelEvent& event) float v = getValueNormalized (); if (buttonStateFromEventModifiers (event.modifiers) & kZoomModifier) - v += 0.1f * event.deltaY * getWheelInc (); + v += 0.1f * static_cast (event.deltaY) * getWheelInc (); else - v += event.deltaY * getWheelInc (); + v += static_cast (event.deltaY) * getWheelInc (); setValueNormalized (v); if (isDirty ()) diff --git a/vstgui/lib/controls/cscrollbar.cpp b/vstgui/lib/controls/cscrollbar.cpp index 969525395..8737873ed 100644 --- a/vstgui/lib/controls/cscrollbar.cpp +++ b/vstgui/lib/controls/cscrollbar.cpp @@ -316,9 +316,9 @@ void CScrollbar::onMouseWheelEvent (MouseWheelEvent& event) float distance = 0.f; if (direction == kHorizontal) - distance = event.deltaX; + distance = static_cast (event.deltaX); else - distance = event.deltaY; + distance = static_cast (event.deltaY); if (distance == 0.f) return; diff --git a/vstgui/lib/controls/cslider.cpp b/vstgui/lib/controls/cslider.cpp index 98d547ae3..4ce6d477f 100644 --- a/vstgui/lib/controls/cslider.cpp +++ b/vstgui/lib/controls/cslider.cpp @@ -519,9 +519,9 @@ void CSliderBase::onMouseWheelEvent (MouseWheelEvent& event) distance *= -1.; float normValue = getValueNormalized (); if (buttonStateFromEventModifiers (event.modifiers) & kZoomModifier) - normValue += 0.1 * distance * getWheelInc (); + normValue += 0.1f * static_cast (distance) * getWheelInc (); else - normValue += distance * getWheelInc (); + normValue += static_cast (distance) * getWheelInc (); setValueNormalized (normValue); diff --git a/vstgui/lib/controls/cxypad.cpp b/vstgui/lib/controls/cxypad.cpp index 264548a2b..ae98ce62c 100644 --- a/vstgui/lib/controls/cxypad.cpp +++ b/vstgui/lib/controls/cxypad.cpp @@ -151,17 +151,17 @@ void CXYPad::onMouseWheelEvent (MouseWheelEvent& event) float x, y; calculateXY (getValue (), x, y); - auto distanceX = event.deltaX * getWheelInc (); - auto distanceY = event.deltaY * getWheelInc (); + auto distanceX = static_cast (event.deltaX) * getWheelInc (); + auto distanceY = static_cast (event.deltaY) * getWheelInc (); if (event.flags & MouseWheelEvent::DirectionInvertedFromDevice) { - distanceX *= -1.; - distanceY *= -1.; + distanceX *= -1.f; + distanceY *= -1.f; } if (event.modifiers.has (ModifierKey::Shift)) { - distanceX *= 0.1; - distanceY *= 0.1; + distanceX *= 0.1f; + distanceY *= 0.1f; } x += distanceX; y += distanceY; diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index fa2f5a349..34f9c6239 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -474,12 +474,12 @@ void CView::onMouseWheelEvent (MouseWheelEvent& event) buttons |= kMouseWheelInverted; if (event.deltaX != 0.) { - if (onWheel (event.mousePosition, kMouseWheelAxisX, event.deltaX, buttons)) + if (onWheel (event.mousePosition, kMouseWheelAxisX, static_cast (event.deltaX), buttons)) event.consumed = true; } if (event.deltaY != 0.) { - if (onWheel (event.mousePosition, kMouseWheelAxisY, event.deltaY, buttons)) + if (onWheel (event.mousePosition, kMouseWheelAxisY, static_cast (event.deltaY), buttons)) event.consumed = true; } #include "private/enbledeprecatedmessage.h" From b5244367a4c25a0a79d306ad9697174c3d2fe91a Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 15:38:58 +0200 Subject: [PATCH 034/319] fix deprecated warning messages --- vstgui/lib/cview.cpp | 2 ++ vstgui/lib/private/disabledeprecatedmessage.h | 5 +++-- vstgui/lib/private/enbledeprecatedmessage.h | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index 34f9c6239..a8c6db0b1 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -1094,7 +1094,9 @@ void CView::addAnimation (IdStringPtr name, Animation::IAnimationTarget* target, vstgui_assert (isAttached (), "to start an animation, the view needs to be attached"); if (auto frame = getFrame ()) { +#include "private/disabledeprecatedmessage.h" frame->getAnimator ()->addAnimation (this, name, target, timingFunction, notificationObject); +#include "private/enbledeprecatedmessage.h" } } #endif diff --git a/vstgui/lib/private/disabledeprecatedmessage.h b/vstgui/lib/private/disabledeprecatedmessage.h index ceab11557..46a4b4180 100644 --- a/vstgui/lib/private/disabledeprecatedmessage.h +++ b/vstgui/lib/private/disabledeprecatedmessage.h @@ -5,8 +5,9 @@ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated" -#elif _MSVC -#pragma warning(disabled : 4995) // deprecated +#elif _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4996) // deprecated #else #endif diff --git a/vstgui/lib/private/enbledeprecatedmessage.h b/vstgui/lib/private/enbledeprecatedmessage.h index 2257a4294..3fd235cce 100644 --- a/vstgui/lib/private/enbledeprecatedmessage.h +++ b/vstgui/lib/private/enbledeprecatedmessage.h @@ -4,8 +4,8 @@ #ifdef __clang__ #pragma clang diagnostic pop -#elif _MSVC -#pragma warning(3 : 4995) // deprecated +#elif _MSC_VER +#pragma warning(pop) #else #endif From 0ed7ef7a1bd37514ace31ad917a8a7e9ee3756f4 Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 17:21:48 +0200 Subject: [PATCH 035/319] implement convertCurrentKeyEventToText for win32 --- vstgui/lib/platform/win32/win32frame.cpp | 26 ++++++++++++++++++++++-- vstgui/lib/platform/win32/win32frame.h | 3 ++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index bbba129a7..ab52eb3f4 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -24,6 +24,7 @@ #include "../../cgradient.h" #include "../../cinvalidrectlist.h" #include "../../events.h" +#include "../../finally.h" #if VSTGUI_OPENGL_SUPPORT #include "win32openglview.h" @@ -616,7 +617,11 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM SharedPointer lifeGuard (this); IPlatformFrameCallback* pFrame = getFrame (); bool doubleClick = false; - + + auto oldEvent = std::move (currentEvent); + auto f = finally ([this, oldEvent = std::move (oldEvent)] () mutable { currentEvent = std::move (oldEvent); }); + currentEvent = Optional ({hwnd, message, wParam, lParam}); + switch (message) { case WM_MOUSEWHEEL: @@ -778,7 +783,8 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM if (message == WM_KEYDOWN) { keyEvent.type = EventType::KeyDown; - if (lParam & 0xFFFF) + auto repeatCount = (lParam & 0xFFFF); + if (repeatCount > 1) keyEvent.isRepeat = true; } else @@ -849,6 +855,22 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM return DefWindowProc (hwnd, message, wParam, lParam); } +//----------------------------------------------------------------------------- +Optional Win32Frame::convertCurrentKeyEventToText () +{ + if (currentEvent && currentEvent->message == WM_KEYDOWN) + { + MSG msg; + if (PeekMessage (&msg, windowHandle, WM_CHAR, WM_CHAR, PM_REMOVE | PM_NOYIELD)) + { + std::wstring wideStr (1, static_cast (msg.wParam)); + UTF8StringHelper helper (wideStr.data ()); + return Optional (UTF8String (helper.getUTF8String ())); + } + } + return {}; +} + //----------------------------------------------------------------------------- LONG_PTR WINAPI Win32Frame::WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { diff --git a/vstgui/lib/platform/win32/win32frame.h b/vstgui/lib/platform/win32/win32frame.h index 3a200aba6..cac50c2a1 100644 --- a/vstgui/lib/platform/win32/win32frame.h +++ b/vstgui/lib/platform/win32/win32frame.h @@ -52,7 +52,7 @@ class Win32Frame final : public IPlatformFrame, public IWin32PlatformFrame PlatformType getPlatformType () const override { return PlatformType::kHWND; } void onFrameClosed () override; - Optional convertCurrentKeyEventToText () override { return {}; } + Optional convertCurrentKeyEventToText () override; bool setupGenericOptionMenu (bool use, GenericOptionMenuTheme* theme = nullptr) override; LONG_PTR WINAPI proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); @@ -74,6 +74,7 @@ class Win32Frame final : public IPlatformFrame, public IWin32PlatformFrame SharedPointer backBuffer; CDrawContext* deviceContext; std::unique_ptr genericOptionMenuTheme; + Optional currentEvent; bool inPaint; bool mouseInside; From b715fbbecb13a032a74b683bc6c538cc3a1de291 Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 7 Apr 2021 21:50:23 +0200 Subject: [PATCH 036/319] adopt linux platform for event handling changes --- vstgui/lib/events.h | 35 ++++-- vstgui/lib/platform/linux/x11frame.cpp | 14 +-- vstgui/lib/platform/linux/x11platform.cpp | 134 +++++++++++----------- vstgui/lib/platform/linux/x11platform.h | 2 +- 4 files changed, 97 insertions(+), 88 deletions(-) diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index 64a38098c..dad91bf9f 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -36,7 +36,9 @@ struct Event { Event () noexcept; Event (const Event&) = delete; + Event& operator= (const Event&) = delete; Event (Event&&) = default; + Event& operator= (Event&&) = default; /** Type */ EventType type {EventType::Unknown}; @@ -56,9 +58,9 @@ struct Modifiers { Modifiers () = default; Modifiers (const Modifiers&) = default; - + /** test if no modifier key is set */ - bool empty () const { return data == 0;} + bool empty () const { return data == 0; } /** test if modifier key is set */ bool has (ModifierKey modifier) const { return data & cast (modifier); } /** test if modifier key is set exclusively */ @@ -139,13 +141,14 @@ struct MouseWheelEvent : MousePositionEvent //------------------------------------------------------------------------ struct GestureEvent : MousePositionEvent { - enum class Phase { + enum class Phase + { Unknown, Begin, Changed, End, }; - + Phase phase {Phase::Unknown}; }; @@ -246,7 +249,8 @@ enum class ModifierKey : uint32_t Alt = 1 << 1, /** the control key (Command key on macOS and control key on other platforms) */ Control = 1 << 2, - /** the super key (Control key on macOS, Windows key on Windows and Super key on other platforms)*/ + /** the super key (Control key on macOS, Windows key on Windows and Super key on other + platforms)*/ Super = 1 << 3, }; @@ -272,10 +276,12 @@ inline MousePositionEvent* asMousePositionEvent (Event& event) { switch (event.type) { - case EventType::ZoomGesture: [[fallthrough]]; + case EventType::ZoomGesture: + [[fallthrough]]; case EventType::MouseWheel: return static_cast (&event); - default: break; + default: + break; } return nullptr; } @@ -288,11 +294,14 @@ inline ModifierEvent* asModifierEvent (Event& event) { switch (event.type) { - case EventType::KeyDown: [[fallthrough]]; - case EventType::KeyUp: [[fallthrough]]; + case EventType::KeyDown: + [[fallthrough]]; + case EventType::KeyUp: + [[fallthrough]]; case EventType::MouseWheel: return static_cast (&event); - default: break; + default: + break; } return nullptr; } @@ -305,10 +314,12 @@ inline KeyboardEvent* asKeyboardEvent (Event& event) { switch (event.type) { - case EventType::KeyDown: [[fallthrough]]; + case EventType::KeyDown: + [[fallthrough]]; case EventType::KeyUp: return static_cast (&event); - default: break; + default: + break; } return nullptr; } diff --git a/vstgui/lib/platform/linux/x11frame.cpp b/vstgui/lib/platform/linux/x11frame.cpp index 410e46460..81c3320f9 100644 --- a/vstgui/lib/platform/linux/x11frame.cpp +++ b/vstgui/lib/platform/linux/x11frame.cpp @@ -11,7 +11,6 @@ #include "../../dragging.h" #include "../../vstkeycode.h" #include "../../cinvalidrectlist.h" -#include "../../events.h" #include "../iplatformopenglview.h" #include "../iplatformviewlayer.h" #include "../iplatformtextedit.h" @@ -35,6 +34,8 @@ #undef None #endif +#include "../../events.h" + //------------------------------------------------------------------------ namespace VSTGUI { namespace X11 { @@ -379,15 +380,8 @@ struct Frame::Impl : IFrameEventHandler void onEvent (xcb_key_press_event_t& event) override { auto type = (event.response_type & ~0x80); - auto keyCode = RunLoop::instance ().getCurrentKeyEvent (); - if (type == XCB_KEY_PRESS) - { - frame->platformOnKeyDown (keyCode); - } - else - { - frame->platformOnKeyUp (keyCode); - } + auto keyEvent = RunLoop::instance ().getCurrentKeyEvent (); + frame->platformOnEvent (keyEvent); } //------------------------------------------------------------------------ diff --git a/vstgui/lib/platform/linux/x11platform.cpp b/vstgui/lib/platform/linux/x11platform.cpp index 3f97857b5..4bb982236 100644 --- a/vstgui/lib/platform/linux/x11platform.cpp +++ b/vstgui/lib/platform/linux/x11platform.cpp @@ -6,6 +6,7 @@ #include "../../cfileselector.h" #include "../../cframe.h" #include "../../cstring.h" +#include "../../events.h" #include "x11frame.h" #include "x11dragging.h" #include "cairobitmap.h" @@ -31,6 +32,7 @@ #define explicit _explicit #include #undef explicit +#undef None //------------------------------------------------------------------------ namespace VSTGUI { @@ -41,63 +43,63 @@ namespace X11 { //------------------------------------------------------------------------ namespace { -using VirtMap = std::unordered_map; -const VirtMap keyMap = {{XKB_KEY_BackSpace, VKEY_BACK}, - {XKB_KEY_Tab, VKEY_TAB}, - {XKB_KEY_Clear, VKEY_CLEAR}, - {XKB_KEY_Return, VKEY_RETURN}, - {XKB_KEY_Pause, VKEY_PAUSE}, - {XKB_KEY_Escape, VKEY_ESCAPE}, - {XKB_KEY_space, VKEY_SPACE}, - {XKB_KEY_KP_Next, VKEY_NEXT}, - {XKB_KEY_End, VKEY_END}, - {XKB_KEY_Home, VKEY_HOME}, - - {XKB_KEY_Left, VKEY_LEFT}, - {XKB_KEY_Up, VKEY_UP}, - {XKB_KEY_Right, VKEY_RIGHT}, - {XKB_KEY_Down, VKEY_DOWN}, - {XKB_KEY_Page_Up, VKEY_PAGEUP}, - {XKB_KEY_Page_Down, VKEY_PAGEDOWN}, - {XKB_KEY_KP_Page_Up, VKEY_PAGEUP}, - {XKB_KEY_KP_Page_Down, VKEY_PAGEDOWN}, - - {XKB_KEY_Select, VKEY_SELECT}, - {XKB_KEY_Print, VKEY_PRINT}, - {XKB_KEY_KP_Enter, VKEY_ENTER}, - {XKB_KEY_Insert, VKEY_INSERT}, - {XKB_KEY_Delete, VKEY_DELETE}, - {XKB_KEY_Help, VKEY_HELP}, +using VirtMap = std::unordered_map; +const VirtMap keyMap = {{XKB_KEY_BackSpace, VirtualKey::Back}, + {XKB_KEY_Tab, VirtualKey::Tab}, + {XKB_KEY_Clear, VirtualKey::Clear}, + {XKB_KEY_Return, VirtualKey::Return}, + {XKB_KEY_Pause, VirtualKey::Pause}, + {XKB_KEY_Escape, VirtualKey::Escape}, + {XKB_KEY_space, VirtualKey::Space}, + {XKB_KEY_KP_Next, VirtualKey::Next}, + {XKB_KEY_End, VirtualKey::End}, + {XKB_KEY_Home, VirtualKey::Home}, + + {XKB_KEY_Left, VirtualKey::Left}, + {XKB_KEY_Up, VirtualKey::Up}, + {XKB_KEY_Right, VirtualKey::Right}, + {XKB_KEY_Down, VirtualKey::Down}, + {XKB_KEY_Page_Up, VirtualKey::PageUp}, + {XKB_KEY_Page_Down, VirtualKey::PageDown}, + {XKB_KEY_KP_Page_Up, VirtualKey::PageUp}, + {XKB_KEY_KP_Page_Down, VirtualKey::PageDown}, + + {XKB_KEY_Select, VirtualKey::Select}, + {XKB_KEY_Print, VirtualKey::Print}, + {XKB_KEY_KP_Enter, VirtualKey::Enter}, + {XKB_KEY_Insert, VirtualKey::Insert}, + {XKB_KEY_Delete, VirtualKey::Delete}, + {XKB_KEY_Help, VirtualKey::Help}, // Numpads ??? - {XKB_KEY_KP_Multiply, VKEY_MULTIPLY}, - {XKB_KEY_KP_Add, VKEY_ADD}, - {XKB_KEY_KP_Separator, VKEY_SEPARATOR}, - {XKB_KEY_KP_Subtract, VKEY_SUBTRACT}, - {XKB_KEY_KP_Decimal, VKEY_DECIMAL}, - {XKB_KEY_KP_Divide, VKEY_DIVIDE}, - {XKB_KEY_F1, VKEY_F1}, - {XKB_KEY_F2, VKEY_F2}, - {XKB_KEY_F3, VKEY_F3}, - {XKB_KEY_F4, VKEY_F4}, - {XKB_KEY_F5, VKEY_F5}, - {XKB_KEY_F6, VKEY_F6}, - {XKB_KEY_F7, VKEY_F7}, - {XKB_KEY_F8, VKEY_F8}, - {XKB_KEY_F9, VKEY_F9}, - {XKB_KEY_F10, VKEY_F10}, - {XKB_KEY_F11, VKEY_F11}, - {XKB_KEY_F12, VKEY_F12}, - {XKB_KEY_Num_Lock, VKEY_NUMLOCK}, - {XKB_KEY_Scroll_Lock, VKEY_SCROLL}, // correct ? + {XKB_KEY_KP_Multiply, VirtualKey::Multiply}, + {XKB_KEY_KP_Add, VirtualKey::Add}, + {XKB_KEY_KP_Separator, VirtualKey::Separator}, + {XKB_KEY_KP_Subtract, VirtualKey::Subtract}, + {XKB_KEY_KP_Decimal, VirtualKey::Decimal}, + {XKB_KEY_KP_Divide, VirtualKey::Divide}, + {XKB_KEY_F1, VirtualKey::F1}, + {XKB_KEY_F2, VirtualKey::F2}, + {XKB_KEY_F3, VirtualKey::F3}, + {XKB_KEY_F4, VirtualKey::F4}, + {XKB_KEY_F5, VirtualKey::F5}, + {XKB_KEY_F6, VirtualKey::F6}, + {XKB_KEY_F7, VirtualKey::F7}, + {XKB_KEY_F8, VirtualKey::F8}, + {XKB_KEY_F9, VirtualKey::F9}, + {XKB_KEY_F10, VirtualKey::F10}, + {XKB_KEY_F11, VirtualKey::F11}, + {XKB_KEY_F12, VirtualKey::F12}, + {XKB_KEY_Num_Lock, VirtualKey::NumLock}, + {XKB_KEY_Scroll_Lock, VirtualKey::Scroll}, // correct ? #if 0 - {XKB_KEY_Shift_L, VKEY_SHIFT}, - {XKB_KEY_Shift_R, VKEY_SHIFT}, - {XKB_KEY_Control_L, VKEY_CONTROL}, - {XKB_KEY_Control_R, VKEY_CONTROL}, - {XKB_KEY_Alt_L, VKEY_ALT}, - {XKB_KEY_Alt_R, VKEY_ALT}, + {XKB_KEY_Shift_L, VirtualKey::SHIFT}, + {XKB_KEY_Shift_R, VirtualKey::SHIFT}, + {XKB_KEY_Control_L, VirtualKey::CONTROL}, + {XKB_KEY_Control_R, VirtualKey::CONTROL}, + {XKB_KEY_Alt_L, VirtualKey::ALT}, + {XKB_KEY_Alt_R, VirtualKey::ALT}, #endif - {XKB_KEY_VoidSymbol, 0}}; + {XKB_KEY_VoidSymbol, VirtualKey::None}}; //------------------------------------------------------------------------ } // anonymous @@ -117,7 +119,7 @@ struct RunLoop::Impl : IEventHandler xkb_keymap* xkbKeymap {nullptr}; WindowEventHandlerMap windowEventHandlerMap; std::array cursors {{XCB_CURSOR_NONE}}; - VstKeyCode lastUnprocessedKeyEvent; + KeyboardEvent lastUnprocessedKeyEvent; uint32_t lastUtf32KeyEventChar {0}; void init (const SharedPointer& inRunLoop) @@ -199,7 +201,8 @@ struct RunLoop::Impl : IEventHandler xcb_window_t targetId = getXdndProxy (windowId); if (targetId != 0) it = windowEventHandlerMap.find (targetId); - if (it != windowEventHandlerMap.end ()) { + if (it != windowEventHandlerMap.end ()) + { it->second->onEvent (cmsg, windowId); return; } @@ -213,25 +216,26 @@ struct RunLoop::Impl : IEventHandler if (!xkbUnprocessedState) return; - VstKeyCode code {}; + KeyboardEvent keyEvent; + keyEvent.type = isKeyDown ? EventType::KeyDown : EventType::KeyUp; if (event.state & XCB_MOD_MASK_SHIFT) - code.modifier |= MODIFIER_SHIFT; + keyEvent.modifiers.add (ModifierKey::Shift); if (event.state & XCB_MOD_MASK_CONTROL) - code.modifier |= MODIFIER_CONTROL; + keyEvent.modifiers.add (ModifierKey::Control); if (event.state & (XCB_MOD_MASK_1 | XCB_MOD_MASK_5)) - code.modifier |= MODIFIER_ALTERNATE; + keyEvent.modifiers.add (ModifierKey::Alt); auto ksym = xkb_state_key_get_one_sym (xkbUnprocessedState, event.detail); auto it = keyMap.find (ksym); if (it != keyMap.end ()) - code.virt = it->second; + keyEvent.virt = it->second; else - code.character = xkb_keysym_to_utf32 (ksym); + keyEvent.character = xkb_keysym_to_utf32 (ksym); xkb_state_update_key (xkbState, event.detail, isKeyDown ? XKB_KEY_DOWN : XKB_KEY_UP); lastUtf32KeyEventChar = xkb_state_key_get_utf32 (xkbState, event.detail); - lastUnprocessedKeyEvent = code; + lastUnprocessedKeyEvent = std::move (keyEvent); } void onEvent () override @@ -490,9 +494,9 @@ uint32_t RunLoop::getCursorID (CCursorType cursor) } //------------------------------------------------------------------------ -VstKeyCode RunLoop::getCurrentKeyEvent () const +KeyboardEvent&& RunLoop::getCurrentKeyEvent () const { - return impl->lastUnprocessedKeyEvent; + return std::move (impl->lastUnprocessedKeyEvent); } //------------------------------------------------------------------------ diff --git a/vstgui/lib/platform/linux/x11platform.h b/vstgui/lib/platform/linux/x11platform.h index d9769c790..690f69fc7 100644 --- a/vstgui/lib/platform/linux/x11platform.h +++ b/vstgui/lib/platform/linux/x11platform.h @@ -59,7 +59,7 @@ struct RunLoop void unregisterWindowEventHandler (uint32_t windowId); uint32_t getCursorID (CCursorType cursor); - VstKeyCode getCurrentKeyEvent () const; + KeyboardEvent&& getCurrentKeyEvent () const; Optional convertCurrentKeyEventToText () const; static RunLoop& instance (); From e0acde7fef744eae9010713a0de2c4ad72712b4f Mon Sep 17 00:00:00 2001 From: scheffle Date: Sat, 24 Apr 2021 17:59:09 +0200 Subject: [PATCH 037/319] new mouse event handling --- vstgui/lib/cframe.cpp | 269 ++++++++++-------- vstgui/lib/cframe.h | 10 +- vstgui/lib/cview.cpp | 105 +++++++ vstgui/lib/cview.h | 14 +- vstgui/lib/cviewcontainer.cpp | 195 +++++++------ vstgui/lib/cviewcontainer.h | 11 +- vstgui/lib/events.h | 245 +++++++++++++++- vstgui/lib/platform/iplatformframecallback.h | 3 - vstgui/lib/platform/mac/cocoa/nsviewframe.mm | 81 ++++-- vstgui/lib/platform/win32/win32frame.cpp | 105 +++---- vstgui/lib/vstguifwd.h | 5 + .../standalone/resource/resources.uidesc | 2 +- .../examples/standalone/resource/test.uidesc | 12 +- vstgui/tests/unittest/lib/cframe_test.cpp | 91 +++--- vstgui/tests/unittest/lib/csplitview_test.cpp | 68 ++--- vstgui/tests/unittest/lib/cview_test.cpp | 9 +- .../unittest/lib/cviewcontainer_test.cpp | 58 ++-- vstgui/tests/unittest/unittests.cpp | 6 + vstgui/tests/unittest/unittests.h | 2 +- 19 files changed, 874 insertions(+), 417 deletions(-) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index 4a5734283..db651442e 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -4,6 +4,7 @@ #include "cframe.h" #include "events.h" +#include "finally.h" #include "coffscreencontext.h" #include "ctooltipsupport.h" #include "cinvalidrectlist.h" @@ -521,104 +522,9 @@ bool CFrame::hitTestSubViews (const CPoint& where, const CButtonState& buttons) return CViewContainer::hitTestSubViews (where, buttons); } -//----------------------------------------------------------------------------- -CMouseEventResult CFrame::onMouseDown (CPoint &where, const CButtonState& buttons) -{ - CPoint where2 (where); - getTransform ().inverse ().transform (where2); - - if (pImpl->tooltips) - pImpl->tooltips->onMouseDown (where2); - - CMouseEventResult result = callMouseObserverMouseDown (where, buttons); - if (result != kMouseEventNotHandled) - return result; - - // reset views - setMouseDownView (nullptr); - if (pImpl->focusView && dynamic_cast (pImpl->focusView)) - setFocusView (nullptr); - - if (auto modalView = getModalView ()) - { - CBaseObjectGuard rg (modalView); - - if (modalView->isVisible () && modalView->getMouseEnabled ()) - { - result = modalView->callMouseListener (MouseListenerCall::MouseDown, where2, buttons); - if (result == kMouseEventNotHandled || result == kMouseEventNotImplemented) - result = modalView->onMouseDown (where2, buttons); - if (result == kMouseEventHandled) - { - setMouseDownView (modalView); - return kMouseEventHandled; - } - return result; - } - } - else - return CViewContainer::onMouseDown (where, buttons); - return kMouseEventNotHandled; -} - -//----------------------------------------------------------------------------- -CMouseEventResult CFrame::onMouseUp (CPoint &where, const CButtonState& buttons) -{ - CMouseEventResult result = CViewContainer::onMouseUp (where, buttons); - CButtonState modifiers = buttons & (kShift | kControl | kAlt | kApple); - checkMouseViews (where, modifiers); - return result; -} - -//----------------------------------------------------------------------------- -CMouseEventResult CFrame::onMouseMoved (CPoint &where, const CButtonState& buttons) -{ - CPoint where2 (where); - getTransform ().inverse ().transform (where2); - - if (pImpl->tooltips) - pImpl->tooltips->onMouseMoved (where2); - - checkMouseViews (where, buttons); - - CMouseEventResult result = callMouseObserverMouseMoved (where, buttons); - if (result != kMouseEventNotHandled) - return result; - - if (auto modalView = getModalView ()) - { - CBaseObjectGuard rg (modalView); - result = modalView->callMouseListener (MouseListenerCall::MouseMoved, where2, buttons); - if (result == kMouseEventNotHandled || result == kMouseEventNotImplemented) - result = modalView->onMouseMoved (where2, buttons); - } - else - { - result = CViewContainer::onMouseMoved (where, buttons); - } - if (result == kMouseEventNotHandled) - { - CButtonState buttons2 = (buttons & (kShift | kControl | kAlt | kApple)); - auto it = pImpl->mouseViews.rbegin (); - while (it != pImpl->mouseViews.rend ()) - { - CPoint p (where2); - auto view = *it; - if (auto parent = view->getParentView ()) - parent->translateToLocal (p); - result = view->onMouseMoved (p, buttons2); - if (result == kMouseEventHandled) - break; - ++it; - } - } - return result; -} - //----------------------------------------------------------------------------- CMouseEventResult CFrame::onMouseExited (CPoint &where, const CButtonState& buttons) { // this should only get called from the platform implementation - if (getMouseDownView () == nullptr) { clearMouseViews (where, buttons); @@ -672,12 +578,153 @@ void CFrame::dispatchKeyboardEvent (KeyboardEvent& event) } } +//------------------------------------------------------------------------ +void CFrame::dispatchMouseDownEvent (MouseDownEvent& event) +{ + auto originMousePosition = event.mousePosition; + auto transformedMousePosition = event.mousePosition; + getTransform ().inverse ().transform (transformedMousePosition); + if (auto tooltips = pImpl->tooltips) + tooltips->onMouseDown (transformedMousePosition); + + auto buttonState = buttonStateFromMouseEvent (event); + + if (callMouseObserverMouseDown (event.mousePosition, buttonState) == kMouseEventHandled) + { + event.consumed = true; + return; + } + setMouseDownView (nullptr); + if (pImpl->focusView && dynamic_cast (pImpl->focusView)) + setFocusView (nullptr); + + if (auto modalView = shared (getModalView ())) + { + if (modalView->isVisible () && modalView->getMouseEnabled ()) + { + event.mousePosition = transformedMousePosition; + auto result = modalView->callMouseListener (MouseListenerCall::MouseDown, event.mousePosition, buttonState); + if (result != kMouseEventNotHandled && result != kMouseEventNotImplemented) + { + event.consumed = true; + return; + } + modalView->dispatchEvent (event); + if (event.consumed) + setMouseDownView (modalView); + } + return; + } + CView::dispatchEvent (event); +} + +//------------------------------------------------------------------------ +void CFrame::dispatchMouseMoveEvent (MouseMoveEvent& event) +{ + auto originMousePosition = event.mousePosition; + auto transformedMousePosition = event.mousePosition; + getTransform ().inverse ().transform (transformedMousePosition); + + if (auto tooltips = pImpl->tooltips) + tooltips->onMouseMoved (transformedMousePosition); + + auto buttonState = buttonStateFromMouseEvent (event); + checkMouseViews (originMousePosition, buttonState); + + if (callMouseObserverMouseMoved (event.mousePosition, buttonState) == kMouseEventHandled) + { + event.consumed = true; + return; + } + if (auto modalView = shared (getModalView ())) + { + if (modalView->isVisible () && modalView->getMouseEnabled ()) + { + event.mousePosition = transformedMousePosition; + auto result = modalView->callMouseListener (MouseListenerCall::MouseMoved, event.mousePosition, buttonState); + if (result != kMouseEventNotHandled && result != kMouseEventNotImplemented) + { + event.consumed = true; + return; + } + modalView->dispatchEvent (event); + } + return; + } + CView::dispatchEvent (event); + if (event.consumed == false) + { + event.buttonState.clear (); + auto it = pImpl->mouseViews.rbegin (); + while (it != pImpl->mouseViews.rend ()) + { + CPoint p (transformedMousePosition); + auto view = *it; + if (auto parent = view->getParentView ()) + parent->translateToLocal (p); + view->onMouseMoveEvent (event); + if (event.consumed) + break; + ++it; + } + } +} + +//------------------------------------------------------------------------ +void CFrame::dispatchMouseUpEvent (MouseUpEvent& event) +{ + auto originMousePosition = event.mousePosition; + auto transformedMousePosition = event.mousePosition; + getTransform ().inverse ().transform (transformedMousePosition); + + auto f = finally ([this] () { setMouseDownView (nullptr); }); + + auto buttonState = buttonStateFromMouseEvent (event); + if (auto modalView = shared (getModalView ())) + { + if (modalView->isVisible () && modalView->getMouseEnabled ()) + { + event.mousePosition = transformedMousePosition; + auto result = modalView->callMouseListener (MouseListenerCall::MouseUp, event.mousePosition, buttonState); + if (result != kMouseEventNotHandled && result != kMouseEventNotImplemented) + { + event.consumed = true; + return; + } + + modalView->dispatchEvent (event); + } + return; + } + CView::dispatchEvent (event); +} + +//------------------------------------------------------------------------ +void CFrame::dispatchMouseEvent (MouseEvent& event) +{ + if (event.type == EventType::MouseMove) + dispatchMouseMoveEvent (castMouseMoveEvent (event)); + else if (event.type == EventType::MouseDown) + dispatchMouseDownEvent (castMouseDownEvent (event)); + else if (event.type == EventType::MouseUp) + dispatchMouseUpEvent (castMouseUpEvent (event)); + else + { + vstgui_assert (false); + } +} + //----------------------------------------------------------------------------- void CFrame::dispatchEvent (Event& event) { Impl::PostEventHandler peh (*pImpl); CollectInvalidRects cir (this); + if (auto mouseEvent = asMouseEvent (event)) + { + dispatchMouseEvent (*mouseEvent); + return; + } if (auto keyEvent = asKeyboardEvent (event)) { dispatchKeyboardEvent (*keyEvent); @@ -696,7 +743,7 @@ void CFrame::dispatchEvent (Event& event) if (modalView) modalView->dispatchEvent (event); else - CViewContainer::dispatchEvent (event); + CView::dispatchEvent (event); if (mousePosEvent) { @@ -1624,36 +1671,6 @@ void CFrame::platformOnEvent (Event& event) dispatchEvent (event); } -//----------------------------------------------------------------------------- -CMouseEventResult CFrame::platformOnMouseDown (CPoint& where, const CButtonState& buttons) -{ - if (!getMouseEnabled ()) - return kMouseEventNotHandled; - Impl::PostEventHandler peh (*pImpl); - CollectInvalidRects cir (this); - return onMouseDown (where, buttons); -} - -//----------------------------------------------------------------------------- -CMouseEventResult CFrame::platformOnMouseMoved (CPoint& where, const CButtonState& buttons) -{ - if (!getMouseEnabled ()) - return kMouseEventNotHandled; - Impl::PostEventHandler peh (*pImpl); - CollectInvalidRects cir (this); - return onMouseMoved (where, buttons); -} - -//----------------------------------------------------------------------------- -CMouseEventResult CFrame::platformOnMouseUp (CPoint& where, const CButtonState& buttons) -{ - if (!getMouseEnabled ()) - return kMouseEventNotHandled; - Impl::PostEventHandler peh (*pImpl); - CollectInvalidRects cir (this); - return onMouseUp (where, buttons); -} - //----------------------------------------------------------------------------- CMouseEventResult CFrame::platformOnMouseExited (CPoint& where, const CButtonState& buttons) { diff --git a/vstgui/lib/cframe.h b/vstgui/lib/cframe.h index 80b5edb3d..97d2b272a 100644 --- a/vstgui/lib/cframe.h +++ b/vstgui/lib/cframe.h @@ -210,9 +210,6 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback bool attached (CView* parent) override; void draw (CDrawContext* pContext) override; void drawRect (CDrawContext* pContext, const CRect& updateRect) override; - CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override; - CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override; - CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override; void setViewSize (const CRect& rect, bool invalid = true) override; void dispatchEvent (Event& event) override; @@ -251,9 +248,6 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback // platform frame bool platformDrawRect (CDrawContext* context, const CRect& rect) override; - CMouseEventResult platformOnMouseDown (CPoint& where, const CButtonState& buttons) override; - CMouseEventResult platformOnMouseMoved (CPoint& where, const CButtonState& buttons) override; - CMouseEventResult platformOnMouseUp (CPoint& where, const CButtonState& buttons) override; CMouseEventResult platformOnMouseExited (CPoint& where, const CButtonState& buttons) override; void platformOnEvent (Event& event) override; DragOperation platformOnDragEnter (DragEventData data) override; @@ -274,6 +268,10 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback void initModalViewSession (const ModalViewSession& session); void clearModalViewSessions (); void dispatchKeyboardEvent (KeyboardEvent& event); + void dispatchMouseEvent (MouseEvent& event); + void dispatchMouseDownEvent (MouseDownEvent& event); + void dispatchMouseMoveEvent (MouseMoveEvent& event); + void dispatchMouseUpEvent (MouseUpEvent& event); struct Impl; Impl* pImpl {nullptr}; diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index a8c6db0b1..b5c73fe3f 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -464,6 +464,87 @@ bool CView::removed (CView* parent) return true; } +//------------------------------------------------------------------------ +void CView::onMouseDownEvent (MouseDownEvent& event) +{ + auto buttonState = buttonStateFromMouseEvent (event); + switch (onMouseDown (event.mousePosition, buttonState)) + { + case kMouseEventHandled: + { + event.consumed = true; + break; + } + case kMouseDownEventHandledButDontNeedMovedOrUpEvents: + { + event.consumed = true; + event.ignoreFollowUpMoveAndUpEvents (true); + break; + } + case kMouseEventNotHandled: [[fallthrough]]; + case kMouseEventNotImplemented: [[fallthrough]]; + case kMouseMoveEventHandledButDontNeedMoreEvents: break; + } +} + +//------------------------------------------------------------------------ +void CView::onMouseMoveEvent (MouseMoveEvent& event) +{ + auto buttonState = buttonStateFromMouseEvent (event); + switch (onMouseMoved (event.mousePosition, buttonState)) + { + case kMouseEventHandled: + { + event.consumed = true; + break; + } + case kMouseMoveEventHandledButDontNeedMoreEvents: + { + event.consumed = true; + event.ignoreFollowUpMoveAndUpEvents (true); + break; + } + case kMouseEventNotHandled: [[fallthrough]]; + case kMouseEventNotImplemented: [[fallthrough]]; + case kMouseDownEventHandledButDontNeedMovedOrUpEvents: break; + } +} + +//------------------------------------------------------------------------ +void CView::onMouseUpEvent (MouseUpEvent& event) +{ + auto buttonState = buttonStateFromMouseEvent (event); + switch (onMouseUp (event.mousePosition, buttonState)) + { + case kMouseEventHandled: + { + event.consumed = true; + break; + } + case kMouseDownEventHandledButDontNeedMovedOrUpEvents: [[fallthrough]]; + case kMouseEventNotHandled: [[fallthrough]]; + case kMouseEventNotImplemented: [[fallthrough]]; + case kMouseMoveEventHandledButDontNeedMoreEvents: break; + } +} + +//------------------------------------------------------------------------ +void CView::onMouseCancelEvent (MouseCancelEvent& event) +{ + switch (onMouseCancel ()) + { + case kMouseEventHandled: + { + event.consumed = true; + break; + } + case kMouseDownEventHandledButDontNeedMovedOrUpEvents: [[fallthrough]]; + case kMouseEventNotHandled: [[fallthrough]]; + case kMouseEventNotImplemented: [[fallthrough]]; + case kMouseMoveEventHandledButDontNeedMoreEvents: break; + } +} + //------------------------------------------------------------------------ void CView::onMouseWheelEvent (MouseWheelEvent& event) { @@ -527,6 +608,30 @@ void CView::dispatchEvent (Event& event) { switch (event.type) { + case EventType::MouseDown: + { + auto& mouseDownEvent = castMouseDownEvent (event); + onMouseDownEvent (mouseDownEvent); + break; + } + case EventType::MouseMove: + { + auto& mouseMoveEvent = castMouseMoveEvent (event); + onMouseMoveEvent (mouseMoveEvent); + break; + } + case EventType::MouseUp: + { + auto& mouseUpEvent = castMouseUpEvent (event); + onMouseUpEvent (mouseUpEvent); + break; + } + case EventType::MouseCancel: + { + auto& mouseCancelEvent = castMouseCancelEvent (event); + onMouseCancelEvent (mouseCancelEvent); + break; + } case EventType::MouseWheel: { auto& wheelEvent = castMouseWheelEvent (event); diff --git a/vstgui/lib/cview.h b/vstgui/lib/cview.h index 6cc1eb865..9ea12acd2 100644 --- a/vstgui/lib/cview.h +++ b/vstgui/lib/cview.h @@ -81,11 +81,23 @@ class CView : public CBaseObject bool isVisible () const { return hasViewFlag (kVisible) && getAlphaValue () > 0.f; } //@} + //----------------------------------------------------------------------------- + /// @name Event Handling Methods + //----------------------------------------------------------------------------- + //@{ + virtual void onMouseDownEvent (MouseDownEvent& event); + virtual void onMouseMoveEvent (MouseMoveEvent& event); + virtual void onMouseUpEvent (MouseUpEvent& event); + virtual void onMouseCancelEvent (MouseCancelEvent& event); + virtual void onMouseWheelEvent (MouseWheelEvent& event); - virtual void onKeyboardEvent (KeyboardEvent& event); virtual void onZoomGestureEvent (ZoomGestureEvent& event); + virtual void onKeyboardEvent (KeyboardEvent& event); + virtual void dispatchEvent (Event& event); + //@} + //----------------------------------------------------------------------------- /// @name Mouse Methods //----------------------------------------------------------------------------- diff --git a/vstgui/lib/cviewcontainer.cpp b/vstgui/lib/cviewcontainer.cpp index beec522d4..03537fa40 100644 --- a/vstgui/lib/cviewcontainer.cpp +++ b/vstgui/lib/cviewcontainer.cpp @@ -989,78 +989,90 @@ bool CViewContainer::onWheel (const CPoint& where, const CMouseWheelAxis& axis, #endif //------------------------------------------------------------------------ -void CViewContainer::dispatchEvent (Event& event) +void CViewContainer::dispatchEventToSubViews (Event& event) { - CView::dispatchEvent (event); - if (event.consumed) - return; - CPoint mousePos; - auto mouseEvent = asMousePositionEvent (event); - if (mouseEvent) + if (auto mouseEvent = asMousePositionEvent (event)) { - mousePos = mouseEvent->mousePosition; + auto mousePos = mouseEvent->mousePosition; + auto f = finally ([&] () { mouseEvent->mousePosition = mousePos; }); mouseEvent->mousePosition.offset (-getViewSize ().left, -getViewSize ().top); getTransform ().inverse ().transform (mouseEvent->mousePosition); - } - auto f = finally ([&] () { if (mouseEvent) mouseEvent->mousePosition = mousePos; }); - switch (event.type) - { - case EventType::ZoomGesture: - case EventType::MouseWheel: + for (auto it = pImpl->children.rbegin (), end = pImpl->children.rend (); it != end; + ++it) { - auto& mousePosEvent = castMousePositionEvent (event); - for (auto it = pImpl->children.rbegin (), end = pImpl->children.rend (); it != end; - ++it) + const auto& pV = *it; + if (pV && pV->isVisible () && pV->getMouseEnabled () && + pV->getMouseableArea ().pointInside (mouseEvent->mousePosition)) { - const auto& pV = *it; - if (pV && pV->isVisible () && pV->getMouseEnabled () && - pV->getMouseableArea ().pointInside (mousePosEvent.mousePosition)) - { - pV->dispatchEvent (event); - if (!pV->getTransparency () || event.consumed) - return; - } + pV->dispatchEvent (event); + if (!pV->getTransparency () || event.consumed) + return; } - break; } - case EventType::KeyUp: [[fallthrough]]; - case EventType::KeyDown: - { - vstgui_assert (false); - break; - } - default: break; } } -//----------------------------------------------------------------------------- -CMouseEventResult CViewContainer::onMouseDown (CPoint &where, const CButtonState& buttons) +//------------------------------------------------------------------------ +void CViewContainer::onMouseWheelEvent (MouseWheelEvent& event) { - // convert to relativ pos - CPoint where2 (where); - where2.offset (-getViewSize ().left, -getViewSize ().top); - getTransform ().inverse ().transform (where2); + dispatchEventToSubViews (event); +} + +//------------------------------------------------------------------------ +void CViewContainer::onZoomGestureEvent (ZoomGestureEvent& event) +{ + dispatchEventToSubViews (event); +} + +//------------------------------------------------------------------------ +void CViewContainer::onMouseDownEvent (MouseDownEvent& event) +{ + auto buttonState = buttonStateFromMouseEvent (event); + auto mouseResult = onMouseDown (event.mousePosition, buttonState); + if (!(mouseResult == kMouseEventNotHandled || mouseResult == kMouseEventNotImplemented)) + { + event.consumed = true; + if (mouseResult == kMouseMoveEventHandledButDontNeedMoreEvents) + event.ignoreFollowUpMoveAndUpEvents (true); + return; + } + auto f = finally ([&, pos = event.mousePosition] () { event.mousePosition = pos; }); + auto mousePos = event.mousePosition; + event.mousePosition.offset (-getViewSize ().left, -getViewSize ().top); + getTransform ().inverse ().transform (event.mousePosition); for (auto it = pImpl->children.rbegin (), end = pImpl->children.rend (); it != end; ++it) { - auto pV = *it; - if (pV && pV->isVisible () && pV->getMouseEnabled () && pV->hitTest (where2, buttons)) + const auto& pV = *it; + if (pV && pV->isVisible () && pV->getMouseEnabled () && + pV->hitTest (event.mousePosition, buttonState)) { - if (buttons & (kAlt | kShift | kControl | kApple | kRButton)) + if (!event.modifiers.empty ()) { - auto control = pV.cast (); - if (control && control->getListener ()) + if (auto control = pV.cast ()) { - if (control->getListener ()->controlModifierClicked (control, buttons) != 0) - return kMouseEventHandled; + if (auto listener = control->getListener ()) + { + if (listener->controlModifierClicked (control, buttonState) != 0) + { + event.consumed = true; + return; + } + } } } auto frame = getFrame (); auto previousFocusView = frame ? frame->getFocusView () : nullptr; - auto result = pV->callMouseListener (MouseListenerCall::MouseDown, where2, buttons); - if (result == kMouseEventNotHandled || result == kMouseEventNotImplemented) - result = pV->onMouseDown (where2, buttons); - if (result != kMouseEventNotHandled && result != kMouseEventNotImplemented) + mouseResult = pV->callMouseListener (MouseListenerCall::MouseDown, event.mousePosition, buttonState); + if (!(mouseResult == kMouseEventNotHandled || mouseResult == kMouseEventNotImplemented)) + { + event.consumed = true; + if (mouseResult == kMouseMoveEventHandledButDontNeedMoreEvents) + event.ignoreFollowUpMoveAndUpEvents (true); + return; + } + pV->dispatchEvent (event); + if (event.consumed) { if (pV->getNbReference () >1) { @@ -1069,59 +1081,72 @@ CMouseEventResult CViewContainer::onMouseDown (CPoint &where, const CButtonState { getFrame ()->setFocusView (pV); } - - if (result == kMouseEventHandled) + if (!event.ignoreFollowUpMoveAndUpEvents ()) setMouseDownView (pV); } - return result; + return; } if (!pV->getTransparency ()) - return result; + return; } } - return kMouseEventNotHandled; } -//----------------------------------------------------------------------------- -CMouseEventResult CViewContainer::onMouseUp (CPoint &where, const CButtonState& buttons) +//------------------------------------------------------------------------ +void CViewContainer::onMouseMoveEvent (MouseMoveEvent& event) { - if (auto view = getMouseDownView ()) + auto buttonState = buttonStateFromMouseEvent (event); + auto mouseResult = onMouseMoved (event.mousePosition, buttonState); + if (!(mouseResult == kMouseEventNotHandled || mouseResult == kMouseEventNotImplemented)) { - CBaseObjectGuard crg (view); - - CPoint where2 (where); - where2.offset (-getViewSize ().left, -getViewSize ().top); - getTransform ().inverse ().transform (where2); - auto mouseResult = view->callMouseListener (MouseListenerCall::MouseUp, where2, buttons); - if (mouseResult == kMouseEventNotHandled || mouseResult == kMouseEventNotImplemented) - view->onMouseUp (where2, buttons); - clearMouseDownView (); - return kMouseEventHandled; + event.consumed = true; + if (mouseResult == kMouseMoveEventHandledButDontNeedMoreEvents) + event.ignoreFollowUpMoveAndUpEvents (true); + return; + } + if (auto view = shared (getMouseDownView ())) + { + auto f = finally ([&, pos = event.mousePosition] () { event.mousePosition = pos; }); + event.mousePosition.offset (-getViewSize ().left, -getViewSize ().top); + getTransform ().inverse ().transform (event.mousePosition); + mouseResult = view->callMouseListener (MouseListenerCall::MouseMoved, event.mousePosition, + buttonState); + if (!(mouseResult == kMouseEventNotHandled || mouseResult == kMouseEventNotImplemented)) + { + event.consumed = true; + if (mouseResult == kMouseMoveEventHandledButDontNeedMoreEvents) + event.ignoreFollowUpMoveAndUpEvents (true); + return; + } + view->onMouseMoveEvent (event); } - return kMouseEventNotHandled; } -//----------------------------------------------------------------------------- -CMouseEventResult CViewContainer::onMouseMoved (CPoint &where, const CButtonState& buttons) +//------------------------------------------------------------------------ +void CViewContainer::onMouseUpEvent (MouseUpEvent& event) { - if (auto view = getMouseDownView ()) + auto buttonState = buttonStateFromMouseEvent (event); + auto mouseResult = onMouseUp (event.mousePosition, buttonState); + if (!(mouseResult == kMouseEventNotHandled || mouseResult == kMouseEventNotImplemented)) + { + event.consumed = true; + return; + } + if (auto view = shared (getMouseDownView ())) { - CBaseObjectGuard crg (view); - - CPoint where2 (where); - where2.offset (-getViewSize ().left, -getViewSize ().top); - getTransform ().inverse ().transform (where2); - auto mouseResult = view->callMouseListener (MouseListenerCall::MouseMoved, where2, buttons); - if (mouseResult == kMouseEventNotHandled || mouseResult == kMouseEventNotImplemented) - mouseResult = view->onMouseMoved (where2, buttons); - if (mouseResult != kMouseEventHandled && mouseResult != kMouseEventNotImplemented) + auto f = finally ([&, pos = event.mousePosition] () { event.mousePosition = pos; }); + event.mousePosition.offset (-getViewSize ().left, -getViewSize ().top); + getTransform ().inverse ().transform (event.mousePosition); + mouseResult = + view->callMouseListener (MouseListenerCall::MouseUp, event.mousePosition, buttonState); + if (!(mouseResult == kMouseEventNotHandled || mouseResult == kMouseEventNotImplemented)) { - clearMouseDownView (); - return kMouseEventNotHandled; + event.consumed = true; + return; } - return kMouseEventHandled; + view->onMouseUpEvent (event); + clearMouseDownView (); } - return kMouseEventNotHandled; } //----------------------------------------------------------------------------- diff --git a/vstgui/lib/cviewcontainer.h b/vstgui/lib/cviewcontainer.h index d8936492c..72e8db81d 100644 --- a/vstgui/lib/cviewcontainer.h +++ b/vstgui/lib/cviewcontainer.h @@ -136,10 +136,11 @@ class CViewContainer : public CView // CView void draw (CDrawContext* pContext) override; void drawRect (CDrawContext* pContext, const CRect& updateRect) override; - void dispatchEvent (Event& event) override; - CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override; - CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override; - CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; + void onMouseDownEvent (MouseDownEvent& event) override; + void onMouseMoveEvent (MouseMoveEvent& event) override; + void onMouseUpEvent (MouseUpEvent& event) override; + void onMouseWheelEvent (MouseWheelEvent& event) override; + void onZoomGestureEvent (ZoomGestureEvent& event) override; CMouseEventResult onMouseCancel () override; bool hitTest (const CPoint& where, const CButtonState& buttons = -1) override; CMessageResult notify (CBaseObject* sender, IdStringPtr message) override; @@ -253,6 +254,8 @@ class CViewContainer : public CView const ViewList& getChildren () const; private: + void dispatchEventToSubViews (Event& event); + void clearMouseDownView (); CRect getLastDrawnFocus () const; void setLastDrawnFocus (CRect r); diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index dad91bf9f..a038a9f39 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -22,10 +22,32 @@ namespace VSTGUI { enum class EventType : uint32_t { Unknown, - KeyUp, - KeyDown, + MouseDown, + MouseMove, + MouseUp, + MouseCancel, MouseWheel, ZoomGesture, + KeyUp, + KeyDown, +}; + +//------------------------------------------------------------------------ +struct EventConsumeState +{ + enum + { + NotHandled = 0, + Handled, + Last, + }; + + void operator= (bool state) { data = state ? Handled : NotHandled; } + operator bool () { return data & Handled; } + + void reset () { data = NotHandled; } + + uint32_t data {NotHandled}; }; //------------------------------------------------------------------------ @@ -47,7 +69,7 @@ struct Event /** Timestamp */ uint64_t timestamp; /** Consumed? If this is true, event dispatching is stopped. */ - bool consumed {false}; + EventConsumeState consumed; }; //------------------------------------------------------------------------ @@ -115,13 +137,123 @@ struct MousePositionEvent : ModifierEvent CPoint mousePosition; }; +//------------------------------------------------------------------------ +struct MouseEventButtonState +{ + enum Position : uint32_t + { + Left = 1 << 1, + Middle = 1 << 2, + Right = 1 << 3, + Fourth = 1 << 4, + Fifth = 1 << 5, + }; + + bool isLeft () const { return data == Left; } + bool isMiddle () const { return data == Middle; } + bool isRight () const { return data == Right; } + bool is (Position pos) const { return data == pos; } + bool isOther (uint32_t index) const { return data == (1 << index); } + bool has (Position pos) const { return data & pos; } + + void add (Position pos) { data |= pos; } + void set (Position pos) { data = pos; } + void clear () { data = 0; } + + MouseEventButtonState () = default; + MouseEventButtonState (Position pos) { set (pos); } +private: + uint32_t data {0}; +}; + +//------------------------------------------------------------------------ +/** MouseEvent + * @ingroup new_in_4_11 + */ +struct MouseEvent : MousePositionEvent +{ + MouseEventButtonState buttonState; + uint32_t clickCount {0}; +}; + +//------------------------------------------------------------------------ +/** MouseDownEvent + * @ingroup new_in_4_11 + */ +struct MouseDownEvent : MouseEvent +{ + MouseDownEvent () { type = EventType::MouseDown; } + MouseDownEvent (const CPoint& pos, MouseEventButtonState buttons) + : MouseDownEvent () + { + mousePosition = pos; + buttonState = buttons; + } + + void ignoreFollowUpMoveAndUpEvents (bool state) + { + if (state) + consumed.data |= IgnoreFollowUpEventsBit; + else + consumed.data &= ~IgnoreFollowUpEventsBit; + } + + bool ignoreFollowUpMoveAndUpEvents () + { + return consumed.data & IgnoreFollowUpEventsBit; + } + +protected: + enum + { + IgnoreFollowUpEvents = EventConsumeState::Last, + IgnoreFollowUpEventsBit = 1 << IgnoreFollowUpEvents + }; +}; + +//------------------------------------------------------------------------ +/** MouseMoveEvent + * @ingroup new_in_4_11 + */ +struct MouseMoveEvent : MouseDownEvent +{ + MouseMoveEvent () { type = EventType::MouseMove; } + MouseMoveEvent (const CPoint& pos, MouseEventButtonState buttons = {}) + : MouseMoveEvent () + { + mousePosition = pos; + buttonState = buttons; + } +}; + +//------------------------------------------------------------------------ +/** MouseUpEvent + * @ingroup new_in_4_11 + */ +struct MouseUpEvent : MouseEvent +{ + MouseUpEvent () { type = EventType::MouseUp; } + MouseUpEvent (const CPoint& pos, MouseEventButtonState buttons) + : MouseUpEvent () + { + mousePosition = pos; + buttonState = buttons; + } +}; + +//------------------------------------------------------------------------ +struct MouseCancelEvent : Event +{ + MouseCancelEvent () { type = EventType::MouseCancel; } +}; + //------------------------------------------------------------------------ /** MouseWheelEvent * @ingroup new_in_4_11 */ struct MouseWheelEvent : MousePositionEvent { - enum Flags + enum Flags : uint32_t { /** deltaX and deltaY are inverted */ DirectionInvertedFromDevice = 1 << 0, @@ -141,7 +273,7 @@ struct MouseWheelEvent : MousePositionEvent //------------------------------------------------------------------------ struct GestureEvent : MousePositionEvent { - enum class Phase + enum class Phase : uint32_t { Unknown, Begin, @@ -266,6 +398,8 @@ struct KeyboardEvent : ModifierEvent VirtualKey virt {VirtualKey::None}; /** indicates for a key down event if this is a repeated key down */ bool isRepeat {false}; + + KeyboardEvent (EventType t = EventType::KeyDown) { type = t; } }; //------------------------------------------------------------------------ @@ -279,6 +413,12 @@ inline MousePositionEvent* asMousePositionEvent (Event& event) case EventType::ZoomGesture: [[fallthrough]]; case EventType::MouseWheel: + [[fallthrough]]; + case EventType::MouseDown: + [[fallthrough]]; + case EventType::MouseMove: + [[fallthrough]]; + case EventType::MouseUp: return static_cast (&event); default: break; @@ -286,6 +426,26 @@ inline MousePositionEvent* asMousePositionEvent (Event& event) return nullptr; } +//------------------------------------------------------------------------ +/** event as mouse position event or nullpointer if not a mouse position event + * @ingroup new_in_4_11 + */ +inline MouseEvent* asMouseEvent (Event& event) +{ + switch (event.type) + { + case EventType::MouseDown: + [[fallthrough]]; + case EventType::MouseMove: + [[fallthrough]]; + case EventType::MouseUp: + return static_cast (&event); + default: + break; + } + return nullptr; +} + //------------------------------------------------------------------------ /** event as modifier event or nullpointer if not a modifier event * @ingroup new_in_4_11 @@ -299,6 +459,12 @@ inline ModifierEvent* asModifierEvent (Event& event) case EventType::KeyUp: [[fallthrough]]; case EventType::MouseWheel: + [[fallthrough]]; + case EventType::MouseDown: + [[fallthrough]]; + case EventType::MouseMove: + [[fallthrough]]; + case EventType::MouseUp: return static_cast (&event); default: break; @@ -330,10 +496,60 @@ inline KeyboardEvent* asKeyboardEvent (Event& event) */ inline MousePositionEvent& castMousePositionEvent (Event& event) { - vstgui_assert (event.type == EventType::MouseWheel || event.type == EventType::ZoomGesture); + vstgui_assert (event.type >= EventType::MouseDown && event.type <= EventType::ZoomGesture); return static_cast (event); } +//------------------------------------------------------------------------ +/** cast to a mouse event + * @ingroup new_in_4_11 + */ +inline MouseEvent& castMouseEvent (Event& event) +{ + vstgui_assert (event.type >= EventType::MouseDown && event.type <= EventType::MouseUp); + return static_cast (event); +} + +//------------------------------------------------------------------------ +/** cast to a mouse down event + * @ingroup new_in_4_11 + */ +inline MouseDownEvent& castMouseDownEvent (Event& event) +{ + vstgui_assert (event.type == EventType::MouseDown); + return static_cast (event); +} + +//------------------------------------------------------------------------ +/** cast to a mouse move event + * @ingroup new_in_4_11 + */ +inline MouseMoveEvent& castMouseMoveEvent (Event& event) +{ + vstgui_assert (event.type == EventType::MouseMove); + return static_cast (event); +} + +//------------------------------------------------------------------------ +/** cast to a mouse up event + * @ingroup new_in_4_11 + */ +inline MouseUpEvent& castMouseUpEvent (Event& event) +{ + vstgui_assert (event.type == EventType::MouseUp); + return static_cast (event); +} + +//------------------------------------------------------------------------ +/** cast to a mouse cancel event + * @ingroup new_in_4_11 + */ +inline MouseCancelEvent& castMouseCancelEvent (Event& event) +{ + vstgui_assert (event.type == EventType::MouseCancel); + return static_cast (event); +} + //------------------------------------------------------------------------ /** cast to a mouse wheel event * @ingroup new_in_4_11 @@ -380,6 +596,23 @@ inline CButtonState buttonStateFromEventModifiers (const Modifiers& mods) return state; } +//------------------------------------------------------------------------ +inline CButtonState buttonStateFromMouseEvent (const MouseEvent& event) +{ + CButtonState state = buttonStateFromEventModifiers (event.modifiers); + if (event.buttonState.has (MouseEventButtonState::Left)) + state |= kLButton; + if (event.buttonState.has (MouseEventButtonState::Right)) + state |= kRButton; + if (event.buttonState.has (MouseEventButtonState::Middle)) + state |= kMButton; + if (event.buttonState.has (MouseEventButtonState::Fourth)) + state |= kButton4; + if (event.buttonState.has (MouseEventButtonState::Fifth)) + state |= kButton5; + return state; +} + //------------------------------------------------------------------------ /** helper function to convert from new VirtualKey to old VstVirtualKey * diff --git a/vstgui/lib/platform/iplatformframecallback.h b/vstgui/lib/platform/iplatformframecallback.h index 798e7f3b6..9643a19f9 100644 --- a/vstgui/lib/platform/iplatformframecallback.h +++ b/vstgui/lib/platform/iplatformframecallback.h @@ -33,9 +33,6 @@ class IPlatformFrameCallback public: virtual bool platformDrawRect (CDrawContext* context, const CRect& rect) = 0; - virtual CMouseEventResult platformOnMouseDown (CPoint& where, const CButtonState& buttons) = 0; - virtual CMouseEventResult platformOnMouseMoved (CPoint& where, const CButtonState& buttons) = 0; - virtual CMouseEventResult platformOnMouseUp (CPoint& where, const CButtonState& buttons) = 0; virtual CMouseEventResult platformOnMouseExited (CPoint& where, const CButtonState& buttons) = 0; virtual void platformOnEvent (Event& event) = 0; diff --git a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm index 6b52c6911..1b741d3bf 100644 --- a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm +++ b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm @@ -421,12 +421,12 @@ static void VSTGUI_NSView_mouseEntered (id self, SEL _cmd, NSEvent* theEvent) IPlatformFrameCallback* _vstguiframe = getFrame (self); if (!_vstguiframe) return; - CButtonState buttons = 0; //eventButton (theEvent); - NSUInteger modifiers = [theEvent modifierFlags]; - CPoint p = pointFromNSPoint (getGlobalMouseLocation (self)); - mapModifiers (modifiers, buttons); - _vstguiframe->platformOnMouseMoved (p, buttons); + MouseMoveEvent event; + event.modifiers = modifiersFromModifierFlags (theEvent.modifierFlags); + event.mousePosition = pointFromNSPoint (getGlobalMouseLocation (self)); + + _vstguiframe->platformOnEvent (event); } //------------------------------------------------------------------------------------ @@ -940,8 +940,10 @@ static id VSTGUI_NSView_makeTouchbar (id self) if ([nsView hitTest:p]) { options |= NSTrackingAssumeInside; - CPoint cp = pointFromNSPoint (p); - frame->platformOnMouseMoved (cp, 0); + + MouseMoveEvent event; + event.mousePosition = pointFromNSPoint (p); + frame->platformOnEvent (event); } NSTrackingArea* trackingArea = [[[NSTrackingArea alloc] initWithRect:[nsView frame] options:options owner:nsView userInfo:nil] autorelease]; [nsView addTrackingArea: trackingArea]; @@ -1045,47 +1047,68 @@ static id VSTGUI_NSView_makeTouchbar (id self) inDraw = false; } +//------------------------------------------------------------------------ +static MouseEventButtonState buttonStateFromNSEvent (NSEvent* theEvent) +{ + MouseEventButtonState state; + switch (theEvent.buttonNumber) + { + case 0: + { + if (theEvent.modifierFlags & NSControlKeyMask) + state.add (MouseEventButtonState::Right); + else + state.add (MouseEventButtonState::Left); + break; + } + case 1: state.add (MouseEventButtonState::Right); break; + case 2: state.add (MouseEventButtonState::Middle); break; + case 3: state.add (MouseEventButtonState::Fourth); break; + case 4: state.add (MouseEventButtonState::Fifth); break; + } + return state; +} + //----------------------------------------------------------------------------- bool NSViewFrame::onMouseDown (NSEvent* theEvent) { - CButtonState buttons = eventButton (theEvent); - mouseDownButtonState = buttons.getButtonState (); - [nsView.window makeFirstResponder:nsView]; - NSUInteger modifiers = [theEvent modifierFlags]; + MouseDownEvent event; + event.buttonState = buttonStateFromNSEvent (theEvent); + event.modifiers = modifiersFromModifierFlags (theEvent.modifierFlags); + event.clickCount = theEvent.clickCount; NSPoint nsPoint = [theEvent locationInWindow]; nsPoint = [nsView convertPoint:nsPoint fromView:nil]; - mapModifiers (modifiers, buttons); - if ([theEvent clickCount] == 2) - buttons |= kDoubleClick; - CPoint p = pointFromNSPoint (nsPoint); - CMouseEventResult result = frame->platformOnMouseDown (p, buttons); - return (result != kMouseEventNotHandled) ? true : false; + event.mousePosition = pointFromNSPoint (nsPoint); + frame->platformOnEvent (event); + return event.consumed; } //----------------------------------------------------------------------------- bool NSViewFrame::onMouseUp (NSEvent* theEvent) { - CButtonState buttons = eventButton (theEvent); - NSUInteger modifiers = [theEvent modifierFlags]; - mapModifiers (modifiers, buttons); + MouseUpEvent event; + event.buttonState = buttonStateFromNSEvent (theEvent); + event.modifiers = modifiersFromModifierFlags (theEvent.modifierFlags); + event.clickCount = theEvent.clickCount; NSPoint nsPoint = [theEvent locationInWindow]; nsPoint = [nsView convertPoint:nsPoint fromView:nil]; - CPoint p = pointFromNSPoint (nsPoint); - CMouseEventResult result = frame->platformOnMouseUp (p, buttons); - return (result != kMouseEventNotHandled) ? true : false; + event.mousePosition = pointFromNSPoint (nsPoint); + frame->platformOnEvent (event); + return event.consumed; } //----------------------------------------------------------------------------- bool NSViewFrame::onMouseMoved (NSEvent* theEvent) { - NSUInteger modifiers = [theEvent modifierFlags]; - CButtonState buttons = theEvent.type == MacEventType::MouseMoved ? 0 : mouseDownButtonState; - mapModifiers (modifiers, buttons); + MouseMoveEvent event; + event.buttonState = buttonStateFromNSEvent (theEvent); + event.modifiers = modifiersFromModifierFlags (theEvent.modifierFlags); + event.clickCount = theEvent.clickCount; NSPoint nsPoint = [theEvent locationInWindow]; nsPoint = [nsView convertPoint:nsPoint fromView:nil]; - CPoint p = pointFromNSPoint (nsPoint); - CMouseEventResult result = frame->platformOnMouseMoved (p, buttons); - return (result != kMouseEventNotHandled) ? true : false; + event.mousePosition = pointFromNSPoint (nsPoint); + frame->platformOnEvent (event); + return event.consumed; } // IPlatformFrame diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index ab52eb3f4..ddf94c13d 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -608,6 +608,27 @@ void Win32Frame::paint (HWND hwnd) inPaint = false; } +//----------------------------------------------------------------------------- +static void setupMouseEventFromWParam (MouseEvent& event, WPARAM wParam) +{ + if (wParam & MK_LBUTTON) + event.buttonState.add (MouseEventButtonState::Left); + if (wParam & MK_RBUTTON) + event.buttonState.add (MouseEventButtonState::Right); + if (wParam & MK_MBUTTON) + event.buttonState.add (MouseEventButtonState::Middle); + if (wParam & MK_XBUTTON1) + event.buttonState.add (MouseEventButtonState::Fourth); + if (wParam & MK_XBUTTON2) + event.buttonState.add (MouseEventButtonState::Fifth); + if (wParam & MK_CONTROL) + event.modifiers.add (ModifierKey::Control); + if (wParam & MK_SHIFT) + event.modifiers.add (ModifierKey::Shift); + if (GetAsyncKeyState (VK_MENU) < 0) + event.modifiers.add (ModifierKey::Alt); +} + //----------------------------------------------------------------------------- LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -678,31 +699,17 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM case WM_LBUTTONDOWN: case WM_XBUTTONDOWN: { - CButtonState buttons = 0; - if (wParam & MK_LBUTTON) - buttons |= kLButton; - if (wParam & MK_RBUTTON) - buttons |= kRButton; - if (wParam & MK_MBUTTON) - buttons |= kMButton; - if (wParam & MK_XBUTTON1) - buttons |= kButton4; - if (wParam & MK_XBUTTON2) - buttons |= kButton5; - if (wParam & MK_CONTROL) - buttons |= kControl; - if (wParam & MK_SHIFT) - buttons |= kShift; - if (GetAsyncKeyState (VK_MENU) < 0) - buttons |= kAlt; - if (doubleClick) - buttons |= kDoubleClick; - HWND oldFocus = SetFocus(getPlatformWindow()); + MouseDownEvent event; + setupMouseEventFromWParam (event, wParam); + event.clickCount = doubleClick ? 2 : 1; + + HWND oldFocus = SetFocus (getPlatformWindow ()); if(oldFocus != hwnd) oldFocusWindow = oldFocus; - CPoint where (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); - if (pFrame->platformOnMouseDown (where, buttons) == kMouseEventHandled && getPlatformWindow ()) + event.mousePosition (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); + pFrame->platformOnEvent (event); + if (event.consumed && getPlatformWindow ()) SetCapture (getPlatformWindow ()); return 0; } @@ -718,23 +725,8 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM } case WM_MOUSEMOVE: { - CButtonState buttons = 0; - if (wParam & MK_LBUTTON) - buttons |= kLButton; - if (wParam & MK_RBUTTON) - buttons |= kRButton; - if (wParam & MK_MBUTTON) - buttons |= kMButton; - if (wParam & MK_XBUTTON1) - buttons |= kButton4; - if (wParam & MK_XBUTTON2) - buttons |= kButton5; - if (wParam & MK_CONTROL) - buttons |= kControl; - if (wParam & MK_SHIFT) - buttons |= kShift; - if (GetAsyncKeyState (VK_MENU) < 0) - buttons |= kAlt; + MouseMoveEvent event; + setupMouseEventFromWParam (event, wParam); if (!mouseInside) { // this makes sure that WM_MOUSELEAVE will be generated by the system @@ -745,8 +737,8 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM tme.hwndTrack = windowHandle; TrackMouseEvent (&tme); } - CPoint where (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); - pFrame->platformOnMouseMoved (where, buttons); + event.mousePosition (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); + pFrame->platformOnEvent (event); return 0; } case WM_LBUTTONUP: @@ -754,25 +746,18 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM case WM_MBUTTONUP: case WM_XBUTTONUP: { - CButtonState buttons = 0; - if (wParam & MK_LBUTTON || message == WM_LBUTTONUP) - buttons |= kLButton; - if (wParam & MK_RBUTTON || message == WM_RBUTTONUP) - buttons |= kRButton; - if (wParam & MK_MBUTTON || message == WM_MBUTTONUP) - buttons |= kMButton; - if (wParam & MK_XBUTTON1) - buttons |= kButton4; - if (wParam & MK_XBUTTON2) - buttons |= kButton5; - if (wParam & MK_CONTROL) - buttons |= kControl; - if (wParam & MK_SHIFT) - buttons |= kShift; - if (GetAsyncKeyState (VK_MENU) < 0) - buttons |= kAlt; - CPoint where (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); - pFrame->platformOnMouseUp (where, buttons); + MouseUpEvent event; + setupMouseEventFromWParam (event, wParam); + + if (message == WM_LBUTTONUP) + event.buttonState.add (MouseEventButtonState::Left); + else if (message == WM_RBUTTONUP) + event.buttonState.add (MouseEventButtonState::Right); + else if (message == WM_MBUTTONUP) + event.buttonState.add (MouseEventButtonState::Middle); + + event.mousePosition (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); + pFrame->platformOnEvent (event); ReleaseCapture (); return 0; } diff --git a/vstgui/lib/vstguifwd.h b/vstgui/lib/vstguifwd.h index dd3ecbdb6..f1c78c427 100644 --- a/vstgui/lib/vstguifwd.h +++ b/vstgui/lib/vstguifwd.h @@ -247,6 +247,11 @@ class CListControl; struct Event; struct ModifierEvent; struct MousePositionEvent; +struct MouseEvent; +struct MouseDownEvent; +struct MouseMoveEvent; +struct MouseUpEvent; +struct MouseCancelEvent; struct GestureEvent; struct MouseWheelEvent; struct ZoomGestureEvent; diff --git a/vstgui/standalone/examples/standalone/resource/resources.uidesc b/vstgui/standalone/examples/standalone/resource/resources.uidesc index 86eee7359..5e7d3b019 100644 --- a/vstgui/standalone/examples/standalone/resource/resources.uidesc +++ b/vstgui/standalone/examples/standalone/resource/resources.uidesc @@ -118,7 +118,7 @@ }, "custom": { "UIDescFilePath": { - "path": "/media/psf/Source/vstgui/vstgui/standalone/examples/standalone/resource/resources.uidesc" + "path": "/Users/scheffle/Source/vstgui/vstgui/standalone/examples/standalone/resource/resources.uidesc" } } } diff --git a/vstgui/standalone/examples/standalone/resource/test.uidesc b/vstgui/standalone/examples/standalone/resource/test.uidesc index 2944a5f20..aaff6c178 100644 --- a/vstgui/standalone/examples/standalone/resource/test.uidesc +++ b/vstgui/standalone/examples/standalone/resource/test.uidesc @@ -24,11 +24,11 @@ }, "UIEditController": { "EditViewScale": "1.5", - "EditorSize": "0, 0, 1158, 1005", - "SplitViewSize_0_0": "0.7436159346271705716802102870133239775896", - "SplitViewSize_0_1": "0.2359550561797752743498080008066608570516", - "SplitViewSize_1_0": "0.5842696629213482983900007639022078365088", - "SplitViewSize_1_1": "0.411644535240040854162657524284441024065", + "EditorSize": "0, 0, 1158, 997", + "SplitViewSize_0_0": "0.7415036045314109536263913469156250357628", + "SplitViewSize_0_1": "0.2378990731204943254173400646322988905013", + "SplitViewSize_1_0": "0.5849639546858907968029939183907117694616", + "SplitViewSize_1_1": "0.4109165808444902312501767482899595052004", "SplitViewSize_2_0": "0.6424870466321243034357735268713440746069", "SplitViewSize_2_1": "0.3531951640759931065893795221199980005622", "TabSwitchValue": "2", @@ -39,7 +39,7 @@ "SelectedRow": "24" }, "UIDescFilePath": { - "path": "/media/psf/Source/vstgui/vstgui/standalone/examples/standalone/resource/test.uidesc" + "path": "/Users/scheffle/Source/vstgui/vstgui/standalone/examples/standalone/resource/test.uidesc" }, "UITagsDataSource": { "SelectedRow": "-1" diff --git a/vstgui/tests/unittest/lib/cframe_test.cpp b/vstgui/tests/unittest/lib/cframe_test.cpp index 7e75308f7..1cba68caf 100644 --- a/vstgui/tests/unittest/lib/cframe_test.cpp +++ b/vstgui/tests/unittest/lib/cframe_test.cpp @@ -160,19 +160,22 @@ TESTCASE(CFrameTest, frame->addView (v1); frame->addView (v2); frame->attached (frame); - CPoint p (30, 30); - frame->onMouseMoved (p, 0); + MouseMoveEvent moveEvent; + moveEvent.mousePosition (30, 30); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size() == 0); EXPECT (observer.exitedViews.size() == 0); observer.reset(); - p (19, 19); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (19, 19); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT(observer.enteredViews.size () == 1); EXPECT(contains (observer.enteredViews, v2)); EXPECT(observer.exitedViews.size () == 0); observer.reset(); - p (9, 9); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (9, 9); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT(observer.enteredViews.size () == 1); EXPECT(contains (observer.enteredViews, v1)); EXPECT(observer.exitedViews.size () == 1); @@ -196,78 +199,90 @@ TESTCASE(CFrameTest, container2->addView (v1); container2->addView (v2); frame->attached (frame); - CPoint p (90, 90); - frame->onMouseMoved (p, 0); + MouseMoveEvent moveEvent; + moveEvent.mousePosition (90, 90); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 0); EXPECT (observer.exitedViews.size () == 0); observer.reset (); - p (79, 79); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (79, 79); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 1); EXPECT (contains (observer.enteredViews, container)); EXPECT (observer.exitedViews.size () == 0); observer.reset (); - p (49, 49); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (49, 49); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 1); EXPECT (contains (observer.enteredViews, container2)); EXPECT (observer.exitedViews.size () == 0); observer.reset (); - p (19, 19); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (19, 19); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 1); EXPECT (contains (observer.enteredViews, v2)); EXPECT (observer.exitedViews.size () == 0); observer.reset (); - p (18, 18); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (18, 18); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 0); EXPECT (observer.exitedViews.size () == 0); observer.reset (); - p (9, 9); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (9, 9); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 1); EXPECT (contains (observer.enteredViews, v1)); EXPECT (observer.exitedViews.size () == 1); EXPECT (contains (observer.exitedViews, v2)); observer.reset (); - p (51, 51); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (51, 51); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 0); EXPECT (observer.exitedViews.size () == 2); EXPECT (contains (observer.exitedViews, v1)); EXPECT (contains (observer.exitedViews, container2)); observer.reset (); - p (81, 81); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (81, 81); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 0); EXPECT (observer.exitedViews.size () == 1); EXPECT (contains (observer.exitedViews, container)); observer.reset (); - p (9, 9); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (9, 9); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 3); EXPECT (observer.exitedViews.size () == 0); EXPECT (contains (observer.enteredViews, container)); EXPECT (contains (observer.enteredViews, container2)); EXPECT (contains (observer.enteredViews, v1)); observer.reset (); - p (81, 81); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (81, 81); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 0); EXPECT (observer.exitedViews.size () == 3); EXPECT (contains (observer.exitedViews, container)); EXPECT (contains (observer.exitedViews, container2)); EXPECT (contains (observer.exitedViews, v1)); observer.reset (); - p (79, 79); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (79, 79); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 1); EXPECT (observer.exitedViews.size () == 0); EXPECT (contains (observer.enteredViews, container)); observer.reset (); - p (8, 8); - frame->onMouseMoved (p, 0); + moveEvent.mousePosition (8, 8); + moveEvent.consumed.reset (); + frame->dispatchEvent (moveEvent); EXPECT (observer.enteredViews.size () == 2); EXPECT (observer.exitedViews.size () == 0); EXPECT (contains (observer.enteredViews, container2)); @@ -284,8 +299,8 @@ TESTCASE(CFrameTest, auto v1 = new View (); frame->addView(v1); frame->attached (frame); - CPoint p (5, 5); - frame->onMouseMoved (p, 0); + MouseMoveEvent moveEvent (CPoint (5, 5)); + frame->dispatchEvent (moveEvent); EXPECT (contains (observer.enteredViews, v1)); observer.reset (); frame->removeView (v1); @@ -536,12 +551,14 @@ TESTCASE(CFrameTest, container->addView (view1); frame->attached (frame); auto modalSession = frame->beginModalViewSession (container); - - CPoint p (80, 80); - EXPECT (frame->onMouseDown (p, 0) == kMouseEventNotHandled); + MouseDownEvent downEvent (CPoint (80, 80), MouseEventButtonState (MouseEventButtonState::Left)); + frame->dispatchEvent (downEvent); + EXPECT (downEvent.consumed == false); EXPECT (view1->onMouseDownCalled == false); - p (1, 1); - EXPECT (frame->onMouseDown (p, 0) == kMouseEventHandled); + downEvent.consumed.reset (); + downEvent.mousePosition (1, 1); + frame->dispatchEvent (downEvent); + EXPECT (downEvent.consumed == true); EXPECT (view1->onMouseDownCalled); frame->endModalViewSession (*modalSession); diff --git a/vstgui/tests/unittest/lib/csplitview_test.cpp b/vstgui/tests/unittest/lib/csplitview_test.cpp index f3b5d7d53..d364611ca 100644 --- a/vstgui/tests/unittest/lib/csplitview_test.cpp +++ b/vstgui/tests/unittest/lib/csplitview_test.cpp @@ -4,6 +4,7 @@ #include "../unittests.h" #include "../../../lib/csplitview.h" +#include "../../../lib/events.h" #include "../../../uidescription/icontroller.h" #include @@ -276,25 +277,27 @@ TESTCASE(CSplitViewTests, sv->attached (container); EXPECT (view1->getViewSize () == CRect (0, 0, 20, 100)); EXPECT (view2->getViewSize () == CRect (30, 0, 100, 100)); - CPoint p (25, 1); - sv->onMouseDown (p, kLButton); - p (55, 1); - sv->onMouseMoved (p, kLButton); + + MouseDownEvent downEvent ({25, 1}, MouseEventButtonState::Left); + sv->onMouseDownEvent (downEvent); + MouseMoveEvent moveEvent ({55,1}, MouseEventButtonState::Left); + sv->onMouseMoveEvent (moveEvent); EXPECT (view1->getViewSize () == CRect (0, 0, 50, 100)); EXPECT (view2->getViewSize () == CRect (60, 0, 100, 100)); - p (65, 1); - sv->onMouseMoved (p, kLButton); + moveEvent.mousePosition (65, 1); + sv->onMouseMoveEvent (moveEvent); EXPECT (view1->getViewSize () == CRect (0, 0, 50, 100)); EXPECT (view2->getViewSize () == CRect (60, 0, 100, 100)); - p (15, 1); - sv->onMouseMoved (p, kLButton); + moveEvent.mousePosition (15, 1); + sv->onMouseMoveEvent (moveEvent); EXPECT (view1->getViewSize () == CRect (0, 0, 10, 100)); EXPECT (view2->getViewSize () == CRect (20, 0, 100, 100)); - p (1, 1); - sv->onMouseMoved (p, kLButton); + moveEvent.mousePosition (1, 1); + sv->onMouseMoveEvent (moveEvent); EXPECT (view1->getViewSize () == CRect (0, 0, 10, 100)); EXPECT (view2->getViewSize () == CRect (20, 0, 100, 100)); - sv->onMouseUp (p, kLButton); + MouseUpEvent upEvent (moveEvent.mousePosition, moveEvent.buttonState); + sv->onMouseUpEvent (upEvent); sv->removed (container); EXPECT(controller->sizes[0] == 10); @@ -315,25 +318,26 @@ TESTCASE(CSplitViewTests, sv->attached (container); EXPECT (view1->getViewSize () == CRect (0, 0, 100, 20)); EXPECT (view2->getViewSize () == CRect (0, 30, 100, 100)); - CPoint p (1, 25); - sv->onMouseDown (p, kLButton); - p (1, 55); - sv->onMouseMoved (p, kLButton); + MouseDownEvent downEvent ({1, 25}, MouseEventButtonState::Left); + sv->onMouseDownEvent (downEvent); + MouseMoveEvent moveEvent ({1,55}, MouseEventButtonState::Left); + sv->onMouseMoveEvent (moveEvent); EXPECT (view1->getViewSize () == CRect (0, 0, 100, 50)); EXPECT (view2->getViewSize () == CRect (0, 60, 100, 100)); - p (1, 65); - sv->onMouseMoved (p, kLButton); + moveEvent.mousePosition (1, 65); + sv->onMouseMoveEvent (moveEvent); EXPECT (view1->getViewSize () == CRect (0, 0, 100, 50)); EXPECT (view2->getViewSize () == CRect (0, 60, 100, 100)); - p (1, 15); - sv->onMouseMoved (p, kLButton); + moveEvent.mousePosition (1, 15); + sv->onMouseMoveEvent (moveEvent); EXPECT (view1->getViewSize () == CRect (0, 0, 100, 10)); EXPECT (view2->getViewSize () == CRect (00, 20, 100, 100)); - p (1, 1); - sv->onMouseMoved (p, kLButton); + moveEvent.mousePosition (1, 1); + sv->onMouseMoveEvent (moveEvent); EXPECT (view1->getViewSize () == CRect (0, 0, 100, 10)); EXPECT (view2->getViewSize () == CRect (0, 20, 100, 100)); - sv->onMouseUp (p, kLButton); + MouseUpEvent upEvent (moveEvent.mousePosition, moveEvent.buttonState); + sv->onMouseUpEvent (upEvent); sv->removed (container); EXPECT(controller->sizes[0] == 10); @@ -355,20 +359,20 @@ TESTCASE(CSplitViewTests, sepView->setMouseableArea (CRect (0, 0, 10, 10)); sv->addViewToSeparator (0, sepView); sv->attached (container); - CPoint p (41, 25); - sv->onMouseDown (p, kLButton); + MouseDownEvent downEvent ({41, 25}, MouseEventButtonState::Left); + sv->onMouseDownEvent (downEvent); EXPECT(sepView->mouseDownCalled == false); - p (41, 1); - sv->onMouseDown (p, kLButton); + downEvent.mousePosition (41, 1); + sv->onMouseDownEvent (downEvent); EXPECT(sepView->mouseDownCalled); - p (41, 3); - sv->onMouseMoved (p, kLButton); + MouseMoveEvent moveEvent ({41,3}, MouseEventButtonState::Left); + sv->onMouseMoveEvent (moveEvent); EXPECT(sepView->mouseMovedCalled); - p (41, 3); - sv->onMouseUp (p, kLButton); + MouseUpEvent upEvent ({41, 3}, MouseEventButtonState::Left); + sv->onMouseUpEvent (upEvent); EXPECT(sepView->mouseUpCalled); - p (41, 1); - sv->onMouseDown (p, kLButton); + downEvent.mousePosition (41, 1); + sv->onMouseDownEvent (downEvent); sv->onMouseCancel (); EXPECT(sepView->mouseCancelCalled); sv->removed (container); diff --git a/vstgui/tests/unittest/lib/cview_test.cpp b/vstgui/tests/unittest/lib/cview_test.cpp index bc71ccd16..fe35871fc 100644 --- a/vstgui/tests/unittest/lib/cview_test.cpp +++ b/vstgui/tests/unittest/lib/cview_test.cpp @@ -250,9 +250,12 @@ TESTCASE(CViewTest, TEST(defaultHandling, View v; - VstKeyCode key; - EXPECT(v.onKeyDown (key) == -1); - EXPECT(v.onKeyUp (key) == -1); + KeyboardEvent keyEvent; + v.dispatchEvent (keyEvent); + EXPECT(keyEvent.consumed == false); + keyEvent.type = EventType::KeyUp; + v.dispatchEvent (keyEvent); + EXPECT(keyEvent.consumed == false); MouseWheelEvent event; v.onMouseWheelEvent (event); EXPECT(event.consumed == false); diff --git a/vstgui/tests/unittest/lib/cviewcontainer_test.cpp b/vstgui/tests/unittest/lib/cviewcontainer_test.cpp index 0cec6b5ad..0947c262d 100644 --- a/vstgui/tests/unittest/lib/cviewcontainer_test.cpp +++ b/vstgui/tests/unittest/lib/cviewcontainer_test.cpp @@ -373,10 +373,18 @@ TESTCASE(CViewContainerTest, TEST(mouseEventsInEmptyContainer, CPoint p; - EXPECT(container->onMouseDown (p, kLButton) == kMouseEventNotHandled); - EXPECT(container->onMouseMoved (p, kLButton) == kMouseEventNotHandled); - EXPECT(container->onMouseUp (p, kLButton) == kMouseEventNotHandled); - EXPECT(container->onMouseCancel () == kMouseEventHandled); + MouseDownEvent downEvent; + container->dispatchEvent (downEvent); + EXPECT(downEvent.consumed == false); + MouseMoveEvent moveEvent; + container->dispatchEvent (moveEvent); + EXPECT(moveEvent.consumed == false); + MouseUpEvent upEvent; + container->dispatchEvent (upEvent); + EXPECT(upEvent.consumed == false); + MouseCancelEvent cancelEvent; + container->dispatchEvent (cancelEvent); + EXPECT(cancelEvent.consumed == true); MouseWheelEvent event; event.mousePosition = p; @@ -397,20 +405,24 @@ TESTCASE(CViewContainerTest, container->addView (v1); container->addView (v2); - CPoint p (10, 10); - EXPECT(container->onMouseDown (p, kLButton) == kMouseEventHandled); + MouseDownEvent downEvent (CPoint (10, 10), MouseEventButtonState (MouseEventButtonState::Left)); + container->dispatchEvent (downEvent); + EXPECT(downEvent.consumed == true); EXPECT(v1->mouseDownCalled); EXPECT(v2->mouseDownCalled == false); - EXPECT(container->onMouseMoved (p, kLButton) == kMouseEventHandled); + MouseMoveEvent moveEvent (CPoint (10, 10), MouseEventButtonState (MouseEventButtonState::Left)); + container->dispatchEvent (moveEvent); + EXPECT(moveEvent.consumed == true); EXPECT(v1->mouseMovedCalled); EXPECT(v2->mouseMovedCalled == false); - EXPECT(container->onMouseUp (p, kLButton) == kMouseEventHandled); + MouseUpEvent upEvent (CPoint (10 ,10), MouseEventButtonState (MouseEventButtonState::Left)); + container->dispatchEvent (upEvent); + EXPECT(upEvent.consumed); EXPECT(v1->mouseUpCalled); EXPECT(v2->mouseUpCalled == false); - p (60, 10); MouseWheelEvent event; - event.mousePosition = p; + event.mousePosition (60, 10); event.deltaX = 0.5; container->dispatchEvent (event); EXPECT(v1->onWheelCalled == false); @@ -424,10 +436,13 @@ TESTCASE(CViewContainerTest, v1->setMouseableArea (r1); container->addView (v1); - CPoint p (10, 10); - EXPECT(container->onMouseDown (p, kLButton) == kMouseEventHandled); + MouseDownEvent downEvent (CPoint (10, 10), MouseEventButtonState (MouseEventButtonState::Left)); + container->dispatchEvent (downEvent); + EXPECT(downEvent.consumed == true); EXPECT(v1->mouseDownCalled); - container->onMouseCancel (); + MouseCancelEvent cancelEvent; + container->dispatchEvent (cancelEvent); + EXPECT(cancelEvent.consumed == true); EXPECT(v1->mouseCancelCalled); ); @@ -496,11 +511,20 @@ TESTCASE(CViewContainerTest, v1->setMouseableArea (r1); container->addView (v1); container->addView (v2); - CPoint p1 (10, 10); - EXPECT(container->onMouseDown (p1, kLButton) == kMouseEventNotImplemented); + MouseDownEvent downEvent (CPoint (10, 10), MouseEventButtonState (MouseEventButtonState::Left)); + container->dispatchEvent (downEvent); + EXPECT(downEvent.consumed == false); EXPECT(v1->mouseDownCalled == false); - EXPECT(container->onMouseMoved (p1, kLButton) == kMouseEventNotHandled); - EXPECT(container->onMouseUp (p1, kLButton) == kMouseEventNotHandled); + MouseMoveEvent moveEvent; + moveEvent.mousePosition = downEvent.mousePosition; + moveEvent.buttonState = downEvent.buttonState; + container->dispatchEvent (moveEvent); + EXPECT(moveEvent.consumed == false); + MouseUpEvent upEvent; + upEvent.mousePosition = downEvent.mousePosition; + upEvent.buttonState = downEvent.buttonState; + container->dispatchEvent (upEvent); + EXPECT(upEvent.consumed == false); ); TEST(getViewsAt, diff --git a/vstgui/tests/unittest/unittests.cpp b/vstgui/tests/unittest/unittests.cpp index 774010b0e..bacce533d 100644 --- a/vstgui/tests/unittest/unittests.cpp +++ b/vstgui/tests/unittest/unittests.cpp @@ -49,6 +49,12 @@ static void printf (const char* fmt, ...) } #endif +//------------------------------------------------------------------------ +error::error (const char* str) +: std::logic_error (str) +{ +} + //---------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------- diff --git a/vstgui/tests/unittest/unittests.h b/vstgui/tests/unittest/unittests.h index b547e973f..ff7133029 100644 --- a/vstgui/tests/unittest/unittests.h +++ b/vstgui/tests/unittest/unittests.h @@ -61,7 +61,7 @@ namespace UnitTest { class error : public std::logic_error { public: - error (const char* str) : std::logic_error (str) {} + error (const char* str); }; #define VSTGUI_UNITTEST_MAKE_STRING_PRIVATE_DONT_USE(x) # x From 001d0ed62aec6dd26100acb213afeebccf859f7b Mon Sep 17 00:00:00 2001 From: scheffle Date: Sat, 24 Apr 2021 18:35:47 +0200 Subject: [PATCH 038/319] update linux platform mouse event handling --- vstgui/lib/platform/linux/x11frame.cpp | 75 +++++++++++++++++++++----- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/vstgui/lib/platform/linux/x11frame.cpp b/vstgui/lib/platform/linux/x11frame.cpp index 81c3320f9..eefa310c5 100644 --- a/vstgui/lib/platform/linux/x11frame.cpp +++ b/vstgui/lib/platform/linux/x11frame.cpp @@ -41,6 +41,45 @@ namespace VSTGUI { namespace X11 { namespace { +//------------------------------------------------------------------------ +inline void setupMouseEventButtons (MouseEvent& event, xcb_button_t value) +{ + switch (value) + { + case 1: + event.buttonState.add (MouseEventButtonState::Left); + break; + case 2: + event.buttonState.add (MouseEventButtonState::Middle); + break; + case 3: + event.buttonState.add (MouseEventButtonState::Right); + break; + } +} + +//------------------------------------------------------------------------ +inline void setupMouseEventButtons (MouseEvent& event, int state) +{ + if (state & XCB_BUTTON_MASK_1) + event.buttonState.add (MouseEventButtonState::Left); + if (state & XCB_BUTTON_MASK_2) + event.buttonState.add (MouseEventButtonState::Right); + if (state & XCB_BUTTON_MASK_3) + event.buttonState.add (MouseEventButtonState::Middle); +} + +//------------------------------------------------------------------------ +inline void setupEventModifiers (Modifiers& modifiers, int state) +{ + if (state & XCB_MOD_MASK_CONTROL) + modifiers.add (ModifierKey::Control); + if (state & XCB_MOD_MASK_SHIFT) + modifiers.add (ModifierKey::Shift); + if (state & (XCB_MOD_MASK_1 | XCB_MOD_MASK_5)) + modifiers.add (ModifierKey::Alt); +} + //------------------------------------------------------------------------ inline CButtonState translateMouseButtons (xcb_button_t value) { @@ -422,12 +461,15 @@ struct Frame::Impl : IFrameEventHandler } else // mouse down { - auto buttons = translateMouseButtons (event.detail); - buttons |= translateModifiers (event.state); - doubleClickDetector.onMouseDown (where, buttons, event.time); - auto result = frame->platformOnMouseDown (where, buttons); + MouseDownEvent downEvent; + downEvent.mousePosition = where; + setupMouseEventButtons (downEvent, event.detail); + setupEventModifiers (downEvent.modifiers, event.state); + // TODO: doubleClickDetector + // doubleClickDetector.onMouseDown (where, buttons, event.time); + frame->platformOnEvent (downEvent); grabPointer (); - if (result != kMouseEventNotHandled) + if (downEvent.consumed) { auto xcb = RunLoop::instance ().getXcbConnection (); xcb_set_input_focus (xcb, XCB_INPUT_FOCUS_PARENT, window.getID (), @@ -442,10 +484,13 @@ struct Frame::Impl : IFrameEventHandler } else { - auto buttons = translateMouseButtons (event.detail); - buttons |= translateModifiers (event.state); - doubleClickDetector.onMouseUp (where, buttons, event.time); - frame->platformOnMouseUp (where, buttons); + MouseUpEvent upEvent; + upEvent.mousePosition = where; + setupMouseEventButtons (upEvent, event.detail); + setupEventModifiers (upEvent.modifiers, event.state); + // TODO: doubleClickDetector + // doubleClickDetector.onMouseUp (where, buttons, event.time); + frame->platformOnEvent (upEvent); ungrabPointer (); } } @@ -454,11 +499,13 @@ struct Frame::Impl : IFrameEventHandler //------------------------------------------------------------------------ void onEvent (xcb_motion_notify_event_t& event) override { - CPoint where (event.event_x, event.event_y); - auto buttons = translateMouseButtons (event.state); - buttons |= translateModifiers (event.state); - doubleClickDetector.onMouseMove (where, buttons, event.time); - frame->platformOnMouseMoved (where, buttons); + MouseMoveEvent moveEvent; + moveEvent.mousePosition (event.event_x, event.event_y); + setupMouseEventButtons (moveEvent, event.state); + setupEventModifiers (moveEvent.modifiers, event.state); + // TODO: doubleClickDetector + // doubleClickDetector.onMouseMove (where, buttons, event.time); + frame->platformOnEvent (moveEvent); // make sure we get more motion events auto xcb = RunLoop::instance ().getXcbConnection (); xcb_get_motion_events (xcb, window.getID (), event.time, event.time + 10000000); From 31a5aa48842ade5a08d959b28de15cac7b011f00 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sat, 24 Apr 2021 19:09:22 +0200 Subject: [PATCH 039/319] update double click detector --- vstgui/lib/platform/linux/x11frame.cpp | 37 +++++++++++++++++--------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/vstgui/lib/platform/linux/x11frame.cpp b/vstgui/lib/platform/linux/x11frame.cpp index eefa310c5..d99561e70 100644 --- a/vstgui/lib/platform/linux/x11frame.cpp +++ b/vstgui/lib/platform/linux/x11frame.cpp @@ -233,7 +233,20 @@ struct DrawHandler //------------------------------------------------------------------------ struct DoubleClickDetector { - void onMouseDown (CPoint where, CButtonState& buttons, xcb_timestamp_t time) + void onEvent (MouseDownEvent& event, xcb_timestamp_t time) + { + if (event.type == EventType::MouseDown) + onMouseDown (event.mousePosition, event.buttonState, time); + if (event.type == EventType::MouseMove) + onMouseMove (event.mousePosition, event.buttonState, time); + if (event.type == EventType::MouseUp) + onMouseUp (event.mousePosition, event.buttonState, time); + if (isDoubleClick) + event.clickCount = 2; + } + +private: + void onMouseDown (CPoint where, MouseEventButtonState buttonState, xcb_timestamp_t time) { switch (state) { @@ -241,8 +254,9 @@ struct DoubleClickDetector case State::Uninitialized: { state = State::MouseDown; - firstClickState = buttons; + firstClickState = buttonState; firstClickTime = time; + isDoubleClick = false; point = where; break; } @@ -250,7 +264,7 @@ struct DoubleClickDetector { if (timeInside (time) && pointInside (where)) { - buttons |= kDoubleClick; + isDoubleClick = true; } state = State::Uninitialized; break; @@ -258,7 +272,7 @@ struct DoubleClickDetector } } - void onMouseUp (CPoint where, CButtonState buttons, xcb_timestamp_t time) + void onMouseUp (CPoint where, MouseEventButtonState buttonState, xcb_timestamp_t time) { if (state == State::MouseDown && pointInside (where)) state = State::MouseUp; @@ -266,13 +280,12 @@ struct DoubleClickDetector state = State::Uninitialized; } - void onMouseMove (CPoint where, CButtonState buttons, xcb_timestamp_t time) + void onMouseMove (CPoint where, MouseEventButtonState buttonState, xcb_timestamp_t time) { if (!pointInside (where)) state = State::Uninitialized; } -private: bool timeInside (xcb_timestamp_t time) { constexpr xcb_timestamp_t threshold = 250; // in milliseconds @@ -296,8 +309,9 @@ struct DoubleClickDetector }; State state {State::Uninitialized}; + bool isDoubleClick {false}; CPoint point; - CButtonState firstClickState; + MouseEventButtonState firstClickState; xcb_timestamp_t firstClickTime {0}; }; @@ -465,8 +479,7 @@ struct Frame::Impl : IFrameEventHandler downEvent.mousePosition = where; setupMouseEventButtons (downEvent, event.detail); setupEventModifiers (downEvent.modifiers, event.state); - // TODO: doubleClickDetector - // doubleClickDetector.onMouseDown (where, buttons, event.time); + doubleClickDetector.onEvent (downEvent, event.time); frame->platformOnEvent (downEvent); grabPointer (); if (downEvent.consumed) @@ -488,8 +501,7 @@ struct Frame::Impl : IFrameEventHandler upEvent.mousePosition = where; setupMouseEventButtons (upEvent, event.detail); setupEventModifiers (upEvent.modifiers, event.state); - // TODO: doubleClickDetector - // doubleClickDetector.onMouseUp (where, buttons, event.time); + doubleClickDetector.onEvent (upEvent, event.time); frame->platformOnEvent (upEvent); ungrabPointer (); } @@ -503,8 +515,7 @@ struct Frame::Impl : IFrameEventHandler moveEvent.mousePosition (event.event_x, event.event_y); setupMouseEventButtons (moveEvent, event.state); setupEventModifiers (moveEvent.modifiers, event.state); - // TODO: doubleClickDetector - // doubleClickDetector.onMouseMove (where, buttons, event.time); + doubleClickDetector.onEvent (moveEvent, event.time); frame->platformOnEvent (moveEvent); // make sure we get more motion events auto xcb = RunLoop::instance ().getXcbConnection (); From 741662edce9cf1c0b60487f78087cc6c550c770e Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 11:17:30 +0200 Subject: [PATCH 040/319] new mouse enter/exit events --- vstgui/lib/cframe.cpp | 97 +++++++++----------- vstgui/lib/cframe.h | 6 +- vstgui/lib/cview.cpp | 48 ++++++++++ vstgui/lib/cview.h | 17 ++-- vstgui/lib/events.h | 77 +++++++++++++++- vstgui/lib/idependency.h | 4 +- vstgui/lib/platform/iplatformframecallback.h | 1 - vstgui/lib/platform/linux/x11frame.cpp | 9 +- vstgui/lib/platform/mac/cocoa/nsviewframe.mm | 9 +- vstgui/lib/platform/win32/win32frame.cpp | 9 +- vstgui/lib/vstguibase.h | 13 +-- vstgui/lib/vstguifwd.h | 2 + 12 files changed, 199 insertions(+), 93 deletions(-) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index db651442e..d68fb1376 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -138,7 +138,7 @@ CFrame::CFrame (const CRect& inSize, VSTGUIEditorInterface* inEditor) : CViewCon //----------------------------------------------------------------------------- void CFrame::beforeDelete () { - clearMouseViews (CPoint (0, 0), 0, false); + clearMouseViews (CPoint (0, 0), Modifiers (), false); clearModalViewSessions (); @@ -184,7 +184,7 @@ void CFrame::beforeDelete () //----------------------------------------------------------------------------- void CFrame::close () { - clearMouseViews (CPoint (0, 0), 0, false); + clearMouseViews (CPoint (0, 0), Modifiers (), false); clearModalViewSessions (); @@ -339,7 +339,7 @@ void CFrame::drawRect (CDrawContext* pContext, const CRect& updateRect) } //----------------------------------------------------------------------------- -void CFrame::clearMouseViews (const CPoint& where, const CButtonState& buttons, bool callMouseExit) +void CFrame::clearMouseViews (const CPoint& where, Modifiers modifiers, bool callMouseExit) { CPoint lp; auto it = pImpl->mouseViews.rbegin (); @@ -347,9 +347,10 @@ void CFrame::clearMouseViews (const CPoint& where, const CButtonState& buttons, { if (callMouseExit) { - lp = where; - lp = (*it)->translateToLocal (lp); - (*it)->onMouseExited (lp, buttons); + MouseExitEvent exitEvent; + exitEvent.modifiers = modifiers; + exitEvent.mousePosition = (*it)->translateToLocal (where); + (*it)->dispatchEvent (exitEvent); #if DEBUG_MOUSE_VIEWS DebugPrint ("mouseExited : %p[%d,%d]\n", (*it), (int)lp.x, (int)lp.y); #endif @@ -389,12 +390,12 @@ void CFrame::removeFromMouseViews (CView* view) } //----------------------------------------------------------------------------- -void CFrame::checkMouseViews (const CPoint& where, const CButtonState& buttons) +void CFrame::checkMouseViews (const MouseEvent& event) { if (getMouseDownView ()) return; CPoint lp; - CView* mouseView = getViewAt (where, GetViewOptions ().deep ().mouseEnabled ().includeViewContainer ()); + CView* mouseView = getViewAt (event.mousePosition, GetViewOptions ().deep ().mouseEnabled ().includeViewContainer ()); CView* currentMouseView = pImpl->mouseViews.empty () == false ? pImpl->mouseViews.back () : nullptr; if (currentMouseView == mouseView) return; // no change @@ -409,7 +410,7 @@ void CFrame::checkMouseViews (const CPoint& where, const CButtonState& buttons) if (mouseView == nullptr || mouseView == this) { - clearMouseViews (where, buttons); + clearMouseViews (event.mousePosition, event.modifiers); return; } CViewContainer* vc = currentMouseView ? currentMouseView->asViewContainer () : nullptr; @@ -417,9 +418,9 @@ void CFrame::checkMouseViews (const CPoint& where, const CButtonState& buttons) // views in the list are viewcontainers if (vc == nullptr && currentMouseView) { - lp = where; - lp = currentMouseView->translateToLocal (lp); - currentMouseView->onMouseExited (lp, buttons); + MouseExitEvent exitEvent (event); + exitEvent.mousePosition = currentMouseView->translateToLocal (exitEvent.mousePosition); + currentMouseView->dispatchEvent (exitEvent); callMouseObserverMouseExited (currentMouseView); #if DEBUG_MOUSE_VIEWS DebugPrint ("mouseExited : %p[%d,%d]\n", currentMouseView, (int)lp.x, (int)lp.y); @@ -435,9 +436,9 @@ void CFrame::checkMouseViews (const CPoint& where, const CButtonState& buttons) return; if (vc->isChild (mouseView, true) == false) { - lp = where; - lp = vc->translateToLocal (lp); - vc->onMouseExited (lp, buttons); + MouseExitEvent exitEvent (event); + exitEvent.mousePosition = vc->translateToLocal (exitEvent.mousePosition); + vc->dispatchEvent (exitEvent); callMouseObserverMouseExited (vc); #if DEBUG_MOUSE_VIEWS DebugPrint ("mouseExited : %p[%d,%d]\n", vc, (int)lp.x, (int)lp.y); @@ -465,9 +466,9 @@ void CFrame::checkMouseViews (const CPoint& where, const CButtonState& buttons) ++it2; while (it2 != pImpl->mouseViews.end ()) { - lp = where; - lp = (*it2)->translateToLocal (lp); - (*it2)->onMouseEntered (lp, buttons); + MouseEnterEvent enterEvent (event); + enterEvent.mousePosition = (*it2)->translateToLocal (enterEvent.mousePosition); + (*it2)->dispatchEvent (enterEvent); callMouseObserverMouseEntered ((*it2)); #if DEBUG_MOUSE_VIEWS DebugPrint ("mouseEntered : %p[%d,%d]\n", (*it2), (int)lp.x, (int)lp.y); @@ -490,9 +491,9 @@ void CFrame::checkMouseViews (const CPoint& where, const CButtonState& buttons) auto it2 = pImpl->mouseViews.begin (); while (it2 != pImpl->mouseViews.end ()) { - lp = where; - lp = (*it2)->translateToLocal (lp); - (*it2)->onMouseEntered (lp, buttons); + MouseEnterEvent enterEvent (event); + enterEvent.mousePosition = (*it2)->translateToLocal (enterEvent.mousePosition); + (*it2)->dispatchEvent (enterEvent); callMouseObserverMouseEntered ((*it2)); #if DEBUG_MOUSE_VIEWS DebugPrint ("mouseEntered : %p[%d,%d]\n", (*it2), (int)lp.x, (int)lp.y); @@ -522,19 +523,6 @@ bool CFrame::hitTestSubViews (const CPoint& where, const CButtonState& buttons) return CViewContainer::hitTestSubViews (where, buttons); } -//----------------------------------------------------------------------------- -CMouseEventResult CFrame::onMouseExited (CPoint &where, const CButtonState& buttons) -{ // this should only get called from the platform implementation - if (getMouseDownView () == nullptr) - { - clearMouseViews (where, buttons); - if (pImpl->tooltips) - pImpl->tooltips->hideTooltip (); - } - - return kMouseEventHandled; -} - //----------------------------------------------------------------------------- void CFrame::dispatchKeyboardEvent (KeyboardEvent& event) { @@ -629,7 +617,7 @@ void CFrame::dispatchMouseMoveEvent (MouseMoveEvent& event) tooltips->onMouseMoved (transformedMousePosition); auto buttonState = buttonStateFromMouseEvent (event); - checkMouseViews (originMousePosition, buttonState); + checkMouseViews (event); if (callMouseObserverMouseMoved (event.mousePosition, buttonState) == kMouseEventHandled) { @@ -708,6 +696,18 @@ void CFrame::dispatchMouseEvent (MouseEvent& event) dispatchMouseDownEvent (castMouseDownEvent (event)); else if (event.type == EventType::MouseUp) dispatchMouseUpEvent (castMouseUpEvent (event)); + else if (event.type == EventType::MouseEnter) + {} + else if (event.type == EventType::MouseExit) + { + if (getMouseDownView () == nullptr) + { + clearMouseViews (event.mousePosition, event.modifiers); + if (pImpl->tooltips) + pImpl->tooltips->hideTooltip (); + } + event.consumed = true; + } else { vstgui_assert (false); @@ -747,10 +747,10 @@ void CFrame::dispatchEvent (Event& event) if (mousePosEvent) { - CButtonState buttons; - if (auto modifierEvent = asModifierEvent (event)) - buttons = buttonStateFromEventModifiers (modifierEvent->modifiers); - checkMouseViews (mousePosition, buttons); + MouseEvent mouseEvent; + mouseEvent.mousePosition = mousePosEvent->mousePosition; + mouseEvent.modifiers = mousePosEvent->modifiers; + checkMouseViews (mouseEvent); } } @@ -956,7 +956,7 @@ void CFrame::initModalViewSession (const ModalViewSession& session) { onMouseCancel (); } - clearMouseViews (CPoint (0, 0), 0, true); + clearMouseViews (CPoint (0, 0), Modifiers (), true); if (auto container = session.view->asViewContainer ()) container->advanceNextFocusView (nullptr, false); else @@ -966,7 +966,10 @@ void CFrame::initModalViewSession (const ModalViewSession& session) { CPoint where; getCurrentMouseLocation (where); - checkMouseViews (where, getCurrentMouseButtons ()); + MouseEvent mouseEvent; + mouseEvent.mousePosition = where; + // TODO: modifiers and mouse button state + checkMouseViews (mouseEvent); } } @@ -1300,7 +1303,7 @@ bool CFrame::removeAll (bool withForget) pImpl->focusView = nullptr; } pImpl->activeFocusView = nullptr; - clearMouseViews (CPoint (0, 0), 0, false); + clearMouseViews (CPoint (0, 0), Modifiers (), false); return CViewContainer::removeAll (withForget); } @@ -1671,16 +1674,6 @@ void CFrame::platformOnEvent (Event& event) dispatchEvent (event); } -//----------------------------------------------------------------------------- -CMouseEventResult CFrame::platformOnMouseExited (CPoint& where, const CButtonState& buttons) -{ - if (!getMouseEnabled ()) - return kMouseEventNotHandled; - Impl::PostEventHandler peh (*pImpl); - CollectInvalidRects cir (this); - return onMouseExited (where, buttons); -} - //----------------------------------------------------------------------------- DragOperation CFrame::platformOnDragEnter (DragEventData data) { diff --git a/vstgui/lib/cframe.h b/vstgui/lib/cframe.h index 97d2b272a..8cc597303 100644 --- a/vstgui/lib/cframe.h +++ b/vstgui/lib/cframe.h @@ -210,7 +210,6 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback bool attached (CView* parent) override; void draw (CDrawContext* pContext) override; void drawRect (CDrawContext* pContext, const CRect& updateRect) override; - CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override; void setViewSize (const CRect& rect, bool invalid = true) override; void dispatchEvent (Event& event) override; @@ -230,8 +229,8 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback ~CFrame () noexcept override = default; void beforeDelete () override; - void checkMouseViews (const CPoint& where, const CButtonState& buttons); - void clearMouseViews (const CPoint& where, const CButtonState& buttons, bool callMouseExit = true); + void checkMouseViews (const MouseEvent& event); + void clearMouseViews (const CPoint& where, Modifiers modifiers, bool callMouseExit = true); void removeFromMouseViews (CView* view); void setCollectInvalidRects (CollectInvalidRects* collectInvalidRects); @@ -248,7 +247,6 @@ class CFrame final : public CViewContainer, public IPlatformFrameCallback // platform frame bool platformDrawRect (CDrawContext* context, const CRect& rect) override; - CMouseEventResult platformOnMouseExited (CPoint& where, const CButtonState& buttons) override; void platformOnEvent (Event& event) override; DragOperation platformOnDragEnter (DragEventData data) override; DragOperation platformOnDragMove (DragEventData data) override; diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index b5c73fe3f..efd4e4712 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -545,6 +545,42 @@ void CView::onMouseCancelEvent (MouseCancelEvent& event) } } +//------------------------------------------------------------------------ +void CView::onMouseEnterEvent (MouseEnterEvent& event) +{ + auto buttonState = buttonStateFromMouseEvent (event); + switch (onMouseEntered (event.mousePosition, buttonState)) + { + case kMouseEventHandled: + { + event.consumed = true; + break; + } + case kMouseDownEventHandledButDontNeedMovedOrUpEvents: [[fallthrough]]; + case kMouseEventNotHandled: [[fallthrough]]; + case kMouseEventNotImplemented: [[fallthrough]]; + case kMouseMoveEventHandledButDontNeedMoreEvents: break; + } +} + +//------------------------------------------------------------------------ +void CView::onMouseExitEvent (MouseExitEvent& event) +{ + auto buttonState = buttonStateFromMouseEvent (event); + switch (onMouseExited (event.mousePosition, buttonState)) + { + case kMouseEventHandled: + { + event.consumed = true; + break; + } + case kMouseDownEventHandledButDontNeedMovedOrUpEvents: [[fallthrough]]; + case kMouseEventNotHandled: [[fallthrough]]; + case kMouseEventNotImplemented: [[fallthrough]]; + case kMouseMoveEventHandledButDontNeedMoreEvents: break; + } +} + //------------------------------------------------------------------------ void CView::onMouseWheelEvent (MouseWheelEvent& event) { @@ -632,6 +668,18 @@ void CView::dispatchEvent (Event& event) onMouseCancelEvent (mouseCancelEvent); break; } + case EventType::MouseEnter: + { + auto& mouseEnterEvent = castMouseEnterEvent (event); + onMouseEnterEvent (mouseEnterEvent); + break; + } + case EventType::MouseExit: + { + auto& mouseExitEvent = castMouseExitEvent (event); + onMouseExitEvent (mouseExitEvent); + break; + } case EventType::MouseWheel: { auto& wheelEvent = castMouseWheelEvent (event); diff --git a/vstgui/lib/cview.h b/vstgui/lib/cview.h index 9ea12acd2..08fcc449d 100644 --- a/vstgui/lib/cview.h +++ b/vstgui/lib/cview.h @@ -89,6 +89,8 @@ class CView : public CBaseObject virtual void onMouseMoveEvent (MouseMoveEvent& event); virtual void onMouseUpEvent (MouseUpEvent& event); virtual void onMouseCancelEvent (MouseCancelEvent& event); + virtual void onMouseEnterEvent (MouseEnterEvent& event); + virtual void onMouseExitEvent (MouseExitEvent& event); virtual void onMouseWheelEvent (MouseWheelEvent& event); virtual void onZoomGestureEvent (ZoomGestureEvent& event); @@ -123,9 +125,9 @@ class CView : public CBaseObject VSTGUI_DEPRECATED( /** \deprecated never called anymore, please use onMouseWheelEvent instead */ virtual bool onWheel (const CPoint& where, const float& distance, const CButtonState& buttons) final { return false; }) - VSTGUI_DEPRECATED( + VSTGUI_DEPRECATED_MSG( /** \deprecated please use onMouseWheelEvent instead */ - virtual bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons);) + virtual bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons);, "Use CView::onMouseWheelEvent instead") /** turn on/off mouse usage for this view */ virtual void setMouseEnabled (bool bEnable = true); @@ -162,20 +164,21 @@ class CView : public CBaseObject /** set a custom drop target */ void setDropTarget (const SharedPointer& dt); + VSTGUI_DEPRECATED( /** \deprecated start a drag operation. See CDropSource to create the source data package */ - VSTGUI_DEPRECATED(DragResult doDrag (IDataPackage* source, const CPoint& offset = CPoint (0, 0), CBitmap* dragBitmap = nullptr);) + DragResult doDrag (IDataPackage* source, const CPoint& offset = CPoint (0, 0), CBitmap* dragBitmap = nullptr);) //@} //----------------------------------------------------------------------------- /// @name Keyboard Methods //----------------------------------------------------------------------------- //@{ - VSTGUI_DEPRECATED( + VSTGUI_DEPRECATED_MSG( /** called if a key down event occurs and this view has focus */ - virtual int32_t onKeyDown (VstKeyCode& keyCode);) - VSTGUI_DEPRECATED( + virtual int32_t onKeyDown (VstKeyCode& keyCode);, "Use CView::onKeyboardEvent instead") + VSTGUI_DEPRECATED_MSG( /** called if a key up event occurs and this view has focus */ - virtual int32_t onKeyUp (VstKeyCode& keyCode);) + virtual int32_t onKeyUp (VstKeyCode& keyCode);, "Use CView::onKeyboardEvent instead") //@} //----------------------------------------------------------------------------- diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index a038a9f39..93b0be716 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -26,6 +26,8 @@ enum class EventType : uint32_t MouseMove, MouseUp, MouseCancel, + MouseEnter, + MouseExit, MouseWheel, ZoomGesture, KeyUp, @@ -173,7 +175,46 @@ struct MouseEventButtonState struct MouseEvent : MousePositionEvent { MouseEventButtonState buttonState; - uint32_t clickCount {0}; +}; + +//------------------------------------------------------------------------ +/** MouseEnterEvent + * @ingroup new_in_4_11 + */ +struct MouseEnterEvent : MouseEvent +{ + MouseEnterEvent () { type = EventType::MouseEnter; } + MouseEnterEvent (CPoint pos, MouseEventButtonState buttons, Modifiers mods) + : MouseEnterEvent () + { + mousePosition = pos; + buttonState = buttons; + modifiers = mods; + } + MouseEnterEvent (const MouseEvent& e) + : MouseEnterEvent (e.mousePosition, e.buttonState, e.modifiers) + { + } +}; + +//------------------------------------------------------------------------ +/** MouseExitEvent + * @ingroup new_in_4_11 + */ +struct MouseExitEvent : MouseEvent +{ + MouseExitEvent () { type = EventType::MouseExit; } + MouseExitEvent (CPoint pos, MouseEventButtonState buttons, Modifiers mods) + : MouseExitEvent () + { + mousePosition = pos; + buttonState = buttons; + modifiers = mods; + } + MouseExitEvent (const MouseEvent& e) + : MouseExitEvent (e.mousePosition, e.buttonState, e.modifiers) + { + } }; //------------------------------------------------------------------------ @@ -182,6 +223,8 @@ struct MouseEvent : MousePositionEvent */ struct MouseDownEvent : MouseEvent { + uint32_t clickCount {0}; + MouseDownEvent () { type = EventType::MouseDown; } MouseDownEvent (const CPoint& pos, MouseEventButtonState buttons) : MouseDownEvent () @@ -230,7 +273,7 @@ struct MouseMoveEvent : MouseDownEvent /** MouseUpEvent * @ingroup new_in_4_11 */ -struct MouseUpEvent : MouseEvent +struct MouseUpEvent : MouseDownEvent { MouseUpEvent () { type = EventType::MouseUp; } MouseUpEvent (const CPoint& pos, MouseEventButtonState buttons) @@ -419,6 +462,10 @@ inline MousePositionEvent* asMousePositionEvent (Event& event) case EventType::MouseMove: [[fallthrough]]; case EventType::MouseUp: + [[fallthrough]]; + case EventType::MouseEnter: + [[fallthrough]]; + case EventType::MouseExit: return static_cast (&event); default: break; @@ -439,6 +486,10 @@ inline MouseEvent* asMouseEvent (Event& event) case EventType::MouseMove: [[fallthrough]]; case EventType::MouseUp: + [[fallthrough]]; + case EventType::MouseEnter: + [[fallthrough]]; + case EventType::MouseExit: return static_cast (&event); default: break; @@ -506,7 +557,7 @@ inline MousePositionEvent& castMousePositionEvent (Event& event) */ inline MouseEvent& castMouseEvent (Event& event) { - vstgui_assert (event.type >= EventType::MouseDown && event.type <= EventType::MouseUp); + vstgui_assert (event.type >= EventType::MouseDown && event.type <= EventType::MouseExit); return static_cast (event); } @@ -540,6 +591,26 @@ inline MouseUpEvent& castMouseUpEvent (Event& event) return static_cast (event); } +//------------------------------------------------------------------------ +/** cast to a mouse enter event + * @ingroup new_in_4_11 + */ +inline MouseEnterEvent& castMouseEnterEvent (Event& event) +{ + vstgui_assert (event.type == EventType::MouseEnter); + return static_cast (event); +} + +//------------------------------------------------------------------------ +/** cast to a mouse exit event + * @ingroup new_in_4_11 + */ +inline MouseExitEvent& castMouseExitEvent (Event& event) +{ + vstgui_assert (event.type == EventType::MouseExit); + return static_cast (event); +} + //------------------------------------------------------------------------ /** cast to a mouse cancel event * @ingroup new_in_4_11 diff --git a/vstgui/lib/idependency.h b/vstgui/lib/idependency.h index 0e71ec34d..876853ea9 100644 --- a/vstgui/lib/idependency.h +++ b/vstgui/lib/idependency.h @@ -25,7 +25,7 @@ namespace VSTGUI { and that you must make sure that the dependent objects are alife while added as dependent. */ //---------------------------------------------------------------------------------------------------- -class IDependency +class [[deprecated("Please use listeners instead")]] IDependency { public: /** add a dependent object */ @@ -61,7 +61,7 @@ class IDependency int32_t deferChangeCount {0}; DeferedChangesSet deferedChanges; DependentList dependents; -} VSTGUI_DEPRECATED_ATTRIBUTE; +}; //---------------------------------------------------------------------------------------------------- inline void IDependency::addDependency (CBaseObject* obj) diff --git a/vstgui/lib/platform/iplatformframecallback.h b/vstgui/lib/platform/iplatformframecallback.h index 9643a19f9..c01ceea9b 100644 --- a/vstgui/lib/platform/iplatformframecallback.h +++ b/vstgui/lib/platform/iplatformframecallback.h @@ -33,7 +33,6 @@ class IPlatformFrameCallback public: virtual bool platformDrawRect (CDrawContext* context, const CRect& rect) = 0; - virtual CMouseEventResult platformOnMouseExited (CPoint& where, const CButtonState& buttons) = 0; virtual void platformOnEvent (Event& event) = 0; virtual DragOperation platformOnDragEnter (DragEventData data) = 0; diff --git a/vstgui/lib/platform/linux/x11frame.cpp b/vstgui/lib/platform/linux/x11frame.cpp index d99561e70..e301dd802 100644 --- a/vstgui/lib/platform/linux/x11frame.cpp +++ b/vstgui/lib/platform/linux/x11frame.cpp @@ -527,10 +527,11 @@ struct Frame::Impl : IFrameEventHandler { if ((event.response_type & ~0x80) == XCB_LEAVE_NOTIFY) { - CPoint where (event.event_x, event.event_y); - auto buttons = translateMouseButtons (event.state); - buttons |= translateModifiers (event.state); - frame->platformOnMouseExited (where, buttons); + MouseExitEvent exitEvent; + exitEvent.mousePosition (event.event_x, event.event_y); + setupMouseEventButtons (exitEvent, event.state); + setupEventModifiers (exitEvent.modifiers, event.state); + frame->platformOnEvent (exitEvent); setCursorInternal (kCursorDefault); } else diff --git a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm index 1b741d3bf..4eac0412f 100644 --- a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm +++ b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm @@ -435,11 +435,10 @@ static void VSTGUI_NSView_mouseExited (id self, SEL _cmd, NSEvent* theEvent) IPlatformFrameCallback* _vstguiframe = getFrame (self); if (!_vstguiframe) return; - CButtonState buttons = 0; //eventButton (theEvent); - NSUInteger modifiers = [theEvent modifierFlags]; - mapModifiers (modifiers, buttons); - CPoint p = pointFromNSPoint (getGlobalMouseLocation (self)); - _vstguiframe->platformOnMouseExited (p, buttons); + MouseExitEvent event; + event.modifiers = modifiersFromModifierFlags (theEvent.modifierFlags); + event.mousePosition = pointFromNSPoint (getGlobalMouseLocation (self)); + _vstguiframe->platformOnEvent (event); } //------------------------------------------------------------------------------------ diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index ddf94c13d..add54c48e 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -715,11 +715,10 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM } case WM_MOUSELEAVE: { - CPoint where; - getCurrentMousePosition (where); - CButtonState buttons; - getCurrentMouseButtons (buttons); - pFrame->platformOnMouseExited (where, buttons); + MouseExitEvent event; + getCurrentMousePosition (event.mousePosition); + // TODO: mouse button state + pFrame->platformOnEvent (event); mouseInside = false; return 0; } diff --git a/vstgui/lib/vstguibase.h b/vstgui/lib/vstguibase.h index 4e1d95331..7cc47520c 100644 --- a/vstgui/lib/vstguibase.h +++ b/vstgui/lib/vstguibase.h @@ -65,8 +65,6 @@ #endif #include - #define VSTGUI_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) - #if defined (__clang__) && __clang_major__ > 4 #if defined (VSTGUI_WARN_EVERYTHING) && VSTGUI_WARN_EVERYTHING == 1 #pragma clang diagnostic warning "-Weverything" @@ -118,15 +116,12 @@ #endif #if defined (__clang__) && __clang__ - #define VSTGUI_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) #if defined (VSTGUI_WARN_EVERYTHING) && VSTGUI_WARN_EVERYTHING == 1 #pragma clang diagnostic warning "-Wconversion" #pragma clang diagnostic ignored "-Wreorder" #else #pragma clang diagnostic warning "-Wunreachable-code" #endif - #else - #define VSTGUI_DEPRECATED_ATTRIBUTE __declspec(deprecated) #endif #include @@ -162,14 +157,12 @@ #define VSTGUI_ENABLE_DEPRECATED_METHODS 1 #endif -#ifndef VSTGUI_DEPRECATED_ATTRIBUTE - #define VSTGUI_DEPRECATED_ATTRIBUTE -#endif - #if VSTGUI_ENABLE_DEPRECATED_METHODS - #define VSTGUI_DEPRECATED(x) VSTGUI_DEPRECATED_ATTRIBUTE x + #define VSTGUI_DEPRECATED(x) [[deprecated]] x + #define VSTGUI_DEPRECATED_MSG(x, msg) [[deprecated(msg)]] x #else #define VSTGUI_DEPRECATED(x) + #define VSTGUI_DEPRECATED_MSG(x, msg) #endif //---------------------------------------------------- diff --git a/vstgui/lib/vstguifwd.h b/vstgui/lib/vstguifwd.h index f1c78c427..1c6564ee1 100644 --- a/vstgui/lib/vstguifwd.h +++ b/vstgui/lib/vstguifwd.h @@ -252,6 +252,8 @@ struct MouseDownEvent; struct MouseMoveEvent; struct MouseUpEvent; struct MouseCancelEvent; +struct MouseEnterEvent; +struct MouseExitEvent; struct GestureEvent; struct MouseWheelEvent; struct ZoomGestureEvent; From bc50d9d9e3b762101a3b7ed2a31cc8d4bb9b3e4b Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 12:12:11 +0200 Subject: [PATCH 041/319] always call the dispatchEvent method of CView --- vstgui/lib/cframe.cpp | 9 +++++---- vstgui/lib/cviewcontainer.cpp | 16 +++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index d68fb1376..d38feea97 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -534,7 +534,7 @@ void CFrame::dispatchKeyboardEvent (KeyboardEvent& event) { CBaseObjectGuard og (pImpl->focusView); if (pImpl->focusView->getMouseEnabled ()) - pImpl->focusView->onKeyboardEvent (event); + pImpl->focusView->dispatchEvent (event); if (event.consumed) return; CView* parent = pImpl->focusView->getParentView (); @@ -542,7 +542,7 @@ void CFrame::dispatchKeyboardEvent (KeyboardEvent& event) { if (parent->getMouseEnabled ()) { - parent->onKeyboardEvent (event); + parent->dispatchEvent (event); if (event.consumed) return; } @@ -552,7 +552,7 @@ void CFrame::dispatchKeyboardEvent (KeyboardEvent& event) if (auto modalView = getModalView ()) { CBaseObjectGuard og (modalView); - modalView->onKeyboardEvent (event); + modalView->dispatchEvent (event); if (event.consumed) return; } @@ -650,7 +650,8 @@ void CFrame::dispatchMouseMoveEvent (MouseMoveEvent& event) auto view = *it; if (auto parent = view->getParentView ()) parent->translateToLocal (p); - view->onMouseMoveEvent (event); + event.mousePosition = p; + view->dispatchEvent (event); if (event.consumed) break; ++it; diff --git a/vstgui/lib/cviewcontainer.cpp b/vstgui/lib/cviewcontainer.cpp index 03537fa40..c6aee7afe 100644 --- a/vstgui/lib/cviewcontainer.cpp +++ b/vstgui/lib/cviewcontainer.cpp @@ -204,10 +204,16 @@ void CViewContainer::setMouseDownView (CView* view) // make sure the old mouse down view get a mouse cancel or if not implemented a mouse up if (auto cvc = mouseDownView->asViewContainer ()) cvc->setMouseDownView (nullptr); - else if (mouseDownView->onMouseCancel () == kMouseEventNotImplemented) + else { - CPoint p = mouseDownView->getViewSize ().getTopLeft () - CPoint (10, 10); - mouseDownView->onMouseUp (p, 0); + MouseCancelEvent cancelEvent; + mouseDownView->dispatchEvent (cancelEvent); + if (!cancelEvent.consumed) + { + MouseUpEvent upEvent; + upEvent.mousePosition = mouseDownView->getViewSize ().getTopLeft () - CPoint (10, 10); + mouseDownView->dispatchEvent (upEvent); + } } } setAttribute (kCViewContainerMouseDownViewAttribute, view); @@ -1118,7 +1124,7 @@ void CViewContainer::onMouseMoveEvent (MouseMoveEvent& event) event.ignoreFollowUpMoveAndUpEvents (true); return; } - view->onMouseMoveEvent (event); + view->dispatchEvent (event); } } @@ -1144,7 +1150,7 @@ void CViewContainer::onMouseUpEvent (MouseUpEvent& event) event.consumed = true; return; } - view->onMouseUpEvent (event); + view->dispatchEvent (event); clearMouseDownView (); } } From 6356d47d654a0bd683265f753b86376baef8f04c Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 12:37:40 +0200 Subject: [PATCH 042/319] move events must be dispatched to mouse views also when there's a modal view --- vstgui/lib/cframe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index d38feea97..45dae858a 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -637,9 +637,9 @@ void CFrame::dispatchMouseMoveEvent (MouseMoveEvent& event) } modalView->dispatchEvent (event); } - return; } - CView::dispatchEvent (event); + else + CView::dispatchEvent (event); if (event.consumed == false) { event.buttonState.clear (); From c07dfefb81f7ba0bd7740608d77cc3ae980fc74f Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 12:37:55 +0200 Subject: [PATCH 043/319] consume zoom gesture event --- vstgui/uidescription/editing/uieditview.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vstgui/uidescription/editing/uieditview.cpp b/vstgui/uidescription/editing/uieditview.cpp index 61da1703e..8fbcba683 100644 --- a/vstgui/uidescription/editing/uieditview.cpp +++ b/vstgui/uidescription/editing/uieditview.cpp @@ -498,9 +498,8 @@ void UIEditView::onZoomGestureEvent (ZoomGestureEvent& event) auto scale = getTransform ().m11; auto newScale = scale + scale * event.zoom; setScale (newScale); + event.consumed = true; } - else - CViewContainer::onZoomGestureEvent (event); } //---------------------------------------------------------------------------------------------------- From 6ddb86e525421887400da4882c7d02c34f05efbb Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 12:40:40 +0200 Subject: [PATCH 044/319] Add event listening to view listener and deprecate the view mouse listener interface --- vstgui/lib/cview.cpp | 30 ++++++- vstgui/lib/cview.h | 6 +- vstgui/lib/iviewlistener.h | 13 ++- .../lib/platform/common/genericoptionmenu.cpp | 81 ++++++++++++------- .../lib/platform/common/genericoptionmenu.h | 7 +- .../standalone/source/testappdelegate.cpp | 4 - .../editing/uieditcontroller.cpp | 13 ++- 7 files changed, 103 insertions(+), 51 deletions(-) diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index efd4e4712..78ff12556 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -179,12 +179,15 @@ struct CView::Impl { using ViewAttributes = std::unordered_map>; using ViewListenerDispatcher = DispatchList; - using ViewMouseListenerDispatcher = DispatchList; ViewAttributes attributes; std::unique_ptr viewListeners; +#if VSTGUI_ENABLE_DEPRECATED_METHODS +#include "private/disabledeprecatedmessage.h" + using ViewMouseListenerDispatcher = DispatchList; std::unique_ptr viewMouseListener; - +#include "private/enbledeprecatedmessage.h" +#endif CRect size; int32_t viewFlags {0}; int32_t autosizeFlags {kAutosizeNone}; @@ -354,11 +357,18 @@ void CView::setMouseEnabled (bool state) { setDirty (true); } + if (pImpl->viewListeners) + pImpl->viewListeners->forEach ( + [&] (IViewListener* listener) { listener->viewOnMouseEnabled (this, state); }); +#if VSTGUI_ENABLE_DEPRECATED_METHODS if (pImpl->viewMouseListener) { +#include "private/disabledeprecatedmessage.h" pImpl->viewMouseListener->forEach ( [&] (IViewMouseListener* listener) { listener->viewOnMouseEnabled (this, state); }); +#include "private/enbledeprecatedmessage.h" } +#endif } } @@ -642,6 +652,16 @@ void CView::onZoomGestureEvent (ZoomGestureEvent& event) //------------------------------------------------------------------------ void CView::dispatchEvent (Event& event) { + if (pImpl->viewListeners) + { + pImpl->viewListeners->forEachReverse ( + [&] (IViewListener* listener) { + listener->viewOnEvent (this, event); + return event.consumed; + }, + [] (bool consumed) { return consumed; }); + } + switch (event.type) { case EventType::MouseDown: @@ -1315,6 +1335,7 @@ void CView::unregisterViewListener (IViewListener* listener) pImpl->viewListeners->remove (listener); } +#if VSTGUI_ENABLE_DEPRECATED_METHODS //------------------------------------------------------------------------ void CView::registerViewMouseListener (IViewMouseListener* listener) { @@ -1339,7 +1360,9 @@ CMouseEventResult CView::callMouseListener (MouseListenerCall type, CPoint pos, if (!pImpl->viewMouseListener) return result; pImpl->viewMouseListener->forEachReverse ( +#include "private/disabledeprecatedmessage.h" [&] (IViewMouseListener* l) { +#include "private/enbledeprecatedmessage.h" switch (type) { case MouseListenerCall::MouseDown: return l->viewOnMouseDown (this, pos, buttons); @@ -1365,13 +1388,16 @@ void CView::callMouseListenerEnteredExited (bool mouseEntered) { if (!pImpl->viewMouseListener) return; +#include "private/disabledeprecatedmessage.h" pImpl->viewMouseListener->forEachReverse ([&] (IViewMouseListener* l) { +#include "private/enbledeprecatedmessage.h" if (mouseEntered) l->viewOnMouseEntered (this); else l->viewOnMouseExited (this); }); } +#endif //----------------------------------------------------------------------------- SharedPointer CView::getDropTarget () diff --git a/vstgui/lib/cview.h b/vstgui/lib/cview.h index 08fcc449d..c23657ad0 100644 --- a/vstgui/lib/cview.h +++ b/vstgui/lib/cview.h @@ -356,8 +356,10 @@ class CView : public CBaseObject void registerViewListener (IViewListener* listener); void unregisterViewListener (IViewListener* listener); - void registerViewMouseListener (IViewMouseListener* listener); - void unregisterViewMouseListener (IViewMouseListener* listener); + VSTGUI_DEPRECATED_MSG( + void registerViewMouseListener (IViewMouseListener* listener);, "Use registerViewListener instead") + VSTGUI_DEPRECATED_MSG( + void unregisterViewMouseListener (IViewMouseListener* listener);, "Use unregisterViewListener instead") //@} //----------------------------------------------------------------------------- diff --git a/vstgui/lib/iviewlistener.h b/vstgui/lib/iviewlistener.h index 3d44a9b49..dcb28061f 100644 --- a/vstgui/lib/iviewlistener.h +++ b/vstgui/lib/iviewlistener.h @@ -25,6 +25,10 @@ class IViewListener virtual void viewLostFocus (CView* view) = 0; virtual void viewTookFocus (CView* view) = 0; virtual void viewWillDelete (CView* view) = 0; + /** @ingroup new_in_4_11 */ + virtual void viewOnEvent (CView* view, Event& event) = 0; + /** @ingroup new_in_4_11 */ + virtual void viewOnMouseEnabled (CView* view, bool state) = 0; }; //----------------------------------------------------------------------------- @@ -48,7 +52,7 @@ class IViewContainerListener * @ingroup new_in_4_7 */ //----------------------------------------------------------------------------- -class IViewMouseListener +class [[deprecated("Use IViewEventListener instead")]] IViewMouseListener { public: virtual ~IViewMouseListener () noexcept = default; @@ -75,6 +79,8 @@ class ViewListenerAdapter : public IViewListener void viewLostFocus (CView* view) override {} void viewTookFocus (CView* view) override {} void viewWillDelete (CView* view) override {} + void viewOnEvent (CView* view, Event& event) override {} + void viewOnMouseEnabled (CView* view, bool state) override {} }; //----------------------------------------------------------------------------- @@ -90,13 +96,15 @@ class ViewContainerListenerAdapter : public IViewContainerListener void viewContainerTransformChanged (CViewContainer* container) override {} }; +#include "private/disabledeprecatedmessage.h" //----------------------------------------------------------------------------- /** @brief View Mouse Listener Interface Adapter * * @ingroup new_in_4_7 */ //----------------------------------------------------------------------------- -class ViewMouseListenerAdapter : public IViewMouseListener +class [[deprecated("Use ViewListenerAdapter instead")]] ViewMouseListenerAdapter +: public IViewMouseListener { public: CMouseEventResult viewOnMouseDown (CView* view, CPoint pos, CButtonState buttons) override @@ -116,5 +124,6 @@ class ViewMouseListenerAdapter : public IViewMouseListener void viewOnMouseExited (CView* view) override {} void viewOnMouseEnabled (CView* view, bool state) override {} }; +#include "private/enbledeprecatedmessage.h" } // VSTGUI diff --git a/vstgui/lib/platform/common/genericoptionmenu.cpp b/vstgui/lib/platform/common/genericoptionmenu.cpp index 6e2f0bd51..6aadf8987 100644 --- a/vstgui/lib/platform/common/genericoptionmenu.cpp +++ b/vstgui/lib/platform/common/genericoptionmenu.cpp @@ -15,6 +15,7 @@ #include "../../controls/coptionmenu.h" #include "../../controls/cscrollbar.h" #include "../../cvstguitimer.h" +#include "../../events.h" #include "../../idatabrowserdelegate.h" //------------------------------------------------------------------------ @@ -587,7 +588,7 @@ GenericOptionMenu::GenericOptionMenu (CFrame* frame, CButtonState initialButtons impl->container = new Impl::ContainerT (frameSize); impl->container->setZIndex (100); impl->container->setTransparency (true); - impl->container->registerViewMouseListener (this); + impl->container->registerViewListener (this); impl->modalViewSession = impl->frame->beginModalViewSession (impl->container); impl->focusDrawingWasEnabled = impl->frame->focusDrawingEnabled (); impl->frame->setFocusDrawingEnabled (false); @@ -624,7 +625,7 @@ void GenericOptionMenu::removeModalView (PlatformOptionMenuResult result) return; auto callback = std::move (self->impl->callback); self->impl->callback = nullptr; - self->impl->container->unregisterViewMouseListener (self); + self->impl->container->unregisterViewListener (self); if (self->impl->modalViewSession) { self->impl->frame->endModalViewSession (*self->impl->modalViewSession); @@ -638,44 +639,62 @@ void GenericOptionMenu::removeModalView (PlatformOptionMenuResult result) } //------------------------------------------------------------------------ -CMouseEventResult GenericOptionMenu::viewOnMouseDown (CView* view, CPoint pos, CButtonState buttons) +void GenericOptionMenu::viewOnEvent (CView* view, Event& event) { - if (auto container = view->asViewContainer ()) - { - CViewContainer::ViewList views; - if (container->getViewsAt (pos, views, GetViewOptions ().deep ().includeInvisible ())) - { - return kMouseEventNotHandled; - } - auto self = shared (this); - self->removeModalView ({nullptr, -1}); - return kMouseDownEventHandledButDontNeedMovedOrUpEvents; - } - return kMouseEventNotHandled; -} - -//------------------------------------------------------------------------ -CMouseEventResult GenericOptionMenu::viewOnMouseUp (CView* view, CPoint pos, CButtonState buttons) -{ - if (impl->initialButtons.isLeftButton () && buttons.isLeftButton ()) + if (event.type == EventType::MouseDown) { if (auto container = view->asViewContainer ()) { + auto& downEvent = castMouseDownEvent (event); CViewContainer::ViewList views; - if (container->getViewsAt (pos, views, GetViewOptions ().deep ().includeInvisible ())) + if (container->getViewsAt (downEvent.mousePosition, views, GetViewOptions ().deep ().includeInvisible ())) { - if (view->onMouseDown (pos, buttons) == kMouseEventHandled) - view->onMouseUp (pos, buttons); + return; } - else + auto self = shared (this); + self->removeModalView ({nullptr, -1}); + downEvent.ignoreFollowUpMoveAndUpEvents (true); + downEvent.consumed = true; + return; + } + } + else if (event.type == EventType::MouseUp) + { + auto& upEvent = castMouseUpEvent (event); + if (impl->initialButtons.isLeftButton () && upEvent.buttonState.isLeft ()) + { + if (auto container = view->asViewContainer ()) { - auto self = shared (this); - self->removeModalView ({nullptr, -1}); - return kMouseDownEventHandledButDontNeedMovedOrUpEvents; + CViewContainer::ViewList views; + if (container->getViewsAt (upEvent.mousePosition, views, GetViewOptions ().deep ().includeInvisible ())) + { + MouseDownEvent downEvent; + downEvent.mousePosition = upEvent.mousePosition; + downEvent.buttonState = upEvent.buttonState; + downEvent.clickCount = 1; + for (auto& v : views) + { + v->dispatchEvent (downEvent); + if (downEvent.consumed) + { + v->dispatchEvent (upEvent); + break; + } + } + event.consumed = true; + return; + } + else + { + auto self = shared (this); + self->removeModalView ({nullptr, -1}); + upEvent.ignoreFollowUpMoveAndUpEvents (true); + upEvent.consumed = true; + return; + } } } } - return kMouseEventNotHandled; } //------------------------------------------------------------------------ @@ -686,7 +705,7 @@ void GenericOptionMenu::popup (COptionMenu* optionMenu, const Callback& callback auto self = shared (this); auto clickCallback = [self] (COptionMenu* menu, int32_t index) { - self->impl->container->unregisterViewMouseListener (self); + self->impl->container->unregisterViewListener (self); self->removeModalView ({menu, index}); }; @@ -709,7 +728,7 @@ void GenericOptionMenu::popup (COptionMenu* optionMenu, const Callback& callback if (!impl->container || impl->frame->getCurrentMouseButtons ().getButtonState () == 0) return; - impl->container->registerViewMouseListener (this); + impl->container->registerViewListener (this); CPoint p (where); view->translateToGlobal (p); impl->frame->onMouseDown (p, impl->initialButtons); diff --git a/vstgui/lib/platform/common/genericoptionmenu.h b/vstgui/lib/platform/common/genericoptionmenu.h index 9795dd3a5..878683959 100644 --- a/vstgui/lib/platform/common/genericoptionmenu.h +++ b/vstgui/lib/platform/common/genericoptionmenu.h @@ -40,7 +40,7 @@ struct IGenericOptionMenuListener }; //------------------------------------------------------------------------ -class GenericOptionMenu : public IPlatformOptionMenu, public ViewMouseListenerAdapter +class GenericOptionMenu : public IPlatformOptionMenu, public ViewListenerAdapter { public: GenericOptionMenu (CFrame* frame, CButtonState initialButtons, @@ -53,8 +53,9 @@ class GenericOptionMenu : public IPlatformOptionMenu, public ViewMouseListenerAd private: void removeModalView (PlatformOptionMenuResult result); - CMouseEventResult viewOnMouseDown (CView* view, CPoint pos, CButtonState buttons) override; - CMouseEventResult viewOnMouseUp (CView* view, CPoint pos, CButtonState buttons) override; + void viewOnEvent (CView* view, Event& event) override; +// CMouseEventResult viewOnMouseDown (CView* view, CPoint pos, CButtonState buttons) override; +// CMouseEventResult viewOnMouseUp (CView* view, CPoint pos, CButtonState buttons) override; struct Impl; std::unique_ptr impl; diff --git a/vstgui/standalone/examples/standalone/source/testappdelegate.cpp b/vstgui/standalone/examples/standalone/source/testappdelegate.cpp index 9db6d967f..2a9c4971f 100644 --- a/vstgui/standalone/examples/standalone/source/testappdelegate.cpp +++ b/vstgui/standalone/examples/standalone/source/testappdelegate.cpp @@ -65,7 +65,6 @@ static Command ShowAlertBoxDesign {CommandGroup::File, "Show AlertBox Design"}; //------------------------------------------------------------------------ class DisabledControlsController : public DelegationController, - public ViewMouseListenerAdapter, public ViewListenerAdapter { public: @@ -75,7 +74,6 @@ class DisabledControlsController : public DelegationController, for (auto control : controls) { control->unregisterViewListener (this); - control->unregisterViewMouseListener (this); } controls.clear (); } @@ -85,7 +83,6 @@ class DisabledControlsController : public DelegationController, { if (auto control = dynamic_cast (view)) { - control->registerViewMouseListener (this); control->registerViewListener (this); controls.push_back (control); } @@ -105,7 +102,6 @@ class DisabledControlsController : public DelegationController, if (it != controls.end ()) { control->unregisterViewListener (this); - control->unregisterViewMouseListener (this); controls.erase (it); } } diff --git a/vstgui/uidescription/editing/uieditcontroller.cpp b/vstgui/uidescription/editing/uieditcontroller.cpp index 4be235fc2..128a09bb4 100644 --- a/vstgui/uidescription/editing/uieditcontroller.cpp +++ b/vstgui/uidescription/editing/uieditcontroller.cpp @@ -213,7 +213,6 @@ class UIEditControllerShadingView : public CView //---------------------------------------------------------------------------------------------------- class UIZoomSettingController : public IController, public IContextMenuController2, - public ViewMouseListenerAdapter, public ViewListenerAdapter, public NonAtomicReferenceCounted { @@ -312,7 +311,6 @@ class UIZoomSettingController : public IController, zoomValueControl->setFrameWidth (-1); zoomValueControl->setTooltipText ("Editor Zoom"); zoomValueControl->registerViewListener (this); - zoomValueControl->registerViewMouseListener (this); zoomValueControl->setStyle (zoomValueControl->getStyle () | CTextEdit::kDoubleClickStyle); } } @@ -342,12 +340,15 @@ class UIZoomSettingController : public IController, } } - CMouseEventResult viewOnMouseDown (CView* view, CPoint pos, CButtonState buttons) override + void viewOnEvent (CView* view, Event& event) override { vstgui_assert (view == zoomValueControl); - if (buttons.isDoubleClick ()) + if (event.type != EventType::MouseDown) + return; + auto& downEvent = castMouseDownEvent (event); + if (downEvent.clickCount > 1) popupTimer = nullptr; - else if (buttons.isLeftButton () && buttons.getModifierState () == 0) + else if (downEvent.buttonState.isLeft () && downEvent.modifiers.empty ()) { popupTimer = makeOwned ([this] (CVSTGUITimer*) { popupTimer = nullptr; @@ -359,14 +360,12 @@ class UIZoomSettingController : public IController, zoomValueControl->getViewSize ().getTopLeft (), true)); }, 250); } - return kMouseEventNotHandled; } void viewWillDelete (CView* view) override { vstgui_assert (view == zoomValueControl); view->unregisterViewListener (this); - view->unregisterViewMouseListener (this); zoomValueControl = nullptr; } From cd9c928d179faf41b91a7d74084d2224c7dde0f3 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 12:45:23 +0200 Subject: [PATCH 045/319] move deprecated classes and fix unit test --- vstgui/lib/iviewlistener.h | 42 +++++++++++++----------- vstgui/tests/unittest/lib/cview_test.cpp | 2 ++ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/vstgui/lib/iviewlistener.h b/vstgui/lib/iviewlistener.h index dcb28061f..8f9983c81 100644 --- a/vstgui/lib/iviewlistener.h +++ b/vstgui/lib/iviewlistener.h @@ -46,26 +46,6 @@ class IViewContainerListener virtual void viewContainerTransformChanged (CViewContainer* container) = 0; }; -//----------------------------------------------------------------------------- -/** @brief View Mouse Listener Interface - * - * @ingroup new_in_4_7 - */ -//----------------------------------------------------------------------------- -class [[deprecated("Use IViewEventListener instead")]] IViewMouseListener -{ -public: - virtual ~IViewMouseListener () noexcept = default; - - virtual CMouseEventResult viewOnMouseDown (CView* view, CPoint pos, CButtonState buttons) = 0; - virtual CMouseEventResult viewOnMouseUp (CView* view, CPoint pos, CButtonState buttons) = 0; - virtual CMouseEventResult viewOnMouseMoved (CView* view, CPoint pos, CButtonState buttons) = 0; - virtual CMouseEventResult viewOnMouseCancel (CView* view) = 0; - virtual void viewOnMouseEntered (CView* view) = 0; - virtual void viewOnMouseExited (CView* view) = 0; - virtual void viewOnMouseEnabled (CView* view, bool state) = 0; -}; - //----------------------------------------------------------------------------- /** @brief View Listener Interface Adapter */ @@ -96,6 +76,27 @@ class ViewContainerListenerAdapter : public IViewContainerListener void viewContainerTransformChanged (CViewContainer* container) override {} }; +#if VSTGUI_ENABLE_DEPRECATED_METHODS +//----------------------------------------------------------------------------- +/** @brief View Mouse Listener Interface + * + * @ingroup new_in_4_7 + */ +//----------------------------------------------------------------------------- +class [[deprecated("Use IViewEventListener instead")]] IViewMouseListener +{ +public: + virtual ~IViewMouseListener () noexcept = default; + + virtual CMouseEventResult viewOnMouseDown (CView* view, CPoint pos, CButtonState buttons) = 0; + virtual CMouseEventResult viewOnMouseUp (CView* view, CPoint pos, CButtonState buttons) = 0; + virtual CMouseEventResult viewOnMouseMoved (CView* view, CPoint pos, CButtonState buttons) = 0; + virtual CMouseEventResult viewOnMouseCancel (CView* view) = 0; + virtual void viewOnMouseEntered (CView* view) = 0; + virtual void viewOnMouseExited (CView* view) = 0; + virtual void viewOnMouseEnabled (CView* view, bool state) = 0; +}; + #include "private/disabledeprecatedmessage.h" //----------------------------------------------------------------------------- /** @brief View Mouse Listener Interface Adapter @@ -125,5 +126,6 @@ class [[deprecated("Use ViewListenerAdapter instead")]] ViewMouseListenerAdapter void viewOnMouseEnabled (CView* view, bool state) override {} }; #include "private/enbledeprecatedmessage.h" +#endif // VSTGUI_ENABLE_DEPRECATED_METHODS } // VSTGUI diff --git a/vstgui/tests/unittest/lib/cview_test.cpp b/vstgui/tests/unittest/lib/cview_test.cpp index fe35871fc..d1fa6523a 100644 --- a/vstgui/tests/unittest/lib/cview_test.cpp +++ b/vstgui/tests/unittest/lib/cview_test.cpp @@ -53,6 +53,8 @@ struct ViewListener : public IViewListener view->unregisterViewListener (this); willDeleteCalled = true; } + void viewOnEvent (CView* view, Event& event) override {} + void viewOnMouseEnabled (CView* view, bool state) override {} bool sizeChangedCalled {false}; bool attachedCalled {false}; From dea65e8d23c4427b05d89ac6aaf83b7e43b14c79 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 12:46:56 +0200 Subject: [PATCH 046/319] not necessary to call CView::onKeyDown here --- vstgui/uidescription/editing/uigradientscontroller.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/vstgui/uidescription/editing/uigradientscontroller.cpp b/vstgui/uidescription/editing/uigradientscontroller.cpp index 08809d44e..c871ec2a9 100644 --- a/vstgui/uidescription/editing/uigradientscontroller.cpp +++ b/vstgui/uidescription/editing/uigradientscontroller.cpp @@ -198,7 +198,6 @@ int32_t UIColorStopEditView::onKeyDown (VstKeyCode& keyCode) break; } } - return CView::onKeyDown (keyCode); } //---------------------------------------------------------------------------------------------------- From e4e708f42e412e5180e8be0127e4d228b6514f1b Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 13:23:08 +0200 Subject: [PATCH 047/319] fix generic option menu with new event handling --- vstgui/lib/cframe.cpp | 2 +- vstgui/lib/events.h | 4 ++ .../lib/platform/common/genericoptionmenu.cpp | 48 +++++++++++-------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index 45dae858a..347f3c33a 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -577,7 +577,7 @@ void CFrame::dispatchMouseDownEvent (MouseDownEvent& event) auto buttonState = buttonStateFromMouseEvent (event); - if (callMouseObserverMouseDown (event.mousePosition, buttonState) == kMouseEventHandled) + if (callMouseObserverMouseDown (event.mousePosition, buttonState) != kMouseEventNotHandled) { event.consumed = true; return; diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index 93b0be716..e2b36fdba 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -157,6 +157,7 @@ struct MouseEventButtonState bool is (Position pos) const { return data == pos; } bool isOther (uint32_t index) const { return data == (1 << index); } bool has (Position pos) const { return data & pos; } + bool empty () const { return data == 0; } void add (Position pos) { data |= pos; } void set (Position pos) { data = pos; } @@ -164,6 +165,9 @@ struct MouseEventButtonState MouseEventButtonState () = default; MouseEventButtonState (Position pos) { set (pos); } + + bool operator== (const MouseEventButtonState& other) const { return data == other.data; } + bool operator!= (const MouseEventButtonState& other) const { return data != other.data; } private: uint32_t data {0}; }; diff --git a/vstgui/lib/platform/common/genericoptionmenu.cpp b/vstgui/lib/platform/common/genericoptionmenu.cpp index 6aadf8987..fd8fdf0da 100644 --- a/vstgui/lib/platform/common/genericoptionmenu.cpp +++ b/vstgui/lib/platform/common/genericoptionmenu.cpp @@ -569,7 +569,7 @@ struct GenericOptionMenu::Impl IGenericOptionMenuListener* listener {nullptr}; GenericOptionMenuTheme theme; Callback callback; - CButtonState initialButtons; + MouseEventButtonState initialButtonState; bool focusDrawingWasEnabled {false}; }; @@ -583,7 +583,6 @@ GenericOptionMenu::GenericOptionMenu (CFrame* frame, CButtonState initialButtons impl = std::unique_ptr (new Impl); impl->frame = frame; - impl->initialButtons = initialButtons; impl->theme = theme; impl->container = new Impl::ContainerT (frameSize); impl->container->setZIndex (100); @@ -592,6 +591,10 @@ GenericOptionMenu::GenericOptionMenu (CFrame* frame, CButtonState initialButtons impl->modalViewSession = impl->frame->beginModalViewSession (impl->container); impl->focusDrawingWasEnabled = impl->frame->focusDrawingEnabled (); impl->frame->setFocusDrawingEnabled (false); + if (initialButtons.isLeftButton ()) + impl->initialButtonState.set(MouseEventButtonState::Left); + else if (initialButtons.isRightButton ()) + impl->initialButtonState.set(MouseEventButtonState::Right); } //------------------------------------------------------------------------ @@ -661,22 +664,26 @@ void GenericOptionMenu::viewOnEvent (CView* view, Event& event) else if (event.type == EventType::MouseUp) { auto& upEvent = castMouseUpEvent (event); - if (impl->initialButtons.isLeftButton () && upEvent.buttonState.isLeft ()) + if (impl->initialButtonState == upEvent.buttonState && !impl->mouseUpTimer) { if (auto container = view->asViewContainer ()) { CViewContainer::ViewList views; if (container->getViewsAt (upEvent.mousePosition, views, GetViewOptions ().deep ().includeInvisible ())) { + auto pos = upEvent.mousePosition; + view->translateToGlobal (pos); MouseDownEvent downEvent; - downEvent.mousePosition = upEvent.mousePosition; downEvent.buttonState = upEvent.buttonState; downEvent.clickCount = 1; for (auto& v : views) { + downEvent.mousePosition = pos; + v->translateToLocal (downEvent.mousePosition); v->dispatchEvent (downEvent); if (downEvent.consumed) { + upEvent.mousePosition = downEvent.mousePosition; v->dispatchEvent (upEvent); break; } @@ -717,25 +724,26 @@ void GenericOptionMenu::popup (COptionMenu* optionMenu, const Callback& callback if (auto view = impl->frame->getViewAt (where, GetViewOptions ().deep ().includeInvisible ())) { - if (impl->initialButtons.getButtonState () != 0) + if (!impl->initialButtonState.empty ()) { - impl->frame->getCurrentMouseLocation (where); - view->translateToLocal (where); - view->onMouseMoved (where, impl->initialButtons); - impl->mouseUpTimer = makeOwned ( - [this, where, view] (CVSTGUITimer* timer) { - timer->stop (); - if (!impl->container || - impl->frame->getCurrentMouseButtons ().getButtonState () == 0) - return; - impl->container->registerViewListener (this); - CPoint p (where); - view->translateToGlobal (p); - impl->frame->onMouseDown (p, impl->initialButtons); - }, - 200); + MouseMoveEvent moveEvent; + moveEvent.buttonState = impl->initialButtonState; + impl->frame->getCurrentMouseLocation (moveEvent.mousePosition); + view->translateToLocal (moveEvent.mousePosition); + view->dispatchEvent (moveEvent); } } + if (!impl->initialButtonState.empty ()) + { + impl->mouseUpTimer = makeOwned ( + [this] (CVSTGUITimer*) { + impl->mouseUpTimer = nullptr; + if (!impl->container || + impl->frame->getCurrentMouseButtons ().getButtonState () == 0) + return; + }, + 200); + } if (impl->listener) impl->listener->optionMenuPopupStarted (); } From 06bf0f840fb0485260cbe62a7c06ab5c7e04b7e1 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 15:55:15 +0200 Subject: [PATCH 048/319] turn off formatting on save --- vstgui/.vscode/settings.json | 1 - 1 file changed, 1 deletion(-) diff --git a/vstgui/.vscode/settings.json b/vstgui/.vscode/settings.json index 0a7405ac6..9d890f35f 100644 --- a/vstgui/.vscode/settings.json +++ b/vstgui/.vscode/settings.json @@ -51,6 +51,5 @@ "files.insertFinalNewline": true, "files.trimFinalNewlines": true, "files.trimTrailingWhitespace": true, - "editor.formatOnSave": true, "editor.insertSpaces": false } \ No newline at end of file From d07cec1ae9d79ea5548b41adc12f1acd22b31d8d Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 15:55:43 +0200 Subject: [PATCH 049/319] implement ignore deprecated method for GCC --- vstgui/lib/cview.cpp | 4 +++- vstgui/lib/private/disabledeprecatedmessage.h | 4 +++- vstgui/lib/private/enbledeprecatedmessage.h | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index 78ff12556..bfc8aef65 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -1336,6 +1336,7 @@ void CView::unregisterViewListener (IViewListener* listener) } #if VSTGUI_ENABLE_DEPRECATED_METHODS +#include "private/disabledeprecatedmessage.h" //------------------------------------------------------------------------ void CView::registerViewMouseListener (IViewMouseListener* listener) { @@ -1352,6 +1353,7 @@ void CView::unregisterViewMouseListener (IViewMouseListener* listener) return; pImpl->viewMouseListener->remove (listener); } +#include "private/enbledeprecatedmessage.h" //----------------------------------------------------------------------------- CMouseEventResult CView::callMouseListener (MouseListenerCall type, CPoint pos, CButtonState buttons) @@ -1359,8 +1361,8 @@ CMouseEventResult CView::callMouseListener (MouseListenerCall type, CPoint pos, CMouseEventResult result = kMouseEventNotHandled; if (!pImpl->viewMouseListener) return result; - pImpl->viewMouseListener->forEachReverse ( #include "private/disabledeprecatedmessage.h" + pImpl->viewMouseListener->forEachReverse ( [&] (IViewMouseListener* l) { #include "private/enbledeprecatedmessage.h" switch (type) diff --git a/vstgui/lib/private/disabledeprecatedmessage.h b/vstgui/lib/private/disabledeprecatedmessage.h index 46a4b4180..1a85a124d 100644 --- a/vstgui/lib/private/disabledeprecatedmessage.h +++ b/vstgui/lib/private/disabledeprecatedmessage.h @@ -5,9 +5,11 @@ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated" +#elif defined __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #elif _MSC_VER #pragma warning(push) #pragma warning(disable : 4996) // deprecated #else #endif - diff --git a/vstgui/lib/private/enbledeprecatedmessage.h b/vstgui/lib/private/enbledeprecatedmessage.h index 3fd235cce..71bb3a151 100644 --- a/vstgui/lib/private/enbledeprecatedmessage.h +++ b/vstgui/lib/private/enbledeprecatedmessage.h @@ -4,8 +4,9 @@ #ifdef __clang__ #pragma clang diagnostic pop +#elif defined __GNUC__ +#pragma GCC diagnostic pop #elif _MSC_VER #pragma warning(pop) #else #endif - From 7a0fc79bde54294906aac086e0ac7238cebaff01 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 15:56:07 +0200 Subject: [PATCH 050/319] replace use of CButtons in GenericOptionMenu --- vstgui/lib/platform/common/genericoptionmenu.cpp | 7 ++----- vstgui/lib/platform/common/genericoptionmenu.h | 3 ++- vstgui/lib/platform/linux/x11frame.cpp | 3 ++- vstgui/lib/platform/mac/cocoa/nsviewframe.mm | 7 ++++--- vstgui/lib/platform/win32/win32frame.cpp | 7 ++++++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/vstgui/lib/platform/common/genericoptionmenu.cpp b/vstgui/lib/platform/common/genericoptionmenu.cpp index fd8fdf0da..355191ccd 100644 --- a/vstgui/lib/platform/common/genericoptionmenu.cpp +++ b/vstgui/lib/platform/common/genericoptionmenu.cpp @@ -574,7 +574,7 @@ struct GenericOptionMenu::Impl }; //------------------------------------------------------------------------ -GenericOptionMenu::GenericOptionMenu (CFrame* frame, CButtonState initialButtons, +GenericOptionMenu::GenericOptionMenu (CFrame* frame, MouseEventButtonState initialButtons, GenericOptionMenuTheme theme) { auto frameSize = frame->getViewSize (); @@ -591,10 +591,7 @@ GenericOptionMenu::GenericOptionMenu (CFrame* frame, CButtonState initialButtons impl->modalViewSession = impl->frame->beginModalViewSession (impl->container); impl->focusDrawingWasEnabled = impl->frame->focusDrawingEnabled (); impl->frame->setFocusDrawingEnabled (false); - if (initialButtons.isLeftButton ()) - impl->initialButtonState.set(MouseEventButtonState::Left); - else if (initialButtons.isRightButton ()) - impl->initialButtonState.set(MouseEventButtonState::Right); + impl->initialButtonState = initialButtons; } //------------------------------------------------------------------------ diff --git a/vstgui/lib/platform/common/genericoptionmenu.h b/vstgui/lib/platform/common/genericoptionmenu.h index 878683959..35e909477 100644 --- a/vstgui/lib/platform/common/genericoptionmenu.h +++ b/vstgui/lib/platform/common/genericoptionmenu.h @@ -8,6 +8,7 @@ #include "../../ccolor.h" #include "../../cfont.h" +#include "../../events.h" #include "../../iviewlistener.h" #include @@ -43,7 +44,7 @@ struct IGenericOptionMenuListener class GenericOptionMenu : public IPlatformOptionMenu, public ViewListenerAdapter { public: - GenericOptionMenu (CFrame* frame, CButtonState initialButtons, + GenericOptionMenu (CFrame* frame, MouseEventButtonState initialButtons, GenericOptionMenuTheme theme = {}); ~GenericOptionMenu () noexcept override; diff --git a/vstgui/lib/platform/linux/x11frame.cpp b/vstgui/lib/platform/linux/x11frame.cpp index e301dd802..c09a483ff 100644 --- a/vstgui/lib/platform/linux/x11frame.cpp +++ b/vstgui/lib/platform/linux/x11frame.cpp @@ -778,7 +778,8 @@ SharedPointer Frame::createPlatformOptionMenu () GenericOptionMenuTheme theme; if (impl->genericOptionMenuTheme) theme = *impl->genericOptionMenuTheme.get (); - auto optionMenu = makeOwned (cFrame, 0, theme); + auto optionMenu = makeOwned ( + cFrame, MouseEventButtonState (MouseEventButtonState::Left), theme); optionMenu->setListener (this); return optionMenu; } diff --git a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm index 4eac0412f..2183fd0bf 100644 --- a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm +++ b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm @@ -1347,9 +1347,10 @@ static MouseEventButtonState buttonStateFromNSEvent (NSEvent* theEvent) { if (genericOptionMenuTheme) { - CButtonState buttons; - getCurrentMouseButtons (buttons); - return makeOwned (dynamic_cast (frame), buttons, + MouseEventButtonState buttonState; + if (auto event = [NSApp currentEvent]) + buttonState = buttonStateFromNSEvent (event); + return makeOwned (dynamic_cast (frame), buttonState, *genericOptionMenuTheme.get ()); } return makeOwned (); diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index add54c48e..8d54f17e9 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -459,7 +459,12 @@ SharedPointer Win32Frame::createPlatformOptionMenu () { CButtonState buttons; getCurrentMouseButtons (buttons); - return makeOwned (dynamic_cast (frame), buttons, + MouseEventButtonState buttonState; + if (buttons.isLeft ()) + buttonState.set (MouseEventButtonState::Left); + else if (buttons.isRIght ()) + buttonState.set (MouseEventButtonState::Right); + return makeOwned (dynamic_cast (frame), buttonState, *genericOptionMenuTheme); } return owned (new Win32OptionMenu (windowHandle)); From c22892723548a8d3ea3dd7b7928510cca75800c7 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 16:04:33 +0200 Subject: [PATCH 051/319] remove unused include --- vstgui/uidescription/uidescription.h | 1 - 1 file changed, 1 deletion(-) diff --git a/vstgui/uidescription/uidescription.h b/vstgui/uidescription/uidescription.h index f048dbf48..42fcd2c27 100644 --- a/vstgui/uidescription/uidescription.h +++ b/vstgui/uidescription/uidescription.h @@ -4,7 +4,6 @@ #pragma once -#include "../lib/idependency.h" #include "iuidescription.h" #include "uidescriptionfwd.h" #include From 10375f8fc24145d1b54abc8b51ae46f8a78db393 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 16:21:36 +0200 Subject: [PATCH 052/319] fix build --- vstgui/lib/cview.cpp | 4 ++-- vstgui/lib/platform/win32/win32frame.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index bfc8aef65..14f8bf676 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -1364,7 +1364,6 @@ CMouseEventResult CView::callMouseListener (MouseListenerCall type, CPoint pos, #include "private/disabledeprecatedmessage.h" pImpl->viewMouseListener->forEachReverse ( [&] (IViewMouseListener* l) { -#include "private/enbledeprecatedmessage.h" switch (type) { case MouseListenerCall::MouseDown: return l->viewOnMouseDown (this, pos, buttons); @@ -1382,6 +1381,7 @@ CMouseEventResult CView::callMouseListener (MouseListenerCall type, CPoint pos, } return false; }); +#include "private/enbledeprecatedmessage.h" return result; } @@ -1392,12 +1392,12 @@ void CView::callMouseListenerEnteredExited (bool mouseEntered) return; #include "private/disabledeprecatedmessage.h" pImpl->viewMouseListener->forEachReverse ([&] (IViewMouseListener* l) { -#include "private/enbledeprecatedmessage.h" if (mouseEntered) l->viewOnMouseEntered (this); else l->viewOnMouseExited (this); }); +#include "private/enbledeprecatedmessage.h" } #endif diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index 8d54f17e9..2e066525a 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -460,9 +460,9 @@ SharedPointer Win32Frame::createPlatformOptionMenu () CButtonState buttons; getCurrentMouseButtons (buttons); MouseEventButtonState buttonState; - if (buttons.isLeft ()) + if (buttons.isLeftButton ()) buttonState.set (MouseEventButtonState::Left); - else if (buttons.isRIght ()) + else if (buttons.isRightButton ()) buttonState.set (MouseEventButtonState::Right); return makeOwned (dynamic_cast (frame), buttonState, *genericOptionMenuTheme); From 75f2f12267c20ba8643f644e9dcbbb05e4fe50f6 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 16:47:30 +0200 Subject: [PATCH 053/319] change DragEventData::modifiers type to Modifiers --- vstgui/doxygen/page_changes.h | 2 ++ vstgui/lib/cframe.cpp | 4 ---- vstgui/lib/dragging.h | 4 ++-- vstgui/lib/platform/mac/cocoa/nsviewframe.mm | 24 +++++++------------ vstgui/lib/platform/win32/win32dragging.cpp | 8 +++---- vstgui/lib/platform/win32/win32frame.cpp | 13 ++++++++++ vstgui/lib/platform/win32/win32frame.h | 2 ++ .../unittest/lib/cviewcontainer_test.cpp | 4 ++-- .../imagestitcher/source/imageframesview.cpp | 4 ++-- 9 files changed, 35 insertions(+), 30 deletions(-) diff --git a/vstgui/doxygen/page_changes.h b/vstgui/doxygen/page_changes.h index e28846823..835d150fc 100644 --- a/vstgui/doxygen/page_changes.h +++ b/vstgui/doxygen/page_changes.h @@ -132,6 +132,8 @@ Which replaces the following old methods: - onWheel - ... +- DragEventData has changed it's modifiers type from CButtonState to Modifiers + @subsection code_changes_4_9_to_4_10 VSTGUI 4.9 -> VSTGUI 4.10 - one has to use VSTGUI::init() before using VSTGUI and VSTGUI::exit() after use diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index 347f3c33a..e17f57494 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -1682,7 +1682,6 @@ DragOperation CFrame::platformOnDragEnter (DragEventData data) return DragOperation::None; Impl::PostEventHandler peh (*pImpl); CollectInvalidRects cir (this); - data.modifiers = data.modifiers.getModifierState (); return getDropTarget ()->onDragEnter (data); } @@ -1693,7 +1692,6 @@ DragOperation CFrame::platformOnDragMove (DragEventData data) return DragOperation::None; Impl::PostEventHandler peh (*pImpl); CollectInvalidRects cir (this); - data.modifiers = data.modifiers.getModifierState (); return getDropTarget ()->onDragMove (data); } @@ -1704,7 +1702,6 @@ void CFrame::platformOnDragLeave (DragEventData data) return; Impl::PostEventHandler peh (*pImpl); CollectInvalidRects cir (this); - data.modifiers = data.modifiers.getModifierState (); getDropTarget ()->onDragLeave (data); } @@ -1715,7 +1712,6 @@ bool CFrame::platformOnDrop (DragEventData data) return false; Impl::PostEventHandler peh (*pImpl); CollectInvalidRects cir (this); - data.modifiers = data.modifiers.getModifierState (); return getDropTarget ()->onDrop (data); } diff --git a/vstgui/lib/dragging.h b/vstgui/lib/dragging.h index 0aaffe7f6..ef54675d6 100644 --- a/vstgui/lib/dragging.h +++ b/vstgui/lib/dragging.h @@ -6,7 +6,7 @@ #include "vstguifwd.h" #include "cbitmap.h" -#include "cbuttonstate.h" +#include "events.h" #include "cpoint.h" #include "idatapackage.h" #include @@ -71,7 +71,7 @@ struct DragEventData /** mouse position */ CPoint pos; /** key modifiers */ - CButtonState modifiers; + Modifiers modifiers; }; //------------------------------------------------------------------------ diff --git a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm index 2183fd0bf..df3a8e46f 100644 --- a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm +++ b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm @@ -565,11 +565,9 @@ static NSDragOperation VSTGUI_NSView_draggingEntered (id self, SEL _cmd, id send CPoint where; nsViewGetCurrentMouseLocation (self, where); - NSUInteger modifiers = [NSEvent modifierFlags]; - CButtonState buttons = 0; - mapModifiers (modifiers, buttons); + auto modifiers = modifiersFromModifierFlags (NSEvent.modifierFlags); - DragEventData data {frame->getDragDataPackage (), where, buttons}; + DragEventData data {frame->getDragDataPackage (), where, modifiers}; auto result = frame->getFrame ()->platformOnDragEnter (data); if (result == DragOperation::Copy) return NSDragOperationCopy; @@ -588,11 +586,9 @@ static NSDragOperation VSTGUI_NSView_draggingUpdated (id self, SEL _cmd, id send CPoint where; nsViewGetCurrentMouseLocation (self, where); - NSUInteger modifiers = [NSEvent modifierFlags]; - CButtonState buttons = 0; - mapModifiers (modifiers, buttons); + auto modifiers = modifiersFromModifierFlags (NSEvent.modifierFlags); - DragEventData data {frame->getDragDataPackage (), where, buttons}; + DragEventData data {frame->getDragDataPackage (), where, modifiers}; auto result = frame->getFrame ()->platformOnDragMove (data); if (result == DragOperation::Copy) return NSDragOperationCopy; @@ -611,11 +607,9 @@ static void VSTGUI_NSView_draggingExited (id self, SEL _cmd, id sender) CPoint where; nsViewGetCurrentMouseLocation (self, where); - NSUInteger modifiers = [NSEvent modifierFlags]; - CButtonState buttons = 0; - mapModifiers (modifiers, buttons); + auto modifiers = modifiersFromModifierFlags (NSEvent.modifierFlags); - DragEventData data {frame->getDragDataPackage (), where, buttons}; + DragEventData data {frame->getDragDataPackage (), where, modifiers}; frame->getFrame ()->platformOnDragLeave (data); frame->setDragDataPackage (nullptr); @@ -631,11 +625,9 @@ static BOOL VSTGUI_NSView_performDragOperation (id self, SEL _cmd, id sender) CPoint where; nsViewGetCurrentMouseLocation (self, where); - NSUInteger modifiers = [NSEvent modifierFlags]; - CButtonState buttons = 0; - mapModifiers (modifiers, buttons); + auto modifiers = modifiersFromModifierFlags (NSEvent.modifierFlags); - DragEventData data {frame->getDragDataPackage (), where, buttons}; + DragEventData data {frame->getDragDataPackage (), where, modifiers}; bool result = frame->getFrame ()->platformOnDrop (data); frame->setMouseCursor (kCursorDefault); frame->setDragDataPackage (nullptr); diff --git a/vstgui/lib/platform/win32/win32dragging.cpp b/vstgui/lib/platform/win32/win32dragging.cpp index 0990fb960..864a9a6e2 100644 --- a/vstgui/lib/platform/win32/win32dragging.cpp +++ b/vstgui/lib/platform/win32/win32dragging.cpp @@ -236,7 +236,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CDropTarget::DragEnter (IDataObject* dataObjec DragEventData data; data.drag = dragData; pFrame->getCurrentMousePosition (data.pos); - pFrame->getCurrentMouseButtons (data.modifiers); + pFrame->getCurrentModifiers (data.modifiers); auto result = pFrame->getFrame ()->platformOnDragEnter (data); if (result == DragOperation::Copy) *effect = DROPEFFECT_COPY; @@ -258,7 +258,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CDropTarget::DragOver (DWORD keyState, POINTL DragEventData data; data.drag = dragData; pFrame->getCurrentMousePosition (data.pos); - pFrame->getCurrentMouseButtons (data.modifiers); + pFrame->getCurrentModifiers (data.modifiers); auto result = pFrame->getFrame ()->platformOnDragMove (data); if (result == DragOperation::Copy) *effect = DROPEFFECT_COPY; @@ -278,7 +278,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CDropTarget::DragLeave () DragEventData data; data.drag = dragData; pFrame->getCurrentMousePosition (data.pos); - pFrame->getCurrentMouseButtons (data.modifiers); + pFrame->getCurrentModifiers (data.modifiers); pFrame->getFrame ()->platformOnDragLeave (data); dragData->forget (); dragData = nullptr; @@ -294,7 +294,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CDropTarget::Drop (IDataObject* dataObject, DW DragEventData data; data.drag = dragData; pFrame->getCurrentMousePosition (data.pos); - pFrame->getCurrentMouseButtons (data.modifiers); + pFrame->getCurrentModifiers (data.modifiers); pFrame->getFrame ()->platformOnDrop (data); dragData->forget (); dragData = nullptr; diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index 2e066525a..a8ac2fe05 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -314,6 +314,19 @@ bool Win32Frame::getCurrentMousePosition (CPoint& mousePosition) const return false; } +//----------------------------------------------------------------------------- +bool Win32Frame::getCurrentModifiers (Modifiers& modifiers) const +{ + modifiers.clear (); + if (GetAsyncKeyState (VK_SHIFT) < 0) + modifiers.add (ModifierKey::Shift); + if (GetAsyncKeyState (VK_CONTROL) < 0) + modifiers.add (ModifierKey::Control); + if (GetAsyncKeyState (VK_MENU) < 0) + modifiers.add (ModifierKey::Alt); + return true; +} + //----------------------------------------------------------------------------- bool Win32Frame::getCurrentMouseButtons (CButtonState& buttons) const { diff --git a/vstgui/lib/platform/win32/win32frame.h b/vstgui/lib/platform/win32/win32frame.h index cac50c2a1..3e41c217f 100644 --- a/vstgui/lib/platform/win32/win32frame.h +++ b/vstgui/lib/platform/win32/win32frame.h @@ -27,6 +27,8 @@ class Win32Frame final : public IPlatformFrame, public IWin32PlatformFrame CCursorType getLastSetCursor () const { return lastSetCursor; } + bool getCurrentModifiers (Modifiers& modifiers) const; + // IPlatformFrame bool getGlobalPosition (CPoint& pos) const override; bool setSize (const CRect& newSize) override; diff --git a/vstgui/tests/unittest/lib/cviewcontainer_test.cpp b/vstgui/tests/unittest/lib/cviewcontainer_test.cpp index 0947c262d..5aea34823 100644 --- a/vstgui/tests/unittest/lib/cviewcontainer_test.cpp +++ b/vstgui/tests/unittest/lib/cviewcontainer_test.cpp @@ -461,7 +461,7 @@ TESTCASE(CViewContainerTest, DragEventData data; data.drag = nullptr; data.pos = CPoint (10, 10); - data.modifiers = 0; + data.modifiers.clear (); auto dropTarget = container->getDropTarget (); dropTarget->onDragEnter (data); @@ -490,7 +490,7 @@ TESTCASE(CViewContainerTest, DragEventData data; data.drag = nullptr; data.pos = CPoint (10, 10); - data.modifiers = 0; + data.modifiers.clear (); auto dropTarget = container->getDropTarget (); dropTarget->onDragEnter (data); diff --git a/vstgui/tools/imagestitcher/source/imageframesview.cpp b/vstgui/tools/imagestitcher/source/imageframesview.cpp index c2131cbd4..b0057a3b4 100644 --- a/vstgui/tools/imagestitcher/source/imageframesview.cpp +++ b/vstgui/tools/imagestitcher/source/imageframesview.cpp @@ -505,7 +505,7 @@ bool ImageFramesView::onDrop (DragEventData eventData) std::vector indices; if (getIndicesFromDataPackage (eventData.drag, &indices)) { - auto doCopy = (eventData.modifiers.getModifierState () & kAlt) != 0; + auto doCopy = eventData.modifiers.has (ModifierKey::Alt); reorderImages (dropPosition, doCopy, indices); } else @@ -556,7 +556,7 @@ DragOperation ImageFramesView::onDragMove (DragEventData eventData) dropIndicatorPos = newIndex; invalid (); } - auto doCopy = dragHasImages ? true : (eventData.modifiers.getModifierState () & kAlt); + auto doCopy = dragHasImages ? true : eventData.modifiers.has (ModifierKey::Alt); return doCopy ? DragOperation::Copy : DragOperation::Move; } return DragOperation::None; From 99bf656ad0c3646d4fa674df4a361d2a767f5c09 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 16:58:44 +0200 Subject: [PATCH 054/319] add getCurrentModifiers to IPlatformFrame --- vstgui/lib/platform/iplatformframe.h | 2 ++ vstgui/lib/platform/linux/x11frame.cpp | 6 ++++++ vstgui/lib/platform/linux/x11frame.h | 1 + vstgui/lib/platform/mac/cocoa/nsviewframe.h | 1 + vstgui/lib/platform/mac/cocoa/nsviewframe.mm | 7 +++++++ vstgui/lib/platform/win32/win32frame.h | 2 +- 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/vstgui/lib/platform/iplatformframe.h b/vstgui/lib/platform/iplatformframe.h index 1b38c184f..2fe67166a 100644 --- a/vstgui/lib/platform/iplatformframe.h +++ b/vstgui/lib/platform/iplatformframe.h @@ -31,6 +31,8 @@ class IPlatformFrame : public AtomicReferenceCounted virtual bool getCurrentMousePosition (CPoint& mousePosition) const = 0; /** get current mouse buttons out of event stream */ virtual bool getCurrentMouseButtons (CButtonState& buttons) const = 0; + /** get current hardware modifier key state */ + virtual bool getCurrentModifiers (Modifiers& modifiers) const = 0; /** set mouse cursor shape */ virtual bool setMouseCursor (CCursorType type) = 0; diff --git a/vstgui/lib/platform/linux/x11frame.cpp b/vstgui/lib/platform/linux/x11frame.cpp index c09a483ff..299a6c3bd 100644 --- a/vstgui/lib/platform/linux/x11frame.cpp +++ b/vstgui/lib/platform/linux/x11frame.cpp @@ -717,6 +717,12 @@ bool Frame::getCurrentMouseButtons (CButtonState& buttons) const return false; } +//------------------------------------------------------------------------ +bool Frame::getCurrentModifiers (Modifiers& modifiers) const +{ + return false; +} + //------------------------------------------------------------------------ bool Frame::setMouseCursor (CCursorType type) { diff --git a/vstgui/lib/platform/linux/x11frame.h b/vstgui/lib/platform/linux/x11frame.h index a78d8788a..0aa88477c 100644 --- a/vstgui/lib/platform/linux/x11frame.h +++ b/vstgui/lib/platform/linux/x11frame.h @@ -33,6 +33,7 @@ class Frame bool getSize (CRect& size) const override; bool getCurrentMousePosition (CPoint& mousePosition) const override; bool getCurrentMouseButtons (CButtonState& buttons) const override; + bool getCurrentModifiers (Modifiers& modifiers) const override; bool setMouseCursor (CCursorType type) override; bool invalidRect (const CRect& rect) override; bool scrollRect (const CRect& src, const CPoint& distance) override; diff --git a/vstgui/lib/platform/mac/cocoa/nsviewframe.h b/vstgui/lib/platform/mac/cocoa/nsviewframe.h index e8193fe29..a96962945 100644 --- a/vstgui/lib/platform/mac/cocoa/nsviewframe.h +++ b/vstgui/lib/platform/mac/cocoa/nsviewframe.h @@ -66,6 +66,7 @@ class NSViewFrame : public IPlatformFrame, public ICocoaPlatformFrame, public IP bool getSize (CRect& size) const override; bool getCurrentMousePosition (CPoint& mousePosition) const override; bool getCurrentMouseButtons (CButtonState& buttons) const override; + bool getCurrentModifiers (Modifiers& modifiers) const override; bool setMouseCursor (CCursorType type) override; bool invalidRect (const CRect& rect) override; bool scrollRect (const CRect& src, const CPoint& distance) override; diff --git a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm index df3a8e46f..9043348d6 100644 --- a/vstgui/lib/platform/mac/cocoa/nsviewframe.mm +++ b/vstgui/lib/platform/mac/cocoa/nsviewframe.mm @@ -1182,6 +1182,13 @@ static MouseEventButtonState buttonStateFromNSEvent (NSEvent* theEvent) return true; } +//----------------------------------------------------------------------------- +bool NSViewFrame::getCurrentModifiers (Modifiers& modifiers) const +{ + modifiers = modifiersFromModifierFlags (NSEvent.modifierFlags); + return true; +} + //----------------------------------------------------------------------------- bool NSViewFrame::setMouseCursor (CCursorType type) { diff --git a/vstgui/lib/platform/win32/win32frame.h b/vstgui/lib/platform/win32/win32frame.h index 3e41c217f..9b712ee14 100644 --- a/vstgui/lib/platform/win32/win32frame.h +++ b/vstgui/lib/platform/win32/win32frame.h @@ -27,7 +27,6 @@ class Win32Frame final : public IPlatformFrame, public IWin32PlatformFrame CCursorType getLastSetCursor () const { return lastSetCursor; } - bool getCurrentModifiers (Modifiers& modifiers) const; // IPlatformFrame bool getGlobalPosition (CPoint& pos) const override; @@ -35,6 +34,7 @@ class Win32Frame final : public IPlatformFrame, public IWin32PlatformFrame bool getSize (CRect& size) const override; bool getCurrentMousePosition (CPoint& mousePosition) const override; bool getCurrentMouseButtons (CButtonState& buttons) const override; + bool getCurrentModifiers (Modifiers& modifiers) const override; bool setMouseCursor (CCursorType type) override; bool invalidRect (const CRect& rect) override; bool scrollRect (const CRect& src, const CPoint& distance) override; From 18b3c95b7280da997f0d6e83aad897cf9b11e376 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 17:04:33 +0200 Subject: [PATCH 055/319] add missing return --- vstgui/uidescription/editing/uigradientscontroller.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/vstgui/uidescription/editing/uigradientscontroller.cpp b/vstgui/uidescription/editing/uigradientscontroller.cpp index c871ec2a9..c076a2e30 100644 --- a/vstgui/uidescription/editing/uigradientscontroller.cpp +++ b/vstgui/uidescription/editing/uigradientscontroller.cpp @@ -198,6 +198,7 @@ int32_t UIColorStopEditView::onKeyDown (VstKeyCode& keyCode) break; } } + return -1; } //---------------------------------------------------------------------------------------------------- From 0619f515b18750a8c60d9c317dfb60957c8f25cd Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 17:14:39 +0200 Subject: [PATCH 056/319] remove unused code comment --- vstgui/lib/platform/common/genericoptionmenu.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/vstgui/lib/platform/common/genericoptionmenu.h b/vstgui/lib/platform/common/genericoptionmenu.h index 35e909477..03b398a4d 100644 --- a/vstgui/lib/platform/common/genericoptionmenu.h +++ b/vstgui/lib/platform/common/genericoptionmenu.h @@ -55,8 +55,6 @@ class GenericOptionMenu : public IPlatformOptionMenu, public ViewListenerAdapter private: void removeModalView (PlatformOptionMenuResult result); void viewOnEvent (CView* view, Event& event) override; -// CMouseEventResult viewOnMouseDown (CView* view, CPoint pos, CButtonState buttons) override; -// CMouseEventResult viewOnMouseUp (CView* view, CPoint pos, CButtonState buttons) override; struct Impl; std::unique_ptr impl; From 7b5afea1533e061c0c4b7e1732d409cf408702b7 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 25 Apr 2021 17:45:56 +0200 Subject: [PATCH 057/319] a few left overs --- vstgui/lib/platform/win32/win32frame.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vstgui/lib/platform/win32/win32frame.cpp b/vstgui/lib/platform/win32/win32frame.cpp index a8ac2fe05..53617a9a2 100644 --- a/vstgui/lib/platform/win32/win32frame.cpp +++ b/vstgui/lib/platform/win32/win32frame.cpp @@ -324,6 +324,8 @@ bool Win32Frame::getCurrentModifiers (Modifiers& modifiers) const modifiers.add (ModifierKey::Control); if (GetAsyncKeyState (VK_MENU) < 0) modifiers.add (ModifierKey::Alt); + if (GetAsyncKeyState (VK_LWIN) < 0) + modifiers.add (ModifierKey::Super); return true; } @@ -643,8 +645,10 @@ static void setupMouseEventFromWParam (MouseEvent& event, WPARAM wParam) event.modifiers.add (ModifierKey::Control); if (wParam & MK_SHIFT) event.modifiers.add (ModifierKey::Shift); - if (GetAsyncKeyState (VK_MENU) < 0) + if (GetAsyncKeyState (VK_MENU) < 0) event.modifiers.add (ModifierKey::Alt); + if (GetAsyncKeyState (VK_LWIN) < 0) + event.modifiers.add (ModifierKey::Super); } //----------------------------------------------------------------------------- @@ -735,7 +739,7 @@ LONG_PTR WINAPI Win32Frame::proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM { MouseExitEvent event; getCurrentMousePosition (event.mousePosition); - // TODO: mouse button state + getCurrentModifiers (event.modifiers); pFrame->platformOnEvent (event); mouseInside = false; return 0; From 2e08898c67c1b95d0e94321dddd28b140a4b993a Mon Sep 17 00:00:00 2001 From: scheffle Date: Wed, 28 Apr 2021 12:22:02 +0200 Subject: [PATCH 058/319] move methods and add some documentation --- vstgui/lib/cview.h | 84 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/vstgui/lib/cview.h b/vstgui/lib/cview.h index c23657ad0..e3ed2a66a 100644 --- a/vstgui/lib/cview.h +++ b/vstgui/lib/cview.h @@ -85,43 +85,65 @@ class CView : public CBaseObject /// @name Event Handling Methods //----------------------------------------------------------------------------- //@{ + + /** dispatch an event + * + * the event is then dispatched to one of the event methods. + */ + virtual void dispatchEvent (Event& event); + + //@} + + //----------------------------------------------------------------------------- + /// @name Mouse Methods + //----------------------------------------------------------------------------- + //@{ + /** called when a mouse down event occurs */ virtual void onMouseDownEvent (MouseDownEvent& event); + /** called when a mouse move event occurs */ virtual void onMouseMoveEvent (MouseMoveEvent& event); + /** called when a mouse up event occurs */ virtual void onMouseUpEvent (MouseUpEvent& event); + /** called when mouse tracking should be canceled */ virtual void onMouseCancelEvent (MouseCancelEvent& event); + + /** called when the mouse enters this view */ virtual void onMouseEnterEvent (MouseEnterEvent& event); + /** called when the mouse leaves this view */ virtual void onMouseExitEvent (MouseExitEvent& event); + /** called when a mouse wheel event occurs */ virtual void onMouseWheelEvent (MouseWheelEvent& event); + /** called when a zoom gesture event occurs */ virtual void onZoomGestureEvent (ZoomGestureEvent& event); - virtual void onKeyboardEvent (KeyboardEvent& event); + /** turn on/off mouse usage for this view */ + virtual void setMouseEnabled (bool bEnable = true); + /** get the state of wheather this view uses the mouse or not */ + bool getMouseEnabled () const { return hasViewFlag (kMouseEnabled); } - virtual void dispatchEvent (Event& event); - //@} + /** set the area in which the view reacts to the mouse */ + virtual void setMouseableArea (const CRect& rect); + /** get the area in which the view reacts to the mouse */ + CRect getMouseableArea () const; //----------------------------------------------------------------------------- - /// @name Mouse Methods + // The following non deprecated mouse methods will still work for the next few years, + // but you should if possible refactor your own code to use the newer event methods //----------------------------------------------------------------------------- - //@{ - /** called when a mouse down event occurs */ + /** do not use any longer. if possible refactor your classes to use the newer mouse event methods above. */ virtual CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons); - /** called when a mouse up event occurs */ + /** do not use any longer. if possible refactor your classes to use the newer mouse event methods above. */ virtual CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons); - /** called when a mouse move event occurs */ + /** do not use any longer. if possible refactor your classes to use the newer mouse event methods above. */ virtual CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons); - /** called when mouse tracking should be canceled */ + /** do not use any longer. if possible refactor your classes to use the newer mouse event methods above. */ virtual CMouseEventResult onMouseCancel (); - - /** called when the mouse enters this view */ + /** do not use any longer. if possible refactor your classes to use the newer mouse event methods above. */ virtual CMouseEventResult onMouseEntered (CPoint& where, const CButtonState& buttons) {return kMouseEventNotImplemented;} - /** called when the mouse leaves this view */ + /** do not use any longer. if possible refactor your classes to use the newer mouse event methods above. */ virtual CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) {return kMouseEventNotImplemented;} - void setHitTestPath (CGraphicsPath* path); - /** check if where hits this view */ - virtual bool hitTest (const CPoint& where, const CButtonState& buttons = -1); - VSTGUI_DEPRECATED( /** \deprecated never called anymore, please use onMouseWheelEvent instead */ virtual bool onWheel (const CPoint& where, const float& distance, const CButtonState& buttons) final { return false; }) @@ -129,20 +151,25 @@ class CView : public CBaseObject /** \deprecated please use onMouseWheelEvent instead */ virtual bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons);, "Use CView::onMouseWheelEvent instead") - /** turn on/off mouse usage for this view */ - virtual void setMouseEnabled (bool bEnable = true); - /** get the state of wheather this view uses the mouse or not */ - bool getMouseEnabled () const { return hasViewFlag (kMouseEnabled); } - - /** set the area in which the view reacts to the mouse */ - void setMouseableArea (const CRect& rect); VSTGUI_DEPRECATED( /** get the area in which the view reacts to the mouse */ CRect& getMouseableArea (CRect& rect) const;) - /** get the area in which the view reacts to the mouse */ - CRect getMouseableArea () const; //@} + //----------------------------------------------------------------------------- + /// @name Hit testing Methods + //----------------------------------------------------------------------------- + //@{ + void setHitTestPath (CGraphicsPath* path); + /** check if where hits this view + * + * the default behaviour is to return true if where is inside the view size of this view, but if you set a hit test path + * the path is checked if the point lies in its boundaries. + */ + virtual bool hitTest (const CPoint& where, const CButtonState& buttons = -1); + //@} + + #if VSTGUI_TOUCH_EVENT_HANDLING //----------------------------------------------------------------------------- /// @name Touch Event Handling Methods @@ -173,6 +200,13 @@ class CView : public CBaseObject /// @name Keyboard Methods //----------------------------------------------------------------------------- //@{ + + /** called when a keyboard event is dispatched to this view + * + * This happens normally only if the view is the focus view. + */ + virtual void onKeyboardEvent (KeyboardEvent& event); + VSTGUI_DEPRECATED_MSG( /** called if a key down event occurs and this view has focus */ virtual int32_t onKeyDown (VstKeyCode& keyCode);, "Use CView::onKeyboardEvent instead") From edb9d9fc6b20074df226fd3f81f2296accacccb5 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 2 May 2021 11:54:49 +0200 Subject: [PATCH 059/319] add OldKeyboardHookAdapter --- vstgui/doxygen/page_changes.h | 4 ++-- vstgui/lib/cframe.cpp | 18 ++++++++++++++++++ vstgui/lib/cframe.h | 12 ++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/vstgui/doxygen/page_changes.h b/vstgui/doxygen/page_changes.h index 835d150fc..87febd1d5 100644 --- a/vstgui/doxygen/page_changes.h +++ b/vstgui/doxygen/page_changes.h @@ -117,8 +117,8 @@ Note: All current deprecated methods will be removed in the next version. So mak @subsection code_changes_4_10_to_4_11 VSTGUI 4.10 -> VSTGUI 4.11 Changes due to event handling rework: -- IKeyboardHook changed its methods. If you inherit from it, you need to adopt to the new methods -- CViewContainer::onWheel is now marked final, you cannot inherit this method, please use the new CView::onMouseWheelEvent instead +- IKeyboardHook changed its methods. If you inherit from it, you need to adopt to the new methods or use OldKeyboardHookAdapter +- CViewContainer::onWheel is now marked final, you cannot inherit this method, please override the new CView::onMouseWheelEvent instead if you need to handle mouse wheel events in a custom view container CView has the following new methods: - dispatchEvent diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index e17f57494..b56741932 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -1932,4 +1932,22 @@ void CFrame::CollectInvalidRects::addRect (const CRect& rect) } } +#if VSTGUI_ENABLE_DEPRECATED_METHODS +//----------------------------------------------------------------------------- +void OldKeyboardHookAdapter::onKeyboardEvent (KeyboardEvent& event, CFrame* frame) +{ + auto vstKeyCode = toVstKeyCode (event); + if (event.type == EventType::KeyDown) + { + if (onKeyDown (vstKeyCode, frame) != -1) + event.consumed = true; + } + else + { + if (onKeyUp (vstKeyCode, frame) != -1) + event.consumed = true; + } +} +#endif + } // VSTGUI diff --git a/vstgui/lib/cframe.h b/vstgui/lib/cframe.h index 8cc597303..c910581be 100644 --- a/vstgui/lib/cframe.h +++ b/vstgui/lib/cframe.h @@ -326,6 +326,18 @@ class IKeyboardHook virtual void onKeyboardEvent (KeyboardEvent& event, CFrame* frame) = 0; }; +#if VSTGUI_ENABLE_DEPRECATED_METHODS +//------------------------------------------------------------------------ +class OldKeyboardHookAdapter : public IKeyboardHook +{ +public: + virtual int32_t onKeyDown (const VstKeyCode& code, CFrame* frame) = 0; + virtual int32_t onKeyUp (const VstKeyCode& code, CFrame* frame) = 0; +private: + void onKeyboardEvent (KeyboardEvent& event, CFrame* frame) override; +}; +#endif + //----------------------------------------------------------------------------- // IViewAddedRemovedObserver Declaration //! @brief view added removed observer interface for CFrame From f7d86d2055033bef9344d254a6c99a74dbef9372 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 2 May 2021 11:55:20 +0200 Subject: [PATCH 060/319] add macro to conditionally compile for newer vstgui versions --- vstgui/lib/vstguibase.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vstgui/lib/vstguibase.h b/vstgui/lib/vstguibase.h index 7cc47520c..d4565d8d4 100644 --- a/vstgui/lib/vstguibase.h +++ b/vstgui/lib/vstguibase.h @@ -536,6 +536,12 @@ struct BitScopeToggleT B bit; }; +//----------------------------------------------------------------------------- +#define VSTGUI_NEWER_THAN(major, minor) \ + (VSTGUI_VERSION > major || VSTGUI_VERSION_MAJOR == major && VSTGUI_VERSION_MINOR > minor) + +#define VSTGUI_NEWER_THAN_4_10 VSTGUI_NEWER_THAN (4, 10) + } // VSTGUI //----------------------------------------------------------------------------- From 7a8b437b7c5f76f7e15d269e7130e1a531640eae Mon Sep 17 00:00:00 2001 From: scheffle Date: Fri, 7 May 2021 09:09:54 +0200 Subject: [PATCH 061/319] add double click to old button state --- vstgui/lib/events.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index e2b36fdba..cd08a6dc1 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -501,6 +501,26 @@ inline MouseEvent* asMouseEvent (Event& event) return nullptr; } +//------------------------------------------------------------------------ +/** event as mouse down event or nullpointer if not a mouse down event + * @ingroup new_in_4_11 + */ +inline MouseDownEvent* asMouseDownEvent (Event& event) +{ + switch (event.type) + { + case EventType::MouseDown: + [[fallthrough]]; + case EventType::MouseMove: + [[fallthrough]]; + case EventType::MouseUp: + return static_cast (&event); + default: + break; + } + return nullptr; +} + //------------------------------------------------------------------------ /** event as modifier event or nullpointer if not a modifier event * @ingroup new_in_4_11 @@ -659,7 +679,7 @@ inline KeyboardEvent& castKeyboardEvent (Event& event) /** helper function to convert from new Modifiers to old CButtonState * @ingroup new_in_4_11 */ -inline CButtonState buttonStateFromEventModifiers (const Modifiers& mods) +inline CButtonState buttonStateFromEventModifiers (Modifiers& mods) { CButtonState state; if (mods.has (ModifierKey::Control)) @@ -672,7 +692,7 @@ inline CButtonState buttonStateFromEventModifiers (const Modifiers& mods) } //------------------------------------------------------------------------ -inline CButtonState buttonStateFromMouseEvent (const MouseEvent& event) +inline CButtonState buttonStateFromMouseEvent (MouseEvent& event) { CButtonState state = buttonStateFromEventModifiers (event.modifiers); if (event.buttonState.has (MouseEventButtonState::Left)) @@ -685,6 +705,11 @@ inline CButtonState buttonStateFromMouseEvent (const MouseEvent& event) state |= kButton4; if (event.buttonState.has (MouseEventButtonState::Fifth)) state |= kButton5; + if (auto downEvent = asMouseDownEvent (event)) + { + if (downEvent->clickCount > 1) + state |= kDoubleClick; + } return state; } From 74213d15fc8a8b79e88d7c4b23b1a5151e850ca2 Mon Sep 17 00:00:00 2001 From: scheffle Date: Fri, 7 May 2021 09:20:31 +0200 Subject: [PATCH 062/319] fix two wrong event consume handlings --- vstgui/lib/cframe.cpp | 2 +- vstgui/lib/cview.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index b56741932..ff7e87b00 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -1529,7 +1529,7 @@ void CFrame::dispatchKeyboardEventToHooks (KeyboardEvent& event) pImpl->keyboardHooks.forEachReverse ( [&] (IKeyboardHook* hook) { hook->onKeyboardEvent (event, this); - return !event.consumed; + return event.consumed; }, [] (bool consumed) { return consumed; }); } diff --git a/vstgui/lib/cview.cpp b/vstgui/lib/cview.cpp index 14f8bf676..c6278d43d 100644 --- a/vstgui/lib/cview.cpp +++ b/vstgui/lib/cview.cpp @@ -660,6 +660,8 @@ void CView::dispatchEvent (Event& event) return event.consumed; }, [] (bool consumed) { return consumed; }); + if (event.consumed) + return; } switch (event.type) From 289e17c72859b9c1d244bb7986d5500b8dfb65c1 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 9 May 2021 16:23:23 +0200 Subject: [PATCH 063/319] update list control to use new keyboard event method --- vstgui/lib/controls/clistcontrol.cpp | 43 ++++---- vstgui/lib/controls/clistcontrol.h | 2 +- vstgui/lib/events.h | 2 + .../lib/controls/clistcontrol_test.cpp | 102 ++++++++++++------ 4 files changed, 94 insertions(+), 55 deletions(-) diff --git a/vstgui/lib/controls/clistcontrol.cpp b/vstgui/lib/controls/clistcontrol.cpp index 888d61a6f..121c26447 100644 --- a/vstgui/lib/controls/clistcontrol.cpp +++ b/vstgui/lib/controls/clistcontrol.cpp @@ -7,6 +7,7 @@ #include "../cframe.h" #include "../cgraphicspath.h" #include "../cscrollview.h" +#include "../events.h" #include "clistcontrol.h" #include @@ -351,48 +352,51 @@ bool CListControl::rowSelectable (int32_t row) const } //------------------------------------------------------------------------ -int32_t CListControl::onKeyDown (VstKeyCode& keyCode) +void CListControl::onKeyboardEvent (KeyboardEvent& event) { - if (getMouseEnabled () && keyCode.character == 0) + if (event.type != EventType::KeyDown) + return; + if (getMouseEnabled () && event.character == 0) { int32_t newRow = getIntValue (); - switch (keyCode.virt) + switch (event.virt) { - case VKEY_HOME: + default: return; + case VirtualKey::Home: { - if (keyCode.modifier != 0) + if (!event.modifiers.empty ()) break; newRow = getMinRowIndex (); if (!rowSelectable (newRow)) newRow = getNextSelectableRow (newRow, 1); break; } - case VKEY_END: + case VirtualKey::End: { - if (keyCode.modifier != 0) + if (!event.modifiers.empty ()) break; newRow = getMaxRowIndex (); if (!rowSelectable (newRow)) newRow = getNextSelectableRow (newRow, -1); break; } - case VKEY_UP: + case VirtualKey::Up: { - if (keyCode.modifier != 0) + if (!event.modifiers.empty ()) break; newRow = getNextSelectableRow (newRow, -1); break; } - case VKEY_DOWN: + case VirtualKey::Down: { - if (keyCode.modifier != 0) + if (!event.modifiers.empty ()) break; newRow = getNextSelectableRow (newRow, 1); break; } - case VKEY_PAGEUP: + case VirtualKey::PageUp: { - if (keyCode.modifier != 0) + if (!event.modifiers.empty ()) break; auto vr = getVisibleViewSize (); auto rr = getRowRect (newRow); @@ -403,7 +407,8 @@ int32_t CListControl::onKeyDown (VstKeyCode& keyCode) if (auto scrollView = dynamic_cast (parent->getParentView ())) { scrollView->makeRectVisible (*rr); - return onKeyDown (keyCode); + onKeyboardEvent (event); + return; } } } @@ -427,9 +432,9 @@ int32_t CListControl::onKeyDown (VstKeyCode& keyCode) newRow = getNextSelectableRow (newRow, -1); break; } - case VKEY_PAGEDOWN: + case VirtualKey::PageDown: { - if (keyCode.modifier != 0) + if (!event.modifiers.empty ()) break; auto vr = getVisibleViewSize (); auto rr = getRowRect (newRow); @@ -440,7 +445,8 @@ int32_t CListControl::onKeyDown (VstKeyCode& keyCode) if (auto scrollView = dynamic_cast (parent->getParentView ())) { scrollView->makeRectVisible (*rr); - return onKeyDown (keyCode); + onKeyboardEvent (event); + return; } } } @@ -481,10 +487,9 @@ int32_t CListControl::onKeyDown (VstKeyCode& keyCode) scrollView->makeRectVisible (*rowRect); } } - return 1; + event.consumed = true; } } - return -1; } //------------------------------------------------------------------------ diff --git a/vstgui/lib/controls/clistcontrol.h b/vstgui/lib/controls/clistcontrol.h index 9b2d0b1da..d4e6d773e 100644 --- a/vstgui/lib/controls/clistcontrol.h +++ b/vstgui/lib/controls/clistcontrol.h @@ -56,7 +56,7 @@ class CListControl final : public CControl CMouseEventResult onMouseMoved (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseUp (CPoint& where, const CButtonState& buttons) override; CMouseEventResult onMouseExited (CPoint& where, const CButtonState& buttons) override; - int32_t onKeyDown (VstKeyCode& keyCode) override; + void onKeyboardEvent (KeyboardEvent& event) override; void setViewSize (const CRect& rect, bool invalid = true) override; bool drawFocusOnTop () override; bool getFocusPath (CGraphicsPath& outPath) override; diff --git a/vstgui/lib/events.h b/vstgui/lib/events.h index cd08a6dc1..f97089253 100644 --- a/vstgui/lib/events.h +++ b/vstgui/lib/events.h @@ -431,6 +431,8 @@ enum class ModifierKey : uint32_t /** the super key (Control key on macOS, Windows key on Windows and Super key on other platforms)*/ Super = 1 << 3, + + None = 0 }; //------------------------------------------------------------------------ diff --git a/vstgui/tests/unittest/lib/controls/clistcontrol_test.cpp b/vstgui/tests/unittest/lib/controls/clistcontrol_test.cpp index 7a51521f8..2fc3a2ea5 100644 --- a/vstgui/tests/unittest/lib/controls/clistcontrol_test.cpp +++ b/vstgui/tests/unittest/lib/controls/clistcontrol_test.cpp @@ -4,7 +4,7 @@ #include "../../../../lib/controls/clistcontrol.h" #include "../../../../lib/cscrollview.h" -#include "../../../../lib/vstkeycode.h" +#include "../../../../lib/events.h" #include "../../unittests.h" //------------------------------------------------------------------------ @@ -40,9 +40,14 @@ static SharedPointer createScrollViewAndEmbedListControl (CViewCont } //------------------------------------------------------------------------ -static VstKeyCode makeKeyCode (int32_t c, unsigned char virt, unsigned char modifier) +static KeyboardEvent makeKeyboardEvent (int32_t c, VirtualKey virt, ModifierKey modifier = ModifierKey::None) { - return {c, virt, modifier}; + KeyboardEvent event; + event.type = EventType::KeyDown; + event.character = c; + event.virt = virt; + event.modifiers.add (modifier); + return event; } //------------------------------------------------------------------------ @@ -122,8 +127,9 @@ TESTCASE(CListControlTest, listControl->setValue (2.f); EXPECT (listControl->getValue () == 2.f); - auto code = makeKeyCode (0, VKEY_DOWN, 0); - EXPECT (listControl->onKeyDown (code) == -1); + auto event = makeKeyboardEvent (0, VirtualKey::Down); + listControl->onKeyboardEvent (event); + EXPECT (event.consumed == false); EXPECT (listControl->getValue () == 2.f); ); @@ -134,28 +140,34 @@ TESTCASE(CListControlTest, listControl->setValue (1.f); - auto code = makeKeyCode (0, VKEY_DOWN, MODIFIER_SHIFT); - EXPECT (listControl->onKeyDown (code) == -1); + auto event = makeKeyboardEvent (0, VirtualKey::Down, ModifierKey::Shift); + listControl->onKeyboardEvent (event); + EXPECT (event.consumed == false); EXPECT (listControl->getValue () == 1.f); - code = makeKeyCode (0, VKEY_UP, MODIFIER_SHIFT); - EXPECT (listControl->onKeyDown (code) == -1); + event = makeKeyboardEvent (0, VirtualKey::Up, ModifierKey::Shift); + listControl->onKeyboardEvent (event); + EXPECT (event.consumed == false); EXPECT (listControl->getValue () == 1.f); - code = makeKeyCode (0, VKEY_HOME, MODIFIER_SHIFT); - EXPECT (listControl->onKeyDown (code) == -1); + event = makeKeyboardEvent (0, VirtualKey::Home, ModifierKey::Shift); + listControl->onKeyboardEvent (event); + EXPECT (event.consumed == false); EXPECT (listControl->getValue () == 1.f); - code = makeKeyCode (0, VKEY_END, MODIFIER_SHIFT); - EXPECT (listControl->onKeyDown (code) == -1); + event = makeKeyboardEvent (0, VirtualKey::End, ModifierKey::Shift); + listControl->onKeyboardEvent (event); + EXPECT (event.consumed == false); EXPECT (listControl->getValue () == 1.f); - code = makeKeyCode (0, VKEY_PAGEUP, MODIFIER_SHIFT); - EXPECT (listControl->onKeyDown (code) == -1); + event = makeKeyboardEvent (0, VirtualKey::PageUp, ModifierKey::Shift); + listControl->onKeyboardEvent (event); + EXPECT (event.consumed == false); EXPECT (listControl->getValue () == 1.f); - code = makeKeyCode (0, VKEY_PAGEDOWN, MODIFIER_SHIFT); - EXPECT (listControl->onKeyDown (code) == -1); + event = makeKeyboardEvent (0, VirtualKey::PageDown, ModifierKey::Shift); + listControl->onKeyboardEvent (event); + EXPECT (event.consumed == false); EXPECT (listControl->getValue () == 1.f); ); @@ -165,8 +177,9 @@ TESTCASE(CListControlTest, listControl->setValue (5.f); EXPECT (listControl->getValue () == 5.f); - auto code = makeKeyCode (0, VKEY_HOME, 0); - EXPECT (listControl->onKeyDown (code) == 1); + auto event = makeKeyboardEvent (0, VirtualKey::Home); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 0.f); ); @@ -177,8 +190,9 @@ TESTCASE(CListControlTest, listControl->setValue (0.f); EXPECT (listControl->getValue () == 0.f); - auto code = makeKeyCode (0, VKEY_END, 0); - EXPECT (listControl->onKeyDown (code) == 1); + auto event = makeKeyboardEvent (0, VirtualKey::End); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == numRows); ); @@ -189,12 +203,15 @@ TESTCASE(CListControlTest, listControl->setValue (2.f); EXPECT (listControl->getValue () == 2.f); - auto code = makeKeyCode (0, VKEY_UP, 0); - EXPECT (listControl->onKeyDown (code) == 1); + auto event = makeKeyboardEvent (0, VirtualKey::Up); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 1.f); + event.consumed.reset (); listControl->setValue (0.f); - EXPECT (listControl->onKeyDown (code) == 1); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == numRows); ); @@ -205,12 +222,15 @@ TESTCASE(CListControlTest, listControl->setValue (2.f); EXPECT (listControl->getValue () == 2.f); - auto code = makeKeyCode (0, VKEY_DOWN, 0); - EXPECT (listControl->onKeyDown (code) == 1); + auto event = makeKeyboardEvent (0, VirtualKey::Down); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 3.f); + event.consumed.reset (); listControl->setValue (numRows); - EXPECT (listControl->onKeyDown (code) == 1); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 0.f); ); @@ -224,14 +244,20 @@ TESTCASE(CListControlTest, auto rect = listControl->getRowRect (0); scrollView->makeRectVisible (*rect); - auto code = makeKeyCode (0, VKEY_PAGEUP, 0); - EXPECT (listControl->onKeyDown (code) == 1); + auto event = makeKeyboardEvent (0, VirtualKey::PageUp); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 15.f); + event.consumed.reset (); + listControl->setValue (16); - EXPECT (listControl->onKeyDown (code) == 1); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 15.f); + event.consumed.reset (); - EXPECT (listControl->onKeyDown (code) == 1); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 0.f); scrollView->removed (parent); @@ -248,14 +274,20 @@ TESTCASE(CListControlTest, auto rect = listControl->getRowRect (numRows); scrollView->makeRectVisible (*rect); - auto code = makeKeyCode (0, VKEY_PAGEDOWN, 0); - EXPECT (listControl->onKeyDown (code) == 1); + auto event = makeKeyboardEvent (0, VirtualKey::PageDown); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 15.f); + event.consumed.reset (); + listControl->setValue (14); - EXPECT (listControl->onKeyDown (code) == 1); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 15.f); + event.consumed.reset (); - EXPECT (listControl->onKeyDown (code) == 1); + listControl->onKeyboardEvent (event); + EXPECT(event.consumed == true); EXPECT (listControl->getValue () == 30.f); scrollView->removed (parent); From 55f3fe42cf8b78bb948dd0cdfc59b579d8135bdb Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 9 May 2021 16:31:31 +0200 Subject: [PATCH 064/319] fix keyboard page navigation when the first/last visible row is not selectable --- vstgui/lib/controls/clistcontrol.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vstgui/lib/controls/clistcontrol.cpp b/vstgui/lib/controls/clistcontrol.cpp index 121c26447..60b8078b2 100644 --- a/vstgui/lib/controls/clistcontrol.cpp +++ b/vstgui/lib/controls/clistcontrol.cpp @@ -415,6 +415,8 @@ void CListControl::onKeyboardEvent (KeyboardEvent& event) vr.top += 2; if (auto firstVisibleRow = getRowAtPoint (vr.getTopLeft ())) { + while (!rowSelectable (*firstVisibleRow)) + *firstVisibleRow += 1; if (*firstVisibleRow == getIntValue ()) { vr.offset (0, -vr.getHeight ()); @@ -453,6 +455,8 @@ void CListControl::onKeyboardEvent (KeyboardEvent& event) vr.bottom -= 2; if (auto lastVisibleRow = getRowAtPoint (vr.getBottomLeft ())) { + while (!rowSelectable (*lastVisibleRow)) + *lastVisibleRow -= 1; if (*lastVisibleRow == getIntValue ()) { vr.offset (0, vr.getHeight ()); From a378a9bf0c654535956bf269d60b0a9d31c32e26 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 9 May 2021 16:33:44 +0200 Subject: [PATCH 065/319] change databrowser delegate to use keyboard event instead of vstkeycode --- vstgui/lib/cdatabrowser.cpp | 34 +++++++++++++++---------------- vstgui/lib/cdatabrowser.h | 2 +- vstgui/lib/idatabrowserdelegate.h | 17 ++++++++++++++-- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/vstgui/lib/cdatabrowser.cpp b/vstgui/lib/cdatabrowser.cpp index 5efde14bd..ab1d246a3 100644 --- a/vstgui/lib/cdatabrowser.cpp +++ b/vstgui/lib/cdatabrowser.cpp @@ -36,7 +36,7 @@ class CDataBrowserView : public CView, public IFocusDrawing, public IDropTarget void onDragLeave (DragEventData data) override; bool onDrop (DragEventData data) override; - int32_t onKeyDown (VstKeyCode& keyCode) override; + void onKeyboardEvent (KeyboardEvent& keyCode) override; CRect getRowBounds (int32_t row); void invalidateRow (int32_t row); @@ -160,10 +160,11 @@ bool CDataBrowser::removed (CView* parent) return CScrollView::removed (parent); } -//----------------------------------------------------------------------------------------------- -int32_t CDataBrowser::onKeyDown (VstKeyCode& keyCode) +//------------------------------------------------------------------------ +void CDataBrowser::onKeyboardEvent (KeyboardEvent& event) { - return dbView ? dbView->onKeyDown (keyCode) : -1; + if (dbView) + dbView->onKeyboardEvent (event); } //----------------------------------------------------------------------------- @@ -1054,25 +1055,25 @@ DragOperation CDataBrowserView::onDragMove (DragEventData data) } //----------------------------------------------------------------------------------------------- -int32_t CDataBrowserView::onKeyDown (VstKeyCode& keyCode) +void CDataBrowserView::onKeyboardEvent (KeyboardEvent& event) { - int32_t res = db->dbOnKeyDown (keyCode, browser); - if (res != -1) - return res; - if (keyCode.modifier != 0) - return -1; - if (keyCode.virt == VKEY_UP || keyCode.virt == VKEY_DOWN || keyCode.virt == VKEY_PAGEUP || keyCode.virt == VKEY_PAGEDOWN) + db->dbOnKeyboardEvent (event, browser); + if (event.consumed || event.type != EventType::KeyDown) + return; + if (!event.modifiers.empty ()) + return; + if (event.virt == VirtualKey::Up || event.virt == VirtualKey::Down || event.virt == VirtualKey::PageUp || event.virt == VirtualKey::PageDown) { int32_t numRows = db->dbGetNumRows (browser); int32_t selRow = browser->getSelectedRow (); int32_t changeRow = 0; - if (keyCode.virt == VKEY_UP) + if (event.virt == VirtualKey::Up) changeRow = -1; - else if (keyCode.virt == VKEY_DOWN) + else if (event.virt == VirtualKey::Down) changeRow = 1; - else if (keyCode.virt == VKEY_PAGEUP) + else if (event.virt == VirtualKey::PageUp) changeRow = (int32_t) (-browser->getHeight () / db->dbGetRowHeight (browser)); - else if (keyCode.virt == VKEY_PAGEDOWN) + else if (event.virt == VirtualKey::PageDown) changeRow = (int32_t) (browser->getHeight () / db->dbGetRowHeight (browser)); int32_t newSelRow = selRow + changeRow; newSelRow = std::min (newSelRow, numRows); @@ -1085,9 +1086,8 @@ int32_t CDataBrowserView::onKeyDown (VstKeyCode& keyCode) CRect rect = getRowBounds (newSelRow); browser->makeRectVisible (rect); } - return 1; + event.consumed = true; } - return -1; } //----------------------------------------------------------------------------------------------- diff --git a/vstgui/lib/cdatabrowser.h b/vstgui/lib/cdatabrowser.h index b45a7d531..788c00fcc 100644 --- a/vstgui/lib/cdatabrowser.h +++ b/vstgui/lib/cdatabrowser.h @@ -105,7 +105,7 @@ class CDataBrowser : public CScrollView void setViewSize (const CRect& size, bool invalid) override; void setWantsFocus (bool state) override; - int32_t onKeyDown (VstKeyCode& keyCode) override; + void onKeyboardEvent (KeyboardEvent& event) override; CMouseEventResult onMouseDown (CPoint& where, const CButtonState& buttons) override; protected: ~CDataBrowser () noexcept override; diff --git a/vstgui/lib/idatabrowserdelegate.h b/vstgui/lib/idatabrowserdelegate.h index 2459d9190..703c500af 100644 --- a/vstgui/lib/idatabrowserdelegate.h +++ b/vstgui/lib/idatabrowserdelegate.h @@ -5,7 +5,10 @@ #pragma once #include "dragging.h" +#if VSTGUI_ENABLE_DEPRECATED_METHODS #include "vstkeycode.h" +#include "events.h" +#endif //------------------------------------------------------------------------ namespace VSTGUI { @@ -105,7 +108,7 @@ class IDataBrowserDelegate /** @name Keyboard Handling */ /// @{ - virtual int32_t dbOnKeyDown (const VstKeyCode& key, CDataBrowser* browser) = 0; + virtual void dbOnKeyboardEvent (KeyboardEvent& event, CDataBrowser* browser) = 0; /// @} virtual ~IDataBrowserDelegate () noexcept = default; @@ -187,7 +190,17 @@ class DataBrowserDelegateAdapter : public IDataBrowserDelegate CDataBrowser* browser) override { } - int32_t dbOnKeyDown (const VstKeyCode& key, CDataBrowser* browser) override { return -1; } + void dbOnKeyboardEvent (KeyboardEvent& event, CDataBrowser* browser) override + { +#if VSTGUI_ENABLE_DEPRECATED_METHODS + if (dbOnKeyDown (toVstKeyCode (event), browser) != -1) + event.consumed = true; +#endif + } + +#if VSTGUI_ENABLE_DEPRECATED_METHODS + virtual int32_t dbOnKeyDown (const VstKeyCode& keyCode, CDataBrowser* browser) { return -1; } +#endif }; //------------------------------------------------------------------------ From ad6f0e6c4074c8ad409cff7ad8fd0fc0f8ae4a7c Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 9 May 2021 16:59:22 +0200 Subject: [PATCH 066/319] use pimpl for CMenuItem --- vstgui/lib/controls/coptionmenu.cpp | 121 ++++++++++++++++++++++++---- vstgui/lib/controls/coptionmenu.h | 37 ++++----- 2 files changed, 123 insertions(+), 35 deletions(-) diff --git a/vstgui/lib/controls/coptionmenu.cpp b/vstgui/lib/controls/coptionmenu.cpp index 2af12039e..af2d61f9a 100644 --- a/vstgui/lib/controls/coptionmenu.cpp +++ b/vstgui/lib/controls/coptionmenu.cpp @@ -13,12 +13,35 @@ namespace VSTGUI { +//------------------------------------------------------------------------ +struct CMenuItem::Impl +{ + UTF8String title; + UTF8String keyCode; + SharedPointer submenu; + SharedPointer icon; + int32_t flags {0}; + int32_t keyModifiers {0}; + int32_t virtualKeyCode {0}; + int32_t tag {-1}; +}; + //------------------------------------------------------------------------ // CMenuItem //------------------------------------------------------------------------ /*! @class CMenuItem Defines an item of a VSTGUI::COptionMenu */ + +//------------------------------------------------------------------------ +CMenuItem::CMenuItem () +{ + impl = std::make_unique (); +} + +//------------------------------------------------------------------------ +CMenuItem::~CMenuItem () noexcept = default; + //------------------------------------------------------------------------ /** * CMenuItem constructor. @@ -30,8 +53,9 @@ Defines an item of a VSTGUI::COptionMenu */ //------------------------------------------------------------------------ CMenuItem::CMenuItem (const UTF8String& inTitle, const UTF8String& inKeycode, int32_t inKeyModifiers, CBitmap* inIcon, int32_t inFlags) -: flags (inFlags) +: CMenuItem () { + impl->flags = inFlags; setTitle (inTitle); setKey (inKeycode, inKeyModifiers); setIcon (inIcon); @@ -46,6 +70,7 @@ CMenuItem::CMenuItem (const UTF8String& inTitle, const UTF8String& inKeycode, in */ //------------------------------------------------------------------------ CMenuItem::CMenuItem (const UTF8String& inTitle, COptionMenu* inSubmenu, CBitmap* inIcon) +: CMenuItem () { setTitle (inTitle); setSubmenu (inSubmenu); @@ -60,6 +85,7 @@ CMenuItem::CMenuItem (const UTF8String& inTitle, COptionMenu* inSubmenu, CBitmap */ //------------------------------------------------------------------------ CMenuItem::CMenuItem (const UTF8String& inTitle, int32_t inTag) +: CMenuItem () { setTitle (inTitle); setTag (inTag); @@ -72,8 +98,9 @@ CMenuItem::CMenuItem (const UTF8String& inTitle, int32_t inTag) */ //------------------------------------------------------------------------ CMenuItem::CMenuItem (const CMenuItem& item) -: flags (item.flags) +: CMenuItem () { + impl->flags = item.impl->flags; setTitle (item.getTitle ()); setIcon (item.getIcon ()); if (item.getVirtualKeyCode ()) @@ -87,64 +114,130 @@ CMenuItem::CMenuItem (const CMenuItem& item) //------------------------------------------------------------------------ void CMenuItem::setTitle (const UTF8String& inTitle) { - title = inTitle; + impl->title = inTitle; } //------------------------------------------------------------------------ void CMenuItem::setKey (const UTF8String& inKeycode, int32_t inKeyModifiers) { - keyCode = inKeycode; - keyModifiers = inKeyModifiers; - virtualKeyCode = 0; + impl->keyCode = inKeycode; + impl->keyModifiers = inKeyModifiers; + impl->virtualKeyCode = 0; } //------------------------------------------------------------------------ void CMenuItem::setVirtualKey (int32_t inVirtualKeyCode, int32_t inKeyModifiers) { setKey (nullptr, inKeyModifiers); - virtualKeyCode = inVirtualKeyCode; + impl->virtualKeyCode = inVirtualKeyCode; } //------------------------------------------------------------------------ void CMenuItem::setSubmenu (COptionMenu* inSubmenu) { - submenu = inSubmenu; + impl->submenu = inSubmenu; } //------------------------------------------------------------------------ void CMenuItem::setIcon (CBitmap* inIcon) { - icon = inIcon; + impl->icon = inIcon; } //------------------------------------------------------------------------ void CMenuItem::setTag (int32_t t) { - tag = t; + impl->tag = t; } //------------------------------------------------------------------------ void CMenuItem::setEnabled (bool state) { - setBit (flags, kDisabled, !state); + setBit (impl->flags, kDisabled, !state); } //------------------------------------------------------------------------ void CMenuItem::setChecked (bool state) { - setBit (flags, kChecked, state); + setBit (impl->flags, kChecked, state); } //------------------------------------------------------------------------ void CMenuItem::setIsTitle (bool state) { - setBit (flags, kTitle, state); + setBit (impl->flags, kTitle, state); } //------------------------------------------------------------------------ void CMenuItem::setIsSeparator (bool state) { - setBit (flags, kSeparator, state); + setBit (impl->flags, kSeparator, state); +} + +//------------------------------------------------------------------------ +bool CMenuItem::isEnabled () const +{ + return !hasBit (impl->flags, kDisabled); +} + +//------------------------------------------------------------------------ +bool CMenuItem::isChecked () const +{ + return hasBit (impl->flags, kChecked); +} + +//------------------------------------------------------------------------ +bool CMenuItem::isTitle () const +{ + return hasBit (impl->flags, kTitle); +} + +//------------------------------------------------------------------------ +bool CMenuItem::isSeparator () const +{ + return hasBit (impl->flags, kSeparator); +} + +//------------------------------------------------------------------------ +const UTF8String& CMenuItem::getTitle () const +{ + return impl->title; +} + +//------------------------------------------------------------------------ +int32_t CMenuItem::getKeyModifiers () const +{ + return impl->keyModifiers; +} + +//------------------------------------------------------------------------ +const UTF8String& CMenuItem::getKeycode () const +{ + return impl->keyCode; +} + +//------------------------------------------------------------------------ +int32_t CMenuItem::getVirtualKeyCode () const +{ + return impl->virtualKeyCode; +} + +//------------------------------------------------------------------------ +COptionMenu* CMenuItem::getSubmenu () const +{ + return impl->submenu; +} + +//------------------------------------------------------------------------ +CBitmap* CMenuItem::getIcon () const +{ + return impl->icon; +} + +//------------------------------------------------------------------------ +int32_t CMenuItem::getTag () const +{ + return impl->tag; } //------------------------------------------------------------------------ diff --git a/vstgui/lib/controls/coptionmenu.h b/vstgui/lib/controls/coptionmenu.h index de0aa36ae..2d2bbecbd 100644 --- a/vstgui/lib/controls/coptionmenu.h +++ b/vstgui/lib/controls/coptionmenu.h @@ -65,42 +65,37 @@ class CMenuItem : public CBaseObject virtual void setTag (int32_t tag); /** returns whether the item is enabled or not */ - bool isEnabled () const { return !hasBit (flags, kDisabled); } + bool isEnabled () const; /** returns whether the item is checked or not */ - bool isChecked () const { return hasBit (flags, kChecked); } + bool isChecked () const; /** returns whether the item is a title item or not */ - bool isTitle () const { return hasBit (flags, kTitle); } + bool isTitle () const; /** returns whether the item is a separator or not */ - bool isSeparator () const { return hasBit (flags, kSeparator); } + bool isSeparator () const; /** returns the title of the item */ - const UTF8String& getTitle () const { return title; } + const UTF8String& getTitle () const; /** returns the key modifiers of the item */ - int32_t getKeyModifiers () const { return keyModifiers; } + int32_t getKeyModifiers () const; /** returns the keycode of the item */ - const UTF8String& getKeycode () const { return keyCode; } + const UTF8String& getKeycode () const; /** returns the virtual keycode of the item */ - int32_t getVirtualKeyCode () const { return virtualKeyCode; } + int32_t getVirtualKeyCode () const; /** returns the submenu of the item */ - COptionMenu* getSubmenu () const { return submenu; } + COptionMenu* getSubmenu () const; /** returns the icon of the item */ - CBitmap* getIcon () const { return icon; } + CBitmap* getIcon () const; /** returns the tag of the item */ - int32_t getTag () const { return tag; } + int32_t getTag () const; //@} //------------------------------------------------------------------------ protected: - ~CMenuItem () noexcept override = default; - - UTF8String title; - UTF8String keyCode; - SharedPointer submenu; - SharedPointer icon; - int32_t flags {0}; - int32_t keyModifiers {0}; - int32_t virtualKeyCode {0}; - int32_t tag {-1}; + CMenuItem (); + ~CMenuItem () noexcept override; + + struct Impl; + std::unique_ptr impl; }; //----------------------------------------------------------------------------- From 6e5011b4e40335007bc799a9c5b15ee19ba67901 Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 9 May 2021 18:18:49 +0200 Subject: [PATCH 067/319] use new keyboard event method --- .../lib/platform/common/genericoptionmenu.cpp | 89 ++++++++++--------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/vstgui/lib/platform/common/genericoptionmenu.cpp b/vstgui/lib/platform/common/genericoptionmenu.cpp index 355191ccd..b83693ef3 100644 --- a/vstgui/lib/platform/common/genericoptionmenu.cpp +++ b/vstgui/lib/platform/common/genericoptionmenu.cpp @@ -170,60 +170,63 @@ class DataSource : public DataBrowserDelegateAdapter, } } - int32_t dbOnKeyDown (const VstKeyCode& key, CDataBrowser* browser) override + void dbOnKeyboardEvent (KeyboardEvent& event, CDataBrowser* browser) override { - if (key.character == 0 && key.modifier == 0) + if (event.type != EventType::KeyDown || event.character != 0 || !event.modifiers.empty ()) + return; + switch (event.virt) { - switch (key.virt) + default: return; + case VirtualKey::Down: { - case VKEY_DOWN: - { - alterSelection (browser->getSelectedRow (), 1); - return 1; - } - case VKEY_UP: - { - alterSelection (browser->getSelectedRow (), -1); - return 1; - } - case VKEY_ESCAPE: - { - clickCallback (menu, CDataBrowser::kNoSelection); - return 1; - } - case VKEY_RETURN: - case VKEY_ENTER: - { - if (clickCallback) - clickCallback (menu, browser->getSelectedRow ()); - return 1; - } - case VKEY_LEFT: + alterSelection (browser->getSelectedRow (), 1); + event.consumed = true; + return; + } + case VirtualKey::Up: + { + alterSelection (browser->getSelectedRow (), -1); + event.consumed = true; + return; + } + case VirtualKey::Escape: + { + clickCallback (menu, CDataBrowser::kNoSelection); + event.consumed = true; + return; + } + case VirtualKey::Return: + case VirtualKey::Enter: + { + if (clickCallback) + clickCallback (menu, browser->getSelectedRow ()); + event.consumed = true; + return; + } + case VirtualKey::Left: + { + if (parentDataSource) { - if (parentDataSource) - { - parentDataSource->closeSubMenu (); - return 1; - } - break; + parentDataSource->closeSubMenu (); + event.consumed = true; } - case VKEY_RIGHT: + return; + } + case VirtualKey::Right: + { + auto row = db->getSelectedRow (); + if (auto item = menu->getEntry (row)) { - auto row = db->getSelectedRow (); - if (auto item = menu->getEntry (row)) + if (auto subMenu = item->getSubmenu ()) { - if (auto subMenu = item->getSubmenu ()) - { - auto r = db->getCellBounds ({row, 0}); - openSubMenu (item, r); - return 1; - } + auto r = db->getCellBounds ({row, 0}); + openSubMenu (item, r); + event.consumed = true; } } - default: break; + return; } } - return -1; } CMouseEventResult dbOnMouseMoved (const CPoint& where, const CButtonState& buttons, int32_t row, From 1d6d8626b6aee1e1e6280b795e70119ccd6b24ef Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 9 May 2021 20:44:49 +0200 Subject: [PATCH 068/319] adopt iOS touch events to new event handling --- vstgui/lib/cframe.cpp | 32 ++++++++++++++--------- vstgui/lib/cviewcontainer.cpp | 25 +++++++++--------- vstgui/lib/cviewcontainer.h | 2 +- vstgui/lib/platform/mac/ios/uiviewframe.h | 1 + vstgui/lib/platform/platformfwd.h | 2 ++ 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/vstgui/lib/cframe.cpp b/vstgui/lib/cframe.cpp index ff7e87b00..0071ab22d 100644 --- a/vstgui/lib/cframe.cpp +++ b/vstgui/lib/cframe.cpp @@ -1768,21 +1768,22 @@ void CFrame::platformOnTouchEvent (ITouchEvent& event) { if (e.second.targetIsSingleTouch) { - CButtonState buttons (kLButton); CPoint where (e.second.location); target->frameToLocal (where); switch (e.second.state) { case ITouchEvent::kMoved: { - CMouseEventResult result = target->onMouseMoved (where, buttons); - if (result == kMouseMoveEventHandledButDontNeedMoreEvents) + MouseMoveEvent moveEvent (where, MouseEventButtonState::Left); + target->dispatchEvent (moveEvent); + if (moveEvent.ignoreFollowUpMoveAndUpEvents ()) { - event.unsetTouchTarget(e.first, target); - if (target->hitTest (where, buttons) == false) + event.unsetTouchTarget (e.first, target); + if (target->hitTest (where, kLButton) == false) { // when the touch goes out of the target and it tells us to - const_cast (e.second).state = ITouchEvent::kBegan; + const_cast (e.second).state = + ITouchEvent::kBegan; hasBeganTouch = true; } } @@ -1790,14 +1791,20 @@ void CFrame::platformOnTouchEvent (ITouchEvent& event) } case ITouchEvent::kCanceled: { - if (target->onMouseCancel () != kMouseEventHandled) - target->onMouseUp (where, buttons); + MouseCancelEvent cancelEvent; + target->dispatchEvent (cancelEvent); + if (cancelEvent.consumed == false) + { + MouseUpEvent upEvent (where, MouseEventButtonState::Left); + target->dispatchEvent (upEvent); + } event.unsetTouchTarget (e.first, target); break; } case ITouchEvent::kEnded: { - target->onMouseUp (where, buttons); + MouseUpEvent upEvent (where, MouseEventButtonState::Left); + target->dispatchEvent (upEvent); event.unsetTouchTarget (e.first, target); break; } @@ -1810,7 +1817,8 @@ void CFrame::platformOnTouchEvent (ITouchEvent& event) } else { - if (std::find (targetDispatched.begin (), targetDispatched.end (), target) == targetDispatched.end ()) + if (std::find (targetDispatched.begin (), targetDispatched.end (), target) == + targetDispatched.end ()) { target->onTouchEvent (event); targetDispatched.emplace_back (target); @@ -1827,11 +1835,11 @@ void CFrame::platformOnTouchEvent (ITouchEvent& event) if (CView* focusView = getFocusView ()) { if (dynamic_cast (focusView)) - setFocusView (0); + setFocusView (nullptr); } for (const auto& e : event) { - if (e.second.target == 0 && e.second.state == ITouchEvent::kBegan) + if (e.second.target == nullptr && e.second.state == ITouchEvent::kBegan) { findSingleTouchEventTarget (const_cast (e.second)); } diff --git a/vstgui/lib/cviewcontainer.cpp b/vstgui/lib/cviewcontainer.cpp index c6aee7afe..7b5e26108 100644 --- a/vstgui/lib/cviewcontainer.cpp +++ b/vstgui/lib/cviewcontainer.cpp @@ -1218,12 +1218,11 @@ void CViewContainer::onTouchEvent (ITouchEvent& event) } //----------------------------------------------------------------------------- -void CViewContainer::findSingleTouchEventTarget (ITouchEvent::Touch& event) +bool CViewContainer::findSingleTouchEventTarget (ITouchEvent::Touch& event) { vstgui_assert(event.target == 0); vstgui_assert(event.state == ITouchEvent::kBegan); - CButtonState buttons (kLButton + (event.tapCount > 1 ? kDoubleClick : 0)); CPoint where (event.location); frameToLocal (where); ReverseViewIterator it (this); @@ -1231,31 +1230,31 @@ void CViewContainer::findSingleTouchEventTarget (ITouchEvent::Touch& event) { CView* view = *it; CBaseObjectGuard guard (view); - if (view->getMouseEnabled () && view->isVisible () && view->hitTest (where, buttons)) + if (view->getMouseEnabled () && view->isVisible () && view->hitTest (where, kLButton)) { if (auto container = view->asViewContainer ()) { - container->findSingleTouchEventTarget (event); - if (event.target != 0) - return; + if (container->findSingleTouchEventTarget (event)) + return true; } else { - CMouseEventResult result = view->onMouseDown (where, buttons); - if (result == kMouseEventHandled) + MouseDownEvent downEvent (where, MouseEventButtonState::Left); + downEvent.clickCount = event.tapCount; + view->dispatchEvent (downEvent); + if (downEvent.ignoreFollowUpMoveAndUpEvents()) + return true; + else if (downEvent.consumed) { event.target = view; event.targetIsSingleTouch = true; - return; - } - else if (result == kMouseDownEventHandledButDontNeedMovedOrUpEvents) - { - return; + return true; } } } it++; } + return false; } #endif diff --git a/vstgui/lib/cviewcontainer.h b/vstgui/lib/cviewcontainer.h index 72e8db81d..eba35dcf7 100644 --- a/vstgui/lib/cviewcontainer.h +++ b/vstgui/lib/cviewcontainer.h @@ -152,7 +152,7 @@ class CViewContainer : public CView #if VSTGUI_TOUCH_EVENT_HANDLING virtual void onTouchEvent (ITouchEvent& event) override; virtual bool wantsMultiTouchEvents () const override { return true; } - virtual void findSingleTouchEventTarget (ITouchEvent::Touch& event); + virtual bool findSingleTouchEventTarget (ITouchEvent::Touch& event); #endif SharedPointer getDropTarget () override; diff --git a/vstgui/lib/platform/mac/ios/uiviewframe.h b/vstgui/lib/platform/mac/ios/uiviewframe.h index aeb2cfeed..d340c4b30 100644 --- a/vstgui/lib/platform/mac/ios/uiviewframe.h +++ b/vstgui/lib/platform/mac/ios/uiviewframe.h @@ -34,6 +34,7 @@ class UIViewFrame : public IPlatformFrame bool getSize (CRect& size) const override; bool getCurrentMousePosition (CPoint& mousePosition) const override { return false; }; bool getCurrentMouseButtons (CButtonState& buttons) const override { return false; }; + bool getCurrentModifiers (Modifiers& modifiers) const override { return false; } bool setMouseCursor (CCursorType type) override { return false; }; bool invalidRect (const CRect& rect) override; bool scrollRect (const CRect& src, const CPoint& distance) override; diff --git a/vstgui/lib/platform/platformfwd.h b/vstgui/lib/platform/platformfwd.h index 5bf81076f..ad12a743a 100644 --- a/vstgui/lib/platform/platformfwd.h +++ b/vstgui/lib/platform/platformfwd.h @@ -4,6 +4,8 @@ #pragma once +#include "../vstguibase.h" + #include #include #include From 1c926ef04b8206dbe72ce57c0b0ad9af5ce12b0c Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 9 May 2021 20:46:46 +0200 Subject: [PATCH 069/319] use cmake to build iOS test app --- vstgui/tests/ios standalone/CMakeLists.txt | 46 +++ .../iOS Standalone.xcodeproj/project.pbxproj | 365 ------------------ .../iOS Standalone/AppDelegate.mm | 11 +- .../Base.lproj/Main_iPad.storyboard | 30 -- .../Base.lproj/Main_iPhone.storyboard | 31 -- .../iOS Standalone/en.lproj/InfoPlist.strings | 2 - 6 files changed, 55 insertions(+), 430 deletions(-) create mode 100644 vstgui/tests/ios standalone/CMakeLists.txt delete mode 100644 vstgui/tests/ios standalone/iOS Standalone.xcodeproj/project.pbxproj delete mode 100644 vstgui/tests/ios standalone/iOS Standalone/Base.lproj/Main_iPad.storyboard delete mode 100644 vstgui/tests/ios standalone/iOS Standalone/Base.lproj/Main_iPhone.storyboard delete mode 100644 vstgui/tests/ios standalone/iOS Standalone/en.lproj/InfoPlist.strings diff --git a/vstgui/tests/ios standalone/CMakeLists.txt b/vstgui/tests/ios standalone/CMakeLists.txt new file mode 100644 index 000000000..9512a9ed9 --- /dev/null +++ b/vstgui/tests/ios standalone/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.12) + +project(vstgui_ios_test) + +set(target "iostest") +set(sources + "../../vstgui_ios.mm" + "../../vstgui_uidescription.cpp" + "iOS Standalone/AppDelegate.h" + "iOS Standalone/AppDelegate.mm" + "iOS Standalone/main.m" + "iOS Standalone/ViewController.h" + "iOS Standalone/ViewController.mm" +) + +set(resources + "iOS Standalone/ios_test.uidesc" +) + +add_executable(${target} ${sources}) +set_source_files_properties(${resources} PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources" +) +target_sources(${target} PRIVATE ${resources}) +target_sources(${target} PRIVATE ${resources}) +target_include_directories(${target} PRIVATE "../../../") +target_compile_features(${target} PUBLIC cxx_std_17) + +target_link_libraries(${target} + "-framework UIKit" + "-framework QuartzCore" + "-framework CoreGraphics" + "-framework CoreText" + "-framework ImageIO" + "-framework MobileCoreServices" + "-framework Accelerate" +) + +set(bundleID net.sourceforge.vstgui.iostest) + +set_target_properties(${target} PROPERTIES + MACOSX_BUNDLE_BUNDLE_VERSION 1.0.0 + MACOSX_BUNDLE_SHORT_VERSION_STRING 1.0 + MACOSX_BUNDLE_GUI_IDENTIFIER ${bundleID} + XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER ${bundleID} +) diff --git a/vstgui/tests/ios standalone/iOS Standalone.xcodeproj/project.pbxproj b/vstgui/tests/ios standalone/iOS Standalone.xcodeproj/project.pbxproj deleted file mode 100644 index b73b6a904..000000000 --- a/vstgui/tests/ios standalone/iOS Standalone.xcodeproj/project.pbxproj +++ /dev/null @@ -1,365 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - BCB2A78B1FFD0C2B00DB75B7 /* vstgui_ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCB2A78A1FFD0C2B00DB75B7 /* vstgui_ios.mm */; }; - BCB2A78D1FFD0D1A00DB75B7 /* vstgui_uidescription_ios.mm in Sources */ = {isa = PBXBuildFile; fileRef = BCB2A78C1FFD0D1A00DB75B7 /* vstgui_uidescription_ios.mm */; }; - F44C94D519C344FF0075CC67 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F44C94D419C344FF0075CC67 /* Foundation.framework */; }; - F44C94D719C344FF0075CC67 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F44C94D619C344FF0075CC67 /* CoreGraphics.framework */; }; - F44C94D919C344FF0075CC67 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F44C94D819C344FF0075CC67 /* UIKit.framework */; }; - F44C94DF19C344FF0075CC67 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F44C94DD19C344FF0075CC67 /* InfoPlist.strings */; }; - F44C94E119C344FF0075CC67 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F44C94E019C344FF0075CC67 /* main.m */; }; - F44C94E519C344FF0075CC67 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44C94E419C344FF0075CC67 /* AppDelegate.mm */; }; - F44C94E819C344FF0075CC67 /* Main_iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F44C94E619C344FF0075CC67 /* Main_iPhone.storyboard */; }; - F44C94EB19C344FF0075CC67 /* Main_iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F44C94E919C344FF0075CC67 /* Main_iPad.storyboard */; }; - F44C94EE19C344FF0075CC67 /* ViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44C94ED19C344FF0075CC67 /* ViewController.mm */; }; - F44C951319C34BED0075CC67 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F44C951219C34BED0075CC67 /* Accelerate.framework */; }; - F44C951719C34BFD0075CC67 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F44C951619C34BFD0075CC67 /* ImageIO.framework */; }; - F44C951919C34C160075CC67 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F44C951819C34C160075CC67 /* MobileCoreServices.framework */; }; - F44C951C19C351550075CC67 /* ios_test.uidesc in Resources */ = {isa = PBXBuildFile; fileRef = F44C951B19C351550075CC67 /* ios_test.uidesc */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - BCB2A78A1FFD0C2B00DB75B7 /* vstgui_ios.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = vstgui_ios.mm; path = ../../vstgui_ios.mm; sourceTree = ""; }; - BCB2A78C1FFD0D1A00DB75B7 /* vstgui_uidescription_ios.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = vstgui_uidescription_ios.mm; path = ../../vstgui_uidescription_ios.mm; sourceTree = ""; }; - F44C94D119C344FF0075CC67 /* VSTGUI Test.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "VSTGUI Test.app"; sourceTree = BUILT_PRODUCTS_DIR; }; - F44C94D419C344FF0075CC67 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - F44C94D619C344FF0075CC67 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; - F44C94D819C344FF0075CC67 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - F44C94DC19C344FF0075CC67 /* iOS Standalone-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "iOS Standalone-Info.plist"; sourceTree = ""; }; - F44C94DE19C344FF0075CC67 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; - F44C94E019C344FF0075CC67 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - F44C94E219C344FF0075CC67 /* iOS Standalone-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "iOS Standalone-Prefix.pch"; sourceTree = ""; }; - F44C94E319C344FF0075CC67 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - F44C94E419C344FF0075CC67 /* AppDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AppDelegate.mm; sourceTree = ""; }; - F44C94E719C344FF0075CC67 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main_iPhone.storyboard; sourceTree = ""; }; - F44C94EA19C344FF0075CC67 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main_iPad.storyboard; sourceTree = ""; }; - F44C94EC19C344FF0075CC67 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - F44C94ED19C344FF0075CC67 /* ViewController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ViewController.mm; sourceTree = ""; }; - F44C94F619C344FF0075CC67 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; - F44C951219C34BED0075CC67 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; }; - F44C951419C34BF20075CC67 /* CoreImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreImage.framework; path = System/Library/Frameworks/CoreImage.framework; sourceTree = SDKROOT; }; - F44C951619C34BFD0075CC67 /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; }; - F44C951819C34C160075CC67 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; }; - F44C951B19C351550075CC67 /* ios_test.uidesc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = ios_test.uidesc; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - F44C94CE19C344FF0075CC67 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - F44C951919C34C160075CC67 /* MobileCoreServices.framework in Frameworks */, - F44C951719C34BFD0075CC67 /* ImageIO.framework in Frameworks */, - F44C951319C34BED0075CC67 /* Accelerate.framework in Frameworks */, - F44C94D719C344FF0075CC67 /* CoreGraphics.framework in Frameworks */, - F44C94D919C344FF0075CC67 /* UIKit.framework in Frameworks */, - F44C94D519C344FF0075CC67 /* Foundation.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - F44C94C819C344FF0075CC67 = { - isa = PBXGroup; - children = ( - BCB2A78A1FFD0C2B00DB75B7 /* vstgui_ios.mm */, - BCB2A78C1FFD0D1A00DB75B7 /* vstgui_uidescription_ios.mm */, - F44C94DA19C344FF0075CC67 /* iOS Standalone */, - F44C94D319C344FF0075CC67 /* Frameworks */, - F44C94D219C344FF0075CC67 /* Products */, - ); - sourceTree = ""; - }; - F44C94D219C344FF0075CC67 /* Products */ = { - isa = PBXGroup; - children = ( - F44C94D119C344FF0075CC67 /* VSTGUI Test.app */, - ); - name = Products; - sourceTree = ""; - }; - F44C94D319C344FF0075CC67 /* Frameworks */ = { - isa = PBXGroup; - children = ( - F44C951819C34C160075CC67 /* MobileCoreServices.framework */, - F44C951619C34BFD0075CC67 /* ImageIO.framework */, - F44C951419C34BF20075CC67 /* CoreImage.framework */, - F44C951219C34BED0075CC67 /* Accelerate.framework */, - F44C94D419C344FF0075CC67 /* Foundation.framework */, - F44C94D619C344FF0075CC67 /* CoreGraphics.framework */, - F44C94D819C344FF0075CC67 /* UIKit.framework */, - F44C94F619C344FF0075CC67 /* XCTest.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; - F44C94DA19C344FF0075CC67 /* iOS Standalone */ = { - isa = PBXGroup; - children = ( - F44C94E319C344FF0075CC67 /* AppDelegate.h */, - F44C94E419C344FF0075CC67 /* AppDelegate.mm */, - F44C94E619C344FF0075CC67 /* Main_iPhone.storyboard */, - F44C94E919C344FF0075CC67 /* Main_iPad.storyboard */, - F44C94EC19C344FF0075CC67 /* ViewController.h */, - F44C94ED19C344FF0075CC67 /* ViewController.mm */, - F44C94DB19C344FF0075CC67 /* Supporting Files */, - ); - path = "iOS Standalone"; - sourceTree = ""; - }; - F44C94DB19C344FF0075CC67 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - F44C951B19C351550075CC67 /* ios_test.uidesc */, - F44C94DC19C344FF0075CC67 /* iOS Standalone-Info.plist */, - F44C94DD19C344FF0075CC67 /* InfoPlist.strings */, - F44C94E019C344FF0075CC67 /* main.m */, - F44C94E219C344FF0075CC67 /* iOS Standalone-Prefix.pch */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - F44C94D019C344FF0075CC67 /* iOS Standalone */ = { - isa = PBXNativeTarget; - buildConfigurationList = F44C950619C344FF0075CC67 /* Build configuration list for PBXNativeTarget "iOS Standalone" */; - buildPhases = ( - F44C94CD19C344FF0075CC67 /* Sources */, - F44C94CE19C344FF0075CC67 /* Frameworks */, - F44C94CF19C344FF0075CC67 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "iOS Standalone"; - productName = "iOS Standalone"; - productReference = F44C94D119C344FF0075CC67 /* VSTGUI Test.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - F44C94C919C344FF0075CC67 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0510; - }; - buildConfigurationList = F44C94CC19C344FF0075CC67 /* Build configuration list for PBXProject "iOS Standalone" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - English, - en, - Base, - ); - mainGroup = F44C94C819C344FF0075CC67; - productRefGroup = F44C94D219C344FF0075CC67 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - F44C94D019C344FF0075CC67 /* iOS Standalone */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - F44C94CF19C344FF0075CC67 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - F44C951C19C351550075CC67 /* ios_test.uidesc in Resources */, - F44C94EB19C344FF0075CC67 /* Main_iPad.storyboard in Resources */, - F44C94E819C344FF0075CC67 /* Main_iPhone.storyboard in Resources */, - F44C94DF19C344FF0075CC67 /* InfoPlist.strings in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - F44C94CD19C344FF0075CC67 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - F44C94EE19C344FF0075CC67 /* ViewController.mm in Sources */, - BCB2A78B1FFD0C2B00DB75B7 /* vstgui_ios.mm in Sources */, - BCB2A78D1FFD0D1A00DB75B7 /* vstgui_uidescription_ios.mm in Sources */, - F44C94E519C344FF0075CC67 /* AppDelegate.mm in Sources */, - F44C94E119C344FF0075CC67 /* main.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - F44C94DD19C344FF0075CC67 /* InfoPlist.strings */ = { - isa = PBXVariantGroup; - children = ( - F44C94DE19C344FF0075CC67 /* en */, - ); - name = InfoPlist.strings; - sourceTree = ""; - }; - F44C94E619C344FF0075CC67 /* Main_iPhone.storyboard */ = { - isa = PBXVariantGroup; - children = ( - F44C94E719C344FF0075CC67 /* Base */, - ); - name = Main_iPhone.storyboard; - sourceTree = ""; - }; - F44C94E919C344FF0075CC67 /* Main_iPad.storyboard */ = { - isa = PBXVariantGroup; - children = ( - F44C94EA19C344FF0075CC67 /* Base */, - ); - name = Main_iPad.storyboard; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - F44C950419C344FF0075CC67 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - F44C950519C344FF0075CC67 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = YES; - ENABLE_NS_ASSERTIONS = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - F44C950719C344FF0075CC67 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "iOS Standalone/iOS Standalone-Prefix.pch"; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - ../../../, - ); - INFOPLIST_FILE = "iOS Standalone/iOS Standalone-Info.plist"; - PRODUCT_NAME = "VSTGUI Test"; - WRAPPER_EXTENSION = app; - }; - name = Debug; - }; - F44C950819C344FF0075CC67 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "iOS Standalone/iOS Standalone-Prefix.pch"; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, - ../../../, - ); - INFOPLIST_FILE = "iOS Standalone/iOS Standalone-Info.plist"; - PRODUCT_NAME = "VSTGUI Test"; - WRAPPER_EXTENSION = app; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - F44C94CC19C344FF0075CC67 /* Build configuration list for PBXProject "iOS Standalone" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - F44C950419C344FF0075CC67 /* Debug */, - F44C950519C344FF0075CC67 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - F44C950619C344FF0075CC67 /* Build configuration list for PBXNativeTarget "iOS Standalone" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - F44C950719C344FF0075CC67 /* Debug */, - F44C950819C344FF0075CC67 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = F44C94C919C344FF0075CC67 /* Project object */; -} diff --git a/vstgui/tests/ios standalone/iOS Standalone/AppDelegate.mm b/vstgui/tests/ios standalone/iOS Standalone/AppDelegate.mm index a2cfaaa0b..8054cb0c7 100644 --- a/vstgui/tests/ios standalone/iOS Standalone/AppDelegate.mm +++ b/vstgui/tests/ios standalone/iOS Standalone/AppDelegate.mm @@ -3,15 +3,22 @@ // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE #import "AppDelegate.h" +#import "ViewController.h" #import "vstgui/lib/vstguiinit.h" - +#import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { VSTGUI::init (CFBundleGetMainBundle ()); - // Override point for customization after application launch. + + UIScreen* mainScreen = UIScreen.mainScreen; + + UIWindow* window = [[UIWindow alloc] initWithFrame:mainScreen.bounds]; + window.rootViewController = [ViewController new]; + [window makeKeyAndVisible]; + return YES; } diff --git a/vstgui/tests/ios standalone/iOS Standalone/Base.lproj/Main_iPad.storyboard b/vstgui/tests/ios standalone/iOS Standalone/Base.lproj/Main_iPad.storyboard deleted file mode 100644 index 4edef30d2..000000000 --- a/vstgui/tests/ios standalone/iOS Standalone/Base.lproj/Main_iPad.storyboard +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vstgui/tests/ios standalone/iOS Standalone/Base.lproj/Main_iPhone.storyboard b/vstgui/tests/ios standalone/iOS Standalone/Base.lproj/Main_iPhone.storyboard deleted file mode 100644 index e9b070c2d..000000000 --- a/vstgui/tests/ios standalone/iOS Standalone/Base.lproj/Main_iPhone.storyboard +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vstgui/tests/ios standalone/iOS Standalone/en.lproj/InfoPlist.strings b/vstgui/tests/ios standalone/iOS Standalone/en.lproj/InfoPlist.strings deleted file mode 100644 index 477b28ff8..000000000 --- a/vstgui/tests/ios standalone/iOS Standalone/en.lproj/InfoPlist.strings +++ /dev/null @@ -1,2 +0,0 @@ -/* Localized versions of Info.plist keys */ - From 36a83d54d25a6e355fd3396b6fd7c636ef81a71b Mon Sep 17 00:00:00 2001 From: scheffle Date: Sun, 9 May 2021 20:53:41 +0200 Subject: [PATCH 070/319] add some controls in 768*1024 mode --- .../tests/ios standalone/iOS Standalone/ios_test.uidesc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vstgui/tests/ios standalone/iOS Standalone/ios_test.uidesc b/vstgui/tests/ios standalone/iOS Standalone/ios_test.uidesc index 1bc408685..0dc0ce295 100644 --- a/vstgui/tests/ios standalone/iOS Standalone/ios_test.uidesc +++ b/vstgui/tests/ios standalone/iOS Standalone/ios_test.uidesc @@ -32,7 +32,13 @@ -