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