Merge branch 'gesture-events'

Integrate GSoC 2017 work by Prashant Kumar implementing support for
gesture events.

Closes https://github.com/wxWidgets/wxWidgets/pull/551

Closes https://github.com/wxWidgets/wxWidgets/pull/565
This commit is contained in:
Vadim Zeitlin
2017-12-02 18:46:53 +01:00
28 changed files with 2894 additions and 17 deletions

View File

@@ -3104,6 +3104,12 @@ DECLARE_WXCOCOA_OBJC_CLASS(NSView);
DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLContext);
DECLARE_WXCOCOA_OBJC_CLASS(NSOpenGLPixelFormat);
DECLARE_WXCOCOA_OBJC_CLASS( NSPrintInfo );
DECLARE_WXCOCOA_OBJC_CLASS(NSGestureRecognizer);
DECLARE_WXCOCOA_OBJC_CLASS(NSPanGestureRecognizer);
DECLARE_WXCOCOA_OBJC_CLASS(NSMagnificationGestureRecognizer);
DECLARE_WXCOCOA_OBJC_CLASS(NSRotationGestureRecognizer);
DECLARE_WXCOCOA_OBJC_CLASS(NSPressGestureRecognizer);
DECLARE_WXCOCOA_OBJC_CLASS(NSTouch);
#endif /* __WXMAC__ &__DARWIN__ */
#ifdef __WXMAC__
@@ -3267,6 +3273,7 @@ typedef struct _GdkDragContext GdkDragContext;
#if defined(__WXGTK3__)
typedef struct _GdkWindow GdkWindow;
typedef struct _GdkEventSequence GdkEventSequence;
#elif defined(__WXGTK20__)
typedef struct _GdkDrawable GdkWindow;
typedef struct _GdkDrawable GdkPixmap;

View File

@@ -631,6 +631,13 @@ class WXDLLIMPEXP_FWD_CORE wxInitDialogEvent;
class WXDLLIMPEXP_FWD_CORE wxUpdateUIEvent;
class WXDLLIMPEXP_FWD_CORE wxClipboardTextEvent;
class WXDLLIMPEXP_FWD_CORE wxHelpEvent;
class WXDLLIMPEXP_FWD_CORE wxGestureEvent;
class WXDLLIMPEXP_FWD_CORE wxPanGestureEvent;
class WXDLLIMPEXP_FWD_CORE wxZoomGestureEvent;
class WXDLLIMPEXP_FWD_CORE wxRotateGestureEvent;
class WXDLLIMPEXP_FWD_CORE wxTwoFingerTapEvent;
class WXDLLIMPEXP_FWD_CORE wxLongPressEvent;
class WXDLLIMPEXP_FWD_CORE wxPressAndTapEvent;
// Command events
@@ -736,6 +743,14 @@ wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWin
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEvent);
// Gesture events
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_GESTURE_PAN, wxPanGestureEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_GESTURE_ZOOM, wxZoomGestureEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_GESTURE_ROTATE, wxRotateGestureEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_TWO_FINGER_TAP, wxTwoFingerTapEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LONG_PRESS, wxLongPressEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PRESS_AND_TAP, wxPressAndTapEvent);
// System events
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SIZE, wxSizeEvent);
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE, wxMoveEvent);
@@ -1850,6 +1865,197 @@ private:
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSetCursorEvent);
};
// Gesture Event
const unsigned int wxTwoFingerTimeInterval = 200;
class WXDLLIMPEXP_CORE wxGestureEvent : public wxEvent
{
public:
wxGestureEvent(wxWindowID winid = 0, wxEventType type = wxEVT_NULL)
: wxEvent(winid, type)
{
m_isStart = false;
m_isEnd = false;
}
wxGestureEvent(const wxGestureEvent& event) : wxEvent(event)
{
m_pos = event.m_pos;
m_isStart = event.m_isStart;
m_isEnd = event.m_isEnd;
}
const wxPoint& GetPosition() const { return m_pos; }
void SetPosition(const wxPoint& pos) { m_pos = pos; }
bool IsGestureStart() const { return m_isStart; }
void SetGestureStart(bool isStart = true) { m_isStart = isStart; }
bool IsGestureEnd() const { return m_isEnd; }
void SetGestureEnd(bool isEnd = true) { m_isEnd = isEnd; }
virtual wxEvent *Clone() const { return new wxGestureEvent(*this); }
protected:
wxPoint m_pos;
bool m_isStart, m_isEnd;
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGestureEvent);
};
// Pan Gesture Event
/*
wxEVT_GESTURE_PAN
*/
class WXDLLIMPEXP_CORE wxPanGestureEvent : public wxGestureEvent
{
public:
wxPanGestureEvent(wxWindowID winid = 0)
: wxGestureEvent(winid, wxEVT_GESTURE_PAN)
{
}
wxPanGestureEvent(const wxPanGestureEvent& event)
: wxGestureEvent(event),
m_delta(event.m_delta)
{
}
wxPoint GetDelta() const { return m_delta; }
void SetDelta(const wxPoint& delta) { m_delta = delta; }
virtual wxEvent *Clone() const { return new wxPanGestureEvent(*this); }
private:
wxPoint m_delta;
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPanGestureEvent);
};
// Zoom Gesture Event
/*
wxEVT_GESTURE_ZOOM
*/
class WXDLLIMPEXP_CORE wxZoomGestureEvent : public wxGestureEvent
{
public:
wxZoomGestureEvent(wxWindowID winid = 0)
: wxGestureEvent(winid, wxEVT_GESTURE_ZOOM)
{ m_zoomFactor = 1.0; }
wxZoomGestureEvent(const wxZoomGestureEvent& event) : wxGestureEvent(event)
{
m_zoomFactor = event.m_zoomFactor;
}
double GetZoomFactor() const { return m_zoomFactor; }
void SetZoomFactor(double zoomFactor) { m_zoomFactor = zoomFactor; }
virtual wxEvent *Clone() const { return new wxZoomGestureEvent(*this); }
private:
double m_zoomFactor;
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxZoomGestureEvent);
};
// Rotate Gesture Event
/*
wxEVT_GESTURE_ROTATE
*/
class WXDLLIMPEXP_CORE wxRotateGestureEvent : public wxGestureEvent
{
public:
wxRotateGestureEvent(wxWindowID winid = 0)
: wxGestureEvent(winid, wxEVT_GESTURE_ROTATE)
{ m_rotationAngle = 0.0; }
wxRotateGestureEvent(const wxRotateGestureEvent& event) : wxGestureEvent(event)
{
m_rotationAngle = event.m_rotationAngle;
}
double GetRotationAngle() const { return m_rotationAngle; }
void SetRotationAngle(double rotationAngle) { m_rotationAngle = rotationAngle; }
virtual wxEvent *Clone() const { return new wxRotateGestureEvent(*this); }
private:
double m_rotationAngle;
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxRotateGestureEvent);
};
// Two Finger Tap Gesture Event
/*
wxEVT_TWO_FINGER_TAP
*/
class WXDLLIMPEXP_CORE wxTwoFingerTapEvent : public wxGestureEvent
{
public:
wxTwoFingerTapEvent(wxWindowID winid = 0)
: wxGestureEvent(winid, wxEVT_TWO_FINGER_TAP)
{ }
wxTwoFingerTapEvent(const wxTwoFingerTapEvent& event) : wxGestureEvent(event)
{ }
virtual wxEvent *Clone() const { return new wxTwoFingerTapEvent(*this); }
private:
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxTwoFingerTapEvent);
};
// Long Press Gesture Event
/*
wxEVT_LONG_PRESS
*/
class WXDLLIMPEXP_CORE wxLongPressEvent : public wxGestureEvent
{
public:
wxLongPressEvent(wxWindowID winid = 0)
: wxGestureEvent(winid, wxEVT_LONG_PRESS)
{ }
wxLongPressEvent(const wxLongPressEvent& event) : wxGestureEvent(event)
{ }
virtual wxEvent *Clone() const { return new wxLongPressEvent(*this); }
private:
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxLongPressEvent);
};
// Press And Tap Gesture Event
/*
wxEVT_PRESS_AND_TAP
*/
class WXDLLIMPEXP_CORE wxPressAndTapEvent : public wxGestureEvent
{
public:
wxPressAndTapEvent(wxWindowID winid = 0)
: wxGestureEvent(winid, wxEVT_PRESS_AND_TAP)
{ }
wxPressAndTapEvent(const wxPressAndTapEvent& event) : wxGestureEvent(event)
{ }
virtual wxEvent *Clone() const { return new wxPressAndTapEvent(*this); }
private:
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPressAndTapEvent);
};
// Keyboard input event class
/*
@@ -3908,7 +4114,12 @@ typedef void (wxEvtHandler::*wxContextMenuEventFunction)(wxContextMenuEvent&);
typedef void (wxEvtHandler::*wxMouseCaptureChangedEventFunction)(wxMouseCaptureChangedEvent&);
typedef void (wxEvtHandler::*wxMouseCaptureLostEventFunction)(wxMouseCaptureLostEvent&);
typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent&);
typedef void (wxEvtHandler::*wxPanGestureEventFunction)(wxPanGestureEvent&);
typedef void (wxEvtHandler::*wxZoomGestureEventFunction)(wxZoomGestureEvent&);
typedef void (wxEvtHandler::*wxRotateGestureEventFunction)(wxRotateGestureEvent&);
typedef void (wxEvtHandler::*wxTwoFingerTapEventFunction)(wxTwoFingerTapEvent&);
typedef void (wxEvtHandler::*wxLongPressEventFunction)(wxLongPressEvent&);
typedef void (wxEvtHandler::*wxPressAndTapEventFunction)(wxPressAndTapEvent&);
#define wxCommandEventHandler(func) \
wxEVENT_HANDLER_CAST(wxCommandEventFunction, func)
@@ -3983,6 +4194,18 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent&
wxEVENT_HANDLER_CAST(wxMouseCaptureLostEventFunction, func)
#define wxClipboardTextEventHandler(func) \
wxEVENT_HANDLER_CAST(wxClipboardTextEventFunction, func)
#define wxPanGestureEventHandler(func) \
wxEVENT_HANDLER_CAST(wxPanGestureEventFunction, func)
#define wxZoomGestureEventHandler(func) \
wxEVENT_HANDLER_CAST(wxZoomGestureEventFunction, func)
#define wxRotateGestureEventHandler(func) \
wxEVENT_HANDLER_CAST(wxRotateGestureEventFunction, func)
#define wxTwoFingerTapEventHandler(func) \
wxEVENT_HANDLER_CAST(wxTwoFingerTapEventFunction, func)
#define wxLongPressEventHandler(func) \
wxEVENT_HANDLER_CAST(wxLongPressEventFunction, func)
#define wxPressAndTapEvent(func) \
wxEVENT_HANDLER_CAST(wxPressAndTapEventFunction, func)
#endif // wxUSE_GUI
@@ -4317,6 +4540,14 @@ typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent&
EVT_COMMAND_SCROLL_THUMBRELEASE(winid, func) \
EVT_COMMAND_SCROLL_CHANGED(winid, func)
// Gesture events
#define EVT_GESTURE_PAN(winid, func) wx__DECLARE_EVT1(wxEVT_GESTURE_PAN, winid, wxPanGestureEventHandler(func))
#define EVT_GESTURE_ZOOM(winid, func) wx__DECLARE_EVT1(wxEVT_GESTURE_ZOOM, winid, wxZoomGestureEventHandler(func))
#define EVT_GESTURE_ROTATE(winid, func) wx__DECLARE_EVT1(wxEVT_GESTURE_ROTATE, winid, wxRotateGestureEventHandler(func))
#define EVT_TWO_FINGER_TAP(winid, func) wx__DECLARE_EVT1(wxEVT_TWO_FINGER_TAP, winid, wxTwoFingerTapEventHandler(func))
#define EVT_LONG_PRESS(winid, func) wx__DECLARE_EVT1(wxEVT_LONG_PRESS, winid, wxLongPressEventHandler(func))
#define EVT_PRESS_AND_TAP(winid, func) wx__DECLARE_EVT1(wxEVT_PRESS_AND_TAP, winid, wxPressAndTapEvent(func))
// Convenience macros for commonly-used commands
#define EVT_CHECKBOX(winid, func) wx__DECLARE_EVT1(wxEVT_CHECKBOX, winid, wxCommandEventHandler(func))
#define EVT_CHOICE(winid, func) wx__DECLARE_EVT1(wxEVT_CHOICE, winid, wxCommandEventHandler(func))

View File

@@ -77,6 +77,9 @@ public:
virtual bool Reparent( wxWindowBase *newParent ) wxOVERRIDE;
virtual void WarpPointer(int x, int y) wxOVERRIDE;
#ifdef __WXGTK3__
virtual bool EnableTouchEvents(int eventsMask) wxOVERRIDE;
#endif // __WXGTK3__
virtual void Refresh( bool eraseBackground = true,
const wxRect *rect = (const wxRect *) NULL ) wxOVERRIDE;

View File

@@ -100,6 +100,7 @@ public:
virtual bool Reparent(wxWindowBase *newParent) wxOVERRIDE;
virtual void WarpPointer(int x, int y) wxOVERRIDE;
virtual bool EnableTouchEvents(int eventsMask) wxOVERRIDE;
virtual void Refresh( bool eraseBackground = true,
const wxRect *rect = (const wxRect *) NULL ) wxOVERRIDE;
@@ -360,6 +361,16 @@ public:
bool HandleMouseWheel(wxMouseWheelAxis axis,
WXWPARAM wParam, WXLPARAM lParam);
// Common gesture event initialization, returns true if it is the initial
// event (GF_BEGIN set in flags), false otherwise.
bool InitGestureEvent(wxGestureEvent& event, const wxPoint& pt, WXDWORD flags);
bool HandlePanGesture(const wxPoint& pt, WXDWORD flags);
bool HandleZoomGesture(const wxPoint& pt, WXDWORD fingerDistance, WXDWORD flags);
bool HandleRotateGesture(const wxPoint& pt, WXDWORD angleArgument, WXDWORD flags);
bool HandleTwoFingerTap(const wxPoint& pt, WXDWORD flags);
bool HandlePressAndTap(const wxPoint& pt, WXDWORD flags);
bool HandleChar(WXWPARAM wParam, WXLPARAM lParam);
bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);

View File

@@ -128,6 +128,7 @@ public :
void SetToolTip( wxToolTip* tooltip );
void InstallEventHandler( WXWidget control = NULL );
bool EnableTouchEvents(int eventsMask);
virtual bool ShouldHandleKeyNavigation(const wxKeyEvent &event) const;
bool DoHandleKeyNavigation(const wxKeyEvent &event);
@@ -143,6 +144,15 @@ public :
void SetupCoordinates(wxCoord &x, wxCoord &y, NSEvent *nsEvent);
virtual bool SetupCursor(NSEvent* event);
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
virtual void PanGestureEvent(NSPanGestureRecognizer *panGestureRecognizer);
virtual void ZoomGestureEvent(NSMagnificationGestureRecognizer *magnificationGestureRecognizer);
virtual void RotateGestureEvent(NSRotationGestureRecognizer *rotationGestureRecognizer);
virtual void LongPressEvent(NSPressGestureRecognizer *pressGestureRecognizer);
virtual void TouchesBegan(NSEvent *event);
virtual void TouchesMoved(NSEvent *event);
virtual void TouchesEnded(NSEvent *event);
#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10
#if !wxOSX_USE_NATIVE_FLIPPED
void SetFlipped(bool flipped);

View File

@@ -326,6 +326,8 @@ public :
virtual void InstallEventHandler( WXWidget control = NULL ) = 0;
virtual bool EnableTouchEvents(int eventsMask) = 0;
// Mechanism used to keep track of whether a change should send an event
// Do SendEvents(false) when starting actions that would trigger programmatic events
// and SendEvents(true) at the end of the block.

View File

@@ -105,6 +105,7 @@ public :
void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
void InstallEventHandler( WXWidget control = NULL );
bool EnableTouchEvents(int WXUNUSED(eventsMask)) { return false; }
virtual void DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow);

View File

@@ -77,6 +77,7 @@ public:
virtual void SetFocus() wxOVERRIDE;
virtual void WarpPointer( int x, int y ) wxOVERRIDE;
virtual bool EnableTouchEvents(int eventsMask) wxOVERRIDE;
virtual void Refresh( bool eraseBackground = true,
const wxRect *rect = NULL ) wxOVERRIDE;

View File

@@ -0,0 +1,84 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/private/extfield.h
// Purpose: Declare wxExternalField helper
// Author: Vadim Zeitlin
// Created: 2017-11-21
// Copyright: (c) 2017 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_EXTFIELD_H_
#define _WX_PRIVATE_EXTFIELD_H_
// ----------------------------------------------------------------------------
// wxExternalField: store object data outside of it
// ----------------------------------------------------------------------------
// This class allows to store some data without consuming space for the objects
// that don't need it and can be useful for avoiding to add rarely used fields
// to the classes that are used by many objects, e.g. wxWindow.
//
// Note that using this class costs in speed and convenience of access to the
// field, which requires a hash lookup instead of accessing it directly. It
// also only currently works for heap-allocated fields as it's probably never
// worth using it for fields of simple types.
//
// Template parameter Object is the class that "contains" the field, Field is
// the type of the field itself and FieldMap is the hash map, defined
// separately using WX_DECLARE_HASH_MAP(), with Object* as the key and Field*
// as the value type.
template <typename Object, typename Field, typename FieldMap>
class wxExternalField
{
public:
typedef Object ObjectType;
typedef Field FieldType;
typedef FieldMap MapType;
// Store the field object to be used for the given object, replacing the
// existing one, if any.
//
// This method takes ownership of the field pointer which will be destroyed
// by EraseForObject().
static void StoreForObject(ObjectType* obj, FieldType* field)
{
const typename MapType::iterator it = ms_map.find(obj);
if ( it != ms_map.end() )
{
delete it->second;
it->second = field;
}
else
{
ms_map.insert(typename MapType::value_type(obj, field));
}
}
// Find the object for the corresponding window.
static FieldType* FromObject(ObjectType* obj)
{
const typename MapType::const_iterator it = ms_map.find(obj);
return it == ms_map.end() ? NULL : it->second;
}
// Erase the object used for the corresponding window, return true if there
// was one or false otherwise.
static bool EraseForObject(ObjectType* obj)
{
const typename MapType::iterator it = ms_map.find(obj);
if ( it == ms_map.end() )
return false;
delete it->second;
ms_map.erase(it);
return true;
}
private:
static FieldMap ms_map;
};
template <typename O, typename F, typename M>
M wxExternalField<O, F, M>::ms_map;
#endif // _WX_PRIVATE_EXTFIELD_H_

View File

@@ -133,6 +133,20 @@ enum wxShowEffect
wxSHOW_EFFECT_MAX
};
// Values for EnableTouchEvents() mask.
enum
{
wxTOUCH_NONE = 0x0000,
wxTOUCH_VERTICAL_PAN_GESTURE = 0x0001,
wxTOUCH_HORIZONTAL_PAN_GESTURE = 0x0002,
wxTOUCH_PAN_GESTURES = wxTOUCH_VERTICAL_PAN_GESTURE |
wxTOUCH_HORIZONTAL_PAN_GESTURE,
wxTOUCH_ZOOM_GESTURE = 0x0004,
wxTOUCH_ROTATE_GESTURE = 0x0008,
wxTOUCH_PRESS_GESTURES = 0x0010,
wxTOUCH_ALL_GESTURES = 0x001f
};
// flags for SendSizeEvent()
enum
{
@@ -1033,6 +1047,13 @@ public:
virtual bool HasCapture() const
{ return (wxWindow *)this == GetCapture(); }
// enable the specified touch events for this window, return false if
// the requested events are not supported
virtual bool EnableTouchEvents(int WXUNUSED(eventsMask))
{
return false;
}
// painting the window
// -------------------