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