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