handle middle mouse button events

This commit is contained in:
Vincent Wei
2019-06-12 19:08:24 +08:00
parent 22cf10c508
commit 50fcc2afc9
6 changed files with 262 additions and 172 deletions

View File

@@ -1718,13 +1718,13 @@ typedef struct _GAL_Rect {
#define KS_RIGHTBUTTON 0x00002000
/**
* \def KS_MIDDLBUTTON
* \def KS_MIDDLEBUTTON
* \brief This status indicate that middle button was pressed when
* the key or mouse message posted to the window.
*
* \sa key_msgs
*/
#define KS_MIDDLBUTTON 0x00004000
#define KS_MIDDLEBUTTON 0x00004000
/**
* \def MASK_KS_BUTTONS

View File

@@ -548,6 +548,7 @@ static LRESULT DefaultMouseMsgHandler (PMAINWIN pWin, UINT message,
case MSG_LBUTTONDOWN:
case MSG_RBUTTONDOWN:
case MSG_MBUTTONDOWN:
if (pUnderPointer) {
if (pUnderPointer->dwStyle & WS_DISABLED) {
Ping ();
@@ -585,6 +586,7 @@ static LRESULT DefaultMouseMsgHandler (PMAINWIN pWin, UINT message,
case MSG_RBUTTONUP:
case MSG_LBUTTONUP:
case MSG_MBUTTONUP:
if (__mgs_captured_ctrl && message == MSG_LBUTTONUP) {
PostMessage ((HWND)__mgs_captured_ctrl,
message + MSG_NCMOUSEOFF,
@@ -613,6 +615,7 @@ static LRESULT DefaultMouseMsgHandler (PMAINWIN pWin, UINT message,
case MSG_LBUTTONDBLCLK:
case MSG_RBUTTONDBLCLK:
case MSG_MBUTTONDBLCLK:
if (pUnderPointer) {
if (pUnderPointer->dwStyle & WS_DISABLED) {
Ping ();

View File

@@ -865,6 +865,7 @@ static PMAINWIN _mgs_old_under_p = NULL;
#define DOWN_BUTTON_NONE 0x0000
#define DOWN_BUTTON_LEFT 0x0001
#define DOWN_BUTTON_RIGHT 0x0002
#define DOWN_BUTTON_MIDDLE 0x0004
#define DOWN_BUTTON_ANY 0x000F
static DWORD _mgs_down_buttons = 0;
@@ -975,14 +976,17 @@ static LRESULT MouseMessageHandler (UINT message, WPARAM flags, int x, int y)
case MSG_LBUTTONDOWN:
case MSG_RBUTTONDOWN:
case MSG_MBUTTONDOWN:
if (_mgs_button_down_main_window) {
PostMessage ((HWND)_mgs_button_down_main_window,
message + MSG_DT_MOUSEOFF,
flags, MAKELONG (x, y));
if (message == MSG_LBUTTONDOWN)
_mgs_down_buttons |= DOWN_BUTTON_LEFT;
else
else if (message == MSG_RBUTTONDOWN)
_mgs_down_buttons |= DOWN_BUTTON_RIGHT;
else
_mgs_down_buttons |= DOWN_BUTTON_MIDDLE;
}
else if (pUnderPointer) {
#ifdef _MGHAVE_MENU
@@ -1013,8 +1017,10 @@ static LRESULT MouseMessageHandler (UINT message, WPARAM flags, int x, int y)
_mgs_button_down_main_window = pUnderPointer;
if (message == MSG_LBUTTONDOWN)
_mgs_down_buttons = DOWN_BUTTON_LEFT;
else
else if (message == MSG_RBUTTONDOWN)
_mgs_down_buttons = DOWN_BUTTON_RIGHT;
else
_mgs_down_buttons = DOWN_BUTTON_MIDDLE;
}
else {
dskSetActiveWindow (NULL);
@@ -1027,12 +1033,17 @@ static LRESULT MouseMessageHandler (UINT message, WPARAM flags, int x, int y)
case MSG_LBUTTONUP:
case MSG_RBUTTONUP:
case MSG_MBUTTONUP:
if (_mgs_down_buttons == DOWN_BUTTON_LEFT &&
message == MSG_RBUTTONUP) {
message != MSG_LBUTTONUP) {
break;
}
if (_mgs_down_buttons == DOWN_BUTTON_RIGHT &&
message == MSG_LBUTTONUP) {
message != MSG_RBUTTONUP) {
break;
}
if (_mgs_down_buttons == DOWN_BUTTON_MIDDLE &&
message != MSG_MBUTTONUP) {
break;
}
@@ -1042,8 +1053,10 @@ static LRESULT MouseMessageHandler (UINT message, WPARAM flags, int x, int y)
flags, MAKELONG (x, y));
if (message == MSG_LBUTTONUP)
_mgs_down_buttons &= ~DOWN_BUTTON_LEFT;
else
else if (message == MSG_RBUTTONUP)
_mgs_down_buttons &= ~DOWN_BUTTON_RIGHT;
else
_mgs_down_buttons &= ~DOWN_BUTTON_MIDDLE;
if (!(_mgs_down_buttons & DOWN_BUTTON_ANY)) {
_mgs_button_down_main_window = NULL;
@@ -1074,14 +1087,17 @@ static LRESULT MouseMessageHandler (UINT message, WPARAM flags, int x, int y)
case MSG_LBUTTONDBLCLK:
case MSG_RBUTTONDBLCLK:
case MSG_MBUTTONDBLCLK:
if (_mgs_button_down_main_window) {
PostMessage ((HWND)_mgs_button_down_main_window,
message + MSG_DT_MOUSEOFF,
flags, MAKELONG (x, y));
if (message == MSG_LBUTTONDBLCLK)
_mgs_down_buttons |= DOWN_BUTTON_LEFT;
else
else if (message == MSG_RBUTTONDBLCLK)
_mgs_down_buttons |= DOWN_BUTTON_RIGHT;
else
_mgs_down_buttons |= DOWN_BUTTON_MIDDLE;
}
else if (pUnderPointer) {
PostMessage ((HWND)pUnderPointer,
@@ -1090,8 +1106,10 @@ static LRESULT MouseMessageHandler (UINT message, WPARAM flags, int x, int y)
_mgs_button_down_main_window = pUnderPointer;
if (message == MSG_LBUTTONDBLCLK)
_mgs_down_buttons = DOWN_BUTTON_LEFT;
else
else if (message == MSG_RBUTTONDBLCLK)
_mgs_down_buttons = DOWN_BUTTON_RIGHT;
else
_mgs_down_buttons = DOWN_BUTTON_MIDDLE;
}
else {
PostMessage (HWND_DESKTOP,

File diff suppressed because it is too large Load Diff

View File

@@ -126,8 +126,9 @@ static void GetTimeout (void)
/* Mouse event parameters. */
static int oldbutton = 0;
static DWORD time1;
static DWORD time2;
static DWORD time1; // for double click of left button
static DWORD time2; // for double click of right button
static DWORD time3; // for double click of middle button
/* Key event parameters. */
static DWORD ke_time;
@@ -161,6 +162,7 @@ static void ResetMouseEvent(void)
time1 = 0;
time2 = 0;
time3 = 0;
}
static void ResetKeyEvent(void)
@@ -333,6 +335,7 @@ BOOL kernel_GetLWEvent (int event, PLWEVENT lwe)
me->event = ME_MOVED;
time1 = 0;
time2 = 0;
time3 = 0;
if (button == oldbutton)
goto mouseret;
@@ -381,6 +384,26 @@ BOOL kernel_GetLWEvent (int event, PLWEVENT lwe)
me->event = ME_RIGHTUP;
goto mouseret;
}
if ( !(oldbutton & IAL_MOUSE_MIDDLEBUTTON) &&
(button & IAL_MOUSE_MIDDLEBUTTON) )
{
interval = __mg_timer_counter - time3;
if (interval <= dblclicktime)
me->event = ME_MIDDLEDBLCLICK;
else
me->event = ME_MIDDLEDOWN;
time3 = __mg_timer_counter;
goto mouseret;
}
if ( (oldbutton & IAL_MOUSE_MIDDLEBUTTON) &&
!(button & IAL_MOUSE_MIDDLEBUTTON) )
{
me->event = ME_MIDDLEUP;
goto mouseret;
}
}
if (event & IAL_KEYEVENT) {
@@ -526,6 +549,8 @@ mouseret:
status |= KS_LEFTBUTTON;
if (oldbutton & IAL_MOUSE_RIGHTBUTTON)
status |= KS_RIGHTBUTTON;
if (oldbutton & IAL_MOUSE_MIDDLEBUTTON)
status |= KS_MIDDLEBUTTON;
me->status = status;
#ifndef _MGRM_STANDALONE
SHAREDRES_SHIFTSTATUS = status;
@@ -605,6 +630,7 @@ BOOL kernel_GetLWEvent (int event, PLWEVENT lwe)
me->event = ME_MOVED;
time1 = 0;
time2 = 0;
time3 = 0;
//Note:should contains button state in MSG_MOUSEMOVE
if (button == oldbutton)
@@ -654,6 +680,26 @@ BOOL kernel_GetLWEvent (int event, PLWEVENT lwe)
me->event = ME_RIGHTUP;
goto mouseret;
}
if ( !(oldbutton & IAL_MOUSE_MIDDLEBUTTON) &&
(button & IAL_MOUSE_MIDDLEBUTTON) )
{
interval = __mg_timer_counter - time3;
if (interval <= dblclicktime)
me->event = ME_MIDDLEDBLCLICK;
else
me->event = ME_MIDDLEDOWN;
time3 = __mg_timer_counter;
goto mouseret;
}
if ( (oldbutton & IAL_MOUSE_MIDDLEBUTTON) &&
!(button & IAL_MOUSE_MIDDLEBUTTON) )
{
me->event = ME_MIDDLEUP;
goto mouseret;
}
}
if (event & IAL_KEYEVENT) {
@@ -784,6 +830,8 @@ mouseret:
status |= KS_LEFTBUTTON;
if (oldbutton & IAL_MOUSE_RIGHTBUTTON)
status |= KS_RIGHTBUTTON;
if (oldbutton & IAL_MOUSE_MIDDLEBUTTON)
status |= KS_MIDDLEBUTTON;
me->status = status;
memcpy (&old_lwe, lwe, sizeof (LWEVENT));
__mg_event_timeout.tv_sec = 0;

View File

@@ -142,6 +142,15 @@ static void ParseEvent (PLWEVENT lwe)
case ME_RIGHTDBLCLICK:
Msg.message = MSG_RBUTTONDBLCLK;
break;
case ME_MIDDLEDOWN:
Msg.message = MSG_MBUTTONDOWN;
break;
case ME_MIDDLEUP:
Msg.message = MSG_MBUTTONUP;
break;
case ME_MIDDLEDBLCLICK:
Msg.message = MSG_MBUTTONDBLCLK;
break;
}
if (me->event != ME_MOVED && (mouse_x != me->x || mouse_y != me->y)) {