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