Mercurial > vim
annotate src/ui.c @ 15605:62b3805506b3 v8.1.0810
patch 8.1.0810: too many #ifdefs
commit https://github.com/vim/vim/commit/264b74fa545edfb92c0d7d08a02c26331cc5b168
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jan 24 17:18:42 2019 +0100
patch 8.1.0810: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_MBYTE, part 4.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 24 Jan 2019 17:30:08 +0100 |
parents | d89c5b339c2a |
children | 6f1c7e9a6393 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ui.c: functions that handle the user interface. | |
12 * 1. Keyboard input stuff, and a bit of windowing stuff. These are called | |
13 * before the machine specific stuff (mch_*) so that we can call the GUI | |
14 * stuff instead if the GUI is running. | |
15 * 2. Clipboard stuff. | |
16 * 3. Input buffer stuff. | |
17 */ | |
18 | |
19 #include "vim.h" | |
20 | |
5136
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
21 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
22 # define WIN32_LEAN_AND_MEAN |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
23 # include <windows.h> |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
24 # include "winclip.pro" |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
25 #endif |
28e6f5f88968
updated for version 7.3.1311
Bram Moolenaar <bram@vim.org>
parents:
5106
diff
changeset
|
26 |
7 | 27 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
28 ui_write(char_u *s, int len) |
7 | 29 { |
30 #ifdef FEAT_GUI | |
31 if (gui.in_use && !gui.dying && !gui.starting) | |
32 { | |
33 gui_write(s, len); | |
34 if (p_wd) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
35 gui_wait_for_chars(p_wd, typebuf.tb_change_cnt); |
7 | 36 return; |
37 } | |
38 #endif | |
39 #ifndef NO_CONSOLE | |
40 /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */ | |
41 if (!(silent_mode && p_verbose == 0)) | |
42 { | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
43 #if !defined(WIN3264) |
7 | 44 char_u *tofree = NULL; |
45 | |
46 if (output_conv.vc_type != CONV_NONE) | |
47 { | |
48 /* Convert characters from 'encoding' to 'termencoding'. */ | |
49 tofree = string_convert(&output_conv, s, &len); | |
50 if (tofree != NULL) | |
51 s = tofree; | |
52 } | |
53 #endif | |
54 | |
55 mch_write(s, len); | |
56 | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
57 # if !defined(WIN3264) |
7 | 58 if (output_conv.vc_type != CONV_NONE) |
59 vim_free(tofree); | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
60 # endif |
7 | 61 } |
62 #endif | |
63 } | |
64 | |
2935 | 65 #if defined(UNIX) || defined(VMS) || defined(PROTO) || defined(WIN3264) |
7 | 66 /* |
67 * When executing an external program, there may be some typed characters that | |
68 * are not consumed by it. Give them back to ui_inchar() and they are stored | |
69 * here for the next call. | |
70 */ | |
71 static char_u *ta_str = NULL; | |
72 static int ta_off; /* offset for next char to use when ta_str != NULL */ | |
73 static int ta_len; /* length of ta_str when it's not NULL*/ | |
74 | |
75 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
76 ui_inchar_undo(char_u *s, int len) |
7 | 77 { |
78 char_u *new; | |
79 int newlen; | |
80 | |
81 newlen = len; | |
82 if (ta_str != NULL) | |
83 newlen += ta_len - ta_off; | |
84 new = alloc(newlen); | |
85 if (new != NULL) | |
86 { | |
87 if (ta_str != NULL) | |
88 { | |
89 mch_memmove(new, ta_str + ta_off, (size_t)(ta_len - ta_off)); | |
90 mch_memmove(new + ta_len - ta_off, s, (size_t)len); | |
91 vim_free(ta_str); | |
92 } | |
93 else | |
94 mch_memmove(new, s, (size_t)len); | |
95 ta_str = new; | |
96 ta_len = newlen; | |
97 ta_off = 0; | |
98 } | |
99 } | |
100 #endif | |
101 | |
102 /* | |
3877 | 103 * ui_inchar(): low level input function. |
7 | 104 * Get characters from the keyboard. |
105 * Return the number of characters that are available. | |
106 * If "wtime" == 0 do not wait for characters. | |
107 * If "wtime" == -1 wait forever for characters. | |
108 * If "wtime" > 0 wait "wtime" milliseconds for a character. | |
109 * | |
110 * "tb_change_cnt" is the value of typebuf.tb_change_cnt if "buf" points into | |
111 * it. When typebuf.tb_change_cnt changes (e.g., when a message is received | |
112 * from a remote client) "buf" can no longer be used. "tb_change_cnt" is NULL | |
113 * otherwise. | |
114 */ | |
115 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
116 ui_inchar( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
117 char_u *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
118 int maxlen, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
119 long wtime, /* don't use "time", MIPS cannot handle it */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
120 int tb_change_cnt) |
7 | 121 { |
122 int retval = 0; | |
123 | |
124 #if defined(FEAT_GUI) && (defined(UNIX) || defined(VMS)) | |
125 /* | |
126 * Use the typeahead if there is any. | |
127 */ | |
128 if (ta_str != NULL) | |
129 { | |
130 if (maxlen >= ta_len - ta_off) | |
131 { | |
132 mch_memmove(buf, ta_str + ta_off, (size_t)ta_len); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
133 VIM_CLEAR(ta_str); |
7 | 134 return ta_len; |
135 } | |
136 mch_memmove(buf, ta_str + ta_off, (size_t)maxlen); | |
137 ta_off += maxlen; | |
138 return maxlen; | |
139 } | |
140 #endif | |
141 | |
170 | 142 #ifdef FEAT_PROFILE |
791 | 143 if (do_profiling == PROF_YES && wtime != 0) |
170 | 144 prof_inchar_enter(); |
145 #endif | |
146 | |
7 | 147 #ifdef NO_CONSOLE_INPUT |
148 /* Don't wait for character input when the window hasn't been opened yet. | |
149 * Do try reading, this works when redirecting stdin from a file. | |
150 * Must return something, otherwise we'll loop forever. If we run into | |
151 * this very often we probably got stuck, exit Vim. */ | |
152 if (no_console_input()) | |
153 { | |
154 static int count = 0; | |
155 | |
156 # ifndef NO_CONSOLE | |
15075
fd9c4b1a71aa
patch 8.1.0548: crash when job callback unloads a buffer
Bram Moolenaar <Bram@vim.org>
parents:
15052
diff
changeset
|
157 retval = mch_inchar(buf, maxlen, wtime, tb_change_cnt); |
228 | 158 if (retval > 0 || typebuf_changed(tb_change_cnt) || wtime >= 0) |
170 | 159 goto theend; |
7 | 160 # endif |
161 if (wtime == -1 && ++count == 1000) | |
162 read_error_exit(); | |
163 buf[0] = CAR; | |
170 | 164 retval = 1; |
165 goto theend; | |
7 | 166 } |
167 #endif | |
168 | |
1086 | 169 /* If we are going to wait for some time or block... */ |
170 if (wtime == -1 || wtime > 100L) | |
171 { | |
172 /* ... allow signals to kill us. */ | |
173 (void)vim_handle_signal(SIGNAL_UNBLOCK); | |
174 | |
175 /* ... there is no need for CTRL-C to interrupt something, don't let | |
176 * it set got_int when it was mapped. */ | |
6491 | 177 if ((mapped_ctrl_c | curbuf->b_mapped_ctrl_c) & get_real_state()) |
1086 | 178 ctrl_c_interrupts = FALSE; |
179 } | |
7 | 180 |
181 #ifdef FEAT_GUI | |
182 if (gui.in_use) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
183 retval = gui_inchar(buf, maxlen, wtime, tb_change_cnt); |
7 | 184 #endif |
185 #ifndef NO_CONSOLE | |
186 # ifdef FEAT_GUI | |
187 else | |
188 # endif | |
189 retval = mch_inchar(buf, maxlen, wtime, tb_change_cnt); | |
190 #endif | |
191 | |
1086 | 192 if (wtime == -1 || wtime > 100L) |
193 /* block SIGHUP et al. */ | |
194 (void)vim_handle_signal(SIGNAL_BLOCK); | |
195 | |
7 | 196 ctrl_c_interrupts = TRUE; |
197 | |
170 | 198 #ifdef NO_CONSOLE_INPUT |
199 theend: | |
200 #endif | |
201 #ifdef FEAT_PROFILE | |
791 | 202 if (do_profiling == PROF_YES && wtime != 0) |
170 | 203 prof_inchar_exit(); |
204 #endif | |
7 | 205 return retval; |
206 } | |
207 | |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
208 #if defined(FEAT_TIMERS) || defined(PROTO) |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
209 /* |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
210 * Wait for a timer to fire or "wait_func" to return non-zero. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
211 * Returns OK when something was read. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
212 * Returns FAIL when it timed out or was interrupted. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
213 */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
214 int |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
215 ui_wait_for_chars_or_timer( |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
216 long wtime, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
217 int (*wait_func)(long wtime, int *interrupted, int ignore_input), |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
218 int *interrupted, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
219 int ignore_input) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
220 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
221 int due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
222 long remaining = wtime; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
223 int tb_change_cnt = typebuf.tb_change_cnt; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
224 # ifdef FEAT_JOB_CHANNEL |
15506
8b508af36a80
patch 8.1.0761: default value for brief_wait is wrong
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
225 int brief_wait = FALSE; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
226 # endif |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
227 |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
228 // When waiting very briefly don't trigger timers. |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
229 if (wtime >= 0 && wtime < 10L) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
230 return wait_func(wtime, NULL, ignore_input); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
231 |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
232 while (wtime < 0 || remaining > 0) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
233 { |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
234 // Trigger timers and then get the time in wtime until the next one is |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
235 // due. Wait up to that time. |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
236 due_time = check_due_timer(); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
237 if (typebuf.tb_change_cnt != tb_change_cnt) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
238 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
239 /* timer may have used feedkeys() */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
240 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
241 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
242 if (due_time <= 0 || (wtime > 0 && due_time > remaining)) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
243 due_time = remaining; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
244 # ifdef FEAT_JOB_CHANNEL |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
245 if ((due_time < 0 || due_time > 10L) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
246 # ifdef FEAT_GUI |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
247 && !gui.in_use |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
248 # endif |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
249 && (has_pending_job() || channel_any_readahead())) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
250 { |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
251 // There is a pending job or channel, should return soon in order |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
252 // to handle them ASAP. Do check for input briefly. |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
253 due_time = 10L; |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
254 brief_wait = TRUE; |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
255 } |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
256 # endif |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
257 if (wait_func(due_time, interrupted, ignore_input)) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
258 return OK; |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
259 if ((interrupted != NULL && *interrupted) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
260 # ifdef FEAT_JOB_CHANNEL |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
261 || brief_wait |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
262 # endif |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
263 ) |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
264 // Nothing available, but need to return so that side effects get |
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
265 // handled, such as handling a message on a channel. |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
266 return FAIL; |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
267 if (wtime > 0) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
268 remaining -= due_time; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
269 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
270 return FAIL; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
271 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
272 #endif |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
273 |
7 | 274 /* |
15404
440e5071f3f8
patch 8.1.0710: when using timers may wait for job exit quite long
Bram Moolenaar <Bram@vim.org>
parents:
15075
diff
changeset
|
275 * Return non-zero if a character is available. |
7 | 276 */ |
277 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
278 ui_char_avail(void) |
7 | 279 { |
280 #ifdef FEAT_GUI | |
281 if (gui.in_use) | |
282 { | |
283 gui_mch_update(); | |
284 return input_available(); | |
285 } | |
286 #endif | |
287 #ifndef NO_CONSOLE | |
288 # ifdef NO_CONSOLE_INPUT | |
289 if (no_console_input()) | |
290 return 0; | |
291 # endif | |
292 return mch_char_avail(); | |
293 #else | |
294 return 0; | |
295 #endif | |
296 } | |
297 | |
298 /* | |
299 * Delay for the given number of milliseconds. If ignoreinput is FALSE then we | |
300 * cancel the delay if a key is hit. | |
301 */ | |
302 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
303 ui_delay(long msec, int ignoreinput) |
7 | 304 { |
305 #ifdef FEAT_GUI | |
306 if (gui.in_use && !ignoreinput) | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
12924
diff
changeset
|
307 gui_wait_for_chars(msec, typebuf.tb_change_cnt); |
7 | 308 else |
309 #endif | |
310 mch_delay(msec, ignoreinput); | |
311 } | |
312 | |
313 /* | |
314 * If the machine has job control, use it to suspend the program, | |
315 * otherwise fake it by starting a new shell. | |
316 * When running the GUI iconify the window. | |
317 */ | |
318 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
319 ui_suspend(void) |
7 | 320 { |
321 #ifdef FEAT_GUI | |
322 if (gui.in_use) | |
323 { | |
324 gui_mch_iconify(); | |
325 return; | |
326 } | |
327 #endif | |
328 mch_suspend(); | |
329 } | |
330 | |
331 #if !defined(UNIX) || !defined(SIGTSTP) || defined(PROTO) || defined(__BEOS__) | |
332 /* | |
333 * When the OS can't really suspend, call this function to start a shell. | |
334 * This is never called in the GUI. | |
335 */ | |
336 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
337 suspend_shell(void) |
7 | 338 { |
339 if (*p_sh == NUL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15404
diff
changeset
|
340 emsg(_(e_shellempty)); |
7 | 341 else |
342 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
343 msg_puts(_("new shell started\n")); |
7 | 344 do_shell(NULL, 0); |
345 } | |
346 } | |
347 #endif | |
348 | |
349 /* | |
350 * Try to get the current Vim shell size. Put the result in Rows and Columns. | |
351 * Use the new sizes as defaults for 'columns' and 'lines'. | |
352 * Return OK when size could be determined, FAIL otherwise. | |
353 */ | |
354 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
355 ui_get_shellsize(void) |
7 | 356 { |
357 int retval; | |
358 | |
359 #ifdef FEAT_GUI | |
360 if (gui.in_use) | |
361 retval = gui_get_shellsize(); | |
362 else | |
363 #endif | |
364 retval = mch_get_shellsize(); | |
365 | |
366 check_shellsize(); | |
367 | |
368 /* adjust the default for 'lines' and 'columns' */ | |
369 if (retval == OK) | |
370 { | |
371 set_number_default("lines", Rows); | |
372 set_number_default("columns", Columns); | |
373 } | |
374 return retval; | |
375 } | |
376 | |
377 /* | |
378 * Set the size of the Vim shell according to Rows and Columns, if possible. | |
379 * The gui_set_shellsize() or mch_set_shellsize() function will try to set the | |
380 * new size. If this is not possible, it will adjust Rows and Columns. | |
381 */ | |
382 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
383 ui_set_shellsize( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
384 int mustset UNUSED) /* set by the user */ |
7 | 385 { |
386 #ifdef FEAT_GUI | |
387 if (gui.in_use) | |
5106
c3a82208e143
updated for version 7.3.1296
Bram Moolenaar <bram@vim.org>
parents:
5037
diff
changeset
|
388 gui_set_shellsize(mustset, TRUE, RESIZE_BOTH); |
7 | 389 else |
390 #endif | |
391 mch_set_shellsize(); | |
392 } | |
393 | |
394 /* | |
395 * Called when Rows and/or Columns changed. Adjust scroll region and mouse | |
396 * region. | |
397 */ | |
398 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
399 ui_new_shellsize(void) |
7 | 400 { |
401 if (full_screen && !exiting) | |
402 { | |
403 #ifdef FEAT_GUI | |
404 if (gui.in_use) | |
405 gui_new_shellsize(); | |
406 else | |
407 #endif | |
408 mch_new_shellsize(); | |
409 } | |
410 } | |
411 | |
412 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
413 ui_breakcheck(void) |
7 | 414 { |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
415 ui_breakcheck_force(FALSE); |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
416 } |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
417 |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
418 /* |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
419 * When "force" is true also check when the terminal is not in raw mode. |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
420 * This is useful to read input on channels. |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
421 */ |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
422 void |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
423 ui_breakcheck_force(int force) |
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
424 { |
15052
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
425 static int recursive = FALSE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
426 int save_updating_screen = updating_screen; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
427 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
428 // We could be called recursively if stderr is redirected, calling |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
429 // fill_input_buf() calls settmode() when stdin isn't a tty. settmode() |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
430 // calls vgetorpeek() which calls ui_breakcheck() again. |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
431 if (recursive) |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
432 return; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
433 recursive = TRUE; |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
434 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
435 // We do not want gui_resize_shell() to redraw the screen here. |
10771
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
436 ++updating_screen; |
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
437 |
7 | 438 #ifdef FEAT_GUI |
439 if (gui.in_use) | |
440 gui_mch_update(); | |
441 else | |
442 #endif | |
10240
175b1116f96a
commit https://github.com/vim/vim/commit/b9c31e71f5a4653a27e81c21226039bfa35b9131
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
443 mch_breakcheck(force); |
10771
abc27e523e2a
patch 8.0.0275: the screen may be updated at the wrong time
Christian Brabandt <cb@256bit.org>
parents:
10240
diff
changeset
|
444 |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
445 if (save_updating_screen) |
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
446 updating_screen = TRUE; |
13888
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
447 else |
81e8e6181aeb
patch 8.0.1815: crash with terminal window and with 'lazyredraw' set
Christian Brabandt <cb@256bit.org>
parents:
13876
diff
changeset
|
448 reset_updating_screen(FALSE); |
15052
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
449 |
35c2d164a630
patch 8.1.0537: ui_breakcheck() may be called recursively
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
450 recursive = FALSE; |
7 | 451 } |
452 | |
453 /***************************************************************************** | |
454 * Functions for copying and pasting text between applications. | |
455 * This is always included in a GUI version, but may also be included when the | |
456 * clipboard and mouse is available to a terminal version such as xterm. | |
457 * Note: there are some more functions in ops.c that handle selection stuff. | |
458 * | |
459 * Also note that the majority of functions here deal with the X 'primary' | |
460 * (visible - for Visual mode use) selection, and only that. There are no | |
461 * versions of these for the 'clipboard' selection, as Visual mode has no use | |
462 * for them. | |
463 */ | |
464 | |
465 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
466 | |
467 /* | |
468 * Selection stuff using Visual mode, for cutting and pasting text to other | |
469 * windows. | |
470 */ | |
471 | |
472 /* | |
473 * Call this to initialise the clipboard. Pass it FALSE if the clipboard code | |
474 * is included, but the clipboard can not be used, or TRUE if the clipboard can | |
475 * be used. Eg unix may call this with FALSE, then call it again with TRUE if | |
476 * the GUI starts. | |
477 */ | |
478 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
479 clip_init(int can_use) |
7 | 480 { |
481 VimClipboard *cb; | |
482 | |
483 cb = &clip_star; | |
484 for (;;) | |
485 { | |
486 cb->available = can_use; | |
487 cb->owned = FALSE; | |
488 cb->start.lnum = 0; | |
489 cb->start.col = 0; | |
490 cb->end.lnum = 0; | |
491 cb->end.col = 0; | |
492 cb->state = SELECT_CLEARED; | |
493 | |
494 if (cb == &clip_plus) | |
495 break; | |
496 cb = &clip_plus; | |
497 } | |
498 } | |
499 | |
500 /* | |
501 * Check whether the VIsual area has changed, and if so try to become the owner | |
502 * of the selection, and free any old converted selection we may still have | |
503 * lying around. If the VIsual mode has ended, make a copy of what was | |
504 * selected so we can still give it to others. Will probably have to make sure | |
505 * this is called whenever VIsual mode is ended. | |
506 */ | |
507 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
508 clip_update_selection(VimClipboard *clip) |
7 | 509 { |
3674 | 510 pos_T start, end; |
7 | 511 |
512 /* If visual mode is only due to a redo command ("."), then ignore it */ | |
513 if (!redo_VIsual_busy && VIsual_active && (State & NORMAL)) | |
514 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10771
diff
changeset
|
515 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 516 { |
517 start = VIsual; | |
518 end = curwin->w_cursor; | |
519 if (has_mbyte) | |
474 | 520 end.col += (*mb_ptr2len)(ml_get_cursor()) - 1; |
7 | 521 } |
522 else | |
523 { | |
524 start = curwin->w_cursor; | |
525 end = VIsual; | |
526 } | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10771
diff
changeset
|
527 if (!EQUAL_POS(clip->start, start) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10771
diff
changeset
|
528 || !EQUAL_POS(clip->end, end) |
3674 | 529 || clip->vmode != VIsual_mode) |
7 | 530 { |
3674 | 531 clip_clear_selection(clip); |
532 clip->start = start; | |
533 clip->end = end; | |
534 clip->vmode = VIsual_mode; | |
535 clip_free_selection(clip); | |
536 clip_own_selection(clip); | |
537 clip_gen_set_selection(clip); | |
7 | 538 } |
539 } | |
540 } | |
541 | |
542 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
543 clip_own_selection(VimClipboard *cbd) |
7 | 544 { |
545 /* | |
546 * Also want to check somehow that we are reading from the keyboard rather | |
547 * than a mapping etc. | |
548 */ | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
549 #ifdef FEAT_X11 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
550 /* Always own the selection, we might have lost it without being |
2586 | 551 * notified, e.g. during a ":sh" command. */ |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
552 if (cbd->available) |
7 | 553 { |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
554 int was_owned = cbd->owned; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
555 |
7 | 556 cbd->owned = (clip_gen_own_selection(cbd) == OK); |
3674 | 557 if (!was_owned && (cbd == &clip_star || cbd == &clip_plus)) |
7 | 558 { |
620 | 559 /* May have to show a different kind of highlighting for the |
560 * selected area. There is no specific redraw command for this, | |
561 * just redraw all windows on the current buffer. */ | |
7 | 562 if (cbd->owned |
791 | 563 && (get_real_state() == VISUAL |
564 || get_real_state() == SELECTMODE) | |
3674 | 565 && (cbd == &clip_star ? clip_isautosel_star() |
566 : clip_isautosel_plus()) | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
567 && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC)) |
7 | 568 redraw_curbuf_later(INVERTED_ALL); |
569 } | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
570 } |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
571 #else |
3877 | 572 /* Only own the clipboard when we didn't own it yet. */ |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
573 if (!cbd->owned && cbd->available) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
574 cbd->owned = (clip_gen_own_selection(cbd) == OK); |
7 | 575 #endif |
576 } | |
577 | |
578 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
579 clip_lose_selection(VimClipboard *cbd) |
7 | 580 { |
581 #ifdef FEAT_X11 | |
582 int was_owned = cbd->owned; | |
583 #endif | |
3674 | 584 int visual_selection = FALSE; |
585 | |
586 if (cbd == &clip_star || cbd == &clip_plus) | |
587 visual_selection = TRUE; | |
7 | 588 |
589 clip_free_selection(cbd); | |
590 cbd->owned = FALSE; | |
591 if (visual_selection) | |
3674 | 592 clip_clear_selection(cbd); |
7 | 593 clip_gen_lose_selection(cbd); |
594 #ifdef FEAT_X11 | |
595 if (visual_selection) | |
596 { | |
597 /* May have to show a different kind of highlighting for the selected | |
598 * area. There is no specific redraw command for this, just redraw all | |
599 * windows on the current buffer. */ | |
600 if (was_owned | |
791 | 601 && (get_real_state() == VISUAL |
602 || get_real_state() == SELECTMODE) | |
3674 | 603 && (cbd == &clip_star ? |
604 clip_isautosel_star() : clip_isautosel_plus()) | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
605 && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC)) |
7 | 606 { |
607 update_curbuf(INVERTED_ALL); | |
608 setcursor(); | |
609 cursor_on(); | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
610 out_flush_cursor(TRUE, FALSE); |
7 | 611 } |
612 } | |
613 #endif | |
614 } | |
615 | |
3674 | 616 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
617 clip_copy_selection(VimClipboard *clip) |
7 | 618 { |
3674 | 619 if (VIsual_active && (State & NORMAL) && clip->available) |
7 | 620 { |
3674 | 621 clip_update_selection(clip); |
622 clip_free_selection(clip); | |
623 clip_own_selection(clip); | |
624 if (clip->owned) | |
625 clip_get_selection(clip); | |
626 clip_gen_set_selection(clip); | |
7 | 627 } |
628 } | |
629 | |
630 /* | |
6116 | 631 * Save and restore clip_unnamed before doing possibly many changes. This |
632 * prevents accessing the clipboard very often which might slow down Vim | |
633 * considerably. | |
634 */ | |
6561 | 635 static int global_change_count = 0; /* if set, inside a start_global_changes */ |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
636 static int clipboard_needs_update = FALSE; /* clipboard needs to be updated */ |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
637 static int clip_did_set_selection = TRUE; |
6116 | 638 |
639 /* | |
640 * Save clip_unnamed and reset it. | |
641 */ | |
642 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
643 start_global_changes(void) |
6116 | 644 { |
6543 | 645 if (++global_change_count > 1) |
646 return; | |
6116 | 647 clip_unnamed_saved = clip_unnamed; |
6543 | 648 clipboard_needs_update = FALSE; |
6116 | 649 |
6543 | 650 if (clip_did_set_selection) |
6116 | 651 { |
652 clip_unnamed = FALSE; | |
653 clip_did_set_selection = FALSE; | |
654 } | |
655 } | |
656 | |
657 /* | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
658 * Return TRUE if setting the clipboard was postponed, it already contains the |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
659 * right text. |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
660 */ |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
661 int |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
662 is_clipboard_needs_update() |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
663 { |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
664 return clipboard_needs_update; |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
665 } |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
666 |
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
667 /* |
6116 | 668 * Restore clip_unnamed and set the selection when needed. |
669 */ | |
670 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
671 end_global_changes(void) |
6116 | 672 { |
6543 | 673 if (--global_change_count > 0) |
674 /* recursive */ | |
675 return; | |
676 if (!clip_did_set_selection) | |
6116 | 677 { |
678 clip_did_set_selection = TRUE; | |
679 clip_unnamed = clip_unnamed_saved; | |
6543 | 680 clip_unnamed_saved = FALSE; |
681 if (clipboard_needs_update) | |
6116 | 682 { |
6543 | 683 /* only store something in the clipboard, |
684 * if we have yanked anything to it */ | |
685 if (clip_unnamed & CLIP_UNNAMED) | |
686 { | |
687 clip_own_selection(&clip_star); | |
688 clip_gen_set_selection(&clip_star); | |
689 } | |
690 if (clip_unnamed & CLIP_UNNAMED_PLUS) | |
691 { | |
692 clip_own_selection(&clip_plus); | |
693 clip_gen_set_selection(&clip_plus); | |
694 } | |
6116 | 695 } |
696 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
697 clipboard_needs_update = FALSE; |
6116 | 698 } |
699 | |
700 /* | |
7 | 701 * Called when Visual mode is ended: update the selection. |
702 */ | |
703 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
704 clip_auto_select(void) |
7 | 705 { |
3674 | 706 if (clip_isautosel_star()) |
707 clip_copy_selection(&clip_star); | |
708 if (clip_isautosel_plus()) | |
709 clip_copy_selection(&clip_plus); | |
7 | 710 } |
711 | |
712 /* | |
3674 | 713 * Return TRUE if automatic selection of Visual area is desired for the * |
714 * register. | |
7 | 715 */ |
716 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
717 clip_isautosel_star(void) |
7 | 718 { |
719 return ( | |
720 #ifdef FEAT_GUI | |
721 gui.in_use ? (vim_strchr(p_go, GO_ASEL) != NULL) : | |
722 #endif | |
3674 | 723 clip_autoselect_star); |
724 } | |
725 | |
726 /* | |
727 * Return TRUE if automatic selection of Visual area is desired for the + | |
728 * register. | |
729 */ | |
730 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
731 clip_isautosel_plus(void) |
3674 | 732 { |
733 return ( | |
734 #ifdef FEAT_GUI | |
735 gui.in_use ? (vim_strchr(p_go, GO_ASELPLUS) != NULL) : | |
736 #endif | |
737 clip_autoselect_plus); | |
7 | 738 } |
739 | |
740 | |
741 /* | |
742 * Stuff for general mouse selection, without using Visual mode. | |
743 */ | |
744 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
745 static void clip_invert_area(int, int, int, int, int how); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
746 static void clip_invert_rectangle(int row, int col, int height, int width, int invert); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
747 static void clip_get_word_boundaries(VimClipboard *, int, int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
748 static int clip_get_line_end(int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
749 static void clip_update_modeless_selection(VimClipboard *, int, int, |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7743
diff
changeset
|
750 int, int); |
7 | 751 |
752 /* flags for clip_invert_area() */ | |
753 #define CLIP_CLEAR 1 | |
754 #define CLIP_SET 2 | |
755 #define CLIP_TOGGLE 3 | |
756 | |
757 /* | |
758 * Start, continue or end a modeless selection. Used when editing the | |
759 * command-line and in the cmdline window. | |
760 */ | |
761 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
762 clip_modeless(int button, int is_click, int is_drag) |
7 | 763 { |
764 int repeat; | |
765 | |
766 repeat = ((clip_star.mode == SELECT_MODE_CHAR | |
767 || clip_star.mode == SELECT_MODE_LINE) | |
768 && (mod_mask & MOD_MASK_2CLICK)) | |
769 || (clip_star.mode == SELECT_MODE_WORD | |
770 && (mod_mask & MOD_MASK_3CLICK)); | |
771 if (is_click && button == MOUSE_RIGHT) | |
772 { | |
773 /* Right mouse button: If there was no selection, start one. | |
774 * Otherwise extend the existing selection. */ | |
775 if (clip_star.state == SELECT_CLEARED) | |
776 clip_start_selection(mouse_col, mouse_row, FALSE); | |
777 clip_process_selection(button, mouse_col, mouse_row, repeat); | |
778 } | |
779 else if (is_click) | |
780 clip_start_selection(mouse_col, mouse_row, repeat); | |
781 else if (is_drag) | |
782 { | |
783 /* Don't try extending a selection if there isn't one. Happens when | |
784 * button-down is in the cmdline and them moving mouse upwards. */ | |
785 if (clip_star.state != SELECT_CLEARED) | |
786 clip_process_selection(button, mouse_col, mouse_row, repeat); | |
787 } | |
788 else /* release */ | |
789 clip_process_selection(MOUSE_RELEASE, mouse_col, mouse_row, FALSE); | |
790 } | |
791 | |
792 /* | |
793 * Compare two screen positions ala strcmp() | |
794 */ | |
795 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
796 clip_compare_pos( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
797 int row1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
798 int col1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
799 int row2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
800 int col2) |
7 | 801 { |
802 if (row1 > row2) return(1); | |
803 if (row1 < row2) return(-1); | |
804 if (col1 > col2) return(1); | |
805 if (col1 < col2) return(-1); | |
8236
6d221d623c8e
commit https://github.com/vim/vim/commit/9e34110816522b081feb65ed5b2f4ec03d290e30
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
806 return(0); |
7 | 807 } |
808 | |
809 /* | |
810 * Start the selection | |
811 */ | |
812 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
813 clip_start_selection(int col, int row, int repeated_click) |
7 | 814 { |
815 VimClipboard *cb = &clip_star; | |
816 | |
817 if (cb->state == SELECT_DONE) | |
3674 | 818 clip_clear_selection(cb); |
7 | 819 |
820 row = check_row(row); | |
821 col = check_col(col); | |
822 col = mb_fix_col(col, row); | |
823 | |
824 cb->start.lnum = row; | |
825 cb->start.col = col; | |
826 cb->end = cb->start; | |
827 cb->origin_row = (short_u)cb->start.lnum; | |
828 cb->state = SELECT_IN_PROGRESS; | |
829 | |
830 if (repeated_click) | |
831 { | |
832 if (++cb->mode > SELECT_MODE_LINE) | |
833 cb->mode = SELECT_MODE_CHAR; | |
834 } | |
835 else | |
836 cb->mode = SELECT_MODE_CHAR; | |
837 | |
838 #ifdef FEAT_GUI | |
839 /* clear the cursor until the selection is made */ | |
840 if (gui.in_use) | |
841 gui_undraw_cursor(); | |
842 #endif | |
843 | |
844 switch (cb->mode) | |
845 { | |
846 case SELECT_MODE_CHAR: | |
847 cb->origin_start_col = cb->start.col; | |
848 cb->word_end_col = clip_get_line_end((int)cb->start.lnum); | |
849 break; | |
850 | |
851 case SELECT_MODE_WORD: | |
852 clip_get_word_boundaries(cb, (int)cb->start.lnum, cb->start.col); | |
853 cb->origin_start_col = cb->word_start_col; | |
854 cb->origin_end_col = cb->word_end_col; | |
855 | |
856 clip_invert_area((int)cb->start.lnum, cb->word_start_col, | |
857 (int)cb->end.lnum, cb->word_end_col, CLIP_SET); | |
858 cb->start.col = cb->word_start_col; | |
859 cb->end.col = cb->word_end_col; | |
860 break; | |
861 | |
862 case SELECT_MODE_LINE: | |
863 clip_invert_area((int)cb->start.lnum, 0, (int)cb->start.lnum, | |
864 (int)Columns, CLIP_SET); | |
865 cb->start.col = 0; | |
866 cb->end.col = Columns; | |
867 break; | |
868 } | |
869 | |
870 cb->prev = cb->start; | |
871 | |
872 #ifdef DEBUG_SELECTION | |
873 printf("Selection started at (%u,%u)\n", cb->start.lnum, cb->start.col); | |
874 #endif | |
875 } | |
876 | |
877 /* | |
878 * Continue processing the selection | |
879 */ | |
880 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
881 clip_process_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
882 int button, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
883 int col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
884 int row, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
885 int_u repeated_click) |
7 | 886 { |
887 VimClipboard *cb = &clip_star; | |
888 int diff; | |
889 int slen = 1; /* cursor shape width */ | |
890 | |
891 if (button == MOUSE_RELEASE) | |
892 { | |
893 /* Check to make sure we have something selected */ | |
894 if (cb->start.lnum == cb->end.lnum && cb->start.col == cb->end.col) | |
895 { | |
896 #ifdef FEAT_GUI | |
897 if (gui.in_use) | |
898 gui_update_cursor(FALSE, FALSE); | |
899 #endif | |
900 cb->state = SELECT_CLEARED; | |
901 return; | |
902 } | |
903 | |
904 #ifdef DEBUG_SELECTION | |
905 printf("Selection ended: (%u,%u) to (%u,%u)\n", cb->start.lnum, | |
906 cb->start.col, cb->end.lnum, cb->end.col); | |
907 #endif | |
3674 | 908 if (clip_isautosel_star() |
7 | 909 || ( |
910 #ifdef FEAT_GUI | |
911 gui.in_use ? (vim_strchr(p_go, GO_ASELML) != NULL) : | |
912 #endif | |
913 clip_autoselectml)) | |
914 clip_copy_modeless_selection(FALSE); | |
915 #ifdef FEAT_GUI | |
916 if (gui.in_use) | |
917 gui_update_cursor(FALSE, FALSE); | |
918 #endif | |
919 | |
920 cb->state = SELECT_DONE; | |
921 return; | |
922 } | |
923 | |
924 row = check_row(row); | |
925 col = check_col(col); | |
926 col = mb_fix_col(col, row); | |
927 | |
928 if (col == (int)cb->prev.col && row == cb->prev.lnum && !repeated_click) | |
929 return; | |
930 | |
931 /* | |
932 * When extending the selection with the right mouse button, swap the | |
933 * start and end if the position is before half the selection | |
934 */ | |
935 if (cb->state == SELECT_DONE && button == MOUSE_RIGHT) | |
936 { | |
937 /* | |
938 * If the click is before the start, or the click is inside the | |
939 * selection and the start is the closest side, set the origin to the | |
940 * end of the selection. | |
941 */ | |
942 if (clip_compare_pos(row, col, (int)cb->start.lnum, cb->start.col) < 0 | |
943 || (clip_compare_pos(row, col, | |
944 (int)cb->end.lnum, cb->end.col) < 0 | |
945 && (((cb->start.lnum == cb->end.lnum | |
946 && cb->end.col - col > col - cb->start.col)) | |
947 || ((diff = (cb->end.lnum - row) - | |
948 (row - cb->start.lnum)) > 0 | |
949 || (diff == 0 && col < (int)(cb->start.col + | |
950 cb->end.col) / 2))))) | |
951 { | |
952 cb->origin_row = (short_u)cb->end.lnum; | |
953 cb->origin_start_col = cb->end.col - 1; | |
954 cb->origin_end_col = cb->end.col; | |
955 } | |
956 else | |
957 { | |
958 cb->origin_row = (short_u)cb->start.lnum; | |
959 cb->origin_start_col = cb->start.col; | |
960 cb->origin_end_col = cb->start.col; | |
961 } | |
962 if (cb->mode == SELECT_MODE_WORD && !repeated_click) | |
963 cb->mode = SELECT_MODE_CHAR; | |
964 } | |
965 | |
966 /* set state, for when using the right mouse button */ | |
967 cb->state = SELECT_IN_PROGRESS; | |
968 | |
969 #ifdef DEBUG_SELECTION | |
970 printf("Selection extending to (%d,%d)\n", row, col); | |
971 #endif | |
972 | |
973 if (repeated_click && ++cb->mode > SELECT_MODE_LINE) | |
974 cb->mode = SELECT_MODE_CHAR; | |
975 | |
976 switch (cb->mode) | |
977 { | |
978 case SELECT_MODE_CHAR: | |
979 /* If we're on a different line, find where the line ends */ | |
980 if (row != cb->prev.lnum) | |
981 cb->word_end_col = clip_get_line_end(row); | |
982 | |
983 /* See if we are before or after the origin of the selection */ | |
984 if (clip_compare_pos(row, col, cb->origin_row, | |
985 cb->origin_start_col) >= 0) | |
986 { | |
987 if (col >= (int)cb->word_end_col) | |
988 clip_update_modeless_selection(cb, cb->origin_row, | |
989 cb->origin_start_col, row, (int)Columns); | |
990 else | |
991 { | |
992 if (has_mbyte && mb_lefthalve(row, col)) | |
993 slen = 2; | |
994 clip_update_modeless_selection(cb, cb->origin_row, | |
995 cb->origin_start_col, row, col + slen); | |
996 } | |
997 } | |
998 else | |
999 { | |
1000 if (has_mbyte | |
1001 && mb_lefthalve(cb->origin_row, cb->origin_start_col)) | |
1002 slen = 2; | |
1003 if (col >= (int)cb->word_end_col) | |
1004 clip_update_modeless_selection(cb, row, cb->word_end_col, | |
1005 cb->origin_row, cb->origin_start_col + slen); | |
1006 else | |
1007 clip_update_modeless_selection(cb, row, col, | |
1008 cb->origin_row, cb->origin_start_col + slen); | |
1009 } | |
1010 break; | |
1011 | |
1012 case SELECT_MODE_WORD: | |
1013 /* If we are still within the same word, do nothing */ | |
1014 if (row == cb->prev.lnum && col >= (int)cb->word_start_col | |
1015 && col < (int)cb->word_end_col && !repeated_click) | |
1016 return; | |
1017 | |
1018 /* Get new word boundaries */ | |
1019 clip_get_word_boundaries(cb, row, col); | |
1020 | |
1021 /* Handle being after the origin point of selection */ | |
1022 if (clip_compare_pos(row, col, cb->origin_row, | |
1023 cb->origin_start_col) >= 0) | |
1024 clip_update_modeless_selection(cb, cb->origin_row, | |
1025 cb->origin_start_col, row, cb->word_end_col); | |
1026 else | |
1027 clip_update_modeless_selection(cb, row, cb->word_start_col, | |
1028 cb->origin_row, cb->origin_end_col); | |
1029 break; | |
1030 | |
1031 case SELECT_MODE_LINE: | |
1032 if (row == cb->prev.lnum && !repeated_click) | |
1033 return; | |
1034 | |
1035 if (clip_compare_pos(row, col, cb->origin_row, | |
1036 cb->origin_start_col) >= 0) | |
1037 clip_update_modeless_selection(cb, cb->origin_row, 0, row, | |
1038 (int)Columns); | |
1039 else | |
1040 clip_update_modeless_selection(cb, row, 0, cb->origin_row, | |
1041 (int)Columns); | |
1042 break; | |
1043 } | |
1044 | |
1045 cb->prev.lnum = row; | |
1046 cb->prev.col = col; | |
1047 | |
1048 #ifdef DEBUG_SELECTION | |
1049 printf("Selection is: (%u,%u) to (%u,%u)\n", cb->start.lnum, | |
1050 cb->start.col, cb->end.lnum, cb->end.col); | |
1051 #endif | |
1052 } | |
1053 | |
1054 # if defined(FEAT_GUI) || defined(PROTO) | |
1055 /* | |
1056 * Redraw part of the selection if character at "row,col" is inside of it. | |
1057 * Only used for the GUI. | |
1058 */ | |
1059 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1060 clip_may_redraw_selection(int row, int col, int len) |
7 | 1061 { |
1062 int start = col; | |
1063 int end = col + len; | |
1064 | |
1065 if (clip_star.state != SELECT_CLEARED | |
1066 && row >= clip_star.start.lnum | |
1067 && row <= clip_star.end.lnum) | |
1068 { | |
1069 if (row == clip_star.start.lnum && start < (int)clip_star.start.col) | |
1070 start = clip_star.start.col; | |
1071 if (row == clip_star.end.lnum && end > (int)clip_star.end.col) | |
1072 end = clip_star.end.col; | |
1073 if (end > start) | |
1074 clip_invert_area(row, start, row, end, 0); | |
1075 } | |
1076 } | |
1077 # endif | |
1078 | |
1079 /* | |
1080 * Called from outside to clear selected region from the display | |
1081 */ | |
1082 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1083 clip_clear_selection(VimClipboard *cbd) |
7 | 1084 { |
1085 | |
3674 | 1086 if (cbd->state == SELECT_CLEARED) |
7 | 1087 return; |
1088 | |
3674 | 1089 clip_invert_area((int)cbd->start.lnum, cbd->start.col, (int)cbd->end.lnum, |
1090 cbd->end.col, CLIP_CLEAR); | |
1091 cbd->state = SELECT_CLEARED; | |
7 | 1092 } |
1093 | |
1094 /* | |
1095 * Clear the selection if any lines from "row1" to "row2" are inside of it. | |
1096 */ | |
1097 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1098 clip_may_clear_selection(int row1, int row2) |
7 | 1099 { |
1100 if (clip_star.state == SELECT_DONE | |
1101 && row2 >= clip_star.start.lnum | |
1102 && row1 <= clip_star.end.lnum) | |
3674 | 1103 clip_clear_selection(&clip_star); |
7 | 1104 } |
1105 | |
1106 /* | |
1107 * Called before the screen is scrolled up or down. Adjusts the line numbers | |
1108 * of the selection. Call with big number when clearing the screen. | |
1109 */ | |
1110 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1111 clip_scroll_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1112 int rows) /* negative for scroll down */ |
7 | 1113 { |
1114 int lnum; | |
1115 | |
1116 if (clip_star.state == SELECT_CLEARED) | |
1117 return; | |
1118 | |
1119 lnum = clip_star.start.lnum - rows; | |
1120 if (lnum <= 0) | |
1121 clip_star.start.lnum = 0; | |
1122 else if (lnum >= screen_Rows) /* scrolled off of the screen */ | |
1123 clip_star.state = SELECT_CLEARED; | |
1124 else | |
1125 clip_star.start.lnum = lnum; | |
1126 | |
1127 lnum = clip_star.end.lnum - rows; | |
1128 if (lnum < 0) /* scrolled off of the screen */ | |
1129 clip_star.state = SELECT_CLEARED; | |
1130 else if (lnum >= screen_Rows) | |
1131 clip_star.end.lnum = screen_Rows - 1; | |
1132 else | |
1133 clip_star.end.lnum = lnum; | |
1134 } | |
1135 | |
1136 /* | |
1137 * Invert a region of the display between a starting and ending row and column | |
1138 * Values for "how": | |
1139 * CLIP_CLEAR: undo inversion | |
1140 * CLIP_SET: set inversion | |
1141 * CLIP_TOGGLE: set inversion if pos1 < pos2, undo inversion otherwise. | |
1142 * 0: invert (GUI only). | |
1143 */ | |
1144 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1145 clip_invert_area( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1146 int row1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1147 int col1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1148 int row2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1149 int col2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1150 int how) |
7 | 1151 { |
1152 int invert = FALSE; | |
1153 | |
1154 if (how == CLIP_SET) | |
1155 invert = TRUE; | |
1156 | |
1157 /* Swap the from and to positions so the from is always before */ | |
1158 if (clip_compare_pos(row1, col1, row2, col2) > 0) | |
1159 { | |
1160 int tmp_row, tmp_col; | |
1161 | |
1162 tmp_row = row1; | |
1163 tmp_col = col1; | |
1164 row1 = row2; | |
1165 col1 = col2; | |
1166 row2 = tmp_row; | |
1167 col2 = tmp_col; | |
1168 } | |
1169 else if (how == CLIP_TOGGLE) | |
1170 invert = TRUE; | |
1171 | |
1172 /* If all on the same line, do it the easy way */ | |
1173 if (row1 == row2) | |
1174 { | |
1175 clip_invert_rectangle(row1, col1, 1, col2 - col1, invert); | |
1176 } | |
1177 else | |
1178 { | |
1179 /* Handle a piece of the first line */ | |
1180 if (col1 > 0) | |
1181 { | |
1182 clip_invert_rectangle(row1, col1, 1, (int)Columns - col1, invert); | |
1183 row1++; | |
1184 } | |
1185 | |
1186 /* Handle a piece of the last line */ | |
1187 if (col2 < Columns - 1) | |
1188 { | |
1189 clip_invert_rectangle(row2, 0, 1, col2, invert); | |
1190 row2--; | |
1191 } | |
1192 | |
1193 /* Handle the rectangle thats left */ | |
1194 if (row2 >= row1) | |
1195 clip_invert_rectangle(row1, 0, row2 - row1 + 1, (int)Columns, | |
1196 invert); | |
1197 } | |
1198 } | |
1199 | |
1200 /* | |
1201 * Invert or un-invert a rectangle of the screen. | |
1202 * "invert" is true if the result is inverted. | |
1203 */ | |
1204 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1205 clip_invert_rectangle( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1206 int row, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1207 int col, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1208 int height, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1209 int width, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1210 int invert) |
7 | 1211 { |
1212 #ifdef FEAT_GUI | |
1213 if (gui.in_use) | |
1214 gui_mch_invert_rectangle(row, col, height, width); | |
1215 else | |
1216 #endif | |
1217 screen_draw_rectangle(row, col, height, width, invert); | |
1218 } | |
1219 | |
1220 /* | |
1221 * Copy the currently selected area into the '*' register so it will be | |
1222 * available for pasting. | |
1223 * When "both" is TRUE also copy to the '+' register. | |
1224 */ | |
1225 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1226 clip_copy_modeless_selection(int both UNUSED) |
7 | 1227 { |
1228 char_u *buffer; | |
1229 char_u *bufp; | |
1230 int row; | |
1231 int start_col; | |
1232 int end_col; | |
1233 int line_end_col; | |
1234 int add_newline_flag = FALSE; | |
1235 int len; | |
1236 char_u *p; | |
1237 int row1 = clip_star.start.lnum; | |
1238 int col1 = clip_star.start.col; | |
1239 int row2 = clip_star.end.lnum; | |
1240 int col2 = clip_star.end.col; | |
1241 | |
534 | 1242 /* Can't use ScreenLines unless initialized */ |
1243 if (ScreenLines == NULL) | |
1244 return; | |
1245 | |
7 | 1246 /* |
1247 * Make sure row1 <= row2, and if row1 == row2 that col1 <= col2. | |
1248 */ | |
1249 if (row1 > row2) | |
1250 { | |
1251 row = row1; row1 = row2; row2 = row; | |
1252 row = col1; col1 = col2; col2 = row; | |
1253 } | |
1254 else if (row1 == row2 && col1 > col2) | |
1255 { | |
1256 row = col1; col1 = col2; col2 = row; | |
1257 } | |
1258 /* correct starting point for being on right halve of double-wide char */ | |
1259 p = ScreenLines + LineOffset[row1]; | |
1260 if (enc_dbcs != 0) | |
1261 col1 -= (*mb_head_off)(p, p + col1); | |
1262 else if (enc_utf8 && p[col1] == 0) | |
1263 --col1; | |
1264 | |
1265 /* Create a temporary buffer for storing the text */ | |
1266 len = (row2 - row1 + 1) * Columns + 1; | |
1267 if (enc_dbcs != 0) | |
1268 len *= 2; /* max. 2 bytes per display cell */ | |
1269 else if (enc_utf8) | |
714 | 1270 len *= MB_MAXBYTES; |
7 | 1271 buffer = lalloc((long_u)len, TRUE); |
1272 if (buffer == NULL) /* out of memory */ | |
1273 return; | |
1274 | |
1275 /* Process each row in the selection */ | |
1276 for (bufp = buffer, row = row1; row <= row2; row++) | |
1277 { | |
1278 if (row == row1) | |
1279 start_col = col1; | |
1280 else | |
1281 start_col = 0; | |
1282 | |
1283 if (row == row2) | |
1284 end_col = col2; | |
1285 else | |
1286 end_col = Columns; | |
1287 | |
1288 line_end_col = clip_get_line_end(row); | |
1289 | |
1290 /* See if we need to nuke some trailing whitespace */ | |
1291 if (end_col >= Columns && (row < row2 || end_col > line_end_col)) | |
1292 { | |
1293 /* Get rid of trailing whitespace */ | |
1294 end_col = line_end_col; | |
1295 if (end_col < start_col) | |
1296 end_col = start_col; | |
1297 | |
1298 /* If the last line extended to the end, add an extra newline */ | |
1299 if (row == row2) | |
1300 add_newline_flag = TRUE; | |
1301 } | |
1302 | |
1303 /* If after the first row, we need to always add a newline */ | |
1304 if (row > row1 && !LineWraps[row - 1]) | |
1305 *bufp++ = NL; | |
1306 | |
1307 if (row < screen_Rows && end_col <= screen_Columns) | |
1308 { | |
1309 if (enc_dbcs != 0) | |
1310 { | |
944 | 1311 int i; |
1312 | |
7 | 1313 p = ScreenLines + LineOffset[row]; |
1314 for (i = start_col; i < end_col; ++i) | |
1315 if (enc_dbcs == DBCS_JPNU && p[i] == 0x8e) | |
1316 { | |
1317 /* single-width double-byte char */ | |
1318 *bufp++ = 0x8e; | |
1319 *bufp++ = ScreenLines2[LineOffset[row] + i]; | |
1320 } | |
1321 else | |
1322 { | |
1323 *bufp++ = p[i]; | |
1324 if (MB_BYTE2LEN(p[i]) == 2) | |
1325 *bufp++ = p[++i]; | |
1326 } | |
1327 } | |
1328 else if (enc_utf8) | |
1329 { | |
1330 int off; | |
714 | 1331 int i; |
761 | 1332 int ci; |
7 | 1333 |
1334 off = LineOffset[row]; | |
1335 for (i = start_col; i < end_col; ++i) | |
1336 { | |
1337 /* The base character is either in ScreenLinesUC[] or | |
1338 * ScreenLines[]. */ | |
1339 if (ScreenLinesUC[off + i] == 0) | |
1340 *bufp++ = ScreenLines[off + i]; | |
1341 else | |
1342 { | |
1343 bufp += utf_char2bytes(ScreenLinesUC[off + i], bufp); | |
761 | 1344 for (ci = 0; ci < Screen_mco; ++ci) |
7 | 1345 { |
714 | 1346 /* Add a composing character. */ |
761 | 1347 if (ScreenLinesC[ci][off + i] == 0) |
714 | 1348 break; |
761 | 1349 bufp += utf_char2bytes(ScreenLinesC[ci][off + i], |
7 | 1350 bufp); |
1351 } | |
1352 } | |
1353 /* Skip right halve of double-wide character. */ | |
1354 if (ScreenLines[off + i + 1] == 0) | |
1355 ++i; | |
1356 } | |
1357 } | |
1358 else | |
1359 { | |
1360 STRNCPY(bufp, ScreenLines + LineOffset[row] + start_col, | |
1361 end_col - start_col); | |
1362 bufp += end_col - start_col; | |
1363 } | |
1364 } | |
1365 } | |
1366 | |
1367 /* Add a newline at the end if the selection ended there */ | |
1368 if (add_newline_flag) | |
1369 *bufp++ = NL; | |
1370 | |
1371 /* First cleanup any old selection and become the owner. */ | |
1372 clip_free_selection(&clip_star); | |
1373 clip_own_selection(&clip_star); | |
1374 | |
1375 /* Yank the text into the '*' register. */ | |
1376 clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_star); | |
1377 | |
1378 /* Make the register contents available to the outside world. */ | |
1379 clip_gen_set_selection(&clip_star); | |
1380 | |
1381 #ifdef FEAT_X11 | |
1382 if (both) | |
1383 { | |
1384 /* Do the same for the '+' register. */ | |
1385 clip_free_selection(&clip_plus); | |
1386 clip_own_selection(&clip_plus); | |
1387 clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_plus); | |
1388 clip_gen_set_selection(&clip_plus); | |
1389 } | |
1390 #endif | |
1391 vim_free(buffer); | |
1392 } | |
1393 | |
1394 /* | |
1395 * Find the starting and ending positions of the word at the given row and | |
1396 * column. Only white-separated words are recognized here. | |
1397 */ | |
1398 #define CHAR_CLASS(c) (c <= ' ' ? ' ' : vim_iswordc(c)) | |
1399 | |
1400 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1401 clip_get_word_boundaries(VimClipboard *cb, int row, int col) |
7 | 1402 { |
1403 int start_class; | |
1404 int temp_col; | |
1405 char_u *p; | |
1406 int mboff; | |
1407 | |
534 | 1408 if (row >= screen_Rows || col >= screen_Columns || ScreenLines == NULL) |
7 | 1409 return; |
1410 | |
1411 p = ScreenLines + LineOffset[row]; | |
1412 /* Correct for starting in the right halve of a double-wide char */ | |
1413 if (enc_dbcs != 0) | |
1414 col -= dbcs_screen_head_off(p, p + col); | |
1415 else if (enc_utf8 && p[col] == 0) | |
1416 --col; | |
1417 start_class = CHAR_CLASS(p[col]); | |
1418 | |
1419 temp_col = col; | |
1420 for ( ; temp_col > 0; temp_col--) | |
1421 if (enc_dbcs != 0 | |
1422 && (mboff = dbcs_screen_head_off(p, p + temp_col - 1)) > 0) | |
1423 temp_col -= mboff; | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1424 else if (CHAR_CLASS(p[temp_col - 1]) != start_class |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1425 && !(enc_utf8 && p[temp_col - 1] == 0)) |
7 | 1426 break; |
1427 cb->word_start_col = temp_col; | |
1428 | |
1429 temp_col = col; | |
1430 for ( ; temp_col < screen_Columns; temp_col++) | |
1431 if (enc_dbcs != 0 && dbcs_ptr2cells(p + temp_col) == 2) | |
1432 ++temp_col; | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1433 else if (CHAR_CLASS(p[temp_col]) != start_class |
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1434 && !(enc_utf8 && p[temp_col] == 0)) |
7 | 1435 break; |
1436 cb->word_end_col = temp_col; | |
1437 } | |
1438 | |
1439 /* | |
1440 * Find the column position for the last non-whitespace character on the given | |
1441 * line. | |
1442 */ | |
1443 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1444 clip_get_line_end(int row) |
7 | 1445 { |
1446 int i; | |
1447 | |
534 | 1448 if (row >= screen_Rows || ScreenLines == NULL) |
7 | 1449 return 0; |
1450 for (i = screen_Columns; i > 0; i--) | |
1451 if (ScreenLines[LineOffset[row] + i - 1] != ' ') | |
1452 break; | |
1453 return i; | |
1454 } | |
1455 | |
1456 /* | |
1457 * Update the currently selected region by adding and/or subtracting from the | |
1458 * beginning or end and inverting the changed area(s). | |
1459 */ | |
1460 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1461 clip_update_modeless_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1462 VimClipboard *cb, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1463 int row1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1464 int col1, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1465 int row2, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1466 int col2) |
7 | 1467 { |
1468 /* See if we changed at the beginning of the selection */ | |
1469 if (row1 != cb->start.lnum || col1 != (int)cb->start.col) | |
1470 { | |
1471 clip_invert_area(row1, col1, (int)cb->start.lnum, cb->start.col, | |
1472 CLIP_TOGGLE); | |
1473 cb->start.lnum = row1; | |
1474 cb->start.col = col1; | |
1475 } | |
1476 | |
1477 /* See if we changed at the end of the selection */ | |
1478 if (row2 != cb->end.lnum || col2 != (int)cb->end.col) | |
1479 { | |
1480 clip_invert_area((int)cb->end.lnum, cb->end.col, row2, col2, | |
1481 CLIP_TOGGLE); | |
1482 cb->end.lnum = row2; | |
1483 cb->end.col = col2; | |
1484 } | |
1485 } | |
1486 | |
1487 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1488 clip_gen_own_selection(VimClipboard *cbd) |
7 | 1489 { |
1490 #ifdef FEAT_XCLIPBOARD | |
1491 # ifdef FEAT_GUI | |
1492 if (gui.in_use) | |
1493 return clip_mch_own_selection(cbd); | |
1494 else | |
1495 # endif | |
1496 return clip_xterm_own_selection(cbd); | |
1497 #else | |
1498 return clip_mch_own_selection(cbd); | |
1499 #endif | |
1500 } | |
1501 | |
1502 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1503 clip_gen_lose_selection(VimClipboard *cbd) |
7 | 1504 { |
1505 #ifdef FEAT_XCLIPBOARD | |
1506 # ifdef FEAT_GUI | |
1507 if (gui.in_use) | |
1508 clip_mch_lose_selection(cbd); | |
1509 else | |
1510 # endif | |
1511 clip_xterm_lose_selection(cbd); | |
1512 #else | |
1513 clip_mch_lose_selection(cbd); | |
1514 #endif | |
1515 } | |
1516 | |
1517 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1518 clip_gen_set_selection(VimClipboard *cbd) |
7 | 1519 { |
6116 | 1520 if (!clip_did_set_selection) |
1521 { | |
1522 /* Updating postponed, so that accessing the system clipboard won't | |
1523 * hang Vim when accessing it many times (e.g. on a :g comand). */ | |
6543 | 1524 if ((cbd == &clip_plus && (clip_unnamed_saved & CLIP_UNNAMED_PLUS)) |
1525 || (cbd == &clip_star && (clip_unnamed_saved & CLIP_UNNAMED))) | |
1526 { | |
1527 clipboard_needs_update = TRUE; | |
6116 | 1528 return; |
6543 | 1529 } |
6116 | 1530 } |
7 | 1531 #ifdef FEAT_XCLIPBOARD |
1532 # ifdef FEAT_GUI | |
1533 if (gui.in_use) | |
1534 clip_mch_set_selection(cbd); | |
1535 else | |
1536 # endif | |
1537 clip_xterm_set_selection(cbd); | |
1538 #else | |
1539 clip_mch_set_selection(cbd); | |
1540 #endif | |
1541 } | |
1542 | |
1543 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1544 clip_gen_request_selection(VimClipboard *cbd) |
7 | 1545 { |
1546 #ifdef FEAT_XCLIPBOARD | |
1547 # ifdef FEAT_GUI | |
1548 if (gui.in_use) | |
1549 clip_mch_request_selection(cbd); | |
1550 else | |
1551 # endif | |
1552 clip_xterm_request_selection(cbd); | |
1553 #else | |
1554 clip_mch_request_selection(cbd); | |
1555 #endif | |
1556 } | |
1557 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1558 #if (defined(FEAT_X11) && defined(USE_SYSTEM)) || defined(PROTO) |
4209 | 1559 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1560 clip_gen_owner_exists(VimClipboard *cbd UNUSED) |
4209 | 1561 { |
1562 #ifdef FEAT_XCLIPBOARD | |
1563 # ifdef FEAT_GUI_GTK | |
1564 if (gui.in_use) | |
1565 return clip_gtk_owner_exists(cbd); | |
1566 else | |
1567 # endif | |
1568 return clip_x11_owner_exists(cbd); | |
5184
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5136
diff
changeset
|
1569 #else |
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5136
diff
changeset
|
1570 return TRUE; |
4209 | 1571 #endif |
1572 } | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1573 #endif |
4209 | 1574 |
7 | 1575 #endif /* FEAT_CLIPBOARD */ |
1576 | |
1577 /***************************************************************************** | |
1578 * Functions that handle the input buffer. | |
1579 * This is used for any GUI version, and the unix terminal version. | |
1580 * | |
1581 * For Unix, the input characters are buffered to be able to check for a | |
1582 * CTRL-C. This should be done with signals, but I don't know how to do that | |
1583 * in a portable way for a tty in RAW mode. | |
1584 * | |
1585 * For the client-server code in the console the received keys are put in the | |
1586 * input buffer. | |
1587 */ | |
1588 | |
1589 #if defined(USE_INPUT_BUF) || defined(PROTO) | |
1590 | |
1591 /* | |
1592 * Internal typeahead buffer. Includes extra space for long key code | |
1593 * descriptions which would otherwise overflow. The buffer is considered full | |
1594 * when only this extra space (or part of it) remains. | |
1595 */ | |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15506
diff
changeset
|
1596 #if defined(FEAT_JOB_CHANNEL) || defined(FEAT_CLIENTSERVER) |
7 | 1597 /* |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15506
diff
changeset
|
1598 * NetBeans stuffs debugger commands into the input buffer. |
7 | 1599 * This requires a larger buffer... |
1600 * (Madsen) Go with this for remote input as well ... | |
1601 */ | |
1602 # define INBUFLEN 4096 | |
1603 #else | |
1604 # define INBUFLEN 250 | |
1605 #endif | |
1606 | |
1607 static char_u inbuf[INBUFLEN + MAX_KEY_CODE_LEN]; | |
1608 static int inbufcount = 0; /* number of chars in inbuf[] */ | |
1609 | |
1610 /* | |
1611 * vim_is_input_buf_full(), vim_is_input_buf_empty(), add_to_input_buf(), and | |
1612 * trash_input_buf() are functions for manipulating the input buffer. These | |
1613 * are used by the gui_* calls when a GUI is used to handle keyboard input. | |
1614 */ | |
1615 | |
1616 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1617 vim_is_input_buf_full(void) |
7 | 1618 { |
1619 return (inbufcount >= INBUFLEN); | |
1620 } | |
1621 | |
1622 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1623 vim_is_input_buf_empty(void) |
7 | 1624 { |
1625 return (inbufcount == 0); | |
1626 } | |
1627 | |
1628 #if defined(FEAT_OLE) || defined(PROTO) | |
1629 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1630 vim_free_in_input_buf(void) |
7 | 1631 { |
1632 return (INBUFLEN - inbufcount); | |
1633 } | |
1634 #endif | |
1635 | |
575 | 1636 #if defined(FEAT_GUI_GTK) || defined(PROTO) |
7 | 1637 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1638 vim_used_in_input_buf(void) |
7 | 1639 { |
1640 return inbufcount; | |
1641 } | |
1642 #endif | |
1643 | |
1644 /* | |
1645 * Return the current contents of the input buffer and make it empty. | |
1646 * The returned pointer must be passed to set_input_buf() later. | |
1647 */ | |
1648 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1649 get_input_buf(void) |
7 | 1650 { |
1651 garray_T *gap; | |
1652 | |
1653 /* We use a growarray to store the data pointer and the length. */ | |
1654 gap = (garray_T *)alloc((unsigned)sizeof(garray_T)); | |
1655 if (gap != NULL) | |
1656 { | |
1657 /* Add one to avoid a zero size. */ | |
1658 gap->ga_data = alloc((unsigned)inbufcount + 1); | |
1659 if (gap->ga_data != NULL) | |
1660 mch_memmove(gap->ga_data, inbuf, (size_t)inbufcount); | |
1661 gap->ga_len = inbufcount; | |
1662 } | |
1663 trash_input_buf(); | |
1664 return (char_u *)gap; | |
1665 } | |
1666 | |
1667 /* | |
1668 * Restore the input buffer with a pointer returned from get_input_buf(). | |
1669 * The allocated memory is freed, this only works once! | |
1670 */ | |
1671 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1672 set_input_buf(char_u *p) |
7 | 1673 { |
1674 garray_T *gap = (garray_T *)p; | |
1675 | |
1676 if (gap != NULL) | |
1677 { | |
1678 if (gap->ga_data != NULL) | |
1679 { | |
1680 mch_memmove(inbuf, gap->ga_data, gap->ga_len); | |
1681 inbufcount = gap->ga_len; | |
1682 vim_free(gap->ga_data); | |
1683 } | |
1684 vim_free(gap); | |
1685 } | |
1686 } | |
1687 | |
1688 /* | |
1689 * Add the given bytes to the input buffer | |
1690 * Special keys start with CSI. A real CSI must have been translated to | |
1691 * CSI KS_EXTRA KE_CSI. K_SPECIAL doesn't require translation. | |
1692 */ | |
1693 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1694 add_to_input_buf(char_u *s, int len) |
7 | 1695 { |
1696 if (inbufcount + len > INBUFLEN + MAX_KEY_CODE_LEN) | |
1697 return; /* Shouldn't ever happen! */ | |
1698 | |
1699 #ifdef FEAT_HANGULIN | |
1700 if ((State & (INSERT|CMDLINE)) && hangul_input_state_get()) | |
1701 if ((len = hangul_input_process(s, len)) == 0) | |
1702 return; | |
1703 #endif | |
1704 | |
1705 while (len--) | |
1706 inbuf[inbufcount++] = *s++; | |
1707 } | |
1708 | |
1709 /* | |
1710 * Add "str[len]" to the input buffer while escaping CSI bytes. | |
1711 */ | |
1712 void | |
1713 add_to_input_buf_csi(char_u *str, int len) | |
1714 { | |
1715 int i; | |
1716 char_u buf[2]; | |
1717 | |
1718 for (i = 0; i < len; ++i) | |
1719 { | |
1720 add_to_input_buf(str + i, 1); | |
1721 if (str[i] == CSI) | |
1722 { | |
1723 /* Turn CSI into K_CSI. */ | |
1724 buf[0] = KS_EXTRA; | |
1725 buf[1] = (int)KE_CSI; | |
1726 add_to_input_buf(buf, 2); | |
1727 } | |
1728 } | |
1729 } | |
1730 | |
1731 #if defined(FEAT_HANGULIN) || defined(PROTO) | |
1732 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1733 push_raw_key(char_u *s, int len) |
7 | 1734 { |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1735 char_u *tmpbuf; |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1736 char_u *inp = s; |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1737 |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1738 /* use the conversion result if possible */ |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1739 tmpbuf = hangul_string_convert(s, &len); |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7080
diff
changeset
|
1740 if (tmpbuf != NULL) |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1741 inp = tmpbuf; |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1742 |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1743 for (; len--; inp++) |
8366
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1744 { |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1745 inbuf[inbufcount++] = *inp; |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1746 if (*inp == CSI) |
8366
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1747 { |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1748 /* Turn CSI into K_CSI. */ |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1749 inbuf[inbufcount++] = KS_EXTRA; |
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1750 inbuf[inbufcount++] = (int)KE_CSI; |
8366
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1751 } |
6099e8185045
commit https://github.com/vim/vim/commit/00ded43a5a85df57abb74f9e3a38a401f6fbd8fd
Christian Brabandt <cb@256bit.org>
parents:
8281
diff
changeset
|
1752 } |
8393
a7f94f0ba183
commit https://github.com/vim/vim/commit/179f1b9a7ddf3624daf6380c3dad740e0a1ba361
Christian Brabandt <cb@256bit.org>
parents:
8366
diff
changeset
|
1753 vim_free(tmpbuf); |
7 | 1754 } |
1755 #endif | |
1756 | |
1757 /* Remove everything from the input buffer. Called when ^C is found */ | |
1758 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1759 trash_input_buf(void) |
7 | 1760 { |
1761 inbufcount = 0; | |
1762 } | |
1763 | |
1764 /* | |
1765 * Read as much data from the input buffer as possible up to maxlen, and store | |
1766 * it in buf. | |
1767 */ | |
1768 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1769 read_from_input_buf(char_u *buf, long maxlen) |
7 | 1770 { |
1771 if (inbufcount == 0) /* if the buffer is empty, fill it */ | |
1772 fill_input_buf(TRUE); | |
1773 if (maxlen > inbufcount) | |
1774 maxlen = inbufcount; | |
1775 mch_memmove(buf, inbuf, (size_t)maxlen); | |
1776 inbufcount -= maxlen; | |
1777 if (inbufcount) | |
1778 mch_memmove(inbuf, inbuf + maxlen, (size_t)inbufcount); | |
1779 return (int)maxlen; | |
1780 } | |
1781 | |
1782 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1783 fill_input_buf(int exit_on_error UNUSED) |
7 | 1784 { |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
1785 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 1786 int len; |
1787 int try; | |
1788 static int did_read_something = FALSE; | |
1789 static char_u *rest = NULL; /* unconverted rest of previous read */ | |
1790 static int restlen = 0; | |
1791 int unconverted; | |
1792 #endif | |
1793 | |
1794 #ifdef FEAT_GUI | |
294 | 1795 if (gui.in_use |
1796 # ifdef NO_CONSOLE_INPUT | |
1797 /* Don't use the GUI input when the window hasn't been opened yet. | |
1798 * We get here from ui_inchar() when we should try reading from stdin. */ | |
1799 && !no_console_input() | |
1800 # endif | |
1801 ) | |
7 | 1802 { |
1803 gui_mch_update(); | |
1804 return; | |
1805 } | |
1806 #endif | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12519
diff
changeset
|
1807 #if defined(UNIX) || defined(VMS) || defined(MACOS_X) |
7 | 1808 if (vim_is_input_buf_full()) |
1809 return; | |
1810 /* | |
1811 * Fill_input_buf() is only called when we really need a character. | |
1812 * If we can't get any, but there is some in the buffer, just return. | |
1813 * If we can't get any, and there isn't any in the buffer, we give up and | |
1814 * exit Vim. | |
1815 */ | |
1816 # ifdef __BEOS__ | |
1817 /* | |
1818 * On the BeBox version (for now), all input is secretly performed within | |
1819 * beos_select() which is called from RealWaitForChar(). | |
1820 */ | |
1821 while (!vim_is_input_buf_full() && RealWaitForChar(read_cmd_fd, 0, NULL)) | |
1822 ; | |
1823 len = inbufcount; | |
1824 inbufcount = 0; | |
1825 # else | |
1826 | |
1827 if (rest != NULL) | |
1828 { | |
1829 /* Use remainder of previous call, starts with an invalid character | |
1830 * that may become valid when reading more. */ | |
1831 if (restlen > INBUFLEN - inbufcount) | |
1832 unconverted = INBUFLEN - inbufcount; | |
1833 else | |
1834 unconverted = restlen; | |
1835 mch_memmove(inbuf + inbufcount, rest, unconverted); | |
1836 if (unconverted == restlen) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
1837 VIM_CLEAR(rest); |
7 | 1838 else |
1839 { | |
1840 restlen -= unconverted; | |
1841 mch_memmove(rest, rest + unconverted, restlen); | |
1842 } | |
1843 inbufcount += unconverted; | |
1844 } | |
1845 else | |
1846 unconverted = 0; | |
1847 | |
1848 len = 0; /* to avoid gcc warning */ | |
1849 for (try = 0; try < 100; ++try) | |
1850 { | |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1851 size_t readlen = (size_t)((INBUFLEN - inbufcount) |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1852 / input_conv.vc_factor); |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1853 # ifdef VMS |
13776
ef6de4674811
patch 8.0.1760: wrong number of arguments to vms_read()
Christian Brabandt <cb@256bit.org>
parents:
13758
diff
changeset
|
1854 len = vms_read((char *)inbuf + inbufcount, readlen); |
13758
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1855 # else |
63679d671ced
patch 8.0.1751: #ifdef causes bad highlighting
Christian Brabandt <cb@256bit.org>
parents:
13448
diff
changeset
|
1856 len = read(read_cmd_fd, (char *)inbuf + inbufcount, readlen); |
7 | 1857 # endif |
169 | 1858 |
7 | 1859 if (len > 0 || got_int) |
1860 break; | |
1861 /* | |
1862 * If reading stdin results in an error, continue reading stderr. | |
1863 * This helps when using "foo | xargs vim". | |
1864 */ | |
1865 if (!did_read_something && !isatty(read_cmd_fd) && read_cmd_fd == 0) | |
1866 { | |
1867 int m = cur_tmode; | |
1868 | |
1869 /* We probably set the wrong file descriptor to raw mode. Switch | |
1870 * back to cooked mode, use another descriptor and set the mode to | |
1871 * what it was. */ | |
1872 settmode(TMODE_COOK); | |
1873 #ifdef HAVE_DUP | |
1874 /* Use stderr for stdin, also works for shell commands. */ | |
1875 close(0); | |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
13888
diff
changeset
|
1876 vim_ignored = dup(2); |
7 | 1877 #else |
1878 read_cmd_fd = 2; /* read from stderr instead of stdin */ | |
1879 #endif | |
1880 settmode(m); | |
1881 } | |
1882 if (!exit_on_error) | |
1883 return; | |
1884 } | |
1885 # endif | |
1886 if (len <= 0 && !got_int) | |
1887 read_error_exit(); | |
1888 if (len > 0) | |
1889 did_read_something = TRUE; | |
1890 if (got_int) | |
1891 { | |
1892 /* Interrupted, pretend a CTRL-C was typed. */ | |
1893 inbuf[0] = 3; | |
1894 inbufcount = 1; | |
1895 } | |
1896 else | |
1897 { | |
1898 /* | |
1899 * May perform conversion on the input characters. | |
1900 * Include the unconverted rest of the previous call. | |
1901 * If there is an incomplete char at the end it is kept for the next | |
1902 * time, reading more bytes should make conversion possible. | |
1903 * Don't do this in the unlikely event that the input buffer is too | |
1904 * small ("rest" still contains more bytes). | |
1905 */ | |
1906 if (input_conv.vc_type != CONV_NONE) | |
1907 { | |
1908 inbufcount -= unconverted; | |
1909 len = convert_input_safe(inbuf + inbufcount, | |
1910 len + unconverted, INBUFLEN - inbufcount, | |
1911 rest == NULL ? &rest : NULL, &restlen); | |
1912 } | |
1913 while (len-- > 0) | |
1914 { | |
1915 /* | |
1916 * if a CTRL-C was typed, remove it from the buffer and set got_int | |
1917 */ | |
1918 if (inbuf[inbufcount] == 3 && ctrl_c_interrupts) | |
1919 { | |
1920 /* remove everything typed before the CTRL-C */ | |
1921 mch_memmove(inbuf, inbuf + inbufcount, (size_t)(len + 1)); | |
1922 inbufcount = 0; | |
1923 got_int = TRUE; | |
1924 } | |
1925 ++inbufcount; | |
1926 } | |
1927 } | |
7408
1886f2863437
commit https://github.com/vim/vim/commit/e7fedb6ebe72d9a475aa65109b77d5ed4667067a
Christian Brabandt <cb@256bit.org>
parents:
7208
diff
changeset
|
1928 #endif /* UNIX or VMS*/ |
7 | 1929 } |
7408
1886f2863437
commit https://github.com/vim/vim/commit/e7fedb6ebe72d9a475aa65109b77d5ed4667067a
Christian Brabandt <cb@256bit.org>
parents:
7208
diff
changeset
|
1930 #endif /* defined(UNIX) || defined(FEAT_GUI) || defined(VMS) */ |
7 | 1931 |
1932 /* | |
1933 * Exit because of an input read error. | |
1934 */ | |
1935 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1936 read_error_exit(void) |
7 | 1937 { |
1938 if (silent_mode) /* Normal way to exit for "ex -s" */ | |
1939 getout(0); | |
1940 STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); | |
1941 preserve_exit(); | |
1942 } | |
1943 | |
1944 #if defined(CURSOR_SHAPE) || defined(PROTO) | |
1945 /* | |
1946 * May update the shape of the cursor. | |
1947 */ | |
1948 void | |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1949 ui_cursor_shape_forced(int forced) |
7 | 1950 { |
1951 # ifdef FEAT_GUI | |
1952 if (gui.in_use) | |
1953 gui_update_cursor_later(); | |
36 | 1954 else |
7 | 1955 # endif |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1956 term_cursor_mode(forced); |
36 | 1957 |
7 | 1958 # ifdef MCH_CURSOR_SHAPE |
1959 mch_update_cursor(); | |
1960 # endif | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1961 |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1962 # ifdef FEAT_CONCEAL |
13876
156ebdcb8ef5
patch 8.0.1809: various typos
Christian Brabandt <cb@256bit.org>
parents:
13776
diff
changeset
|
1963 conceal_check_cursor_line(); |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1964 # endif |
7 | 1965 } |
12076
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1966 |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1967 void |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1968 ui_cursor_shape(void) |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1969 { |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1970 ui_cursor_shape_forced(FALSE); |
ca4931a20f8c
patch 8.0.0918: cannot get terminal window cursor shape or attributes
Christian Brabandt <cb@256bit.org>
parents:
11709
diff
changeset
|
1971 } |
7 | 1972 #endif |
1973 | |
1974 /* | |
1975 * Check bounds for column number | |
1976 */ | |
1977 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1978 check_col(int col) |
7 | 1979 { |
1980 if (col < 0) | |
1981 return 0; | |
1982 if (col >= (int)screen_Columns) | |
1983 return (int)screen_Columns - 1; | |
1984 return col; | |
1985 } | |
1986 | |
1987 /* | |
1988 * Check bounds for row number | |
1989 */ | |
1990 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1991 check_row(int row) |
7 | 1992 { |
1993 if (row < 0) | |
1994 return 0; | |
1995 if (row >= (int)screen_Rows) | |
1996 return (int)screen_Rows - 1; | |
1997 return row; | |
1998 } | |
1999 | |
2000 /* | |
2001 * Stuff for the X clipboard. Shared between VMS and Unix. | |
2002 */ | |
2003 | |
2004 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) || defined(PROTO) | |
2005 # include <X11/Xatom.h> | |
2006 # include <X11/Intrinsic.h> | |
2007 | |
2008 /* | |
2009 * Open the application context (if it hasn't been opened yet). | |
2010 * Used for Motif and Athena GUI and the xterm clipboard. | |
2011 */ | |
2012 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2013 open_app_context(void) |
7 | 2014 { |
2015 if (app_context == NULL) | |
2016 { | |
2017 XtToolkitInitialize(); | |
2018 app_context = XtCreateApplicationContext(); | |
2019 } | |
2020 } | |
2021 | |
2022 static Atom vim_atom; /* Vim's own special selection format */ | |
2023 static Atom vimenc_atom; /* Vim's extended selection format */ | |
3346 | 2024 static Atom utf8_atom; |
7 | 2025 static Atom compound_text_atom; |
2026 static Atom text_atom; | |
2027 static Atom targets_atom; | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2028 static Atom timestamp_atom; /* Used to get a timestamp */ |
7 | 2029 |
2030 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2031 x11_setup_atoms(Display *dpy) |
7 | 2032 { |
2033 vim_atom = XInternAtom(dpy, VIM_ATOM_NAME, False); | |
2034 vimenc_atom = XInternAtom(dpy, VIMENC_ATOM_NAME,False); | |
3346 | 2035 utf8_atom = XInternAtom(dpy, "UTF8_STRING", False); |
7 | 2036 compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False); |
2037 text_atom = XInternAtom(dpy, "TEXT", False); | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2038 targets_atom = XInternAtom(dpy, "TARGETS", False); |
7 | 2039 clip_star.sel_atom = XA_PRIMARY; |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2040 clip_plus.sel_atom = XInternAtom(dpy, "CLIPBOARD", False); |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2041 timestamp_atom = XInternAtom(dpy, "TIMESTAMP", False); |
7 | 2042 } |
2043 | |
2044 /* | |
2045 * X Selection stuff, for cutting and pasting text to other windows. | |
2046 */ | |
2047 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2048 static Boolean clip_x11_convert_selection_cb(Widget w, Atom *sel_atom, Atom *target, Atom *type, XtPointer *value, long_u *length, int *format); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2049 static void clip_x11_lose_ownership_cb(Widget w, Atom *sel_atom); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2050 static void clip_x11_notify_cb(Widget w, Atom *sel_atom, Atom *target); |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2051 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2052 /* |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2053 * Property callback to get a timestamp for XtOwnSelection. |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2054 */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2055 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2056 clip_x11_timestamp_cb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2057 Widget w, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2058 XtPointer n UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2059 XEvent *event, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2060 Boolean *cont UNUSED) |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2061 { |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2062 Atom actual_type; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2063 int format; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2064 unsigned long nitems, bytes_after; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2065 unsigned char *prop=NULL; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2066 XPropertyEvent *xproperty=&event->xproperty; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2067 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2068 /* Must be a property notify, state can't be Delete (True), has to be |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2069 * one of the supported selection types. */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2070 if (event->type != PropertyNotify || xproperty->state |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2071 || (xproperty->atom != clip_star.sel_atom |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2072 && xproperty->atom != clip_plus.sel_atom)) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2073 return; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2074 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2075 if (XGetWindowProperty(xproperty->display, xproperty->window, |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2076 xproperty->atom, 0, 0, False, timestamp_atom, &actual_type, &format, |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2077 &nitems, &bytes_after, &prop)) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2078 return; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2079 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2080 if (prop) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2081 XFree(prop); |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2082 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2083 /* Make sure the property type is "TIMESTAMP" and it's 32 bits. */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2084 if (actual_type != timestamp_atom || format != 32) |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2085 return; |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2086 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2087 /* Get the selection, using the event timestamp. */ |
2586 | 2088 if (XtOwnSelection(w, xproperty->atom, xproperty->time, |
2089 clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2090 clip_x11_notify_cb) == OK) |
2586 | 2091 { |
2092 /* Set the "owned" flag now, there may have been a call to | |
2093 * lose_ownership_cb in between. */ | |
2094 if (xproperty->atom == clip_plus.sel_atom) | |
2095 clip_plus.owned = TRUE; | |
2096 else | |
2097 clip_star.owned = TRUE; | |
2098 } | |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2099 } |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2100 |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2101 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2102 x11_setup_selection(Widget w) |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2103 { |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2104 XtAddEventHandler(w, PropertyChangeMask, False, |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2105 /*(XtEventHandler)*/clip_x11_timestamp_cb, (XtPointer)NULL); |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2106 } |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2107 |
7 | 2108 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2109 clip_x11_request_selection_cb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2110 Widget w UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2111 XtPointer success, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2112 Atom *sel_atom, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2113 Atom *type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2114 XtPointer value, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2115 long_u *length, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2116 int *format) |
7 | 2117 { |
2896 | 2118 int motion_type = MAUTO; |
7 | 2119 long_u len; |
2120 char_u *p; | |
2121 char **text_list = NULL; | |
2122 VimClipboard *cbd; | |
2123 char_u *tmpbuf = NULL; | |
2124 | |
2125 if (*sel_atom == clip_plus.sel_atom) | |
2126 cbd = &clip_plus; | |
2127 else | |
2128 cbd = &clip_star; | |
2129 | |
2130 if (value == NULL || *length == 0) | |
2131 { | |
1719 | 2132 clip_free_selection(cbd); /* nothing received, clear register */ |
7 | 2133 *(int *)success = FALSE; |
2134 return; | |
2135 } | |
2136 p = (char_u *)value; | |
2137 len = *length; | |
2138 if (*type == vim_atom) | |
2139 { | |
2140 motion_type = *p++; | |
2141 len--; | |
2142 } | |
2143 | |
2144 else if (*type == vimenc_atom) | |
2145 { | |
2146 char_u *enc; | |
2147 vimconv_T conv; | |
2148 int convlen; | |
2149 | |
2150 motion_type = *p++; | |
2151 --len; | |
2152 | |
2153 enc = p; | |
2154 p += STRLEN(p) + 1; | |
2155 len -= p - enc; | |
2156 | |
2157 /* If the encoding of the text is different from 'encoding', attempt | |
2158 * converting it. */ | |
2159 conv.vc_type = CONV_NONE; | |
2160 convert_setup(&conv, enc, p_enc); | |
2161 if (conv.vc_type != CONV_NONE) | |
2162 { | |
2163 convlen = len; /* Need to use an int here. */ | |
2164 tmpbuf = string_convert(&conv, p, &convlen); | |
2165 len = convlen; | |
2166 if (tmpbuf != NULL) | |
2167 p = tmpbuf; | |
2168 convert_setup(&conv, NULL, NULL); | |
2169 } | |
2170 } | |
2171 | |
3346 | 2172 else if (*type == compound_text_atom |
2173 || *type == utf8_atom | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2174 || (enc_dbcs != 0 && *type == text_atom)) |
7 | 2175 { |
2176 XTextProperty text_prop; | |
2177 int n_text = 0; | |
2178 int status; | |
2179 | |
2180 text_prop.value = (unsigned char *)value; | |
2181 text_prop.encoding = *type; | |
2182 text_prop.format = *format; | |
1719 | 2183 text_prop.nitems = len; |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2184 #if defined(X_HAVE_UTF8_STRING) |
4201 | 2185 if (*type == utf8_atom) |
2186 status = Xutf8TextPropertyToTextList(X_DISPLAY, &text_prop, | |
2187 &text_list, &n_text); | |
2188 else | |
2189 #endif | |
2190 status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop, | |
7 | 2191 &text_list, &n_text); |
2192 if (status != Success || n_text < 1) | |
2193 { | |
2194 *(int *)success = FALSE; | |
2195 return; | |
2196 } | |
2197 p = (char_u *)text_list[0]; | |
2198 len = STRLEN(p); | |
2199 } | |
2200 clip_yank_selection(motion_type, p, (long)len, cbd); | |
2201 | |
2202 if (text_list != NULL) | |
2203 XFreeStringList(text_list); | |
2204 vim_free(tmpbuf); | |
2205 XtFree((char *)value); | |
2206 *(int *)success = TRUE; | |
2207 } | |
2208 | |
2209 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2210 clip_x11_request_selection( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2211 Widget myShell, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2212 Display *dpy, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2213 VimClipboard *cbd) |
7 | 2214 { |
2215 XEvent event; | |
2216 Atom type; | |
2217 static int success; | |
2218 int i; | |
1715 | 2219 time_t start_time; |
2220 int timed_out = FALSE; | |
7 | 2221 |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2222 for (i = 0; i < 6; i++) |
7 | 2223 { |
2224 switch (i) | |
2225 { | |
2226 case 0: type = vimenc_atom; break; | |
2227 case 1: type = vim_atom; break; | |
3346 | 2228 case 2: type = utf8_atom; break; |
2229 case 3: type = compound_text_atom; break; | |
2230 case 4: type = text_atom; break; | |
7 | 2231 default: type = XA_STRING; |
2232 } | |
4272 | 2233 if (type == utf8_atom |
2234 # if defined(X_HAVE_UTF8_STRING) | |
2235 && !enc_utf8 | |
2236 # endif | |
2237 ) | |
2238 /* Only request utf-8 when 'encoding' is utf8 and | |
2239 * Xutf8TextPropertyToTextList is available. */ | |
3346 | 2240 continue; |
1719 | 2241 success = MAYBE; |
7 | 2242 XtGetSelectionValue(myShell, cbd->sel_atom, type, |
2243 clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime); | |
2244 | |
2245 /* Make sure the request for the selection goes out before waiting for | |
2246 * a response. */ | |
2247 XFlush(dpy); | |
2248 | |
2249 /* | |
2250 * Wait for result of selection request, otherwise if we type more | |
2251 * characters, then they will appear before the one that requested the | |
2252 * paste! Don't worry, we will catch up with any other events later. | |
2253 */ | |
1715 | 2254 start_time = time(NULL); |
1719 | 2255 while (success == MAYBE) |
7 | 2256 { |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2257 if (XCheckTypedEvent(dpy, PropertyNotify, &event) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2258 || XCheckTypedEvent(dpy, SelectionNotify, &event) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2259 || XCheckTypedEvent(dpy, SelectionRequest, &event)) |
1715 | 2260 { |
1719 | 2261 /* This is where clip_x11_request_selection_cb() should be |
2262 * called. It may actually happen a bit later, so we loop | |
2263 * until "success" changes. | |
2264 * We may get a SelectionRequest here and if we don't handle | |
2265 * it we hang. KDE klipper does this, for example. | |
2266 * We need to handle a PropertyNotify for large selections. */ | |
1715 | 2267 XtDispatchEvent(&event); |
1719 | 2268 continue; |
1715 | 2269 } |
7 | 2270 |
1715 | 2271 /* Time out after 2 to 3 seconds to avoid that we hang when the |
2272 * other process doesn't respond. Note that the SelectionNotify | |
2273 * event may still come later when the selection owner comes back | |
1719 | 2274 * to life and the text gets inserted unexpectedly. Don't know |
2275 * why that happens or how to avoid that :-(. */ | |
1715 | 2276 if (time(NULL) > start_time + 2) |
2277 { | |
2278 timed_out = TRUE; | |
2279 break; | |
2280 } | |
2281 | |
7 | 2282 /* Do we need this? Probably not. */ |
2283 XSync(dpy, False); | |
2284 | |
1715 | 2285 /* Wait for 1 msec to avoid that we eat up all CPU time. */ |
2286 ui_delay(1L, TRUE); | |
7 | 2287 } |
2288 | |
1719 | 2289 if (success == TRUE) |
7 | 2290 return; |
1715 | 2291 |
2292 /* don't do a retry with another type after timing out, otherwise we | |
2293 * hang for 15 seconds. */ | |
2294 if (timed_out) | |
2295 break; | |
7 | 2296 } |
2297 | |
2298 /* Final fallback position - use the X CUT_BUFFER0 store */ | |
1924 | 2299 yank_cut_buffer0(dpy, cbd); |
7 | 2300 } |
2301 | |
2302 static Boolean | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2303 clip_x11_convert_selection_cb( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2304 Widget w UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2305 Atom *sel_atom, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2306 Atom *target, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2307 Atom *type, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2308 XtPointer *value, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2309 long_u *length, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2310 int *format) |
7 | 2311 { |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2312 static char_u *save_result = NULL; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2313 static long_u save_length = 0; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2314 char_u *string; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2315 int motion_type; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2316 VimClipboard *cbd; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2317 int i; |
7 | 2318 |
2319 if (*sel_atom == clip_plus.sel_atom) | |
2320 cbd = &clip_plus; | |
2321 else | |
2322 cbd = &clip_star; | |
2323 | |
2324 if (!cbd->owned) | |
2325 return False; /* Shouldn't ever happen */ | |
2326 | |
2327 /* requestor wants to know what target types we support */ | |
2328 if (*target == targets_atom) | |
2329 { | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2330 static Atom array[7]; |
7 | 2331 |
2332 *value = (XtPointer)array; | |
2333 i = 0; | |
2334 array[i++] = targets_atom; | |
2335 array[i++] = vimenc_atom; | |
2336 array[i++] = vim_atom; | |
3346 | 2337 if (enc_utf8) |
2338 array[i++] = utf8_atom; | |
2339 array[i++] = XA_STRING; | |
7 | 2340 array[i++] = text_atom; |
2341 array[i++] = compound_text_atom; | |
3346 | 2342 |
7 | 2343 *type = XA_ATOM; |
2344 /* This used to be: *format = sizeof(Atom) * 8; but that caused | |
2345 * crashes on 64 bit machines. (Peter Derr) */ | |
2346 *format = 32; | |
2347 *length = i; | |
2348 return True; | |
2349 } | |
2350 | |
2351 if ( *target != XA_STRING | |
2352 && *target != vimenc_atom | |
5956 | 2353 && (*target != utf8_atom || !enc_utf8) |
7 | 2354 && *target != vim_atom |
2355 && *target != text_atom | |
2356 && *target != compound_text_atom) | |
2357 return False; | |
2358 | |
2359 clip_get_selection(cbd); | |
2360 motion_type = clip_convert_selection(&string, length, cbd); | |
2361 if (motion_type < 0) | |
2362 return False; | |
2363 | |
2364 /* For our own format, the first byte contains the motion type */ | |
2365 if (*target == vim_atom) | |
2366 (*length)++; | |
2367 | |
2368 /* Our own format with encoding: motion 'encoding' NUL text */ | |
2369 if (*target == vimenc_atom) | |
2370 *length += STRLEN(p_enc) + 2; | |
2371 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2372 if (save_length < *length || save_length / 2 >= *length) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2373 *value = XtRealloc((char *)save_result, (Cardinal)*length + 1); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2374 else |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2375 *value = save_result; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2376 if (*value == NULL) |
7 | 2377 { |
2378 vim_free(string); | |
2379 return False; | |
2380 } | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2381 save_result = (char_u *)*value; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2382 save_length = *length; |
7 | 2383 |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2384 if (*target == XA_STRING || (*target == utf8_atom && enc_utf8)) |
7 | 2385 { |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2386 mch_memmove(save_result, string, (size_t)(*length)); |
3346 | 2387 *type = *target; |
7 | 2388 } |
3346 | 2389 else if (*target == compound_text_atom || *target == text_atom) |
7 | 2390 { |
2391 XTextProperty text_prop; | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2392 char *string_nt = (char *)save_result; |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2393 int conv_result; |
7 | 2394 |
2395 /* create NUL terminated string which XmbTextListToTextProperty wants */ | |
2396 mch_memmove(string_nt, string, (size_t)*length); | |
2397 string_nt[*length] = NUL; | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2398 conv_result = XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt, |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2399 1, XCompoundTextStyle, &text_prop); |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2400 if (conv_result != Success) |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2401 { |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2402 vim_free(string); |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2403 return False; |
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4272
diff
changeset
|
2404 } |
7 | 2405 *value = (XtPointer)(text_prop.value); /* from plain text */ |
2406 *length = text_prop.nitems; | |
2407 *type = compound_text_atom; | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2408 XtFree((char *)save_result); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2409 save_result = (char_u *)*value; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2410 save_length = *length; |
7 | 2411 } |
2412 else if (*target == vimenc_atom) | |
2413 { | |
2414 int l = STRLEN(p_enc); | |
2415 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2416 save_result[0] = motion_type; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2417 STRCPY(save_result + 1, p_enc); |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2418 mch_memmove(save_result + l + 2, string, (size_t)(*length - l - 2)); |
7 | 2419 *type = vimenc_atom; |
2420 } | |
2421 else | |
2422 { | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2423 save_result[0] = motion_type; |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2424 mch_memmove(save_result + 1, string, (size_t)(*length - 1)); |
7 | 2425 *type = vim_atom; |
2426 } | |
2427 *format = 8; /* 8 bits per char */ | |
2428 vim_free(string); | |
2429 return True; | |
2430 } | |
2431 | |
2432 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2433 clip_x11_lose_ownership_cb(Widget w UNUSED, Atom *sel_atom) |
7 | 2434 { |
2435 if (*sel_atom == clip_plus.sel_atom) | |
2436 clip_lose_selection(&clip_plus); | |
2437 else | |
2438 clip_lose_selection(&clip_star); | |
2439 } | |
2440 | |
2441 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2442 clip_x11_lose_selection(Widget myShell, VimClipboard *cbd) |
7 | 2443 { |
4209 | 2444 XtDisownSelection(myShell, cbd->sel_atom, |
2445 XtLastTimestampProcessed(XtDisplay(myShell))); | |
7 | 2446 } |
2447 | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2448 static void |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2449 clip_x11_notify_cb(Widget w UNUSED, Atom *sel_atom UNUSED, Atom *target UNUSED) |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2450 { |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2451 /* To prevent automatically freeing the selection value. */ |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2452 } |
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2453 |
7 | 2454 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2455 clip_x11_own_selection(Widget myShell, VimClipboard *cbd) |
7 | 2456 { |
2586 | 2457 /* When using the GUI we have proper timestamps, use the one of the last |
2458 * event. When in the console we don't get events (the terminal gets | |
2459 * them), Get the time by a zero-length append, clip_x11_timestamp_cb will | |
2460 * be called with the current timestamp. */ | |
2461 #ifdef FEAT_GUI | |
2462 if (gui.in_use) | |
2463 { | |
2464 if (XtOwnSelection(myShell, cbd->sel_atom, | |
2465 XtLastTimestampProcessed(XtDisplay(myShell)), | |
2466 clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb, | |
11709
c3227699ad4d
patch 8.0.0737: crash when X11 selection is very big
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
2467 clip_x11_notify_cb) == False) |
3312 | 2468 return FAIL; |
2586 | 2469 } |
2470 else | |
2471 #endif | |
2472 { | |
2473 if (!XChangeProperty(XtDisplay(myShell), XtWindow(myShell), | |
2474 cbd->sel_atom, timestamp_atom, 32, PropModeAppend, NULL, 0)) | |
3312 | 2475 return FAIL; |
2586 | 2476 } |
2270
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2477 /* Flush is required in a terminal as nothing else is doing it. */ |
917fff7bc09d
Fixes for time in clipboard request. Also fix ownership. (David Fries)
Bram Moolenaar <bram@vim.org>
parents:
2250
diff
changeset
|
2478 XFlush(XtDisplay(myShell)); |
7 | 2479 return OK; |
2480 } | |
2481 | |
2482 /* | |
2483 * Send the current selection to the clipboard. Do nothing for X because we | |
2484 * will fill in the selection only when requested by another app. | |
2485 */ | |
2486 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2487 clip_x11_set_selection(VimClipboard *cbd UNUSED) |
7 | 2488 { |
2489 } | |
4209 | 2490 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2491 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) && defined(USE_SYSTEM)) \ |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2492 || defined(PROTO) |
4209 | 2493 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2494 clip_x11_owner_exists(VimClipboard *cbd) |
4209 | 2495 { |
2496 return XGetSelectionOwner(X_DISPLAY, cbd->sel_atom) != None; | |
2497 } | |
7 | 2498 #endif |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2499 #endif |
7 | 2500 |
1924 | 2501 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) \ |
2502 || defined(FEAT_GUI_GTK) || defined(PROTO) | |
2503 /* | |
2504 * Get the contents of the X CUT_BUFFER0 and put it in "cbd". | |
2505 */ | |
2506 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2507 yank_cut_buffer0(Display *dpy, VimClipboard *cbd) |
1924 | 2508 { |
2509 int nbytes = 0; | |
2510 char_u *buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0); | |
2511 | |
2512 if (nbytes > 0) | |
2513 { | |
2514 int done = FALSE; | |
2515 | |
2516 /* CUT_BUFFER0 is supposed to be always latin1. Convert to 'enc' when | |
2517 * using a multi-byte encoding. Conversion between two 8-bit | |
2518 * character sets usually fails and the text might actually be in | |
2519 * 'enc' anyway. */ | |
2520 if (has_mbyte) | |
2521 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1961
diff
changeset
|
2522 char_u *conv_buf; |
1924 | 2523 vimconv_T vc; |
2524 | |
2525 vc.vc_type = CONV_NONE; | |
2526 if (convert_setup(&vc, (char_u *)"latin1", p_enc) == OK) | |
2527 { | |
2528 conv_buf = string_convert(&vc, buffer, &nbytes); | |
2529 if (conv_buf != NULL) | |
2530 { | |
2531 clip_yank_selection(MCHAR, conv_buf, (long)nbytes, cbd); | |
2532 vim_free(conv_buf); | |
2533 done = TRUE; | |
2534 } | |
2535 convert_setup(&vc, NULL, NULL); | |
2536 } | |
2537 } | |
2538 if (!done) /* use the text without conversion */ | |
2539 clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd); | |
2540 XFree((void *)buffer); | |
2541 if (p_verbose > 0) | |
2542 { | |
2543 verbose_enter(); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
2544 verb_msg(_("Used CUT_BUFFER0 instead of empty selection")); |
1924 | 2545 verbose_leave(); |
2546 } | |
2547 } | |
2548 } | |
2549 #endif | |
2550 | |
7 | 2551 #if defined(FEAT_MOUSE) || defined(PROTO) |
2552 | |
2553 /* | |
2554 * Move the cursor to the specified row and column on the screen. | |
1226 | 2555 * Change current window if necessary. Returns an integer with the |
7 | 2556 * CURSOR_MOVED bit set if the cursor has moved or unset otherwise. |
2557 * | |
2558 * The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column. | |
2559 * The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column. | |
2560 * | |
2561 * If flags has MOUSE_FOCUS, then the current window will not be changed, and | |
2562 * if the mouse is outside the window then the text will scroll, or if the | |
2563 * mouse was previously on a status line, then the status line may be dragged. | |
2564 * | |
2565 * If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the | |
2566 * cursor is moved unless the cursor was on a status line. | |
2567 * This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or | |
2568 * IN_SEP_LINE depending on where the cursor was clicked. | |
2569 * | |
2570 * If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless | |
2571 * the mouse is on the status line of the same window. | |
2572 * | |
2573 * If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since | |
2574 * the last call. | |
2575 * | |
2576 * If flags has MOUSE_SETPOS, nothing is done, only the current position is | |
2577 * remembered. | |
2578 */ | |
2579 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2580 jump_to_mouse( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2581 int flags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2582 int *inclusive, /* used for inclusive operator, can be NULL */ |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2583 int which_button) /* MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE */ |
7 | 2584 { |
2585 static int on_status_line = 0; /* #lines below bottom of window */ | |
2586 static int on_sep_line = 0; /* on separator right of window */ | |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2587 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2588 static int in_winbar = FALSE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2589 #endif |
7 | 2590 static int prev_row = -1; |
2591 static int prev_col = -1; | |
2592 static win_T *dragwin = NULL; /* window being dragged */ | |
2593 static int did_drag = FALSE; /* drag was noticed */ | |
2594 | |
2595 win_T *wp, *old_curwin; | |
2596 pos_T old_cursor; | |
2597 int count; | |
2598 int first; | |
2599 int row = mouse_row; | |
2600 int col = mouse_col; | |
2601 #ifdef FEAT_FOLDING | |
2602 int mouse_char; | |
2603 #endif | |
2604 | |
2605 mouse_past_bottom = FALSE; | |
2606 mouse_past_eol = FALSE; | |
2607 | |
2608 if (flags & MOUSE_RELEASED) | |
2609 { | |
2610 /* On button release we may change window focus if positioned on a | |
2611 * status line and no dragging happened. */ | |
2612 if (dragwin != NULL && !did_drag) | |
2613 flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE); | |
2614 dragwin = NULL; | |
2615 did_drag = FALSE; | |
2616 } | |
2617 | |
2618 if ((flags & MOUSE_DID_MOVE) | |
2619 && prev_row == mouse_row | |
2620 && prev_col == mouse_col) | |
2621 { | |
2622 retnomove: | |
1226 | 2623 /* before moving the cursor for a left click which is NOT in a status |
7 | 2624 * line, stop Visual mode */ |
2625 if (on_status_line) | |
2626 return IN_STATUS_LINE; | |
2627 if (on_sep_line) | |
2628 return IN_SEP_LINE; | |
12831
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2629 #ifdef FEAT_MENU |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2630 if (in_winbar) |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2631 { |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2632 /* A quick second click may arrive as a double-click, but we use it |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2633 * as a second click in the WinBar. */ |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2634 if ((mod_mask & MOD_MASK_MULTI_CLICK) && !(flags & MOUSE_RELEASED)) |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2635 { |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2636 wp = mouse_find_win(&row, &col); |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2637 if (wp == NULL) |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2638 return IN_UNKNOWN; |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2639 winbar_click(wp, col); |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2640 } |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2641 return IN_OTHER_WIN | MOUSE_WINBAR; |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2642 } |
5cb08ec9d4cf
patch 8.0.1292: quick clicks in the WinBar start Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
2643 #endif |
7 | 2644 if (flags & MOUSE_MAY_STOP_VIS) |
2645 { | |
2646 end_visual_mode(); | |
2647 redraw_curbuf_later(INVERTED); /* delete the inversion */ | |
2648 } | |
2649 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD) | |
2650 /* Continue a modeless selection in another window. */ | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2651 if (cmdwin_type != 0 && row < curwin->w_winrow) |
7 | 2652 return IN_OTHER_WIN; |
2653 #endif | |
2654 return IN_BUFFER; | |
2655 } | |
2656 | |
2657 prev_row = mouse_row; | |
2658 prev_col = mouse_col; | |
2659 | |
2660 if (flags & MOUSE_SETPOS) | |
2661 goto retnomove; /* ugly goto... */ | |
2662 | |
2663 #ifdef FEAT_FOLDING | |
2664 /* Remember the character under the mouse, it might be a '-' or '+' in the | |
2665 * fold column. */ | |
534 | 2666 if (row >= 0 && row < Rows && col >= 0 && col <= Columns |
2667 && ScreenLines != NULL) | |
7 | 2668 mouse_char = ScreenLines[LineOffset[row] + col]; |
2669 else | |
2670 mouse_char = ' '; | |
2671 #endif | |
2672 | |
2673 old_curwin = curwin; | |
2674 old_cursor = curwin->w_cursor; | |
2675 | |
2676 if (!(flags & MOUSE_FOCUS)) | |
2677 { | |
2678 if (row < 0 || col < 0) /* check if it makes sense */ | |
2679 return IN_UNKNOWN; | |
2680 | |
2681 /* find the window where the row is in */ | |
2682 wp = mouse_find_win(&row, &col); | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
2683 if (wp == NULL) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
2684 return IN_UNKNOWN; |
7 | 2685 dragwin = NULL; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2686 |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2687 #ifdef FEAT_MENU |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2688 if (row == -1) |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2689 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2690 /* A click in the window toolbar does not enter another window or |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2691 * change Visual highlighting. */ |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2692 winbar_click(wp, col); |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2693 in_winbar = TRUE; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2694 return IN_OTHER_WIN | MOUSE_WINBAR; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2695 } |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2696 in_winbar = FALSE; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2697 #endif |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2698 |
7 | 2699 /* |
2700 * winpos and height may change in win_enter()! | |
2701 */ | |
2702 if (row >= wp->w_height) /* In (or below) status line */ | |
2703 { | |
2704 on_status_line = row - wp->w_height + 1; | |
2705 dragwin = wp; | |
2706 } | |
2707 else | |
2708 on_status_line = 0; | |
2709 if (col >= wp->w_width) /* In separator line */ | |
2710 { | |
2711 on_sep_line = col - wp->w_width + 1; | |
2712 dragwin = wp; | |
2713 } | |
2714 else | |
2715 on_sep_line = 0; | |
2716 | |
2717 /* The rightmost character of the status line might be a vertical | |
2718 * separator character if there is no connecting window to the right. */ | |
2719 if (on_status_line && on_sep_line) | |
2720 { | |
2721 if (stl_connected(wp)) | |
2722 on_sep_line = 0; | |
2723 else | |
2724 on_status_line = 0; | |
2725 } | |
2726 | |
2727 /* Before jumping to another buffer, or moving the cursor for a left | |
2728 * click, stop Visual mode. */ | |
2729 if (VIsual_active | |
2730 && (wp->w_buffer != curwin->w_buffer | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12337
diff
changeset
|
2731 || (!on_status_line && !on_sep_line |
5735 | 2732 #ifdef FEAT_FOLDING |
7 | 2733 && ( |
5735 | 2734 # ifdef FEAT_RIGHTLEFT |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2735 wp->w_p_rl ? col < wp->w_width - wp->w_p_fdc : |
5735 | 2736 # endif |
7 | 2737 col >= wp->w_p_fdc |
5735 | 2738 # ifdef FEAT_CMDWIN |
7 | 2739 + (cmdwin_type == 0 && wp == curwin ? 0 : 1) |
5735 | 2740 # endif |
7 | 2741 ) |
5735 | 2742 #endif |
7 | 2743 && (flags & MOUSE_MAY_STOP_VIS)))) |
2744 { | |
2745 end_visual_mode(); | |
2746 redraw_curbuf_later(INVERTED); /* delete the inversion */ | |
2747 } | |
2748 #ifdef FEAT_CMDWIN | |
2749 if (cmdwin_type != 0 && wp != curwin) | |
2750 { | |
2751 /* A click outside the command-line window: Use modeless | |
2102
907cf09fbb32
updated for version 7.2.385
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
2752 * selection if possible. Allow dragging the status lines. */ |
7 | 2753 on_sep_line = 0; |
2754 # ifdef FEAT_CLIPBOARD | |
2755 if (on_status_line) | |
2756 return IN_STATUS_LINE; | |
2757 return IN_OTHER_WIN; | |
2758 # else | |
2759 row = 0; | |
2760 col += wp->w_wincol; | |
2761 wp = curwin; | |
2762 # endif | |
2763 } | |
2764 #endif | |
2765 /* Only change window focus when not clicking on or dragging the | |
2766 * status line. Do change focus when releasing the mouse button | |
2767 * (MOUSE_FOCUS was set above if we dragged first). */ | |
2768 if (dragwin == NULL || (flags & MOUSE_RELEASED)) | |
2769 win_enter(wp, TRUE); /* can make wp invalid! */ | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2770 |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2771 if (curwin != old_curwin) |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2772 { |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12337
diff
changeset
|
2773 #ifdef CHECK_DOUBLE_CLICK |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2774 /* set topline, to be able to check for double click ourselves */ |
7 | 2775 set_mouse_topline(curwin); |
2776 #endif | |
13448
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2777 #ifdef FEAT_TERMINAL |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2778 /* when entering a terminal window may change state */ |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2779 term_win_entered(); |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2780 #endif |
a62b0bbc8834
patch 8.0.1598: cannot select text in a terminal with the mouse
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
2781 } |
7 | 2782 if (on_status_line) /* In (or below) status line */ |
2783 { | |
2784 /* Don't use start_arrow() if we're in the same window */ | |
2785 if (curwin == old_curwin) | |
2786 return IN_STATUS_LINE; | |
2787 else | |
2788 return IN_STATUS_LINE | CURSOR_MOVED; | |
2789 } | |
2790 if (on_sep_line) /* In (or below) status line */ | |
2791 { | |
2792 /* Don't use start_arrow() if we're in the same window */ | |
2793 if (curwin == old_curwin) | |
2794 return IN_SEP_LINE; | |
2795 else | |
2796 return IN_SEP_LINE | CURSOR_MOVED; | |
2797 } | |
2798 | |
2799 curwin->w_cursor.lnum = curwin->w_topline; | |
2800 #ifdef FEAT_GUI | |
2801 /* remember topline, needed for double click */ | |
2802 gui_prev_topline = curwin->w_topline; | |
2803 # ifdef FEAT_DIFF | |
2804 gui_prev_topfill = curwin->w_topfill; | |
2805 # endif | |
2806 #endif | |
2807 } | |
2808 else if (on_status_line && which_button == MOUSE_LEFT) | |
2809 { | |
2810 if (dragwin != NULL) | |
2811 { | |
2812 /* Drag the status line */ | |
2813 count = row - dragwin->w_winrow - dragwin->w_height + 1 | |
2814 - on_status_line; | |
2815 win_drag_status_line(dragwin, count); | |
2816 did_drag |= count; | |
2817 } | |
2818 return IN_STATUS_LINE; /* Cursor didn't move */ | |
2819 } | |
2820 else if (on_sep_line && which_button == MOUSE_LEFT) | |
2821 { | |
2822 if (dragwin != NULL) | |
2823 { | |
2824 /* Drag the separator column */ | |
2825 count = col - dragwin->w_wincol - dragwin->w_width + 1 | |
2826 - on_sep_line; | |
2827 win_drag_vsep_line(dragwin, count); | |
2828 did_drag |= count; | |
2829 } | |
2830 return IN_SEP_LINE; /* Cursor didn't move */ | |
2831 } | |
12519
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2832 #ifdef FEAT_MENU |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2833 else if (in_winbar) |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2834 { |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2835 /* After a click on the window toolbar don't start Visual mode. */ |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2836 return IN_OTHER_WIN | MOUSE_WINBAR; |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2837 } |
f62696bd1a9f
patch 8.0.1138: click in window toolbar starts Visual mode
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
2838 #endif |
7 | 2839 else /* keep_window_focus must be TRUE */ |
2840 { | |
2841 /* before moving the cursor for a left click, stop Visual mode */ | |
2842 if (flags & MOUSE_MAY_STOP_VIS) | |
2843 { | |
2844 end_visual_mode(); | |
2845 redraw_curbuf_later(INVERTED); /* delete the inversion */ | |
2846 } | |
2847 | |
2848 #if defined(FEAT_CMDWIN) && defined(FEAT_CLIPBOARD) | |
2849 /* Continue a modeless selection in another window. */ | |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
2850 if (cmdwin_type != 0 && row < curwin->w_winrow) |
7 | 2851 return IN_OTHER_WIN; |
2852 #endif | |
2853 | |
2854 row -= W_WINROW(curwin); | |
12513
3ca08bf99396
patch 8.0.1135: W_WINCOL() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12487
diff
changeset
|
2855 col -= curwin->w_wincol; |
7 | 2856 |
2857 /* | |
2858 * When clicking beyond the end of the window, scroll the screen. | |
2859 * Scroll by however many rows outside the window we are. | |
2860 */ | |
2861 if (row < 0) | |
2862 { | |
2863 count = 0; | |
2864 for (first = TRUE; curwin->w_topline > 1; ) | |
2865 { | |
2866 #ifdef FEAT_DIFF | |
2867 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) | |
2868 ++count; | |
2869 else | |
2870 #endif | |
2871 count += plines(curwin->w_topline - 1); | |
2872 if (!first && count > -row) | |
2873 break; | |
2874 first = FALSE; | |
2875 #ifdef FEAT_FOLDING | |
7009 | 2876 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
7 | 2877 #endif |
2878 #ifdef FEAT_DIFF | |
2879 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)) | |
2880 ++curwin->w_topfill; | |
2881 else | |
2882 #endif | |
2883 { | |
2884 --curwin->w_topline; | |
2885 #ifdef FEAT_DIFF | |
2886 curwin->w_topfill = 0; | |
2887 #endif | |
2888 } | |
2889 } | |
2890 #ifdef FEAT_DIFF | |
2891 check_topfill(curwin, FALSE); | |
2892 #endif | |
2893 curwin->w_valid &= | |
2894 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2895 redraw_later(VALID); | |
2896 row = 0; | |
2897 } | |
2898 else if (row >= curwin->w_height) | |
2899 { | |
2900 count = 0; | |
2901 for (first = TRUE; curwin->w_topline < curbuf->b_ml.ml_line_count; ) | |
2902 { | |
2903 #ifdef FEAT_DIFF | |
2904 if (curwin->w_topfill > 0) | |
2905 ++count; | |
2906 else | |
2907 #endif | |
2908 count += plines(curwin->w_topline); | |
2909 if (!first && count > row - curwin->w_height + 1) | |
2910 break; | |
2911 first = FALSE; | |
2912 #ifdef FEAT_FOLDING | |
2913 if (hasFolding(curwin->w_topline, NULL, &curwin->w_topline) | |
2914 && curwin->w_topline == curbuf->b_ml.ml_line_count) | |
2915 break; | |
2916 #endif | |
2917 #ifdef FEAT_DIFF | |
2918 if (curwin->w_topfill > 0) | |
2919 --curwin->w_topfill; | |
2920 else | |
2921 #endif | |
2922 { | |
2923 ++curwin->w_topline; | |
2924 #ifdef FEAT_DIFF | |
2925 curwin->w_topfill = | |
2926 diff_check_fill(curwin, curwin->w_topline); | |
2927 #endif | |
2928 } | |
2929 } | |
2930 #ifdef FEAT_DIFF | |
2931 check_topfill(curwin, FALSE); | |
2932 #endif | |
2933 redraw_later(VALID); | |
2934 curwin->w_valid &= | |
2935 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2936 row = curwin->w_height - 1; | |
2937 } | |
2938 else if (row == 0) | |
2939 { | |
2940 /* When dragging the mouse, while the text has been scrolled up as | |
2941 * far as it goes, moving the mouse in the top line should scroll | |
2942 * the text down (done later when recomputing w_topline). */ | |
1164 | 2943 if (mouse_dragging > 0 |
7 | 2944 && curwin->w_cursor.lnum |
2945 == curwin->w_buffer->b_ml.ml_line_count | |
2946 && curwin->w_cursor.lnum == curwin->w_topline) | |
2947 curwin->w_valid &= ~(VALID_TOPLINE); | |
2948 } | |
2949 } | |
2950 | |
2951 #ifdef FEAT_FOLDING | |
2952 /* Check for position outside of the fold column. */ | |
2953 if ( | |
2954 # ifdef FEAT_RIGHTLEFT | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
2955 curwin->w_p_rl ? col < curwin->w_width - curwin->w_p_fdc : |
7 | 2956 # endif |
2957 col >= curwin->w_p_fdc | |
2958 # ifdef FEAT_CMDWIN | |
2959 + (cmdwin_type == 0 ? 0 : 1) | |
2960 # endif | |
2961 ) | |
2962 mouse_char = ' '; | |
2963 #endif | |
2964 | |
2965 /* compute the position in the buffer line from the posn on the screen */ | |
2966 if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum)) | |
2967 mouse_past_bottom = TRUE; | |
2968 | |
2969 /* Start Visual mode before coladvance(), for when 'sel' != "old" */ | |
2970 if ((flags & MOUSE_MAY_VIS) && !VIsual_active) | |
2971 { | |
2972 check_visual_highlight(); | |
2973 VIsual = old_cursor; | |
2974 VIsual_active = TRUE; | |
2975 VIsual_reselect = TRUE; | |
2976 /* if 'selectmode' contains "mouse", start Select mode */ | |
2977 may_start_select('o'); | |
2978 setmouse(); | |
642 | 2979 if (p_smd && msg_silent == 0) |
7 | 2980 redraw_cmdline = TRUE; /* show visual mode later */ |
2981 } | |
2982 | |
2983 curwin->w_curswant = col; | |
2984 curwin->w_set_curswant = FALSE; /* May still have been TRUE */ | |
2985 if (coladvance(col) == FAIL) /* Mouse click beyond end of line */ | |
2986 { | |
2987 if (inclusive != NULL) | |
2988 *inclusive = TRUE; | |
2989 mouse_past_eol = TRUE; | |
2990 } | |
2991 else if (inclusive != NULL) | |
2992 *inclusive = FALSE; | |
2993 | |
2994 count = IN_BUFFER; | |
2995 if (curwin != old_curwin || curwin->w_cursor.lnum != old_cursor.lnum | |
2996 || curwin->w_cursor.col != old_cursor.col) | |
2997 count |= CURSOR_MOVED; /* Cursor has moved */ | |
2998 | |
2999 #ifdef FEAT_FOLDING | |
3000 if (mouse_char == '+') | |
3001 count |= MOUSE_FOLD_OPEN; | |
3002 else if (mouse_char != ' ') | |
3003 count |= MOUSE_FOLD_CLOSE; | |
3004 #endif | |
3005 | |
3006 return count; | |
3007 } | |
3008 | |
3009 /* | |
3010 * Compute the position in the buffer line from the posn on the screen in | |
3011 * window "win". | |
3012 * Returns TRUE if the position is below the last line. | |
3013 */ | |
3014 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3015 mouse_comp_pos( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3016 win_T *win, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3017 int *rowp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3018 int *colp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3019 linenr_T *lnump) |
7 | 3020 { |
3021 int col = *colp; | |
3022 int row = *rowp; | |
3023 linenr_T lnum; | |
3024 int retval = FALSE; | |
3025 int off; | |
3026 int count; | |
3027 | |
3028 #ifdef FEAT_RIGHTLEFT | |
3029 if (win->w_p_rl) | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3030 col = win->w_width - 1 - col; |
7 | 3031 #endif |
3032 | |
3033 lnum = win->w_topline; | |
3034 | |
3035 while (row > 0) | |
3036 { | |
3037 #ifdef FEAT_DIFF | |
3038 /* Don't include filler lines in "count" */ | |
237 | 3039 if (win->w_p_diff |
3040 # ifdef FEAT_FOLDING | |
3041 && !hasFoldingWin(win, lnum, NULL, NULL, TRUE, NULL) | |
3042 # endif | |
3043 ) | |
7 | 3044 { |
3045 if (lnum == win->w_topline) | |
3046 row -= win->w_topfill; | |
3047 else | |
3048 row -= diff_check_fill(win, lnum); | |
3049 count = plines_win_nofill(win, lnum, TRUE); | |
3050 } | |
3051 else | |
3052 #endif | |
3053 count = plines_win(win, lnum, TRUE); | |
3054 if (count > row) | |
3055 break; /* Position is in this buffer line. */ | |
3056 #ifdef FEAT_FOLDING | |
3057 (void)hasFoldingWin(win, lnum, NULL, &lnum, TRUE, NULL); | |
3058 #endif | |
3059 if (lnum == win->w_buffer->b_ml.ml_line_count) | |
3060 { | |
3061 retval = TRUE; | |
3062 break; /* past end of file */ | |
3063 } | |
3064 row -= count; | |
3065 ++lnum; | |
3066 } | |
3067 | |
3068 if (!retval) | |
3069 { | |
3070 /* Compute the column without wrapping. */ | |
3071 off = win_col_off(win) - win_col_off2(win); | |
3072 if (col < off) | |
3073 col = off; | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12513
diff
changeset
|
3074 col += row * (win->w_width - off); |
7 | 3075 /* add skip column (for long wrapping line) */ |
3076 col += win->w_skipcol; | |
3077 } | |
3078 | |
3079 if (!win->w_p_wrap) | |
3080 col += win->w_leftcol; | |
3081 | |
3082 /* skip line number and fold column in front of the line */ | |
3083 col -= win_col_off(win); | |
3084 if (col < 0) | |
3085 { | |
3086 #ifdef FEAT_NETBEANS_INTG | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2270
diff
changeset
|
3087 netbeans_gutter_click(lnum); |
7 | 3088 #endif |
3089 col = 0; | |
3090 } | |
3091 | |
3092 *colp = col; | |
3093 *rowp = row; | |
3094 *lnump = lnum; | |
3095 return retval; | |
3096 } | |
3097 | |
3098 /* | |
3099 * Find the window at screen position "*rowp" and "*colp". The positions are | |
3100 * updated to become relative to the top-left of the window. | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3101 * Returns NULL when something is wrong. |
7 | 3102 */ |
3103 win_T * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3104 mouse_find_win(int *rowp, int *colp UNUSED) |
7 | 3105 { |
3106 frame_T *fp; | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3107 win_T *wp; |
7 | 3108 |
3109 fp = topframe; | |
667 | 3110 *rowp -= firstwin->w_winrow; |
7 | 3111 for (;;) |
3112 { | |
3113 if (fp->fr_layout == FR_LEAF) | |
3114 break; | |
3115 if (fp->fr_layout == FR_ROW) | |
3116 { | |
3117 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) | |
3118 { | |
3119 if (*colp < fp->fr_width) | |
3120 break; | |
3121 *colp -= fp->fr_width; | |
3122 } | |
3123 } | |
3124 else /* fr_layout == FR_COL */ | |
3125 { | |
3126 for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) | |
3127 { | |
3128 if (*rowp < fp->fr_height) | |
3129 break; | |
3130 *rowp -= fp->fr_height; | |
3131 } | |
3132 } | |
3133 } | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3134 /* When using a timer that closes a window the window might not actually |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3135 * exist. */ |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3136 FOR_ALL_WINDOWS(wp) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3137 if (wp == fp->fr_win) |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3138 { |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3139 #ifdef FEAT_MENU |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3140 *rowp -= wp->w_winbar_height; |
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3141 #endif |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3142 return wp; |
12487
3f16cf18386c
patch 8.0.1123: cannot define a toolbar for a window
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
3143 } |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3144 return NULL; |
7 | 3145 } |
3146 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3147 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MAC) \ |
7 | 3148 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
13371
1a3f5759b61e
patch 8.0.1559: build failure without GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3149 || defined(FEAT_GUI_PHOTON) || defined(FEAT_TERM_POPUP_MENU) \ |
1a3f5759b61e
patch 8.0.1559: build failure without GUI
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
3150 || defined(PROTO) |
7 | 3151 /* |
3152 * Translate window coordinates to buffer position without any side effects | |
3153 */ | |
3154 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3155 get_fpos_of_mouse(pos_T *mpos) |
7 | 3156 { |
3157 win_T *wp; | |
3158 int row = mouse_row; | |
3159 int col = mouse_col; | |
3160 | |
3161 if (row < 0 || col < 0) /* check if it makes sense */ | |
3162 return IN_UNKNOWN; | |
3163 | |
3164 /* find the window where the row is in */ | |
3165 wp = mouse_find_win(&row, &col); | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3166 if (wp == NULL) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12076
diff
changeset
|
3167 return IN_UNKNOWN; |
7 | 3168 /* |
3169 * winpos and height may change in win_enter()! | |
3170 */ | |
3171 if (row >= wp->w_height) /* In (or below) status line */ | |
3172 return IN_STATUS_LINE; | |
3173 if (col >= wp->w_width) /* In vertical separator line */ | |
3174 return IN_SEP_LINE; | |
3175 | |
3176 if (wp != curwin) | |
3177 return IN_UNKNOWN; | |
3178 | |
3179 /* compute the position in the buffer line from the posn on the screen */ | |
3180 if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum)) | |
3181 return IN_STATUS_LINE; /* past bottom */ | |
3182 | |
3183 mpos->col = vcol2col(wp, mpos->lnum, col); | |
3184 | |
3185 if (mpos->col > 0) | |
3186 --mpos->col; | |
2445
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
3187 #ifdef FEAT_VIRTUALEDIT |
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
3188 mpos->coladd = 0; |
04dae202d316
Fixes for coverity warnings.
Bram Moolenaar <bram@vim.org>
parents:
2428
diff
changeset
|
3189 #endif |
7 | 3190 return IN_BUFFER; |
3191 } | |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12831
diff
changeset
|
3192 #endif |
7 | 3193 |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12831
diff
changeset
|
3194 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MAC) \ |
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12831
diff
changeset
|
3195 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \ |
13373
0802633a0b2d
patch 8.0.1560: build failure without GUI on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13371
diff
changeset
|
3196 || defined(FEAT_GUI_PHOTON) || defined(FEAT_BEVAL) \ |
0802633a0b2d
patch 8.0.1560: build failure without GUI on MS-Windows
Christian Brabandt <cb@256bit.org>
parents:
13371
diff
changeset
|
3197 || defined(FEAT_TERM_POPUP_MENU) || defined(PROTO) |
7 | 3198 /* |
3199 * Convert a virtual (screen) column to a character column. | |
3200 * The first column is one. | |
3201 */ | |
3202 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3203 vcol2col(win_T *wp, linenr_T lnum, int vcol) |
7 | 3204 { |
3205 /* try to advance to the specified column */ | |
3206 int count = 0; | |
3207 char_u *ptr; | |
5995 | 3208 char_u *line; |
7 | 3209 |
5995 | 3210 line = ptr = ml_get_buf(wp->w_buffer, lnum, FALSE); |
3877 | 3211 while (count < vcol && *ptr != NUL) |
7 | 3212 { |
5995 | 3213 count += win_lbr_chartabsize(wp, line, ptr, count, NULL); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3214 MB_PTR_ADV(ptr); |
7 | 3215 } |
5995 | 3216 return (int)(ptr - line); |
7 | 3217 } |
3218 #endif | |
3219 | |
3220 #endif /* FEAT_MOUSE */ | |
3221 | |
3222 #if defined(FEAT_GUI) || defined(WIN3264) || defined(PROTO) | |
3223 /* | |
3224 * Called when focus changed. Used for the GUI or for systems where this can | |
3225 * be done in the console (Win32). | |
3226 */ | |
3227 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3228 ui_focus_change( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3229 int in_focus) /* TRUE if focus gained. */ |
7 | 3230 { |
3231 static time_t last_time = (time_t)0; | |
3232 int need_redraw = FALSE; | |
3233 | |
3234 /* When activated: Check if any file was modified outside of Vim. | |
3235 * Only do this when not done within the last two seconds (could get | |
3236 * several events in a row). */ | |
3237 if (in_focus && last_time + 2 < time(NULL)) | |
3238 { | |
3239 need_redraw = check_timestamps( | |
3240 # ifdef FEAT_GUI | |
3241 gui.in_use | |
3242 # else | |
3243 FALSE | |
3244 # endif | |
3245 ); | |
3246 last_time = time(NULL); | |
3247 } | |
3248 | |
3249 /* | |
3250 * Fire the focus gained/lost autocommand. | |
3251 */ | |
3252 need_redraw |= apply_autocmds(in_focus ? EVENT_FOCUSGAINED | |
3253 : EVENT_FOCUSLOST, NULL, NULL, FALSE, curbuf); | |
3254 | |
3255 if (need_redraw) | |
3256 { | |
3257 /* Something was executed, make sure the cursor is put back where it | |
3258 * belongs. */ | |
3259 need_wait_return = FALSE; | |
3260 | |
3261 if (State & CMDLINE) | |
3262 redrawcmdline(); | |
3263 else if (State == HITRETURN || State == SETWSIZE || State == ASKMORE | |
3264 || State == EXTERNCMD || State == CONFIRM || exmode_active) | |
3265 repeat_message(); | |
3266 else if ((State & NORMAL) || (State & INSERT)) | |
3267 { | |
3268 if (must_redraw != 0) | |
3269 update_screen(0); | |
3270 setcursor(); | |
3271 } | |
3272 cursor_on(); /* redrawing may have switched it off */ | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
3273 out_flush_cursor(FALSE, TRUE); |
7 | 3274 # ifdef FEAT_GUI |
3275 if (gui.in_use) | |
3276 gui_update_scrollbars(FALSE); | |
3277 # endif | |
3278 } | |
3279 #ifdef FEAT_TITLE | |
3280 /* File may have been changed from 'readonly' to 'noreadonly' */ | |
3281 if (need_maketitle) | |
3282 maketitle(); | |
3283 #endif | |
3284 } | |
3285 #endif | |
3286 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13373
diff
changeset
|
3287 #if defined(HAVE_INPUT_METHOD) || defined(PROTO) |
7 | 3288 /* |
3289 * Save current Input Method status to specified place. | |
3290 */ | |
3291 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3292 im_save_status(long *psave) |
7 | 3293 { |
3294 /* Don't save when 'imdisable' is set or "xic" is NULL, IM is always | |
3295 * disabled then (but might start later). | |
3296 * Also don't save when inside a mapping, vgetc_im_active has not been set | |
3297 * then. | |
3298 * And don't save when the keys were stuffed (e.g., for a "." command). | |
3299 * And don't save when the GUI is running but our window doesn't have | |
3300 * input focus (e.g., when a find dialog is open). */ | |
3301 if (!p_imdisable && KeyTyped && !KeyStuffed | |
3302 # ifdef FEAT_XIM | |
3303 && xic != NULL | |
3304 # endif | |
3305 # ifdef FEAT_GUI | |
3306 && (!gui.in_use || gui.in_focus) | |
3307 # endif | |
3308 ) | |
3309 { | |
3310 /* Do save when IM is on, or IM is off and saved status is on. */ | |
3311 if (vgetc_im_active) | |
3312 *psave = B_IMODE_IM; | |
3313 else if (*psave == B_IMODE_IM) | |
3314 *psave = B_IMODE_NONE; | |
3315 } | |
3316 } | |
3317 #endif |