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