Allow enabling individual touch gesture events

Implement support for enabling just some gesture events instead of
having to choose between getting none or all of them.

Also make wxTOUCH_NONE really disable the gestures events generation
instead of just doing nothing as before.
This commit is contained in:
Vadim Zeitlin
2017-11-21 22:46:56 +01:00
parent 842dd1cfd9
commit a8dfaa569b
5 changed files with 356 additions and 87 deletions

View File

@@ -51,6 +51,7 @@
#include "wx/textctrl.h"
#include "wx/menuitem.h"
#include "wx/module.h"
#include "wx/vector.h"
#endif
#if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
@@ -909,17 +910,105 @@ void wxWindowMSW::WarpPointer(int x, int y)
bool wxWindowMSW::EnableTouchEvents(int eventsMask)
{
#ifdef WM_GESTURE
if ( GestureFuncs::IsOk() && eventsMask == wxTOUCH_ALL_GESTURES )
if ( GestureFuncs::IsOk() )
{
// Configure to receive all gestures
GESTURECONFIG gestureConfig = {0, GC_ALLGESTURES, 0};
// Static struct used when we need to use just a single configuration.
GESTURECONFIG config = {0, 0, 0};
GESTURECONFIG* ptrConfigs = &config;
UINT numConfigs = 1;
// This is used only if we need to allocate the configurations
// dynamically.
wxVector<GESTURECONFIG> configs;
// There are two simple cases: enabling or disabling all gestures.
if ( eventsMask == wxTOUCH_NONE )
{
config.dwBlock = GC_ALLGESTURES;
}
else if ( eventsMask == wxTOUCH_ALL_GESTURES )
{
config.dwWant = GC_ALLGESTURES;
}
else // Need to enable the individual gestures
{
int wantedPan = 0;
switch ( eventsMask & wxTOUCH_PAN_GESTURES )
{
case wxTOUCH_VERTICAL_PAN_GESTURE:
wantedPan = GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
break;
case wxTOUCH_HORIZONTAL_PAN_GESTURE:
wantedPan = GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
break;
case wxTOUCH_PAN_GESTURES:
wantedPan = GC_PAN;
break;
case 0:
// This is the only other possibility and wantedPan is
// already initialized to 0 anyhow, so don't do anything,
// just list it for completeness.
break;
}
if ( wantedPan )
{
eventsMask &= ~wxTOUCH_PAN_GESTURES;
config.dwID = GID_PAN;
config.dwWant = wantedPan;
configs.push_back(config);
}
if ( eventsMask & wxTOUCH_ZOOM_GESTURE )
{
eventsMask &= ~wxTOUCH_ZOOM_GESTURE;
config.dwID = GID_ZOOM;
config.dwWant = GC_ZOOM;
configs.push_back(config);
}
if ( eventsMask & wxTOUCH_ROTATE_GESTURE )
{
eventsMask &= ~wxTOUCH_ROTATE_GESTURE;
config.dwID = GID_ROTATE;
config.dwWant = GC_ROTATE;
configs.push_back(config);
}
if ( eventsMask & wxTOUCH_PRESS_GESTURES )
{
eventsMask &= ~wxTOUCH_PRESS_GESTURES;
config.dwID = GID_TWOFINGERTAP;
config.dwWant = GC_TWOFINGERTAP;
configs.push_back(config);
config.dwID = GID_PRESSANDTAP;
config.dwWant = GC_PRESSANDTAP;
configs.push_back(config);
}
// As we clear all the known bits if they're set in the code above,
// there should be nothing left.
wxCHECK_MSG( eventsMask == 0, false,
wxS("Unknown touch event mask bit specified") );
ptrConfigs = &configs[0];
}
if ( !GestureFuncs::SetGestureConfig()
(
m_hWnd,
0, // Reserved, must be always 0.
1, // Number of gesture configurations.
&gestureConfig, // Pointer to the first one.
numConfigs, // Number of gesture configurations.
ptrConfigs, // Pointer to the first one.
sizeof(GESTURECONFIG) // Size of each configuration.
)
)