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