patch 9.0.1084: code handling low level MS-Windows events cannot be tested

Problem:    Code handling low level MS-Windows events cannot be tested.
Solution:   Add test_mswin_event() and tests using it. (Christopher Plewright,
            closes #11622)
diff --git a/src/testdir/mouse.vim b/src/testdir/mouse.vim
index d59ad0e..e2979b7 100644
--- a/src/testdir/mouse.vim
+++ b/src/testdir/mouse.vim
@@ -20,6 +20,27 @@
   let g:Ttymouse_netterm = []
 endif
 
+" Vim Mouse Codes.
+" Used by the GUI and by MS-Windows Consoles.
+" Keep these in sync with vim.h
+let s:MOUSE_CODE = {
+  \ 'BTN_LEFT'    :  0x00,
+  \ 'BTN_MIDDLE'  :  0x01,
+  \ 'BTN_RIGHT'   :  0x02,
+  \ 'BTN_RELEASE' :  0x03,
+  \ 'BTN_X1'      : 0x300,
+  \ 'BTN_X2'      : 0x400,
+  \ 'SCRL_DOWN'   : 0x100,
+  \ 'SCRL_UP'     : 0x200,
+  \ 'SCRL_LEFT'   : 0x500,
+  \ 'SCRL_RIGHT'  : 0x600,
+  \ 'MOVE'        : 0x700,
+  \ 'MOD_SHIFT'   :  0x04,
+  \ 'MOD_ALT'     :  0x08,
+  \ 'MOD_CTRL'    :  0x10,
+  \ }
+
+
 " Helper function to emit a terminal escape code.
 func TerminalEscapeCode(code, row, col, m)
   if &ttymouse ==# 'xterm2'
@@ -47,6 +68,31 @@
     return printf("\<Esc>}%d,%d\r", a:row, a:col)
 endfunc
 
+" Send low level mouse event to MS-Windows consoles or GUI
+func MSWinMouseEvent(button, row, col, move, multiclick, modifiers)
+    let args = { }
+    let args.button = a:button
+    " Scroll directions are inverted in the GUI, no idea why.
+    if has('gui_running')
+      if a:button == s:MOUSE_CODE.SCRL_UP
+        let args.button = s:MOUSE_CODE.SCRL_DOWN
+      elseif a:button == s:MOUSE_CODE.SCRL_DOWN
+        let args.button = s:MOUSE_CODE.SCRL_UP
+      elseif a:button == s:MOUSE_CODE.SCRL_LEFT
+        let args.button = s:MOUSE_CODE.SCRL_RIGHT
+      elseif a:button == s:MOUSE_CODE.SCRL_RIGHT
+        let args.button = s:MOUSE_CODE.SCRL_LEFT
+      endif
+    endif
+    let args.row = a:row
+    let args.col = a:col
+    let args.move = a:move
+    let args.multiclick = a:multiclick
+    let args.modifiers = a:modifiers
+    call test_mswin_event("mouse", args)
+    unlet args
+endfunc
+
 func MouseLeftClickCode(row, col)
   if &ttymouse ==# 'dec'
     return DecEscapeCode(2, 4, a:row, a:col)
@@ -58,7 +104,11 @@
 endfunc
 
 func MouseLeftClick(row, col)
-  call feedkeys(MouseLeftClickCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_LEFT, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseLeftClickCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseMiddleClickCode(row, col)
@@ -70,7 +120,11 @@
 endfunc
 
 func MouseMiddleClick(row, col)
-  call feedkeys(MouseMiddleClickCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_MIDDLE, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseMiddleClickCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseRightClickCode(row, col)
@@ -82,7 +136,11 @@
 endfunc
 
 func MouseRightClick(row, col)
-  call feedkeys(MouseRightClickCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_RIGHT, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseRightClickCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseCtrlLeftClickCode(row, col)
@@ -91,7 +149,12 @@
 endfunc
 
 func MouseCtrlLeftClick(row, col)
-  call feedkeys(MouseCtrlLeftClickCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_LEFT, a:row, a:col, 0, 0,
+                                                         \ s:MOUSE_CODE.MOD_CTRL)
+  else
+    call feedkeys(MouseCtrlLeftClickCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseCtrlRightClickCode(row, col)
@@ -100,7 +163,12 @@
 endfunc
 
 func MouseCtrlRightClick(row, col)
-  call feedkeys(MouseCtrlRightClickCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_RIGHT, a:row, a:col, 0, 0,
+                                                       \ s:MOUSE_CODE.MOD_CTRL)
+  else
+    call feedkeys(MouseCtrlRightClickCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseAltLeftClickCode(row, col)
@@ -109,7 +177,12 @@
 endfunc
 
 func MouseAltLeftClick(row, col)
-  call feedkeys(MouseAltLeftClickCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_LEFT, a:row, a:col, 0, 0,
+                                                       \ s:MOUSE_CODE.MOD_ALT)
+  else
+    call feedkeys(MouseAltLeftClickCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseAltRightClickCode(row, col)
@@ -118,7 +191,12 @@
 endfunc
 
 func MouseAltRightClick(row, col)
-  call feedkeys(MouseAltRightClickCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_RIGHT, a:row, a:col, 0, 0,
+                                                       \ s:MOUSE_CODE.MOD_ALT)
+  else
+    call feedkeys(MouseAltRightClickCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseLeftReleaseCode(row, col)
@@ -132,7 +210,11 @@
 endfunc
 
 func MouseLeftRelease(row, col)
-  call feedkeys(MouseLeftReleaseCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_RELEASE, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseLeftReleaseCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseMiddleReleaseCode(row, col)
@@ -144,7 +226,11 @@
 endfunc
 
 func MouseMiddleRelease(row, col)
-  call feedkeys(MouseMiddleReleaseCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_RELEASE, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseMiddleReleaseCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseRightReleaseCode(row, col)
@@ -156,7 +242,11 @@
 endfunc
 
 func MouseRightRelease(row, col)
-  call feedkeys(MouseRightReleaseCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_RELEASE, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseRightReleaseCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseLeftDragCode(row, col)
@@ -168,7 +258,11 @@
 endfunc
 
 func MouseLeftDrag(row, col)
-  call feedkeys(MouseLeftDragCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.BTN_LEFT, a:row, a:col, 1, 0, 0)
+  else
+    call feedkeys(MouseLeftDragCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseWheelUpCode(row, col)
@@ -176,7 +270,11 @@
 endfunc
 
 func MouseWheelUp(row, col)
-  call feedkeys(MouseWheelUpCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.SCRL_UP, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseWheelUpCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseWheelDownCode(row, col)
@@ -184,7 +282,11 @@
 endfunc
 
 func MouseWheelDown(row, col)
-  call feedkeys(MouseWheelDownCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.SCRL_DOWN, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseWheelDownCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseWheelLeftCode(row, col)
@@ -192,7 +294,11 @@
 endfunc
 
 func MouseWheelLeft(row, col)
-  call feedkeys(MouseWheelLeftCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.SCRL_LEFT, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseWheelLeftCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 func MouseWheelRightCode(row, col)
@@ -200,7 +306,67 @@
 endfunc
 
 func MouseWheelRight(row, col)
-  call feedkeys(MouseWheelRightCode(a:row, a:col), 'Lx!')
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.SCRL_RIGHT, a:row, a:col, 0, 0, 0)
+  else
+    call feedkeys(MouseWheelRightCode(a:row, a:col), 'Lx!')
+  endif
+endfunc
+
+func MouseShiftWheelUpCode(row, col)
+  " todo feed shift mod.
+  return TerminalEscapeCode(0x40, a:row, a:col, 'M')
+endfunc
+
+func MouseShiftWheelUp(row, col)
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.SCRL_UP, a:row, a:col, 0, 0,
+                                                      \ s:MOUSE_CODE.MOD_SHIFT)
+  else
+    call feedkeys(MouseShiftWheelUpCode(a:row, a:col), 'Lx!')
+  endif
+endfunc
+
+func MouseShiftWheelDownCode(row, col)
+  " todo feed shift mod.
+  return TerminalEscapeCode(0x41, a:row, a:col, 'M')
+endfunc
+
+func MouseShiftWheelDown(row, col)
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.SCRL_DOWN, a:row, a:col, 0, 0,
+                                                      \ s:MOUSE_CODE.MOD_SHIFT)
+  else
+    call feedkeys(MouseShiftWheelDownCode(a:row, a:col), 'Lx!')
+  endif
+endfunc
+
+func MouseShiftWheelLeftCode(row, col)
+  " todo feed shift mod.
+  return TerminalEscapeCode(0x42, a:row, a:col, 'M')
+endfunc
+
+func MouseShiftWheelLeft(row, col)
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.SCRL_LEFT, a:row, a:col, 0, 0,
+                                                      \ s:MOUSE_CODE.MOD_SHIFT)
+  else
+    call feedkeys(MouseShiftWheelLeftCode(a:row, a:col), 'Lx!')
+  endif
+endfunc
+
+func MouseShiftWheelRightCode(row, col)
+	" todo feed shift mod.
+  return TerminalEscapeCode(0x43, a:row, a:col, 'M')
+endfunc
+
+func MouseShiftWheelRight(row, col)
+  if has('win32')
+    call MSWinMouseEvent(s:MOUSE_CODE.SCRL_RIGHT, a:row, a:col, 0, 0,
+                                                      \ s:MOUSE_CODE.MOD_SHIFT)
+  else
+    call feedkeys(MouseShiftWheelRightCode(a:row, a:col), 'Lx!')
+  endif
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab