annotate src/mouse.c @ 18150:0ec6521e9d80 v8.1.2070

patch 8.1.2070: mouse code is spread out Commit: https://github.com/vim/vim/commit/b8ff5c271ee5dcef6f63436b77e228e062ff9a0e Author: Bram Moolenaar <Bram@vim.org> Date: Mon Sep 23 21:16:54 2019 +0200 patch 8.1.2070: mouse code is spread out Problem: Mouse code is spread out. Solution: Move mouse terminal code parsing to mouse.c. (Yegappan Lakshmanan, closes #4966)
author Bram Moolenaar <Bram@vim.org>
date Mon, 23 Sep 2019 21:30:04 +0200
parents 2cc67e54edf8
children 9f51d0cef8da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18135
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * mouse.c: mouse handling functions
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_MOUSE) || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * Get class of a character for selection: same class means same word.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 * 0: blank
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 * 1: punctuation groups
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * 2: normal word character
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 * >2: multi-byte word character.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 static int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 get_mouse_class(char_u *p)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 int c;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 return mb_get_class(p);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 c = *p;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 if (c == ' ' || c == '\t')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 return 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 if (vim_iswordc(c))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 return 2;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 // There are a few special cases where we want certain combinations of
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 // characters to be considered as a single word. These are things like
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 // "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 // character is in its own class.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 return 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 return c;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 * Move "pos" back to the start of the word it's in.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 static void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 find_start_of_word(pos_T *pos)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 char_u *line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 int cclass;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 int col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 line = ml_get(pos->lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 cclass = get_mouse_class(line + pos->col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 while (pos->col > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 col = pos->col - 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 col -= (*mb_head_off)(line, line + col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 if (get_mouse_class(line + col) != cclass)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 pos->col = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 * Move "pos" forward to the end of the word it's in.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 * When 'selection' is "exclusive", the position is just after the word.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 static void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 find_end_of_word(pos_T *pos)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 char_u *line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 int cclass;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 int col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 line = ml_get(pos->lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 if (*p_sel == 'e' && pos->col > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 --pos->col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 pos->col -= (*mb_head_off)(line, line + pos->col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 cclass = get_mouse_class(line + pos->col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 while (line[pos->col] != NUL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 col = pos->col + (*mb_ptr2len)(line + pos->col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 if (get_mouse_class(line + col) != cclass)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 if (*p_sel == 'e')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 pos->col = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 pos->col = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102
18141
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
103 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
104 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
105 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON) \
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
106 || defined(FEAT_TERM_POPUP_MENU)
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
107 # define USE_POPUP_SETPOS
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
108 # define NEED_VCOL2COL
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
109
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
110 /*
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
111 * Translate window coordinates to buffer position without any side effects
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
112 */
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
113 static int
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
114 get_fpos_of_mouse(pos_T *mpos)
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
115 {
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
116 win_T *wp;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
117 int row = mouse_row;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
118 int col = mouse_col;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
119
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
120 if (row < 0 || col < 0) // check if it makes sense
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
121 return IN_UNKNOWN;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
122
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
123 // find the window where the row is in
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
124 wp = mouse_find_win(&row, &col, FAIL_POPUP);
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
125 if (wp == NULL)
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
126 return IN_UNKNOWN;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
127 // winpos and height may change in win_enter()!
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
128 if (row >= wp->w_height) // In (or below) status line
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
129 return IN_STATUS_LINE;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
130 if (col >= wp->w_width) // In vertical separator line
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
131 return IN_SEP_LINE;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
132
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
133 if (wp != curwin)
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
134 return IN_UNKNOWN;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
135
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
136 // compute the position in the buffer line from the posn on the screen
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
137 if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum, NULL))
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
138 return IN_STATUS_LINE; // past bottom
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
139
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
140 mpos->col = vcol2col(wp, mpos->lnum, col);
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
141
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
142 if (mpos->col > 0)
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
143 --mpos->col;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
144 mpos->coladd = 0;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
145 return IN_BUFFER;
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
146 }
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
147 #endif
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
148
18135
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 * Do the appropriate action for the current mouse click in the current mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 * Not used for Command-line mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 * Normal and Visual Mode:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 * event modi- position visual change action
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 * fier cursor window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 * left press - yes end yes
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 * left press C yes end yes "^]" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 * left press S yes end (popup: extend) yes "*" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 * left drag - yes start if moved no
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 * left relse - yes start if moved no
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 * middle press - yes if not active no put register
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 * middle press - yes if active no yank and put
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 * right press - yes start or extend yes
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 * right press S yes no change yes "#" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 * right drag - yes extend no
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 * right relse - yes extend no
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 * Insert or Replace Mode:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 * event modi- position visual change action
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 * fier cursor window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 * left press - yes (cannot be active) yes
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 * left press C yes (cannot be active) yes "CTRL-O^]" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 * left press S yes (cannot be active) yes "CTRL-O*" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 * left drag - yes start or extend (1) no CTRL-O (1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 * left relse - yes start or extend (1) no CTRL-O (1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 * middle press - no (cannot be active) no put register
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 * right press - yes start or extend yes CTRL-O
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 * right press S yes (cannot be active) yes "CTRL-O#" (2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 * (1) only if mouse pointer moved since press
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 * (2) only if click is in same buffer
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 * Return TRUE if start_arrow() should be called for edit mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 do_mouse(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 oparg_T *oap, // operator argument, can be NULL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 int c, // K_LEFTMOUSE, etc
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 int dir, // Direction to 'put' if necessary
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 long count,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 int fixindent) // PUT_FIXINDENT if fixing indent necessary
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 static int do_always = FALSE; // ignore 'mouse' setting next time
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 static int got_click = FALSE; // got a click some time back
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 int which_button; // MOUSE_LEFT, _MIDDLE or _RIGHT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 int is_click = FALSE; // If FALSE it's a drag or release event
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 int is_drag = FALSE; // If TRUE it's a drag event
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 int jump_flags = 0; // flags for jump_to_mouse()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 pos_T start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 int moved; // Has cursor moved?
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 int in_status_line; // mouse in status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 static int in_tab_line = FALSE; // mouse clicked in tab line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 int in_sep_line; // mouse in vertical separator line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 int c1, c2;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 #if defined(FEAT_FOLDING)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 pos_T save_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 win_T *old_curwin = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 static pos_T orig_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 colnr_T leftcol, rightcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 pos_T end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 int diff;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 int old_active = VIsual_active;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 int old_mode = VIsual_mode;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 int regname;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 #if defined(FEAT_FOLDING)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 save_cursor = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 // When GUI is active, always recognize mouse events, otherwise:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 // - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 // - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 // - For command line and insert mode 'mouse' is checked before calling
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 // do_mouse().
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 if (do_always)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 do_always = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 if (!gui.in_use)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 if (!mouse_has(MOUSE_VISUAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 else if (State == NORMAL && !mouse_has(MOUSE_NORMAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 for (;;)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 if (is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 // If the next character is the same mouse event then use that
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 // one. Speeds up dragging the status line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 if (vpeekc() != NUL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 int nc;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 int save_mouse_row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 int save_mouse_col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 // Need to get the character, peeking doesn't get the actual
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 // one.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 nc = safe_vgetc();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 if (c == nc)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 continue;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 vungetc(nc);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 mouse_row = save_mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 mouse_col = save_mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 if (c == K_MOUSEMOVE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 // Mouse moved without a button pressed.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 #ifdef FEAT_BEVAL_TERM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 ui_may_remove_balloon();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 if (p_bevalterm)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 profile_setlimit(p_bdlay, &bevalexpr_due);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 bevalexpr_due_set = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 popup_handle_mouse_moved();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 #ifdef FEAT_MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 // May have stopped dragging the status or separator line. The pointer is
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 // most likely still on the status or separator line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 if (!is_drag && drag_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 drag_status_line = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 update_mouseshape(SHAPE_IDX_STATUS);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 if (!is_drag && drag_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 drag_sep_line = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 update_mouseshape(SHAPE_IDX_VSEP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 // Ignore drag and release events if we didn't get a click.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 if (is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 got_click = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 if (!got_click) // didn't get click, ignore
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 if (!is_drag) // release, reset got_click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 got_click = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 if (in_tab_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 in_tab_line = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 // CTRL right mouse button does CTRL-T
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 if (State & INSERT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 stuffcharReadbuff(Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 if (count > 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 stuffnumReadbuff(count);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 stuffcharReadbuff(Ctrl_T);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 got_click = FALSE; // ignore drag&release now
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 // CTRL only works with left mouse button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 // When a modifier is down, ignore drag and release events, as well as
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 // multiple clicks and the middle mouse button.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 // Accept shift-leftmouse drags when 'mousemodel' is "popup.*".
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 | MOD_MASK_META))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 && (!is_click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 || (mod_mask & MOD_MASK_MULTI_CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 || which_button == MOUSE_MIDDLE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 && !((mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 && mouse_model_popup()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 && !((mod_mask & MOD_MASK_ALT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 && !mouse_model_popup()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 && which_button == MOUSE_RIGHT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 // If the button press was used as the movement command for an operator
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 // (eg "d<MOUSE>"), or it is the middle button that is held down, ignore
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 // drag/release events.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 if (!is_click && which_button == MOUSE_MIDDLE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 if (oap != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 regname = oap->regname;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 regname = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 // Middle mouse button does a 'put' of the selected text
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 if (which_button == MOUSE_MIDDLE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 if (State == NORMAL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 // If an operator was pending, we don't know what the user wanted
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 // to do. Go back to normal mode: Clear the operator and beep().
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 if (oap != NULL && oap->op_type != OP_NOP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 clearopbeep(oap);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 // If visual was active, yank the highlighted text and put it
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 // before the mouse pointer position.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 // In Select mode replace the highlighted text with the clipboard.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 if (VIsual_select)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 stuffcharReadbuff(Ctrl_G);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 stuffReadbuff((char_u *)"\"+p");
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 stuffcharReadbuff('y');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 stuffcharReadbuff(K_MIDDLEMOUSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 do_always = TRUE; // ignore 'mouse' setting next time
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 // The rest is below jump_to_mouse()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 else if ((State & INSERT) == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 // Middle click in insert mode doesn't move the mouse, just insert the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 // contents of a register. '.' register is special, can't insert that
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 // with do_put().
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 // Also paste at the cursor if the current mode isn't in 'mouse' (only
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 // happens for the GUI).
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 if (regname == '.')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 insert_reg(regname, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 #ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 if (clip_star.available && regname == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 regname = '*';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 if ((State & REPLACE_FLAG) && !yank_register_mline(regname))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 insert_reg(regname, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 // Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 AppendCharToRedobuff(Ctrl_R);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 AppendCharToRedobuff(regname == 0 ? '"' : regname);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 // When dragging or button-up stay in the same window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 if (!is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 start_visual.lnum = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 // Check for clicking in the tab page line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 if (mouse_row == 0 && firstwin->w_winrow > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 if (is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 if (in_tab_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 c1 = TabPageIdxs[mouse_col];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 tabpage_move(c1 <= 0 ? 9999 : c1 < tabpage_index(curtab)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 ? c1 - 1 : c1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 // click in a tab selects that tab page
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 if (is_click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 # ifdef FEAT_CMDWIN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 && cmdwin_type == 0
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 && mouse_col < Columns)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 in_tab_line = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 c1 = TabPageIdxs[mouse_col];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 if (c1 >= 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 // double click opens new page
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 tabpage_new();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 tabpage_move(c1 == 0 ? 9999 : c1 - 1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 // Go to specified tab page, or next one if not clicking
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 // on a label.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 goto_tabpage(c1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 // It's like clicking on the status line of a window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 if (curwin != old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 tabpage_T *tp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 // Close the current or specified tab page.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 if (c1 == -999)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 tp = curtab;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 tp = find_tabpage(-c1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 if (tp == curtab)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 if (first_tabpage->tp_next != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 tabpage_close(FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 else if (tp != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 tabpage_close_other(tp, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 return TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 else if (is_drag && in_tab_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 c1 = TabPageIdxs[mouse_col];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 tabpage_move(c1 <= 0 ? 9999 : c1 - 1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 // When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 // right button up -> pop-up menu
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 // shift-left button -> right button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 // alt-left button -> alt-right button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 if (mouse_model_popup())
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 if (which_button == MOUSE_RIGHT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 {
18141
2cc67e54edf8 patch 8.1.2065: compiler warning building non-GUI with MinGW.
Bram Moolenaar <Bram@vim.org>
parents: 18135
diff changeset
516 #ifdef USE_POPUP_SETPOS
18135
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 # ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 if (gui.in_use)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 if (!is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 // Ignore right button release events, only shows the popup
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 // menu on the button down event.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 # if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 if (is_click || is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 // Ignore right button down and drag mouse events. Windows
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 // only shows the popup menu on the button up event.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 # if defined(FEAT_GUI) && defined(FEAT_TERM_POPUP_MENU)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 # if defined(FEAT_TERM_POPUP_MENU)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 if (!is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 // Ignore right button release events, only shows the popup
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 // menu on the button down event.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 jump_flags = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 if (STRCMP(p_mousem, "popup_setpos") == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 // First set the cursor position before showing the popup
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 // menu.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 pos_T m_pos;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 // set MOUSE_MAY_STOP_VIS if we are outside the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 // selection or the current window (might have false
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 // negative here)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 if (mouse_row < curwin->w_winrow
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 || mouse_row
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 > (curwin->w_winrow + curwin->w_height))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 if ((LT_POS(curwin->w_cursor, VIsual)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 && (LT_POS(m_pos, curwin->w_cursor)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 || LT_POS(VIsual, m_pos)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 || (LT_POS(VIsual, curwin->w_cursor)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 && (LT_POS(m_pos, VIsual)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 || LT_POS(curwin->w_cursor, m_pos))))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 else if (VIsual_mode == Ctrl_V)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 getvcols(curwin, &curwin->w_cursor, &VIsual,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 &leftcol, &rightcol);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 if (m_pos.col < leftcol || m_pos.col > rightcol)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 jump_flags = MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 if (jump_flags)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 jump_flags = jump_to_mouse(jump_flags, NULL, which_button);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 update_curbuf(VIsual_active ? INVERTED : VALID);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 setcursor();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 out_flush(); // Update before showing popup menu
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 # ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 show_popupmenu();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 got_click = FALSE; // ignore release events
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 return (jump_flags & CURSOR_MOVED) != 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 #else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 if (which_button == MOUSE_LEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 && (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_ALT)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 which_button = MOUSE_RIGHT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 mod_mask &= ~MOD_MASK_SHIFT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 if ((State & (NORMAL | INSERT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 if (which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 if (is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 // stop Visual mode for a left click in a window, but not when
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 // on a status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 jump_flags |= MOUSE_MAY_STOP_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 else if (mouse_has(MOUSE_VISUAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 jump_flags |= MOUSE_MAY_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 else if (which_button == MOUSE_RIGHT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 if (is_click && VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 // Remember the start and end of visual before moving the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 // cursor.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 if (LT_POS(curwin->w_cursor, VIsual))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 start_visual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 end_visual = VIsual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 start_visual = VIsual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 end_visual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 jump_flags |= MOUSE_FOCUS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 if (mouse_has(MOUSE_VISUAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 jump_flags |= MOUSE_MAY_VIS;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 // If an operator is pending, ignore all drags and releases until the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 // next mouse click.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 if (!is_drag && oap != NULL && oap->op_type != OP_NOP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 got_click = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 oap->motion_type = MCHAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 // When releasing the button let jump_to_mouse() know.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 if (!is_click && !is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 jump_flags |= MOUSE_RELEASED;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 // JUMP!
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 jump_flags = jump_to_mouse(jump_flags,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 oap == NULL ? NULL : &(oap->inclusive), which_button);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 // A click in the window toolbar has no side effects.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 if (jump_flags & MOUSE_WINBAR)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 moved = (jump_flags & CURSOR_MOVED);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 in_status_line = (jump_flags & IN_STATUS_LINE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 in_sep_line = (jump_flags & IN_SEP_LINE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 #ifdef FEAT_NETBEANS_INTG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 if (isNetbeansBuffer(curbuf)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 int key = KEY2TERMCAP1(c);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 || key == (int)KE_RIGHTRELEASE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 netbeans_button_release(which_button);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 // When jumping to another window, clear a pending operator. That's a bit
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 // friendlier than beeping and not jumping to that window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 clearop(oap);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 if (mod_mask == 0
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 && !is_drag
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 // open or close a fold at this line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 if (jump_flags & MOUSE_FOLD_OPEN)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 openFold(curwin->w_cursor.lnum, 1L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 closeFold(curwin->w_cursor.lnum, 1L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 // don't move the cursor if still in the same window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 if (curwin == old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 curwin->w_cursor = save_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 clip_modeless(which_button, is_click, is_drag);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 // Set global flag that we are extending the Visual area with mouse
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 // dragging; temporarily minimize 'scrolloff'.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 if (VIsual_active && is_drag && get_scrolloff_value())
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 // In the very first line, allow scrolling one line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 if (mouse_row == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 mouse_dragging = 2;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 mouse_dragging = 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 // When dragging the mouse above the window, scroll down.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 if (is_drag && mouse_row < 0 && !in_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 scroll_redraw(FALSE, 1L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 mouse_row = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 if (start_visual.lnum) // right click in visual mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 // When ALT is pressed make Visual mode blockwise.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 if (mod_mask & MOD_MASK_ALT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 VIsual_mode = Ctrl_V;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 // In Visual-block mode, divide the area in four, pick up the corner
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 // that is in the quarter that the cursor is in.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 if (VIsual_mode == Ctrl_V)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 if (curwin->w_curswant > (leftcol + rightcol) / 2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 end_visual.col = leftcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 end_visual.col = rightcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 if (curwin->w_cursor.lnum >=
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 (start_visual.lnum + end_visual.lnum) / 2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 end_visual.lnum = start_visual.lnum;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 // move VIsual to the right column
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 start_visual = curwin->w_cursor; // save the cursor pos
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 curwin->w_cursor = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 coladvance(end_visual.col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 VIsual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 curwin->w_cursor = start_visual; // restore the cursor
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 // If the click is before the start of visual, change the start.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 // If the click is after the end of visual, change the end. If
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 // the click is inside the visual, change the closest side.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 if (LT_POS(curwin->w_cursor, start_visual))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 VIsual = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 else if (LT_POS(end_visual, curwin->w_cursor))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 VIsual = start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 // In the same line, compare column number
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 if (end_visual.lnum == start_visual.lnum)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 if (curwin->w_cursor.col - start_visual.col >
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 end_visual.col - curwin->w_cursor.col)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 VIsual = start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 VIsual = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 // In different lines, compare line number
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 diff = (curwin->w_cursor.lnum - start_visual.lnum) -
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 (end_visual.lnum - curwin->w_cursor.lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 if (diff > 0) // closest to end
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 VIsual = start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 else if (diff < 0) // closest to start
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 VIsual = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 else // in the middle line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 if (curwin->w_cursor.col <
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 (start_visual.col + end_visual.col) / 2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 VIsual = end_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 VIsual = start_visual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 // If Visual mode started in insert mode, execute "CTRL-O"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 else if ((State & INSERT) && VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 stuffcharReadbuff(Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 // Middle mouse click: Put text before cursor.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 if (which_button == MOUSE_MIDDLE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 #ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 if (clip_star.available && regname == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 regname = '*';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 if (yank_register_mline(regname))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 if (mouse_past_bottom)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 dir = FORWARD;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 else if (mouse_past_eol)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 dir = FORWARD;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 if (fixindent)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 c1 = (dir == BACKWARD) ? '[' : ']';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 c2 = 'p';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 c1 = (dir == FORWARD) ? 'p' : 'P';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 c2 = NUL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 prep_redo(regname, count, NUL, c1, NUL, c2, NUL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 // Remember where the paste started, so in edit() Insstart can be set
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 // to this position
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 if (restart_edit != 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 where_paste_started = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 do_put(regname, dir, count, fixindent | PUT_CURSEND);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 #if defined(FEAT_QUICKFIX)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 // Ctrl-Mouse click or double click in a quickfix window jumps to the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 // error under the mouse pointer.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 else if (((mod_mask & MOD_MASK_CTRL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 && bt_quickfix(curbuf))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 if (curwin->w_llist_ref == NULL) // quickfix window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 do_cmdline_cmd((char_u *)".cc");
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 else // location list window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 do_cmdline_cmd((char_u *)".ll");
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 got_click = FALSE; // ignore drag&release now
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 // Ctrl-Mouse click (or double click in a help window) jumps to the tag
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 // under the mouse pointer.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 if (State & INSERT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 stuffcharReadbuff(Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 stuffcharReadbuff(Ctrl_RSB);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 got_click = FALSE; // ignore drag&release now
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 // Shift-Mouse click searches for the next occurrence of the word under
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 // the mouse pointer
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 else if ((mod_mask & MOD_MASK_SHIFT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 if ((State & INSERT) || (VIsual_active && VIsual_select))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 stuffcharReadbuff(Ctrl_O);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 if (which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 stuffcharReadbuff('*');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 else // MOUSE_RIGHT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 stuffcharReadbuff('#');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 // Handle double clicks, unless on status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 else if (in_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 #ifdef FEAT_MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 if ((is_drag || is_click) && !drag_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 drag_status_line = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 update_mouseshape(-1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 else if (in_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 #ifdef FEAT_MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 if ((is_drag || is_click) && !drag_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 drag_sep_line = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 update_mouseshape(-1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 && mouse_has(MOUSE_VISUAL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 if (is_click || !VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 orig_cursor = VIsual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 check_visual_highlight();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 VIsual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 orig_cursor = VIsual;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 VIsual_active = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 VIsual_reselect = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 // start Select mode if 'selectmode' contains "mouse"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 may_start_select('o');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 setmouse();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 // Double click with ALT pressed makes it blockwise.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 if (mod_mask & MOD_MASK_ALT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 VIsual_mode = Ctrl_V;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 VIsual_mode = 'v';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 VIsual_mode = 'V';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 VIsual_mode = Ctrl_V;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 #ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 // Make sure the clipboard gets updated. Needed because start and
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 // end may still be the same, and the selection needs to be owned
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 clip_star.vmode = NUL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 // A double click selects a word or a block.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 pos_T *pos = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 int gc;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 if (is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 // If the character under the cursor (skipping white space) is
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 // not a word character, try finding a match and select a (),
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 // {}, [], #if/#endif, etc. block.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 end_visual = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 while (gc = gchar_pos(&end_visual), VIM_ISWHITE(gc))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 inc(&end_visual);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 if (oap != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 oap->motion_type = MCHAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 if (oap != NULL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 && VIsual_mode == 'v'
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 && !vim_iswordc(gchar_pos(&end_visual))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 && EQUAL_POS(curwin->w_cursor, VIsual)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 && (pos = findmatch(oap, NUL)) != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 curwin->w_cursor = *pos;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 if (oap->motion_type == MLINE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 VIsual_mode = 'V';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 else if (*p_sel == 'e')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 if (LT_POS(curwin->w_cursor, VIsual))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 ++VIsual.col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 ++curwin->w_cursor.col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 if (pos == NULL && (is_click || is_drag))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 // When not found a match or when dragging: extend to include
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 // a word.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 if (LT_POS(curwin->w_cursor, orig_cursor))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 find_start_of_word(&curwin->w_cursor);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 find_end_of_word(&VIsual);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 find_start_of_word(&VIsual);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 if (*p_sel == 'e' && *ml_get_cursor() != NUL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 curwin->w_cursor.col +=
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 (*mb_ptr2len)(ml_get_cursor());
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 find_end_of_word(&curwin->w_cursor);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 curwin->w_set_curswant = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 if (is_click)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 redraw_curbuf_later(INVERTED); // update the inversion
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 else if (VIsual_active && !old_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 if (mod_mask & MOD_MASK_ALT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 VIsual_mode = Ctrl_V;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 VIsual_mode = 'v';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 // If Visual mode changed show it later.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 if ((!VIsual_active && old_active && mode_displayed)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 || (VIsual_active && p_smd && msg_silent == 0
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 && (!old_active || VIsual_mode != old_mode)))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 redraw_cmdline = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 return moved;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 ins_mouse(int c)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 pos_T tpos;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 win_T *old_curwin = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 # ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 // When GUI is active, also move/paste when 'mouse' is empty
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 if (!gui.in_use)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 if (!mouse_has(MOUSE_INSERT))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 undisplay_dollar();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 tpos = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 if (do_mouse(NULL, c, BACKWARD, 1L, 0))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 win_T *new_curwin = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 if (curwin != old_curwin && win_valid(old_curwin))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 // Mouse took us to another window. We need to go back to the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 // previous one to stop insert there properly.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 curwin = old_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 #ifdef FEAT_JOB_CHANNEL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 if (bt_prompt(curbuf))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 // Restart Insert mode when re-entering the prompt buffer.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 curbuf->b_prompt_insert = 'A';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 start_arrow(curwin == old_curwin ? &tpos : NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 if (curwin != new_curwin && win_valid(new_curwin))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 curwin = new_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 # ifdef FEAT_CINDENT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 set_can_cindent(TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 // redraw status lines (in case another window became active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 redraw_statuslines();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 ins_mousescroll(int dir)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 pos_T tpos;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 win_T *old_curwin = curwin, *wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 int did_scroll = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 tpos = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 if (mouse_row >= 0 && mouse_col >= 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 int row, col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 // find the window at the pointer coordinates
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 wp = mouse_find_win(&row, &col, FIND_POPUP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 if (wp == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 curwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 if (curwin == old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 undisplay_dollar();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 // Don't scroll the window in which completion is being done.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 if (!pum_visible() || curwin != old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 if (dir == MSCR_DOWN || dir == MSCR_UP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 scroll_redraw(dir,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 (long)(curwin->w_botline - curwin->w_topline));
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 scroll_redraw(dir, 3L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 # ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 if (WIN_IS_POPUP(curwin))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 popup_set_firstline(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 int val, step = 6;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 step = curwin->w_width;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 val = curwin->w_leftcol + (dir == MSCR_RIGHT ? -step : step);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 if (val < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 val = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 gui_do_horiz_scroll(val, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 did_scroll = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 curwin->w_redr_status = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 curwin = old_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 // The popup menu may overlay the window, need to redraw it.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 // TODO: Would be more efficient to only redraw the windows that are
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 // overlapped by the popup menu.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 if (pum_visible() && did_scroll)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 redraw_all_later(NOT_VALID);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 ins_compl_show_pum();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 if (!EQUAL_POS(curwin->w_cursor, tpos))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 start_arrow(&tpos);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 # ifdef FEAT_CINDENT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 set_can_cindent(TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 * Return TRUE if "c" is a mouse key.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 is_mouse_key(int c)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 return c == K_LEFTMOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 || c == K_LEFTMOUSE_NM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 || c == K_LEFTDRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 || c == K_LEFTRELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 || c == K_LEFTRELEASE_NM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 || c == K_MOUSEMOVE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 || c == K_MIDDLEMOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 || c == K_MIDDLEDRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 || c == K_MIDDLERELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 || c == K_RIGHTMOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 || c == K_RIGHTDRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 || c == K_RIGHTRELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 || c == K_MOUSEDOWN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 || c == K_MOUSEUP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 || c == K_MOUSELEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 || c == K_MOUSERIGHT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 || c == K_X1MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 || c == K_X1DRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 || c == K_X1RELEASE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 || c == K_X2MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 || c == K_X2DRAG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 || c == K_X2RELEASE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 static struct mousetable
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 int pseudo_code; // Code for pseudo mouse event
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 int button; // Which mouse button is it?
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 int is_click; // Is it a mouse button click event?
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 int is_drag; // Is it a mouse drag event?
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 } mouse_table[] =
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 {(int)KE_LEFTMOUSE, MOUSE_LEFT, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 {(int)KE_LEFTMOUSE_NM, MOUSE_LEFT, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 {(int)KE_LEFTDRAG, MOUSE_LEFT, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 {(int)KE_LEFTRELEASE, MOUSE_LEFT, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 {(int)KE_LEFTRELEASE_NM, MOUSE_LEFT, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 {(int)KE_MIDDLEMOUSE, MOUSE_MIDDLE, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 {(int)KE_MIDDLEDRAG, MOUSE_MIDDLE, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 {(int)KE_MIDDLERELEASE, MOUSE_MIDDLE, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 {(int)KE_RIGHTMOUSE, MOUSE_RIGHT, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 {(int)KE_RIGHTDRAG, MOUSE_RIGHT, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 {(int)KE_RIGHTRELEASE, MOUSE_RIGHT, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 {(int)KE_X1MOUSE, MOUSE_X1, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 {(int)KE_X1DRAG, MOUSE_X1, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 {(int)KE_X1RELEASE, MOUSE_X1, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 {(int)KE_X2MOUSE, MOUSE_X2, TRUE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 {(int)KE_X2DRAG, MOUSE_X2, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 {(int)KE_X2RELEASE, MOUSE_X2, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 // DRAG without CLICK
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 {(int)KE_MOUSEMOVE, MOUSE_RELEASE, FALSE, TRUE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 // RELEASE without CLICK
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 {(int)KE_IGNORE, MOUSE_RELEASE, FALSE, FALSE},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 {0, 0, 0, 0},
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 };
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 * Look up the given mouse code to return the relevant information in the other
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 * arguments. Return which button is down or was released.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 get_mouse_button(int code, int *is_click, int *is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 int i;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 for (i = 0; mouse_table[i].pseudo_code; i++)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 if (code == mouse_table[i].pseudo_code)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 *is_click = mouse_table[i].is_click;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 *is_drag = mouse_table[i].is_drag;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 return mouse_table[i].button;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 return 0; // Shouldn't get here
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 * Return the appropriate pseudo mouse event token (KE_LEFTMOUSE etc) based on
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 * the given information about which mouse button is down, and whether the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 * mouse was clicked, dragged or released.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 get_pseudo_mouse_code(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 int button, // eg MOUSE_LEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 int is_click,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 int is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 int i;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 for (i = 0; mouse_table[i].pseudo_code; i++)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 if (button == mouse_table[i].button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 && is_click == mouse_table[i].is_click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 && is_drag == mouse_table[i].is_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 // Trick: a non mappable left click and release has mouse_col -1
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 // or added MOUSE_COLOFF. Used for 'mousefocus' in
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 // gui_mouse_moved()
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 if (mouse_col < 0 || mouse_col > MOUSE_COLOFF)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 if (mouse_col < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 mouse_col = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 mouse_col -= MOUSE_COLOFF;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 if (mouse_table[i].pseudo_code == (int)KE_LEFTMOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 return (int)KE_LEFTMOUSE_NM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 if (mouse_table[i].pseudo_code == (int)KE_LEFTRELEASE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 return (int)KE_LEFTRELEASE_NM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 return mouse_table[i].pseudo_code;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 return (int)KE_IGNORE; // not recognized, ignore it
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 # ifdef FEAT_MOUSE_TTY
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 # define HMT_NORMAL 1
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 # define HMT_NETTERM 2
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 # define HMT_DEC 4
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 # define HMT_JSBTERM 8
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 # define HMT_PTERM 16
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 # define HMT_URXVT 32
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 # define HMT_GPM 64
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 # define HMT_SGR 128
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 # define HMT_SGR_REL 256
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 static int has_mouse_termcode = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 # if (!defined(UNIX) || defined(FEAT_MOUSE_TTY)) || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 set_mouse_termcode(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 int n, // KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 char_u *s)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 char_u name[2];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 name[0] = n;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 name[1] = KE_FILLER;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 add_termcode(name, s, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 # ifdef FEAT_MOUSE_TTY
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 # ifdef FEAT_MOUSE_JSB
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 if (n == KS_JSBTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 has_mouse_termcode |= HMT_JSBTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 # ifdef FEAT_MOUSE_NET
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 if (n == KS_NETTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 has_mouse_termcode |= HMT_NETTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 # ifdef FEAT_MOUSE_DEC
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 if (n == KS_DEC_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 has_mouse_termcode |= HMT_DEC;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 # ifdef FEAT_MOUSE_PTERM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 if (n == KS_PTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 has_mouse_termcode |= HMT_PTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 # ifdef FEAT_MOUSE_URXVT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 if (n == KS_URXVT_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 has_mouse_termcode |= HMT_URXVT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 # ifdef FEAT_MOUSE_GPM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 if (n == KS_GPM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 has_mouse_termcode |= HMT_GPM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 if (n == KS_SGR_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 has_mouse_termcode |= HMT_SGR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 else if (n == KS_SGR_MOUSE_RELEASE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 has_mouse_termcode |= HMT_SGR_REL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 has_mouse_termcode |= HMT_NORMAL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 # if ((defined(UNIX) || defined(VMS)) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 && defined(FEAT_MOUSE_TTY)) || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 del_mouse_termcode(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 int n) // KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 char_u name[2];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 name[0] = n;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 name[1] = KE_FILLER;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 del_termcode(name);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 # ifdef FEAT_MOUSE_TTY
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 # ifdef FEAT_MOUSE_JSB
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 if (n == KS_JSBTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 has_mouse_termcode &= ~HMT_JSBTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 # ifdef FEAT_MOUSE_NET
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 if (n == KS_NETTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 has_mouse_termcode &= ~HMT_NETTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 # ifdef FEAT_MOUSE_DEC
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 if (n == KS_DEC_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 has_mouse_termcode &= ~HMT_DEC;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 # ifdef FEAT_MOUSE_PTERM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 if (n == KS_PTERM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 has_mouse_termcode &= ~HMT_PTERM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 # ifdef FEAT_MOUSE_URXVT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 if (n == KS_URXVT_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 has_mouse_termcode &= ~HMT_URXVT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 # ifdef FEAT_MOUSE_GPM
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 if (n == KS_GPM_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 has_mouse_termcode &= ~HMT_GPM;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 if (n == KS_SGR_MOUSE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 has_mouse_termcode &= ~HMT_SGR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 else if (n == KS_SGR_MOUSE_RELEASE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 has_mouse_termcode &= ~HMT_SGR_REL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 has_mouse_termcode &= ~HMT_NORMAL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 * setmouse() - switch mouse on/off depending on current mode and 'mouse'
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 setmouse(void)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 # ifdef FEAT_MOUSE_TTY
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 int checkfor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 # ifdef FEAT_MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 update_mouseshape(-1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 # ifdef FEAT_MOUSE_TTY // Should be outside proc, but may break MOUSESHAPE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 # ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 // In the GUI the mouse is always enabled.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 if (gui.in_use)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 // be quick when mouse is off
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 if (*p_mouse == NUL || has_mouse_termcode == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 // don't switch mouse on when not in raw mode (Ex mode)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 if (cur_tmode != TMODE_RAW)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 mch_setmouse(FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 if (VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 checkfor = MOUSE_VISUAL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 else if (State == HITRETURN || State == ASKMORE || State == SETWSIZE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 checkfor = MOUSE_RETURN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 else if (State & INSERT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 checkfor = MOUSE_INSERT;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 else if (State & CMDLINE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 checkfor = MOUSE_COMMAND;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 else if (State == CONFIRM || State == EXTERNCMD)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 checkfor = ' '; // don't use mouse for ":confirm" or ":!cmd"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 checkfor = MOUSE_NORMAL; // assume normal mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 if (mouse_has(checkfor))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 mch_setmouse(TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 mch_setmouse(FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 * Return TRUE if
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 * - "c" is in 'mouse', or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 * - 'a' is in 'mouse' and "c" is in MOUSE_A, or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 * - the current buffer is a help file and 'h' is in 'mouse' and we are in a
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 * normal editing mode (not at hit-return message).
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 mouse_has(int c)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 char_u *p;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 for (p = p_mouse; *p; ++p)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 switch (*p)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 case 'a': if (vim_strchr((char_u *)MOUSE_A, c) != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 return TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 case MOUSE_HELP: if (c != MOUSE_RETURN && curbuf->b_help)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 return TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 default: if (c == *p) return TRUE; break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 return FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 * Return TRUE when 'mousemodel' is set to "popup" or "popup_setpos".
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 mouse_model_popup(void)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 return (p_mousem[0] == 'p');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 * Move the cursor to the specified row and column on the screen.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 * Change current window if necessary. Returns an integer with the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 * CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 * The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 * The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 * If flags has MOUSE_FOCUS, then the current window will not be changed, and
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 * if the mouse is outside the window then the text will scroll, or if the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 * mouse was previously on a status line, then the status line may be dragged.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 * If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 * cursor is moved unless the cursor was on a status line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 * This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 * IN_SEP_LINE depending on where the cursor was clicked.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 * If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 * the mouse is on the status line of the same window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 * If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 * the last call.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 * If flags has MOUSE_SETPOS, nothing is done, only the current position is
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 * remembered.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 jump_to_mouse(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 int flags,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 int *inclusive, // used for inclusive operator, can be NULL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 int which_button) // MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 static int on_status_line = 0; // #lines below bottom of window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 static int on_sep_line = 0; // on separator right of window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 static int in_winbar = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 static int in_popup_win = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 static win_T *click_in_popup_win = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 static int prev_row = -1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 static int prev_col = -1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 static win_T *dragwin = NULL; // window being dragged
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 static int did_drag = FALSE; // drag was noticed
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 win_T *wp, *old_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 pos_T old_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 int count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 int first;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 int row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 int col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 int mouse_char;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 mouse_past_bottom = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 mouse_past_eol = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 if (flags & MOUSE_RELEASED)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 // On button release we may change window focus if positioned on a
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 // status line and no dragging happened.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 if (dragwin != NULL && !did_drag)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 dragwin = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 did_drag = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 if (click_in_popup_win != NULL && popup_dragwin == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 popup_close_for_mouse_click(click_in_popup_win);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 popup_dragwin = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 click_in_popup_win = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 if ((flags & MOUSE_DID_MOVE)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 && prev_row == mouse_row
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 && prev_col == mouse_col)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 retnomove:
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 // before moving the cursor for a left click which is NOT in a status
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 // line, stop Visual mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 if (on_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 return IN_STATUS_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 if (on_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 return IN_SEP_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 if (in_winbar)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 // A quick second click may arrive as a double-click, but we use it
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 // as a second click in the WinBar.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 if ((mod_mask & MOD_MASK_MULTI_CLICK) && !(flags & MOUSE_RELEASED))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 wp = mouse_find_win(&row, &col, FAIL_POPUP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 if (wp == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 winbar_click(wp, col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 return IN_OTHER_WIN | MOUSE_WINBAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 if (flags & MOUSE_MAY_STOP_VIS)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 redraw_curbuf_later(INVERTED); // delete the inversion
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 // Continue a modeless selection in another window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 if (cmdwin_type != 0 && row < curwin->w_winrow)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 // Continue a modeless selection in a popup window or dragging it.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 if (in_popup_win)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 click_in_popup_win = NULL; // don't close it on release
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 if (popup_dragwin != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 // dragging a popup window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 popup_drag(popup_dragwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 return IN_BUFFER;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 prev_row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 prev_col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 if (flags & MOUSE_SETPOS)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 goto retnomove; // ugly goto...
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 // Remember the character under the mouse, it might be a '-' or '+' in the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 // fold column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 if (row >= 0 && row < Rows && col >= 0 && col <= Columns
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 && ScreenLines != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 mouse_char = ScreenLines[LineOffset[row] + col];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 mouse_char = ' ';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 old_curwin = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 old_cursor = curwin->w_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 if (!(flags & MOUSE_FOCUS))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 if (row < 0 || col < 0) // check if it makes sense
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 // find the window where the row is in and adjust "row" and "col" to be
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 // relative to top-left of the window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 wp = mouse_find_win(&row, &col, FIND_POPUP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 if (wp == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 dragwin = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 // Click in a popup window may start dragging or modeless selection,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 // but not much else.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 if (WIN_IS_POPUP(wp))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 on_sep_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 in_popup_win = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 if (which_button == MOUSE_LEFT && popup_close_if_on_X(wp, row, col))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 else if ((wp->w_popup_flags & (POPF_DRAG | POPF_RESIZE))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 && popup_on_border(wp, row, col))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 popup_dragwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 popup_start_drag(wp, row, col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 // Only close on release, otherwise it's not possible to drag or do
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 // modeless selection.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 else if (wp->w_popup_close == POPCLOSE_CLICK
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 click_in_popup_win = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 else if (which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 // If the click is in the scrollbar, may scroll up/down.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 popup_handle_scrollbar_click(wp, row, col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 # ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 # else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 in_popup_win = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 popup_dragwin = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 if (row == -1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 // A click in the window toolbar does not enter another window or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 // change Visual highlighting.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 winbar_click(wp, col);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 in_winbar = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 return IN_OTHER_WIN | MOUSE_WINBAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 in_winbar = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 // winpos and height may change in win_enter()!
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 if (row >= wp->w_height) // In (or below) status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 on_status_line = row - wp->w_height + 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 dragwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 on_status_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 if (col >= wp->w_width) // In separator line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 on_sep_line = col - wp->w_width + 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 dragwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 on_sep_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 // The rightmost character of the status line might be a vertical
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 // separator character if there is no connecting window to the right.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 if (on_status_line && on_sep_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 if (stl_connected(wp))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 on_sep_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 on_status_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 // Before jumping to another buffer, or moving the cursor for a left
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 // click, stop Visual mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 if (VIsual_active
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 && (wp->w_buffer != curwin->w_buffer
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 || (!on_status_line && !on_sep_line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 && (
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 # ifdef FEAT_RIGHTLEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 wp->w_p_rl ? col < wp->w_width - wp->w_p_fdc :
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 col >= wp->w_p_fdc
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 # ifdef FEAT_CMDWIN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 + (cmdwin_type == 0 && wp == curwin ? 0 : 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 && (flags & MOUSE_MAY_STOP_VIS))))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 redraw_curbuf_later(INVERTED); // delete the inversion
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 #ifdef FEAT_CMDWIN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 if (cmdwin_type != 0 && wp != curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 // A click outside the command-line window: Use modeless
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 // selection if possible. Allow dragging the status lines.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 on_sep_line = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 # ifdef FEAT_CLIPBOARD
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 if (on_status_line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 return IN_STATUS_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 # else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 row = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 col += wp->w_wincol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 wp = curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 // Only change window focus when not clicking on or dragging the
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738 // status line. Do change focus when releasing the mouse button
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 // (MOUSE_FOCUS was set above if we dragged first).
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 if (dragwin == NULL || (flags & MOUSE_RELEASED))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 win_enter(wp, TRUE); // can make wp invalid!
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 if (curwin != old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 #ifdef CHECK_DOUBLE_CLICK
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 // set topline, to be able to check for double click ourselves
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 set_mouse_topline(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 #ifdef FEAT_TERMINAL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 // when entering a terminal window may change state
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 term_win_entered();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 if (on_status_line) // In (or below) status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 // Don't use start_arrow() if we're in the same window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 if (curwin == old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 return IN_STATUS_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 return IN_STATUS_LINE | CURSOR_MOVED;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 if (on_sep_line) // In (or below) status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 // Don't use start_arrow() if we're in the same window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 if (curwin == old_curwin)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 return IN_SEP_LINE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 return IN_SEP_LINE | CURSOR_MOVED;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 curwin->w_cursor.lnum = curwin->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 #ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 // remember topline, needed for double click
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 gui_prev_topline = curwin->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 # ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 gui_prev_topfill = curwin->w_topfill;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 else if (on_status_line && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 if (dragwin != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 // Drag the status line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 count = row - dragwin->w_winrow - dragwin->w_height + 1
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 - on_status_line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 win_drag_status_line(dragwin, count);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 did_drag |= count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 return IN_STATUS_LINE; // Cursor didn't move
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 else if (on_sep_line && which_button == MOUSE_LEFT)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 if (dragwin != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796 // Drag the separator column
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 count = col - dragwin->w_wincol - dragwin->w_width + 1
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 - on_sep_line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 win_drag_vsep_line(dragwin, count);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 did_drag |= count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 return IN_SEP_LINE; // Cursor didn't move
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 else if (in_winbar)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 // After a click on the window toolbar don't start Visual mode.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 return IN_OTHER_WIN | MOUSE_WINBAR;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 else // keep_window_focus must be TRUE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 // before moving the cursor for a left click, stop Visual mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 if (flags & MOUSE_MAY_STOP_VIS)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 end_visual_mode();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 redraw_curbuf_later(INVERTED); // delete the inversion
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 // Continue a modeless selection in another window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 if (cmdwin_type != 0 && row < curwin->w_winrow)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 if (in_popup_win)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 if (popup_dragwin != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 // dragging a popup window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831 popup_drag(popup_dragwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 return IN_UNKNOWN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 // continue a modeless selection in a popup window
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 click_in_popup_win = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 return IN_OTHER_WIN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 row -= W_WINROW(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 col -= curwin->w_wincol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 // When clicking beyond the end of the window, scroll the screen.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 // Scroll by however many rows outside the window we are.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 if (row < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 count = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 for (first = TRUE; curwin->w_topline > 1; )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 ++count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 count += plines(curwin->w_topline - 1);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 if (!first && count > -row)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 first = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 ++curwin->w_topfill;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 --curwin->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 curwin->w_topfill = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 check_topfill(curwin, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 curwin->w_valid &=
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 redraw_later(VALID);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 row = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 else if (row >= curwin->w_height)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 count = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 for (first = TRUE; curwin->w_topline < curbuf->b_ml.ml_line_count; )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 if (curwin->w_topfill > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 ++count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 count += plines(curwin->w_topline);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 if (!first && count > row - curwin->w_height + 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 first = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 if (hasFolding(curwin->w_topline, NULL, &curwin->w_topline)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 && curwin->w_topline == curbuf->b_ml.ml_line_count)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 if (curwin->w_topfill > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 --curwin->w_topfill;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 ++curwin->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 curwin->w_topfill =
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 diff_check_fill(curwin, curwin->w_topline);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 check_topfill(curwin, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 redraw_later(VALID);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 curwin->w_valid &=
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 row = curwin->w_height - 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 else if (row == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 // When dragging the mouse, while the text has been scrolled up as
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 // far as it goes, moving the mouse in the top line should scroll
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 // the text down (done later when recomputing w_topline).
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 if (mouse_dragging > 0
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 && curwin->w_cursor.lnum
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 == curwin->w_buffer->b_ml.ml_line_count
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 && curwin->w_cursor.lnum == curwin->w_topline)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 curwin->w_valid &= ~(VALID_TOPLINE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 // Check for position outside of the fold column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 if (
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 # ifdef FEAT_RIGHTLEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 curwin->w_p_rl ? col < curwin->w_width - curwin->w_p_fdc :
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 col >= curwin->w_p_fdc
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 # ifdef FEAT_CMDWIN
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 + (cmdwin_type == 0 ? 0 : 1)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 mouse_char = ' ';
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 // compute the position in the buffer line from the posn on the screen
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum, NULL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 mouse_past_bottom = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 // Start Visual mode before coladvance(), for when 'sel' != "old"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 if ((flags & MOUSE_MAY_VIS) && !VIsual_active)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 check_visual_highlight();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 VIsual = old_cursor;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 VIsual_active = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 VIsual_reselect = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 // if 'selectmode' contains "mouse", start Select mode
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 may_start_select('o');
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 setmouse();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 if (p_smd && msg_silent == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 redraw_cmdline = TRUE; // show visual mode later
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 curwin->w_curswant = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 curwin->w_set_curswant = FALSE; // May still have been TRUE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 if (coladvance(col) == FAIL) // Mouse click beyond end of line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 if (inclusive != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 *inclusive = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 mouse_past_eol = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 else if (inclusive != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 *inclusive = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 count = IN_BUFFER;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 if (curwin != old_curwin || curwin->w_cursor.lnum != old_cursor.lnum
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 || curwin->w_cursor.col != old_cursor.col)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 count |= CURSOR_MOVED; // Cursor has moved
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 # ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 if (mouse_char == '+')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 count |= MOUSE_FOLD_OPEN;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 else if (mouse_char != ' ')
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 count |= MOUSE_FOLD_CLOSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 return count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 * Mouse scroll wheel: Default action is to scroll three lines, or one page
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 * when Shift or Ctrl is used.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 * K_MOUSEUP (cap->arg == 1) or K_MOUSEDOWN (cap->arg == 0) or
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 * K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 nv_mousescroll(cmdarg_T *cap)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 win_T *old_curwin = curwin, *wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 if (mouse_row >= 0 && mouse_col >= 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 int row, col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 row = mouse_row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 col = mouse_col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 // find the window at the pointer coordinates
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 wp = mouse_find_win(&row, &col, FIND_POPUP);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 if (wp == NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 if (WIN_IS_POPUP(wp) && !wp->w_has_scrollbar)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 return;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019 curwin = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 if (cap->arg == MSCR_UP || cap->arg == MSCR_DOWN)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 # ifdef FEAT_TERMINAL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 if (term_use_loop())
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 // This window is a terminal window, send the mouse event there.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 // Set "typed" to FALSE to avoid an endless loop.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 send_keys_to_term(curbuf->b_term, cap->cmdchar, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 (void)onepage(cap->arg ? FORWARD : BACKWARD, 1L);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 // Don't scroll more than half the window height.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 if (curwin->w_height < 6)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 cap->count1 = curwin->w_height / 2;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 if (cap->count1 == 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 cap->count1 = 1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 cap->count1 = 3;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047 cap->count0 = cap->count1;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 nv_scroll_line(cap);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 if (WIN_IS_POPUP(curwin))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 popup_set_firstline(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 # ifdef FEAT_GUI
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 // Horizontal scroll - only allowed when 'wrap' is disabled
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 if (!curwin->w_p_wrap)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 int val, step = 6;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 step = curwin->w_width;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065 val = curwin->w_leftcol + (cap->arg == MSCR_RIGHT ? -step : +step);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 if (val < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 val = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 gui_do_horiz_scroll(val, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 # ifdef FEAT_SYN_HL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 if (curwin != old_curwin && curwin->w_p_cul)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075 redraw_for_cursorline(curwin);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078 curwin->w_redr_status = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 curwin = old_curwin;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 curbuf = curwin->w_buffer;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 * Mouse clicks and drags.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 nv_mouse(cmdarg_T *cap)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 }
18150
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2092
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2093 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2094 * Check if typebuf 'tp' contains a terminal mouse code and returns the
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2095 * modifiers found in typebuf in 'modifiers'.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2096 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2097 int
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2098 check_termcode_mouse(
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2099 char_u *tp,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2100 int *slen,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2101 char_u *key_name,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2102 char_u *modifiers_start,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2103 int idx,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2104 int *modifiers)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2105 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2106 int j;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2107 char_u *p;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2108 # if !defined(UNIX) || defined(FEAT_MOUSE_XTERM) || defined(FEAT_GUI) \
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2109 || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2110 char_u bytes[6];
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2111 int num_bytes;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2112 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2113 int mouse_code = 0; // init for GCC
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2114 int is_click, is_drag;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2115 int wheel_code = 0;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2116 int current_button;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2117 static int held_button = MOUSE_RELEASE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2118 static int orig_num_clicks = 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2119 static int orig_mouse_code = 0x0;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2120 # ifdef CHECK_DOUBLE_CLICK
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2121 static int orig_mouse_col = 0;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2122 static int orig_mouse_row = 0;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2123 static struct timeval orig_mouse_time = {0, 0};
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2124 // time of previous mouse click
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2125 struct timeval mouse_time; // time of current mouse click
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2126 long timediff; // elapsed time in msec
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2127 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2128
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2129 is_click = is_drag = FALSE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2130
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2131 # if !defined(UNIX) || defined(FEAT_MOUSE_XTERM) || defined(FEAT_GUI) \
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2132 || defined(FEAT_MOUSE_GPM) || defined(FEAT_SYSMOUSE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2133 if (key_name[0] == KS_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2134 # ifdef FEAT_MOUSE_GPM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2135 || key_name[0] == KS_GPM_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2136 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2137 )
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2138 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2139 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2140 * For xterm we get "<t_mouse>scr", where
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2141 * s == encoded button state:
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2142 * 0x20 = left button down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2143 * 0x21 = middle button down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2144 * 0x22 = right button down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2145 * 0x23 = any button release
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2146 * 0x60 = button 4 down (scroll wheel down)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2147 * 0x61 = button 5 down (scroll wheel up)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2148 * add 0x04 for SHIFT
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2149 * add 0x08 for ALT
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2150 * add 0x10 for CTRL
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2151 * add 0x20 for mouse drag (0x40 is drag with left button)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2152 * add 0x40 for mouse move (0x80 is move, 0x81 too)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2153 * 0x43 (drag + release) is also move
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2154 * c == column + ' ' + 1 == column + 33
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2155 * r == row + ' ' + 1 == row + 33
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2156 *
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2157 * The coordinates are passed on through global variables.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2158 * Ugly, but this avoids trouble with mouse clicks at an
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2159 * unexpected moment and allows for mapping them.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2160 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2161 for (;;)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2162 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2163 # ifdef FEAT_GUI
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2164 if (gui.in_use)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2165 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2166 // GUI uses more bits for columns > 223
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2167 num_bytes = get_bytes_from_buf(tp + *slen, bytes, 5);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2168 if (num_bytes == -1) // not enough coordinates
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2169 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2170 mouse_code = bytes[0];
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2171 mouse_col = 128 * (bytes[1] - ' ' - 1)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2172 + bytes[2] - ' ' - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2173 mouse_row = 128 * (bytes[3] - ' ' - 1)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2174 + bytes[4] - ' ' - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2175 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2176 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2177 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2178 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2179 num_bytes = get_bytes_from_buf(tp + *slen, bytes, 3);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2180 if (num_bytes == -1) // not enough coordinates
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2181 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2182 mouse_code = bytes[0];
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2183 mouse_col = bytes[1] - ' ' - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2184 mouse_row = bytes[2] - ' ' - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2185 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2186 *slen += num_bytes;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2187
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2188 // If the following bytes is also a mouse code and it has
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2189 // the same code, dump this one and get the next. This
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2190 // makes dragging a whole lot faster.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2191 # ifdef FEAT_GUI
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2192 if (gui.in_use)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2193 j = 3;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2194 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2195 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2196 j = get_termcode_len(idx);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2197 if (STRNCMP(tp, tp + *slen, (size_t)j) == 0
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2198 && tp[*slen + j] == mouse_code
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2199 && tp[*slen + j + 1] != NUL
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2200 && tp[*slen + j + 2] != NUL
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2201 # ifdef FEAT_GUI
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2202 && (!gui.in_use
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2203 || (tp[*slen + j + 3] != NUL
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2204 && tp[*slen + j + 4] != NUL))
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2205 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2206 )
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2207 *slen += j;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2208 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2209 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2210 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2211 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2212
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2213 if (key_name[0] == KS_URXVT_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2214 || key_name[0] == KS_SGR_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2215 || key_name[0] == KS_SGR_MOUSE_RELEASE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2216 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2217 // URXVT 1015 mouse reporting mode:
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2218 // Almost identical to xterm mouse mode, except the values
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2219 // are decimal instead of bytes.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2220 //
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2221 // \033[%d;%d;%dM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2222 // ^-- row
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2223 // ^----- column
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2224 // ^-------- code
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2225 //
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2226 // SGR 1006 mouse reporting mode:
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2227 // Almost identical to xterm mouse mode, except the values
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2228 // are decimal instead of bytes.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2229 //
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2230 // \033[<%d;%d;%dM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2231 // ^-- row
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2232 // ^----- column
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2233 // ^-------- code
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2234 //
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2235 // \033[<%d;%d;%dm : mouse release event
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2236 // ^-- row
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2237 // ^----- column
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2238 // ^-------- code
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2239 p = modifiers_start;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2240 if (p == NULL)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2241 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2242
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2243 mouse_code = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2244 if (*p++ != ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2245 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2246
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2247 // when mouse reporting is SGR, add 32 to mouse code
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2248 if (key_name[0] == KS_SGR_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2249 || key_name[0] == KS_SGR_MOUSE_RELEASE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2250 mouse_code += 32;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2251
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2252 if (key_name[0] == KS_SGR_MOUSE_RELEASE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2253 mouse_code |= MOUSE_RELEASE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2254
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2255 mouse_col = getdigits(&p) - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2256 if (*p++ != ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2257 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2258
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2259 mouse_row = getdigits(&p) - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2260
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2261 // The modifiers were the mouse coordinates, not the
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2262 // modifier keys (alt/shift/ctrl/meta) state.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2263 *modifiers = 0;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2264 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2265
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2266 if (key_name[0] == KS_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2267 # ifdef FEAT_MOUSE_GPM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2268 || key_name[0] == KS_GPM_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2269 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2270 # ifdef FEAT_MOUSE_URXVT
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2271 || key_name[0] == KS_URXVT_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2272 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2273 || key_name[0] == KS_SGR_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2274 || key_name[0] == KS_SGR_MOUSE_RELEASE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2275 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2276 # if !defined(MSWIN)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2277 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2278 * Handle mouse events.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2279 * Recognize the xterm mouse wheel, but not in the GUI, the
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2280 * Linux console with GPM and the MS-DOS or Win32 console
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2281 * (multi-clicks use >= 0x60).
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2282 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2283 if (mouse_code >= MOUSEWHEEL_LOW
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2284 # ifdef FEAT_GUI
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2285 && !gui.in_use
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2286 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2287 # ifdef FEAT_MOUSE_GPM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2288 && key_name[0] != KS_GPM_MOUSE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2289 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2290 )
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2291 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2292 # if defined(UNIX) && defined(FEAT_MOUSE_TTY)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2293 if (use_xterm_mouse() > 1 && mouse_code >= 0x80)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2294 // mouse-move event, using MOUSE_DRAG works
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2295 mouse_code = MOUSE_DRAG;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2296 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2297 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2298 // Keep the mouse_code before it's changed, so that we
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2299 // remember that it was a mouse wheel click.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2300 wheel_code = mouse_code;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2301 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2302 # ifdef FEAT_MOUSE_XTERM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2303 else if (held_button == MOUSE_RELEASE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2304 # ifdef FEAT_GUI
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2305 && !gui.in_use
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2306 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2307 && (mouse_code == 0x23 || mouse_code == 0x24
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2308 || mouse_code == 0x40 || mouse_code == 0x41))
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2309 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2310 // Apparently 0x23 and 0x24 are used by rxvt scroll wheel.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2311 // And 0x40 and 0x41 are used by some xterm emulator.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2312 wheel_code = mouse_code - (mouse_code >= 0x40 ? 0x40 : 0x23)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2313 + MOUSEWHEEL_LOW;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2314 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2315 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2316
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2317 # if defined(UNIX) && defined(FEAT_MOUSE_TTY)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2318 else if (use_xterm_mouse() > 1)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2319 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2320 if (mouse_code & MOUSE_DRAG_XTERM)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2321 mouse_code |= MOUSE_DRAG;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2322 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2323 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2324 # ifdef FEAT_XCLIPBOARD
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2325 else if (!(mouse_code & MOUSE_DRAG & ~MOUSE_CLICK_MASK))
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2326 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2327 if ((mouse_code & MOUSE_RELEASE) == MOUSE_RELEASE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2328 stop_xterm_trace();
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2329 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2330 start_xterm_trace(mouse_code);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2331 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2332 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2333 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2334 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2335 # endif // !UNIX || FEAT_MOUSE_XTERM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2336 # ifdef FEAT_MOUSE_NET
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2337 if (key_name[0] == KS_NETTERM_MOUSE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2338 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2339 int mc, mr;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2340
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2341 // expect a rather limited sequence like: balancing {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2342 // \033}6,45\r
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2343 // '6' is the row, 45 is the column
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2344 p = tp + *slen;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2345 mr = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2346 if (*p++ != ',')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2347 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2348 mc = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2349 if (*p++ != '\r')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2350 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2351
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2352 mouse_col = mc - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2353 mouse_row = mr - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2354 mouse_code = MOUSE_LEFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2355 *slen += (int)(p - (tp + *slen));
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2356 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2357 # endif // FEAT_MOUSE_NET
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2358 # ifdef FEAT_MOUSE_JSB
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2359 if (key_name[0] == KS_JSBTERM_MOUSE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2360 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2361 int mult, val, iter, button, status;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2362
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2363 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2364 * JSBTERM Input Model
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2365 * \033[0~zw uniq escape sequence
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2366 * (L-x) Left button pressed - not pressed x not reporting
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2367 * (M-x) Middle button pressed - not pressed x not reporting
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2368 * (R-x) Right button pressed - not pressed x not reporting
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2369 * (SDmdu) Single , Double click, m mouse move d button down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2370 * u button up
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2371 * ### X cursor position padded to 3 digits
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2372 * ### Y cursor position padded to 3 digits
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2373 * (s-x) SHIFT key pressed - not pressed x not reporting
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2374 * (c-x) CTRL key pressed - not pressed x not reporting
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2375 * \033\\ terminating sequence
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2376 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2377 p = tp + *slen;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2378 button = mouse_code = 0;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2379 switch (*p++)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2380 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2381 case 'L': button = 1; break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2382 case '-': break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2383 case 'x': break; // ignore sequence
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2384 default: return -1; // Unknown Result
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2385 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2386 switch (*p++)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2387 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2388 case 'M': button |= 2; break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2389 case '-': break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2390 case 'x': break; // ignore sequence
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2391 default: return -1; // Unknown Result
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2392 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2393 switch (*p++)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2394 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2395 case 'R': button |= 4; break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2396 case '-': break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2397 case 'x': break; // ignore sequence
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2398 default: return -1; // Unknown Result
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2399 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2400 status = *p++;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2401 for (val = 0, mult = 100, iter = 0; iter < 3; iter++,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2402 mult /= 10, p++)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2403 if (*p >= '0' && *p <= '9')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2404 val += (*p - '0') * mult;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2405 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2406 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2407 mouse_col = val;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2408 for (val = 0, mult = 100, iter = 0; iter < 3; iter++,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2409 mult /= 10, p++)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2410 if (*p >= '0' && *p <= '9')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2411 val += (*p - '0') * mult;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2412 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2413 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2414 mouse_row = val;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2415 switch (*p++)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2416 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2417 case 's': button |= 8; break; // SHIFT key Pressed
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2418 case '-': break; // Not Pressed
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2419 case 'x': break; // Not Reporting
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2420 default: return -1; // Unknown Result
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2421 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2422 switch (*p++)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2423 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2424 case 'c': button |= 16; break; // CTRL key Pressed
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2425 case '-': break; // Not Pressed
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2426 case 'x': break; // Not Reporting
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2427 default: return -1; // Unknown Result
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2428 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2429 if (*p++ != '\033')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2430 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2431 if (*p++ != '\\')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2432 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2433 switch (status)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2434 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2435 case 'D': // Double Click
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2436 case 'S': // Single Click
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2437 if (button & 1) mouse_code |= MOUSE_LEFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2438 if (button & 2) mouse_code |= MOUSE_MIDDLE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2439 if (button & 4) mouse_code |= MOUSE_RIGHT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2440 if (button & 8) mouse_code |= MOUSE_SHIFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2441 if (button & 16) mouse_code |= MOUSE_CTRL;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2442 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2443 case 'm': // Mouse move
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2444 if (button & 1) mouse_code |= MOUSE_LEFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2445 if (button & 2) mouse_code |= MOUSE_MIDDLE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2446 if (button & 4) mouse_code |= MOUSE_RIGHT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2447 if (button & 8) mouse_code |= MOUSE_SHIFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2448 if (button & 16) mouse_code |= MOUSE_CTRL;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2449 if ((button & 7) != 0)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2450 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2451 held_button = mouse_code;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2452 mouse_code |= MOUSE_DRAG;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2453 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2454 is_drag = TRUE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2455 showmode();
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2456 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2457 case 'd': // Button Down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2458 if (button & 1) mouse_code |= MOUSE_LEFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2459 if (button & 2) mouse_code |= MOUSE_MIDDLE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2460 if (button & 4) mouse_code |= MOUSE_RIGHT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2461 if (button & 8) mouse_code |= MOUSE_SHIFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2462 if (button & 16) mouse_code |= MOUSE_CTRL;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2463 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2464 case 'u': // Button Up
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2465 if (button & 1)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2466 mouse_code |= MOUSE_LEFT | MOUSE_RELEASE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2467 if (button & 2)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2468 mouse_code |= MOUSE_MIDDLE | MOUSE_RELEASE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2469 if (button & 4)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2470 mouse_code |= MOUSE_RIGHT | MOUSE_RELEASE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2471 if (button & 8)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2472 mouse_code |= MOUSE_SHIFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2473 if (button & 16)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2474 mouse_code |= MOUSE_CTRL;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2475 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2476 default: return -1; // Unknown Result
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2477 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2478
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2479 *slen += (p - (tp + *slen));
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2480 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2481 # endif // FEAT_MOUSE_JSB
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2482 # ifdef FEAT_MOUSE_DEC
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2483 if (key_name[0] == KS_DEC_MOUSE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2484 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2485 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2486 * The DEC Locator Input Model
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2487 * Netterm delivers the code sequence:
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2488 * \033[2;4;24;80&w (left button down)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2489 * \033[3;0;24;80&w (left button up)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2490 * \033[6;1;24;80&w (right button down)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2491 * \033[7;0;24;80&w (right button up)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2492 * CSI Pe ; Pb ; Pr ; Pc ; Pp & w
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2493 * Pe is the event code
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2494 * Pb is the button code
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2495 * Pr is the row coordinate
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2496 * Pc is the column coordinate
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2497 * Pp is the third coordinate (page number)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2498 * Pe, the event code indicates what event caused this report
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2499 * The following event codes are defined:
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2500 * 0 - request, the terminal received an explicit request
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2501 * for a locator report, but the locator is unavailable
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2502 * 1 - request, the terminal received an explicit request
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2503 * for a locator report
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2504 * 2 - left button down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2505 * 3 - left button up
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2506 * 4 - middle button down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2507 * 5 - middle button up
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2508 * 6 - right button down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2509 * 7 - right button up
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2510 * 8 - fourth button down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2511 * 9 - fourth button up
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2512 * 10 - locator outside filter rectangle
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2513 * Pb, the button code, ASCII decimal 0-15 indicating which
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2514 * buttons are down if any. The state of the four buttons
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2515 * on the locator correspond to the low four bits of the
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2516 * decimal value,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2517 * "1" means button depressed
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2518 * 0 - no buttons down,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2519 * 1 - right,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2520 * 2 - middle,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2521 * 4 - left,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2522 * 8 - fourth
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2523 * Pr is the row coordinate of the locator position in the page,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2524 * encoded as an ASCII decimal value.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2525 * If Pr is omitted, the locator position is undefined
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2526 * (outside the terminal window for example).
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2527 * Pc is the column coordinate of the locator position in the
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2528 * page, encoded as an ASCII decimal value.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2529 * If Pc is omitted, the locator position is undefined
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2530 * (outside the terminal window for example).
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2531 * Pp is the page coordinate of the locator position
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2532 * encoded as an ASCII decimal value.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2533 * The page coordinate may be omitted if the locator is on
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2534 * page one (the default). We ignore it anyway.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2535 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2536 int Pe, Pb, Pr, Pc;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2537
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2538 p = tp + *slen;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2539
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2540 // get event status
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2541 Pe = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2542 if (*p++ != ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2543 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2544
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2545 // get button status
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2546 Pb = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2547 if (*p++ != ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2548 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2549
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2550 // get row status
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2551 Pr = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2552 if (*p++ != ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2553 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2554
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2555 // get column status
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2556 Pc = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2557
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2558 // the page parameter is optional
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2559 if (*p == ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2560 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2561 p++;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2562 (void)getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2563 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2564 if (*p++ != '&')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2565 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2566 if (*p++ != 'w')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2567 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2568
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2569 mouse_code = 0;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2570 switch (Pe)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2571 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2572 case 0: return -1; // position request while unavailable
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2573 case 1: // a response to a locator position request includes
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2574 // the status of all buttons
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2575 Pb &= 7; // mask off and ignore fourth button
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2576 if (Pb & 4)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2577 mouse_code = MOUSE_LEFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2578 if (Pb & 2)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2579 mouse_code = MOUSE_MIDDLE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2580 if (Pb & 1)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2581 mouse_code = MOUSE_RIGHT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2582 if (Pb)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2583 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2584 held_button = mouse_code;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2585 mouse_code |= MOUSE_DRAG;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2586 WantQueryMouse = TRUE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2587 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2588 is_drag = TRUE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2589 showmode();
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2590 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2591 case 2: mouse_code = MOUSE_LEFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2592 WantQueryMouse = TRUE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2593 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2594 case 3: mouse_code = MOUSE_RELEASE | MOUSE_LEFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2595 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2596 case 4: mouse_code = MOUSE_MIDDLE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2597 WantQueryMouse = TRUE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2598 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2599 case 5: mouse_code = MOUSE_RELEASE | MOUSE_MIDDLE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2600 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2601 case 6: mouse_code = MOUSE_RIGHT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2602 WantQueryMouse = TRUE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2603 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2604 case 7: mouse_code = MOUSE_RELEASE | MOUSE_RIGHT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2605 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2606 case 8: return -1; // fourth button down
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2607 case 9: return -1; // fourth button up
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2608 case 10: return -1; // mouse outside of filter rectangle
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2609 default: return -1; // should never occur
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2610 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2611
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2612 mouse_col = Pc - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2613 mouse_row = Pr - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2614
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2615 *slen += (int)(p - (tp + *slen));
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2616 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2617 # endif // FEAT_MOUSE_DEC
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2618 # ifdef FEAT_MOUSE_PTERM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2619 if (key_name[0] == KS_PTERM_MOUSE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2620 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2621 int button, num_clicks, action;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2622
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2623 p = tp + *slen;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2624
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2625 action = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2626 if (*p++ != ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2627 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2628
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2629 mouse_row = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2630 if (*p++ != ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2631 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2632 mouse_col = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2633 if (*p++ != ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2634 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2635
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2636 button = getdigits(&p);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2637 mouse_code = 0;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2638
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2639 switch (button)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2640 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2641 case 4: mouse_code = MOUSE_LEFT; break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2642 case 1: mouse_code = MOUSE_RIGHT; break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2643 case 2: mouse_code = MOUSE_MIDDLE; break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2644 default: return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2645 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2646
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2647 switch (action)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2648 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2649 case 31: // Initial press
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2650 if (*p++ != ';')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2651 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2652
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2653 num_clicks = getdigits(&p); // Not used
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2654 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2655
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2656 case 32: // Release
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2657 mouse_code |= MOUSE_RELEASE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2658 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2659
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2660 case 33: // Drag
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2661 held_button = mouse_code;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2662 mouse_code |= MOUSE_DRAG;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2663 break;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2664
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2665 default:
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2666 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2667 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2668
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2669 if (*p++ != 't')
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2670 return -1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2671
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2672 *slen += (p - (tp + *slen));
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2673 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2674 # endif // FEAT_MOUSE_PTERM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2675
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2676 // Interpret the mouse code
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2677 current_button = (mouse_code & MOUSE_CLICK_MASK);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2678 if (current_button == MOUSE_RELEASE
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2679 # ifdef FEAT_MOUSE_XTERM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2680 && wheel_code == 0
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2681 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2682 )
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2683 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2684 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2685 * If we get a mouse drag or release event when
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2686 * there is no mouse button held down (held_button ==
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2687 * MOUSE_RELEASE), produce a K_IGNORE below.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2688 * (can happen when you hold down two buttons
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2689 * and then let them go, or click in the menu bar, but not
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2690 * on a menu, and drag into the text).
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2691 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2692 if ((mouse_code & MOUSE_DRAG) == MOUSE_DRAG)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2693 is_drag = TRUE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2694 current_button = held_button;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2695 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2696 else if (wheel_code == 0)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2697 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2698 # ifdef CHECK_DOUBLE_CLICK
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2699 # ifdef FEAT_MOUSE_GPM
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2700 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2701 * Only for Unix, when GUI not active, we handle
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2702 * multi-clicks here, but not for GPM mouse events.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2703 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2704 # ifdef FEAT_GUI
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2705 if (key_name[0] != KS_GPM_MOUSE && !gui.in_use)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2706 # else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2707 if (key_name[0] != KS_GPM_MOUSE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2708 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2709 # else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2710 # ifdef FEAT_GUI
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2711 if (!gui.in_use)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2712 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2713 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2714 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2715 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2716 * Compute the time elapsed since the previous mouse click.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2717 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2718 gettimeofday(&mouse_time, NULL);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2719 if (orig_mouse_time.tv_sec == 0)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2720 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2721 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2722 * Avoid computing the difference between mouse_time
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2723 * and orig_mouse_time for the first click, as the
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2724 * difference would be huge and would cause
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2725 * multiplication overflow.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2726 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2727 timediff = p_mouset;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2728 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2729 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2730 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2731 timediff = (mouse_time.tv_usec
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2732 - orig_mouse_time.tv_usec) / 1000;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2733 if (timediff < 0)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2734 --orig_mouse_time.tv_sec;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2735 timediff += (mouse_time.tv_sec
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2736 - orig_mouse_time.tv_sec) * 1000;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2737 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2738 orig_mouse_time = mouse_time;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2739 if (mouse_code == orig_mouse_code
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2740 && timediff < p_mouset
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2741 && orig_num_clicks != 4
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2742 && orig_mouse_col == mouse_col
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2743 && orig_mouse_row == mouse_row
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2744 && (is_mouse_topline(curwin)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2745 // Double click in tab pages line also works
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2746 // when window contents changes.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2747 || (mouse_row == 0 && firstwin->w_winrow > 0))
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2748 )
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2749 ++orig_num_clicks;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2750 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2751 orig_num_clicks = 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2752 orig_mouse_col = mouse_col;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2753 orig_mouse_row = mouse_row;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2754 set_mouse_topline(curwin);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2755 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2756 # if defined(FEAT_GUI) || defined(FEAT_MOUSE_GPM)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2757 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2758 orig_num_clicks = NUM_MOUSE_CLICKS(mouse_code);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2759 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2760 # else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2761 orig_num_clicks = NUM_MOUSE_CLICKS(mouse_code);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2762 # endif
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2763 is_click = TRUE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2764 orig_mouse_code = mouse_code;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2765 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2766 if (!is_drag)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2767 held_button = mouse_code & MOUSE_CLICK_MASK;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2768
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2769 /*
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2770 * Translate the actual mouse event into a pseudo mouse event.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2771 * First work out what modifiers are to be used.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2772 */
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2773 if (orig_mouse_code & MOUSE_SHIFT)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2774 *modifiers |= MOD_MASK_SHIFT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2775 if (orig_mouse_code & MOUSE_CTRL)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2776 *modifiers |= MOD_MASK_CTRL;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2777 if (orig_mouse_code & MOUSE_ALT)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2778 *modifiers |= MOD_MASK_ALT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2779 if (orig_num_clicks == 2)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2780 *modifiers |= MOD_MASK_2CLICK;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2781 else if (orig_num_clicks == 3)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2782 *modifiers |= MOD_MASK_3CLICK;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2783 else if (orig_num_clicks == 4)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2784 *modifiers |= MOD_MASK_4CLICK;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2785
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2786 // Work out our pseudo mouse event. Note that MOUSE_RELEASE gets
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2787 // added, then it's not mouse up/down.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2788 key_name[0] = KS_EXTRA;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2789 if (wheel_code != 0
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2790 && (wheel_code & MOUSE_RELEASE) != MOUSE_RELEASE)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2791 {
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2792 if (wheel_code & MOUSE_CTRL)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2793 *modifiers |= MOD_MASK_CTRL;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2794 if (wheel_code & MOUSE_ALT)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2795 *modifiers |= MOD_MASK_ALT;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2796 key_name[1] = (wheel_code & 1)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2797 ? (int)KE_MOUSEUP : (int)KE_MOUSEDOWN;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2798 held_button = MOUSE_RELEASE;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2799 }
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2800 else
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2801 key_name[1] = get_pseudo_mouse_code(current_button,
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2802 is_click, is_drag);
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2803
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2804 // Make sure the mouse position is valid. Some terminals may
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2805 // return weird values.
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2806 if (mouse_col >= Columns)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2807 mouse_col = Columns - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2808 if (mouse_row >= Rows)
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2809 mouse_row = Rows - 1;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2810
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2811 return 0;
0ec6521e9d80 patch 8.1.2070: mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 18141
diff changeset
2812 }
18135
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2813 #endif // FEAT_MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2814
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2815 // Functions also used for popup windows.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2816 #if defined(FEAT_MOUSE) || defined(FEAT_TEXT_PROP) || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2817
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2818 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 * Compute the buffer line position from the screen position "rowp" / "colp" in
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2820 * window "win".
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2821 * "plines_cache" can be NULL (no cache) or an array with "win->w_height"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2822 * entries that caches the plines_win() result from a previous call. Entry is
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2823 * zero if not computed yet. There must be no text or setting changes since
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2824 * the entry is put in the cache.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2825 * Returns TRUE if the position is below the last line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2826 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2827 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2828 mouse_comp_pos(
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2829 win_T *win,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2830 int *rowp,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2831 int *colp,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2832 linenr_T *lnump,
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2833 int *plines_cache)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2834 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2835 int col = *colp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2836 int row = *rowp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2837 linenr_T lnum;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2838 int retval = FALSE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2839 int off;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2840 int count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2841
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2842 #ifdef FEAT_RIGHTLEFT
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2843 if (win->w_p_rl)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2844 col = win->w_width - 1 - col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2845 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2846
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2847 lnum = win->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2848
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2849 while (row > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2850 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2851 int cache_idx = lnum - win->w_topline;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2852
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2853 if (plines_cache != NULL && plines_cache[cache_idx] > 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2854 count = plines_cache[cache_idx];
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2855 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2856 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2857 #ifdef FEAT_DIFF
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2858 // Don't include filler lines in "count"
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859 if (win->w_p_diff
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2860 # ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2861 && !hasFoldingWin(win, lnum, NULL, NULL, TRUE, NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2862 # endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2863 )
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2865 if (lnum == win->w_topline)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2866 row -= win->w_topfill;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2867 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2868 row -= diff_check_fill(win, lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2869 count = plines_win_nofill(win, lnum, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2870 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2871 else
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2872 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2873 count = plines_win(win, lnum, TRUE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2874 if (plines_cache != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2875 plines_cache[cache_idx] = count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2876 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2877 if (count > row)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2878 break; // Position is in this buffer line.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2879 #ifdef FEAT_FOLDING
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2880 (void)hasFoldingWin(win, lnum, NULL, &lnum, TRUE, NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2881 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2882 if (lnum == win->w_buffer->b_ml.ml_line_count)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2883 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2884 retval = TRUE;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2885 break; // past end of file
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2886 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2887 row -= count;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2888 ++lnum;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2889 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2890
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2891 if (!retval)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2892 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2893 // Compute the column without wrapping.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2894 off = win_col_off(win) - win_col_off2(win);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2895 if (col < off)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2896 col = off;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2897 col += row * (win->w_width - off);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2898 // add skip column (for long wrapping line)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2899 col += win->w_skipcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2900 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2901
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2902 if (!win->w_p_wrap)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2903 col += win->w_leftcol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2904
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2905 // skip line number and fold column in front of the line
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2906 col -= win_col_off(win);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2907 if (col < 0)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2908 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2909 #ifdef FEAT_NETBEANS_INTG
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2910 netbeans_gutter_click(lnum);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2911 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2912 col = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2913 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2915 *colp = col;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2916 *rowp = row;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2917 *lnump = lnum;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2918 return retval;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2919 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2920
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2921 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2922 * Find the window at screen position "*rowp" and "*colp". The positions are
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2923 * updated to become relative to the top-left of the window.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2924 * When "popup" is FAIL_POPUP and the position is in a popup window then NULL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2925 * is returned. When "popup" is IGNORE_POPUP then do not even check popup
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2926 * windows.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2927 * Returns NULL when something is wrong.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2928 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2929 win_T *
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2930 mouse_find_win(int *rowp, int *colp, mouse_find_T popup UNUSED)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2931 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2932 frame_T *fp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2933 win_T *wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2934
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2935 #ifdef FEAT_TEXT_PROP
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2936 win_T *pwp = NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2937
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2938 if (popup != IGNORE_POPUP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2939 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2940 popup_reset_handled();
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 while ((wp = find_next_popup(TRUE)) != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2942 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2943 if (*rowp >= wp->w_winrow && *rowp < wp->w_winrow + popup_height(wp)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 && *colp >= wp->w_wincol
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2945 && *colp < wp->w_wincol + popup_width(wp))
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 pwp = wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2947 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2948 if (pwp != NULL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2949 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2950 if (popup == FAIL_POPUP)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2951 return NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2952 *rowp -= pwp->w_winrow;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2953 *colp -= pwp->w_wincol;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2954 return pwp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2955 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2956 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2957 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2958
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2959 fp = topframe;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2960 *rowp -= firstwin->w_winrow;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2961 for (;;)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2962 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2963 if (fp->fr_layout == FR_LEAF)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2964 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2965 if (fp->fr_layout == FR_ROW)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2966 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2967 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2969 if (*colp < fp->fr_width)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2970 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2971 *colp -= fp->fr_width;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2972 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2973 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2974 else // fr_layout == FR_COL
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2975 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2976 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2978 if (*rowp < fp->fr_height)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2979 break;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2980 *rowp -= fp->fr_height;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2982 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2983 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2984 // When using a timer that closes a window the window might not actually
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2985 // exist.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 FOR_ALL_WINDOWS(wp)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2987 if (wp == fp->fr_win)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2988 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2989 #ifdef FEAT_MENU
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2990 *rowp -= wp->w_winbar_height;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2991 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2992 return wp;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2993 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2994 return NULL;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2995 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2996
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2997 #if defined(NEED_VCOL2COL) || defined(FEAT_BEVAL) || defined(FEAT_TEXT_PROP) \
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2998 || defined(PROTO)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2999 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3000 * Convert a virtual (screen) column to a character column.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3001 * The first column is one.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3002 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3003 int
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3004 vcol2col(win_T *wp, linenr_T lnum, int vcol)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3005 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3006 // try to advance to the specified column
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3007 int count = 0;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3008 char_u *ptr;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3009 char_u *line;
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3010
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3011 line = ptr = ml_get_buf(wp->w_buffer, lnum, FALSE);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3012 while (count < vcol && *ptr != NUL)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3013 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3014 count += win_lbr_chartabsize(wp, line, ptr, count, NULL);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3015 MB_PTR_ADV(ptr);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3016 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3017 return (int)(ptr - line);
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3018 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3019 #endif
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3020
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3021 #else // FEAT_MOUSE
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3022
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3023 /*
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3024 * Dummy implementation of setmouse() to avoid lots of #ifdefs.
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3025 */
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3026 void
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3027 setmouse(void)
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3028 {
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3029 }
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3030
1868ec23360e patch 8.1.2062: the mouse code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3031 #endif // FEAT_MOUSE