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