Mercurial > vim
annotate src/gui.c @ 14350:142c0083b3b8 v8.1.0190
patch 8.1.0190: Perl refcounts are wrong
commit https://github.com/vim/vim/commit/18c4f1badbc96d39de5b348f268ac8d55c2b0b67
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jul 16 17:45:38 2018 +0200
patch 8.1.0190: Perl refcounts are wrong
Problem: Perl refcounts are wrong.
Solution: Improve refcounting. Add a test. (Damien)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 16 Jul 2018 18:00:07 +0200 |
parents | 4cb334816bb1 |
children | 0a69e6e708f9 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9939
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * GUI/Motif support by Robert Webb | |
5 * | |
6 * Do ":help uganda" in Vim to read copying and usage conditions. | |
7 * Do ":help credits" in Vim to see a list of people who contributed. | |
8 * See README.txt for an overview of the Vim source code. | |
9 */ | |
10 | |
11 #include "vim.h" | |
12 | |
13 /* Structure containing all the GUI information */ | |
14 gui_T gui; | |
15 | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
16 #if defined(FEAT_MBYTE) && !defined(FEAT_GUI_GTK) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
17 static void set_guifontwide(char_u *font_name); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
18 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
19 static void gui_check_pos(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
20 static void gui_position_components(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
21 static void gui_outstr(char_u *, int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
22 static int gui_screenchar(int off, int flags, guicolor_T fg, guicolor_T bg, int back); |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
23 #ifdef FEAT_GUI_GTK |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
24 static int gui_screenstr(int off, int len, int flags, guicolor_T fg, guicolor_T bg, int back); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
25 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
26 static void gui_delete_lines(int row, int count); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
27 static void gui_insert_lines(int row, int count); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
28 static void fill_mouse_coord(char_u *p, int col, int row); |
685 | 29 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
30 static int gui_has_tabline(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
31 #endif |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
32 static void gui_do_scrollbar(win_T *wp, int which, int enable); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
33 static colnr_T scroll_line_len(linenr_T lnum); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
34 static linenr_T gui_find_longest_lnum(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
35 static void gui_update_horiz_scrollbar(int); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
36 static void gui_set_fg_color(char_u *name); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
37 static void gui_set_bg_color(char_u *name); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
38 static win_T *xy2win(int x, int y); |
7 | 39 |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
40 #ifdef GUI_MAY_FORK |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
41 static void gui_do_fork(void); |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
42 |
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
43 static int gui_read_child_pipe(int fd); |
3087 | 44 |
45 /* Return values for gui_read_child_pipe */ | |
46 enum { | |
47 GUI_CHILD_IO_ERROR, | |
48 GUI_CHILD_OK, | |
49 GUI_CHILD_FAILED | |
50 }; | |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
51 #endif |
3087 | 52 |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
53 static void gui_attempt_start(void); |
3087 | 54 |
7 | 55 static int can_update_cursor = TRUE; /* can display the cursor */ |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
56 static int disable_flush = 0; /* If > 0, gui_mch_flush() is disabled. */ |
7 | 57 |
58 /* | |
59 * The Athena scrollbars can move the thumb to after the end of the scrollbar, | |
60 * this makes the thumb indicate the part of the text that is shown. Motif | |
61 * can't do this. | |
62 */ | |
63 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MAC) | |
64 # define SCROLL_PAST_END | |
65 #endif | |
66 | |
67 /* | |
68 * gui_start -- Called when user wants to start the GUI. | |
69 * | |
70 * Careful: This function can be called recursively when there is a ":gui" | |
71 * command in the .gvimrc file. Only the first call should fork, not the | |
72 * recursive call. | |
73 */ | |
74 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
75 gui_start(void) |
7 | 76 { |
77 char_u *old_term; | |
78 static int recursive = 0; | |
79 | |
80 old_term = vim_strsave(T_NAME); | |
81 | |
82 settmode(TMODE_COOK); /* stop RAW mode */ | |
83 if (full_screen) | |
84 cursor_on(); /* needed for ":gui" in .vimrc */ | |
85 full_screen = FALSE; | |
86 | |
3087 | 87 ++recursive; |
2923 | 88 |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
89 #ifdef GUI_MAY_FORK |
3087 | 90 /* |
91 * Quit the current process and continue in the child. | |
92 * Makes "gvim file" disconnect from the shell it was started in. | |
93 * Don't do this when Vim was started with "-f" or the 'f' flag is present | |
94 * in 'guioptions'. | |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
95 * Don't do this when there is a running job, we can only get the status |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
96 * of a child from the parent. |
3087 | 97 */ |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
98 if (gui.dofork && !vim_strchr(p_go, GO_FORG) && recursive <= 1 |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
99 # ifdef FEAT_JOB_CHANNEL |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
100 && !job_any_running() |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
101 # endif |
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
102 ) |
3087 | 103 { |
104 gui_do_fork(); | |
105 } | |
106 else | |
107 #endif | |
108 { | |
3541 | 109 #ifdef FEAT_GUI_GTK |
3539 | 110 /* If there is 'f' in 'guioptions' and specify -g argument, |
111 * gui_mch_init_check() was not called yet. */ | |
112 if (gui_mch_init_check() != OK) | |
8617
eab968bf3ce7
commit https://github.com/vim/vim/commit/6d8d849f5ac8a3a228c62fd29e8f40ae1b8381fc
Christian Brabandt <cb@256bit.org>
parents:
8577
diff
changeset
|
113 getout_preserve_modified(1); |
3541 | 114 #endif |
3087 | 115 gui_attempt_start(); |
116 } | |
7 | 117 |
118 if (!gui.in_use) /* failed to start GUI */ | |
119 { | |
3087 | 120 /* Back to old term settings |
121 * | |
122 * FIXME: If we got here because a child process failed and flagged to | |
123 * the parent to resume, and X11 is enabled with FEAT_TITLE, this will | |
124 * hit an X11 I/O error and do a longjmp(), leaving recursive | |
125 * permanently set to 1. This is probably not as big a problem as it | |
126 * sounds, because gui_mch_init() in both gui_x11.c and gui_gtk_x11.c | |
127 * return "OK" unconditionally, so it would be very difficult to | |
128 * actually hit this case. | |
129 */ | |
130 termcapinit(old_term); | |
7 | 131 settmode(TMODE_RAW); /* restart RAW mode */ |
132 #ifdef FEAT_TITLE | |
133 set_title_defaults(); /* set 'title' and 'icon' again */ | |
134 #endif | |
135 } | |
136 | |
137 vim_free(old_term); | |
138 | |
3087 | 139 /* If the GUI started successfully, trigger the GUIEnter event, otherwise |
140 * the GUIFailed event. */ | |
141 gui_mch_update(); | |
142 apply_autocmds(gui.in_use ? EVENT_GUIENTER : EVENT_GUIFAILED, | |
143 NULL, NULL, FALSE, curbuf); | |
144 --recursive; | |
145 } | |
146 | |
147 /* | |
148 * Set_termname() will call gui_init() to start the GUI. | |
149 * Set the "starting" flag, to indicate that the GUI will start. | |
150 * | |
151 * We don't want to open the GUI shell until after we've read .gvimrc, | |
152 * otherwise we don't know what font we will use, and hence we don't know | |
153 * what size the shell should be. So if there are errors in the .gvimrc | |
154 * file, they will have to go to the terminal: Set full_screen to FALSE. | |
155 * full_screen will be set to TRUE again by a successful termcapinit(). | |
156 */ | |
157 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
158 gui_attempt_start(void) |
3087 | 159 { |
160 static int recursive = 0; | |
161 | |
162 ++recursive; | |
163 gui.starting = TRUE; | |
164 | |
165 #ifdef FEAT_GUI_GTK | |
166 gui.event_time = GDK_CURRENT_TIME; | |
167 #endif | |
168 | |
169 termcapinit((char_u *)"builtin_gui"); | |
170 gui.starting = recursive - 1; | |
171 | |
574 | 172 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) |
7 | 173 if (gui.in_use) |
2609 | 174 { |
175 # ifdef FEAT_EVAL | |
176 Window x11_window; | |
177 Display *x11_display; | |
178 | |
179 if (gui_get_x11_windis(&x11_window, &x11_display) == OK) | |
180 set_vim_var_nr(VV_WINDOWID, (long)x11_window); | |
181 # endif | |
182 | |
7 | 183 /* Display error messages in a dialog now. */ |
184 display_errors(); | |
2609 | 185 } |
7 | 186 #endif |
3087 | 187 --recursive; |
188 } | |
189 | |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
190 #ifdef GUI_MAY_FORK |
3087 | 191 |
192 /* for waitpid() */ | |
193 # if defined(HAVE_SYS_WAIT_H) || defined(HAVE_UNION_WAIT) | |
194 # include <sys/wait.h> | |
195 # endif | |
196 | |
197 /* | |
198 * Create a new process, by forking. In the child, start the GUI, and in | |
199 * the parent, exit. | |
200 * | |
201 * If something goes wrong, this will return with gui.in_use still set | |
202 * to FALSE, in which case the caller should continue execution without | |
203 * the GUI. | |
204 * | |
205 * If the child fails to start the GUI, then the child will exit and the | |
206 * parent will return. If the child succeeds, then the parent will exit | |
207 * and the child will return. | |
208 */ | |
209 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
210 gui_do_fork(void) |
3087 | 211 { |
212 int pipefd[2]; /* pipe between parent and child */ | |
213 int pipe_error; | |
214 int status; | |
215 int exit_status; | |
216 pid_t pid = -1; | |
217 | |
218 /* Setup a pipe between the child and the parent, so that the parent | |
219 * knows when the child has done the setsid() call and is allowed to | |
220 * exit. */ | |
221 pipe_error = (pipe(pipefd) < 0); | |
222 pid = fork(); | |
223 if (pid < 0) /* Fork error */ | |
7 | 224 { |
3087 | 225 EMSG(_("E851: Failed to create a new process for the GUI")); |
226 return; | |
227 } | |
228 else if (pid > 0) /* Parent */ | |
229 { | |
230 /* Give the child some time to do the setsid(), otherwise the | |
231 * exit() may kill the child too (when starting gvim from inside a | |
232 * gvim). */ | |
233 if (!pipe_error) | |
7 | 234 { |
3087 | 235 /* The read returns when the child closes the pipe (or when |
236 * the child dies for some reason). */ | |
237 close(pipefd[1]); | |
238 status = gui_read_child_pipe(pipefd[0]); | |
239 if (status == GUI_CHILD_FAILED) | |
7 | 240 { |
3087 | 241 /* The child failed to start the GUI, so the caller must |
242 * continue. There may be more error information written | |
243 * to stderr by the child. */ | |
244 # ifdef __NeXT__ | |
245 wait4(pid, &exit_status, 0, (struct rusage *)0); | |
246 # else | |
247 waitpid(pid, &exit_status, 0); | |
248 # endif | |
249 EMSG(_("E852: The child process failed to start the GUI")); | |
250 return; | |
7 | 251 } |
3087 | 252 else if (status == GUI_CHILD_IO_ERROR) |
253 { | |
254 pipe_error = TRUE; | |
255 } | |
256 /* else GUI_CHILD_OK: parent exit */ | |
7 | 257 } |
258 | |
3087 | 259 if (pipe_error) |
260 ui_delay(300L, TRUE); | |
261 | |
262 /* When swapping screens we may need to go to the next line, e.g., | |
263 * after a hit-enter prompt and using ":gui". */ | |
264 if (newline_on_exit) | |
265 mch_errmsg("\r\n"); | |
266 | |
267 /* | |
268 * The parent must skip the normal exit() processing, the child | |
269 * will do it. For example, GTK messes up signals when exiting. | |
270 */ | |
271 _exit(0); | |
272 } | |
273 /* Child */ | |
274 | |
3518 | 275 #ifdef FEAT_GUI_GTK |
276 /* Call gtk_init_check() here after fork(). See gui_init_check(). */ | |
277 if (gui_mch_init_check() != OK) | |
8617
eab968bf3ce7
commit https://github.com/vim/vim/commit/6d8d849f5ac8a3a228c62fd29e8f40ae1b8381fc
Christian Brabandt <cb@256bit.org>
parents:
8577
diff
changeset
|
278 getout_preserve_modified(1); |
3518 | 279 #endif |
280 | |
7 | 281 # if defined(HAVE_SETSID) || defined(HAVE_SETPGID) |
3087 | 282 /* |
283 * Change our process group. On some systems/shells a CTRL-C in the | |
284 * shell where Vim was started would otherwise kill gvim! | |
285 */ | |
7 | 286 # if defined(HAVE_SETSID) |
3087 | 287 (void)setsid(); |
7 | 288 # else |
3087 | 289 (void)setpgid(0, 0); |
7 | 290 # endif |
291 # endif | |
3087 | 292 if (!pipe_error) |
293 close(pipefd[0]); | |
7 | 294 |
295 # if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION) | |
3087 | 296 /* Tell the session manager our new PID */ |
297 gui_mch_forked(); | |
7 | 298 # endif |
3087 | 299 |
300 /* Try to start the GUI */ | |
301 gui_attempt_start(); | |
302 | |
303 /* Notify the parent */ | |
3147 | 304 if (!pipe_error) |
3087 | 305 { |
3147 | 306 if (gui.in_use) |
307 write_eintr(pipefd[1], "ok", 3); | |
308 else | |
309 write_eintr(pipefd[1], "fail", 5); | |
310 close(pipefd[1]); | |
3087 | 311 } |
312 | |
313 /* If we failed to start the GUI, exit now. */ | |
314 if (!gui.in_use) | |
8617
eab968bf3ce7
commit https://github.com/vim/vim/commit/6d8d849f5ac8a3a228c62fd29e8f40ae1b8381fc
Christian Brabandt <cb@256bit.org>
parents:
8577
diff
changeset
|
315 getout_preserve_modified(1); |
7 | 316 } |
317 | |
318 /* | |
3087 | 319 * Read from a pipe assumed to be connected to the child process (this |
320 * function is called from the parent). | |
321 * Return GUI_CHILD_OK if the child successfully started the GUI, | |
322 * GUY_CHILD_FAILED if the child failed, or GUI_CHILD_IO_ERROR if there was | |
323 * some other error. | |
324 * | |
325 * The file descriptor will be closed before the function returns. | |
326 */ | |
327 static int | |
328 gui_read_child_pipe(int fd) | |
329 { | |
3147 | 330 long bytes_read; |
331 #define READ_BUFFER_SIZE 10 | |
332 char buffer[READ_BUFFER_SIZE]; | |
333 | |
334 bytes_read = read_eintr(fd, buffer, READ_BUFFER_SIZE - 1); | |
335 #undef READ_BUFFER_SIZE | |
336 close(fd); | |
337 if (bytes_read < 0) | |
3087 | 338 return GUI_CHILD_IO_ERROR; |
3147 | 339 buffer[bytes_read] = NUL; |
3087 | 340 if (strcmp(buffer, "ok") == 0) |
341 return GUI_CHILD_OK; | |
342 return GUI_CHILD_FAILED; | |
343 } | |
344 | |
13847
fa0dcdaec6a3
patch 8.0.1795: lose contact with jobs when :gui forks
Christian Brabandt <cb@256bit.org>
parents:
13386
diff
changeset
|
345 #endif /* GUI_MAY_FORK */ |
3087 | 346 |
347 /* | |
7 | 348 * Call this when vim starts up, whether or not the GUI is started |
349 */ | |
350 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
351 gui_prepare(int *argc, char **argv) |
7 | 352 { |
353 gui.in_use = FALSE; /* No GUI yet (maybe later) */ | |
354 gui.starting = FALSE; /* No GUI yet (maybe later) */ | |
355 gui_mch_prepare(argc, argv); | |
356 } | |
357 | |
358 /* | |
359 * Try initializing the GUI and check if it can be started. | |
360 * Used from main() to check early if "vim -g" can start the GUI. | |
361 * Used from gui_init() to prepare for starting the GUI. | |
362 * Returns FAIL or OK. | |
363 */ | |
364 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
365 gui_init_check(void) |
7 | 366 { |
367 static int result = MAYBE; | |
368 | |
369 if (result != MAYBE) | |
370 { | |
371 if (result == FAIL) | |
372 EMSG(_("E229: Cannot start the GUI")); | |
373 return result; | |
374 } | |
375 | |
376 gui.shell_created = FALSE; | |
377 gui.dying = FALSE; | |
378 gui.in_focus = TRUE; /* so the guicursor setting works */ | |
379 gui.dragged_sb = SBAR_NONE; | |
380 gui.dragged_wp = NULL; | |
381 gui.pointer_hidden = FALSE; | |
382 gui.col = 0; | |
383 gui.row = 0; | |
384 gui.num_cols = Columns; | |
385 gui.num_rows = Rows; | |
386 | |
387 gui.cursor_is_valid = FALSE; | |
388 gui.scroll_region_top = 0; | |
389 gui.scroll_region_bot = Rows - 1; | |
390 gui.scroll_region_left = 0; | |
391 gui.scroll_region_right = Columns - 1; | |
392 gui.highlight_mask = HL_NORMAL; | |
393 gui.char_width = 1; | |
394 gui.char_height = 1; | |
395 gui.char_ascent = 0; | |
396 gui.border_width = 0; | |
397 | |
398 gui.norm_font = NOFONT; | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
399 #ifndef FEAT_GUI_GTK |
7 | 400 gui.bold_font = NOFONT; |
401 gui.ital_font = NOFONT; | |
402 gui.boldital_font = NOFONT; | |
403 # ifdef FEAT_XFONTSET | |
404 gui.fontset = NOFONTSET; | |
405 # endif | |
406 #endif | |
4950
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
407 #ifdef FEAT_MBYTE |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
408 gui.wide_font = NOFONT; |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
409 # ifndef FEAT_GUI_GTK |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
410 gui.wide_bold_font = NOFONT; |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
411 gui.wide_ital_font = NOFONT; |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
412 gui.wide_boldital_font = NOFONT; |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
413 # endif |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
414 #endif |
7 | 415 |
416 #ifdef FEAT_MENU | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
417 # ifndef FEAT_GUI_GTK |
7 | 418 # ifdef FONTSET_ALWAYS |
419 gui.menu_fontset = NOFONTSET; | |
420 # else | |
421 gui.menu_font = NOFONT; | |
422 # endif | |
423 # endif | |
424 gui.menu_is_active = TRUE; /* default: include menu */ | |
425 # ifndef FEAT_GUI_GTK | |
426 gui.menu_height = MENU_DEFAULT_HEIGHT; | |
427 gui.menu_width = 0; | |
428 # endif | |
429 #endif | |
430 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) | |
431 gui.toolbar_height = 0; | |
432 #endif | |
433 #if defined(FEAT_FOOTER) && defined(FEAT_GUI_MOTIF) | |
434 gui.footer_height = 0; | |
435 #endif | |
436 #ifdef FEAT_BEVAL_TIP | |
437 gui.tooltip_fontset = NOFONTSET; | |
438 #endif | |
439 | |
440 gui.scrollbar_width = gui.scrollbar_height = SB_DEFAULT_WIDTH; | |
441 gui.prev_wrap = -1; | |
442 | |
443 #ifdef ALWAYS_USE_GUI | |
444 result = OK; | |
445 #else | |
3518 | 446 # ifdef FEAT_GUI_GTK |
447 /* | |
448 * Note: Don't call gtk_init_check() before fork, it will be called after | |
449 * the fork. When calling it before fork, it make vim hang for a while. | |
450 * See gui_do_fork(). | |
451 * Use a simpler check if the GUI window can probably be opened. | |
452 */ | |
9836
bc591685594a
commit https://github.com/vim/vim/commit/717e196060d946fe20bb0f0307f417dc4d0e9b17
Christian Brabandt <cb@256bit.org>
parents:
9651
diff
changeset
|
453 result = gui.dofork ? gui_mch_early_init_check(TRUE) : gui_mch_init_check(); |
3518 | 454 # else |
7 | 455 result = gui_mch_init_check(); |
3518 | 456 # endif |
7 | 457 #endif |
458 return result; | |
459 } | |
460 | |
461 /* | |
462 * This is the call which starts the GUI. | |
463 */ | |
464 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
465 gui_init(void) |
7 | 466 { |
467 win_T *wp; | |
468 static int recursive = 0; | |
469 | |
470 /* | |
471 * It's possible to use ":gui" in a .gvimrc file. The first halve of this | |
472 * function will then be executed at the first call, the rest by the | |
473 * recursive call. This allow the shell to be opened halfway reading a | |
474 * gvimrc file. | |
475 */ | |
476 if (!recursive) | |
477 { | |
478 ++recursive; | |
479 | |
480 clip_init(TRUE); | |
481 | |
482 /* If can't initialize, don't try doing the rest */ | |
483 if (gui_init_check() == FAIL) | |
484 { | |
485 --recursive; | |
486 clip_init(FALSE); | |
487 return; | |
488 } | |
489 | |
490 /* | |
147 | 491 * Reset 'paste'. It's useful in the terminal, but not in the GUI. It |
492 * breaks the Paste toolbar button. | |
493 */ | |
494 set_option_value((char_u *)"paste", 0L, NULL, 0); | |
495 | |
496 /* | |
7 | 497 * Set up system-wide default menus. |
498 */ | |
499 #if defined(SYS_MENU_FILE) && defined(FEAT_MENU) | |
500 if (vim_strchr(p_go, GO_NOSYSMENU) == NULL) | |
501 { | |
502 sys_menu = TRUE; | |
819 | 503 do_source((char_u *)SYS_MENU_FILE, FALSE, DOSO_NONE); |
7 | 504 sys_menu = FALSE; |
505 } | |
506 #endif | |
507 | |
508 /* | |
509 * Switch on the mouse by default, unless the user changed it already. | |
510 * This can then be changed in the .gvimrc. | |
511 */ | |
512 if (!option_was_set((char_u *)"mouse")) | |
513 set_string_option_direct((char_u *)"mouse", -1, | |
694 | 514 (char_u *)"a", OPT_FREE, SID_NONE); |
7 | 515 |
516 /* | |
517 * If -U option given, use only the initializations from that file and | |
518 * nothing else. Skip all initializations for "-U NONE" or "-u NORC". | |
519 */ | |
520 if (use_gvimrc != NULL) | |
521 { | |
522 if (STRCMP(use_gvimrc, "NONE") != 0 | |
523 && STRCMP(use_gvimrc, "NORC") != 0 | |
819 | 524 && do_source(use_gvimrc, FALSE, DOSO_NONE) != OK) |
7 | 525 EMSG2(_("E230: Cannot read from \"%s\""), use_gvimrc); |
526 } | |
527 else | |
528 { | |
529 /* | |
530 * Get system wide defaults for gvim, only when file name defined. | |
531 */ | |
532 #ifdef SYS_GVIMRC_FILE | |
819 | 533 do_source((char_u *)SYS_GVIMRC_FILE, FALSE, DOSO_NONE); |
7 | 534 #endif |
535 | |
536 /* | |
537 * Try to read GUI initialization commands from the following | |
538 * places: | |
539 * - environment variable GVIMINIT | |
540 * - the user gvimrc file (~/.gvimrc) | |
541 * - the second user gvimrc file ($VIM/.gvimrc for Dos) | |
542 * - the third user gvimrc file ($VIM/.gvimrc for Amiga) | |
543 * The first that exists is used, the rest is ignored. | |
544 */ | |
545 if (process_env((char_u *)"GVIMINIT", FALSE) == FAIL | |
819 | 546 && do_source((char_u *)USR_GVIMRC_FILE, TRUE, |
547 DOSO_GVIMRC) == FAIL | |
7 | 548 #ifdef USR_GVIMRC_FILE2 |
819 | 549 && do_source((char_u *)USR_GVIMRC_FILE2, TRUE, |
550 DOSO_GVIMRC) == FAIL | |
7 | 551 #endif |
4863
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
552 #ifdef USR_GVIMRC_FILE3 |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
553 && do_source((char_u *)USR_GVIMRC_FILE3, TRUE, |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
554 DOSO_GVIMRC) == FAIL |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
555 #endif |
7 | 556 ) |
557 { | |
4863
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
558 #ifdef USR_GVIMRC_FILE4 |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
559 (void)do_source((char_u *)USR_GVIMRC_FILE4, TRUE, DOSO_GVIMRC); |
7 | 560 #endif |
561 } | |
562 | |
563 /* | |
564 * Read initialization commands from ".gvimrc" in current | |
565 * directory. This is only done if the 'exrc' option is set. | |
566 * Because of security reasons we disallow shell and write | |
567 * commands now, except for unix if the file is owned by the user | |
568 * or 'secure' option has been reset in environment of global | |
569 * ".gvimrc". | |
570 * Only do this if GVIMRC_FILE is not the same as USR_GVIMRC_FILE, | |
571 * USR_GVIMRC_FILE2, USR_GVIMRC_FILE3 or SYS_GVIMRC_FILE. | |
572 */ | |
573 if (p_exrc) | |
574 { | |
575 #ifdef UNIX | |
576 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9385
diff
changeset
|
577 stat_T s; |
7 | 578 |
579 /* if ".gvimrc" file is not owned by user, set 'secure' | |
580 * mode */ | |
581 if (mch_stat(GVIMRC_FILE, &s) || s.st_uid != getuid()) | |
582 secure = p_secure; | |
583 } | |
584 #else | |
585 secure = p_secure; | |
586 #endif | |
587 | |
588 if ( fullpathcmp((char_u *)USR_GVIMRC_FILE, | |
589 (char_u *)GVIMRC_FILE, FALSE) != FPC_SAME | |
590 #ifdef SYS_GVIMRC_FILE | |
591 && fullpathcmp((char_u *)SYS_GVIMRC_FILE, | |
592 (char_u *)GVIMRC_FILE, FALSE) != FPC_SAME | |
593 #endif | |
594 #ifdef USR_GVIMRC_FILE2 | |
595 && fullpathcmp((char_u *)USR_GVIMRC_FILE2, | |
596 (char_u *)GVIMRC_FILE, FALSE) != FPC_SAME | |
597 #endif | |
598 #ifdef USR_GVIMRC_FILE3 | |
599 && fullpathcmp((char_u *)USR_GVIMRC_FILE3, | |
600 (char_u *)GVIMRC_FILE, FALSE) != FPC_SAME | |
601 #endif | |
4863
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
602 #ifdef USR_GVIMRC_FILE4 |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
603 && fullpathcmp((char_u *)USR_GVIMRC_FILE4, |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
604 (char_u *)GVIMRC_FILE, FALSE) != FPC_SAME |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
605 #endif |
7 | 606 ) |
819 | 607 do_source((char_u *)GVIMRC_FILE, TRUE, DOSO_GVIMRC); |
7 | 608 |
609 if (secure == 2) | |
610 need_wait_return = TRUE; | |
611 secure = 0; | |
612 } | |
613 } | |
614 | |
615 if (need_wait_return || msg_didany) | |
616 wait_return(TRUE); | |
617 | |
618 --recursive; | |
619 } | |
620 | |
621 /* If recursive call opened the shell, return here from the first call */ | |
622 if (gui.in_use) | |
623 return; | |
624 | |
625 /* | |
626 * Create the GUI shell. | |
627 */ | |
628 gui.in_use = TRUE; /* Must be set after menus have been set up */ | |
629 if (gui_mch_init() == FAIL) | |
630 goto error; | |
631 | |
632 /* Avoid a delay for an error message that was printed in the terminal | |
633 * where Vim was started. */ | |
634 emsg_on_display = FALSE; | |
635 msg_scrolled = 0; | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
636 clear_sb_text(TRUE); |
7 | 637 need_wait_return = FALSE; |
638 msg_didany = FALSE; | |
639 | |
640 /* | |
641 * Check validity of any generic resources that may have been loaded. | |
642 */ | |
643 if (gui.border_width < 0) | |
644 gui.border_width = 0; | |
645 | |
646 /* | |
647 * Set up the fonts. First use a font specified with "-fn" or "-font". | |
648 */ | |
649 if (font_argument != NULL) | |
650 set_option_value((char_u *)"gfn", 0L, (char_u *)font_argument, 0); | |
651 if ( | |
652 #ifdef FEAT_XFONTSET | |
653 (*p_guifontset == NUL | |
654 || gui_init_font(p_guifontset, TRUE) == FAIL) && | |
655 #endif | |
656 gui_init_font(*p_guifont == NUL ? hl_get_font_name() | |
657 : p_guifont, FALSE) == FAIL) | |
658 { | |
659 EMSG(_("E665: Cannot start GUI, no valid font found")); | |
660 goto error2; | |
661 } | |
662 #ifdef FEAT_MBYTE | |
663 if (gui_get_wide_font() == FAIL) | |
664 EMSG(_("E231: 'guifontwide' invalid")); | |
665 #endif | |
666 | |
667 gui.num_cols = Columns; | |
668 gui.num_rows = Rows; | |
669 gui_reset_scroll_region(); | |
670 | |
671 /* Create initial scrollbars */ | |
672 FOR_ALL_WINDOWS(wp) | |
673 { | |
674 gui_create_scrollbar(&wp->w_scrollbars[SBAR_LEFT], SBAR_LEFT, wp); | |
675 gui_create_scrollbar(&wp->w_scrollbars[SBAR_RIGHT], SBAR_RIGHT, wp); | |
676 } | |
677 gui_create_scrollbar(&gui.bottom_sbar, SBAR_BOTTOM, NULL); | |
678 | |
679 #ifdef FEAT_MENU | |
680 gui_create_initial_menus(root_menu); | |
681 #endif | |
682 #ifdef FEAT_SUN_WORKSHOP | |
683 if (usingSunWorkShop) | |
684 workshop_init(); | |
685 #endif | |
686 #ifdef FEAT_SIGN_ICONS | |
687 sign_gui_started(); | |
688 #endif | |
689 | |
690 /* Configure the desired menu and scrollbars */ | |
691 gui_init_which_components(NULL); | |
692 | |
693 /* All components of the GUI have been created now */ | |
694 gui.shell_created = TRUE; | |
695 | |
696 #ifndef FEAT_GUI_GTK | |
697 /* Set the shell size, adjusted for the screen size. For GTK this only | |
698 * works after the shell has been opened, thus it is further down. */ | |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
699 gui_set_shellsize(TRUE, TRUE, RESIZE_BOTH); |
7 | 700 #endif |
701 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) | |
702 /* Need to set the size of the menubar after all the menus have been | |
703 * created. */ | |
704 gui_mch_compute_menu_height((Widget)0); | |
705 #endif | |
706 | |
707 /* | |
708 * Actually open the GUI shell. | |
709 */ | |
710 if (gui_mch_open() != FAIL) | |
711 { | |
712 #ifdef FEAT_TITLE | |
713 maketitle(); | |
714 resettitle(); | |
715 #endif | |
716 init_gui_options(); | |
717 #ifdef FEAT_ARABIC | |
718 /* Our GUI can't do bidi. */ | |
719 p_tbidi = FALSE; | |
720 #endif | |
574 | 721 #if defined(FEAT_GUI_GTK) |
7 | 722 /* Give GTK+ a chance to put all widget's into place. */ |
723 gui_mch_update(); | |
827 | 724 |
725 # ifdef FEAT_MENU | |
726 /* If there is no 'm' in 'guioptions' we need to remove the menu now. | |
727 * It was still there to make F10 work. */ | |
728 if (vim_strchr(p_go, GO_MENUS) == NULL) | |
729 { | |
730 --gui.starting; | |
731 gui_mch_enable_menu(FALSE); | |
732 ++gui.starting; | |
733 gui_mch_update(); | |
734 } | |
735 # endif | |
736 | |
7 | 737 /* Now make sure the shell fits on the screen. */ |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
738 gui_set_shellsize(TRUE, TRUE, RESIZE_BOTH); |
7 | 739 #endif |
261 | 740 /* When 'lines' was set while starting up the topframe may have to be |
741 * resized. */ | |
742 win_new_shellsize(); | |
187 | 743 |
12871
1a450ce6980c
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
744 #ifdef FEAT_BEVAL_GUI |
187 | 745 /* Always create the Balloon Evaluation area, but disable it when |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12839
diff
changeset
|
746 * 'ballooneval' is off. */ |
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12839
diff
changeset
|
747 if (balloonEval != NULL) |
14208
4cb334816bb1
patch 8.1.0121: crash when using ballooneval related to 'vartabstop'
Christian Brabandt <cb@256bit.org>
parents:
13927
diff
changeset
|
748 { |
4cb334816bb1
patch 8.1.0121: crash when using ballooneval related to 'vartabstop'
Christian Brabandt <cb@256bit.org>
parents:
13927
diff
changeset
|
749 # ifdef FEAT_VARTABS |
4cb334816bb1
patch 8.1.0121: crash when using ballooneval related to 'vartabstop'
Christian Brabandt <cb@256bit.org>
parents:
13927
diff
changeset
|
750 vim_free(balloonEval->vts); |
4cb334816bb1
patch 8.1.0121: crash when using ballooneval related to 'vartabstop'
Christian Brabandt <cb@256bit.org>
parents:
13927
diff
changeset
|
751 # endif |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12839
diff
changeset
|
752 vim_free(balloonEval); |
14208
4cb334816bb1
patch 8.1.0121: crash when using ballooneval related to 'vartabstop'
Christian Brabandt <cb@256bit.org>
parents:
13927
diff
changeset
|
753 } |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12839
diff
changeset
|
754 balloonEvalForTerm = FALSE; |
187 | 755 # ifdef FEAT_GUI_GTK |
756 balloonEval = gui_mch_create_beval_area(gui.drawarea, NULL, | |
757 &general_beval_cb, NULL); | |
758 # else | |
216 | 759 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) |
187 | 760 { |
761 extern Widget textArea; | |
762 balloonEval = gui_mch_create_beval_area(textArea, NULL, | |
216 | 763 &general_beval_cb, NULL); |
187 | 764 } |
765 # else | |
766 # ifdef FEAT_GUI_W32 | |
767 balloonEval = gui_mch_create_beval_area(NULL, NULL, | |
768 &general_beval_cb, NULL); | |
769 # endif | |
770 # endif | |
771 # endif | |
772 if (!p_beval) | |
773 gui_mch_disable_beval_area(balloonEval); | |
774 #endif | |
775 | |
7 | 776 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
777 if (!im_xim_isvalid_imactivate()) | |
778 EMSG(_("E599: Value of 'imactivatekey' is invalid")); | |
779 #endif | |
37 | 780 /* When 'cmdheight' was set during startup it may not have taken |
781 * effect yet. */ | |
782 if (p_ch != 1L) | |
824 | 783 command_height(); |
7 | 784 |
785 return; | |
786 } | |
787 | |
788 error2: | |
789 #ifdef FEAT_GUI_X11 | |
790 /* undo gui_mch_init() */ | |
791 gui_mch_uninit(); | |
792 #endif | |
793 | |
794 error: | |
795 gui.in_use = FALSE; | |
796 clip_init(FALSE); | |
797 } | |
798 | |
799 | |
800 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
801 gui_exit(int rc) |
7 | 802 { |
803 /* don't free the fonts, it leads to a BUS error | |
804 * richard@whitequeen.com Jul 99 */ | |
805 free_highlight_fonts(); | |
806 gui.in_use = FALSE; | |
807 gui_mch_exit(rc); | |
808 } | |
809 | |
574 | 810 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_MSWIN) \ |
7 | 811 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) || defined(PROTO) |
1002 | 812 # define NEED_GUI_UPDATE_SCREEN 1 |
7 | 813 /* |
814 * Called when the GUI shell is closed by the user. If there are no changed | |
815 * files Vim exits, otherwise there will be a dialog to ask the user what to | |
816 * do. | |
817 * When this function returns, Vim should NOT exit! | |
818 */ | |
819 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
820 gui_shell_closed(void) |
7 | 821 { |
822 cmdmod_T save_cmdmod; | |
823 | |
824 save_cmdmod = cmdmod; | |
825 | |
826 /* Only exit when there are no changed files */ | |
827 exiting = TRUE; | |
828 # ifdef FEAT_BROWSE | |
829 cmdmod.browse = TRUE; | |
830 # endif | |
831 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
832 cmdmod.confirm = TRUE; | |
833 # endif | |
834 /* If there are changed buffers, present the user with a dialog if | |
835 * possible, otherwise give an error message. */ | |
7469
15eefe1b0dad
commit https://github.com/vim/vim/commit/027387f70c671f62e3e08e0bdd09ec05b0232735
Christian Brabandt <cb@256bit.org>
parents:
7208
diff
changeset
|
836 if (!check_changed_any(FALSE, FALSE)) |
7 | 837 getout(0); |
838 | |
839 exiting = FALSE; | |
840 cmdmod = save_cmdmod; | |
1002 | 841 gui_update_screen(); /* redraw, window may show changed buffer */ |
7 | 842 } |
843 #endif | |
844 | |
845 /* | |
4352 | 846 * Set the font. "font_list" is a comma separated list of font names. The |
7 | 847 * first font name that works is used. If none is found, use the default |
848 * font. | |
849 * If "fontset" is TRUE, the "font_list" is used as one name for the fontset. | |
850 * Return OK when able to set the font. When it failed FAIL is returned and | |
851 * the fonts are unchanged. | |
852 */ | |
853 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
854 gui_init_font(char_u *font_list, int fontset UNUSED) |
7 | 855 { |
856 #define FONTLEN 320 | |
857 char_u font_name[FONTLEN]; | |
858 int font_list_empty = FALSE; | |
859 int ret = FAIL; | |
860 | |
861 if (!gui.in_use) | |
862 return FAIL; | |
863 | |
864 font_name[0] = NUL; | |
865 if (*font_list == NUL) | |
866 font_list_empty = TRUE; | |
867 else | |
868 { | |
869 #ifdef FEAT_XFONTSET | |
870 /* When using a fontset, the whole list of fonts is one name. */ | |
871 if (fontset) | |
872 ret = gui_mch_init_font(font_list, TRUE); | |
873 else | |
874 #endif | |
875 while (*font_list != NUL) | |
876 { | |
877 /* Isolate one comma separated font name. */ | |
878 (void)copy_option_part(&font_list, font_name, FONTLEN, ","); | |
879 | |
880 /* Careful!!! The Win32 version of gui_mch_init_font(), when | |
881 * called with "*" will change p_guifont to the selected font | |
882 * name, which frees the old value. This makes font_list | |
883 * invalid. Thus when OK is returned here, font_list must no | |
884 * longer be used! */ | |
885 if (gui_mch_init_font(font_name, FALSE) == OK) | |
886 { | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
887 #if defined(FEAT_MBYTE) && !defined(FEAT_GUI_GTK) |
7 | 888 /* If it's a Unicode font, try setting 'guifontwide' to a |
889 * similar double-width font. */ | |
890 if ((p_guifontwide == NULL || *p_guifontwide == NUL) | |
891 && strstr((char *)font_name, "10646") != NULL) | |
892 set_guifontwide(font_name); | |
893 #endif | |
894 ret = OK; | |
895 break; | |
896 } | |
897 } | |
898 } | |
899 | |
900 if (ret != OK | |
901 && STRCMP(font_list, "*") != 0 | |
902 && (font_list_empty || gui.norm_font == NOFONT)) | |
903 { | |
904 /* | |
905 * Couldn't load any font in 'font_list', keep the current font if | |
906 * there is one. If 'font_list' is empty, or if there is no current | |
907 * font, tell gui_mch_init_font() to try to find a font we can load. | |
908 */ | |
909 ret = gui_mch_init_font(NULL, FALSE); | |
910 } | |
911 | |
912 if (ret == OK) | |
913 { | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
914 #ifndef FEAT_GUI_GTK |
7 | 915 /* Set normal font as current font */ |
916 # ifdef FEAT_XFONTSET | |
917 if (gui.fontset != NOFONTSET) | |
918 gui_mch_set_fontset(gui.fontset); | |
919 else | |
920 # endif | |
921 gui_mch_set_font(gui.norm_font); | |
922 #endif | |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
923 gui_set_shellsize(TRUE, TRUE, RESIZE_BOTH); |
7 | 924 } |
925 | |
926 return ret; | |
927 } | |
928 | |
929 #if defined(FEAT_MBYTE) || defined(PROTO) | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
930 # ifndef FEAT_GUI_GTK |
7 | 931 /* |
932 * Try setting 'guifontwide' to a font twice as wide as "name". | |
933 */ | |
934 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
935 set_guifontwide(char_u *name) |
7 | 936 { |
937 int i = 0; | |
938 char_u wide_name[FONTLEN + 10]; /* room for 2 * width and '*' */ | |
939 char_u *wp = NULL; | |
940 char_u *p; | |
941 GuiFont font; | |
942 | |
943 wp = wide_name; | |
944 for (p = name; *p != NUL; ++p) | |
945 { | |
946 *wp++ = *p; | |
947 if (*p == '-') | |
948 { | |
949 ++i; | |
950 if (i == 6) /* font type: change "--" to "-*-" */ | |
951 { | |
952 if (p[1] == '-') | |
953 *wp++ = '*'; | |
954 } | |
955 else if (i == 12) /* found the width */ | |
956 { | |
957 ++p; | |
958 i = getdigits(&p); | |
959 if (i != 0) | |
960 { | |
961 /* Double the width specification. */ | |
962 sprintf((char *)wp, "%d%s", i * 2, p); | |
963 font = gui_mch_get_font(wide_name, FALSE); | |
964 if (font != NOFONT) | |
965 { | |
37 | 966 gui_mch_free_font(gui.wide_font); |
7 | 967 gui.wide_font = font; |
968 set_string_option_direct((char_u *)"gfw", -1, | |
694 | 969 wide_name, OPT_FREE, 0); |
7 | 970 } |
971 } | |
972 break; | |
973 } | |
974 } | |
975 } | |
976 } | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
977 # endif /* !FEAT_GUI_GTK */ |
7 | 978 |
979 /* | |
980 * Get the font for 'guifontwide'. | |
981 * Return FAIL for an invalid font name. | |
982 */ | |
983 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
984 gui_get_wide_font(void) |
7 | 985 { |
986 GuiFont font = NOFONT; | |
987 char_u font_name[FONTLEN]; | |
988 char_u *p; | |
989 | |
990 if (!gui.in_use) /* Can't allocate font yet, assume it's OK. */ | |
991 return OK; /* Will give an error message later. */ | |
992 | |
993 if (p_guifontwide != NULL && *p_guifontwide != NUL) | |
994 { | |
995 for (p = p_guifontwide; *p != NUL; ) | |
996 { | |
997 /* Isolate one comma separated font name. */ | |
998 (void)copy_option_part(&p, font_name, FONTLEN, ","); | |
999 font = gui_mch_get_font(font_name, FALSE); | |
1000 if (font != NOFONT) | |
1001 break; | |
1002 } | |
1003 if (font == NOFONT) | |
1004 return FAIL; | |
1005 } | |
1006 | |
1007 gui_mch_free_font(gui.wide_font); | |
4250 | 1008 # ifdef FEAT_GUI_GTK |
7 | 1009 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ |
1010 if (font != NOFONT && gui.norm_font != NOFONT | |
1011 && pango_font_description_equal(font, gui.norm_font)) | |
1012 { | |
1013 gui.wide_font = NOFONT; | |
1014 gui_mch_free_font(font); | |
1015 } | |
1016 else | |
4250 | 1017 # endif |
7 | 1018 gui.wide_font = font; |
4250 | 1019 # ifdef FEAT_GUI_MSWIN |
4055 | 1020 gui_mch_wide_font_changed(); |
4950
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
1021 # else |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
1022 /* |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
1023 * TODO: setup wide_bold_font, wide_ital_font and wide_boldital_font to |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
1024 * support those fonts for 'guifontwide'. |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
1025 */ |
4250 | 1026 # endif |
7 | 1027 return OK; |
1028 } | |
1029 #endif | |
1030 | |
1031 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1032 gui_set_cursor(int row, int col) |
7 | 1033 { |
1034 gui.row = row; | |
1035 gui.col = col; | |
1036 } | |
1037 | |
1038 /* | |
1039 * gui_check_pos - check if the cursor is on the screen. | |
1040 */ | |
1041 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1042 gui_check_pos(void) |
7 | 1043 { |
1044 if (gui.row >= screen_Rows) | |
1045 gui.row = screen_Rows - 1; | |
1046 if (gui.col >= screen_Columns) | |
1047 gui.col = screen_Columns - 1; | |
1048 if (gui.cursor_row >= screen_Rows || gui.cursor_col >= screen_Columns) | |
1049 gui.cursor_is_valid = FALSE; | |
1050 } | |
1051 | |
1052 /* | |
1053 * Redraw the cursor if necessary or when forced. | |
1054 * Careful: The contents of ScreenLines[] must match what is on the screen, | |
1055 * otherwise this goes wrong. May need to call out_flush() first. | |
1056 */ | |
1057 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1058 gui_update_cursor( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1059 int force, /* when TRUE, update even when not moved */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1060 int clear_selection)/* clear selection under cursor */ |
7 | 1061 { |
1062 int cur_width = 0; | |
1063 int cur_height = 0; | |
1064 int old_hl_mask; | |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1065 cursorentry_T *shape; |
7 | 1066 int id; |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1067 #ifdef FEAT_TERMINAL |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1068 guicolor_T shape_fg = INVALCOLOR; |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1069 guicolor_T shape_bg = INVALCOLOR; |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1070 #endif |
7 | 1071 guicolor_T cfg, cbg, cc; /* cursor fore-/background color */ |
1072 int cattr; /* cursor attributes */ | |
1073 int attr; | |
1074 attrentry_T *aep = NULL; | |
1075 | |
1695 | 1076 /* Don't update the cursor when halfway busy scrolling or the screen size |
1077 * doesn't match 'columns' and 'lines. ScreenLines[] isn't valid then. */ | |
1078 if (!can_update_cursor || screen_Columns != gui.num_cols | |
1079 || screen_Rows != gui.num_rows) | |
7 | 1080 return; |
1081 | |
1082 gui_check_pos(); | |
1083 if (!gui.cursor_is_valid || force | |
1084 || gui.row != gui.cursor_row || gui.col != gui.cursor_col) | |
1085 { | |
1086 gui_undraw_cursor(); | |
1087 if (gui.row < 0) | |
1088 return; | |
13386
bf3de2fd98fa
patch 8.0.1567: cannot build Win32 GUI without IME
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1089 #ifdef HAVE_INPUT_METHOD |
7 | 1090 if (gui.row != gui.cursor_row || gui.col != gui.cursor_col) |
1091 im_set_position(gui.row, gui.col); | |
1092 #endif | |
1093 gui.cursor_row = gui.row; | |
1094 gui.cursor_col = gui.col; | |
1095 | |
1096 /* Only write to the screen after ScreenLines[] has been initialized */ | |
1097 if (!screen_cleared || ScreenLines == NULL) | |
1098 return; | |
1099 | |
1100 /* Clear the selection if we are about to write over it */ | |
1101 if (clear_selection) | |
1102 clip_may_clear_selection(gui.row, gui.row); | |
1103 /* Check that the cursor is inside the shell (resizing may have made | |
1104 * it invalid) */ | |
1105 if (gui.row >= screen_Rows || gui.col >= screen_Columns) | |
1106 return; | |
1107 | |
1108 gui.cursor_is_valid = TRUE; | |
1109 | |
1110 /* | |
1111 * How the cursor is drawn depends on the current mode. | |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1112 * When in a terminal window use the shape/color specified there. |
7 | 1113 */ |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1114 #ifdef FEAT_TERMINAL |
12457
dfb8254aa735
patch 8.0.1108: cannot specify mappings for the terminal window
Christian Brabandt <cb@256bit.org>
parents:
12317
diff
changeset
|
1115 if (terminal_is_active()) |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1116 shape = term_get_cursor_shape(&shape_fg, &shape_bg); |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1117 else |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1118 #endif |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1119 shape = &shape_table[get_shape_idx(FALSE)]; |
7 | 1120 if (State & LANGMAP) |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1121 id = shape->id_lm; |
7 | 1122 else |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1123 id = shape->id; |
7 | 1124 |
1125 /* get the colors and attributes for the cursor. Default is inverted */ | |
1126 cfg = INVALCOLOR; | |
1127 cbg = INVALCOLOR; | |
1128 cattr = HL_INVERSE; | |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1129 gui_mch_set_blinking(shape->blinkwait, |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1130 shape->blinkon, |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1131 shape->blinkoff); |
12839
9ac41c3148ce
patch 8.0.1296: checking the same condition twice
Christian Brabandt <cb@256bit.org>
parents:
12835
diff
changeset
|
1132 if (shape->blinkwait == 0 || shape->blinkon == 0 |
9ac41c3148ce
patch 8.0.1296: checking the same condition twice
Christian Brabandt <cb@256bit.org>
parents:
12835
diff
changeset
|
1133 || shape->blinkoff == 0) |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
1134 gui_mch_stop_blink(FALSE); |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1135 #ifdef FEAT_TERMINAL |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1136 if (shape_bg != INVALCOLOR) |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1137 { |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1138 cattr = 0; |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1139 cfg = shape_fg; |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1140 cbg = shape_bg; |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1141 } |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1142 else |
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1143 #endif |
7 | 1144 if (id > 0) |
1145 { | |
1146 cattr = syn_id2colors(id, &cfg, &cbg); | |
13386
bf3de2fd98fa
patch 8.0.1567: cannot build Win32 GUI without IME
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
1147 #if defined(HAVE_INPUT_METHOD) || defined(FEAT_HANGULIN) |
7 | 1148 { |
1149 static int iid; | |
1150 guicolor_T fg, bg; | |
1151 | |
1668 | 1152 if ( |
13194
3efdd2ae3717
patch 8.0.1471: on MS-Windows CursorIM highlighting no longer works
Christian Brabandt <cb@256bit.org>
parents:
13176
diff
changeset
|
1153 # if defined(FEAT_GUI_GTK) && defined(FEAT_XIM) && !defined(FEAT_HANGULIN) |
1668 | 1154 preedit_get_status() |
1155 # else | |
1156 im_get_status() | |
1157 # endif | |
1158 ) | |
7 | 1159 { |
1160 iid = syn_name2id((char_u *)"CursorIM"); | |
1161 if (iid > 0) | |
1162 { | |
1163 syn_id2colors(iid, &fg, &bg); | |
1164 if (bg != INVALCOLOR) | |
1165 cbg = bg; | |
1166 if (fg != INVALCOLOR) | |
1167 cfg = fg; | |
1168 } | |
1169 } | |
1170 } | |
1171 #endif | |
1172 } | |
1173 | |
1174 /* | |
1175 * Get the attributes for the character under the cursor. | |
1176 * When no cursor color was given, use the character color. | |
1177 */ | |
1178 attr = ScreenAttrs[LineOffset[gui.row] + gui.col]; | |
1179 if (attr > HL_ALL) | |
1180 aep = syn_gui_attr2entry(attr); | |
1181 if (aep != NULL) | |
1182 { | |
1183 attr = aep->ae_attr; | |
1184 if (cfg == INVALCOLOR) | |
1185 cfg = ((attr & HL_INVERSE) ? aep->ae_u.gui.bg_color | |
1186 : aep->ae_u.gui.fg_color); | |
1187 if (cbg == INVALCOLOR) | |
1188 cbg = ((attr & HL_INVERSE) ? aep->ae_u.gui.fg_color | |
1189 : aep->ae_u.gui.bg_color); | |
1190 } | |
1191 if (cfg == INVALCOLOR) | |
1192 cfg = (attr & HL_INVERSE) ? gui.back_pixel : gui.norm_pixel; | |
1193 if (cbg == INVALCOLOR) | |
1194 cbg = (attr & HL_INVERSE) ? gui.norm_pixel : gui.back_pixel; | |
1195 | |
1196 #ifdef FEAT_XIM | |
1197 if (aep != NULL) | |
1198 { | |
1199 xim_bg_color = ((attr & HL_INVERSE) ? aep->ae_u.gui.fg_color | |
1200 : aep->ae_u.gui.bg_color); | |
1201 xim_fg_color = ((attr & HL_INVERSE) ? aep->ae_u.gui.bg_color | |
1202 : aep->ae_u.gui.fg_color); | |
1203 if (xim_bg_color == INVALCOLOR) | |
1204 xim_bg_color = (attr & HL_INVERSE) ? gui.norm_pixel | |
1205 : gui.back_pixel; | |
1206 if (xim_fg_color == INVALCOLOR) | |
1207 xim_fg_color = (attr & HL_INVERSE) ? gui.back_pixel | |
1208 : gui.norm_pixel; | |
1209 } | |
1210 else | |
1211 { | |
1212 xim_bg_color = (attr & HL_INVERSE) ? gui.norm_pixel | |
1213 : gui.back_pixel; | |
1214 xim_fg_color = (attr & HL_INVERSE) ? gui.back_pixel | |
1215 : gui.norm_pixel; | |
1216 } | |
1217 #endif | |
1218 | |
1219 attr &= ~HL_INVERSE; | |
1220 if (cattr & HL_INVERSE) | |
1221 { | |
1222 cc = cbg; | |
1223 cbg = cfg; | |
1224 cfg = cc; | |
1225 } | |
1226 cattr &= ~HL_INVERSE; | |
1227 | |
1228 /* | |
1229 * When we don't have window focus, draw a hollow cursor. | |
1230 */ | |
1231 if (!gui.in_focus) | |
1232 { | |
1233 gui_mch_draw_hollow_cursor(cbg); | |
1234 return; | |
1235 } | |
1236 | |
1237 old_hl_mask = gui.highlight_mask; | |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1238 if (shape->shape == SHAPE_BLOCK |
7 | 1239 #ifdef FEAT_HANGULIN |
1240 || composing_hangul | |
1241 #endif | |
1242 ) | |
1243 { | |
1244 /* | |
1245 * Draw the text character with the cursor colors. Use the | |
1246 * character attributes plus the cursor attributes. | |
1247 */ | |
1248 gui.highlight_mask = (cattr | attr); | |
1249 #ifdef FEAT_HANGULIN | |
1250 if (composing_hangul) | |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1251 { |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1252 char_u *comp_buf; |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1253 int comp_len; |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1254 |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1255 comp_buf = hangul_composing_buffer_get(&comp_len); |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1256 if (comp_buf) |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1257 { |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1258 (void)gui_outstr_nowrap(comp_buf, comp_len, |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1259 GUI_MON_IS_CURSOR | GUI_MON_NOCLEAR, |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1260 cfg, cbg, 0); |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1261 vim_free(comp_buf); |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1262 } |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1263 } |
7 | 1264 else |
1265 #endif | |
1266 (void)gui_screenchar(LineOffset[gui.row] + gui.col, | |
1267 GUI_MON_IS_CURSOR | GUI_MON_NOCLEAR, cfg, cbg, 0); | |
1268 } | |
1269 else | |
1270 { | |
1271 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT) | |
1272 int col_off = FALSE; | |
1273 #endif | |
1274 /* | |
1275 * First draw the partial cursor, then overwrite with the text | |
1276 * character, using a transparent background. | |
1277 */ | |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1278 if (shape->shape == SHAPE_VER) |
7 | 1279 { |
1280 cur_height = gui.char_height; | |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1281 cur_width = (gui.char_width * shape->percentage + 99) / 100; |
7 | 1282 } |
1283 else | |
1284 { | |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1285 cur_height = (gui.char_height * shape->percentage + 99) / 100; |
7 | 1286 cur_width = gui.char_width; |
1287 } | |
1288 #ifdef FEAT_MBYTE | |
1378 | 1289 if (has_mbyte && (*mb_off2cells)(LineOffset[gui.row] + gui.col, |
1290 LineOffset[gui.row] + screen_Columns) > 1) | |
7 | 1291 { |
1292 /* Double wide character. */ | |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1293 if (shape->shape != SHAPE_VER) |
7 | 1294 cur_width += gui.char_width; |
1295 # ifdef FEAT_RIGHTLEFT | |
1296 if (CURSOR_BAR_RIGHT) | |
1297 { | |
1298 /* gui.col points to the left halve of the character but | |
1299 * the vertical line needs to be on the right halve. | |
1300 * A double-wide horizontal line is also drawn from the | |
1301 * right halve in gui_mch_draw_part_cursor(). */ | |
1302 col_off = TRUE; | |
1303 ++gui.col; | |
1304 } | |
1305 # endif | |
1306 } | |
1307 #endif | |
1308 gui_mch_draw_part_cursor(cur_width, cur_height, cbg); | |
1309 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT) | |
1310 if (col_off) | |
1311 --gui.col; | |
1312 #endif | |
1313 | |
1314 #ifndef FEAT_GUI_MSWIN /* doesn't seem to work for MSWindows */ | |
1315 gui.highlight_mask = ScreenAttrs[LineOffset[gui.row] + gui.col]; | |
1316 (void)gui_screenchar(LineOffset[gui.row] + gui.col, | |
1317 GUI_MON_TRS_CURSOR | GUI_MON_NOCLEAR, | |
1318 (guicolor_T)0, (guicolor_T)0, 0); | |
1319 #endif | |
1320 } | |
1321 gui.highlight_mask = old_hl_mask; | |
1322 } | |
1323 } | |
1324 | |
1325 #if defined(FEAT_MENU) || defined(PROTO) | |
1326 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1327 gui_position_menu(void) |
7 | 1328 { |
574 | 1329 # if !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_MOTIF) |
7 | 1330 if (gui.menu_is_active && gui.in_use) |
1331 gui_mch_set_menu_pos(0, 0, gui.menu_width, gui.menu_height); | |
1332 # endif | |
1333 } | |
1334 #endif | |
1335 | |
1336 /* | |
1337 * Position the various GUI components (text area, menu). The vertical | |
1338 * scrollbars are NOT handled here. See gui_update_scrollbars(). | |
1339 */ | |
1340 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1341 gui_position_components(int total_width UNUSED) |
7 | 1342 { |
1343 int text_area_x; | |
1344 int text_area_y; | |
1345 int text_area_width; | |
1346 int text_area_height; | |
1347 | |
1348 /* avoid that moving components around generates events */ | |
1349 ++hold_gui_events; | |
1350 | |
1351 text_area_x = 0; | |
1352 if (gui.which_scrollbars[SBAR_LEFT]) | |
1353 text_area_x += gui.scrollbar_width; | |
1354 | |
1355 text_area_y = 0; | |
1356 #if defined(FEAT_MENU) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON)) | |
1357 gui.menu_width = total_width; | |
1358 if (gui.menu_is_active) | |
1359 text_area_y += gui.menu_height; | |
1360 #endif | |
1361 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_MSWIN) | |
1362 if (vim_strchr(p_go, GO_TOOLBAR) != NULL) | |
1363 text_area_y = TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT; | |
1364 #endif | |
1365 | |
819 | 1366 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \ |
1378 | 1367 || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_MAC)) |
810 | 1368 if (gui_has_tabline()) |
843 | 1369 text_area_y += gui.tabline_height; |
810 | 1370 #endif |
1371 | |
7 | 1372 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)) |
1373 if (vim_strchr(p_go, GO_TOOLBAR) != NULL) | |
1374 { | |
1375 # ifdef FEAT_GUI_ATHENA | |
1376 gui_mch_set_toolbar_pos(0, text_area_y, | |
1377 gui.menu_width, gui.toolbar_height); | |
1378 # endif | |
1379 text_area_y += gui.toolbar_height; | |
1380 } | |
1381 #endif | |
1382 | |
1383 text_area_width = gui.num_cols * gui.char_width + gui.border_offset * 2; | |
1384 text_area_height = gui.num_rows * gui.char_height + gui.border_offset * 2; | |
1385 | |
1386 gui_mch_set_text_area_pos(text_area_x, | |
1387 text_area_y, | |
1388 text_area_width, | |
1389 text_area_height | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1390 #if defined(FEAT_XIM) && !defined(FEAT_GUI_GTK) |
7 | 1391 + xim_get_status_area_height() |
1392 #endif | |
1393 ); | |
1394 #ifdef FEAT_MENU | |
1395 gui_position_menu(); | |
1396 #endif | |
1397 if (gui.which_scrollbars[SBAR_BOTTOM]) | |
1398 gui_mch_set_scrollbar_pos(&gui.bottom_sbar, | |
1399 text_area_x, | |
1400 text_area_y + text_area_height, | |
1401 text_area_width, | |
1402 gui.scrollbar_height); | |
1403 gui.left_sbar_x = 0; | |
1404 gui.right_sbar_x = text_area_x + text_area_width; | |
1405 | |
1406 --hold_gui_events; | |
1407 } | |
1408 | |
444 | 1409 /* |
1410 * Get the width of the widgets and decorations to the side of the text area. | |
1411 */ | |
7 | 1412 int |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1413 gui_get_base_width(void) |
7 | 1414 { |
1415 int base_width; | |
1416 | |
1417 base_width = 2 * gui.border_offset; | |
1418 if (gui.which_scrollbars[SBAR_LEFT]) | |
1419 base_width += gui.scrollbar_width; | |
1420 if (gui.which_scrollbars[SBAR_RIGHT]) | |
1421 base_width += gui.scrollbar_width; | |
1422 return base_width; | |
1423 } | |
1424 | |
444 | 1425 /* |
1426 * Get the height of the widgets and decorations above and below the text area. | |
1427 */ | |
7 | 1428 int |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1429 gui_get_base_height(void) |
7 | 1430 { |
1431 int base_height; | |
1432 | |
1433 base_height = 2 * gui.border_offset; | |
1434 if (gui.which_scrollbars[SBAR_BOTTOM]) | |
1435 base_height += gui.scrollbar_height; | |
1436 #ifdef FEAT_GUI_GTK | |
1437 /* We can't take the sizes properly into account until anything is | |
1438 * realized. Therefore we recalculate all the values here just before | |
1439 * setting the size. (--mdcki) */ | |
1440 #else | |
1441 # ifdef FEAT_MENU | |
1442 if (gui.menu_is_active) | |
1443 base_height += gui.menu_height; | |
1444 # endif | |
1445 # ifdef FEAT_TOOLBAR | |
1446 if (vim_strchr(p_go, GO_TOOLBAR) != NULL) | |
1447 # if defined(FEAT_GUI_MSWIN) && defined(FEAT_TOOLBAR) | |
1448 base_height += (TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT); | |
1449 # else | |
1450 base_height += gui.toolbar_height; | |
1451 # endif | |
1452 # endif | |
819 | 1453 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \ |
1454 || defined(FEAT_GUI_MOTIF)) | |
810 | 1455 if (gui_has_tabline()) |
843 | 1456 base_height += gui.tabline_height; |
810 | 1457 # endif |
7 | 1458 # ifdef FEAT_FOOTER |
1459 if (vim_strchr(p_go, GO_FOOTER) != NULL) | |
1460 base_height += gui.footer_height; | |
1461 # endif | |
1462 # if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) | |
1463 base_height += gui_mch_text_area_extra_height(); | |
1464 # endif | |
1465 #endif | |
1466 return base_height; | |
1467 } | |
1468 | |
1469 /* | |
1470 * Should be called after the GUI shell has been resized. Its arguments are | |
1471 * the new width and height of the shell in pixels. | |
1472 */ | |
1473 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1474 gui_resize_shell(int pixel_width, int pixel_height) |
7 | 1475 { |
1476 static int busy = FALSE; | |
1477 | |
1478 if (!gui.shell_created) /* ignore when still initializing */ | |
1479 return; | |
1480 | |
1481 /* | |
1482 * Can't resize the screen while it is being redrawn. Remember the new | |
1483 * size and handle it later. | |
1484 */ | |
1485 if (updating_screen || busy) | |
1486 { | |
1487 new_pixel_width = pixel_width; | |
1488 new_pixel_height = pixel_height; | |
1489 return; | |
1490 } | |
1491 | |
1492 again: | |
10819
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1493 new_pixel_width = 0; |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1494 new_pixel_height = 0; |
7 | 1495 busy = TRUE; |
1496 | |
1497 /* Flush pending output before redrawing */ | |
1498 out_flush(); | |
1499 | |
1500 gui.num_cols = (pixel_width - gui_get_base_width()) / gui.char_width; | |
1529 | 1501 gui.num_rows = (pixel_height - gui_get_base_height()) / gui.char_height; |
7 | 1502 |
1503 gui_position_components(pixel_width); | |
1504 gui_reset_scroll_region(); | |
10819
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1505 |
7 | 1506 /* |
1507 * At the "more" and ":confirm" prompt there is no redraw, put the cursor | |
1508 * at the last line here (why does it have to be one row too low?). | |
1509 */ | |
1510 if (State == ASKMORE || State == CONFIRM) | |
1511 gui.row = gui.num_rows; | |
1512 | |
1513 /* Only comparing Rows and Columns may be sufficient, but let's stay on | |
1514 * the safe side. */ | |
1515 if (gui.num_rows != screen_Rows || gui.num_cols != screen_Columns | |
1516 || gui.num_rows != Rows || gui.num_cols != Columns) | |
1517 shell_resized(); | |
1518 | |
1519 gui_update_scrollbars(TRUE); | |
1520 gui_update_cursor(FALSE, TRUE); | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1521 #if defined(FEAT_XIM) && !defined(FEAT_GUI_GTK) |
7 | 1522 xim_set_status_area(); |
1523 #endif | |
1524 | |
1525 busy = FALSE; | |
669 | 1526 |
10819
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1527 /* We may have been called again while redrawing the screen. |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1528 * Need to do it all again with the latest size then. But only if the size |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1529 * actually changed. */ |
7 | 1530 if (new_pixel_height) |
1531 { | |
10819
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1532 if (pixel_width == new_pixel_width && pixel_height == new_pixel_height) |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1533 { |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1534 new_pixel_width = 0; |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1535 new_pixel_height = 0; |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1536 } |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1537 else |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1538 { |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1539 pixel_width = new_pixel_width; |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1540 pixel_height = new_pixel_height; |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1541 goto again; |
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1542 } |
7 | 1543 } |
1544 } | |
1545 | |
1546 /* | |
1547 * Check if gui_resize_shell() must be called. | |
1548 */ | |
1549 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1550 gui_may_resize_shell(void) |
7 | 1551 { |
1552 if (new_pixel_height) | |
1553 /* careful: gui_resize_shell() may postpone the resize again if we | |
1554 * were called indirectly by it */ | |
10819
cd179d7d0b5d
patch 8.0.0299: a window resize is sometimes not taking effect
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
1555 gui_resize_shell(new_pixel_width, new_pixel_height); |
7 | 1556 } |
1557 | |
1558 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1559 gui_get_shellsize(void) |
7 | 1560 { |
1561 Rows = gui.num_rows; | |
1562 Columns = gui.num_cols; | |
1563 return OK; | |
1564 } | |
1565 | |
1566 /* | |
1567 * Set the size of the Vim shell according to Rows and Columns. | |
444 | 1568 * If "fit_to_display" is TRUE then the size may be reduced to fit the window |
1569 * on the screen. | |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1570 * When "mustset" is TRUE the size was set by the user. When FALSE a UI |
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1571 * component was added or removed (e.g., a scrollbar). |
7 | 1572 */ |
1573 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1574 gui_set_shellsize( |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1575 int mustset UNUSED, |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1576 int fit_to_display, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1577 int direction) /* RESIZE_HOR, RESIZE_VER */ |
7 | 1578 { |
1579 int base_width; | |
1580 int base_height; | |
1581 int width; | |
1582 int height; | |
1583 int min_width; | |
1584 int min_height; | |
1585 int screen_w; | |
1586 int screen_h; | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1587 #ifdef FEAT_GUI_GTK |
1967 | 1588 int un_maximize = mustset; |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
1589 int did_adjust = 0; |
1967 | 1590 #endif |
2065
9b78bb3794ba
updated for version 7.2.350
Bram Moolenaar <bram@zimbu.org>
parents:
1967
diff
changeset
|
1591 int x = -1, y = -1; |
7 | 1592 |
1593 if (!gui.shell_created) | |
1594 return; | |
1595 | |
3014 | 1596 #if defined(MSWIN) || defined(FEAT_GUI_GTK) |
7 | 1597 /* If not setting to a user specified size and maximized, calculate the |
1598 * number of characters that fit in the maximized window. */ | |
12802
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1599 if (!mustset && (vim_strchr(p_go, GO_KEEPWINSIZE) != NULL |
29a728529f92
patch 8.0.1278: GUI window always resizes when adding scrollbar
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1600 || gui_mch_maximized())) |
7 | 1601 { |
1602 gui_mch_newfont(); | |
1603 return; | |
1604 } | |
1605 #endif | |
1606 | |
1607 base_width = gui_get_base_width(); | |
1608 base_height = gui_get_base_height(); | |
2065
9b78bb3794ba
updated for version 7.2.350
Bram Moolenaar <bram@zimbu.org>
parents:
1967
diff
changeset
|
1609 if (fit_to_display) |
9b78bb3794ba
updated for version 7.2.350
Bram Moolenaar <bram@zimbu.org>
parents:
1967
diff
changeset
|
1610 /* Remember the original window position. */ |
7009 | 1611 (void)gui_mch_get_winpos(&x, &y); |
2065
9b78bb3794ba
updated for version 7.2.350
Bram Moolenaar <bram@zimbu.org>
parents:
1967
diff
changeset
|
1612 |
7 | 1613 #ifdef USE_SUN_WORKSHOP |
1614 if (!mustset && usingSunWorkShop | |
1615 && workshop_get_width_height(&width, &height)) | |
1616 { | |
1617 Columns = (width - base_width + gui.char_width - 1) / gui.char_width; | |
1618 Rows = (height - base_height + gui.char_height - 1) / gui.char_height; | |
1619 } | |
1620 else | |
1621 #endif | |
1622 { | |
1623 width = Columns * gui.char_width + base_width; | |
1624 height = Rows * gui.char_height + base_height; | |
1625 } | |
1626 | |
1627 if (fit_to_display) | |
1628 { | |
1629 gui_mch_get_screen_dimensions(&screen_w, &screen_h); | |
811 | 1630 if ((direction & RESIZE_HOR) && width > screen_w) |
7 | 1631 { |
1632 Columns = (screen_w - base_width) / gui.char_width; | |
1633 if (Columns < MIN_COLUMNS) | |
1634 Columns = MIN_COLUMNS; | |
1635 width = Columns * gui.char_width + base_width; | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1636 #ifdef FEAT_GUI_GTK |
1967 | 1637 ++did_adjust; |
1638 #endif | |
7 | 1639 } |
811 | 1640 if ((direction & RESIZE_VERT) && height > screen_h) |
7 | 1641 { |
1642 Rows = (screen_h - base_height) / gui.char_height; | |
1643 check_shellsize(); | |
1644 height = Rows * gui.char_height + base_height; | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1645 #ifdef FEAT_GUI_GTK |
1967 | 1646 ++did_adjust; |
1647 #endif | |
7 | 1648 } |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1649 #ifdef FEAT_GUI_GTK |
1967 | 1650 if (did_adjust == 2 || (width + gui.char_width >= screen_w |
1651 && height + gui.char_height >= screen_h)) | |
1652 /* don't unmaximize if at maximum size */ | |
1653 un_maximize = FALSE; | |
1654 #endif | |
7 | 1655 } |
5070
cf52d2a8c05c
updated for version 7.3.1278
Bram Moolenaar <bram@vim.org>
parents:
5045
diff
changeset
|
1656 limit_screen_size(); |
7 | 1657 gui.num_cols = Columns; |
1658 gui.num_rows = Rows; | |
1659 | |
1660 min_width = base_width + MIN_COLUMNS * gui.char_width; | |
1661 min_height = base_height + MIN_LINES * gui.char_height; | |
685 | 1662 min_height += tabline_height() * gui.char_height; |
1967 | 1663 |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1664 #ifdef FEAT_GUI_GTK |
1967 | 1665 if (un_maximize) |
1666 { | |
1667 /* If the window size is smaller than the screen unmaximize the | |
1668 * window, otherwise resizing won't work. */ | |
1669 gui_mch_get_screen_dimensions(&screen_w, &screen_h); | |
1670 if ((width + gui.char_width < screen_w | |
1671 || height + gui.char_height * 2 < screen_h) | |
1672 && gui_mch_maximized()) | |
1673 gui_mch_unmaximize(); | |
1674 } | |
1675 #endif | |
7 | 1676 |
1677 gui_mch_set_shellsize(width, height, min_width, min_height, | |
811 | 1678 base_width, base_height, direction); |
2065
9b78bb3794ba
updated for version 7.2.350
Bram Moolenaar <bram@zimbu.org>
parents:
1967
diff
changeset
|
1679 |
9b78bb3794ba
updated for version 7.2.350
Bram Moolenaar <bram@zimbu.org>
parents:
1967
diff
changeset
|
1680 if (fit_to_display && x >= 0 && y >= 0) |
7 | 1681 { |
2065
9b78bb3794ba
updated for version 7.2.350
Bram Moolenaar <bram@zimbu.org>
parents:
1967
diff
changeset
|
1682 /* Some window managers put the Vim window left of/above the screen. |
9b78bb3794ba
updated for version 7.2.350
Bram Moolenaar <bram@zimbu.org>
parents:
1967
diff
changeset
|
1683 * Only change the position if it wasn't already negative before |
9b78bb3794ba
updated for version 7.2.350
Bram Moolenaar <bram@zimbu.org>
parents:
1967
diff
changeset
|
1684 * (happens on MS-Windows with a secondary monitor). */ |
7 | 1685 gui_mch_update(); |
1686 if (gui_mch_get_winpos(&x, &y) == OK && (x < 0 || y < 0)) | |
1687 gui_mch_set_winpos(x < 0 ? 0 : x, y < 0 ? 0 : y); | |
1688 } | |
1689 | |
1690 gui_position_components(width); | |
1691 gui_update_scrollbars(TRUE); | |
1692 gui_reset_scroll_region(); | |
1693 } | |
1694 | |
1695 /* | |
1696 * Called when Rows and/or Columns has changed. | |
1697 */ | |
1698 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1699 gui_new_shellsize(void) |
7 | 1700 { |
1701 gui_reset_scroll_region(); | |
1702 } | |
1703 | |
1704 /* | |
1705 * Make scroll region cover whole screen. | |
1706 */ | |
1707 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1708 gui_reset_scroll_region(void) |
7 | 1709 { |
1710 gui.scroll_region_top = 0; | |
1711 gui.scroll_region_bot = gui.num_rows - 1; | |
1712 gui.scroll_region_left = 0; | |
1713 gui.scroll_region_right = gui.num_cols - 1; | |
1714 } | |
1715 | |
1716 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1717 gui_start_highlight(int mask) |
7 | 1718 { |
1719 if (mask > HL_ALL) /* highlight code */ | |
1720 gui.highlight_mask = mask; | |
1721 else /* mask */ | |
1722 gui.highlight_mask |= mask; | |
1723 } | |
1724 | |
1725 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1726 gui_stop_highlight(int mask) |
7 | 1727 { |
1728 if (mask > HL_ALL) /* highlight code */ | |
1729 gui.highlight_mask = HL_NORMAL; | |
1730 else /* mask */ | |
1731 gui.highlight_mask &= ~mask; | |
1732 } | |
1733 | |
1734 /* | |
1735 * Clear a rectangular region of the screen from text pos (row1, col1) to | |
1736 * (row2, col2) inclusive. | |
1737 */ | |
1738 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1739 gui_clear_block( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1740 int row1, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1741 int col1, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1742 int row2, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1743 int col2) |
7 | 1744 { |
1745 /* Clear the selection if we are about to write over it */ | |
1746 clip_may_clear_selection(row1, row2); | |
1747 | |
1748 gui_mch_clear_block(row1, col1, row2, col2); | |
1749 | |
1750 /* Invalidate cursor if it was in this block */ | |
1751 if ( gui.cursor_row >= row1 && gui.cursor_row <= row2 | |
1752 && gui.cursor_col >= col1 && gui.cursor_col <= col2) | |
1753 gui.cursor_is_valid = FALSE; | |
1754 } | |
1755 | |
1756 /* | |
1757 * Write code to update the cursor later. This avoids the need to flush the | |
1758 * output buffer before calling gui_update_cursor(). | |
1759 */ | |
1760 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1761 gui_update_cursor_later(void) |
7 | 1762 { |
12082
504df4aa84c6
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1763 OUT_STR(IF_EB("\033|s", ESC_STR "|s")); |
7 | 1764 } |
1765 | |
1766 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1767 gui_write( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1768 char_u *s, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
1769 int len) |
7 | 1770 { |
1771 char_u *p; | |
1772 int arg1 = 0, arg2 = 0; | |
1773 int force_cursor = FALSE; /* force cursor update */ | |
1774 int force_scrollbar = FALSE; | |
1775 static win_T *old_curwin = NULL; | |
1776 | |
1777 /* #define DEBUG_GUI_WRITE */ | |
1778 #ifdef DEBUG_GUI_WRITE | |
1779 { | |
1780 int i; | |
1781 char_u *str; | |
1782 | |
1783 printf("gui_write(%d):\n ", len); | |
1784 for (i = 0; i < len; i++) | |
1785 if (s[i] == ESC) | |
1786 { | |
1787 if (i != 0) | |
1788 printf("\n "); | |
1789 printf("<ESC>"); | |
1790 } | |
1791 else | |
1792 { | |
1793 str = transchar_byte(s[i]); | |
1794 if (str[0] && str[1]) | |
1795 printf("<%s>", (char *)str); | |
1796 else | |
1797 printf("%s", (char *)str); | |
1798 } | |
1799 printf("\n"); | |
1800 } | |
1801 #endif | |
1802 while (len) | |
1803 { | |
1804 if (s[0] == ESC && s[1] == '|') | |
1805 { | |
1806 p = s + 2; | |
9385
60db35a20823
commit https://github.com/vim/vim/commit/4a6c670b844a3ef9aec865a8216eaf363bab8721
Christian Brabandt <cb@256bit.org>
parents:
9305
diff
changeset
|
1807 if (VIM_ISDIGIT(*p) || (*p == '-' && VIM_ISDIGIT(*(p + 1)))) |
7 | 1808 { |
1809 arg1 = getdigits(&p); | |
1810 if (p > s + len) | |
1811 break; | |
1812 if (*p == ';') | |
1813 { | |
1814 ++p; | |
1815 arg2 = getdigits(&p); | |
1816 if (p > s + len) | |
1817 break; | |
1818 } | |
1819 } | |
1820 switch (*p) | |
1821 { | |
1822 case 'C': /* Clear screen */ | |
1823 clip_scroll_selection(9999); | |
1824 gui_mch_clear_all(); | |
1825 gui.cursor_is_valid = FALSE; | |
1826 force_scrollbar = TRUE; | |
1827 break; | |
1828 case 'M': /* Move cursor */ | |
1829 gui_set_cursor(arg1, arg2); | |
1830 break; | |
1831 case 's': /* force cursor (shape) update */ | |
1832 force_cursor = TRUE; | |
1833 break; | |
1834 case 'R': /* Set scroll region */ | |
1835 if (arg1 < arg2) | |
1836 { | |
1837 gui.scroll_region_top = arg1; | |
1838 gui.scroll_region_bot = arg2; | |
1839 } | |
1840 else | |
1841 { | |
1842 gui.scroll_region_top = arg2; | |
1843 gui.scroll_region_bot = arg1; | |
1844 } | |
1845 break; | |
1846 case 'V': /* Set vertical scroll region */ | |
1847 if (arg1 < arg2) | |
1848 { | |
1849 gui.scroll_region_left = arg1; | |
1850 gui.scroll_region_right = arg2; | |
1851 } | |
1852 else | |
1853 { | |
1854 gui.scroll_region_left = arg2; | |
1855 gui.scroll_region_right = arg1; | |
1856 } | |
1857 break; | |
1858 case 'd': /* Delete line */ | |
1859 gui_delete_lines(gui.row, 1); | |
1860 break; | |
1861 case 'D': /* Delete lines */ | |
1862 gui_delete_lines(gui.row, arg1); | |
1863 break; | |
1864 case 'i': /* Insert line */ | |
1865 gui_insert_lines(gui.row, 1); | |
1866 break; | |
1867 case 'I': /* Insert lines */ | |
1868 gui_insert_lines(gui.row, arg1); | |
1869 break; | |
1870 case '$': /* Clear to end-of-line */ | |
1871 gui_clear_block(gui.row, gui.col, gui.row, | |
1872 (int)Columns - 1); | |
1873 break; | |
1874 case 'h': /* Turn on highlighting */ | |
1875 gui_start_highlight(arg1); | |
1876 break; | |
1877 case 'H': /* Turn off highlighting */ | |
1878 gui_stop_highlight(arg1); | |
1879 break; | |
1880 case 'f': /* flash the window (visual bell) */ | |
1881 gui_mch_flash(arg1 == 0 ? 20 : arg1); | |
1882 break; | |
1883 default: | |
1884 p = s + 1; /* Skip the ESC */ | |
1885 break; | |
1886 } | |
1887 len -= (int)(++p - s); | |
1888 s = p; | |
1889 } | |
1890 else if ( | |
1891 #ifdef EBCDIC | |
1892 CtrlChar(s[0]) != 0 /* Ctrl character */ | |
1893 #else | |
1894 s[0] < 0x20 /* Ctrl character */ | |
1895 #endif | |
1896 #ifdef FEAT_SIGN_ICONS | |
1897 && s[0] != SIGN_BYTE | |
1898 # ifdef FEAT_NETBEANS_INTG | |
1899 && s[0] != MULTISIGN_BYTE | |
1900 # endif | |
1901 #endif | |
1902 ) | |
1903 { | |
1904 if (s[0] == '\n') /* NL */ | |
1905 { | |
1906 gui.col = 0; | |
1907 if (gui.row < gui.scroll_region_bot) | |
1908 gui.row++; | |
1909 else | |
1910 gui_delete_lines(gui.scroll_region_top, 1); | |
1911 } | |
1912 else if (s[0] == '\r') /* CR */ | |
1913 { | |
1914 gui.col = 0; | |
1915 } | |
1916 else if (s[0] == '\b') /* Backspace */ | |
1917 { | |
1918 if (gui.col) | |
1919 --gui.col; | |
1920 } | |
1921 else if (s[0] == Ctrl_L) /* cursor-right */ | |
1922 { | |
1923 ++gui.col; | |
1924 } | |
1925 else if (s[0] == Ctrl_G) /* Beep */ | |
1926 { | |
1927 gui_mch_beep(); | |
1928 } | |
1929 /* Other Ctrl character: shouldn't happen! */ | |
1930 | |
1931 --len; /* Skip this char */ | |
1932 ++s; | |
1933 } | |
1934 else | |
1935 { | |
1936 p = s; | |
1937 while (len > 0 && ( | |
1938 #ifdef EBCDIC | |
1939 CtrlChar(*p) == 0 | |
1940 #else | |
1941 *p >= 0x20 | |
1942 #endif | |
1943 #ifdef FEAT_SIGN_ICONS | |
1944 || *p == SIGN_BYTE | |
1945 # ifdef FEAT_NETBEANS_INTG | |
1946 || *p == MULTISIGN_BYTE | |
1947 # endif | |
1948 #endif | |
1949 )) | |
1950 { | |
1951 len--; | |
1952 p++; | |
1953 } | |
1954 gui_outstr(s, (int)(p - s)); | |
1955 s = p; | |
1956 } | |
1957 } | |
1958 | |
1959 /* Postponed update of the cursor (won't work if "can_update_cursor" isn't | |
1960 * set). */ | |
1961 if (force_cursor) | |
1962 gui_update_cursor(TRUE, TRUE); | |
1963 | |
1964 /* When switching to another window the dragging must have stopped. | |
1965 * Required for GTK, dragged_sb isn't reset. */ | |
1966 if (old_curwin != curwin) | |
1967 gui.dragged_sb = SBAR_NONE; | |
1968 | |
1969 /* Update the scrollbars after clearing the screen or when switched | |
1970 * to another window. | |
1971 * Update the horizontal scrollbar always, it's difficult to check all | |
1972 * situations where it might change. */ | |
1973 if (force_scrollbar || old_curwin != curwin) | |
1974 gui_update_scrollbars(force_scrollbar); | |
1975 else | |
1976 gui_update_horiz_scrollbar(FALSE); | |
1977 old_curwin = curwin; | |
1978 | |
1979 /* | |
1980 * We need to make sure this is cleared since Athena doesn't tell us when | |
1981 * he is done dragging. Do the same for GTK. | |
1982 */ | |
574 | 1983 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_GTK) |
7 | 1984 gui.dragged_sb = SBAR_NONE; |
1985 #endif | |
1986 | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
1987 gui_may_flush(); /* In case vim decides to take a nap */ |
7 | 1988 } |
1989 | |
1990 /* | |
1991 * When ScreenLines[] is invalid, updating the cursor should not be done, it | |
1992 * produces wrong results. Call gui_dont_update_cursor() before that code and | |
1993 * gui_can_update_cursor() afterwards. | |
1994 */ | |
1995 void | |
9848
664276833670
commit https://github.com/vim/vim/commit/107abd2ca53c31fd3bb40d77ff296e98eaae2975
Christian Brabandt <cb@256bit.org>
parents:
9836
diff
changeset
|
1996 gui_dont_update_cursor(int undraw) |
7 | 1997 { |
1998 if (gui.in_use) | |
1999 { | |
2000 /* Undraw the cursor now, we probably can't do it after the change. */ | |
9848
664276833670
commit https://github.com/vim/vim/commit/107abd2ca53c31fd3bb40d77ff296e98eaae2975
Christian Brabandt <cb@256bit.org>
parents:
9836
diff
changeset
|
2001 if (undraw) |
664276833670
commit https://github.com/vim/vim/commit/107abd2ca53c31fd3bb40d77ff296e98eaae2975
Christian Brabandt <cb@256bit.org>
parents:
9836
diff
changeset
|
2002 gui_undraw_cursor(); |
7 | 2003 can_update_cursor = FALSE; |
2004 } | |
2005 } | |
2006 | |
2007 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2008 gui_can_update_cursor(void) |
7 | 2009 { |
2010 can_update_cursor = TRUE; | |
2011 /* No need to update the cursor right now, there is always more output | |
2012 * after scrolling. */ | |
2013 } | |
2014 | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2015 /* |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2016 * Disable issuing gui_mch_flush(). |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2017 */ |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2018 void |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2019 gui_disable_flush(void) |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2020 { |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2021 ++disable_flush; |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2022 } |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2023 |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2024 /* |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2025 * Enable issuing gui_mch_flush(). |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2026 */ |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2027 void |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2028 gui_enable_flush(void) |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2029 { |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2030 --disable_flush; |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2031 } |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2032 |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2033 /* |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2034 * Issue gui_mch_flush() if it is not disabled. |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2035 */ |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2036 void |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2037 gui_may_flush(void) |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2038 { |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2039 if (disable_flush == 0) |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2040 gui_mch_flush(); |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2041 } |
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
2042 |
7 | 2043 static void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2044 gui_outstr(char_u *s, int len) |
7 | 2045 { |
2046 int this_len; | |
2047 #ifdef FEAT_MBYTE | |
2048 int cells; | |
2049 #endif | |
2050 | |
2051 if (len == 0) | |
2052 return; | |
2053 | |
2054 if (len < 0) | |
2055 len = (int)STRLEN(s); | |
2056 | |
2057 while (len > 0) | |
2058 { | |
2059 #ifdef FEAT_MBYTE | |
2060 if (has_mbyte) | |
2061 { | |
2062 /* Find out how many chars fit in the current line. */ | |
2063 cells = 0; | |
2064 for (this_len = 0; this_len < len; ) | |
2065 { | |
2066 cells += (*mb_ptr2cells)(s + this_len); | |
2067 if (gui.col + cells > Columns) | |
2068 break; | |
474 | 2069 this_len += (*mb_ptr2len)(s + this_len); |
7 | 2070 } |
2071 if (this_len > len) | |
2072 this_len = len; /* don't include following composing char */ | |
2073 } | |
2074 else | |
2075 #endif | |
2076 if (gui.col + len > Columns) | |
2077 this_len = Columns - gui.col; | |
2078 else | |
2079 this_len = len; | |
2080 | |
2081 (void)gui_outstr_nowrap(s, this_len, | |
2082 0, (guicolor_T)0, (guicolor_T)0, 0); | |
2083 s += this_len; | |
2084 len -= this_len; | |
2085 #ifdef FEAT_MBYTE | |
2086 /* fill up for a double-width char that doesn't fit. */ | |
2087 if (len > 0 && gui.col < Columns) | |
2088 (void)gui_outstr_nowrap((char_u *)" ", 1, | |
2089 0, (guicolor_T)0, (guicolor_T)0, 0); | |
2090 #endif | |
2091 /* The cursor may wrap to the next line. */ | |
2092 if (gui.col >= Columns) | |
2093 { | |
2094 gui.col = 0; | |
2095 gui.row++; | |
2096 } | |
2097 } | |
2098 } | |
2099 | |
2100 /* | |
2101 * Output one character (may be one or two display cells). | |
2102 * Caller must check for valid "off". | |
2103 * Returns FAIL or OK, just like gui_outstr_nowrap(). | |
2104 */ | |
2105 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2106 gui_screenchar( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2107 int off, /* Offset from start of screen */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2108 int flags, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2109 guicolor_T fg, /* colors for cursor */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2110 guicolor_T bg, /* colors for cursor */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2111 int back) /* backup this many chars when using bold trick */ |
7 | 2112 { |
2113 #ifdef FEAT_MBYTE | |
2114 char_u buf[MB_MAXBYTES + 1]; | |
2115 | |
2116 /* Don't draw right halve of a double-width UTF-8 char. "cannot happen" */ | |
2117 if (enc_utf8 && ScreenLines[off] == 0) | |
2118 return OK; | |
2119 | |
2120 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
2121 /* Draw UTF-8 multi-byte character. */ | |
2122 return gui_outstr_nowrap(buf, utfc_char2bytes(off, buf), | |
2123 flags, fg, bg, back); | |
2124 | |
2125 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
2126 { | |
2127 buf[0] = ScreenLines[off]; | |
2128 buf[1] = ScreenLines2[off]; | |
2129 return gui_outstr_nowrap(buf, 2, flags, fg, bg, back); | |
2130 } | |
2131 | |
2132 /* Draw non-multi-byte character or DBCS character. */ | |
2133 return gui_outstr_nowrap(ScreenLines + off, | |
474 | 2134 enc_dbcs ? (*mb_ptr2len)(ScreenLines + off) : 1, |
7 | 2135 flags, fg, bg, back); |
2136 #else | |
2137 return gui_outstr_nowrap(ScreenLines + off, 1, flags, fg, bg, back); | |
2138 #endif | |
2139 } | |
2140 | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
2141 #ifdef FEAT_GUI_GTK |
7 | 2142 /* |
2143 * Output the string at the given screen position. This is used in place | |
2144 * of gui_screenchar() where possible because Pango needs as much context | |
2145 * as possible to work nicely. It's a lot faster as well. | |
2146 */ | |
2147 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2148 gui_screenstr( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2149 int off, /* Offset from start of screen */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2150 int len, /* string length in screen cells */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2151 int flags, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2152 guicolor_T fg, /* colors for cursor */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2153 guicolor_T bg, /* colors for cursor */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2154 int back) /* backup this many chars when using bold trick */ |
7 | 2155 { |
2156 char_u *buf; | |
2157 int outlen = 0; | |
2158 int i; | |
2159 int retval; | |
2160 | |
2161 if (len <= 0) /* "cannot happen"? */ | |
2162 return OK; | |
2163 | |
2164 if (enc_utf8) | |
2165 { | |
2166 buf = alloc((unsigned)(len * MB_MAXBYTES + 1)); | |
2167 if (buf == NULL) | |
2168 return OK; /* not much we could do here... */ | |
2169 | |
2170 for (i = off; i < off + len; ++i) | |
2171 { | |
2172 if (ScreenLines[i] == 0) | |
2173 continue; /* skip second half of double-width char */ | |
2174 | |
2175 if (ScreenLinesUC[i] == 0) | |
2176 buf[outlen++] = ScreenLines[i]; | |
2177 else | |
2178 outlen += utfc_char2bytes(i, buf + outlen); | |
2179 } | |
2180 | |
2181 buf[outlen] = NUL; /* only to aid debugging */ | |
2182 retval = gui_outstr_nowrap(buf, outlen, flags, fg, bg, back); | |
2183 vim_free(buf); | |
2184 | |
2185 return retval; | |
2186 } | |
2187 else if (enc_dbcs == DBCS_JPNU) | |
2188 { | |
2189 buf = alloc((unsigned)(len * 2 + 1)); | |
2190 if (buf == NULL) | |
2191 return OK; /* not much we could do here... */ | |
2192 | |
2193 for (i = off; i < off + len; ++i) | |
2194 { | |
2195 buf[outlen++] = ScreenLines[i]; | |
2196 | |
2197 /* handle double-byte single-width char */ | |
2198 if (ScreenLines[i] == 0x8e) | |
2199 buf[outlen++] = ScreenLines2[i]; | |
2200 else if (MB_BYTE2LEN(ScreenLines[i]) == 2) | |
2201 buf[outlen++] = ScreenLines[++i]; | |
2202 } | |
2203 | |
2204 buf[outlen] = NUL; /* only to aid debugging */ | |
2205 retval = gui_outstr_nowrap(buf, outlen, flags, fg, bg, back); | |
2206 vim_free(buf); | |
2207 | |
2208 return retval; | |
2209 } | |
2210 else | |
2211 { | |
2212 return gui_outstr_nowrap(&ScreenLines[off], len, | |
2213 flags, fg, bg, back); | |
2214 } | |
2215 } | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
2216 #endif /* FEAT_GUI_GTK */ |
7 | 2217 |
2218 /* | |
2219 * Output the given string at the current cursor position. If the string is | |
2220 * too long to fit on the line, then it is truncated. | |
2221 * "flags": | |
2222 * GUI_MON_IS_CURSOR should only be used when this function is being called to | |
2223 * actually draw (an inverted) cursor. | |
1199 | 2224 * GUI_MON_TRS_CURSOR is used to draw the cursor text with a transparent |
7 | 2225 * background. |
2226 * GUI_MON_NOCLEAR is used to avoid clearing the selection when drawing over | |
2227 * it. | |
2228 * Returns OK, unless "back" is non-zero and using the bold trick, then return | |
2229 * FAIL (the caller should start drawing "back" chars back). | |
2230 */ | |
2231 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2232 gui_outstr_nowrap( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2233 char_u *s, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2234 int len, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2235 int flags, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2236 guicolor_T fg, /* colors for cursor */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2237 guicolor_T bg, /* colors for cursor */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2238 int back) /* backup this many chars when using bold trick */ |
7 | 2239 { |
2240 long_u highlight_mask; | |
2241 long_u hl_mask_todo; | |
2242 guicolor_T fg_color; | |
2243 guicolor_T bg_color; | |
203 | 2244 guicolor_T sp_color; |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2245 #if !defined(FEAT_GUI_GTK) |
7 | 2246 GuiFont font = NOFONT; |
4950
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2247 # ifdef FEAT_MBYTE |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2248 GuiFont wide_font = NOFONT; |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2249 # endif |
7 | 2250 # ifdef FEAT_XFONTSET |
2251 GuiFontset fontset = NOFONTSET; | |
2252 # endif | |
2253 #endif | |
2254 attrentry_T *aep = NULL; | |
2255 int draw_flags; | |
2256 int col = gui.col; | |
2257 #ifdef FEAT_SIGN_ICONS | |
2258 int draw_sign = FALSE; | |
2259 # ifdef FEAT_NETBEANS_INTG | |
2260 int multi_sign = FALSE; | |
2261 # endif | |
2262 #endif | |
2263 | |
2264 if (len < 0) | |
2265 len = (int)STRLEN(s); | |
2266 if (len == 0) | |
2267 return OK; | |
2268 | |
2269 #ifdef FEAT_SIGN_ICONS | |
2270 if (*s == SIGN_BYTE | |
2271 # ifdef FEAT_NETBEANS_INTG | |
2272 || *s == MULTISIGN_BYTE | |
2273 # endif | |
2274 ) | |
2275 { | |
2276 # ifdef FEAT_NETBEANS_INTG | |
2277 if (*s == MULTISIGN_BYTE) | |
2278 multi_sign = TRUE; | |
2279 # endif | |
2280 /* draw spaces instead */ | |
2281 s = (char_u *)" "; | |
2282 if (len == 1 && col > 0) | |
2283 --col; | |
2284 len = 2; | |
2285 draw_sign = TRUE; | |
2286 highlight_mask = 0; | |
2287 } | |
2288 else | |
2289 #endif | |
2290 if (gui.highlight_mask > HL_ALL) | |
2291 { | |
2292 aep = syn_gui_attr2entry(gui.highlight_mask); | |
2293 if (aep == NULL) /* highlighting not set */ | |
2294 highlight_mask = 0; | |
2295 else | |
2296 highlight_mask = aep->ae_attr; | |
2297 } | |
2298 else | |
2299 highlight_mask = gui.highlight_mask; | |
2300 hl_mask_todo = highlight_mask; | |
2301 | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2302 #if !defined(FEAT_GUI_GTK) |
7 | 2303 /* Set the font */ |
2304 if (aep != NULL && aep->ae_u.gui.font != NOFONT) | |
2305 font = aep->ae_u.gui.font; | |
2306 # ifdef FEAT_XFONTSET | |
2307 else if (aep != NULL && aep->ae_u.gui.fontset != NOFONTSET) | |
2308 fontset = aep->ae_u.gui.fontset; | |
2309 # endif | |
2310 else | |
2311 { | |
2312 # ifdef FEAT_XFONTSET | |
2313 if (gui.fontset != NOFONTSET) | |
2314 fontset = gui.fontset; | |
2315 else | |
2316 # endif | |
2317 if (hl_mask_todo & (HL_BOLD | HL_STANDOUT)) | |
2318 { | |
2319 if ((hl_mask_todo & HL_ITALIC) && gui.boldital_font != NOFONT) | |
2320 { | |
2321 font = gui.boldital_font; | |
2322 hl_mask_todo &= ~(HL_BOLD | HL_STANDOUT | HL_ITALIC); | |
2323 } | |
2324 else if (gui.bold_font != NOFONT) | |
2325 { | |
2326 font = gui.bold_font; | |
2327 hl_mask_todo &= ~(HL_BOLD | HL_STANDOUT); | |
2328 } | |
2329 else | |
2330 font = gui.norm_font; | |
2331 } | |
2332 else if ((hl_mask_todo & HL_ITALIC) && gui.ital_font != NOFONT) | |
2333 { | |
2334 font = gui.ital_font; | |
2335 hl_mask_todo &= ~HL_ITALIC; | |
2336 } | |
2337 else | |
2338 font = gui.norm_font; | |
4950
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2339 |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2340 # ifdef FEAT_MBYTE |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2341 /* |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2342 * Choose correct wide_font by font. wide_font should be set with font |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2343 * at same time in above block. But it will make many "ifdef" nasty |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2344 * blocks. So we do it here. |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2345 */ |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2346 if (font == gui.boldital_font && gui.wide_boldital_font) |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2347 wide_font = gui.wide_boldital_font; |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2348 else if (font == gui.bold_font && gui.wide_bold_font) |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2349 wide_font = gui.wide_bold_font; |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2350 else if (font == gui.ital_font && gui.wide_ital_font) |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2351 wide_font = gui.wide_ital_font; |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2352 else if (font == gui.norm_font && gui.wide_font) |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2353 wide_font = gui.wide_font; |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2354 # endif |
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2355 |
7 | 2356 } |
2357 # ifdef FEAT_XFONTSET | |
2358 if (fontset != NOFONTSET) | |
2359 gui_mch_set_fontset(fontset); | |
2360 else | |
2361 # endif | |
2362 gui_mch_set_font(font); | |
2363 #endif | |
2364 | |
2365 draw_flags = 0; | |
2366 | |
2367 /* Set the color */ | |
2368 bg_color = gui.back_pixel; | |
2369 if ((flags & GUI_MON_IS_CURSOR) && gui.in_focus) | |
2370 { | |
2371 draw_flags |= DRAW_CURSOR; | |
2372 fg_color = fg; | |
2373 bg_color = bg; | |
203 | 2374 sp_color = fg; |
7 | 2375 } |
2376 else if (aep != NULL) | |
2377 { | |
2378 fg_color = aep->ae_u.gui.fg_color; | |
2379 if (fg_color == INVALCOLOR) | |
2380 fg_color = gui.norm_pixel; | |
2381 bg_color = aep->ae_u.gui.bg_color; | |
2382 if (bg_color == INVALCOLOR) | |
2383 bg_color = gui.back_pixel; | |
203 | 2384 sp_color = aep->ae_u.gui.sp_color; |
2385 if (sp_color == INVALCOLOR) | |
2386 sp_color = fg_color; | |
7 | 2387 } |
2388 else | |
203 | 2389 { |
7 | 2390 fg_color = gui.norm_pixel; |
203 | 2391 sp_color = fg_color; |
2392 } | |
7 | 2393 |
2394 if (highlight_mask & (HL_INVERSE | HL_STANDOUT)) | |
2395 { | |
2823 | 2396 #if defined(AMIGA) |
7 | 2397 gui_mch_set_colors(bg_color, fg_color); |
2398 #else | |
2399 gui_mch_set_fg_color(bg_color); | |
2400 gui_mch_set_bg_color(fg_color); | |
2401 #endif | |
2402 } | |
2403 else | |
2404 { | |
2823 | 2405 #if defined(AMIGA) |
7 | 2406 gui_mch_set_colors(fg_color, bg_color); |
2407 #else | |
2408 gui_mch_set_fg_color(fg_color); | |
2409 gui_mch_set_bg_color(bg_color); | |
2410 #endif | |
2411 } | |
203 | 2412 gui_mch_set_sp_color(sp_color); |
7 | 2413 |
2414 /* Clear the selection if we are about to write over it */ | |
2415 if (!(flags & GUI_MON_NOCLEAR)) | |
2416 clip_may_clear_selection(gui.row, gui.row); | |
2417 | |
2418 | |
2419 /* If there's no bold font, then fake it */ | |
2420 if (hl_mask_todo & (HL_BOLD | HL_STANDOUT)) | |
2421 draw_flags |= DRAW_BOLD; | |
2422 | |
2423 /* | |
2424 * When drawing bold or italic characters the spill-over from the left | |
2425 * neighbor may be destroyed. Let the caller backup to start redrawing | |
2426 * just after a blank. | |
2427 */ | |
2428 if (back != 0 && ((draw_flags & DRAW_BOLD) || (highlight_mask & HL_ITALIC))) | |
2429 return FAIL; | |
2430 | |
2823 | 2431 #if defined(FEAT_GUI_GTK) |
7 | 2432 /* If there's no italic font, then fake it. |
2433 * For GTK2, we don't need a different font for italic style. */ | |
2434 if (hl_mask_todo & HL_ITALIC) | |
2435 draw_flags |= DRAW_ITALIC; | |
2436 | |
2437 /* Do we underline the text? */ | |
2438 if (hl_mask_todo & HL_UNDERLINE) | |
2439 draw_flags |= DRAW_UNDERL; | |
12317
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
2440 |
7 | 2441 #else |
2442 /* Do we underline the text? */ | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
2443 if ((hl_mask_todo & HL_UNDERLINE) || (hl_mask_todo & HL_ITALIC)) |
7 | 2444 draw_flags |= DRAW_UNDERL; |
2445 #endif | |
203 | 2446 /* Do we undercurl the text? */ |
2447 if (hl_mask_todo & HL_UNDERCURL) | |
2448 draw_flags |= DRAW_UNDERC; | |
7 | 2449 |
12317
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
2450 /* Do we strikethrough the text? */ |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
2451 if (hl_mask_todo & HL_STRIKETHROUGH) |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
2452 draw_flags |= DRAW_STRIKE; |
2a8890b80923
patch 8.0.1038: strike-through text not supported
Christian Brabandt <cb@256bit.org>
parents:
12136
diff
changeset
|
2453 |
1199 | 2454 /* Do we draw transparently? */ |
7 | 2455 if (flags & GUI_MON_TRS_CURSOR) |
2456 draw_flags |= DRAW_TRANSP; | |
2457 | |
2458 /* | |
2459 * Draw the text. | |
2460 */ | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
2461 #ifdef FEAT_GUI_GTK |
7 | 2462 /* The value returned is the length in display cells */ |
2463 len = gui_gtk2_draw_string(gui.row, col, s, len, draw_flags); | |
2464 #else | |
2465 # ifdef FEAT_MBYTE | |
2466 if (enc_utf8) | |
2467 { | |
2468 int start; /* index of bytes to be drawn */ | |
2469 int cells; /* cellwidth of bytes to be drawn */ | |
4352 | 2470 int thislen; /* length of bytes to be drawn */ |
7 | 2471 int cn; /* cellwidth of current char */ |
2472 int i; /* index of current char */ | |
2473 int c; /* current char value */ | |
2474 int cl; /* byte length of current char */ | |
2475 int comping; /* current char is composing */ | |
2476 int scol = col; /* screen column */ | |
12712
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2477 int curr_wide = FALSE; /* use 'guifontwide' */ |
4053 | 2478 int prev_wide = FALSE; |
2479 int wide_changed; | |
12712
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2480 # ifdef WIN3264 |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2481 int sep_comp = FALSE; /* Don't separate composing chars. */ |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2482 # else |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2483 int sep_comp = TRUE; /* Separate composing chars. */ |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2484 # endif |
7 | 2485 |
2486 /* Break the string at a composing character, it has to be drawn on | |
2487 * top of the previous character. */ | |
2488 start = 0; | |
2489 cells = 0; | |
2490 for (i = 0; i < len; i += cl) | |
2491 { | |
2492 c = utf_ptr2char(s + i); | |
2493 cn = utf_char2cells(c); | |
2494 comping = utf_iscomposing(c); | |
2495 if (!comping) /* count cells from non-composing chars */ | |
2496 cells += cn; | |
12712
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2497 if (!comping || sep_comp) |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2498 { |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2499 if (cn > 1 |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2500 # ifdef FEAT_XFONTSET |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2501 && fontset == NOFONTSET |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2502 # endif |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2503 && wide_font != NOFONT) |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2504 curr_wide = TRUE; |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2505 else |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2506 curr_wide = FALSE; |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2507 } |
474 | 2508 cl = utf_ptr2len(s + i); |
7 | 2509 if (cl == 0) /* hit end of string */ |
2510 len = i + cl; /* len must be wrong "cannot happen" */ | |
2511 | |
4053 | 2512 wide_changed = curr_wide != prev_wide; |
2513 | |
2514 /* Print the string so far if it's the last character or there is | |
7 | 2515 * a composing character. */ |
12712
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2516 if (i + cl >= len || (comping && sep_comp && i > start) |
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2517 || wide_changed |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2518 # if defined(FEAT_GUI_X11) |
7 | 2519 || (cn > 1 |
2520 # ifdef FEAT_XFONTSET | |
2521 /* No fontset: At least draw char after wide char at | |
2522 * right position. */ | |
2523 && fontset == NOFONTSET | |
2524 # endif | |
2525 ) | |
2526 # endif | |
2527 ) | |
2528 { | |
12712
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2529 if ((comping && sep_comp) || wide_changed) |
7 | 2530 thislen = i - start; |
2531 else | |
2532 thislen = i - start + cl; | |
2533 if (thislen > 0) | |
2534 { | |
4053 | 2535 if (prev_wide) |
4950
ba7db05e1482
updated for version 7.3.1220
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2536 gui_mch_set_font(wide_font); |
7 | 2537 gui_mch_draw_string(gui.row, scol, s + start, thislen, |
2538 draw_flags); | |
4053 | 2539 if (prev_wide) |
2540 gui_mch_set_font(font); | |
7 | 2541 start += thislen; |
2542 } | |
2543 scol += cells; | |
2544 cells = 0; | |
4053 | 2545 /* Adjust to not draw a character which width is changed |
2546 * against with last one. */ | |
12712
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2547 if (wide_changed && !(comping && sep_comp)) |
7 | 2548 { |
4053 | 2549 scol -= cn; |
2550 cl = 0; | |
7 | 2551 } |
2552 | |
2275
e4d849f4df03
Remove the old and not well supported GTK 1 code. (James Vega)
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2553 # if defined(FEAT_GUI_X11) |
11 | 2554 /* No fontset: draw a space to fill the gap after a wide char |
2555 * */ | |
7 | 2556 if (cn > 1 && (draw_flags & DRAW_TRANSP) == 0 |
2557 # ifdef FEAT_XFONTSET | |
2558 && fontset == NOFONTSET | |
2559 # endif | |
4053 | 2560 && !wide_changed) |
7 | 2561 gui_mch_draw_string(gui.row, scol - 1, (char_u *)" ", |
2562 1, draw_flags); | |
2563 # endif | |
2564 } | |
2565 /* Draw a composing char on top of the previous char. */ | |
12712
25f7d8ee04c7
patch 8.0.1234: MS-Windows: composing chars are not shown properly
Christian Brabandt <cb@256bit.org>
parents:
12529
diff
changeset
|
2566 if (comping && sep_comp) |
7 | 2567 { |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12712
diff
changeset
|
2568 # if defined(__APPLE_CC__) && TARGET_API_MAC_CARBON |
536 | 2569 /* Carbon ATSUI autodraws composing char over previous char */ |
2570 gui_mch_draw_string(gui.row, scol, s + i, cl, | |
7 | 2571 draw_flags | DRAW_TRANSP); |
187 | 2572 # else |
536 | 2573 gui_mch_draw_string(gui.row, scol - cn, s + i, cl, |
187 | 2574 draw_flags | DRAW_TRANSP); |
2575 # endif | |
7 | 2576 start = i + cl; |
2577 } | |
4053 | 2578 prev_wide = curr_wide; |
7 | 2579 } |
2580 /* The stuff below assumes "len" is the length in screen columns. */ | |
2581 len = scol - col; | |
2582 } | |
2583 else | |
2584 # endif | |
2585 { | |
2586 gui_mch_draw_string(gui.row, col, s, len, draw_flags); | |
2587 # ifdef FEAT_MBYTE | |
2588 if (enc_dbcs == DBCS_JPNU) | |
2589 { | |
2590 /* Get the length in display cells, this can be different from the | |
2591 * number of bytes for "euc-jp". */ | |
2338
da6ec32d8d8f
Added strwidth() and strchars() functions.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
2592 len = mb_string2cells(s, len); |
7 | 2593 } |
2594 # endif | |
2595 } | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
2596 #endif /* !FEAT_GUI_GTK */ |
7 | 2597 |
2598 if (!(flags & (GUI_MON_IS_CURSOR | GUI_MON_TRS_CURSOR))) | |
2599 gui.col = col + len; | |
2600 | |
2601 /* May need to invert it when it's part of the selection. */ | |
2602 if (flags & GUI_MON_NOCLEAR) | |
2603 clip_may_redraw_selection(gui.row, col, len); | |
2604 | |
2605 if (!(flags & (GUI_MON_IS_CURSOR | GUI_MON_TRS_CURSOR))) | |
2606 { | |
2607 /* Invalidate the old physical cursor position if we wrote over it */ | |
2608 if (gui.cursor_row == gui.row | |
2609 && gui.cursor_col >= col | |
2610 && gui.cursor_col < col + len) | |
2611 gui.cursor_is_valid = FALSE; | |
2612 } | |
2613 | |
2614 #ifdef FEAT_SIGN_ICONS | |
2615 if (draw_sign) | |
2616 /* Draw the sign on top of the spaces. */ | |
2617 gui_mch_drawsign(gui.row, col, gui.highlight_mask); | |
2592 | 2618 # if defined(FEAT_NETBEANS_INTG) && (defined(FEAT_GUI_X11) \ |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2208
diff
changeset
|
2619 || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32)) |
7 | 2620 if (multi_sign) |
2621 netbeans_draw_multisign_indicator(gui.row); | |
2622 # endif | |
2623 #endif | |
2624 | |
2625 return OK; | |
2626 } | |
2627 | |
2628 /* | |
2629 * Un-draw the cursor. Actually this just redraws the character at the given | |
2630 * position. The character just before it too, for when it was in bold. | |
2631 */ | |
2632 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2633 gui_undraw_cursor(void) |
7 | 2634 { |
2635 if (gui.cursor_is_valid) | |
2636 { | |
2637 #ifdef FEAT_HANGULIN | |
2638 if (composing_hangul | |
2639 && gui.col == gui.cursor_col && gui.row == gui.cursor_row) | |
7208
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2640 { |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2641 char_u *comp_buf; |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2642 int comp_len; |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2643 |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2644 comp_buf = hangul_composing_buffer_get(&comp_len); |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2645 if (comp_buf) |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2646 { |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2647 (void)gui_outstr_nowrap(comp_buf, comp_len, |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2648 GUI_MON_IS_CURSOR | GUI_MON_NOCLEAR, |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2649 gui.norm_pixel, gui.back_pixel, 0); |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2650 vim_free(comp_buf); |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2651 } |
2c00f6b312bf
commit https://github.com/vim/vim/commit/72f4cc4a987d123c0ed909c85b9a05f65cef7202
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
2652 } |
7 | 2653 else |
2654 { | |
2655 #endif | |
2656 if (gui_redraw_block(gui.cursor_row, gui.cursor_col, | |
2657 gui.cursor_row, gui.cursor_col, GUI_MON_NOCLEAR) | |
2658 && gui.cursor_col > 0) | |
2659 (void)gui_redraw_block(gui.cursor_row, gui.cursor_col - 1, | |
2660 gui.cursor_row, gui.cursor_col - 1, GUI_MON_NOCLEAR); | |
2661 #ifdef FEAT_HANGULIN | |
2662 if (composing_hangul) | |
2663 (void)gui_redraw_block(gui.cursor_row, gui.cursor_col + 1, | |
2664 gui.cursor_row, gui.cursor_col + 1, GUI_MON_NOCLEAR); | |
2665 } | |
2666 #endif | |
2667 /* Cursor_is_valid is reset when the cursor is undrawn, also reset it | |
2668 * here in case it wasn't needed to undraw it. */ | |
2669 gui.cursor_is_valid = FALSE; | |
2670 } | |
2671 } | |
2672 | |
2673 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2674 gui_redraw( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2675 int x, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2676 int y, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2677 int w, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2678 int h) |
7 | 2679 { |
2680 int row1, col1, row2, col2; | |
2681 | |
2682 row1 = Y_2_ROW(y); | |
2683 col1 = X_2_COL(x); | |
2684 row2 = Y_2_ROW(y + h - 1); | |
2685 col2 = X_2_COL(x + w - 1); | |
2686 | |
2687 (void)gui_redraw_block(row1, col1, row2, col2, GUI_MON_NOCLEAR); | |
2688 | |
2689 /* | |
2690 * We may need to redraw the cursor, but don't take it upon us to change | |
2691 * its location after a scroll. | |
2692 * (maybe be more strict even and test col too?) | |
2693 * These things may be outside the update/clipping region and reality may | |
2694 * not reflect Vims internal ideas if these operations are clipped away. | |
2695 */ | |
2696 if (gui.row == gui.cursor_row) | |
2697 gui_update_cursor(TRUE, TRUE); | |
2698 } | |
2699 | |
2700 /* | |
2701 * Draw a rectangular block of characters, from row1 to row2 (inclusive) and | |
2702 * from col1 to col2 (inclusive). | |
2703 * Return TRUE when the character before the first drawn character has | |
2704 * different attributes (may have to be redrawn too). | |
2705 */ | |
2706 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2707 gui_redraw_block( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2708 int row1, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2709 int col1, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2710 int row2, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2711 int col2, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2712 int flags) /* flags for gui_outstr_nowrap() */ |
7 | 2713 { |
2714 int old_row, old_col; | |
2715 long_u old_hl_mask; | |
2716 int off; | |
203 | 2717 sattr_T first_attr; |
7 | 2718 int idx, len; |
2719 int back, nback; | |
2720 int retval = FALSE; | |
2721 #ifdef FEAT_MBYTE | |
2722 int orig_col1, orig_col2; | |
2723 #endif | |
2724 | |
2725 /* Don't try to update when ScreenLines is not valid */ | |
2726 if (!screen_cleared || ScreenLines == NULL) | |
2727 return retval; | |
2728 | |
2729 /* Don't try to draw outside the shell! */ | |
2730 /* Check everything, strange values may be caused by a big border width */ | |
2731 col1 = check_col(col1); | |
2732 col2 = check_col(col2); | |
2733 row1 = check_row(row1); | |
2734 row2 = check_row(row2); | |
2735 | |
2736 /* Remember where our cursor was */ | |
2737 old_row = gui.row; | |
2738 old_col = gui.col; | |
2739 old_hl_mask = gui.highlight_mask; | |
2740 #ifdef FEAT_MBYTE | |
2741 orig_col1 = col1; | |
2742 orig_col2 = col2; | |
2743 #endif | |
2744 | |
2745 for (gui.row = row1; gui.row <= row2; gui.row++) | |
2746 { | |
2747 #ifdef FEAT_MBYTE | |
2748 /* When only half of a double-wide character is in the block, include | |
2749 * the other half. */ | |
2750 col1 = orig_col1; | |
2751 col2 = orig_col2; | |
2752 off = LineOffset[gui.row]; | |
2753 if (enc_dbcs != 0) | |
2754 { | |
2755 if (col1 > 0) | |
2756 col1 -= dbcs_screen_head_off(ScreenLines + off, | |
2757 ScreenLines + off + col1); | |
2758 col2 += dbcs_screen_tail_off(ScreenLines + off, | |
2759 ScreenLines + off + col2); | |
2760 } | |
2761 else if (enc_utf8) | |
2762 { | |
2763 if (ScreenLines[off + col1] == 0) | |
2764 --col1; | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
2765 # ifdef FEAT_GUI_GTK |
7 | 2766 if (col2 + 1 < Columns && ScreenLines[off + col2 + 1] == 0) |
2767 ++col2; | |
2768 # endif | |
2769 } | |
2770 #endif | |
2771 gui.col = col1; | |
2772 off = LineOffset[gui.row] + gui.col; | |
2773 len = col2 - col1 + 1; | |
2774 | |
2775 /* Find how many chars back this highlighting starts, or where a space | |
2776 * is. Needed for when the bold trick is used */ | |
2777 for (back = 0; back < col1; ++back) | |
2778 if (ScreenAttrs[off - 1 - back] != ScreenAttrs[off] | |
2779 || ScreenLines[off - 1 - back] == ' ') | |
2780 break; | |
2781 retval = (col1 > 0 && ScreenAttrs[off - 1] != 0 && back == 0 | |
2782 && ScreenLines[off - 1] != ' '); | |
2783 | |
2784 /* Break it up in strings of characters with the same attributes. */ | |
2785 /* Print UTF-8 characters individually. */ | |
2786 while (len > 0) | |
2787 { | |
2788 first_attr = ScreenAttrs[off]; | |
2789 gui.highlight_mask = first_attr; | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
2790 #if defined(FEAT_MBYTE) && !defined(FEAT_GUI_GTK) |
7 | 2791 if (enc_utf8 && ScreenLinesUC[off] != 0) |
2792 { | |
2793 /* output multi-byte character separately */ | |
2794 nback = gui_screenchar(off, flags, | |
2795 (guicolor_T)0, (guicolor_T)0, back); | |
2796 if (gui.col < Columns && ScreenLines[off + 1] == 0) | |
2797 idx = 2; | |
2798 else | |
2799 idx = 1; | |
2800 } | |
2801 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
2802 { | |
2803 /* output double-byte, single-width character separately */ | |
2804 nback = gui_screenchar(off, flags, | |
2805 (guicolor_T)0, (guicolor_T)0, back); | |
2806 idx = 1; | |
2807 } | |
2808 else | |
2809 #endif | |
2810 { | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
2811 #ifdef FEAT_GUI_GTK |
7 | 2812 for (idx = 0; idx < len; ++idx) |
2813 { | |
2814 if (enc_utf8 && ScreenLines[off + idx] == 0) | |
2815 continue; /* skip second half of double-width char */ | |
2816 if (ScreenAttrs[off + idx] != first_attr) | |
2817 break; | |
2818 } | |
2819 /* gui_screenstr() takes care of multibyte chars */ | |
2820 nback = gui_screenstr(off, idx, flags, | |
2821 (guicolor_T)0, (guicolor_T)0, back); | |
2822 #else | |
2823 for (idx = 0; idx < len && ScreenAttrs[off + idx] == first_attr; | |
2824 idx++) | |
2825 { | |
2826 # ifdef FEAT_MBYTE | |
2827 /* Stop at a multi-byte Unicode character. */ | |
2828 if (enc_utf8 && ScreenLinesUC[off + idx] != 0) | |
2829 break; | |
2830 if (enc_dbcs == DBCS_JPNU) | |
2831 { | |
2832 /* Stop at a double-byte single-width char. */ | |
2833 if (ScreenLines[off + idx] == 0x8e) | |
2834 break; | |
474 | 2835 if (len > 1 && (*mb_ptr2len)(ScreenLines |
7 | 2836 + off + idx) == 2) |
2837 ++idx; /* skip second byte of double-byte char */ | |
2838 } | |
2839 # endif | |
2840 } | |
2841 nback = gui_outstr_nowrap(ScreenLines + off, idx, flags, | |
2842 (guicolor_T)0, (guicolor_T)0, back); | |
2843 #endif | |
2844 } | |
2845 if (nback == FAIL) | |
2846 { | |
2847 /* Must back up to start drawing where a bold or italic word | |
2848 * starts. */ | |
2849 off -= back; | |
2850 len += back; | |
2851 gui.col -= back; | |
2852 } | |
2853 else | |
2854 { | |
2855 off += idx; | |
2856 len -= idx; | |
2857 } | |
2858 back = 0; | |
2859 } | |
2860 } | |
2861 | |
2862 /* Put the cursor back where it was */ | |
2863 gui.row = old_row; | |
2864 gui.col = old_col; | |
835 | 2865 gui.highlight_mask = (int)old_hl_mask; |
7 | 2866 |
2867 return retval; | |
2868 } | |
2869 | |
2870 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2871 gui_delete_lines(int row, int count) |
7 | 2872 { |
2873 if (count <= 0) | |
2874 return; | |
2875 | |
2876 if (row + count > gui.scroll_region_bot) | |
2877 /* Scrolled out of region, just blank the lines out */ | |
2878 gui_clear_block(row, gui.scroll_region_left, | |
2879 gui.scroll_region_bot, gui.scroll_region_right); | |
2880 else | |
2881 { | |
2882 gui_mch_delete_lines(row, count); | |
2883 | |
2884 /* If the cursor was in the deleted lines it's now gone. If the | |
2885 * cursor was in the scrolled lines adjust its position. */ | |
2886 if (gui.cursor_row >= row | |
2887 && gui.cursor_col >= gui.scroll_region_left | |
2888 && gui.cursor_col <= gui.scroll_region_right) | |
2889 { | |
2890 if (gui.cursor_row < row + count) | |
2891 gui.cursor_is_valid = FALSE; | |
2892 else if (gui.cursor_row <= gui.scroll_region_bot) | |
2893 gui.cursor_row -= count; | |
2894 } | |
2895 } | |
2896 } | |
2897 | |
2898 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
2899 gui_insert_lines(int row, int count) |
7 | 2900 { |
2901 if (count <= 0) | |
2902 return; | |
2903 | |
2904 if (row + count > gui.scroll_region_bot) | |
2905 /* Scrolled out of region, just blank the lines out */ | |
2906 gui_clear_block(row, gui.scroll_region_left, | |
2907 gui.scroll_region_bot, gui.scroll_region_right); | |
2908 else | |
2909 { | |
2910 gui_mch_insert_lines(row, count); | |
2911 | |
2912 if (gui.cursor_row >= gui.row | |
2913 && gui.cursor_col >= gui.scroll_region_left | |
2914 && gui.cursor_col <= gui.scroll_region_right) | |
2915 { | |
2916 if (gui.cursor_row <= gui.scroll_region_bot - count) | |
2917 gui.cursor_row += count; | |
2918 else if (gui.cursor_row <= gui.scroll_region_bot) | |
2919 gui.cursor_is_valid = FALSE; | |
2920 } | |
2921 } | |
2922 } | |
2923 | |
13080
eee366f56b1a
patch 8.0.1415: warning for unused function without timers feature
Christian Brabandt <cb@256bit.org>
parents:
13064
diff
changeset
|
2924 #ifdef FEAT_TIMERS |
11471
26525db57c4c
patch 8.0.0619: GUI gets stuck if timer uses feedkeys()
Christian Brabandt <cb@256bit.org>
parents:
11163
diff
changeset
|
2925 /* |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2926 * Passed to ui_wait_for_chars_or_timer(), ignoring extra arguments. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2927 */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2928 static int |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2929 gui_wait_for_chars_3( |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2930 long wtime, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2931 int *interrupted UNUSED, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2932 int ignore_input UNUSED) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2933 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2934 return gui_mch_wait_for_chars(wtime); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2935 } |
13080
eee366f56b1a
patch 8.0.1415: warning for unused function without timers feature
Christian Brabandt <cb@256bit.org>
parents:
13064
diff
changeset
|
2936 #endif |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2937 |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2938 /* |
11471
26525db57c4c
patch 8.0.0619: GUI gets stuck if timer uses feedkeys()
Christian Brabandt <cb@256bit.org>
parents:
11163
diff
changeset
|
2939 * Returns OK if a character was found to be available within the given time, |
26525db57c4c
patch 8.0.0619: GUI gets stuck if timer uses feedkeys()
Christian Brabandt <cb@256bit.org>
parents:
11163
diff
changeset
|
2940 * or FAIL otherwise. |
26525db57c4c
patch 8.0.0619: GUI gets stuck if timer uses feedkeys()
Christian Brabandt <cb@256bit.org>
parents:
11163
diff
changeset
|
2941 */ |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2942 static int |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2943 gui_wait_for_chars_or_timer(long wtime) |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2944 { |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2945 #ifdef FEAT_TIMERS |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2946 return ui_wait_for_chars_or_timer(wtime, gui_wait_for_chars_3, NULL, 0); |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2947 #else |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2948 return gui_mch_wait_for_chars(wtime); |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2949 #endif |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2950 } |
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2951 |
7 | 2952 /* |
2953 * The main GUI input routine. Waits for a character from the keyboard. | |
2954 * wtime == -1 Wait forever. | |
2955 * wtime == 0 Don't wait. | |
2956 * wtime > 0 Wait wtime milliseconds for a character. | |
2957 * Returns OK if a character was found to be available within the given time, | |
2958 * or FAIL otherwise. | |
2959 */ | |
2960 int | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
2961 gui_wait_for_chars(long wtime, int tb_change_cnt) |
7 | 2962 { |
2963 int retval; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
2964 #if defined(ELAPSED_FUNC) |
13064
dc160dbdcfe2
patch 8.0.1407: GUI: CursorHold may trigger before 'updatetime'
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
2965 ELAPSED_TYPE start_tv; |
dc160dbdcfe2
patch 8.0.1407: GUI: CursorHold may trigger before 'updatetime'
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
2966 #endif |
7 | 2967 |
2208
495995b9ce7d
Fix: window title not updated after file dropped.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
2968 #ifdef FEAT_MENU |
7 | 2969 /* |
2970 * If we're going to wait a bit, update the menus and mouse shape for the | |
2971 * current State. | |
2972 */ | |
2973 if (wtime != 0) | |
2974 gui_update_menus(0); | |
2975 #endif | |
2976 | |
2977 gui_mch_update(); | |
2978 if (input_available()) /* Got char, return immediately */ | |
2979 return OK; | |
2980 if (wtime == 0) /* Don't wait for char */ | |
2981 return FAIL; | |
2982 | |
2983 /* Before waiting, flush any output to the screen. */ | |
2984 gui_mch_flush(); | |
2985 | |
2986 if (wtime > 0) | |
2987 { | |
2988 /* Blink when waiting for a character. Probably only does something | |
2989 * for showmatch() */ | |
2990 gui_mch_start_blink(); | |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
2991 retval = gui_wait_for_chars_or_timer(wtime); |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
2992 gui_mch_stop_blink(TRUE); |
7 | 2993 return retval; |
2994 } | |
2995 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
2996 #if defined(ELAPSED_FUNC) |
13064
dc160dbdcfe2
patch 8.0.1407: GUI: CursorHold may trigger before 'updatetime'
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
2997 ELAPSED_INIT(start_tv); |
dc160dbdcfe2
patch 8.0.1407: GUI: CursorHold may trigger before 'updatetime'
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
2998 #endif |
dc160dbdcfe2
patch 8.0.1407: GUI: CursorHold may trigger before 'updatetime'
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
2999 |
7 | 3000 /* |
1199 | 3001 * While we are waiting indefinitely for a character, blink the cursor. |
7 | 3002 */ |
3003 gui_mch_start_blink(); | |
3004 | |
203 | 3005 retval = FAIL; |
3006 /* | |
3007 * We may want to trigger the CursorHold event. First wait for | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3008 * 'updatetime' and if nothing is typed within that time, and feedkeys() |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3009 * wasn't used, put the K_CURSORHOLD key in the input buffer. |
203 | 3010 */ |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3011 if (gui_wait_for_chars_or_timer(p_ut) == OK) |
203 | 3012 retval = OK; |
13064
dc160dbdcfe2
patch 8.0.1407: GUI: CursorHold may trigger before 'updatetime'
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
3013 else if (trigger_cursorhold() |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
3014 #ifdef ELAPSED_FUNC |
13064
dc160dbdcfe2
patch 8.0.1407: GUI: CursorHold may trigger before 'updatetime'
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
3015 && ELAPSED_FUNC(start_tv) >= p_ut |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
3016 #endif |
13064
dc160dbdcfe2
patch 8.0.1407: GUI: CursorHold may trigger before 'updatetime'
Christian Brabandt <cb@256bit.org>
parents:
13060
diff
changeset
|
3017 && typebuf.tb_change_cnt == tb_change_cnt) |
7 | 3018 { |
203 | 3019 char_u buf[3]; |
3020 | |
3021 /* Put K_CURSORHOLD in the input buffer. */ | |
3022 buf[0] = CSI; | |
3023 buf[1] = KS_EXTRA; | |
3024 buf[2] = (int)KE_CURSORHOLD; | |
3025 add_to_input_buf(buf, 3); | |
3026 | |
3027 retval = OK; | |
3028 } | |
3029 | |
11471
26525db57c4c
patch 8.0.0619: GUI gets stuck if timer uses feedkeys()
Christian Brabandt <cb@256bit.org>
parents:
11163
diff
changeset
|
3030 if (retval == FAIL && typebuf.tb_change_cnt == tb_change_cnt) |
203 | 3031 { |
3032 /* Blocking wait. */ | |
368 | 3033 before_blocking(); |
8577
63dc856bd13d
commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
3034 retval = gui_wait_for_chars_or_timer(-1L); |
7 | 3035 } |
3036 | |
13152
f4c3a7f410f4
patch 8.0.1450: GUI: endless loop when stopping cursor blinking
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
3037 gui_mch_stop_blink(TRUE); |
7 | 3038 return retval; |
3039 } | |
3040 | |
3041 /* | |
13060
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3042 * Equivalent of mch_inchar() for the GUI. |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3043 */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3044 int |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3045 gui_inchar( |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3046 char_u *buf, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3047 int maxlen, |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3048 long wtime, /* milli seconds */ |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3049 int tb_change_cnt) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3050 { |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3051 if (gui_wait_for_chars(wtime, tb_change_cnt) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3052 && !typebuf_changed(tb_change_cnt)) |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3053 return read_from_input_buf(buf, (long)maxlen); |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3054 return 0; |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3055 } |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3056 |
1bdc12630fc0
patch 8.0.1405: duplicated code for getting a typed character
Christian Brabandt <cb@256bit.org>
parents:
13052
diff
changeset
|
3057 /* |
1137 | 3058 * Fill p[4] with mouse coordinates encoded for check_termcode(). |
7 | 3059 */ |
3060 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3061 fill_mouse_coord(char_u *p, int col, int row) |
7 | 3062 { |
3063 p[0] = (char_u)(col / 128 + ' ' + 1); | |
3064 p[1] = (char_u)(col % 128 + ' ' + 1); | |
3065 p[2] = (char_u)(row / 128 + ' ' + 1); | |
3066 p[3] = (char_u)(row % 128 + ' ' + 1); | |
3067 } | |
3068 | |
3069 /* | |
3070 * Generic mouse support function. Add a mouse event to the input buffer with | |
3071 * the given properties. | |
3072 * button --- may be any of MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT, | |
3073 * MOUSE_X1, MOUSE_X2 | |
3074 * MOUSE_DRAG, or MOUSE_RELEASE. | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3075 * MOUSE_4 and MOUSE_5 are used for vertical scroll wheel, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3076 * MOUSE_6 and MOUSE_7 for horizontal scroll wheel. |
7 | 3077 * x, y --- Coordinates of mouse in pixels. |
3078 * repeated_click --- TRUE if this click comes only a short time after a | |
3079 * previous click. | |
3080 * modifiers --- Bit field which may be any of the following modifiers | |
3081 * or'ed together: MOUSE_SHIFT | MOUSE_CTRL | MOUSE_ALT. | |
3082 * This function will ignore drag events where the mouse has not moved to a new | |
3083 * character. | |
3084 */ | |
3085 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3086 gui_send_mouse_event( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3087 int button, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3088 int x, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3089 int y, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3090 int repeated_click, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3091 int_u modifiers) |
7 | 3092 { |
3093 static int prev_row = 0, prev_col = 0; | |
3094 static int prev_button = -1; | |
3095 static int num_clicks = 1; | |
3096 char_u string[10]; | |
3097 enum key_extra button_char; | |
3098 int row, col; | |
3099 #ifdef FEAT_CLIPBOARD | |
3100 int checkfor; | |
3101 int did_clip = FALSE; | |
3102 #endif | |
3103 | |
3104 /* | |
3105 * Scrolling may happen at any time, also while a selection is present. | |
3106 */ | |
3107 switch (button) | |
3108 { | |
3109 case MOUSE_X1: | |
3110 button_char = KE_X1MOUSE; | |
3111 goto button_set; | |
3112 case MOUSE_X2: | |
3113 button_char = KE_X2MOUSE; | |
3114 goto button_set; | |
3115 case MOUSE_4: | |
3116 button_char = KE_MOUSEDOWN; | |
3117 goto button_set; | |
3118 case MOUSE_5: | |
3119 button_char = KE_MOUSEUP; | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3120 goto button_set; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3121 case MOUSE_6: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3122 button_char = KE_MOUSELEFT; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3123 goto button_set; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3124 case MOUSE_7: |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
3125 button_char = KE_MOUSERIGHT; |
7 | 3126 button_set: |
3127 { | |
3128 /* Don't put events in the input queue now. */ | |
3129 if (hold_gui_events) | |
3130 return; | |
3131 | |
3132 string[3] = CSI; | |
3133 string[4] = KS_EXTRA; | |
3134 string[5] = (int)button_char; | |
3135 | |
3136 /* Pass the pointer coordinates of the scroll event so that we | |
3137 * know which window to scroll. */ | |
3138 row = gui_xy2colrow(x, y, &col); | |
3139 string[6] = (char_u)(col / 128 + ' ' + 1); | |
3140 string[7] = (char_u)(col % 128 + ' ' + 1); | |
3141 string[8] = (char_u)(row / 128 + ' ' + 1); | |
3142 string[9] = (char_u)(row % 128 + ' ' + 1); | |
3143 | |
3144 if (modifiers == 0) | |
3145 add_to_input_buf(string + 3, 7); | |
3146 else | |
3147 { | |
3148 string[0] = CSI; | |
3149 string[1] = KS_MODIFIER; | |
3150 string[2] = 0; | |
3151 if (modifiers & MOUSE_SHIFT) | |
3152 string[2] |= MOD_MASK_SHIFT; | |
3153 if (modifiers & MOUSE_CTRL) | |
3154 string[2] |= MOD_MASK_CTRL; | |
3155 if (modifiers & MOUSE_ALT) | |
3156 string[2] |= MOD_MASK_ALT; | |
3157 add_to_input_buf(string, 10); | |
3158 } | |
3159 return; | |
3160 } | |
3161 } | |
3162 | |
3163 #ifdef FEAT_CLIPBOARD | |
3164 /* If a clipboard selection is in progress, handle it */ | |
3165 if (clip_star.state == SELECT_IN_PROGRESS) | |
3166 { | |
3167 clip_process_selection(button, X_2_COL(x), Y_2_ROW(y), repeated_click); | |
3168 return; | |
3169 } | |
3170 | |
3171 /* Determine which mouse settings to look for based on the current mode */ | |
3172 switch (get_real_state()) | |
3173 { | |
3174 case NORMAL_BUSY: | |
3175 case OP_PENDING: | |
12822
0eb12ef4f8ba
patch 8.0.1288: GUI: cannot drag the statusline of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
3176 # ifdef FEAT_TERMINAL |
0eb12ef4f8ba
patch 8.0.1288: GUI: cannot drag the statusline of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
3177 case TERMINAL: |
0eb12ef4f8ba
patch 8.0.1288: GUI: cannot drag the statusline of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
3178 # endif |
7 | 3179 case NORMAL: checkfor = MOUSE_NORMAL; break; |
3180 case VISUAL: checkfor = MOUSE_VISUAL; break; | |
788 | 3181 case SELECTMODE: checkfor = MOUSE_VISUAL; break; |
7 | 3182 case REPLACE: |
3183 case REPLACE+LANGMAP: | |
12822
0eb12ef4f8ba
patch 8.0.1288: GUI: cannot drag the statusline of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
3184 # ifdef FEAT_VREPLACE |
7 | 3185 case VREPLACE: |
3186 case VREPLACE+LANGMAP: | |
12822
0eb12ef4f8ba
patch 8.0.1288: GUI: cannot drag the statusline of a terminal window
Christian Brabandt <cb@256bit.org>
parents:
12802
diff
changeset
|
3187 # endif |
7 | 3188 case INSERT: |
3189 case INSERT+LANGMAP: checkfor = MOUSE_INSERT; break; | |
3190 case ASKMORE: | |
3191 case HITRETURN: /* At the more- and hit-enter prompt pass the | |
3192 mouse event for a click on or below the | |
3193 message line. */ | |
3194 if (Y_2_ROW(y) >= msg_row) | |
3195 checkfor = MOUSE_NORMAL; | |
3196 else | |
3197 checkfor = MOUSE_RETURN; | |
3198 break; | |
3199 | |
3200 /* | |
3201 * On the command line, use the clipboard selection on all lines | |
3202 * but the command line. But not when pasting. | |
3203 */ | |
3204 case CMDLINE: | |
3205 case CMDLINE+LANGMAP: | |
3206 if (Y_2_ROW(y) < cmdline_row && button != MOUSE_MIDDLE) | |
3207 checkfor = MOUSE_NONE; | |
3208 else | |
3209 checkfor = MOUSE_COMMAND; | |
3210 break; | |
3211 | |
3212 default: | |
3213 checkfor = MOUSE_NONE; | |
3214 break; | |
3215 }; | |
3216 | |
3217 /* | |
3218 * Allow clipboard selection of text on the command line in "normal" | |
3219 * modes. Don't do this when dragging the status line, or extending a | |
3220 * Visual selection. | |
3221 */ | |
3222 if ((State == NORMAL || State == NORMAL_BUSY || (State & INSERT)) | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12457
diff
changeset
|
3223 && Y_2_ROW(y) >= topframe->fr_height + firstwin->w_winrow |
7 | 3224 && button != MOUSE_DRAG |
3225 # ifdef FEAT_MOUSESHAPE | |
3226 && !drag_status_line | |
3227 && !drag_sep_line | |
3228 # endif | |
3229 ) | |
3230 checkfor = MOUSE_NONE; | |
3231 | |
3232 /* | |
3233 * Use modeless selection when holding CTRL and SHIFT pressed. | |
3234 */ | |
3235 if ((modifiers & MOUSE_CTRL) && (modifiers & MOUSE_SHIFT)) | |
3236 checkfor = MOUSE_NONEF; | |
3237 | |
3238 /* | |
3239 * In Ex mode, always use modeless selection. | |
3240 */ | |
3241 if (exmode_active) | |
3242 checkfor = MOUSE_NONE; | |
3243 | |
3244 /* | |
3245 * If the mouse settings say to not use the mouse, use the modeless | |
3246 * selection. But if Visual is active, assume that only the Visual area | |
3247 * will be selected. | |
3248 * Exception: On the command line, both the selection is used and a mouse | |
3249 * key is send. | |
3250 */ | |
3251 if (!mouse_has(checkfor) || checkfor == MOUSE_COMMAND) | |
3252 { | |
3253 /* Don't do modeless selection in Visual mode. */ | |
3254 if (checkfor != MOUSE_NONEF && VIsual_active && (State & NORMAL)) | |
3255 return; | |
3256 | |
3257 /* | |
3258 * When 'mousemodel' is "popup", shift-left is translated to right. | |
3259 * But not when also using Ctrl. | |
3260 */ | |
3261 if (mouse_model_popup() && button == MOUSE_LEFT | |
3262 && (modifiers & MOUSE_SHIFT) && !(modifiers & MOUSE_CTRL)) | |
3263 { | |
3264 button = MOUSE_RIGHT; | |
3265 modifiers &= ~ MOUSE_SHIFT; | |
3266 } | |
3267 | |
3268 /* If the selection is done, allow the right button to extend it. | |
3269 * If the selection is cleared, allow the right button to start it | |
3270 * from the cursor position. */ | |
3271 if (button == MOUSE_RIGHT) | |
3272 { | |
3273 if (clip_star.state == SELECT_CLEARED) | |
3274 { | |
3275 if (State & CMDLINE) | |
3276 { | |
3277 col = msg_col; | |
3278 row = msg_row; | |
3279 } | |
3280 else | |
3281 { | |
3282 col = curwin->w_wcol; | |
3283 row = curwin->w_wrow + W_WINROW(curwin); | |
3284 } | |
3285 clip_start_selection(col, row, FALSE); | |
3286 } | |
3287 clip_process_selection(button, X_2_COL(x), Y_2_ROW(y), | |
3288 repeated_click); | |
3289 did_clip = TRUE; | |
3290 } | |
3291 /* Allow the left button to start the selection */ | |
2823 | 3292 else if (button == MOUSE_LEFT) |
7 | 3293 { |
3294 clip_start_selection(X_2_COL(x), Y_2_ROW(y), repeated_click); | |
3295 did_clip = TRUE; | |
3296 } | |
3297 | |
3298 /* Always allow pasting */ | |
3299 if (button != MOUSE_MIDDLE) | |
3300 { | |
3301 if (!mouse_has(checkfor) || button == MOUSE_RELEASE) | |
3302 return; | |
3303 if (checkfor != MOUSE_COMMAND) | |
3304 button = MOUSE_LEFT; | |
3305 } | |
3306 repeated_click = FALSE; | |
3307 } | |
3308 | |
3309 if (clip_star.state != SELECT_CLEARED && !did_clip) | |
3674 | 3310 clip_clear_selection(&clip_star); |
7 | 3311 #endif |
3312 | |
3313 /* Don't put events in the input queue now. */ | |
3314 if (hold_gui_events) | |
3315 return; | |
3316 | |
3317 row = gui_xy2colrow(x, y, &col); | |
3318 | |
3319 /* | |
3320 * If we are dragging and the mouse hasn't moved far enough to be on a | |
3321 * different character, then don't send an event to vim. | |
3322 */ | |
3323 if (button == MOUSE_DRAG) | |
3324 { | |
3325 if (row == prev_row && col == prev_col) | |
3326 return; | |
3327 /* Dragging above the window, set "row" to -1 to cause a scroll. */ | |
3328 if (y < 0) | |
3329 row = -1; | |
3330 } | |
3331 | |
3332 /* | |
3333 * If topline has changed (window scrolled) since the last click, reset | |
3334 * repeated_click, because we don't want starting Visual mode when | |
3335 * clicking on a different character in the text. | |
3336 */ | |
3337 if (curwin->w_topline != gui_prev_topline | |
3338 #ifdef FEAT_DIFF | |
3339 || curwin->w_topfill != gui_prev_topfill | |
3340 #endif | |
3341 ) | |
3342 repeated_click = FALSE; | |
3343 | |
3344 string[0] = CSI; /* this sequence is recognized by check_termcode() */ | |
3345 string[1] = KS_MOUSE; | |
3346 string[2] = KE_FILLER; | |
3347 if (button != MOUSE_DRAG && button != MOUSE_RELEASE) | |
3348 { | |
3349 if (repeated_click) | |
3350 { | |
3351 /* | |
3352 * Handle multiple clicks. They only count if the mouse is still | |
3353 * pointing at the same character. | |
3354 */ | |
3355 if (button != prev_button || row != prev_row || col != prev_col) | |
3356 num_clicks = 1; | |
3357 else if (++num_clicks > 4) | |
3358 num_clicks = 1; | |
3359 } | |
3360 else | |
3361 num_clicks = 1; | |
3362 prev_button = button; | |
3363 gui_prev_topline = curwin->w_topline; | |
3364 #ifdef FEAT_DIFF | |
3365 gui_prev_topfill = curwin->w_topfill; | |
3366 #endif | |
3367 | |
3368 string[3] = (char_u)(button | 0x20); | |
3369 SET_NUM_MOUSE_CLICKS(string[3], num_clicks); | |
3370 } | |
3371 else | |
3372 string[3] = (char_u)button; | |
3373 | |
3374 string[3] |= modifiers; | |
3375 fill_mouse_coord(string + 4, col, row); | |
3376 add_to_input_buf(string, 8); | |
3377 | |
3378 if (row < 0) | |
3379 prev_row = 0; | |
3380 else | |
3381 prev_row = row; | |
3382 prev_col = col; | |
3383 | |
3384 /* | |
3385 * We need to make sure this is cleared since Athena doesn't tell us when | |
3386 * he is done dragging. Neither does GTK+ 2 -- at least for now. | |
3387 */ | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
3388 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_GTK) |
7 | 3389 gui.dragged_sb = SBAR_NONE; |
3390 #endif | |
3391 } | |
3392 | |
3393 /* | |
3394 * Convert x and y coordinate to column and row in text window. | |
3395 * Corrects for multi-byte character. | |
3396 * returns column in "*colp" and row as return value; | |
3397 */ | |
3398 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3399 gui_xy2colrow(int x, int y, int *colp) |
7 | 3400 { |
3401 int col = check_col(X_2_COL(x)); | |
3402 int row = check_row(Y_2_ROW(y)); | |
3403 | |
3404 #ifdef FEAT_MBYTE | |
3405 *colp = mb_fix_col(col, row); | |
3406 #else | |
3407 *colp = col; | |
3408 #endif | |
3409 return row; | |
3410 } | |
3411 | |
3412 #if defined(FEAT_MENU) || defined(PROTO) | |
3413 /* | |
3414 * Callback function for when a menu entry has been selected. | |
3415 */ | |
3416 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3417 gui_menu_cb(vimmenu_T *menu) |
7 | 3418 { |
664 | 3419 char_u bytes[sizeof(long_u)]; |
7 | 3420 |
3421 /* Don't put events in the input queue now. */ | |
3422 if (hold_gui_events) | |
3423 return; | |
3424 | |
3425 bytes[0] = CSI; | |
3426 bytes[1] = KS_MENU; | |
3427 bytes[2] = KE_FILLER; | |
664 | 3428 add_to_input_buf(bytes, 3); |
3429 add_long_to_buf((long_u)menu, bytes); | |
3430 add_to_input_buf_csi(bytes, sizeof(long_u)); | |
7 | 3431 } |
3432 #endif | |
3433 | |
811 | 3434 static int prev_which_scrollbars[3]; |
669 | 3435 |
7 | 3436 /* |
3437 * Set which components are present. | |
685 | 3438 * If "oldval" is not NULL, "oldval" is the previous value, the new value is |
7 | 3439 * in p_go. |
3440 */ | |
3441 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3442 gui_init_which_components(char_u *oldval UNUSED) |
7 | 3443 { |
3444 #ifdef FEAT_MENU | |
3445 static int prev_menu_is_active = -1; | |
3446 #endif | |
3447 #ifdef FEAT_TOOLBAR | |
3448 static int prev_toolbar = -1; | |
3449 int using_toolbar = FALSE; | |
3450 #endif | |
685 | 3451 #ifdef FEAT_GUI_TABLINE |
3452 int using_tabline; | |
3453 #endif | |
7 | 3454 #ifdef FEAT_FOOTER |
3455 static int prev_footer = -1; | |
3456 int using_footer = FALSE; | |
3457 #endif | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3458 #if defined(FEAT_MENU) |
7 | 3459 static int prev_tearoff = -1; |
3460 int using_tearoff = FALSE; | |
3461 #endif | |
3462 | |
3463 char_u *p; | |
3464 int i; | |
3465 #ifdef FEAT_MENU | |
3466 int grey_old, grey_new; | |
3467 char_u *temp; | |
3468 #endif | |
3469 win_T *wp; | |
3470 int need_set_size; | |
3471 int fix_size; | |
3472 | |
3473 #ifdef FEAT_MENU | |
3474 if (oldval != NULL && gui.in_use) | |
3475 { | |
3476 /* | |
3477 * Check if the menu's go from grey to non-grey or vise versa. | |
3478 */ | |
3479 grey_old = (vim_strchr(oldval, GO_GREY) != NULL); | |
3480 grey_new = (vim_strchr(p_go, GO_GREY) != NULL); | |
3481 if (grey_old != grey_new) | |
3482 { | |
3483 temp = p_go; | |
3484 p_go = oldval; | |
3485 gui_update_menus(MENU_ALL_MODES); | |
3486 p_go = temp; | |
3487 } | |
3488 } | |
3489 gui.menu_is_active = FALSE; | |
3490 #endif | |
3491 | |
3492 for (i = 0; i < 3; i++) | |
3493 gui.which_scrollbars[i] = FALSE; | |
3494 for (p = p_go; *p; p++) | |
3495 switch (*p) | |
3496 { | |
3497 case GO_LEFT: | |
3498 gui.which_scrollbars[SBAR_LEFT] = TRUE; | |
3499 break; | |
3500 case GO_RIGHT: | |
3501 gui.which_scrollbars[SBAR_RIGHT] = TRUE; | |
3502 break; | |
3503 case GO_VLEFT: | |
3504 if (win_hasvertsplit()) | |
3505 gui.which_scrollbars[SBAR_LEFT] = TRUE; | |
3506 break; | |
3507 case GO_VRIGHT: | |
3508 if (win_hasvertsplit()) | |
3509 gui.which_scrollbars[SBAR_RIGHT] = TRUE; | |
3510 break; | |
3511 case GO_BOT: | |
3512 gui.which_scrollbars[SBAR_BOTTOM] = TRUE; | |
3513 break; | |
3514 #ifdef FEAT_MENU | |
3515 case GO_MENUS: | |
3516 gui.menu_is_active = TRUE; | |
3517 break; | |
3518 #endif | |
3519 case GO_GREY: | |
3520 /* make menu's have grey items, ignored here */ | |
3521 break; | |
3522 #ifdef FEAT_TOOLBAR | |
3523 case GO_TOOLBAR: | |
3524 using_toolbar = TRUE; | |
3525 break; | |
3526 #endif | |
3527 #ifdef FEAT_FOOTER | |
3528 case GO_FOOTER: | |
3529 using_footer = TRUE; | |
3530 break; | |
3531 #endif | |
3532 case GO_TEAROFF: | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3533 #if defined(FEAT_MENU) |
7 | 3534 using_tearoff = TRUE; |
3535 #endif | |
3536 break; | |
3537 default: | |
3538 /* Ignore options that are not supported */ | |
3539 break; | |
3540 } | |
685 | 3541 |
7 | 3542 if (gui.in_use) |
3543 { | |
811 | 3544 need_set_size = 0; |
7 | 3545 fix_size = FALSE; |
685 | 3546 |
3547 #ifdef FEAT_GUI_TABLINE | |
687 | 3548 /* Update the GUI tab line, it may appear or disappear. This may |
3549 * cause the non-GUI tab line to disappear or appear. */ | |
685 | 3550 using_tabline = gui_has_tabline(); |
706 | 3551 if (!gui_mch_showing_tabline() != !using_tabline) |
685 | 3552 { |
797 | 3553 /* We don't want a resize event change "Rows" here, save and |
3554 * restore it. Resizing is handled below. */ | |
3555 i = Rows; | |
685 | 3556 gui_update_tabline(); |
797 | 3557 Rows = i; |
1767 | 3558 need_set_size |= RESIZE_VERT; |
685 | 3559 if (using_tabline) |
3560 fix_size = TRUE; | |
3561 if (!gui_use_tabline()) | |
3562 redraw_tabline = TRUE; /* may draw non-GUI tab line */ | |
3563 } | |
3564 #endif | |
3565 | |
7 | 3566 for (i = 0; i < 3; i++) |
3567 { | |
811 | 3568 /* The scrollbar needs to be updated when it is shown/unshown and |
3569 * when switching tab pages. But the size only changes when it's | |
3570 * shown/unshown. Thus we need two places to remember whether a | |
3571 * scrollbar is there or not. */ | |
3572 if (gui.which_scrollbars[i] != prev_which_scrollbars[i] | |
3573 || gui.which_scrollbars[i] | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12457
diff
changeset
|
3574 != curtab->tp_prev_which_scrollbars[i]) |
7 | 3575 { |
3576 if (i == SBAR_BOTTOM) | |
3577 gui_mch_enable_scrollbar(&gui.bottom_sbar, | |
3578 gui.which_scrollbars[i]); | |
3579 else | |
3580 { | |
3581 FOR_ALL_WINDOWS(wp) | |
3582 { | |
3583 gui_do_scrollbar(wp, i, gui.which_scrollbars[i]); | |
3584 } | |
3585 } | |
811 | 3586 if (gui.which_scrollbars[i] != prev_which_scrollbars[i]) |
3587 { | |
3588 if (i == SBAR_BOTTOM) | |
1767 | 3589 need_set_size |= RESIZE_VERT; |
811 | 3590 else |
1767 | 3591 need_set_size |= RESIZE_HOR; |
811 | 3592 if (gui.which_scrollbars[i]) |
3593 fix_size = TRUE; | |
3594 } | |
7 | 3595 } |
811 | 3596 curtab->tp_prev_which_scrollbars[i] = gui.which_scrollbars[i]; |
3597 prev_which_scrollbars[i] = gui.which_scrollbars[i]; | |
7 | 3598 } |
3599 | |
3600 #ifdef FEAT_MENU | |
3601 if (gui.menu_is_active != prev_menu_is_active) | |
3602 { | |
3603 /* We don't want a resize event change "Rows" here, save and | |
3604 * restore it. Resizing is handled below. */ | |
3605 i = Rows; | |
3606 gui_mch_enable_menu(gui.menu_is_active); | |
3607 Rows = i; | |
3608 prev_menu_is_active = gui.menu_is_active; | |
1767 | 3609 need_set_size |= RESIZE_VERT; |
7 | 3610 if (gui.menu_is_active) |
3611 fix_size = TRUE; | |
3612 } | |
3613 #endif | |
3614 | |
3615 #ifdef FEAT_TOOLBAR | |
3616 if (using_toolbar != prev_toolbar) | |
3617 { | |
3618 gui_mch_show_toolbar(using_toolbar); | |
3619 prev_toolbar = using_toolbar; | |
1767 | 3620 need_set_size |= RESIZE_VERT; |
7 | 3621 if (using_toolbar) |
3622 fix_size = TRUE; | |
3623 } | |
3624 #endif | |
3625 #ifdef FEAT_FOOTER | |
3626 if (using_footer != prev_footer) | |
3627 { | |
3628 gui_mch_enable_footer(using_footer); | |
3629 prev_footer = using_footer; | |
1767 | 3630 need_set_size |= RESIZE_VERT; |
7 | 3631 if (using_footer) |
3632 fix_size = TRUE; | |
3633 } | |
3634 #endif | |
8140
563c923b1584
commit https://github.com/vim/vim/commit/cf7164a088664961e7d70dd100c5874dc5ceb293
Christian Brabandt <cb@256bit.org>
parents:
7821
diff
changeset
|
3635 #if defined(FEAT_MENU) && !(defined(WIN3264) && !defined(FEAT_TEAROFF)) |
7 | 3636 if (using_tearoff != prev_tearoff) |
3637 { | |
3638 gui_mch_toggle_tearoffs(using_tearoff); | |
3639 prev_tearoff = using_tearoff; | |
3640 } | |
3641 #endif | |
1767 | 3642 if (need_set_size != 0) |
276 | 3643 { |
3644 #ifdef FEAT_GUI_GTK | |
1767 | 3645 long prev_Columns = Columns; |
3646 long prev_Rows = Rows; | |
276 | 3647 #endif |
7 | 3648 /* Adjust the size of the window to make the text area keep the |
3649 * same size and to avoid that part of our window is off-screen | |
3650 * and a scrollbar can't be used, for example. */ | |
811 | 3651 gui_set_shellsize(FALSE, fix_size, need_set_size); |
276 | 3652 |
3653 #ifdef FEAT_GUI_GTK | |
3654 /* GTK has the annoying habit of sending us resize events when | |
3655 * changing the window size ourselves. This mostly happens when | |
3656 * waiting for a character to arrive, quite unpredictably, and may | |
3657 * change Columns and Rows when we don't want it. Wait for a | |
3658 * character here to avoid this effect. | |
3659 * If you remove this, please test this command for resizing | |
292 | 3660 * effects (with optional left scrollbar): ":vsp|q|vsp|q|vsp|q". |
687 | 3661 * Don't do this while starting up though. |
1767 | 3662 * Don't change Rows when adding menu/toolbar/tabline. |
3663 * Don't change Columns when adding vertical toolbar. */ | |
3664 if (!gui.starting && need_set_size != (RESIZE_VERT | RESIZE_HOR)) | |
287 | 3665 (void)char_avail(); |
1767 | 3666 if ((need_set_size & RESIZE_VERT) == 0) |
3667 Rows = prev_Rows; | |
3668 if ((need_set_size & RESIZE_HOR) == 0) | |
3669 Columns = prev_Columns; | |
276 | 3670 #endif |
3671 } | |
687 | 3672 /* When the console tabline appears or disappears the window positions |
3673 * change. */ | |
3674 if (firstwin->w_winrow != tabline_height()) | |
3675 shell_new_rows(); /* recompute window positions and heights */ | |
7 | 3676 } |
3677 } | |
3678 | |
685 | 3679 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
3680 /* | |
3681 * Return TRUE if the GUI is taking care of the tabline. | |
3682 * It may still be hidden if 'showtabline' is zero. | |
3683 */ | |
3684 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3685 gui_use_tabline(void) |
685 | 3686 { |
3687 return gui.in_use && vim_strchr(p_go, GO_TABLINE) != NULL; | |
3688 } | |
3689 | |
3690 /* | |
3691 * Return TRUE if the GUI is showing the tabline. | |
3692 * This uses 'showtabline'. | |
3693 */ | |
3694 static int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3695 gui_has_tabline(void) |
685 | 3696 { |
3697 if (!gui_use_tabline() | |
3698 || p_stal == 0 | |
3699 || (p_stal == 1 && first_tabpage->tp_next == NULL)) | |
3700 return FALSE; | |
3701 return TRUE; | |
3702 } | |
3703 | |
3704 /* | |
3705 * Update the tabline. | |
3706 * This may display/undisplay the tabline and update the labels. | |
3707 */ | |
3708 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3709 gui_update_tabline(void) |
685 | 3710 { |
3711 int showit = gui_has_tabline(); | |
797 | 3712 int shown = gui_mch_showing_tabline(); |
685 | 3713 |
3714 if (!gui.starting && starting == 0) | |
3715 { | |
848 | 3716 /* Updating the tabline uses direct GUI commands, flush |
3717 * outstanding instructions first. (esp. clear screen) */ | |
3718 out_flush(); | |
3719 | |
797 | 3720 if (!showit != !shown) |
3721 gui_mch_show_tabline(showit); | |
685 | 3722 if (showit != 0) |
3723 gui_mch_update_tabline(); | |
797 | 3724 |
3725 /* When the tabs change from hidden to shown or from shown to | |
3726 * hidden the size of the text area should remain the same. */ | |
3727 if (!showit != !shown) | |
811 | 3728 gui_set_shellsize(FALSE, showit, RESIZE_VERT); |
685 | 3729 } |
3730 } | |
3731 | |
3732 /* | |
839 | 3733 * Get the label or tooltip for tab page "tp" into NameBuff[]. |
685 | 3734 */ |
3735 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3736 get_tabline_label( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3737 tabpage_T *tp, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3738 int tooltip) /* TRUE: get tooltip */ |
685 | 3739 { |
3740 int modified = FALSE; | |
3741 char_u buf[40]; | |
3742 int wincount; | |
3743 win_T *wp; | |
857 | 3744 char_u **opt; |
839 | 3745 |
3746 /* Use 'guitablabel' or 'guitabtooltip' if it's set. */ | |
857 | 3747 opt = (tooltip ? &p_gtt : &p_gtl); |
3748 if (**opt != NUL) | |
685 | 3749 { |
687 | 3750 int use_sandbox = FALSE; |
3751 int save_called_emsg = called_emsg; | |
3752 char_u res[MAXPATHL]; | |
706 | 3753 tabpage_T *save_curtab; |
839 | 3754 char_u *opt_name = (char_u *)(tooltip ? "guitabtooltip" |
3755 : "guitablabel"); | |
687 | 3756 |
3757 called_emsg = FALSE; | |
3758 | |
3759 printer_page_num = tabpage_index(tp); | |
3760 # ifdef FEAT_EVAL | |
3761 set_vim_var_nr(VV_LNUM, printer_page_num); | |
839 | 3762 use_sandbox = was_set_insecurely(opt_name, 0); |
687 | 3763 # endif |
706 | 3764 /* It's almost as going to the tabpage, but without autocommands. */ |
3765 curtab->tp_firstwin = firstwin; | |
3766 curtab->tp_lastwin = lastwin; | |
3767 curtab->tp_curwin = curwin; | |
3768 save_curtab = curtab; | |
3769 curtab = tp; | |
3770 topframe = curtab->tp_topframe; | |
3771 firstwin = curtab->tp_firstwin; | |
3772 lastwin = curtab->tp_lastwin; | |
3773 curwin = curtab->tp_curwin; | |
3774 curbuf = curwin->w_buffer; | |
3775 | |
687 | 3776 /* Can't use NameBuff directly, build_stl_str_hl() uses it. */ |
857 | 3777 build_stl_str_hl(curwin, res, MAXPATHL, *opt, use_sandbox, |
706 | 3778 0, (int)Columns, NULL, NULL); |
687 | 3779 STRCPY(NameBuff, res); |
3780 | |
706 | 3781 /* Back to the original curtab. */ |
3782 curtab = save_curtab; | |
3783 topframe = curtab->tp_topframe; | |
3784 firstwin = curtab->tp_firstwin; | |
3785 lastwin = curtab->tp_lastwin; | |
3786 curwin = curtab->tp_curwin; | |
3787 curbuf = curwin->w_buffer; | |
3788 | |
687 | 3789 if (called_emsg) |
839 | 3790 set_string_option_direct(opt_name, -1, |
694 | 3791 (char_u *)"", OPT_FREE, SID_ERROR); |
687 | 3792 called_emsg |= save_called_emsg; |
3793 } | |
857 | 3794 |
3795 /* If 'guitablabel'/'guitabtooltip' is not set or the result is empty then | |
3796 * use a default label. */ | |
3797 if (**opt == NUL || *NameBuff == NUL) | |
687 | 3798 { |
819 | 3799 /* Get the buffer name into NameBuff[] and shorten it. */ |
687 | 3800 get_trans_bufname(tp == curtab ? curbuf : tp->tp_curwin->w_buffer); |
839 | 3801 if (!tooltip) |
3802 shorten_dir(NameBuff); | |
687 | 3803 |
3804 wp = (tp == curtab) ? firstwin : tp->tp_firstwin; | |
3805 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
3806 if (bufIsChanged(wp->w_buffer)) | |
3807 modified = TRUE; | |
3808 if (modified || wincount > 1) | |
3809 { | |
3810 if (wincount > 1) | |
3811 vim_snprintf((char *)buf, sizeof(buf), "%d", wincount); | |
3812 else | |
3813 buf[0] = NUL; | |
3814 if (modified) | |
3815 STRCAT(buf, "+"); | |
3816 STRCAT(buf, " "); | |
1620 | 3817 STRMOVE(NameBuff + STRLEN(buf), NameBuff); |
687 | 3818 mch_memmove(NameBuff, buf, STRLEN(buf)); |
3819 } | |
685 | 3820 } |
3821 } | |
3822 | |
691 | 3823 /* |
3824 * Send the event for clicking to select tab page "nr". | |
3825 * Returns TRUE if it was done, FALSE when skipped because we are already at | |
838 | 3826 * that tab page or the cmdline window is open. |
691 | 3827 */ |
3828 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3829 send_tabline_event(int nr) |
691 | 3830 { |
3831 char_u string[3]; | |
3832 | |
3833 if (nr == tabpage_index(curtab)) | |
3834 return FALSE; | |
844 | 3835 |
3836 /* Don't put events in the input queue now. */ | |
3837 if (hold_gui_events | |
838 | 3838 # ifdef FEAT_CMDWIN |
844 | 3839 || cmdwin_type != 0 |
3840 # endif | |
3841 ) | |
838 | 3842 { |
3843 /* Set it back to the current tab page. */ | |
3844 gui_mch_set_curtab(tabpage_index(curtab)); | |
3845 return FALSE; | |
3846 } | |
844 | 3847 |
691 | 3848 string[0] = CSI; |
3849 string[1] = KS_TABLINE; | |
3850 string[2] = KE_FILLER; | |
3851 add_to_input_buf(string, 3); | |
3852 string[0] = nr; | |
3853 add_to_input_buf_csi(string, 1); | |
3854 return TRUE; | |
3855 } | |
3856 | |
824 | 3857 /* |
3858 * Send a tabline menu event | |
3859 */ | |
3860 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3861 send_tabline_menu_event(int tabidx, int event) |
824 | 3862 { |
3863 char_u string[3]; | |
3864 | |
844 | 3865 /* Don't put events in the input queue now. */ |
3866 if (hold_gui_events) | |
3867 return; | |
3868 | |
824 | 3869 string[0] = CSI; |
3870 string[1] = KS_TABMENU; | |
3871 string[2] = KE_FILLER; | |
3872 add_to_input_buf(string, 3); | |
3873 string[0] = tabidx; | |
3874 string[1] = (char_u)(long)event; | |
3875 add_to_input_buf_csi(string, 2); | |
3876 } | |
3877 | |
685 | 3878 #endif |
7 | 3879 |
3880 /* | |
3881 * Scrollbar stuff: | |
3882 */ | |
3883 | |
669 | 3884 /* |
3885 * Remove all scrollbars. Used before switching to another tab page. | |
3886 */ | |
3887 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3888 gui_remove_scrollbars(void) |
669 | 3889 { |
3890 int i; | |
3891 win_T *wp; | |
3892 | |
3893 for (i = 0; i < 3; i++) | |
3894 { | |
3895 if (i == SBAR_BOTTOM) | |
3896 gui_mch_enable_scrollbar(&gui.bottom_sbar, FALSE); | |
3897 else | |
3898 { | |
3899 FOR_ALL_WINDOWS(wp) | |
3900 { | |
3901 gui_do_scrollbar(wp, i, FALSE); | |
3902 } | |
3903 } | |
788 | 3904 curtab->tp_prev_which_scrollbars[i] = -1; |
669 | 3905 } |
3906 } | |
3907 | |
7 | 3908 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3909 gui_create_scrollbar(scrollbar_T *sb, int type, win_T *wp) |
7 | 3910 { |
3911 static int sbar_ident = 0; | |
3912 | |
3913 sb->ident = sbar_ident++; /* No check for too big, but would it happen? */ | |
3914 sb->wp = wp; | |
3915 sb->type = type; | |
3916 sb->value = 0; | |
3917 #ifdef FEAT_GUI_ATHENA | |
3918 sb->pixval = 0; | |
3919 #endif | |
3920 sb->size = 1; | |
3921 sb->max = 1; | |
3922 sb->top = 0; | |
3923 sb->height = 0; | |
3924 sb->width = 0; | |
3925 sb->status_height = 0; | |
3926 gui_mch_create_scrollbar(sb, (wp == NULL) ? SBAR_HORIZ : SBAR_VERT); | |
3927 } | |
3928 | |
3929 /* | |
3930 * Find the scrollbar with the given index. | |
3931 */ | |
3932 scrollbar_T * | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3933 gui_find_scrollbar(long ident) |
7 | 3934 { |
3935 win_T *wp; | |
3936 | |
3937 if (gui.bottom_sbar.ident == ident) | |
3938 return &gui.bottom_sbar; | |
3939 FOR_ALL_WINDOWS(wp) | |
3940 { | |
3941 if (wp->w_scrollbars[SBAR_LEFT].ident == ident) | |
3942 return &wp->w_scrollbars[SBAR_LEFT]; | |
3943 if (wp->w_scrollbars[SBAR_RIGHT].ident == ident) | |
3944 return &wp->w_scrollbars[SBAR_RIGHT]; | |
3945 } | |
3946 return NULL; | |
3947 } | |
3948 | |
3949 /* | |
3950 * For most systems: Put a code in the input buffer for a dragged scrollbar. | |
3951 * | |
3952 * For Win32, Macintosh and GTK+ 2: | |
3953 * Scrollbars seem to grab focus and vim doesn't read the input queue until | |
3954 * you stop dragging the scrollbar. We get here each time the scrollbar is | |
3955 * dragged another pixel, but as far as the rest of vim goes, it thinks | |
3956 * we're just hanging in the call to DispatchMessage() in | |
3957 * process_message(). The DispatchMessage() call that hangs was passed a | |
3958 * mouse button click event in the scrollbar window. -- webb. | |
3959 * | |
3960 * Solution: Do the scrolling right here. But only when allowed. | |
3961 * Ignore the scrollbars while executing an external command or when there | |
3962 * are still characters to be processed. | |
3963 */ | |
3964 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
3965 gui_drag_scrollbar(scrollbar_T *sb, long value, int still_dragging) |
7 | 3966 { |
3967 win_T *wp; | |
3968 int sb_num; | |
3969 #ifdef USE_ON_FLY_SCROLL | |
3970 colnr_T old_leftcol = curwin->w_leftcol; | |
3971 linenr_T old_topline = curwin->w_topline; | |
3972 # ifdef FEAT_DIFF | |
3973 int old_topfill = curwin->w_topfill; | |
3974 # endif | |
3975 #else | |
664 | 3976 char_u bytes[sizeof(long_u)]; |
7 | 3977 int byte_count; |
3978 #endif | |
3979 | |
3980 if (sb == NULL) | |
3981 return; | |
3982 | |
3983 /* Don't put events in the input queue now. */ | |
3984 if (hold_gui_events) | |
3985 return; | |
3986 | |
3987 #ifdef FEAT_CMDWIN | |
3988 if (cmdwin_type != 0 && sb->wp != curwin) | |
3989 return; | |
3990 #endif | |
3991 | |
3992 if (still_dragging) | |
3993 { | |
3994 if (sb->wp == NULL) | |
3995 gui.dragged_sb = SBAR_BOTTOM; | |
3996 else if (sb == &sb->wp->w_scrollbars[SBAR_LEFT]) | |
3997 gui.dragged_sb = SBAR_LEFT; | |
3998 else | |
3999 gui.dragged_sb = SBAR_RIGHT; | |
4000 gui.dragged_wp = sb->wp; | |
4001 } | |
4002 else | |
4003 { | |
4004 gui.dragged_sb = SBAR_NONE; | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
4005 #ifdef FEAT_GUI_GTK |
7 | 4006 /* Keep the "dragged_wp" value until after the scrolling, for when the |
4352 | 4007 * mouse button is released. GTK2 doesn't send the button-up event. */ |
7 | 4008 gui.dragged_wp = NULL; |
4009 #endif | |
4010 } | |
4011 | |
4012 /* Vertical sbar info is kept in the first sbar (the left one) */ | |
4013 if (sb->wp != NULL) | |
4014 sb = &sb->wp->w_scrollbars[0]; | |
4015 | |
4016 /* | |
4017 * Check validity of value | |
4018 */ | |
4019 if (value < 0) | |
4020 value = 0; | |
4021 #ifdef SCROLL_PAST_END | |
4022 else if (value > sb->max) | |
4023 value = sb->max; | |
4024 #else | |
4025 if (value > sb->max - sb->size + 1) | |
4026 value = sb->max - sb->size + 1; | |
4027 #endif | |
4028 | |
4029 sb->value = value; | |
4030 | |
4031 #ifdef USE_ON_FLY_SCROLL | |
1476 | 4032 /* When not allowed to do the scrolling right now, return. |
4033 * This also checked input_available(), but that causes the first click in | |
4034 * a scrollbar to be ignored when Vim doesn't have focus. */ | |
4035 if (dont_scroll) | |
7 | 4036 return; |
4037 #endif | |
973 | 4038 #ifdef FEAT_INS_EXPAND |
4039 /* Disallow scrolling the current window when the completion popup menu is | |
4040 * visible. */ | |
4041 if ((sb->wp == NULL || sb->wp == curwin) && pum_visible()) | |
4042 return; | |
4043 #endif | |
7 | 4044 |
4045 #ifdef FEAT_RIGHTLEFT | |
4046 if (sb->wp == NULL && curwin->w_p_rl) | |
4047 { | |
4048 value = sb->max + 1 - sb->size - value; | |
4049 if (value < 0) | |
4050 value = 0; | |
4051 } | |
4052 #endif | |
4053 | |
4054 if (sb->wp != NULL) /* vertical scrollbar */ | |
4055 { | |
4056 sb_num = 0; | |
4057 for (wp = firstwin; wp != sb->wp && wp != NULL; wp = wp->w_next) | |
4058 sb_num++; | |
4059 if (wp == NULL) | |
4060 return; | |
4061 | |
4062 #ifdef USE_ON_FLY_SCROLL | |
4063 current_scrollbar = sb_num; | |
4064 scrollbar_value = value; | |
4065 if (State & NORMAL) | |
4066 { | |
4067 gui_do_scroll(); | |
4068 setcursor(); | |
4069 } | |
4070 else if (State & INSERT) | |
4071 { | |
4072 ins_scroll(); | |
4073 setcursor(); | |
4074 } | |
4075 else if (State & CMDLINE) | |
4076 { | |
4077 if (msg_scrolled == 0) | |
4078 { | |
4079 gui_do_scroll(); | |
4080 redrawcmdline(); | |
4081 } | |
4082 } | |
4083 # ifdef FEAT_FOLDING | |
4084 /* Value may have been changed for closed fold. */ | |
4085 sb->value = sb->wp->w_topline - 1; | |
4086 # endif | |
788 | 4087 |
4088 /* When dragging one scrollbar and there is another one at the other | |
4089 * side move the thumb of that one too. */ | |
4090 if (gui.which_scrollbars[SBAR_RIGHT] && gui.which_scrollbars[SBAR_LEFT]) | |
4091 gui_mch_set_scrollbar_thumb( | |
4092 &sb->wp->w_scrollbars[ | |
4093 sb == &sb->wp->w_scrollbars[SBAR_RIGHT] | |
4094 ? SBAR_LEFT : SBAR_RIGHT], | |
4095 sb->value, sb->size, sb->max); | |
4096 | |
7 | 4097 #else |
4098 bytes[0] = CSI; | |
4099 bytes[1] = KS_VER_SCROLLBAR; | |
4100 bytes[2] = KE_FILLER; | |
4101 bytes[3] = (char_u)sb_num; | |
4102 byte_count = 4; | |
4103 #endif | |
4104 } | |
4105 else | |
4106 { | |
4107 #ifdef USE_ON_FLY_SCROLL | |
4108 scrollbar_value = value; | |
4109 | |
4110 if (State & NORMAL) | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4111 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 4112 else if (State & INSERT) |
4113 ins_horscroll(); | |
4114 else if (State & CMDLINE) | |
4115 { | |
540 | 4116 if (msg_scrolled == 0) |
7 | 4117 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4118 gui_do_horiz_scroll(scrollbar_value, FALSE); |
7 | 4119 redrawcmdline(); |
4120 } | |
4121 } | |
4122 if (old_leftcol != curwin->w_leftcol) | |
4123 { | |
4124 updateWindow(curwin); /* update window, status and cmdline */ | |
4125 setcursor(); | |
4126 } | |
4127 #else | |
4128 bytes[0] = CSI; | |
4129 bytes[1] = KS_HOR_SCROLLBAR; | |
4130 bytes[2] = KE_FILLER; | |
4131 byte_count = 3; | |
4132 #endif | |
4133 } | |
4134 | |
4135 #ifdef USE_ON_FLY_SCROLL | |
4136 /* | |
4137 * synchronize other windows, as necessary according to 'scrollbind' | |
4138 */ | |
4139 if (curwin->w_p_scb | |
4140 && ((sb->wp == NULL && curwin->w_leftcol != old_leftcol) | |
4141 || (sb->wp == curwin && (curwin->w_topline != old_topline | |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
4142 # ifdef FEAT_DIFF |
7 | 4143 || curwin->w_topfill != old_topfill |
13384
6740c499de13
patch 8.0.1566: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
4144 # endif |
7 | 4145 )))) |
4146 { | |
4147 do_check_scrollbind(TRUE); | |
4148 /* need to update the window right here */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
4149 FOR_ALL_WINDOWS(wp) |
7 | 4150 if (wp->w_redr_type > 0) |
4151 updateWindow(wp); | |
4152 setcursor(); | |
4153 } | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
4154 out_flush_cursor(FALSE, TRUE); |
7 | 4155 #else |
664 | 4156 add_to_input_buf(bytes, byte_count); |
4157 add_long_to_buf((long_u)value, bytes); | |
4158 add_to_input_buf_csi(bytes, sizeof(long_u)); | |
7 | 4159 #endif |
4160 } | |
4161 | |
4162 /* | |
4163 * Scrollbar stuff: | |
4164 */ | |
4165 | |
1906 | 4166 /* |
4167 * Called when something in the window layout has changed. | |
4168 */ | |
4169 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4170 gui_may_update_scrollbars(void) |
1906 | 4171 { |
4172 if (gui.in_use && starting == 0) | |
4173 { | |
4174 out_flush(); | |
4175 gui_init_which_components(NULL); | |
4176 gui_update_scrollbars(TRUE); | |
4177 } | |
4178 need_mouse_correct = TRUE; | |
4179 } | |
4180 | |
7 | 4181 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4182 gui_update_scrollbars( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4183 int force) /* Force all scrollbars to get updated */ |
7 | 4184 { |
4185 win_T *wp; | |
4186 scrollbar_T *sb; | |
4187 long val, size, max; /* need 32 bits here */ | |
4188 int which_sb; | |
4189 int h, y; | |
4190 static win_T *prev_curwin = NULL; | |
4191 | |
4192 /* Update the horizontal scrollbar */ | |
4193 gui_update_horiz_scrollbar(force); | |
4194 | |
4195 #ifndef WIN3264 | |
4196 /* Return straight away if there is neither a left nor right scrollbar. | |
4197 * On MS-Windows this is required anyway for scrollwheel messages. */ | |
4198 if (!gui.which_scrollbars[SBAR_LEFT] && !gui.which_scrollbars[SBAR_RIGHT]) | |
4199 return; | |
4200 #endif | |
4201 | |
4202 /* | |
4203 * Don't want to update a scrollbar while we're dragging it. But if we | |
4204 * have both a left and right scrollbar, and we drag one of them, we still | |
4205 * need to update the other one. | |
4206 */ | |
674 | 4207 if (!force && (gui.dragged_sb == SBAR_LEFT || gui.dragged_sb == SBAR_RIGHT) |
4208 && gui.which_scrollbars[SBAR_LEFT] | |
4209 && gui.which_scrollbars[SBAR_RIGHT]) | |
7 | 4210 { |
4211 /* | |
4212 * If we have two scrollbars and one of them is being dragged, just | |
4213 * copy the scrollbar position from the dragged one to the other one. | |
4214 */ | |
4215 which_sb = SBAR_LEFT + SBAR_RIGHT - gui.dragged_sb; | |
4216 if (gui.dragged_wp != NULL) | |
4217 gui_mch_set_scrollbar_thumb( | |
4218 &gui.dragged_wp->w_scrollbars[which_sb], | |
4219 gui.dragged_wp->w_scrollbars[0].value, | |
4220 gui.dragged_wp->w_scrollbars[0].size, | |
4221 gui.dragged_wp->w_scrollbars[0].max); | |
4222 } | |
4223 | |
4224 /* avoid that moving components around generates events */ | |
4225 ++hold_gui_events; | |
4226 | |
9651
fe665dae7197
commit https://github.com/vim/vim/commit/45a249513f5ed2de0a6f6b5cb6e32015e35644be
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4227 for (wp = firstwin; wp != NULL; wp = W_NEXT(wp)) |
7 | 4228 { |
4229 if (wp->w_buffer == NULL) /* just in case */ | |
4230 continue; | |
674 | 4231 /* Skip a scrollbar that is being dragged. */ |
4232 if (!force && (gui.dragged_sb == SBAR_LEFT | |
4233 || gui.dragged_sb == SBAR_RIGHT) | |
4234 && gui.dragged_wp == wp) | |
4235 continue; | |
4236 | |
7 | 4237 #ifdef SCROLL_PAST_END |
4238 max = wp->w_buffer->b_ml.ml_line_count - 1; | |
4239 #else | |
4240 max = wp->w_buffer->b_ml.ml_line_count + wp->w_height - 2; | |
4241 #endif | |
4242 if (max < 0) /* empty buffer */ | |
4243 max = 0; | |
4244 val = wp->w_topline - 1; | |
4245 size = wp->w_height; | |
4246 #ifdef SCROLL_PAST_END | |
4247 if (val > max) /* just in case */ | |
4248 val = max; | |
4249 #else | |
4250 if (size > max + 1) /* just in case */ | |
4251 size = max + 1; | |
4252 if (val > max - size + 1) | |
4253 val = max - size + 1; | |
4254 #endif | |
4255 if (val < 0) /* minimal value is 0 */ | |
4256 val = 0; | |
4257 | |
4258 /* | |
4259 * Scrollbar at index 0 (the left one) contains all the information. | |
4260 * It would be the same info for left and right so we just store it for | |
4261 * one of them. | |
4262 */ | |
4263 sb = &wp->w_scrollbars[0]; | |
4264 | |
4265 /* | |
4266 * Note: no check for valid w_botline. If it's not valid the | |
4267 * scrollbars will be updated later anyway. | |
4268 */ | |
4269 if (size < 1 || wp->w_botline - 2 > max) | |
4270 { | |
4271 /* | |
4272 * This can happen during changing files. Just don't update the | |
4273 * scrollbar for now. | |
4274 */ | |
4275 sb->height = 0; /* Force update next time */ | |
4276 if (gui.which_scrollbars[SBAR_LEFT]) | |
4277 gui_do_scrollbar(wp, SBAR_LEFT, FALSE); | |
4278 if (gui.which_scrollbars[SBAR_RIGHT]) | |
4279 gui_do_scrollbar(wp, SBAR_RIGHT, FALSE); | |
4280 continue; | |
4281 } | |
4282 if (force || sb->height != wp->w_height | |
4283 || sb->top != wp->w_winrow | |
4284 || sb->status_height != wp->w_status_height | |
4285 || sb->width != wp->w_width | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12457
diff
changeset
|
4286 || prev_curwin != curwin) |
7 | 4287 { |
4288 /* Height, width or position of scrollbar has changed. For | |
4289 * vertical split: curwin changed. */ | |
4290 sb->height = wp->w_height; | |
4291 sb->top = wp->w_winrow; | |
4292 sb->status_height = wp->w_status_height; | |
4293 sb->width = wp->w_width; | |
4294 | |
4295 /* Calculate height and position in pixels */ | |
4296 h = (sb->height + sb->status_height) * gui.char_height; | |
4297 y = sb->top * gui.char_height + gui.border_offset; | |
4298 #if defined(FEAT_MENU) && !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_MOTIF) && !defined(FEAT_GUI_PHOTON) | |
4299 if (gui.menu_is_active) | |
4300 y += gui.menu_height; | |
4301 #endif | |
4302 | |
4303 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_ATHENA)) | |
4304 if (vim_strchr(p_go, GO_TOOLBAR) != NULL) | |
4305 # ifdef FEAT_GUI_ATHENA | |
4306 y += gui.toolbar_height; | |
4307 # else | |
4308 # ifdef FEAT_GUI_MSWIN | |
4309 y += TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT; | |
4310 # endif | |
4311 # endif | |
4312 #endif | |
4313 | |
810 | 4314 #if defined(FEAT_GUI_TABLINE) && defined(FEAT_GUI_MSWIN) |
4315 if (gui_has_tabline()) | |
843 | 4316 y += gui.tabline_height; |
810 | 4317 #endif |
4318 | |
7 | 4319 if (wp->w_winrow == 0) |
4320 { | |
4321 /* Height of top scrollbar includes width of top border */ | |
4322 h += gui.border_offset; | |
4323 y -= gui.border_offset; | |
4324 } | |
4325 if (gui.which_scrollbars[SBAR_LEFT]) | |
4326 { | |
4327 gui_mch_set_scrollbar_pos(&wp->w_scrollbars[SBAR_LEFT], | |
4328 gui.left_sbar_x, y, | |
4329 gui.scrollbar_width, h); | |
4330 gui_do_scrollbar(wp, SBAR_LEFT, TRUE); | |
4331 } | |
4332 if (gui.which_scrollbars[SBAR_RIGHT]) | |
4333 { | |
4334 gui_mch_set_scrollbar_pos(&wp->w_scrollbars[SBAR_RIGHT], | |
4335 gui.right_sbar_x, y, | |
4336 gui.scrollbar_width, h); | |
4337 gui_do_scrollbar(wp, SBAR_RIGHT, TRUE); | |
4338 } | |
4339 } | |
4340 | |
4341 /* Reduce the number of calls to gui_mch_set_scrollbar_thumb() by | |
4342 * checking if the thumb moved at least a pixel. Only do this for | |
4343 * Athena, most other GUIs require the update anyway to make the | |
4344 * arrows work. */ | |
4345 #ifdef FEAT_GUI_ATHENA | |
4346 if (max == 0) | |
4347 y = 0; | |
4348 else | |
4349 y = (val * (sb->height + 2) * gui.char_height + max / 2) / max; | |
4350 if (force || sb->pixval != y || sb->size != size || sb->max != max) | |
4351 #else | |
4352 if (force || sb->value != val || sb->size != size || sb->max != max) | |
4353 #endif | |
4354 { | |
4355 /* Thumb of scrollbar has moved */ | |
4356 sb->value = val; | |
4357 #ifdef FEAT_GUI_ATHENA | |
4358 sb->pixval = y; | |
4359 #endif | |
4360 sb->size = size; | |
4361 sb->max = max; | |
674 | 4362 if (gui.which_scrollbars[SBAR_LEFT] |
4363 && (gui.dragged_sb != SBAR_LEFT || gui.dragged_wp != wp)) | |
7 | 4364 gui_mch_set_scrollbar_thumb(&wp->w_scrollbars[SBAR_LEFT], |
4365 val, size, max); | |
4366 if (gui.which_scrollbars[SBAR_RIGHT] | |
674 | 4367 && (gui.dragged_sb != SBAR_RIGHT || gui.dragged_wp != wp)) |
7 | 4368 gui_mch_set_scrollbar_thumb(&wp->w_scrollbars[SBAR_RIGHT], |
4369 val, size, max); | |
4370 } | |
4371 } | |
4372 prev_curwin = curwin; | |
4373 --hold_gui_events; | |
4374 } | |
4375 | |
4376 /* | |
4377 * Enable or disable a scrollbar. | |
4378 * Check for scrollbars for vertically split windows which are not enabled | |
4379 * sometimes. | |
4380 */ | |
4381 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4382 gui_do_scrollbar( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4383 win_T *wp, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4384 int which, /* SBAR_LEFT or SBAR_RIGHT */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4385 int enable) /* TRUE to enable scrollbar */ |
7 | 4386 { |
4387 int midcol = curwin->w_wincol + curwin->w_width / 2; | |
4388 int has_midcol = (wp->w_wincol <= midcol | |
4389 && wp->w_wincol + wp->w_width >= midcol); | |
4390 | |
4391 /* Only enable scrollbars that contain the middle column of the current | |
4392 * window. */ | |
4393 if (gui.which_scrollbars[SBAR_RIGHT] != gui.which_scrollbars[SBAR_LEFT]) | |
4394 { | |
4395 /* Scrollbars only on one side. Don't enable scrollbars that don't | |
4396 * contain the middle column of the current window. */ | |
4397 if (!has_midcol) | |
4398 enable = FALSE; | |
4399 } | |
4400 else | |
4401 { | |
4402 /* Scrollbars on both sides. Don't enable scrollbars that neither | |
4403 * contain the middle column of the current window nor are on the far | |
4404 * side. */ | |
4405 if (midcol > Columns / 2) | |
4406 { | |
4407 if (which == SBAR_LEFT ? wp->w_wincol != 0 : !has_midcol) | |
4408 enable = FALSE; | |
4409 } | |
4410 else | |
4411 { | |
4412 if (which == SBAR_RIGHT ? wp->w_wincol + wp->w_width != Columns | |
4413 : !has_midcol) | |
4414 enable = FALSE; | |
4415 } | |
4416 } | |
4417 gui_mch_enable_scrollbar(&wp->w_scrollbars[which], enable); | |
4418 } | |
4419 | |
4420 /* | |
4421 * Scroll a window according to the values set in the globals current_scrollbar | |
4422 * and scrollbar_value. Return TRUE if the cursor in the current window moved | |
4423 * or FALSE otherwise. | |
4424 */ | |
4425 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4426 gui_do_scroll(void) |
7 | 4427 { |
4428 win_T *wp, *save_wp; | |
4429 int i; | |
4430 long nlines; | |
4431 pos_T old_cursor; | |
4432 linenr_T old_topline; | |
4433 #ifdef FEAT_DIFF | |
4434 int old_topfill; | |
4435 #endif | |
4436 | |
4437 for (wp = firstwin, i = 0; i < current_scrollbar; wp = W_NEXT(wp), i++) | |
4438 if (wp == NULL) | |
4439 break; | |
4440 if (wp == NULL) | |
4441 /* Couldn't find window */ | |
4442 return FALSE; | |
4443 | |
4444 /* | |
4445 * Compute number of lines to scroll. If zero, nothing to do. | |
4446 */ | |
4447 nlines = (long)scrollbar_value + 1 - (long)wp->w_topline; | |
4448 if (nlines == 0) | |
4449 return FALSE; | |
4450 | |
4451 save_wp = curwin; | |
4452 old_topline = wp->w_topline; | |
4453 #ifdef FEAT_DIFF | |
4454 old_topfill = wp->w_topfill; | |
4455 #endif | |
4456 old_cursor = wp->w_cursor; | |
4457 curwin = wp; | |
4458 curbuf = wp->w_buffer; | |
4459 if (nlines < 0) | |
4460 scrolldown(-nlines, gui.dragged_wp == NULL); | |
4461 else | |
4462 scrollup(nlines, gui.dragged_wp == NULL); | |
4463 /* Reset dragged_wp after using it. "dragged_sb" will have been reset for | |
4464 * the mouse-up event already, but we still want it to behave like when | |
4465 * dragging. But not the next click in an arrow. */ | |
4466 if (gui.dragged_sb == SBAR_NONE) | |
4467 gui.dragged_wp = NULL; | |
4468 | |
4469 if (old_topline != wp->w_topline | |
4470 #ifdef FEAT_DIFF | |
4471 || old_topfill != wp->w_topfill | |
4472 #endif | |
4473 ) | |
4474 { | |
4475 if (p_so != 0) | |
4476 { | |
4477 cursor_correct(); /* fix window for 'so' */ | |
4478 update_topline(); /* avoid up/down jump */ | |
4479 } | |
4480 if (old_cursor.lnum != wp->w_cursor.lnum) | |
4481 coladvance(wp->w_curswant); | |
4482 wp->w_scbind_pos = wp->w_topline; | |
4483 } | |
4484 | |
519 | 4485 /* Make sure wp->w_leftcol and wp->w_skipcol are correct. */ |
4486 validate_cursor(); | |
4487 | |
7 | 4488 curwin = save_wp; |
4489 curbuf = save_wp->w_buffer; | |
4490 | |
4491 /* | |
4492 * Don't call updateWindow() when nothing has changed (it will overwrite | |
4493 * the status line!). | |
4494 */ | |
4495 if (old_topline != wp->w_topline | |
519 | 4496 || wp->w_redr_type != 0 |
7 | 4497 #ifdef FEAT_DIFF |
4498 || old_topfill != wp->w_topfill | |
4499 #endif | |
4500 ) | |
4501 { | |
1434 | 4502 int type = VALID; |
4503 | |
4504 #ifdef FEAT_INS_EXPAND | |
4505 if (pum_visible()) | |
4506 { | |
4507 type = NOT_VALID; | |
4508 wp->w_lines_valid = 0; | |
4509 } | |
4510 #endif | |
4511 /* Don't set must_redraw here, it may cause the popup menu to | |
4512 * disappear when losing focus after a scrollbar drag. */ | |
4513 if (wp->w_redr_type < type) | |
4514 wp->w_redr_type = type; | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
4515 mch_disable_flush(); |
7 | 4516 updateWindow(wp); /* update window, status line, and cmdline */ |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
4517 mch_enable_flush(); |
7 | 4518 } |
4519 | |
973 | 4520 #ifdef FEAT_INS_EXPAND |
4521 /* May need to redraw the popup menu. */ | |
4522 if (pum_visible()) | |
4523 pum_redraw(); | |
4524 #endif | |
4525 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10819
diff
changeset
|
4526 return (wp == curwin && !EQUAL_POS(curwin->w_cursor, old_cursor)); |
7 | 4527 } |
4528 | |
4529 | |
4530 /* | |
4531 * Horizontal scrollbar stuff: | |
4532 */ | |
4533 | |
4534 /* | |
4535 * Return length of line "lnum" for horizontal scrolling. | |
4536 */ | |
4537 static colnr_T | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4538 scroll_line_len(linenr_T lnum) |
7 | 4539 { |
4540 char_u *p; | |
4541 colnr_T col; | |
4542 int w; | |
4543 | |
4544 p = ml_get(lnum); | |
4545 col = 0; | |
4546 if (*p != NUL) | |
4547 for (;;) | |
4548 { | |
4549 w = chartabsize(p, col); | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4550 MB_PTR_ADV(p); |
7 | 4551 if (*p == NUL) /* don't count the last character */ |
4552 break; | |
4553 col += w; | |
4554 } | |
4555 return col; | |
4556 } | |
4557 | |
4558 /* Remember which line is currently the longest, so that we don't have to | |
4559 * search for it when scrolling horizontally. */ | |
4560 static linenr_T longest_lnum = 0; | |
4561 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4562 /* |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4563 * Find longest visible line number. If this is not possible (or not desired, |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4564 * by setting 'h' in "guioptions") then the current line number is returned. |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4565 */ |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4566 static linenr_T |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4567 gui_find_longest_lnum(void) |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4568 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4569 linenr_T ret = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4570 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4571 /* Calculate maximum for horizontal scrollbar. Check for reasonable |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4572 * line numbers, topline and botline can be invalid when displaying is |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4573 * postponed. */ |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4574 if (vim_strchr(p_go, GO_HORSCROLL) == NULL |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4575 && curwin->w_topline <= curwin->w_cursor.lnum |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4576 && curwin->w_botline > curwin->w_cursor.lnum |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4577 && curwin->w_botline <= curbuf->b_ml.ml_line_count + 1) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4578 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4579 linenr_T lnum; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4580 colnr_T n; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4581 long max = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4582 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4583 /* Use maximum of all visible lines. Remember the lnum of the |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4584 * longest line, closest to the cursor line. Used when scrolling |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4585 * below. */ |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4586 for (lnum = curwin->w_topline; lnum < curwin->w_botline; ++lnum) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4587 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4588 n = scroll_line_len(lnum); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4589 if (n > (colnr_T)max) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4590 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4591 max = n; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4592 ret = lnum; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4593 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4594 else if (n == (colnr_T)max |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4595 && abs((int)(lnum - curwin->w_cursor.lnum)) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4596 < abs((int)(ret - curwin->w_cursor.lnum))) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4597 ret = lnum; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4598 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4599 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4600 else |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4601 /* Use cursor line only. */ |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4602 ret = curwin->w_cursor.lnum; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4603 |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4604 return ret; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4605 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4606 |
7 | 4607 static void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4608 gui_update_horiz_scrollbar(int force) |
7 | 4609 { |
4610 long value, size, max; /* need 32 bit ints here */ | |
4611 | |
4612 if (!gui.which_scrollbars[SBAR_BOTTOM]) | |
4613 return; | |
4614 | |
4615 if (!force && gui.dragged_sb == SBAR_BOTTOM) | |
4616 return; | |
4617 | |
4618 if (!force && curwin->w_p_wrap && gui.prev_wrap) | |
4619 return; | |
4620 | |
4621 /* | |
4622 * It is possible for the cursor to be invalid if we're in the middle of | |
4623 * something (like changing files). If so, don't do anything for now. | |
4624 */ | |
4625 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
4626 { | |
4627 gui.bottom_sbar.value = -1; | |
4628 return; | |
4629 } | |
4630 | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
4631 size = curwin->w_width; |
7 | 4632 if (curwin->w_p_wrap) |
4633 { | |
4634 value = 0; | |
4635 #ifdef SCROLL_PAST_END | |
4636 max = 0; | |
4637 #else | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
4638 max = curwin->w_width - 1; |
7 | 4639 #endif |
4640 } | |
4641 else | |
4642 { | |
4643 value = curwin->w_leftcol; | |
4644 | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4645 longest_lnum = gui_find_longest_lnum(); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4646 max = scroll_line_len(longest_lnum); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4647 |
7 | 4648 #ifdef FEAT_VIRTUALEDIT |
4649 if (virtual_active()) | |
4650 { | |
4651 /* May move the cursor even further to the right. */ | |
4652 if (curwin->w_virtcol >= (colnr_T)max) | |
4653 max = curwin->w_virtcol; | |
4654 } | |
4655 #endif | |
4656 | |
4657 #ifndef SCROLL_PAST_END | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
4658 max += curwin->w_width - 1; |
7 | 4659 #endif |
4660 /* The line number isn't scrolled, thus there is less space when | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2065
diff
changeset
|
4661 * 'number' or 'relativenumber' is set (also for 'foldcolumn'). */ |
7 | 4662 size -= curwin_col_off(); |
4663 #ifndef SCROLL_PAST_END | |
4664 max -= curwin_col_off(); | |
4665 #endif | |
4666 } | |
4667 | |
4668 #ifndef SCROLL_PAST_END | |
4669 if (value > max - size + 1) | |
4670 value = max - size + 1; /* limit the value to allowable range */ | |
4671 #endif | |
4672 | |
4673 #ifdef FEAT_RIGHTLEFT | |
4674 if (curwin->w_p_rl) | |
4675 { | |
4676 value = max + 1 - size - value; | |
4677 if (value < 0) | |
4678 { | |
4679 size += value; | |
4680 value = 0; | |
4681 } | |
4682 } | |
4683 #endif | |
4684 if (!force && value == gui.bottom_sbar.value && size == gui.bottom_sbar.size | |
4685 && max == gui.bottom_sbar.max) | |
4686 return; | |
4687 | |
4688 gui.bottom_sbar.value = value; | |
4689 gui.bottom_sbar.size = size; | |
4690 gui.bottom_sbar.max = max; | |
4691 gui.prev_wrap = curwin->w_p_wrap; | |
4692 | |
4693 gui_mch_set_scrollbar_thumb(&gui.bottom_sbar, value, size, max); | |
4694 } | |
4695 | |
4696 /* | |
4697 * Do a horizontal scroll. Return TRUE if the cursor moved, FALSE otherwise. | |
4698 */ | |
4699 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4700 gui_do_horiz_scroll(long_u leftcol, int compute_longest_lnum) |
7 | 4701 { |
4702 /* no wrapping, no scrolling */ | |
4703 if (curwin->w_p_wrap) | |
4704 return FALSE; | |
4705 | |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4706 if (curwin->w_leftcol == (colnr_T)leftcol) |
7 | 4707 return FALSE; |
4708 | |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4709 curwin->w_leftcol = (colnr_T)leftcol; |
7 | 4710 |
4711 /* When the line of the cursor is too short, move the cursor to the | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4712 * longest visible line. */ |
7 | 4713 if (vim_strchr(p_go, GO_HORSCROLL) == NULL |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4714 && !virtual_active() |
2416
1a9c16dd76d4
Fix compiler warnings on 64 bit systems.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
4715 && (colnr_T)leftcol > scroll_line_len(curwin->w_cursor.lnum)) |
7 | 4716 { |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4717 if (compute_longest_lnum) |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4718 { |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4719 curwin->w_cursor.lnum = gui_find_longest_lnum(); |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4720 curwin->w_cursor.col = 0; |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4721 } |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4722 /* Do a sanity check on "longest_lnum", just in case. */ |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4723 else if (longest_lnum >= curwin->w_topline |
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
4724 && longest_lnum < curwin->w_botline) |
7 | 4725 { |
4726 curwin->w_cursor.lnum = longest_lnum; | |
4727 curwin->w_cursor.col = 0; | |
4728 } | |
4729 } | |
4730 | |
4731 return leftcol_changed(); | |
4732 } | |
4733 | |
4734 /* | |
4735 * Check that none of the colors are the same as the background color | |
4736 */ | |
4737 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4738 gui_check_colors(void) |
7 | 4739 { |
4740 if (gui.norm_pixel == gui.back_pixel || gui.norm_pixel == INVALCOLOR) | |
4741 { | |
4742 gui_set_bg_color((char_u *)"White"); | |
4743 if (gui.norm_pixel == gui.back_pixel || gui.norm_pixel == INVALCOLOR) | |
4744 gui_set_fg_color((char_u *)"Black"); | |
4745 } | |
4746 } | |
4747 | |
203 | 4748 static void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4749 gui_set_fg_color(char_u *name) |
7 | 4750 { |
4751 gui.norm_pixel = gui_get_color(name); | |
4752 hl_set_fg_color_name(vim_strsave(name)); | |
4753 } | |
4754 | |
203 | 4755 static void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4756 gui_set_bg_color(char_u *name) |
7 | 4757 { |
4758 gui.back_pixel = gui_get_color(name); | |
4759 hl_set_bg_color_name(vim_strsave(name)); | |
4760 } | |
4761 | |
4762 /* | |
4763 * Allocate a color by name. | |
4764 * Returns INVALCOLOR and gives an error message when failed. | |
4765 */ | |
4766 guicolor_T | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4767 gui_get_color(char_u *name) |
7 | 4768 { |
4769 guicolor_T t; | |
4770 | |
4771 if (*name == NUL) | |
4772 return INVALCOLOR; | |
4773 t = gui_mch_get_color(name); | |
11 | 4774 |
7 | 4775 if (t == INVALCOLOR |
574 | 4776 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
7 | 4777 && gui.in_use |
4778 #endif | |
4779 ) | |
4780 EMSG2(_("E254: Cannot allocate color %s"), name); | |
4781 return t; | |
4782 } | |
4783 | |
4784 /* | |
4785 * Return the grey value of a color (range 0-255). | |
4786 */ | |
4787 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4788 gui_get_lightness(guicolor_T pixel) |
7 | 4789 { |
9939
ccb6461b82df
commit https://github.com/vim/vim/commit/1b58cdd160c2e0ada0f638679a2aa27e4665fc48
Christian Brabandt <cb@256bit.org>
parents:
9848
diff
changeset
|
4790 long_u rgb = (long_u)gui_mch_get_rgb(pixel); |
7 | 4791 |
835 | 4792 return (int)( (((rgb >> 16) & 0xff) * 299) |
856 | 4793 + (((rgb >> 8) & 0xff) * 587) |
4794 + ((rgb & 0xff) * 114)) / 1000; | |
7 | 4795 } |
4796 | |
4797 #if defined(FEAT_GUI_X11) || defined(PROTO) | |
4798 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4799 gui_new_scrollbar_colors(void) |
7 | 4800 { |
4801 win_T *wp; | |
4802 | |
4803 /* Nothing to do if GUI hasn't started yet. */ | |
4804 if (!gui.in_use) | |
4805 return; | |
4806 | |
4807 FOR_ALL_WINDOWS(wp) | |
4808 { | |
4809 gui_mch_set_scrollbar_colors(&(wp->w_scrollbars[SBAR_LEFT])); | |
4810 gui_mch_set_scrollbar_colors(&(wp->w_scrollbars[SBAR_RIGHT])); | |
4811 } | |
4812 gui_mch_set_scrollbar_colors(&gui.bottom_sbar); | |
4813 } | |
4814 #endif | |
4815 | |
4816 /* | |
4817 * Call this when focus has changed. | |
4818 */ | |
4819 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4820 gui_focus_change(int in_focus) |
7 | 4821 { |
4822 /* | |
4823 * Skip this code to avoid drawing the cursor when debugging and switching | |
4824 * between the debugger window and gvim. | |
4825 */ | |
4826 #if 1 | |
4827 gui.in_focus = in_focus; | |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
4828 out_flush_cursor(TRUE, FALSE); |
7 | 4829 |
4830 # ifdef FEAT_XIM | |
4831 xim_set_focus(in_focus); | |
4832 # endif | |
4833 | |
1380 | 4834 /* Put events in the input queue only when allowed. |
4835 * ui_focus_change() isn't called directly, because it invokes | |
4836 * autocommands and that must not happen asynchronously. */ | |
4837 if (!hold_gui_events) | |
4838 { | |
4839 char_u bytes[3]; | |
4840 | |
4841 bytes[0] = CSI; | |
4842 bytes[1] = KS_EXTRA; | |
4843 bytes[2] = in_focus ? (int)KE_FOCUSGAINED : (int)KE_FOCUSLOST; | |
4844 add_to_input_buf(bytes, 3); | |
4845 } | |
7 | 4846 #endif |
4847 } | |
4848 | |
4849 /* | |
4850 * Called when the mouse moved (but not when dragging). | |
4851 */ | |
4852 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4853 gui_mouse_moved(int x, int y) |
7 | 4854 { |
4855 win_T *wp; | |
894 | 4856 char_u st[8]; |
7 | 4857 |
771 | 4858 /* Ignore this while still starting up. */ |
4859 if (!gui.in_use || gui.starting) | |
4860 return; | |
4861 | |
7 | 4862 #ifdef FEAT_MOUSESHAPE |
4863 /* Get window pointer, and update mouse shape as well. */ | |
4864 wp = xy2win(x, y); | |
4865 #endif | |
4866 | |
4867 /* Only handle this when 'mousefocus' set and ... */ | |
4868 if (p_mousef | |
4869 && !hold_gui_events /* not holding events */ | |
4870 && (State & (NORMAL|INSERT))/* Normal/Visual/Insert mode */ | |
4871 && State != HITRETURN /* but not hit-return prompt */ | |
4872 && msg_scrolled == 0 /* no scrolled message */ | |
4873 && !need_mouse_correct /* not moving the pointer */ | |
4874 && gui.in_focus) /* gvim in focus */ | |
4875 { | |
4876 /* Don't move the mouse when it's left or right of the Vim window */ | |
4877 if (x < 0 || x > Columns * gui.char_width) | |
4878 return; | |
4879 #ifndef FEAT_MOUSESHAPE | |
4880 wp = xy2win(x, y); | |
4881 #endif | |
4882 if (wp == curwin || wp == NULL) | |
4883 return; /* still in the same old window, or none at all */ | |
4884 | |
859 | 4885 /* Ignore position in the tab pages line. */ |
4886 if (Y_2_ROW(y) < tabline_height()) | |
4887 return; | |
4888 | |
7 | 4889 /* |
4890 * format a mouse click on status line input | |
4891 * ala gui_send_mouse_event(0, x, y, 0, 0); | |
261 | 4892 * Trick: Use a column number -1, so that get_pseudo_mouse_code() will |
4893 * generate a K_LEFTMOUSE_NM key code. | |
7 | 4894 */ |
4895 if (finish_op) | |
4896 { | |
4897 /* abort the current operator first */ | |
4898 st[0] = ESC; | |
4899 add_to_input_buf(st, 1); | |
4900 } | |
4901 st[0] = CSI; | |
4902 st[1] = KS_MOUSE; | |
4903 st[2] = KE_FILLER; | |
4904 st[3] = (char_u)MOUSE_LEFT; | |
4905 fill_mouse_coord(st + 4, | |
261 | 4906 wp->w_wincol == 0 ? -1 : wp->w_wincol + MOUSE_COLOFF, |
7 | 4907 wp->w_height + W_WINROW(wp)); |
4908 | |
4909 add_to_input_buf(st, 8); | |
4910 st[3] = (char_u)MOUSE_RELEASE; | |
4911 add_to_input_buf(st, 8); | |
4912 #ifdef FEAT_GUI_GTK | |
4913 /* Need to wake up the main loop */ | |
4914 if (gtk_main_level() > 0) | |
4915 gtk_main_quit(); | |
4916 #endif | |
4917 } | |
4918 } | |
4919 | |
4920 /* | |
4921 * Called when mouse should be moved to window with focus. | |
4922 */ | |
4923 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4924 gui_mouse_correct(void) |
7 | 4925 { |
4926 int x, y; | |
4927 win_T *wp = NULL; | |
4928 | |
4929 need_mouse_correct = FALSE; | |
87 | 4930 |
4931 if (!(gui.in_use && p_mousef)) | |
4932 return; | |
4933 | |
4934 gui_mch_getmouse(&x, &y); | |
4935 /* Don't move the mouse when it's left or right of the Vim window */ | |
4936 if (x < 0 || x > Columns * gui.char_width) | |
4937 return; | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12457
diff
changeset
|
4938 if (y >= 0 && Y_2_ROW(y) >= tabline_height()) |
87 | 4939 wp = xy2win(x, y); |
4940 if (wp != curwin && wp != NULL) /* If in other than current window */ | |
7 | 4941 { |
87 | 4942 validate_cline_row(); |
4943 gui_mch_setmouse((int)W_ENDCOL(curwin) * gui.char_width - 3, | |
4944 (W_WINROW(curwin) + curwin->w_wrow) * gui.char_height | |
7 | 4945 + (gui.char_height) / 2); |
4946 } | |
4947 } | |
4948 | |
4949 /* | |
12136
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12082
diff
changeset
|
4950 * Find window where the mouse pointer "x" / "y" coordinate is in. |
7 | 4951 */ |
4952 static win_T * | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4953 xy2win(int x UNUSED, int y UNUSED) |
7 | 4954 { |
4955 int row; | |
4956 int col; | |
4957 win_T *wp; | |
4958 | |
4959 row = Y_2_ROW(y); | |
4960 col = X_2_COL(x); | |
4961 if (row < 0 || col < 0) /* before first window */ | |
4962 return NULL; | |
4963 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:
12082
diff
changeset
|
4964 if (wp == NULL) |
60cf03e59402
patch 8.0.0948: crash if timer closes window while dragging status line
Christian Brabandt <cb@256bit.org>
parents:
12082
diff
changeset
|
4965 return NULL; |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12457
diff
changeset
|
4966 #ifdef FEAT_MOUSESHAPE |
7 | 4967 if (State == HITRETURN || State == ASKMORE) |
4968 { | |
4969 if (Y_2_ROW(y) >= msg_row) | |
4970 update_mouseshape(SHAPE_IDX_MOREL); | |
4971 else | |
4972 update_mouseshape(SHAPE_IDX_MORE); | |
4973 } | |
4974 else if (row > wp->w_height) /* below status line */ | |
4975 update_mouseshape(SHAPE_IDX_CLINE); | |
12529
158917d728b4
patch 8.0.1143: macros always expand to the same thing
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4976 else if (!(State & CMDLINE) && wp->w_vsep_width > 0 && col == wp->w_width |
819 | 4977 && (row != wp->w_height || !stl_connected(wp)) && msg_scrolled == 0) |
7 | 4978 update_mouseshape(SHAPE_IDX_VSEP); |
12529
158917d728b4
patch 8.0.1143: macros always expand to the same thing
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
4979 else if (!(State & CMDLINE) && wp->w_status_height > 0 |
819 | 4980 && row == wp->w_height && msg_scrolled == 0) |
7 | 4981 update_mouseshape(SHAPE_IDX_STATUS); |
4982 else | |
4983 update_mouseshape(-2); | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12457
diff
changeset
|
4984 #endif |
7 | 4985 return wp; |
4986 } | |
4987 | |
4988 /* | |
4989 * ":gui" and ":gvim": Change from the terminal version to the GUI version. | |
4990 * File names may be given to redefine the args list. | |
4991 */ | |
4992 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
4993 ex_gui(exarg_T *eap) |
7 | 4994 { |
4995 char_u *arg = eap->arg; | |
4996 | |
4997 /* | |
4998 * Check for "-f" argument: foreground, don't fork. | |
4999 * Also don't fork when started with "gvim -f". | |
5000 * Do fork when using "gui -b". | |
5001 */ | |
5002 if (arg[0] == '-' | |
5003 && (arg[1] == 'f' || arg[1] == 'b') | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5004 && (arg[2] == NUL || VIM_ISWHITE(arg[2]))) |
7 | 5005 { |
5006 gui.dofork = (arg[1] == 'b'); | |
5007 eap->arg = skipwhite(eap->arg + 2); | |
5008 } | |
5009 if (!gui.in_use) | |
5010 { | |
5011 /* Clear the command. Needed for when forking+exiting, to avoid part | |
5012 * of the argument ending up after the shell prompt. */ | |
5013 msg_clr_eos_force(); | |
5014 gui_start(); | |
8493
caed4b2d305f
commit https://github.com/vim/vim/commit/509ce2a558e7e0c03242e32e844255af52f1c821
Christian Brabandt <cb@256bit.org>
parents:
8140
diff
changeset
|
5015 #ifdef FEAT_JOB_CHANNEL |
7770
42c1a4e63d12
commit https://github.com/vim/vim/commit/d04a020a8a8d7a438b091d49218c438880beb50c
Christian Brabandt <cb@256bit.org>
parents:
7469
diff
changeset
|
5016 channel_gui_register_all(); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2208
diff
changeset
|
5017 #endif |
7 | 5018 } |
5019 if (!ends_excmd(*eap->arg)) | |
5020 ex_next(eap); | |
5021 } | |
5022 | |
5023 #if ((defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32) \ | |
574 | 5024 || defined(FEAT_GUI_PHOTON)) && defined(FEAT_TOOLBAR)) || defined(PROTO) |
7 | 5025 /* |
5026 * This is shared between Athena, Motif and GTK. | |
5027 */ | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
5028 static void gfp_setname(char_u *fname, void *cookie); |
7 | 5029 |
5030 /* | |
5031 * Callback function for do_in_runtimepath(). | |
5032 */ | |
5033 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5034 gfp_setname(char_u *fname, void *cookie) |
7 | 5035 { |
236 | 5036 char_u *gfp_buffer = cookie; |
5037 | |
7 | 5038 if (STRLEN(fname) >= MAXPATHL) |
5039 *gfp_buffer = NUL; | |
5040 else | |
5041 STRCPY(gfp_buffer, fname); | |
5042 } | |
5043 | |
5044 /* | |
5045 * Find the path of bitmap "name" with extension "ext" in 'runtimepath'. | |
5046 * Return FAIL for failure and OK if buffer[MAXPATHL] contains the result. | |
5047 */ | |
5048 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5049 gui_find_bitmap(char_u *name, char_u *buffer, char *ext) |
7 | 5050 { |
5051 if (STRLEN(name) > MAXPATHL - 14) | |
5052 return FAIL; | |
273 | 5053 vim_snprintf((char *)buffer, MAXPATHL, "bitmaps/%s.%s", name, ext); |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
8493
diff
changeset
|
5054 if (do_in_runtimepath(buffer, 0, gfp_setname, buffer) == FAIL |
236 | 5055 || *buffer == NUL) |
7 | 5056 return FAIL; |
5057 return OK; | |
5058 } | |
5059 | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
5060 # if !defined(FEAT_GUI_GTK) || defined(PROTO) |
7 | 5061 /* |
5062 * Given the name of the "icon=" argument, try finding the bitmap file for the | |
5063 * icon. If it is an absolute path name, use it as it is. Otherwise append | |
5064 * "ext" and search for it in 'runtimepath'. | |
5065 * The result is put in "buffer[MAXPATHL]". If something fails "buffer" | |
5066 * contains "name". | |
5067 */ | |
5068 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5069 gui_find_iconfile(char_u *name, char_u *buffer, char *ext) |
7 | 5070 { |
5071 char_u buf[MAXPATHL + 1]; | |
5072 | |
5073 expand_env(name, buffer, MAXPATHL); | |
5074 if (!mch_isFullName(buffer) && gui_find_bitmap(buffer, buf, ext) == OK) | |
5075 STRCPY(buffer, buf); | |
5076 } | |
5077 # endif | |
5078 #endif | |
5079 | |
574 | 5080 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(PROTO) |
7 | 5081 void |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5082 display_errors(void) |
7 | 5083 { |
5084 char_u *p; | |
5085 | |
5086 if (isatty(2)) | |
5087 fflush(stderr); | |
5088 else if (error_ga.ga_data != NULL) | |
5089 { | |
5090 /* avoid putting up a message box with blanks only */ | |
5091 for (p = (char_u *)error_ga.ga_data; *p != NUL; ++p) | |
5092 if (!isspace(*p)) | |
5093 { | |
5094 /* Truncate a very long message, it will go off-screen. */ | |
5095 if (STRLEN(p) > 2000) | |
5096 STRCPY(p + 2000 - 14, "...(truncated)"); | |
5097 (void)do_dialog(VIM_ERROR, (char_u *)_("Error"), | |
2684 | 5098 p, (char_u *)_("&Ok"), 1, NULL, FALSE); |
7 | 5099 break; |
5100 } | |
5101 ga_clear(&error_ga); | |
5102 } | |
5103 } | |
5104 #endif | |
5105 | |
5106 #if defined(NO_CONSOLE_INPUT) || defined(PROTO) | |
5107 /* | |
5108 * Return TRUE if still starting up and there is no place to enter text. | |
5109 * For GTK and X11 we check if stderr is not a tty, which means we were | |
5110 * (probably) started from the desktop. Also check stdin, "vim >& file" does | |
5111 * allow typing on stdin. | |
5112 */ | |
5113 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5114 no_console_input(void) |
7 | 5115 { |
5116 return ((!gui.in_use || gui.starting) | |
5117 # ifndef NO_CONSOLE | |
5118 && !isatty(0) && !isatty(2) | |
5119 # endif | |
5120 ); | |
5121 } | |
5122 #endif | |
5123 | |
28 | 5124 #if defined(FIND_REPLACE_DIALOG) || defined(FEAT_SUN_WORKSHOP) \ |
1002 | 5125 || defined(NEED_GUI_UPDATE_SCREEN) \ |
28 | 5126 || defined(PROTO) |
7 | 5127 /* |
5128 * Update the current window and the screen. | |
5129 */ | |
5130 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5131 gui_update_screen(void) |
7 | 5132 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
5133 # ifdef FEAT_CONCEAL |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5134 linenr_T conceal_old_cursor_line = 0; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5135 linenr_T conceal_new_cursor_line = 0; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5136 int conceal_update_lines = FALSE; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
5137 # endif |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5138 |
7 | 5139 update_topline(); |
5140 validate_cursor(); | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5141 |
1584 | 5142 /* Trigger CursorMoved if the cursor moved. */ |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
5143 if (!finish_op && (has_cursormoved() |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
5144 # ifdef FEAT_CONCEAL |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
5145 || curwin->w_p_cole > 0 |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5146 # endif |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
5147 ) && !EQUAL_POS(last_cursormoved, curwin->w_cursor)) |
1584 | 5148 { |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5149 if (has_cursormoved()) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5150 apply_autocmds(EVENT_CURSORMOVED, NULL, NULL, FALSE, curbuf); |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5151 # ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5152 if (curwin->w_p_cole > 0) |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5153 { |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5154 conceal_old_cursor_line = last_cursormoved.lnum; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5155 conceal_new_cursor_line = curwin->w_cursor.lnum; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5156 conceal_update_lines = TRUE; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5157 } |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5158 # endif |
1584 | 5159 last_cursormoved = curwin->w_cursor; |
5160 } | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5161 |
7 | 5162 update_screen(0); /* may need to update the screen */ |
5163 setcursor(); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13194
diff
changeset
|
5164 # ifdef FEAT_CONCEAL |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5165 if (conceal_update_lines |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5166 && (conceal_old_cursor_line != conceal_new_cursor_line |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5167 || conceal_cursor_line(curwin) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5168 || need_cursor_line_redraw)) |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5169 { |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5170 if (conceal_old_cursor_line != conceal_new_cursor_line) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
5171 update_single_line(curwin, conceal_old_cursor_line); |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5172 update_single_line(curwin, conceal_new_cursor_line); |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5173 curwin->w_valid &= ~VALID_CROW; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5174 } |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
5175 # endif |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
5176 out_flush_cursor(TRUE, FALSE); |
7 | 5177 } |
5178 #endif | |
5179 | |
28 | 5180 #if defined(FIND_REPLACE_DIALOG) || defined(PROTO) |
7 | 5181 /* |
5182 * Get the text to use in a find/replace dialog. Uses the last search pattern | |
5183 * if the argument is empty. | |
5184 * Returns an allocated string. | |
5185 */ | |
5186 char_u * | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5187 get_find_dialog_text( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5188 char_u *arg, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5189 int *wwordp, /* return: TRUE if \< \> found */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5190 int *mcasep) /* return: TRUE if \C found */ |
7 | 5191 { |
5192 char_u *text; | |
5193 | |
5194 if (*arg == NUL) | |
5195 text = last_search_pat(); | |
5196 else | |
5197 text = arg; | |
5198 if (text != NULL) | |
5199 { | |
5200 text = vim_strsave(text); | |
5201 if (text != NULL) | |
5202 { | |
835 | 5203 int len = (int)STRLEN(text); |
7 | 5204 int i; |
5205 | |
5206 /* Remove "\V" */ | |
5207 if (len >= 2 && STRNCMP(text, "\\V", 2) == 0) | |
5208 { | |
5209 mch_memmove(text, text + 2, (size_t)(len - 1)); | |
5210 len -= 2; | |
5211 } | |
5212 | |
5213 /* Recognize "\c" and "\C" and remove. */ | |
5214 if (len >= 2 && *text == '\\' && (text[1] == 'c' || text[1] == 'C')) | |
5215 { | |
5216 *mcasep = (text[1] == 'C'); | |
5217 mch_memmove(text, text + 2, (size_t)(len - 1)); | |
5218 len -= 2; | |
5219 } | |
5220 | |
5221 /* Recognize "\<text\>" and remove. */ | |
5222 if (len >= 4 | |
5223 && STRNCMP(text, "\\<", 2) == 0 | |
5224 && STRNCMP(text + len - 2, "\\>", 2) == 0) | |
5225 { | |
5226 *wwordp = TRUE; | |
5227 mch_memmove(text, text + 2, (size_t)(len - 4)); | |
5228 text[len - 4] = NUL; | |
5229 } | |
5230 | |
5231 /* Recognize "\/" or "\?" and remove. */ | |
5232 for (i = 0; i + 1 < len; ++i) | |
5233 if (text[i] == '\\' && (text[i + 1] == '/' | |
5234 || text[i + 1] == '?')) | |
5235 { | |
5236 mch_memmove(text + i, text + i + 1, (size_t)(len - i)); | |
5237 --len; | |
5238 } | |
5239 } | |
5240 } | |
5241 return text; | |
5242 } | |
5243 | |
5244 /* | |
5245 * Handle the press of a button in the find-replace dialog. | |
5246 * Return TRUE when something was added to the input buffer. | |
5247 */ | |
5248 int | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5249 gui_do_findrepl( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5250 int flags, /* one of FRD_REPLACE, FRD_FINDNEXT, etc. */ |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5251 char_u *find_text, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5252 char_u *repl_text, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5253 int down) /* Search downwards. */ |
7 | 5254 { |
5255 garray_T ga; | |
5256 int i; | |
5257 int type = (flags & FRD_TYPE_MASK); | |
5258 char_u *p; | |
28 | 5259 regmatch_T regmatch; |
482 | 5260 int save_did_emsg = did_emsg; |
1943 | 5261 static int busy = FALSE; |
5262 | |
5263 /* When the screen is being updated we should not change buffers and | |
5264 * windows structures, it may cause freed memory to be used. Also don't | |
5265 * do this recursively (pressing "Find" quickly several times. */ | |
5266 if (updating_screen || busy) | |
5267 return FALSE; | |
5268 | |
5269 /* refuse replace when text cannot be changed */ | |
5270 if ((type == FRD_REPLACE || type == FRD_REPLACEALL) && text_locked()) | |
5271 return FALSE; | |
5272 | |
5273 busy = TRUE; | |
7 | 5274 |
5275 ga_init2(&ga, 1, 100); | |
28 | 5276 if (type == FRD_REPLACEALL) |
7 | 5277 ga_concat(&ga, (char_u *)"%s/"); |
5278 | |
5279 ga_concat(&ga, (char_u *)"\\V"); | |
5280 if (flags & FRD_MATCH_CASE) | |
5281 ga_concat(&ga, (char_u *)"\\C"); | |
5282 else | |
5283 ga_concat(&ga, (char_u *)"\\c"); | |
5284 if (flags & FRD_WHOLE_WORD) | |
5285 ga_concat(&ga, (char_u *)"\\<"); | |
13927
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5286 /* escape / and \ */ |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5287 p = vim_strsave_escaped(find_text, (char_u *)"/\\"); |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5288 if (p != NULL) |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5289 ga_concat(&ga, p); |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5290 vim_free(p); |
7 | 5291 if (flags & FRD_WHOLE_WORD) |
5292 ga_concat(&ga, (char_u *)"\\>"); | |
5293 | |
5294 if (type == FRD_REPLACEALL) | |
5295 { | |
28 | 5296 ga_concat(&ga, (char_u *)"/"); |
694 | 5297 /* escape / and \ */ |
5298 p = vim_strsave_escaped(repl_text, (char_u *)"/\\"); | |
5299 if (p != NULL) | |
5300 ga_concat(&ga, p); | |
5301 vim_free(p); | |
28 | 5302 ga_concat(&ga, (char_u *)"/g"); |
5303 } | |
5304 ga_append(&ga, NUL); | |
5305 | |
5306 if (type == FRD_REPLACE) | |
5307 { | |
5308 /* Do the replacement when the text at the cursor matches. Thus no | |
5309 * replacement is done if the cursor was moved! */ | |
5310 regmatch.regprog = vim_regcomp(ga.ga_data, RE_MAGIC + RE_STRING); | |
5311 regmatch.rm_ic = 0; | |
5312 if (regmatch.regprog != NULL) | |
5313 { | |
5314 p = ml_get_cursor(); | |
5315 if (vim_regexec_nl(®match, p, (colnr_T)0) | |
5316 && regmatch.startp[0] == p) | |
5317 { | |
5318 /* Clear the command line to remove any old "No match" | |
5319 * error. */ | |
5320 msg_end_prompt(); | |
5321 | |
5322 if (u_save_cursor() == OK) | |
5323 { | |
5324 /* A button was pressed thus undo should be synced. */ | |
825 | 5325 u_sync(FALSE); |
28 | 5326 |
5327 del_bytes((long)(regmatch.endp[0] - regmatch.startp[0]), | |
609 | 5328 FALSE, FALSE); |
28 | 5329 ins_str(repl_text); |
5330 } | |
5331 } | |
5332 else | |
5333 MSG(_("No match at cursor, finding next")); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
5334 vim_regfree(regmatch.regprog); |
28 | 5335 } |
5336 } | |
5337 | |
5338 if (type == FRD_REPLACEALL) | |
5339 { | |
7 | 5340 /* A button was pressed, thus undo should be synced. */ |
825 | 5341 u_sync(FALSE); |
7 | 5342 do_cmdline_cmd(ga.ga_data); |
5343 } | |
5344 else | |
5345 { | |
9305
4981cd0802c7
commit https://github.com/vim/vim/commit/bee666f239eada035d288b77269aebc42f644ea6
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5346 int searchflags = SEARCH_MSG + SEARCH_MARK; |
4981cd0802c7
commit https://github.com/vim/vim/commit/bee666f239eada035d288b77269aebc42f644ea6
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5347 |
4981cd0802c7
commit https://github.com/vim/vim/commit/bee666f239eada035d288b77269aebc42f644ea6
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5348 /* Search for the next match. |
4981cd0802c7
commit https://github.com/vim/vim/commit/bee666f239eada035d288b77269aebc42f644ea6
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5349 * Don't skip text under cursor for single replace. */ |
4981cd0802c7
commit https://github.com/vim/vim/commit/bee666f239eada035d288b77269aebc42f644ea6
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5350 if (type == FRD_REPLACE) |
4981cd0802c7
commit https://github.com/vim/vim/commit/bee666f239eada035d288b77269aebc42f644ea6
Christian Brabandt <cb@256bit.org>
parents:
8947
diff
changeset
|
5351 searchflags += SEARCH_START; |
7 | 5352 i = msg_scroll; |
13927
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5353 if (down) |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5354 { |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5355 (void)do_search(NULL, '/', ga.ga_data, 1L, searchflags, NULL, NULL); |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5356 } |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5357 else |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5358 { |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5359 /* We need to escape '?' if and only if we are searching in the up |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5360 * direction */ |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5361 p = vim_strsave_escaped(ga.ga_data, (char_u *)"?"); |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5362 if (p != NULL) |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5363 (void)do_search(NULL, '?', p, 1L, searchflags, NULL, NULL); |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5364 vim_free(p); |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5365 } |
ec54a202ad0c
patch 8.0.1834: GUI: find/replace dialog does not handle some chars
Christian Brabandt <cb@256bit.org>
parents:
13847
diff
changeset
|
5366 |
7 | 5367 msg_scroll = i; /* don't let an error message set msg_scroll */ |
5368 } | |
5369 | |
482 | 5370 /* Don't want to pass did_emsg to other code, it may cause disabling |
5371 * syntax HL if we were busy redrawing. */ | |
5372 did_emsg = save_did_emsg; | |
5373 | |
7 | 5374 if (State & (NORMAL | INSERT)) |
5375 { | |
5376 gui_update_screen(); /* update the screen */ | |
5377 msg_didout = 0; /* overwrite any message */ | |
5378 need_wait_return = FALSE; /* don't wait for return */ | |
5379 } | |
5380 | |
5381 vim_free(ga.ga_data); | |
1943 | 5382 busy = FALSE; |
7 | 5383 return (ga.ga_len > 0); |
5384 } | |
5385 | |
5386 #endif | |
5387 | |
5388 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \ | |
5389 || defined(FEAT_GUI_MSWIN) \ | |
5390 || defined(FEAT_GUI_MAC) \ | |
5391 || defined(PROTO) | |
5392 | |
7801
a1e71a01dbd6
commit https://github.com/vim/vim/commit/d25c16e2f2776d50245bf31d6e4d5364f12d188e
Christian Brabandt <cb@256bit.org>
parents:
7770
diff
changeset
|
5393 static void gui_wingoto_xy(int x, int y); |
7 | 5394 |
5395 /* | |
5396 * Jump to the window at specified point (x, y). | |
5397 */ | |
5398 static void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5399 gui_wingoto_xy(int x, int y) |
7 | 5400 { |
5401 int row = Y_2_ROW(y); | |
5402 int col = X_2_COL(x); | |
5403 win_T *wp; | |
5404 | |
5405 if (row >= 0 && col >= 0) | |
5406 { | |
5407 wp = mouse_find_win(&row, &col); | |
5408 if (wp != NULL && wp != curwin) | |
5409 win_goto(wp); | |
5410 } | |
5411 } | |
5412 | |
5413 /* | |
5414 * Process file drop. Mouse cursor position, key modifiers, name of files | |
5415 * and count of files are given. Argument "fnames[count]" has full pathnames | |
5416 * of dropped files, they will be freed in this function, and caller can't use | |
5417 * fnames after call this function. | |
5418 */ | |
5419 void | |
7821
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5420 gui_handle_drop( |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5421 int x UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5422 int y UNUSED, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5423 int_u modifiers, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5424 char_u **fnames, |
81794242a275
commit https://github.com/vim/vim/commit/66f948e928d5e0cd3123af902aa8ac1613534c94
Christian Brabandt <cb@256bit.org>
parents:
7801
diff
changeset
|
5425 int count) |
7 | 5426 { |
5427 int i; | |
5428 char_u *p; | |
1668 | 5429 static int entered = FALSE; |
5430 | |
5431 /* | |
5432 * This function is called by event handlers. Just in case we get a | |
5433 * second event before the first one is handled, ignore the second one. | |
5434 * Not sure if this can ever happen, just in case. | |
5435 */ | |
5436 if (entered) | |
5437 return; | |
5438 entered = TRUE; | |
7 | 5439 |
5440 /* | |
5441 * When the cursor is at the command line, add the file names to the | |
5442 * command line, don't edit the files. | |
5443 */ | |
5444 if (State & CMDLINE) | |
5445 { | |
5446 shorten_filenames(fnames, count); | |
5447 for (i = 0; i < count; ++i) | |
5448 { | |
5449 if (fnames[i] != NULL) | |
5450 { | |
5451 if (i > 0) | |
5452 add_to_input_buf((char_u*)" ", 1); | |
5453 | |
5454 /* We don't know what command is used thus we can't be sure | |
5455 * about which characters need to be escaped. Only escape the | |
5456 * most common ones. */ | |
5457 # ifdef BACKSLASH_IN_FILENAME | |
5458 p = vim_strsave_escaped(fnames[i], (char_u *)" \t\"|"); | |
5459 # else | |
5460 p = vim_strsave_escaped(fnames[i], (char_u *)"\\ \t\"|"); | |
5461 # endif | |
5462 if (p != NULL) | |
1364 | 5463 add_to_input_buf_csi(p, (int)STRLEN(p)); |
7 | 5464 vim_free(p); |
5465 vim_free(fnames[i]); | |
5466 } | |
5467 } | |
5468 vim_free(fnames); | |
5469 } | |
5470 else | |
5471 { | |
5472 /* Go to the window under mouse cursor, then shorten given "fnames" by | |
5473 * current window, because a window can have local current dir. */ | |
5474 gui_wingoto_xy(x, y); | |
5475 shorten_filenames(fnames, count); | |
5476 | |
5477 /* If Shift held down, remember the first item. */ | |
5478 if ((modifiers & MOUSE_SHIFT) != 0) | |
5479 p = vim_strsave(fnames[0]); | |
5480 else | |
5481 p = NULL; | |
5482 | |
5483 /* Handle the drop, :edit or :split to get to the file. This also | |
5484 * frees fnames[]. Skip this if there is only one item it's a | |
5485 * directory and Shift is held down. */ | |
5486 if (count == 1 && (modifiers & MOUSE_SHIFT) != 0 | |
5487 && mch_isdir(fnames[0])) | |
5488 { | |
5489 vim_free(fnames[0]); | |
5490 vim_free(fnames); | |
5491 } | |
5492 else | |
5493 handle_drop(count, fnames, (modifiers & MOUSE_CTRL) != 0); | |
5494 | |
5495 /* If Shift held down, change to first file's directory. If the first | |
5496 * item is a directory, change to that directory (and let the explorer | |
5497 * plugin show the contents). */ | |
5498 if (p != NULL) | |
5499 { | |
5500 if (mch_isdir(p)) | |
5501 { | |
5502 if (mch_chdir((char *)p) == 0) | |
5503 shorten_fnames(TRUE); | |
5504 } | |
13176
bd1253c60938
patch 8.0.1462: missing yet another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13152
diff
changeset
|
5505 else if (vim_chdirfile(p, "drop") == OK) |
7 | 5506 shorten_fnames(TRUE); |
5507 vim_free(p); | |
5508 } | |
5509 | |
5510 /* Update the screen display */ | |
5511 update_screen(NOT_VALID); | |
5512 # ifdef FEAT_MENU | |
5513 gui_update_menus(0); | |
5514 # endif | |
2208
495995b9ce7d
Fix: window title not updated after file dropped.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
5515 #ifdef FEAT_TITLE |
495995b9ce7d
Fix: window title not updated after file dropped.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
5516 maketitle(); |
495995b9ce7d
Fix: window title not updated after file dropped.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
5517 #endif |
7 | 5518 setcursor(); |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
13080
diff
changeset
|
5519 out_flush_cursor(FALSE, FALSE); |
7 | 5520 } |
1668 | 5521 |
5522 entered = FALSE; | |
7 | 5523 } |
5524 #endif |