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