summaryrefslogtreecommitdiffstats
path: root/src/testdir/mouse.vim
diff options
context:
space:
mode:
authorChristopher Plewright <chris@createng.com>2022-12-20 20:01:58 +0000
committerBram Moolenaar <Bram@vim.org>2022-12-20 20:01:58 +0000
commit20b795e0eba6c933868c8f7cf62fb85d4f007688 (patch)
treeac278d8ec958a58ba6c5a90fba8aef7270abc72f /src/testdir/mouse.vim
parent418b54788106efd94bbc71a4b100afae1080cbfc (diff)
patch 9.0.1084: code handling low level MS-Windows events cannot be testedv9.0.1084
Problem: Code handling low level MS-Windows events cannot be tested. Solution: Add test_mswin_event() and tests using it. (Christopher Plewright, closes #11622)
Diffstat (limited to 'src/testdir/mouse.vim')
-rw-r--r--src/testdir/mouse.vim196
1 files changed, 181 insertions, 15 deletions
diff --git a/src/testdir/mouse.vim b/src/testdir/mouse.vim
index d59ad0eab6..e2979b771c 100644
--- a/src/testdir/mouse.vim
+++ b/src/testdir/mouse.vim
@@ -20,6 +20,27 @@ else
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 @@ func NettermEscapeCode(row, col)
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 @@ func MouseLeftClickCode(row, col)
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 @@ func MouseMiddleClickCode(row, col)
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 @@ func MouseRightClickCode(row, col)
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 @@ func MouseCtrlLeftClickCode(row, col)
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 @@ func MouseCtrlRightClickCode(row, col)
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 @@ func MouseAltLeftClickCode(row, col)
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 @@ func MouseAltRightClickCode(row, col)
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 @@ func MouseLeftReleaseCode(row, col)
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 @@ func MouseMiddleReleaseCode(row, col)
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 @@ func MouseRightReleaseCode(row, col)
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 @@ func MouseLeftDragCode(row, col)
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 @@ func MouseWheelUpCode(row, col)
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 @@ func MouseWheelDownCode(row, col)
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 @@ func MouseWheelLeftCode(row, col)
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 @@ func MouseWheelRightCode(row, col)
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