1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * GUI/Motif support by Robert Webb
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.
13 /* Structure containing all the GUI information */
16 #if defined(FEAT_MBYTE) && !defined(HAVE_GTK2)
17 static void set_guifontwide
__ARGS((char_u
*font_name
));
19 static void gui_check_pos
__ARGS((void));
20 static void gui_position_components
__ARGS((int));
21 static void gui_outstr
__ARGS((char_u
*, int));
22 static int gui_screenchar
__ARGS((int off
, int flags
, guicolor_T fg
, guicolor_T bg
, int back
));
24 static int gui_screenstr
__ARGS((int off
, int len
, int flags
, guicolor_T fg
, guicolor_T bg
, int back
));
26 static void gui_delete_lines
__ARGS((int row
, int count
));
27 static void gui_insert_lines
__ARGS((int row
, int count
));
28 static void fill_mouse_coord
__ARGS((char_u
*p
, int col
, int row
));
29 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
30 static int gui_has_tabline
__ARGS((void));
32 static void gui_do_scrollbar
__ARGS((win_T
*wp
, int which
, int enable
));
33 static colnr_T scroll_line_len
__ARGS((linenr_T lnum
));
34 static void gui_update_horiz_scrollbar
__ARGS((int));
35 static void gui_set_fg_color
__ARGS((char_u
*name
));
36 static void gui_set_bg_color
__ARGS((char_u
*name
));
37 static win_T
*xy2win
__ARGS((int x
, int y
));
39 static int can_update_cursor
= TRUE
; /* can display the cursor */
42 * The Athena scrollbars can move the thumb to after the end of the scrollbar,
43 * this makes the thumb indicate the part of the text that is shown. Motif
46 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MAC)
47 # define SCROLL_PAST_END
51 * gui_start -- Called when user wants to start the GUI.
53 * Careful: This function can be called recursively when there is a ":gui"
54 * command in the .gvimrc file. Only the first call should fork, not the
61 #if defined(UNIX) && !defined(__BEOS__) && !defined(MACOS_X)
62 /* By the time we get here Mac OS X will already have forked (it does so
63 * right after scanning the command line) so don't do anything here. This
64 * means that "f" in 'guioptions' cannot be supported.
69 static int recursive
= 0;
71 old_term
= vim_strsave(T_NAME
);
74 * Set_termname() will call gui_init() to start the GUI.
75 * Set the "starting" flag, to indicate that the GUI will start.
77 * We don't want to open the GUI shell until after we've read .gvimrc,
78 * otherwise we don't know what font we will use, and hence we don't know
79 * what size the shell should be. So if there are errors in the .gvimrc
80 * file, they will have to go to the terminal: Set full_screen to FALSE.
81 * full_screen will be set to TRUE again by a successful termcapinit().
83 settmode(TMODE_COOK
); /* stop RAW mode */
85 cursor_on(); /* needed for ":gui" in .vimrc */
90 if (!gui
.dofork
|| vim_strchr(p_go
, GO_FORG
) || recursive
)
95 termcapinit((char_u
*)"builtin_gui");
96 gui
.starting
= recursive
- 1;
98 if (!gui
.in_use
) /* failed to start GUI */
100 termcapinit(old_term
); /* back to old term settings */
101 settmode(TMODE_RAW
); /* restart RAW mode */
103 set_title_defaults(); /* set 'title' and 'icon' again */
109 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
111 /* Display error messages in a dialog now. */
115 #if defined(MAY_FORK) && !defined(__QNXNTO__)
117 * Quit the current process and continue in the child.
118 * Makes "gvim file" disconnect from the shell it was started in.
119 * Don't do this when Vim was started with "-f" or the 'f' flag is present
122 if (gui
.in_use
&& dofork
)
124 int pipefd
[2]; /* pipe between parent and child */
129 /* Setup a pipe between the child and the parent, so that the parent
130 * knows when the child has done the setsid() call and is allowed to
132 pipe_error
= (pipe(pipefd
) < 0);
134 if (pid
> 0) /* Parent */
136 /* Give the child some time to do the setsid(), otherwise the
137 * exit() may kill the child too (when starting gvim from inside a
140 ui_delay(300L, TRUE
);
143 /* The read returns when the child closes the pipe (or when
144 * the child dies for some reason). */
146 ignored
= (int)read(pipefd
[0], &dummy
, (size_t)1);
150 /* When swapping screens we may need to go to the next line, e.g.,
151 * after a hit-enter prompt and using ":gui". */
156 * The parent must skip the normal exit() processing, the child
157 * will do it. For example, GTK messes up signals when exiting.
162 # if defined(HAVE_SETSID) || defined(HAVE_SETPGID)
164 * Change our process group. On some systems/shells a CTRL-C in the
165 * shell where Vim was started would otherwise kill gvim!
167 if (pid
== 0) /* child */
168 # if defined(HAVE_SETSID)
180 # if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)
181 /* Tell the session manager our new PID */
186 # if defined(__QNXNTO__)
187 if (gui
.in_use
&& dofork
)
188 procmgr_daemon(0, PROCMGR_DAEMON_KEEPUMASK
| PROCMGR_DAEMON_NOCHDIR
|
189 PROCMGR_DAEMON_NOCLOSE
| PROCMGR_DAEMON_NODEVNULL
);
194 /* If the GUI started successfully, trigger the GUIEnter event, otherwise
195 * the GUIFailed event. */
196 apply_autocmds(gui
.in_use
? EVENT_GUIENTER
: EVENT_GUIFAILED
,
197 NULL
, NULL
, FALSE
, curbuf
);
204 * Call this when vim starts up, whether or not the GUI is started
207 gui_prepare(argc
, argv
)
211 gui
.in_use
= FALSE
; /* No GUI yet (maybe later) */
212 gui
.starting
= FALSE
; /* No GUI yet (maybe later) */
213 gui_mch_prepare(argc
, argv
);
217 * Try initializing the GUI and check if it can be started.
218 * Used from main() to check early if "vim -g" can start the GUI.
219 * Used from gui_init() to prepare for starting the GUI.
220 * Returns FAIL or OK.
225 static int result
= MAYBE
;
230 EMSG(_("E229: Cannot start the GUI"));
234 gui
.shell_created
= FALSE
;
236 gui
.in_focus
= TRUE
; /* so the guicursor setting works */
237 gui
.dragged_sb
= SBAR_NONE
;
238 gui
.dragged_wp
= NULL
;
239 gui
.pointer_hidden
= FALSE
;
242 gui
.num_cols
= Columns
;
245 gui
.cursor_is_valid
= FALSE
;
246 gui
.scroll_region_top
= 0;
247 gui
.scroll_region_bot
= Rows
- 1;
248 gui
.scroll_region_left
= 0;
249 gui
.scroll_region_right
= Columns
- 1;
250 gui
.highlight_mask
= HL_NORMAL
;
254 gui
.border_width
= 0;
256 gui
.norm_font
= NOFONT
;
258 gui
.bold_font
= NOFONT
;
259 gui
.ital_font
= NOFONT
;
260 gui
.boldital_font
= NOFONT
;
261 # ifdef FEAT_XFONTSET
262 gui
.fontset
= NOFONTSET
;
268 # ifdef FONTSET_ALWAYS
269 gui
.menu_fontset
= NOFONTSET
;
271 gui
.menu_font
= NOFONT
;
274 gui
.menu_is_active
= TRUE
; /* default: include menu */
275 # if !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM))
276 gui
.menu_height
= MENU_DEFAULT_HEIGHT
;
280 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA))
281 gui
.toolbar_height
= 0;
283 #if defined(FEAT_FOOTER) && defined(FEAT_GUI_MOTIF)
284 gui
.footer_height
= 0;
286 #ifdef FEAT_BEVAL_TIP
287 gui
.tooltip_fontset
= NOFONTSET
;
290 gui
.scrollbar_width
= gui
.scrollbar_height
= SB_DEFAULT_WIDTH
;
293 #ifdef ALWAYS_USE_GUI
296 result
= gui_mch_init_check();
302 * This is the call which starts the GUI.
308 static int recursive
= 0;
311 * It's possible to use ":gui" in a .gvimrc file. The first halve of this
312 * function will then be executed at the first call, the rest by the
313 * recursive call. This allow the shell to be opened halfway reading a
322 /* If can't initialize, don't try doing the rest */
323 if (gui_init_check() == FAIL
)
331 * Reset 'paste'. It's useful in the terminal, but not in the GUI. It
332 * breaks the Paste toolbar button.
334 set_option_value((char_u
*)"paste", 0L, NULL
, 0);
337 * Set up system-wide default menus.
339 #if defined(SYS_MENU_FILE) && defined(FEAT_MENU)
340 if (vim_strchr(p_go
, GO_NOSYSMENU
) == NULL
)
343 do_source((char_u
*)SYS_MENU_FILE
, FALSE
, DOSO_NONE
);
349 * Switch on the mouse by default, unless the user changed it already.
350 * This can then be changed in the .gvimrc.
352 if (!option_was_set((char_u
*)"mouse"))
353 set_string_option_direct((char_u
*)"mouse", -1,
354 (char_u
*)"a", OPT_FREE
, SID_NONE
);
357 * If -U option given, use only the initializations from that file and
358 * nothing else. Skip all initializations for "-U NONE" or "-u NORC".
360 if (use_gvimrc
!= NULL
)
362 if (STRCMP(use_gvimrc
, "NONE") != 0
363 && STRCMP(use_gvimrc
, "NORC") != 0
364 && do_source(use_gvimrc
, FALSE
, DOSO_NONE
) != OK
)
365 EMSG2(_("E230: Cannot read from \"%s\""), use_gvimrc
);
370 * Get system wide defaults for gvim, only when file name defined.
372 #ifdef SYS_GVIMRC_FILE
373 do_source((char_u
*)SYS_GVIMRC_FILE
, FALSE
, DOSO_NONE
);
377 * Try to read GUI initialization commands from the following
379 * - environment variable GVIMINIT
380 * - the user gvimrc file (~/.gvimrc)
381 * - the second user gvimrc file ($VIM/.gvimrc for Dos)
382 * - the third user gvimrc file ($VIM/.gvimrc for Amiga)
383 * The first that exists is used, the rest is ignored.
385 if (process_env((char_u
*)"GVIMINIT", FALSE
) == FAIL
386 && do_source((char_u
*)USR_GVIMRC_FILE
, TRUE
,
388 #ifdef USR_GVIMRC_FILE2
389 && do_source((char_u
*)USR_GVIMRC_FILE2
, TRUE
,
394 #ifdef USR_GVIMRC_FILE3
395 (void)do_source((char_u
*)USR_GVIMRC_FILE3
, TRUE
, DOSO_GVIMRC
);
400 * Read initialization commands from ".gvimrc" in current
401 * directory. This is only done if the 'exrc' option is set.
402 * Because of security reasons we disallow shell and write
403 * commands now, except for unix if the file is owned by the user
404 * or 'secure' option has been reset in environment of global
406 * Only do this if GVIMRC_FILE is not the same as USR_GVIMRC_FILE,
407 * USR_GVIMRC_FILE2, USR_GVIMRC_FILE3 or SYS_GVIMRC_FILE.
415 /* if ".gvimrc" file is not owned by user, set 'secure'
417 if (mch_stat(GVIMRC_FILE
, &s
) || s
.st_uid
!= getuid())
424 if ( fullpathcmp((char_u
*)USR_GVIMRC_FILE
,
425 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
426 #ifdef SYS_GVIMRC_FILE
427 && fullpathcmp((char_u
*)SYS_GVIMRC_FILE
,
428 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
430 #ifdef USR_GVIMRC_FILE2
431 && fullpathcmp((char_u
*)USR_GVIMRC_FILE2
,
432 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
434 #ifdef USR_GVIMRC_FILE3
435 && fullpathcmp((char_u
*)USR_GVIMRC_FILE3
,
436 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
439 do_source((char_u
*)GVIMRC_FILE
, TRUE
, DOSO_GVIMRC
);
442 need_wait_return
= TRUE
;
447 if (need_wait_return
|| msg_didany
)
453 /* If recursive call opened the shell, return here from the first call */
458 * Create the GUI shell.
460 gui
.in_use
= TRUE
; /* Must be set after menus have been set up */
461 if (gui_mch_init() == FAIL
)
464 /* Avoid a delay for an error message that was printed in the terminal
465 * where Vim was started. */
466 emsg_on_display
= FALSE
;
469 need_wait_return
= FALSE
;
473 * Check validity of any generic resources that may have been loaded.
475 if (gui
.border_width
< 0)
476 gui
.border_width
= 0;
479 * Set up the fonts. First use a font specified with "-fn" or "-font".
481 if (font_argument
!= NULL
)
482 set_option_value((char_u
*)"gfn", 0L, (char_u
*)font_argument
, 0);
485 (*p_guifontset
== NUL
486 || gui_init_font(p_guifontset
, TRUE
) == FAIL
) &&
488 gui_init_font(*p_guifont
== NUL
? hl_get_font_name()
489 : p_guifont
, FALSE
) == FAIL
)
491 EMSG(_("E665: Cannot start GUI, no valid font found"));
495 if (gui_get_wide_font() == FAIL
)
496 EMSG(_("E231: 'guifontwide' invalid"));
499 gui
.num_cols
= Columns
;
501 gui_reset_scroll_region();
503 /* Create initial scrollbars */
506 gui_create_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
], SBAR_LEFT
, wp
);
507 gui_create_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
], SBAR_RIGHT
, wp
);
509 gui_create_scrollbar(&gui
.bottom_sbar
, SBAR_BOTTOM
, NULL
);
512 gui_create_initial_menus(root_menu
);
514 #ifdef FEAT_SUN_WORKSHOP
515 if (usingSunWorkShop
)
518 #ifdef FEAT_SIGN_ICONS
522 /* Configure the desired menu and scrollbars */
523 gui_init_which_components(NULL
);
525 /* All components of the GUI have been created now */
526 gui
.shell_created
= TRUE
;
529 /* Set the shell size, adjusted for the screen size. For GTK this only
530 * works after the shell has been opened, thus it is further down. */
531 gui_set_shellsize(FALSE
, TRUE
, RESIZE_BOTH
);
533 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)
534 /* Need to set the size of the menubar after all the menus have been
536 gui_mch_compute_menu_height((Widget
)0);
540 * Actually open the GUI shell.
542 if (gui_mch_open() != FAIL
)
550 /* Our GUI can't do bidi. */
553 #if defined(FEAT_GUI_GTK)
554 /* Give GTK+ a chance to put all widget's into place. */
558 /* If there is no 'm' in 'guioptions' we need to remove the menu now.
559 * It was still there to make F10 work. */
560 if (vim_strchr(p_go
, GO_MENUS
) == NULL
)
563 gui_mch_enable_menu(FALSE
);
569 /* Now make sure the shell fits on the screen. */
570 gui_set_shellsize(FALSE
, TRUE
, RESIZE_BOTH
);
572 /* When 'lines' was set while starting up the topframe may have to be
577 /* Always create the Balloon Evaluation area, but disable it when
578 * 'ballooneval' is off */
580 balloonEval
= gui_mch_create_beval_area(gui
.drawarea
, NULL
,
581 &general_beval_cb
, NULL
);
583 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
585 extern Widget textArea
;
586 balloonEval
= gui_mch_create_beval_area(textArea
, NULL
,
587 &general_beval_cb
, NULL
);
591 balloonEval
= gui_mch_create_beval_area(NULL
, NULL
,
592 &general_beval_cb
, NULL
);
597 gui_mch_disable_beval_area(balloonEval
);
600 #ifdef FEAT_NETBEANS_INTG
601 if (starting
== 0 && usingNetbeans
)
602 /* Tell the client that it can start sending commands. */
603 netbeans_startup_done();
605 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
606 if (!im_xim_isvalid_imactivate())
607 EMSG(_("E599: Value of 'imactivatekey' is invalid"));
609 /* When 'cmdheight' was set during startup it may not have taken
619 /* undo gui_mch_init() */
634 /* don't free the fonts, it leads to a BUS error
635 * richard@whitequeen.com Jul 99 */
636 free_highlight_fonts();
642 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_MSWIN) \
643 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) \
644 || defined(PROTO) || defined(FEAT_GUI_MACVIM)
645 # define NEED_GUI_UPDATE_SCREEN 1
647 * Called when the GUI shell is closed by the user. If there are no changed
648 * files Vim exits, otherwise there will be a dialog to ask the user what to
650 * When this function returns, Vim should NOT exit!
655 cmdmod_T save_cmdmod
;
657 save_cmdmod
= cmdmod
;
659 /* Only exit when there are no changed files */
662 cmdmod
.browse
= TRUE
;
664 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
665 cmdmod
.confirm
= TRUE
;
667 /* If there are changed buffers, present the user with a dialog if
668 * possible, otherwise give an error message. */
669 if (!check_changed_any(FALSE
))
673 cmdmod
= save_cmdmod
;
674 gui_update_screen(); /* redraw, window may show changed buffer */
679 * Set the font. "font_list" is a a comma separated list of font names. The
680 * first font name that works is used. If none is found, use the default
682 * If "fontset" is TRUE, the "font_list" is used as one name for the fontset.
683 * Return OK when able to set the font. When it failed FAIL is returned and
684 * the fonts are unchanged.
687 gui_init_font(font_list
, fontset
)
692 char_u font_name
[FONTLEN
];
693 int font_list_empty
= FALSE
;
700 if (*font_list
== NUL
)
701 font_list_empty
= TRUE
;
705 /* When using a fontset, the whole list of fonts is one name. */
707 ret
= gui_mch_init_font(font_list
, TRUE
);
710 while (*font_list
!= NUL
)
712 /* Isolate one comma separated font name. */
713 (void)copy_option_part(&font_list
, font_name
, FONTLEN
, ",");
715 #if defined(FEAT_GUI_MACVIM)
716 /* The font dialog is modeless in Mac OS X, so when
717 * gui_mch_init_font() is called with "*" it brings up the
718 * dialog and returns immediately. In this case we don't want
719 * it to be called again with NULL, so return here. */
720 if (STRCMP(font_name
, "*") == 0) {
721 gui_mch_init_font(font_name
, FALSE
);
726 /* Careful!!! The Win32 version of gui_mch_init_font(), when
727 * called with "*" will change p_guifont to the selected font
728 * name, which frees the old value. This makes font_list
729 * invalid. Thus when OK is returned here, font_list must no
731 if (gui_mch_init_font(font_name
, FALSE
) == OK
)
733 #if defined(FEAT_MBYTE) && !defined(HAVE_GTK2)
734 /* If it's a Unicode font, try setting 'guifontwide' to a
735 * similar double-width font. */
736 if ((p_guifontwide
== NULL
|| *p_guifontwide
== NUL
)
737 && strstr((char *)font_name
, "10646") != NULL
)
738 set_guifontwide(font_name
);
747 && STRCMP(font_list
, "*") != 0
748 && (font_list_empty
|| gui
.norm_font
== NOFONT
))
751 * Couldn't load any font in 'font_list', keep the current font if
752 * there is one. If 'font_list' is empty, or if there is no current
753 * font, tell gui_mch_init_font() to try to find a font we can load.
755 ret
= gui_mch_init_font(NULL
, FALSE
);
761 /* Set normal font as current font */
762 # ifdef FEAT_XFONTSET
763 if (gui
.fontset
!= NOFONTSET
)
764 gui_mch_set_fontset(gui
.fontset
);
767 gui_mch_set_font(gui
.norm_font
);
769 gui_set_shellsize(FALSE
,
781 #if defined(FEAT_MBYTE) || defined(PROTO)
784 * Try setting 'guifontwide' to a font twice as wide as "name".
787 set_guifontwide(name
)
791 char_u wide_name
[FONTLEN
+ 10]; /* room for 2 * width and '*' */
797 for (p
= name
; *p
!= NUL
; ++p
)
803 if (i
== 6) /* font type: change "--" to "-*-" */
808 else if (i
== 12) /* found the width */
814 /* Double the width specification. */
815 sprintf((char *)wp
, "%d%s", i
* 2, p
);
816 font
= gui_mch_get_font(wide_name
, FALSE
);
819 gui_mch_free_font(gui
.wide_font
);
820 gui
.wide_font
= font
;
821 set_string_option_direct((char_u
*)"gfw", -1,
822 wide_name
, OPT_FREE
, 0);
830 # endif /* !HAVE_GTK2 */
833 * Get the font for 'guifontwide'.
834 * Return FAIL for an invalid font name.
839 GuiFont font
= NOFONT
;
840 char_u font_name
[FONTLEN
];
843 if (!gui
.in_use
) /* Can't allocate font yet, assume it's OK. */
844 return OK
; /* Will give an error message later. */
846 if (p_guifontwide
!= NULL
&& *p_guifontwide
!= NUL
)
848 for (p
= p_guifontwide
; *p
!= NUL
; )
850 /* Isolate one comma separated font name. */
851 (void)copy_option_part(&p
, font_name
, FONTLEN
, ",");
852 font
= gui_mch_get_font(font_name
, FALSE
);
860 gui_mch_free_font(gui
.wide_font
);
862 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */
863 if (font
!= NOFONT
&& gui
.norm_font
!= NOFONT
864 && pango_font_description_equal(font
, gui
.norm_font
))
866 gui
.wide_font
= NOFONT
;
867 gui_mch_free_font(font
);
871 gui
.wide_font
= font
;
877 gui_set_cursor(row
, col
)
886 * gui_check_pos - check if the cursor is on the screen.
891 if (gui
.row
>= screen_Rows
)
892 gui
.row
= screen_Rows
- 1;
893 if (gui
.col
>= screen_Columns
)
894 gui
.col
= screen_Columns
- 1;
895 if (gui
.cursor_row
>= screen_Rows
|| gui
.cursor_col
>= screen_Columns
)
896 gui
.cursor_is_valid
= FALSE
;
900 * Redraw the cursor if necessary or when forced.
901 * Careful: The contents of ScreenLines[] must match what is on the screen,
902 * otherwise this goes wrong. May need to call out_flush() first.
905 gui_update_cursor(force
, clear_selection
)
906 int force
; /* when TRUE, update even when not moved */
907 int clear_selection
;/* clear selection under cursor */
914 guicolor_T cfg
, cbg
, cc
; /* cursor fore-/background color */
915 int cattr
; /* cursor attributes */
917 attrentry_T
*aep
= NULL
;
919 /* Don't update the cursor when halfway busy scrolling or the screen size
920 * doesn't match 'columns' and 'lines. ScreenLines[] isn't valid then. */
921 if (!can_update_cursor
|| screen_Columns
!= gui
.num_cols
922 || screen_Rows
!= gui
.num_rows
)
926 if (!gui
.cursor_is_valid
|| force
927 || gui
.row
!= gui
.cursor_row
|| gui
.col
!= gui
.cursor_col
)
932 #ifdef USE_IM_CONTROL
933 if (gui
.row
!= gui
.cursor_row
|| gui
.col
!= gui
.cursor_col
)
934 im_set_position(gui
.row
, gui
.col
);
936 gui
.cursor_row
= gui
.row
;
937 gui
.cursor_col
= gui
.col
;
939 /* Only write to the screen after ScreenLines[] has been initialized */
940 if (!screen_cleared
|| ScreenLines
== NULL
)
943 /* Clear the selection if we are about to write over it */
945 clip_may_clear_selection(gui
.row
, gui
.row
);
946 /* Check that the cursor is inside the shell (resizing may have made
948 if (gui
.row
>= screen_Rows
|| gui
.col
>= screen_Columns
)
951 gui
.cursor_is_valid
= TRUE
;
954 * How the cursor is drawn depends on the current mode.
956 idx
= get_shape_idx(FALSE
);
958 id
= shape_table
[idx
].id_lm
;
960 id
= shape_table
[idx
].id
;
962 /* get the colors and attributes for the cursor. Default is inverted */
966 gui_mch_set_blinking(shape_table
[idx
].blinkwait
,
967 shape_table
[idx
].blinkon
,
968 shape_table
[idx
].blinkoff
);
971 cattr
= syn_id2colors(id
, &cfg
, &cbg
);
972 #if defined(USE_IM_CONTROL) || defined(FEAT_HANGULIN)
978 # if defined(HAVE_GTK2) && !defined(FEAT_HANGULIN)
985 iid
= syn_name2id((char_u
*)"CursorIM");
988 syn_id2colors(iid
, &fg
, &bg
);
989 if (bg
!= INVALCOLOR
)
991 if (fg
!= INVALCOLOR
)
1000 * Get the attributes for the character under the cursor.
1001 * When no cursor color was given, use the character color.
1003 attr
= ScreenAttrs
[LineOffset
[gui
.row
] + gui
.col
];
1005 aep
= syn_gui_attr2entry(attr
);
1008 attr
= aep
->ae_attr
;
1009 if (cfg
== INVALCOLOR
)
1010 cfg
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.bg_color
1011 : aep
->ae_u
.gui
.fg_color
);
1012 if (cbg
== INVALCOLOR
)
1013 cbg
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.fg_color
1014 : aep
->ae_u
.gui
.bg_color
);
1016 if (cfg
== INVALCOLOR
)
1017 cfg
= (attr
& HL_INVERSE
) ? gui
.back_pixel
: gui
.norm_pixel
;
1018 if (cbg
== INVALCOLOR
)
1019 cbg
= (attr
& HL_INVERSE
) ? gui
.norm_pixel
: gui
.back_pixel
;
1024 xim_bg_color
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.fg_color
1025 : aep
->ae_u
.gui
.bg_color
);
1026 xim_fg_color
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.bg_color
1027 : aep
->ae_u
.gui
.fg_color
);
1028 if (xim_bg_color
== INVALCOLOR
)
1029 xim_bg_color
= (attr
& HL_INVERSE
) ? gui
.norm_pixel
1031 if (xim_fg_color
== INVALCOLOR
)
1032 xim_fg_color
= (attr
& HL_INVERSE
) ? gui
.back_pixel
1037 xim_bg_color
= (attr
& HL_INVERSE
) ? gui
.norm_pixel
1039 xim_fg_color
= (attr
& HL_INVERSE
) ? gui
.back_pixel
1044 attr
&= ~HL_INVERSE
;
1045 if (cattr
& HL_INVERSE
)
1051 cattr
&= ~HL_INVERSE
;
1054 * When we don't have window focus, draw a hollow cursor.
1058 gui_mch_draw_hollow_cursor(cbg
);
1062 old_hl_mask
= gui
.highlight_mask
;
1063 if (shape_table
[idx
].shape
== SHAPE_BLOCK
1064 #ifdef FEAT_HANGULIN
1070 * Draw the text character with the cursor colors. Use the
1071 * character attributes plus the cursor attributes.
1073 gui
.highlight_mask
= (cattr
| attr
);
1074 #ifdef FEAT_HANGULIN
1075 if (composing_hangul
)
1076 (void)gui_outstr_nowrap(composing_hangul_buffer
, 2,
1077 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
, cfg
, cbg
, 0);
1080 (void)gui_screenchar(LineOffset
[gui
.row
] + gui
.col
,
1081 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
, cfg
, cbg
, 0);
1085 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT)
1086 int col_off
= FALSE
;
1089 * First draw the partial cursor, then overwrite with the text
1090 * character, using a transparent background.
1092 if (shape_table
[idx
].shape
== SHAPE_VER
)
1094 cur_height
= gui
.char_height
;
1095 cur_width
= (gui
.char_width
* shape_table
[idx
].percentage
1100 cur_height
= (gui
.char_height
* shape_table
[idx
].percentage
1102 cur_width
= gui
.char_width
;
1105 if (has_mbyte
&& (*mb_off2cells
)(LineOffset
[gui
.row
] + gui
.col
,
1106 LineOffset
[gui
.row
] + screen_Columns
) > 1)
1108 /* Double wide character. */
1109 if (shape_table
[idx
].shape
!= SHAPE_VER
)
1110 cur_width
+= gui
.char_width
;
1111 # ifdef FEAT_RIGHTLEFT
1112 if (CURSOR_BAR_RIGHT
)
1114 /* gui.col points to the left halve of the character but
1115 * the vertical line needs to be on the right halve.
1116 * A double-wide horizontal line is also drawn from the
1117 * right halve in gui_mch_draw_part_cursor(). */
1124 gui_mch_draw_part_cursor(cur_width
, cur_height
, cbg
);
1125 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT)
1130 #ifndef FEAT_GUI_MSWIN /* doesn't seem to work for MSWindows */
1131 gui
.highlight_mask
= ScreenAttrs
[LineOffset
[gui
.row
] + gui
.col
];
1132 (void)gui_screenchar(LineOffset
[gui
.row
] + gui
.col
,
1133 GUI_MON_TRS_CURSOR
| GUI_MON_NOCLEAR
,
1134 (guicolor_T
)0, (guicolor_T
)0, 0);
1137 gui
.highlight_mask
= old_hl_mask
;
1141 #if defined(FEAT_MENU) || defined(PROTO)
1145 # if !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \
1146 || defined(FEAT_GUI_MACVIM))
1147 if (gui
.menu_is_active
&& gui
.in_use
)
1148 gui_mch_set_menu_pos(0, 0, gui
.menu_width
, gui
.menu_height
);
1154 * Position the various GUI components (text area, menu). The vertical
1155 * scrollbars are NOT handled here. See gui_update_scrollbars().
1158 gui_position_components(total_width
)
1159 int total_width UNUSED
;
1163 int text_area_width
;
1164 int text_area_height
;
1166 /* avoid that moving components around generates events */
1170 if (gui
.which_scrollbars
[SBAR_LEFT
])
1171 text_area_x
+= gui
.scrollbar_width
;
1174 #if defined(FEAT_MENU) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON) \
1175 || defined(FEAT_GUI_MACVIM))
1176 gui
.menu_width
= total_width
;
1177 if (gui
.menu_is_active
)
1178 text_area_y
+= gui
.menu_height
;
1180 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_MSWIN)
1181 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
1182 text_area_y
= TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
;
1185 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
1186 || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_MAC))
1187 if (gui_has_tabline())
1188 text_area_y
+= gui
.tabline_height
;
1191 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA))
1192 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
1194 # ifdef FEAT_GUI_ATHENA
1195 gui_mch_set_toolbar_pos(0, text_area_y
,
1196 gui
.menu_width
, gui
.toolbar_height
);
1198 text_area_y
+= gui
.toolbar_height
;
1202 text_area_width
= gui
.num_cols
* gui
.char_width
+ gui
.border_offset
* 2;
1203 text_area_height
= gui
.num_rows
* gui
.char_height
+ gui
.border_offset
* 2;
1205 gui_mch_set_text_area_pos(text_area_x
,
1209 #if defined(FEAT_XIM) && !(defined(HAVE_GTK2) || defined(FEAT_GUI_MACVIM))
1210 + xim_get_status_area_height()
1214 gui_position_menu();
1216 if (gui
.which_scrollbars
[SBAR_BOTTOM
])
1217 gui_mch_set_scrollbar_pos(&gui
.bottom_sbar
,
1219 text_area_y
+ text_area_height
,
1221 gui
.scrollbar_height
);
1222 gui
.left_sbar_x
= 0;
1223 gui
.right_sbar_x
= text_area_x
+ text_area_width
;
1229 * Get the width of the widgets and decorations to the side of the text area.
1232 gui_get_base_width()
1236 base_width
= 2 * gui
.border_offset
;
1237 if (gui
.which_scrollbars
[SBAR_LEFT
])
1238 base_width
+= gui
.scrollbar_width
;
1239 if (gui
.which_scrollbars
[SBAR_RIGHT
])
1240 base_width
+= gui
.scrollbar_width
;
1245 * Get the height of the widgets and decorations above and below the text area.
1248 gui_get_base_height()
1252 base_height
= 2 * gui
.border_offset
;
1253 if (gui
.which_scrollbars
[SBAR_BOTTOM
])
1254 base_height
+= gui
.scrollbar_height
;
1256 /* We can't take the sizes properly into account until anything is
1257 * realized. Therefore we recalculate all the values here just before
1258 * setting the size. (--mdcki) */
1259 #elif !defined(FEAT_GUI_MACVIM)
1261 if (gui
.menu_is_active
)
1262 base_height
+= gui
.menu_height
;
1264 # ifdef FEAT_TOOLBAR
1265 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
1266 # if defined(FEAT_GUI_MSWIN) && defined(FEAT_TOOLBAR)
1267 base_height
+= (TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
);
1269 base_height
+= gui
.toolbar_height
;
1272 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
1273 || defined(FEAT_GUI_MOTIF))
1274 if (gui_has_tabline())
1275 base_height
+= gui
.tabline_height
;
1278 if (vim_strchr(p_go
, GO_FOOTER
) != NULL
)
1279 base_height
+= gui
.footer_height
;
1281 # if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)
1282 base_height
+= gui_mch_text_area_extra_height();
1289 * Should be called after the GUI shell has been resized. Its arguments are
1290 * the new width and height of the shell in pixels.
1293 gui_resize_shell(pixel_width
, pixel_height
)
1297 static int busy
= FALSE
;
1299 if (!gui
.shell_created
) /* ignore when still initializing */
1303 * Can't resize the screen while it is being redrawn. Remember the new
1304 * size and handle it later.
1306 if (updating_screen
|| busy
)
1308 new_pixel_width
= pixel_width
;
1309 new_pixel_height
= pixel_height
;
1316 /* Flush pending output before redrawing */
1319 gui
.num_cols
= (pixel_width
- gui_get_base_width()) / gui
.char_width
;
1320 gui
.num_rows
= (pixel_height
- gui_get_base_height()) / gui
.char_height
;
1322 gui_position_components(pixel_width
);
1324 gui_reset_scroll_region();
1326 * At the "more" and ":confirm" prompt there is no redraw, put the cursor
1327 * at the last line here (why does it have to be one row too low?).
1329 if (State
== ASKMORE
|| State
== CONFIRM
)
1330 gui
.row
= gui
.num_rows
;
1332 /* Only comparing Rows and Columns may be sufficient, but let's stay on
1334 if (gui
.num_rows
!= screen_Rows
|| gui
.num_cols
!= screen_Columns
1335 || gui
.num_rows
!= Rows
|| gui
.num_cols
!= Columns
)
1338 gui_update_scrollbars(TRUE
);
1339 gui_update_cursor(FALSE
, TRUE
);
1340 #if defined(FEAT_XIM) && !(defined(HAVE_GTK2) || defined(FEAT_GUI_MACVIM))
1341 xim_set_status_area();
1347 * We could have been called again while redrawing the screen.
1348 * Need to do it all again with the latest size then.
1350 if (new_pixel_height
)
1352 pixel_width
= new_pixel_width
;
1353 pixel_height
= new_pixel_height
;
1354 new_pixel_width
= 0;
1355 new_pixel_height
= 0;
1361 * Check if gui_resize_shell() must be called.
1364 gui_may_resize_shell()
1368 if (new_pixel_height
)
1370 /* careful: gui_resize_shell() may postpone the resize again if we
1371 * were called indirectly by it */
1372 w
= new_pixel_width
;
1373 h
= new_pixel_height
;
1374 new_pixel_width
= 0;
1375 new_pixel_height
= 0;
1376 gui_resize_shell(w
, h
);
1383 Rows
= gui
.num_rows
;
1384 Columns
= gui
.num_cols
;
1389 * Set the size of the Vim shell according to Rows and Columns.
1390 * If "fit_to_display" is TRUE then the size may be reduced to fit the window
1394 gui_set_shellsize(mustset
, fit_to_display
, direction
)
1395 int mustset UNUSED
; /* set by the user */
1397 int direction
; /* RESIZE_HOR, RESIZE_VER */
1408 if (!gui
.shell_created
)
1412 /* If not setting to a user specified size and maximized, calculate the
1413 * number of characters that fit in the maximized window. */
1414 if (!mustset
&& gui_mch_maximized())
1421 base_width
= gui_get_base_width();
1422 base_height
= gui_get_base_height();
1423 #ifdef USE_SUN_WORKSHOP
1424 if (!mustset
&& usingSunWorkShop
1425 && workshop_get_width_height(&width
, &height
))
1427 Columns
= (width
- base_width
+ gui
.char_width
- 1) / gui
.char_width
;
1428 Rows
= (height
- base_height
+ gui
.char_height
- 1) / gui
.char_height
;
1433 width
= Columns
* gui
.char_width
+ base_width
;
1434 height
= Rows
* gui
.char_height
+ base_height
;
1439 gui_mch_get_screen_dimensions(&screen_w
, &screen_h
);
1440 if ((direction
& RESIZE_HOR
) && width
> screen_w
)
1442 Columns
= (screen_w
- base_width
) / gui
.char_width
;
1443 if (Columns
< MIN_COLUMNS
)
1444 Columns
= MIN_COLUMNS
;
1445 width
= Columns
* gui
.char_width
+ base_width
;
1447 if ((direction
& RESIZE_VERT
) && height
> screen_h
)
1449 Rows
= (screen_h
- base_height
) / gui
.char_height
;
1451 height
= Rows
* gui
.char_height
+ base_height
;
1454 gui
.num_cols
= Columns
;
1455 gui
.num_rows
= Rows
;
1457 min_width
= base_width
+ MIN_COLUMNS
* gui
.char_width
;
1458 min_height
= base_height
+ MIN_LINES
* gui
.char_height
;
1459 # ifdef FEAT_WINDOWS
1460 min_height
+= tabline_height() * gui
.char_height
;
1463 gui_mch_set_shellsize(width
, height
, min_width
, min_height
,
1464 base_width
, base_height
, direction
);
1469 /* Some window managers put the Vim window left of/above the screen. */
1471 if (gui_mch_get_winpos(&x
, &y
) == OK
&& (x
< 0 || y
< 0))
1472 gui_mch_set_winpos(x
< 0 ? 0 : x
, y
< 0 ? 0 : y
);
1475 gui_position_components(width
);
1476 gui_update_scrollbars(TRUE
);
1477 gui_reset_scroll_region();
1481 * Called when Rows and/or Columns has changed.
1486 gui_reset_scroll_region();
1490 * Make scroll region cover whole screen.
1493 gui_reset_scroll_region()
1495 gui
.scroll_region_top
= 0;
1496 gui
.scroll_region_bot
= gui
.num_rows
- 1;
1497 gui
.scroll_region_left
= 0;
1498 gui
.scroll_region_right
= gui
.num_cols
- 1;
1502 gui_start_highlight(mask
)
1505 if (mask
> HL_ALL
) /* highlight code */
1506 gui
.highlight_mask
= mask
;
1508 gui
.highlight_mask
|= mask
;
1512 gui_stop_highlight(mask
)
1515 if (mask
> HL_ALL
) /* highlight code */
1516 gui
.highlight_mask
= HL_NORMAL
;
1518 gui
.highlight_mask
&= ~mask
;
1522 * Clear a rectangular region of the screen from text pos (row1, col1) to
1523 * (row2, col2) inclusive.
1526 gui_clear_block(row1
, col1
, row2
, col2
)
1532 /* Clear the selection if we are about to write over it */
1533 clip_may_clear_selection(row1
, row2
);
1535 gui_mch_clear_block(row1
, col1
, row2
, col2
);
1537 /* Invalidate cursor if it was in this block */
1538 if ( gui
.cursor_row
>= row1
&& gui
.cursor_row
<= row2
1539 && gui
.cursor_col
>= col1
&& gui
.cursor_col
<= col2
)
1540 gui
.cursor_is_valid
= FALSE
;
1544 * Write code to update the cursor later. This avoids the need to flush the
1545 * output buffer before calling gui_update_cursor().
1548 gui_update_cursor_later()
1550 OUT_STR(IF_EB("\033|s", ESC_STR
"|s"));
1559 int arg1
= 0, arg2
= 0;
1560 /* this doesn't make sense, disabled until someone can explain why it
1561 * would be needed */
1562 #if 0 && (defined(RISCOS) || defined(WIN16))
1563 int force_cursor
= TRUE
; /* JK230798, stop Vim being smart or
1564 our redraw speed will suffer */
1566 int force_cursor
= FALSE
; /* force cursor update */
1568 int force_scrollbar
= FALSE
;
1569 static win_T
*old_curwin
= NULL
;
1571 /* #define DEBUG_GUI_WRITE */
1572 #ifdef DEBUG_GUI_WRITE
1577 printf("gui_write(%d):\n ", len
);
1578 for (i
= 0; i
< len
; i
++)
1587 str
= transchar_byte(s
[i
]);
1588 if (str
[0] && str
[1])
1589 printf("<%s>", (char *)str
);
1591 printf("%s", (char *)str
);
1598 if (s
[0] == ESC
&& s
[1] == '|')
1601 if (VIM_ISDIGIT(*p
))
1603 arg1
= getdigits(&p
);
1609 arg2
= getdigits(&p
);
1616 case 'C': /* Clear screen */
1617 clip_scroll_selection(9999);
1618 gui_mch_clear_all();
1619 gui
.cursor_is_valid
= FALSE
;
1620 force_scrollbar
= TRUE
;
1622 case 'M': /* Move cursor */
1623 gui_set_cursor(arg1
, arg2
);
1625 case 's': /* force cursor (shape) update */
1626 force_cursor
= TRUE
;
1628 case 'R': /* Set scroll region */
1631 gui
.scroll_region_top
= arg1
;
1632 gui
.scroll_region_bot
= arg2
;
1636 gui
.scroll_region_top
= arg2
;
1637 gui
.scroll_region_bot
= arg1
;
1640 #ifdef FEAT_VERTSPLIT
1641 case 'V': /* Set vertical scroll region */
1644 gui
.scroll_region_left
= arg1
;
1645 gui
.scroll_region_right
= arg2
;
1649 gui
.scroll_region_left
= arg2
;
1650 gui
.scroll_region_right
= arg1
;
1654 case 'd': /* Delete line */
1655 gui_delete_lines(gui
.row
, 1);
1657 case 'D': /* Delete lines */
1658 gui_delete_lines(gui
.row
, arg1
);
1660 case 'i': /* Insert line */
1661 gui_insert_lines(gui
.row
, 1);
1663 case 'I': /* Insert lines */
1664 gui_insert_lines(gui
.row
, arg1
);
1666 case '$': /* Clear to end-of-line */
1667 gui_clear_block(gui
.row
, gui
.col
, gui
.row
,
1670 case 'h': /* Turn on highlighting */
1671 gui_start_highlight(arg1
);
1673 case 'H': /* Turn off highlighting */
1674 gui_stop_highlight(arg1
);
1676 case 'f': /* flash the window (visual bell) */
1677 gui_mch_flash(arg1
== 0 ? 20 : arg1
);
1680 p
= s
+ 1; /* Skip the ESC */
1683 len
-= (int)(++p
- s
);
1688 CtrlChar(s
[0]) != 0 /* Ctrl character */
1690 s
[0] < 0x20 /* Ctrl character */
1692 #ifdef FEAT_SIGN_ICONS
1693 && s
[0] != SIGN_BYTE
1694 # ifdef FEAT_NETBEANS_INTG
1695 && s
[0] != MULTISIGN_BYTE
1700 if (s
[0] == '\n') /* NL */
1703 if (gui
.row
< gui
.scroll_region_bot
)
1706 gui_delete_lines(gui
.scroll_region_top
, 1);
1708 else if (s
[0] == '\r') /* CR */
1712 else if (s
[0] == '\b') /* Backspace */
1717 else if (s
[0] == Ctrl_L
) /* cursor-right */
1721 else if (s
[0] == Ctrl_G
) /* Beep */
1725 /* Other Ctrl character: shouldn't happen! */
1727 --len
; /* Skip this char */
1739 #ifdef FEAT_SIGN_ICONS
1741 # ifdef FEAT_NETBEANS_INTG
1742 || *p
== MULTISIGN_BYTE
1750 gui_outstr(s
, (int)(p
- s
));
1755 /* Postponed update of the cursor (won't work if "can_update_cursor" isn't
1758 gui_update_cursor(TRUE
, TRUE
);
1760 /* When switching to another window the dragging must have stopped.
1761 * Required for GTK, dragged_sb isn't reset. */
1762 if (old_curwin
!= curwin
)
1763 gui
.dragged_sb
= SBAR_NONE
;
1765 /* Update the scrollbars after clearing the screen or when switched
1766 * to another window.
1767 * Update the horizontal scrollbar always, it's difficult to check all
1768 * situations where it might change. */
1769 if (force_scrollbar
|| old_curwin
!= curwin
)
1770 gui_update_scrollbars(force_scrollbar
);
1772 gui_update_horiz_scrollbar(FALSE
);
1773 old_curwin
= curwin
;
1776 * We need to make sure this is cleared since Athena doesn't tell us when
1777 * he is done dragging. Do the same for GTK.
1779 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_GTK)
1780 gui
.dragged_sb
= SBAR_NONE
;
1783 gui_mch_flush(); /* In case vim decides to take a nap */
1787 * When ScreenLines[] is invalid, updating the cursor should not be done, it
1788 * produces wrong results. Call gui_dont_update_cursor() before that code and
1789 * gui_can_update_cursor() afterwards.
1792 gui_dont_update_cursor()
1796 /* Undraw the cursor now, we probably can't do it after the change. */
1797 gui_undraw_cursor();
1798 can_update_cursor
= FALSE
;
1803 gui_can_update_cursor()
1805 can_update_cursor
= TRUE
;
1806 /* No need to update the cursor right now, there is always more output
1807 * after scrolling. */
1824 len
= (int)STRLEN(s
);
1831 /* Find out how many chars fit in the current line. */
1833 for (this_len
= 0; this_len
< len
; )
1835 cells
+= (*mb_ptr2cells
)(s
+ this_len
);
1836 if (gui
.col
+ cells
> Columns
)
1838 this_len
+= (*mb_ptr2len
)(s
+ this_len
);
1841 this_len
= len
; /* don't include following composing char */
1845 if (gui
.col
+ len
> Columns
)
1846 this_len
= Columns
- gui
.col
;
1850 (void)gui_outstr_nowrap(s
, this_len
,
1851 0, (guicolor_T
)0, (guicolor_T
)0, 0);
1855 /* fill up for a double-width char that doesn't fit. */
1856 if (len
> 0 && gui
.col
< Columns
)
1857 (void)gui_outstr_nowrap((char_u
*)" ", 1,
1858 0, (guicolor_T
)0, (guicolor_T
)0, 0);
1860 /* The cursor may wrap to the next line. */
1861 if (gui
.col
>= Columns
)
1870 * Output one character (may be one or two display cells).
1871 * Caller must check for valid "off".
1872 * Returns FAIL or OK, just like gui_outstr_nowrap().
1875 gui_screenchar(off
, flags
, fg
, bg
, back
)
1876 int off
; /* Offset from start of screen */
1878 guicolor_T fg
, bg
; /* colors for cursor */
1879 int back
; /* backup this many chars when using bold trick */
1882 char_u buf
[MB_MAXBYTES
+ 1];
1884 /* Don't draw right halve of a double-width UTF-8 char. "cannot happen" */
1885 if (enc_utf8
&& ScreenLines
[off
] == 0)
1888 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
1889 /* Draw UTF-8 multi-byte character. */
1890 return gui_outstr_nowrap(buf
, utfc_char2bytes(off
, buf
),
1891 flags
, fg
, bg
, back
);
1893 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
1895 buf
[0] = ScreenLines
[off
];
1896 buf
[1] = ScreenLines2
[off
];
1897 return gui_outstr_nowrap(buf
, 2, flags
, fg
, bg
, back
);
1900 /* Draw non-multi-byte character or DBCS character. */
1901 return gui_outstr_nowrap(ScreenLines
+ off
,
1902 enc_dbcs
? (*mb_ptr2len
)(ScreenLines
+ off
) : 1,
1903 flags
, fg
, bg
, back
);
1905 return gui_outstr_nowrap(ScreenLines
+ off
, 1, flags
, fg
, bg
, back
);
1911 * Output the string at the given screen position. This is used in place
1912 * of gui_screenchar() where possible because Pango needs as much context
1913 * as possible to work nicely. It's a lot faster as well.
1916 gui_screenstr(off
, len
, flags
, fg
, bg
, back
)
1917 int off
; /* Offset from start of screen */
1918 int len
; /* string length in screen cells */
1920 guicolor_T fg
, bg
; /* colors for cursor */
1921 int back
; /* backup this many chars when using bold trick */
1928 if (len
<= 0) /* "cannot happen"? */
1933 buf
= alloc((unsigned)(len
* MB_MAXBYTES
+ 1));
1935 return OK
; /* not much we could do here... */
1937 for (i
= off
; i
< off
+ len
; ++i
)
1939 if (ScreenLines
[i
] == 0)
1940 continue; /* skip second half of double-width char */
1942 if (ScreenLinesUC
[i
] == 0)
1943 buf
[outlen
++] = ScreenLines
[i
];
1945 outlen
+= utfc_char2bytes(i
, buf
+ outlen
);
1948 buf
[outlen
] = NUL
; /* only to aid debugging */
1949 retval
= gui_outstr_nowrap(buf
, outlen
, flags
, fg
, bg
, back
);
1954 else if (enc_dbcs
== DBCS_JPNU
)
1956 buf
= alloc((unsigned)(len
* 2 + 1));
1958 return OK
; /* not much we could do here... */
1960 for (i
= off
; i
< off
+ len
; ++i
)
1962 buf
[outlen
++] = ScreenLines
[i
];
1964 /* handle double-byte single-width char */
1965 if (ScreenLines
[i
] == 0x8e)
1966 buf
[outlen
++] = ScreenLines2
[i
];
1967 else if (MB_BYTE2LEN(ScreenLines
[i
]) == 2)
1968 buf
[outlen
++] = ScreenLines
[++i
];
1971 buf
[outlen
] = NUL
; /* only to aid debugging */
1972 retval
= gui_outstr_nowrap(buf
, outlen
, flags
, fg
, bg
, back
);
1979 return gui_outstr_nowrap(&ScreenLines
[off
], len
,
1980 flags
, fg
, bg
, back
);
1983 #endif /* HAVE_GTK2 */
1986 * Output the given string at the current cursor position. If the string is
1987 * too long to fit on the line, then it is truncated.
1989 * GUI_MON_IS_CURSOR should only be used when this function is being called to
1990 * actually draw (an inverted) cursor.
1991 * GUI_MON_TRS_CURSOR is used to draw the cursor text with a transparent
1993 * GUI_MON_NOCLEAR is used to avoid clearing the selection when drawing over
1995 * Returns OK, unless "back" is non-zero and using the bold trick, then return
1996 * FAIL (the caller should start drawing "back" chars back).
1999 gui_outstr_nowrap(s
, len
, flags
, fg
, bg
, back
)
2003 guicolor_T fg
, bg
; /* colors for cursor */
2004 int back
; /* backup this many chars when using bold trick */
2006 long_u highlight_mask
;
2007 long_u hl_mask_todo
;
2008 guicolor_T fg_color
;
2009 guicolor_T bg_color
;
2010 guicolor_T sp_color
;
2011 #if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2)
2012 GuiFont font
= NOFONT
;
2013 # ifdef FEAT_XFONTSET
2014 GuiFontset fontset
= NOFONTSET
;
2017 attrentry_T
*aep
= NULL
;
2020 #ifdef FEAT_SIGN_ICONS
2021 int draw_sign
= FALSE
;
2022 # ifdef FEAT_NETBEANS_INTG
2023 int multi_sign
= FALSE
;
2028 len
= (int)STRLEN(s
);
2032 #ifdef FEAT_SIGN_ICONS
2034 # ifdef FEAT_NETBEANS_INTG
2035 || *s
== MULTISIGN_BYTE
2039 # ifdef FEAT_NETBEANS_INTG
2040 if (*s
== MULTISIGN_BYTE
)
2043 /* draw spaces instead */
2045 if (len
== 1 && col
> 0)
2053 if (gui
.highlight_mask
> HL_ALL
)
2055 aep
= syn_gui_attr2entry(gui
.highlight_mask
);
2056 if (aep
== NULL
) /* highlighting not set */
2059 highlight_mask
= aep
->ae_attr
;
2062 highlight_mask
= gui
.highlight_mask
;
2063 hl_mask_todo
= highlight_mask
;
2065 #if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2)
2067 if (aep
!= NULL
&& aep
->ae_u
.gui
.font
!= NOFONT
)
2068 font
= aep
->ae_u
.gui
.font
;
2069 # ifdef FEAT_XFONTSET
2070 else if (aep
!= NULL
&& aep
->ae_u
.gui
.fontset
!= NOFONTSET
)
2071 fontset
= aep
->ae_u
.gui
.fontset
;
2075 # ifdef FEAT_XFONTSET
2076 if (gui
.fontset
!= NOFONTSET
)
2077 fontset
= gui
.fontset
;
2080 if (hl_mask_todo
& (HL_BOLD
| HL_STANDOUT
))
2082 if ((hl_mask_todo
& HL_ITALIC
) && gui
.boldital_font
!= NOFONT
)
2084 font
= gui
.boldital_font
;
2085 hl_mask_todo
&= ~(HL_BOLD
| HL_STANDOUT
| HL_ITALIC
);
2087 else if (gui
.bold_font
!= NOFONT
)
2089 font
= gui
.bold_font
;
2090 hl_mask_todo
&= ~(HL_BOLD
| HL_STANDOUT
);
2093 font
= gui
.norm_font
;
2095 else if ((hl_mask_todo
& HL_ITALIC
) && gui
.ital_font
!= NOFONT
)
2097 font
= gui
.ital_font
;
2098 hl_mask_todo
&= ~HL_ITALIC
;
2101 font
= gui
.norm_font
;
2103 # ifdef FEAT_XFONTSET
2104 if (fontset
!= NOFONTSET
)
2105 gui_mch_set_fontset(fontset
);
2108 gui_mch_set_font(font
);
2114 bg_color
= gui
.back_pixel
;
2115 if ((flags
& GUI_MON_IS_CURSOR
) && gui
.in_focus
)
2117 draw_flags
|= DRAW_CURSOR
;
2122 else if (aep
!= NULL
)
2124 fg_color
= aep
->ae_u
.gui
.fg_color
;
2125 if (fg_color
== INVALCOLOR
)
2126 fg_color
= gui
.norm_pixel
;
2127 bg_color
= aep
->ae_u
.gui
.bg_color
;
2128 if (bg_color
== INVALCOLOR
)
2129 bg_color
= gui
.back_pixel
;
2130 sp_color
= aep
->ae_u
.gui
.sp_color
;
2131 if (sp_color
== INVALCOLOR
)
2132 sp_color
= fg_color
;
2136 fg_color
= gui
.norm_pixel
;
2137 sp_color
= fg_color
;
2140 if (highlight_mask
& (HL_INVERSE
| HL_STANDOUT
))
2142 #if defined(AMIGA) || defined(RISCOS)
2143 gui_mch_set_colors(bg_color
, fg_color
);
2145 gui_mch_set_fg_color(bg_color
);
2146 gui_mch_set_bg_color(fg_color
);
2151 #if defined(AMIGA) || defined(RISCOS)
2152 gui_mch_set_colors(fg_color
, bg_color
);
2154 gui_mch_set_fg_color(fg_color
);
2155 gui_mch_set_bg_color(bg_color
);
2158 gui_mch_set_sp_color(sp_color
);
2160 /* Clear the selection if we are about to write over it */
2161 if (!(flags
& GUI_MON_NOCLEAR
))
2162 clip_may_clear_selection(gui
.row
, gui
.row
);
2165 #ifndef MSWIN16_FASTTEXT
2166 /* If there's no bold font, then fake it */
2167 if (hl_mask_todo
& (HL_BOLD
| HL_STANDOUT
))
2168 draw_flags
|= DRAW_BOLD
;
2172 * When drawing bold or italic characters the spill-over from the left
2173 * neighbor may be destroyed. Let the caller backup to start redrawing
2174 * just after a blank.
2176 if (back
!= 0 && ((draw_flags
& DRAW_BOLD
) || (highlight_mask
& HL_ITALIC
)))
2179 #if defined(RISCOS) || defined(HAVE_GTK2) || defined(FEAT_GUI_MACVIM)
2180 /* If there's no italic font, then fake it.
2181 * For GTK2, we don't need a different font for italic style. */
2182 if (hl_mask_todo
& HL_ITALIC
)
2183 draw_flags
|= DRAW_ITALIC
;
2185 /* Do we underline the text? */
2186 if (hl_mask_todo
& HL_UNDERLINE
)
2187 draw_flags
|= DRAW_UNDERL
;
2189 /* Do we underline the text? */
2190 if ((hl_mask_todo
& HL_UNDERLINE
)
2191 # ifndef MSWIN16_FASTTEXT
2192 || (hl_mask_todo
& HL_ITALIC
)
2195 draw_flags
|= DRAW_UNDERL
;
2197 /* Do we undercurl the text? */
2198 if (hl_mask_todo
& HL_UNDERCURL
)
2199 draw_flags
|= DRAW_UNDERC
;
2201 /* Do we draw transparently? */
2202 if (flags
& GUI_MON_TRS_CURSOR
)
2203 draw_flags
|= DRAW_TRANSP
;
2209 /* The value returned is the length in display cells */
2210 len
= gui_gtk2_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2211 #elif defined(FEAT_GUI_MACVIM) && defined(FEAT_MBYTE)
2212 /* The value returned is the length in display cells */
2213 len
= gui_macvim_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2218 int start
; /* index of bytes to be drawn */
2219 int cells
; /* cellwidth of bytes to be drawn */
2220 int thislen
; /* length of bytes to be drawin */
2221 int cn
; /* cellwidth of current char */
2222 int i
; /* index of current char */
2223 int c
; /* current char value */
2224 int cl
; /* byte length of current char */
2225 int comping
; /* current char is composing */
2226 int scol
= col
; /* screen column */
2227 int dowide
; /* use 'guifontwide' */
2229 /* Break the string at a composing character, it has to be drawn on
2230 * top of the previous character. */
2233 for (i
= 0; i
< len
; i
+= cl
)
2235 c
= utf_ptr2char(s
+ i
);
2236 cn
= utf_char2cells(c
);
2238 # ifdef FEAT_XFONTSET
2239 && fontset
== NOFONTSET
2241 && gui
.wide_font
!= NOFONT
)
2245 comping
= utf_iscomposing(c
);
2246 if (!comping
) /* count cells from non-composing chars */
2248 cl
= utf_ptr2len(s
+ i
);
2249 if (cl
== 0) /* hit end of string */
2250 len
= i
+ cl
; /* len must be wrong "cannot happen" */
2252 /* print the string so far if it's the last character or there is
2253 * a composing character. */
2254 if (i
+ cl
>= len
|| (comping
&& i
> start
) || dowide
2255 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
2257 # ifdef FEAT_XFONTSET
2258 /* No fontset: At least draw char after wide char at
2259 * right position. */
2260 && fontset
== NOFONTSET
2266 if (comping
|| dowide
)
2267 thislen
= i
- start
;
2269 thislen
= i
- start
+ cl
;
2272 gui_mch_draw_string(gui
.row
, scol
, s
+ start
, thislen
,
2280 gui_mch_set_font(gui
.wide_font
);
2281 gui_mch_draw_string(gui
.row
, scol
- cn
,
2282 s
+ start
, cl
, draw_flags
);
2283 gui_mch_set_font(font
);
2287 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
2288 /* No fontset: draw a space to fill the gap after a wide char
2290 if (cn
> 1 && (draw_flags
& DRAW_TRANSP
) == 0
2291 # ifdef FEAT_XFONTSET
2292 && fontset
== NOFONTSET
2295 gui_mch_draw_string(gui
.row
, scol
- 1, (char_u
*)" ",
2299 /* Draw a composing char on top of the previous char. */
2302 # if (defined(__APPLE_CC__) || defined(__MRC__)) && TARGET_API_MAC_CARBON
2303 /* Carbon ATSUI autodraws composing char over previous char */
2304 gui_mch_draw_string(gui
.row
, scol
, s
+ i
, cl
,
2305 draw_flags
| DRAW_TRANSP
);
2307 gui_mch_draw_string(gui
.row
, scol
- cn
, s
+ i
, cl
,
2308 draw_flags
| DRAW_TRANSP
);
2313 /* The stuff below assumes "len" is the length in screen columns. */
2319 gui_mch_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2321 if (enc_dbcs
== DBCS_JPNU
)
2326 /* Get the length in display cells, this can be different from the
2327 * number of bytes for "euc-jp". */
2328 for (i
= 0; i
< len
; i
+= (*mb_ptr2len
)(s
+ i
))
2329 clen
+= (*mb_ptr2cells
)(s
+ i
);
2334 #endif /* !HAVE_GTK2 */
2336 if (!(flags
& (GUI_MON_IS_CURSOR
| GUI_MON_TRS_CURSOR
)))
2337 gui
.col
= col
+ len
;
2339 /* May need to invert it when it's part of the selection. */
2340 if (flags
& GUI_MON_NOCLEAR
)
2341 clip_may_redraw_selection(gui
.row
, col
, len
);
2343 if (!(flags
& (GUI_MON_IS_CURSOR
| GUI_MON_TRS_CURSOR
)))
2345 /* Invalidate the old physical cursor position if we wrote over it */
2346 if (gui
.cursor_row
== gui
.row
2347 && gui
.cursor_col
>= col
2348 && gui
.cursor_col
< col
+ len
)
2349 gui
.cursor_is_valid
= FALSE
;
2352 #ifdef FEAT_SIGN_ICONS
2354 /* Draw the sign on top of the spaces. */
2355 gui_mch_drawsign(gui
.row
, col
, gui
.highlight_mask
);
2356 # ifdef FEAT_NETBEANS_INTG
2358 netbeans_draw_multisign_indicator(gui
.row
);
2366 * Un-draw the cursor. Actually this just redraws the character at the given
2367 * position. The character just before it too, for when it was in bold.
2372 if (gui
.cursor_is_valid
)
2374 #ifdef FEAT_HANGULIN
2375 if (composing_hangul
2376 && gui
.col
== gui
.cursor_col
&& gui
.row
== gui
.cursor_row
)
2377 (void)gui_outstr_nowrap(composing_hangul_buffer
, 2,
2378 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
,
2379 gui
.norm_pixel
, gui
.back_pixel
, 0);
2383 if (gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
,
2384 gui
.cursor_row
, gui
.cursor_col
, GUI_MON_NOCLEAR
)
2385 && gui
.cursor_col
> 0)
2386 (void)gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
- 1,
2387 gui
.cursor_row
, gui
.cursor_col
- 1, GUI_MON_NOCLEAR
);
2388 #ifdef FEAT_HANGULIN
2389 if (composing_hangul
)
2390 (void)gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
+ 1,
2391 gui
.cursor_row
, gui
.cursor_col
+ 1, GUI_MON_NOCLEAR
);
2394 /* Cursor_is_valid is reset when the cursor is undrawn, also reset it
2395 * here in case it wasn't needed to undraw it. */
2396 gui
.cursor_is_valid
= FALSE
;
2401 gui_redraw(x
, y
, w
, h
)
2407 int row1
, col1
, row2
, col2
;
2411 row2
= Y_2_ROW(y
+ h
- 1);
2412 col2
= X_2_COL(x
+ w
- 1);
2414 (void)gui_redraw_block(row1
, col1
, row2
, col2
, GUI_MON_NOCLEAR
);
2417 * We may need to redraw the cursor, but don't take it upon us to change
2418 * its location after a scroll.
2419 * (maybe be more strict even and test col too?)
2420 * These things may be outside the update/clipping region and reality may
2421 * not reflect Vims internal ideas if these operations are clipped away.
2423 if (gui
.row
== gui
.cursor_row
)
2424 gui_update_cursor(TRUE
, TRUE
);
2428 * Draw a rectangular block of characters, from row1 to row2 (inclusive) and
2429 * from col1 to col2 (inclusive).
2430 * Return TRUE when the character before the first drawn character has
2431 * different attributes (may have to be redrawn too).
2434 gui_redraw_block(row1
, col1
, row2
, col2
, flags
)
2439 int flags
; /* flags for gui_outstr_nowrap() */
2441 int old_row
, old_col
;
2449 int orig_col1
, orig_col2
;
2452 /* Don't try to update when ScreenLines is not valid */
2453 if (!screen_cleared
|| ScreenLines
== NULL
)
2456 /* Don't try to draw outside the shell! */
2457 /* Check everything, strange values may be caused by a big border width */
2458 col1
= check_col(col1
);
2459 col2
= check_col(col2
);
2460 row1
= check_row(row1
);
2461 row2
= check_row(row2
);
2463 /* Remember where our cursor was */
2466 old_hl_mask
= gui
.highlight_mask
;
2472 for (gui
.row
= row1
; gui
.row
<= row2
; gui
.row
++)
2475 /* When only half of a double-wide character is in the block, include
2476 * the other half. */
2479 off
= LineOffset
[gui
.row
];
2483 col1
-= dbcs_screen_head_off(ScreenLines
+ off
,
2484 ScreenLines
+ off
+ col1
);
2485 col2
+= dbcs_screen_tail_off(ScreenLines
+ off
,
2486 ScreenLines
+ off
+ col2
);
2490 if (ScreenLines
[off
+ col1
] == 0)
2493 if (col2
+ 1 < Columns
&& ScreenLines
[off
+ col2
+ 1] == 0)
2499 off
= LineOffset
[gui
.row
] + gui
.col
;
2500 len
= col2
- col1
+ 1;
2502 /* Find how many chars back this highlighting starts, or where a space
2503 * is. Needed for when the bold trick is used */
2504 for (back
= 0; back
< col1
; ++back
)
2505 if (ScreenAttrs
[off
- 1 - back
] != ScreenAttrs
[off
]
2506 || ScreenLines
[off
- 1 - back
] == ' ')
2508 retval
= (col1
> 0 && ScreenAttrs
[off
- 1] != 0 && back
== 0
2509 && ScreenLines
[off
- 1] != ' ');
2511 /* Break it up in strings of characters with the same attributes. */
2512 /* Print UTF-8 characters individually. */
2515 first_attr
= ScreenAttrs
[off
];
2516 gui
.highlight_mask
= first_attr
;
2517 #if defined(FEAT_MBYTE) && !defined(HAVE_GTK2)
2518 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
2520 /* output multi-byte character separately */
2521 nback
= gui_screenchar(off
, flags
,
2522 (guicolor_T
)0, (guicolor_T
)0, back
);
2523 if (gui
.col
< Columns
&& ScreenLines
[off
+ 1] == 0)
2528 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
2530 /* output double-byte, single-width character separately */
2531 nback
= gui_screenchar(off
, flags
,
2532 (guicolor_T
)0, (guicolor_T
)0, back
);
2539 for (idx
= 0; idx
< len
; ++idx
)
2541 if (enc_utf8
&& ScreenLines
[off
+ idx
] == 0)
2542 continue; /* skip second half of double-width char */
2543 if (ScreenAttrs
[off
+ idx
] != first_attr
)
2546 /* gui_screenstr() takes care of multibyte chars */
2547 nback
= gui_screenstr(off
, idx
, flags
,
2548 (guicolor_T
)0, (guicolor_T
)0, back
);
2550 for (idx
= 0; idx
< len
&& ScreenAttrs
[off
+ idx
] == first_attr
;
2554 /* Stop at a multi-byte Unicode character. */
2555 if (enc_utf8
&& ScreenLinesUC
[off
+ idx
] != 0)
2557 if (enc_dbcs
== DBCS_JPNU
)
2559 /* Stop at a double-byte single-width char. */
2560 if (ScreenLines
[off
+ idx
] == 0x8e)
2562 if (len
> 1 && (*mb_ptr2len
)(ScreenLines
2564 ++idx
; /* skip second byte of double-byte char */
2568 nback
= gui_outstr_nowrap(ScreenLines
+ off
, idx
, flags
,
2569 (guicolor_T
)0, (guicolor_T
)0, back
);
2574 /* Must back up to start drawing where a bold or italic word
2589 /* Put the cursor back where it was */
2592 gui
.highlight_mask
= (int)old_hl_mask
;
2598 gui_delete_lines(row
, count
)
2605 if (row
+ count
> gui
.scroll_region_bot
)
2606 /* Scrolled out of region, just blank the lines out */
2607 gui_clear_block(row
, gui
.scroll_region_left
,
2608 gui
.scroll_region_bot
, gui
.scroll_region_right
);
2611 gui_mch_delete_lines(row
, count
);
2613 /* If the cursor was in the deleted lines it's now gone. If the
2614 * cursor was in the scrolled lines adjust its position. */
2615 if (gui
.cursor_row
>= row
2616 && gui
.cursor_col
>= gui
.scroll_region_left
2617 && gui
.cursor_col
<= gui
.scroll_region_right
)
2619 if (gui
.cursor_row
< row
+ count
)
2620 gui
.cursor_is_valid
= FALSE
;
2621 else if (gui
.cursor_row
<= gui
.scroll_region_bot
)
2622 gui
.cursor_row
-= count
;
2628 gui_insert_lines(row
, count
)
2635 if (row
+ count
> gui
.scroll_region_bot
)
2636 /* Scrolled out of region, just blank the lines out */
2637 gui_clear_block(row
, gui
.scroll_region_left
,
2638 gui
.scroll_region_bot
, gui
.scroll_region_right
);
2641 gui_mch_insert_lines(row
, count
);
2643 if (gui
.cursor_row
>= gui
.row
2644 && gui
.cursor_col
>= gui
.scroll_region_left
2645 && gui
.cursor_col
<= gui
.scroll_region_right
)
2647 if (gui
.cursor_row
<= gui
.scroll_region_bot
- count
)
2648 gui
.cursor_row
+= count
;
2649 else if (gui
.cursor_row
<= gui
.scroll_region_bot
)
2650 gui
.cursor_is_valid
= FALSE
;
2656 * The main GUI input routine. Waits for a character from the keyboard.
2657 * wtime == -1 Wait forever.
2658 * wtime == 0 Don't wait.
2659 * wtime > 0 Wait wtime milliseconds for a character.
2660 * Returns OK if a character was found to be available within the given time,
2661 * or FAIL otherwise.
2664 gui_wait_for_chars(wtime
)
2670 * If we're going to wait a bit, update the menus and mouse shape for the
2676 gui_update_menus(0);
2681 if (input_available()) /* Got char, return immediately */
2683 if (wtime
== 0) /* Don't wait for char */
2686 /* Before waiting, flush any output to the screen. */
2691 /* Blink when waiting for a character. Probably only does something
2692 * for showmatch() */
2693 gui_mch_start_blink();
2694 retval
= gui_mch_wait_for_chars(wtime
);
2695 gui_mch_stop_blink();
2700 * While we are waiting indefinitely for a character, blink the cursor.
2702 gui_mch_start_blink();
2706 * We may want to trigger the CursorHold event. First wait for
2707 * 'updatetime' and if nothing is typed within that time put the
2708 * K_CURSORHOLD key in the input buffer.
2710 if (gui_mch_wait_for_chars(p_ut
) == OK
)
2713 else if (trigger_cursorhold())
2717 /* Put K_CURSORHOLD in the input buffer. */
2720 buf
[2] = (int)KE_CURSORHOLD
;
2721 add_to_input_buf(buf
, 3);
2729 /* Blocking wait. */
2731 retval
= gui_mch_wait_for_chars(-1L);
2734 gui_mch_stop_blink();
2739 * Fill p[4] with mouse coordinates encoded for check_termcode().
2742 fill_mouse_coord(p
, col
, row
)
2747 p
[0] = (char_u
)(col
/ 128 + ' ' + 1);
2748 p
[1] = (char_u
)(col
% 128 + ' ' + 1);
2749 p
[2] = (char_u
)(row
/ 128 + ' ' + 1);
2750 p
[3] = (char_u
)(row
% 128 + ' ' + 1);
2754 * Generic mouse support function. Add a mouse event to the input buffer with
2755 * the given properties.
2756 * button --- may be any of MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT,
2757 * MOUSE_X1, MOUSE_X2
2758 * MOUSE_DRAG, or MOUSE_RELEASE.
2759 * MOUSE_4 and MOUSE_5 are used for a scroll wheel.
2760 * x, y --- Coordinates of mouse in pixels.
2761 * repeated_click --- TRUE if this click comes only a short time after a
2763 * modifiers --- Bit field which may be any of the following modifiers
2764 * or'ed together: MOUSE_SHIFT | MOUSE_CTRL | MOUSE_ALT.
2765 * This function will ignore drag events where the mouse has not moved to a new
2769 gui_send_mouse_event(button
, x
, y
, repeated_click
, modifiers
)
2776 static int prev_row
= 0, prev_col
= 0;
2777 static int prev_button
= -1;
2778 static int num_clicks
= 1;
2780 enum key_extra button_char
;
2782 #ifdef FEAT_CLIPBOARD
2784 int did_clip
= FALSE
;
2788 * Scrolling may happen at any time, also while a selection is present.
2793 button_char
= KE_X1MOUSE
;
2796 button_char
= KE_X2MOUSE
;
2799 button_char
= KE_MOUSEDOWN
;
2802 button_char
= KE_MOUSEUP
;
2805 /* Don't put events in the input queue now. */
2806 if (hold_gui_events
)
2810 string
[4] = KS_EXTRA
;
2811 string
[5] = (int)button_char
;
2813 /* Pass the pointer coordinates of the scroll event so that we
2814 * know which window to scroll. */
2815 row
= gui_xy2colrow(x
, y
, &col
);
2816 string
[6] = (char_u
)(col
/ 128 + ' ' + 1);
2817 string
[7] = (char_u
)(col
% 128 + ' ' + 1);
2818 string
[8] = (char_u
)(row
/ 128 + ' ' + 1);
2819 string
[9] = (char_u
)(row
% 128 + ' ' + 1);
2822 add_to_input_buf(string
+ 3, 7);
2826 string
[1] = KS_MODIFIER
;
2828 if (modifiers
& MOUSE_SHIFT
)
2829 string
[2] |= MOD_MASK_SHIFT
;
2830 if (modifiers
& MOUSE_CTRL
)
2831 string
[2] |= MOD_MASK_CTRL
;
2832 if (modifiers
& MOUSE_ALT
)
2833 string
[2] |= MOD_MASK_ALT
;
2834 add_to_input_buf(string
, 10);
2840 #ifdef FEAT_CLIPBOARD
2841 /* If a clipboard selection is in progress, handle it */
2842 if (clip_star
.state
== SELECT_IN_PROGRESS
)
2844 clip_process_selection(button
, X_2_COL(x
), Y_2_ROW(y
), repeated_click
);
2848 /* Determine which mouse settings to look for based on the current mode */
2849 switch (get_real_state())
2853 case NORMAL
: checkfor
= MOUSE_NORMAL
; break;
2854 case VISUAL
: checkfor
= MOUSE_VISUAL
; break;
2855 case SELECTMODE
: checkfor
= MOUSE_VISUAL
; break;
2857 case REPLACE
+LANGMAP
:
2858 #ifdef FEAT_VREPLACE
2860 case VREPLACE
+LANGMAP
:
2863 case INSERT
+LANGMAP
: checkfor
= MOUSE_INSERT
; break;
2865 case HITRETURN
: /* At the more- and hit-enter prompt pass the
2866 mouse event for a click on or below the
2868 if (Y_2_ROW(y
) >= msg_row
)
2869 checkfor
= MOUSE_NORMAL
;
2871 checkfor
= MOUSE_RETURN
;
2875 * On the command line, use the clipboard selection on all lines
2876 * but the command line. But not when pasting.
2879 case CMDLINE
+LANGMAP
:
2880 if (Y_2_ROW(y
) < cmdline_row
&& button
!= MOUSE_MIDDLE
)
2881 checkfor
= MOUSE_NONE
;
2883 checkfor
= MOUSE_COMMAND
;
2887 checkfor
= MOUSE_NONE
;
2892 * Allow clipboard selection of text on the command line in "normal"
2893 * modes. Don't do this when dragging the status line, or extending a
2896 if ((State
== NORMAL
|| State
== NORMAL_BUSY
|| (State
& INSERT
))
2897 && Y_2_ROW(y
) >= topframe
->fr_height
2898 # ifdef FEAT_WINDOWS
2899 + firstwin
->w_winrow
2901 && button
!= MOUSE_DRAG
2902 # ifdef FEAT_MOUSESHAPE
2903 && !drag_status_line
2904 # ifdef FEAT_VERTSPLIT
2909 checkfor
= MOUSE_NONE
;
2912 * Use modeless selection when holding CTRL and SHIFT pressed.
2914 if ((modifiers
& MOUSE_CTRL
) && (modifiers
& MOUSE_SHIFT
))
2915 checkfor
= MOUSE_NONEF
;
2918 * In Ex mode, always use modeless selection.
2921 checkfor
= MOUSE_NONE
;
2924 * If the mouse settings say to not use the mouse, use the modeless
2925 * selection. But if Visual is active, assume that only the Visual area
2927 * Exception: On the command line, both the selection is used and a mouse
2930 if (!mouse_has(checkfor
) || checkfor
== MOUSE_COMMAND
)
2933 /* Don't do modeless selection in Visual mode. */
2934 if (checkfor
!= MOUSE_NONEF
&& VIsual_active
&& (State
& NORMAL
))
2939 * When 'mousemodel' is "popup", shift-left is translated to right.
2940 * But not when also using Ctrl.
2942 if (mouse_model_popup() && button
== MOUSE_LEFT
2943 && (modifiers
& MOUSE_SHIFT
) && !(modifiers
& MOUSE_CTRL
))
2945 button
= MOUSE_RIGHT
;
2946 modifiers
&= ~ MOUSE_SHIFT
;
2949 /* If the selection is done, allow the right button to extend it.
2950 * If the selection is cleared, allow the right button to start it
2951 * from the cursor position. */
2952 if (button
== MOUSE_RIGHT
)
2954 if (clip_star
.state
== SELECT_CLEARED
)
2956 if (State
& CMDLINE
)
2963 col
= curwin
->w_wcol
;
2964 row
= curwin
->w_wrow
+ W_WINROW(curwin
);
2966 clip_start_selection(col
, row
, FALSE
);
2968 clip_process_selection(button
, X_2_COL(x
), Y_2_ROW(y
),
2972 /* Allow the left button to start the selection */
2975 /* Only start a drag on a drag event. Otherwise
2976 * we don't get a release event. */
2983 clip_start_selection(X_2_COL(x
), Y_2_ROW(y
), repeated_click
);
2987 else if (button
== MOUSE_LEFT
)
2989 clip_clear_selection();
2994 /* Always allow pasting */
2995 if (button
!= MOUSE_MIDDLE
)
2997 if (!mouse_has(checkfor
) || button
== MOUSE_RELEASE
)
2999 if (checkfor
!= MOUSE_COMMAND
)
3000 button
= MOUSE_LEFT
;
3002 repeated_click
= FALSE
;
3005 if (clip_star
.state
!= SELECT_CLEARED
&& !did_clip
)
3006 clip_clear_selection();
3009 /* Don't put events in the input queue now. */
3010 if (hold_gui_events
)
3013 row
= gui_xy2colrow(x
, y
, &col
);
3016 * If we are dragging and the mouse hasn't moved far enough to be on a
3017 * different character, then don't send an event to vim.
3019 if (button
== MOUSE_DRAG
)
3021 if (row
== prev_row
&& col
== prev_col
)
3023 /* Dragging above the window, set "row" to -1 to cause a scroll. */
3029 * If topline has changed (window scrolled) since the last click, reset
3030 * repeated_click, because we don't want starting Visual mode when
3031 * clicking on a different character in the text.
3033 if (curwin
->w_topline
!= gui_prev_topline
3035 || curwin
->w_topfill
!= gui_prev_topfill
3038 repeated_click
= FALSE
;
3040 string
[0] = CSI
; /* this sequence is recognized by check_termcode() */
3041 string
[1] = KS_MOUSE
;
3042 string
[2] = KE_FILLER
;
3043 if (button
!= MOUSE_DRAG
&& button
!= MOUSE_RELEASE
)
3048 * Handle multiple clicks. They only count if the mouse is still
3049 * pointing at the same character.
3051 if (button
!= prev_button
|| row
!= prev_row
|| col
!= prev_col
)
3053 else if (++num_clicks
> 4)
3058 prev_button
= button
;
3059 gui_prev_topline
= curwin
->w_topline
;
3061 gui_prev_topfill
= curwin
->w_topfill
;
3064 string
[3] = (char_u
)(button
| 0x20);
3065 SET_NUM_MOUSE_CLICKS(string
[3], num_clicks
);
3068 string
[3] = (char_u
)button
;
3070 string
[3] |= modifiers
;
3071 fill_mouse_coord(string
+ 4, col
, row
);
3072 add_to_input_buf(string
, 8);
3081 * We need to make sure this is cleared since Athena doesn't tell us when
3082 * he is done dragging. Neither does GTK+ 2 -- at least for now.
3084 #if defined(FEAT_GUI_ATHENA) || defined(HAVE_GTK2)
3085 gui
.dragged_sb
= SBAR_NONE
;
3090 * Convert x and y coordinate to column and row in text window.
3091 * Corrects for multi-byte character.
3092 * returns column in "*colp" and row as return value;
3095 gui_xy2colrow(x
, y
, colp
)
3100 int col
= check_col(X_2_COL(x
));
3101 int row
= check_row(Y_2_ROW(y
));
3104 *colp
= mb_fix_col(col
, row
);
3111 #if defined(FEAT_MENU) || defined(PROTO)
3113 * Callback function for when a menu entry has been selected.
3119 char_u bytes
[sizeof(long_u
)];
3121 /* Don't put events in the input queue now. */
3122 if (hold_gui_events
)
3127 bytes
[2] = KE_FILLER
;
3128 add_to_input_buf(bytes
, 3);
3129 add_long_to_buf((long_u
)menu
, bytes
);
3130 add_to_input_buf_csi(bytes
, sizeof(long_u
));
3134 static int prev_which_scrollbars
[3];
3137 * Set which components are present.
3138 * If "oldval" is not NULL, "oldval" is the previous value, the new value is
3142 gui_init_which_components(oldval
)
3143 char_u
*oldval UNUSED
;
3146 static int prev_menu_is_active
= -1;
3149 static int prev_toolbar
= -1;
3150 int using_toolbar
= FALSE
;
3152 #ifdef FEAT_GUI_TABLINE
3156 static int prev_footer
= -1;
3157 int using_footer
= FALSE
;
3159 #if defined(FEAT_MENU) && !defined(WIN16)
3160 static int prev_tearoff
= -1;
3161 int using_tearoff
= FALSE
;
3163 static int prev_nocaption
= -1;
3164 int using_caption
= TRUE
;
3169 int grey_old
, grey_new
;
3177 if (oldval
!= NULL
&& gui
.in_use
)
3180 * Check if the menu's go from grey to non-grey or vise versa.
3182 grey_old
= (vim_strchr(oldval
, GO_GREY
) != NULL
);
3183 grey_new
= (vim_strchr(p_go
, GO_GREY
) != NULL
);
3184 if (grey_old
!= grey_new
)
3188 gui_update_menus(MENU_ALL_MODES
);
3192 gui
.menu_is_active
= FALSE
;
3195 for (i
= 0; i
< 3; i
++)
3196 gui
.which_scrollbars
[i
] = FALSE
;
3197 for (p
= p_go
; *p
; p
++)
3201 gui
.which_scrollbars
[SBAR_LEFT
] = TRUE
;
3204 gui
.which_scrollbars
[SBAR_RIGHT
] = TRUE
;
3206 #ifdef FEAT_VERTSPLIT
3208 if (win_hasvertsplit())
3209 gui
.which_scrollbars
[SBAR_LEFT
] = TRUE
;
3212 if (win_hasvertsplit())
3213 gui
.which_scrollbars
[SBAR_RIGHT
] = TRUE
;
3217 gui
.which_scrollbars
[SBAR_BOTTOM
] = TRUE
;
3221 gui
.menu_is_active
= TRUE
;
3225 /* make menu's have grey items, ignored here */
3229 using_toolbar
= TRUE
;
3234 using_footer
= TRUE
;
3238 #if defined(FEAT_MENU) && !defined(WIN16)
3239 using_tearoff
= TRUE
;
3243 using_caption
= FALSE
;
3246 /* Ignore options that are not supported */
3255 #ifdef FEAT_GUI_TABLINE
3256 /* Update the GUI tab line, it may appear or disappear. This may
3257 * cause the non-GUI tab line to disappear or appear. */
3258 using_tabline
= gui_has_tabline();
3259 if (!gui_mch_showing_tabline() != !using_tabline
)
3261 /* We don't want a resize event change "Rows" here, save and
3262 * restore it. Resizing is handled below. */
3264 gui_update_tabline();
3266 need_set_size
|= RESIZE_VERT
;
3269 if (!gui_use_tabline())
3270 redraw_tabline
= TRUE
; /* may draw non-GUI tab line */
3274 for (i
= 0; i
< 3; i
++)
3276 /* The scrollbar needs to be updated when it is shown/unshown and
3277 * when switching tab pages. But the size only changes when it's
3278 * shown/unshown. Thus we need two places to remember whether a
3279 * scrollbar is there or not. */
3280 if (gui
.which_scrollbars
[i
] != prev_which_scrollbars
[i
]
3282 || gui
.which_scrollbars
[i
]
3283 != curtab
->tp_prev_which_scrollbars
[i
]
3287 if (i
== SBAR_BOTTOM
)
3288 gui_mch_enable_scrollbar(&gui
.bottom_sbar
,
3289 gui
.which_scrollbars
[i
]);
3294 gui_do_scrollbar(wp
, i
, gui
.which_scrollbars
[i
]);
3297 if (gui
.which_scrollbars
[i
] != prev_which_scrollbars
[i
])
3299 if (i
== SBAR_BOTTOM
)
3300 need_set_size
|= RESIZE_VERT
;
3302 need_set_size
|= RESIZE_HOR
;
3303 if (gui
.which_scrollbars
[i
])
3308 curtab
->tp_prev_which_scrollbars
[i
] = gui
.which_scrollbars
[i
];
3310 prev_which_scrollbars
[i
] = gui
.which_scrollbars
[i
];
3314 if (gui
.menu_is_active
!= prev_menu_is_active
)
3316 /* We don't want a resize event change "Rows" here, save and
3317 * restore it. Resizing is handled below. */
3319 gui_mch_enable_menu(gui
.menu_is_active
);
3321 prev_menu_is_active
= gui
.menu_is_active
;
3322 need_set_size
|= RESIZE_VERT
;
3323 if (gui
.menu_is_active
)
3329 if (using_toolbar
!= prev_toolbar
)
3331 gui_mch_show_toolbar(using_toolbar
);
3332 prev_toolbar
= using_toolbar
;
3333 need_set_size
|= RESIZE_VERT
;
3339 if (using_footer
!= prev_footer
)
3341 gui_mch_enable_footer(using_footer
);
3342 prev_footer
= using_footer
;
3343 need_set_size
|= RESIZE_VERT
;
3348 #if defined(FEAT_MENU) && !defined(WIN16) && !(defined(WIN3264) && !defined(FEAT_TEAROFF))
3349 if (using_tearoff
!= prev_tearoff
)
3351 gui_mch_toggle_tearoffs(using_tearoff
);
3352 prev_tearoff
= using_tearoff
;
3355 if (using_caption
!= prev_nocaption
)
3357 #if defined(WIN3264)
3358 gui_mch_show_caption(using_caption
);
3360 prev_nocaption
= using_caption
;
3361 need_set_size
= TRUE
;
3363 if (need_set_size
!= 0)
3366 long prev_Columns
= Columns
;
3367 long prev_Rows
= Rows
;
3369 /* Adjust the size of the window to make the text area keep the
3370 * same size and to avoid that part of our window is off-screen
3371 * and a scrollbar can't be used, for example. */
3372 gui_set_shellsize(FALSE
, fix_size
, need_set_size
);
3375 /* GTK has the annoying habit of sending us resize events when
3376 * changing the window size ourselves. This mostly happens when
3377 * waiting for a character to arrive, quite unpredictably, and may
3378 * change Columns and Rows when we don't want it. Wait for a
3379 * character here to avoid this effect.
3380 * If you remove this, please test this command for resizing
3381 * effects (with optional left scrollbar): ":vsp|q|vsp|q|vsp|q".
3382 * Don't do this while starting up though.
3383 * Don't change Rows when adding menu/toolbar/tabline.
3384 * Don't change Columns when adding vertical toolbar. */
3385 if (!gui
.starting
&& need_set_size
!= (RESIZE_VERT
| RESIZE_HOR
))
3387 if ((need_set_size
& RESIZE_VERT
) == 0)
3389 if ((need_set_size
& RESIZE_HOR
) == 0)
3390 Columns
= prev_Columns
;
3394 /* When the console tabline appears or disappears the window positions
3396 if (firstwin
->w_winrow
!= tabline_height())
3397 shell_new_rows(); /* recompute window positions and heights */
3402 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3404 * Return TRUE if the GUI is taking care of the tabline.
3405 * It may still be hidden if 'showtabline' is zero.
3410 return gui
.in_use
&& vim_strchr(p_go
, GO_TABLINE
) != NULL
;
3414 * Return TRUE if the GUI is showing the tabline.
3415 * This uses 'showtabline'.
3420 if (!gui_use_tabline()
3422 || (p_stal
== 1 && first_tabpage
->tp_next
== NULL
))
3428 * Update the tabline.
3429 * This may display/undisplay the tabline and update the labels.
3432 gui_update_tabline()
3434 int showit
= gui_has_tabline();
3435 int shown
= gui_mch_showing_tabline();
3437 if (!gui
.starting
&& starting
== 0)
3439 /* Updating the tabline uses direct GUI commands, flush
3440 * outstanding instructions first. (esp. clear screen) */
3444 if (!showit
!= !shown
)
3445 gui_mch_show_tabline(showit
);
3447 gui_mch_update_tabline();
3449 /* When the tabs change from hidden to shown or from shown to
3450 * hidden the size of the text area should remain the same. */
3451 if (!showit
!= !shown
)
3452 gui_set_shellsize(FALSE
, showit
, RESIZE_VERT
);
3457 * Get the label or tooltip for tab page "tp" into NameBuff[].
3460 get_tabline_label(tp
, tooltip
)
3462 int tooltip
; /* TRUE: get tooltip */
3464 int modified
= FALSE
;
3470 /* Use 'guitablabel' or 'guitabtooltip' if it's set. */
3471 opt
= (tooltip
? &p_gtt
: &p_gtl
);
3474 int use_sandbox
= FALSE
;
3475 int save_called_emsg
= called_emsg
;
3476 char_u res
[MAXPATHL
];
3477 tabpage_T
*save_curtab
;
3478 char_u
*opt_name
= (char_u
*)(tooltip
? "guitabtooltip"
3481 called_emsg
= FALSE
;
3483 printer_page_num
= tabpage_index(tp
);
3485 set_vim_var_nr(VV_LNUM
, printer_page_num
);
3486 use_sandbox
= was_set_insecurely(opt_name
, 0);
3488 /* It's almost as going to the tabpage, but without autocommands. */
3489 curtab
->tp_firstwin
= firstwin
;
3490 curtab
->tp_lastwin
= lastwin
;
3491 curtab
->tp_curwin
= curwin
;
3492 save_curtab
= curtab
;
3494 topframe
= curtab
->tp_topframe
;
3495 firstwin
= curtab
->tp_firstwin
;
3496 lastwin
= curtab
->tp_lastwin
;
3497 curwin
= curtab
->tp_curwin
;
3498 curbuf
= curwin
->w_buffer
;
3500 /* Can't use NameBuff directly, build_stl_str_hl() uses it. */
3501 build_stl_str_hl(curwin
, res
, MAXPATHL
, *opt
, use_sandbox
,
3502 0, (int)Columns
, NULL
, NULL
);
3503 STRCPY(NameBuff
, res
);
3505 /* Back to the original curtab. */
3506 curtab
= save_curtab
;
3507 topframe
= curtab
->tp_topframe
;
3508 firstwin
= curtab
->tp_firstwin
;
3509 lastwin
= curtab
->tp_lastwin
;
3510 curwin
= curtab
->tp_curwin
;
3511 curbuf
= curwin
->w_buffer
;
3514 set_string_option_direct(opt_name
, -1,
3515 (char_u
*)"", OPT_FREE
, SID_ERROR
);
3516 called_emsg
|= save_called_emsg
;
3519 /* If 'guitablabel'/'guitabtooltip' is not set or the result is empty then
3520 * use a default label. */
3521 if (**opt
== NUL
|| *NameBuff
== NUL
)
3523 /* Get the buffer name into NameBuff[] and shorten it. */
3524 get_trans_bufname(tp
== curtab
? curbuf
: tp
->tp_curwin
->w_buffer
);
3526 shorten_dir(NameBuff
);
3528 wp
= (tp
== curtab
) ? firstwin
: tp
->tp_firstwin
;
3529 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
3530 if (bufIsChanged(wp
->w_buffer
))
3532 if (modified
|| wincount
> 1)
3535 vim_snprintf((char *)buf
, sizeof(buf
), "%d", wincount
);
3541 STRMOVE(NameBuff
+ STRLEN(buf
), NameBuff
);
3542 mch_memmove(NameBuff
, buf
, STRLEN(buf
));
3548 * Send the event for clicking to select tab page "nr".
3549 * Returns TRUE if it was done, FALSE when skipped because we are already at
3550 * that tab page or the cmdline window is open.
3553 send_tabline_event(nr
)
3558 if (nr
== tabpage_index(curtab
))
3561 /* Don't put events in the input queue now. */
3568 /* Set it back to the current tab page. */
3569 gui_mch_set_curtab(tabpage_index(curtab
));
3574 string
[1] = KS_TABLINE
;
3575 string
[2] = KE_FILLER
;
3576 add_to_input_buf(string
, 3);
3578 add_to_input_buf_csi(string
, 1);
3583 * Send a tabline menu event
3586 send_tabline_menu_event(tabidx
, event
)
3592 /* Don't put events in the input queue now. */
3593 if (hold_gui_events
)
3597 string
[1] = KS_TABMENU
;
3598 string
[2] = KE_FILLER
;
3599 add_to_input_buf(string
, 3);
3601 string
[1] = (char_u
)(long)event
;
3602 add_to_input_buf_csi(string
, 2);
3611 #if defined(FEAT_WINDOWS) || defined(PROTO)
3613 * Remove all scrollbars. Used before switching to another tab page.
3616 gui_remove_scrollbars()
3621 for (i
= 0; i
< 3; i
++)
3623 if (i
== SBAR_BOTTOM
)
3624 gui_mch_enable_scrollbar(&gui
.bottom_sbar
, FALSE
);
3629 gui_do_scrollbar(wp
, i
, FALSE
);
3632 curtab
->tp_prev_which_scrollbars
[i
] = -1;
3638 gui_create_scrollbar(sb
, type
, wp
)
3643 static int sbar_ident
= 0;
3645 sb
->ident
= sbar_ident
++; /* No check for too big, but would it happen? */
3649 #ifdef FEAT_GUI_ATHENA
3656 #ifdef FEAT_VERTSPLIT
3659 sb
->status_height
= 0;
3660 gui_mch_create_scrollbar(sb
, (wp
== NULL
) ? SBAR_HORIZ
: SBAR_VERT
);
3664 * Find the scrollbar with the given index.
3667 gui_find_scrollbar(ident
)
3672 if (gui
.bottom_sbar
.ident
== ident
)
3673 return &gui
.bottom_sbar
;
3676 if (wp
->w_scrollbars
[SBAR_LEFT
].ident
== ident
)
3677 return &wp
->w_scrollbars
[SBAR_LEFT
];
3678 if (wp
->w_scrollbars
[SBAR_RIGHT
].ident
== ident
)
3679 return &wp
->w_scrollbars
[SBAR_RIGHT
];
3685 * For most systems: Put a code in the input buffer for a dragged scrollbar.
3687 * For Win32, Macintosh and GTK+ 2:
3688 * Scrollbars seem to grab focus and vim doesn't read the input queue until
3689 * you stop dragging the scrollbar. We get here each time the scrollbar is
3690 * dragged another pixel, but as far as the rest of vim goes, it thinks
3691 * we're just hanging in the call to DispatchMessage() in
3692 * process_message(). The DispatchMessage() call that hangs was passed a
3693 * mouse button click event in the scrollbar window. -- webb.
3695 * Solution: Do the scrolling right here. But only when allowed.
3696 * Ignore the scrollbars while executing an external command or when there
3697 * are still characters to be processed.
3700 gui_drag_scrollbar(sb
, value
, still_dragging
)
3709 #ifdef USE_ON_FLY_SCROLL
3710 colnr_T old_leftcol
= curwin
->w_leftcol
;
3711 # ifdef FEAT_SCROLLBIND
3712 linenr_T old_topline
= curwin
->w_topline
;
3715 int old_topfill
= curwin
->w_topfill
;
3718 char_u bytes
[sizeof(long_u
)];
3725 /* Don't put events in the input queue now. */
3726 if (hold_gui_events
)
3730 if (cmdwin_type
!= 0 && sb
->wp
!= curwin
)
3737 gui
.dragged_sb
= SBAR_BOTTOM
;
3738 else if (sb
== &sb
->wp
->w_scrollbars
[SBAR_LEFT
])
3739 gui
.dragged_sb
= SBAR_LEFT
;
3741 gui
.dragged_sb
= SBAR_RIGHT
;
3742 gui
.dragged_wp
= sb
->wp
;
3746 gui
.dragged_sb
= SBAR_NONE
;
3748 /* Keep the "dragged_wp" value until after the scrolling, for when the
3749 * moust button is released. GTK2 doesn't send the button-up event. */
3750 gui
.dragged_wp
= NULL
;
3754 /* Vertical sbar info is kept in the first sbar (the left one) */
3756 sb
= &sb
->wp
->w_scrollbars
[0];
3759 * Check validity of value
3763 #ifdef SCROLL_PAST_END
3764 else if (value
> sb
->max
)
3767 if (value
> sb
->max
- sb
->size
+ 1)
3768 value
= sb
->max
- sb
->size
+ 1;
3773 #ifdef USE_ON_FLY_SCROLL
3774 /* When not allowed to do the scrolling right now, return.
3775 * This also checked input_available(), but that causes the first click in
3776 * a scrollbar to be ignored when Vim doesn't have focus. */
3780 #ifdef FEAT_INS_EXPAND
3781 /* Disallow scrolling the current window when the completion popup menu is
3783 if ((sb
->wp
== NULL
|| sb
->wp
== curwin
) && pum_visible())
3787 #ifdef FEAT_RIGHTLEFT
3788 if (sb
->wp
== NULL
&& curwin
->w_p_rl
)
3790 value
= sb
->max
+ 1 - sb
->size
- value
;
3796 if (sb
->wp
!= NULL
) /* vertical scrollbar */
3800 for (wp
= firstwin
; wp
!= sb
->wp
&& wp
!= NULL
; wp
= wp
->w_next
)
3805 if (sb
->wp
!= curwin
)
3809 #ifdef USE_ON_FLY_SCROLL
3810 current_scrollbar
= sb_num
;
3811 scrollbar_value
= value
;
3817 else if (State
& INSERT
)
3822 else if (State
& CMDLINE
)
3824 if (msg_scrolled
== 0)
3830 # ifdef FEAT_FOLDING
3831 /* Value may have been changed for closed fold. */
3832 sb
->value
= sb
->wp
->w_topline
- 1;
3835 /* When dragging one scrollbar and there is another one at the other
3836 * side move the thumb of that one too. */
3837 if (gui
.which_scrollbars
[SBAR_RIGHT
] && gui
.which_scrollbars
[SBAR_LEFT
])
3838 gui_mch_set_scrollbar_thumb(
3839 &sb
->wp
->w_scrollbars
[
3840 sb
== &sb
->wp
->w_scrollbars
[SBAR_RIGHT
]
3841 ? SBAR_LEFT
: SBAR_RIGHT
],
3842 sb
->value
, sb
->size
, sb
->max
);
3846 bytes
[1] = KS_VER_SCROLLBAR
;
3847 bytes
[2] = KE_FILLER
;
3848 bytes
[3] = (char_u
)sb_num
;
3854 #ifdef USE_ON_FLY_SCROLL
3855 scrollbar_value
= value
;
3858 gui_do_horiz_scroll();
3859 else if (State
& INSERT
)
3861 else if (State
& CMDLINE
)
3863 if (msg_scrolled
== 0)
3865 gui_do_horiz_scroll();
3869 if (old_leftcol
!= curwin
->w_leftcol
)
3871 updateWindow(curwin
); /* update window, status and cmdline */
3876 bytes
[1] = KS_HOR_SCROLLBAR
;
3877 bytes
[2] = KE_FILLER
;
3882 #ifdef USE_ON_FLY_SCROLL
3883 # ifdef FEAT_SCROLLBIND
3885 * synchronize other windows, as necessary according to 'scrollbind'
3888 && ((sb
->wp
== NULL
&& curwin
->w_leftcol
!= old_leftcol
)
3889 || (sb
->wp
== curwin
&& (curwin
->w_topline
!= old_topline
3891 || curwin
->w_topfill
!= old_topfill
3895 do_check_scrollbind(TRUE
);
3896 /* need to update the window right here */
3897 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3898 if (wp
->w_redr_type
> 0)
3904 gui_update_cursor(FALSE
, TRUE
);
3906 add_to_input_buf(bytes
, byte_count
);
3907 add_long_to_buf((long_u
)value
, bytes
);
3908 add_to_input_buf_csi(bytes
, sizeof(long_u
));
3917 * Called when something in the window layout has changed.
3920 gui_may_update_scrollbars()
3922 if (gui
.in_use
&& starting
== 0)
3925 gui_init_which_components(NULL
);
3926 gui_update_scrollbars(TRUE
);
3928 need_mouse_correct
= TRUE
;
3932 gui_update_scrollbars(force
)
3933 int force
; /* Force all scrollbars to get updated */
3937 long val
, size
, max
; /* need 32 bits here */
3940 #ifdef FEAT_VERTSPLIT
3941 static win_T
*prev_curwin
= NULL
;
3944 /* Update the horizontal scrollbar */
3945 gui_update_horiz_scrollbar(force
);
3948 /* Return straight away if there is neither a left nor right scrollbar.
3949 * On MS-Windows this is required anyway for scrollwheel messages. */
3950 if (!gui
.which_scrollbars
[SBAR_LEFT
] && !gui
.which_scrollbars
[SBAR_RIGHT
])
3955 * Don't want to update a scrollbar while we're dragging it. But if we
3956 * have both a left and right scrollbar, and we drag one of them, we still
3957 * need to update the other one.
3959 if (!force
&& (gui
.dragged_sb
== SBAR_LEFT
|| gui
.dragged_sb
== SBAR_RIGHT
)
3960 && gui
.which_scrollbars
[SBAR_LEFT
]
3961 && gui
.which_scrollbars
[SBAR_RIGHT
])
3964 * If we have two scrollbars and one of them is being dragged, just
3965 * copy the scrollbar position from the dragged one to the other one.
3967 which_sb
= SBAR_LEFT
+ SBAR_RIGHT
- gui
.dragged_sb
;
3968 if (gui
.dragged_wp
!= NULL
)
3969 gui_mch_set_scrollbar_thumb(
3970 &gui
.dragged_wp
->w_scrollbars
[which_sb
],
3971 gui
.dragged_wp
->w_scrollbars
[0].value
,
3972 gui
.dragged_wp
->w_scrollbars
[0].size
,
3973 gui
.dragged_wp
->w_scrollbars
[0].max
);
3976 /* avoid that moving components around generates events */
3979 for (wp
= firstwin
; wp
!= NULL
; wp
= W_NEXT(wp
))
3981 if (wp
->w_buffer
== NULL
) /* just in case */
3983 /* Skip a scrollbar that is being dragged. */
3984 if (!force
&& (gui
.dragged_sb
== SBAR_LEFT
3985 || gui
.dragged_sb
== SBAR_RIGHT
)
3986 && gui
.dragged_wp
== wp
)
3989 #ifdef SCROLL_PAST_END
3990 max
= wp
->w_buffer
->b_ml
.ml_line_count
- 1;
3992 max
= wp
->w_buffer
->b_ml
.ml_line_count
+ wp
->w_height
- 2;
3994 if (max
< 0) /* empty buffer */
3996 val
= wp
->w_topline
- 1;
3997 size
= wp
->w_height
;
3998 #ifdef SCROLL_PAST_END
3999 if (val
> max
) /* just in case */
4002 if (size
> max
+ 1) /* just in case */
4004 if (val
> max
- size
+ 1)
4005 val
= max
- size
+ 1;
4007 if (val
< 0) /* minimal value is 0 */
4011 * Scrollbar at index 0 (the left one) contains all the information.
4012 * It would be the same info for left and right so we just store it for
4015 sb
= &wp
->w_scrollbars
[0];
4018 * Note: no check for valid w_botline. If it's not valid the
4019 * scrollbars will be updated later anyway.
4021 if (size
< 1 || wp
->w_botline
- 2 > max
)
4024 * This can happen during changing files. Just don't update the
4025 * scrollbar for now.
4027 sb
->height
= 0; /* Force update next time */
4028 if (gui
.which_scrollbars
[SBAR_LEFT
])
4029 gui_do_scrollbar(wp
, SBAR_LEFT
, FALSE
);
4030 if (gui
.which_scrollbars
[SBAR_RIGHT
])
4031 gui_do_scrollbar(wp
, SBAR_RIGHT
, FALSE
);
4034 if (force
|| sb
->height
!= wp
->w_height
4036 || sb
->top
!= wp
->w_winrow
4037 || sb
->status_height
!= wp
->w_status_height
4038 # ifdef FEAT_VERTSPLIT
4039 || sb
->width
!= wp
->w_width
4040 || prev_curwin
!= curwin
4045 /* Height, width or position of scrollbar has changed. For
4046 * vertical split: curwin changed. */
4047 sb
->height
= wp
->w_height
;
4049 sb
->top
= wp
->w_winrow
;
4050 sb
->status_height
= wp
->w_status_height
;
4051 # ifdef FEAT_VERTSPLIT
4052 sb
->width
= wp
->w_width
;
4056 /* Calculate height and position in pixels */
4057 h
= (sb
->height
+ sb
->status_height
) * gui
.char_height
;
4058 y
= sb
->top
* gui
.char_height
+ gui
.border_offset
;
4059 #if defined(FEAT_MENU) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \
4060 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MACVIM))
4061 if (gui
.menu_is_active
)
4062 y
+= gui
.menu_height
;
4065 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_ATHENA))
4066 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
4067 # ifdef FEAT_GUI_ATHENA
4068 y
+= gui
.toolbar_height
;
4070 # ifdef FEAT_GUI_MSWIN
4071 y
+= TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
;
4076 #if defined(FEAT_GUI_TABLINE) && defined(FEAT_GUI_MSWIN)
4077 if (gui_has_tabline())
4078 y
+= gui
.tabline_height
;
4082 if (wp
->w_winrow
== 0)
4085 /* Height of top scrollbar includes width of top border */
4086 h
+= gui
.border_offset
;
4087 y
-= gui
.border_offset
;
4089 if (gui
.which_scrollbars
[SBAR_LEFT
])
4091 gui_mch_set_scrollbar_pos(&wp
->w_scrollbars
[SBAR_LEFT
],
4093 gui
.scrollbar_width
, h
);
4094 gui_do_scrollbar(wp
, SBAR_LEFT
, TRUE
);
4096 if (gui
.which_scrollbars
[SBAR_RIGHT
])
4098 gui_mch_set_scrollbar_pos(&wp
->w_scrollbars
[SBAR_RIGHT
],
4099 gui
.right_sbar_x
, y
,
4100 gui
.scrollbar_width
, h
);
4101 gui_do_scrollbar(wp
, SBAR_RIGHT
, TRUE
);
4105 /* Reduce the number of calls to gui_mch_set_scrollbar_thumb() by
4106 * checking if the thumb moved at least a pixel. Only do this for
4107 * Athena, most other GUIs require the update anyway to make the
4109 #ifdef FEAT_GUI_ATHENA
4113 y
= (val
* (sb
->height
+ 2) * gui
.char_height
+ max
/ 2) / max
;
4114 if (force
|| sb
->pixval
!= y
|| sb
->size
!= size
|| sb
->max
!= max
)
4116 if (force
|| sb
->value
!= val
|| sb
->size
!= size
|| sb
->max
!= max
)
4119 /* Thumb of scrollbar has moved */
4121 #ifdef FEAT_GUI_ATHENA
4126 if (gui
.which_scrollbars
[SBAR_LEFT
]
4127 && (gui
.dragged_sb
!= SBAR_LEFT
|| gui
.dragged_wp
!= wp
))
4128 gui_mch_set_scrollbar_thumb(&wp
->w_scrollbars
[SBAR_LEFT
],
4130 if (gui
.which_scrollbars
[SBAR_RIGHT
]
4131 && (gui
.dragged_sb
!= SBAR_RIGHT
|| gui
.dragged_wp
!= wp
))
4132 gui_mch_set_scrollbar_thumb(&wp
->w_scrollbars
[SBAR_RIGHT
],
4136 #ifdef FEAT_VERTSPLIT
4137 prev_curwin
= curwin
;
4143 * Enable or disable a scrollbar.
4144 * Check for scrollbars for vertically split windows which are not enabled
4148 gui_do_scrollbar(wp
, which
, enable
)
4150 int which
; /* SBAR_LEFT or SBAR_RIGHT */
4151 int enable
; /* TRUE to enable scrollbar */
4153 #ifdef FEAT_VERTSPLIT
4154 int midcol
= curwin
->w_wincol
+ curwin
->w_width
/ 2;
4155 int has_midcol
= (wp
->w_wincol
<= midcol
4156 && wp
->w_wincol
+ wp
->w_width
>= midcol
);
4158 /* Only enable scrollbars that contain the middle column of the current
4160 if (gui
.which_scrollbars
[SBAR_RIGHT
] != gui
.which_scrollbars
[SBAR_LEFT
])
4162 /* Scrollbars only on one side. Don't enable scrollbars that don't
4163 * contain the middle column of the current window. */
4169 /* Scrollbars on both sides. Don't enable scrollbars that neither
4170 * contain the middle column of the current window nor are on the far
4172 if (midcol
> Columns
/ 2)
4174 if (which
== SBAR_LEFT
? wp
->w_wincol
!= 0 : !has_midcol
)
4179 if (which
== SBAR_RIGHT
? wp
->w_wincol
+ wp
->w_width
!= Columns
4185 gui_mch_enable_scrollbar(&wp
->w_scrollbars
[which
], enable
);
4189 * Scroll a window according to the values set in the globals current_scrollbar
4190 * and scrollbar_value. Return TRUE if the cursor in the current window moved
4191 * or FALSE otherwise.
4196 win_T
*wp
, *save_wp
;
4200 linenr_T old_topline
;
4205 for (wp
= firstwin
, i
= 0; i
< current_scrollbar
; wp
= W_NEXT(wp
), i
++)
4209 /* Couldn't find window */
4213 * Compute number of lines to scroll. If zero, nothing to do.
4215 nlines
= (long)scrollbar_value
+ 1 - (long)wp
->w_topline
;
4220 old_topline
= wp
->w_topline
;
4222 old_topfill
= wp
->w_topfill
;
4224 old_cursor
= wp
->w_cursor
;
4226 curbuf
= wp
->w_buffer
;
4228 scrolldown(-nlines
, gui
.dragged_wp
== NULL
);
4230 scrollup(nlines
, gui
.dragged_wp
== NULL
);
4231 /* Reset dragged_wp after using it. "dragged_sb" will have been reset for
4232 * the mouse-up event already, but we still want it to behave like when
4233 * dragging. But not the next click in an arrow. */
4234 if (gui
.dragged_sb
== SBAR_NONE
)
4235 gui
.dragged_wp
= NULL
;
4237 if (old_topline
!= wp
->w_topline
4239 || old_topfill
!= wp
->w_topfill
4245 cursor_correct(); /* fix window for 'so' */
4246 update_topline(); /* avoid up/down jump */
4248 if (old_cursor
.lnum
!= wp
->w_cursor
.lnum
)
4249 coladvance(wp
->w_curswant
);
4250 #ifdef FEAT_SCROLLBIND
4251 wp
->w_scbind_pos
= wp
->w_topline
;
4255 /* Make sure wp->w_leftcol and wp->w_skipcol are correct. */
4259 curbuf
= save_wp
->w_buffer
;
4262 * Don't call updateWindow() when nothing has changed (it will overwrite
4263 * the status line!).
4265 if (old_topline
!= wp
->w_topline
4266 || wp
->w_redr_type
!= 0
4268 || old_topfill
!= wp
->w_topfill
4274 #ifdef FEAT_INS_EXPAND
4278 wp
->w_lines_valid
= 0;
4281 /* Don't set must_redraw here, it may cause the popup menu to
4282 * disappear when losing focus after a scrollbar drag. */
4283 if (wp
->w_redr_type
< type
)
4284 wp
->w_redr_type
= type
;
4285 updateWindow(wp
); /* update window, status line, and cmdline */
4288 #ifdef FEAT_INS_EXPAND
4289 /* May need to redraw the popup menu. */
4294 return (wp
== curwin
&& !equalpos(curwin
->w_cursor
, old_cursor
));
4299 * Horizontal scrollbar stuff:
4303 * Return length of line "lnum" for horizontal scrolling.
4306 scroll_line_len(lnum
)
4318 w
= chartabsize(p
, col
);
4320 if (*p
== NUL
) /* don't count the last character */
4327 /* Remember which line is currently the longest, so that we don't have to
4328 * search for it when scrolling horizontally. */
4329 static linenr_T longest_lnum
= 0;
4332 gui_update_horiz_scrollbar(force
)
4335 long value
, size
, max
; /* need 32 bit ints here */
4337 if (!gui
.which_scrollbars
[SBAR_BOTTOM
])
4340 if (!force
&& gui
.dragged_sb
== SBAR_BOTTOM
)
4343 if (!force
&& curwin
->w_p_wrap
&& gui
.prev_wrap
)
4347 * It is possible for the cursor to be invalid if we're in the middle of
4348 * something (like changing files). If so, don't do anything for now.
4350 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
4352 gui
.bottom_sbar
.value
= -1;
4356 size
= W_WIDTH(curwin
);
4357 if (curwin
->w_p_wrap
)
4360 #ifdef SCROLL_PAST_END
4363 max
= W_WIDTH(curwin
) - 1;
4368 value
= curwin
->w_leftcol
;
4370 /* Calculate maximum for horizontal scrollbar. Check for reasonable
4371 * line numbers, topline and botline can be invalid when displaying is
4373 if (vim_strchr(p_go
, GO_HORSCROLL
) == NULL
4374 && curwin
->w_topline
<= curwin
->w_cursor
.lnum
4375 && curwin
->w_botline
> curwin
->w_cursor
.lnum
4376 && curwin
->w_botline
<= curbuf
->b_ml
.ml_line_count
+ 1)
4381 /* Use maximum of all visible lines. Remember the lnum of the
4382 * longest line, clostest to the cursor line. Used when scrolling
4385 for (lnum
= curwin
->w_topline
; lnum
< curwin
->w_botline
; ++lnum
)
4387 n
= scroll_line_len(lnum
);
4388 if (n
> (colnr_T
)max
)
4391 longest_lnum
= lnum
;
4393 else if (n
== (colnr_T
)max
4394 && abs((int)(lnum
- curwin
->w_cursor
.lnum
))
4395 < abs((int)(longest_lnum
- curwin
->w_cursor
.lnum
)))
4396 longest_lnum
= lnum
;
4400 /* Use cursor line only. */
4401 max
= scroll_line_len(curwin
->w_cursor
.lnum
);
4402 #ifdef FEAT_VIRTUALEDIT
4403 if (virtual_active())
4405 /* May move the cursor even further to the right. */
4406 if (curwin
->w_virtcol
>= (colnr_T
)max
)
4407 max
= curwin
->w_virtcol
;
4411 #ifndef SCROLL_PAST_END
4412 max
+= W_WIDTH(curwin
) - 1;
4414 /* The line number isn't scrolled, thus there is less space when
4415 * 'number' is set (also for 'foldcolumn'). */
4416 size
-= curwin_col_off();
4417 #ifndef SCROLL_PAST_END
4418 max
-= curwin_col_off();
4422 #ifndef SCROLL_PAST_END
4423 if (value
> max
- size
+ 1)
4424 value
= max
- size
+ 1; /* limit the value to allowable range */
4427 #ifdef FEAT_RIGHTLEFT
4430 value
= max
+ 1 - size
- value
;
4438 if (!force
&& value
== gui
.bottom_sbar
.value
&& size
== gui
.bottom_sbar
.size
4439 && max
== gui
.bottom_sbar
.max
)
4442 gui
.bottom_sbar
.value
= value
;
4443 gui
.bottom_sbar
.size
= size
;
4444 gui
.bottom_sbar
.max
= max
;
4445 gui
.prev_wrap
= curwin
->w_p_wrap
;
4447 gui_mch_set_scrollbar_thumb(&gui
.bottom_sbar
, value
, size
, max
);
4451 * Do a horizontal scroll. Return TRUE if the cursor moved, FALSE otherwise.
4454 gui_do_horiz_scroll()
4456 /* no wrapping, no scrolling */
4457 if (curwin
->w_p_wrap
)
4460 if ((long_u
)curwin
->w_leftcol
== scrollbar_value
)
4463 curwin
->w_leftcol
= (colnr_T
)scrollbar_value
;
4465 /* When the line of the cursor is too short, move the cursor to the
4466 * longest visible line. Do a sanity check on "longest_lnum", just in
4468 if (vim_strchr(p_go
, GO_HORSCROLL
) == NULL
4469 && longest_lnum
>= curwin
->w_topline
4470 && longest_lnum
< curwin
->w_botline
4471 && !virtual_active())
4473 if (scrollbar_value
> (long_u
)scroll_line_len(curwin
->w_cursor
.lnum
))
4475 curwin
->w_cursor
.lnum
= longest_lnum
;
4476 curwin
->w_cursor
.col
= 0;
4480 return leftcol_changed();
4484 * Check that none of the colors are the same as the background color
4489 if (gui
.norm_pixel
== gui
.back_pixel
|| gui
.norm_pixel
== INVALCOLOR
)
4491 gui_set_bg_color((char_u
*)"White");
4492 if (gui
.norm_pixel
== gui
.back_pixel
|| gui
.norm_pixel
== INVALCOLOR
)
4493 gui_set_fg_color((char_u
*)"Black");
4498 gui_set_fg_color(name
)
4501 gui
.norm_pixel
= gui_get_color(name
);
4502 hl_set_fg_color_name(vim_strsave(name
));
4506 gui_set_bg_color(name
)
4509 gui
.back_pixel
= gui_get_color(name
);
4510 hl_set_bg_color_name(vim_strsave(name
));
4514 * Allocate a color by name.
4515 * Returns INVALCOLOR and gives an error message when failed.
4525 t
= gui_mch_get_color(name
);
4528 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
4532 EMSG2(_("E254: Cannot allocate color %s"), name
);
4537 * Return the grey value of a color (range 0-255).
4540 gui_get_lightness(pixel
)
4543 long_u rgb
= gui_mch_get_rgb(pixel
);
4545 return (int)( (((rgb
>> 16) & 0xff) * 299)
4546 + (((rgb
>> 8) & 0xff) * 587)
4547 + ((rgb
& 0xff) * 114)) / 1000;
4550 #if defined(FEAT_GUI_X11) || defined(PROTO)
4552 gui_new_scrollbar_colors()
4556 /* Nothing to do if GUI hasn't started yet. */
4562 gui_mch_set_scrollbar_colors(&(wp
->w_scrollbars
[SBAR_LEFT
]));
4563 gui_mch_set_scrollbar_colors(&(wp
->w_scrollbars
[SBAR_RIGHT
]));
4565 gui_mch_set_scrollbar_colors(&gui
.bottom_sbar
);
4570 * Call this when focus has changed.
4573 gui_focus_change(in_focus
)
4577 * Skip this code to avoid drawing the cursor when debugging and switching
4578 * between the debugger window and gvim.
4581 gui
.in_focus
= in_focus
;
4582 out_flush(); /* make sure output has been written */
4583 gui_update_cursor(TRUE
, FALSE
);
4586 xim_set_focus(in_focus
);
4589 /* Put events in the input queue only when allowed.
4590 * ui_focus_change() isn't called directly, because it invokes
4591 * autocommands and that must not happen asynchronously. */
4592 if (!hold_gui_events
)
4597 bytes
[1] = KS_EXTRA
;
4598 bytes
[2] = in_focus
? (int)KE_FOCUSGAINED
: (int)KE_FOCUSLOST
;
4599 add_to_input_buf(bytes
, 3);
4605 * Called when the mouse moved (but not when dragging).
4608 gui_mouse_moved(x
, y
)
4615 /* Ignore this while still starting up. */
4616 if (!gui
.in_use
|| gui
.starting
)
4619 #ifdef FEAT_MOUSESHAPE
4620 /* Get window pointer, and update mouse shape as well. */
4624 /* Only handle this when 'mousefocus' set and ... */
4626 && !hold_gui_events
/* not holding events */
4627 && (State
& (NORMAL
|INSERT
))/* Normal/Visual/Insert mode */
4628 && State
!= HITRETURN
/* but not hit-return prompt */
4629 && msg_scrolled
== 0 /* no scrolled message */
4630 && !need_mouse_correct
/* not moving the pointer */
4631 && gui
.in_focus
) /* gvim in focus */
4633 /* Don't move the mouse when it's left or right of the Vim window */
4634 if (x
< 0 || x
> Columns
* gui
.char_width
)
4636 #ifndef FEAT_MOUSESHAPE
4639 if (wp
== curwin
|| wp
== NULL
)
4640 return; /* still in the same old window, or none at all */
4643 /* Ignore position in the tab pages line. */
4644 if (Y_2_ROW(y
) < tabline_height())
4649 * format a mouse click on status line input
4650 * ala gui_send_mouse_event(0, x, y, 0, 0);
4651 * Trick: Use a column number -1, so that get_pseudo_mouse_code() will
4652 * generate a K_LEFTMOUSE_NM key code.
4656 /* abort the current operator first */
4658 add_to_input_buf(st
, 1);
4663 st
[3] = (char_u
)MOUSE_LEFT
;
4664 fill_mouse_coord(st
+ 4,
4665 #ifdef FEAT_VERTSPLIT
4666 wp
->w_wincol
== 0 ? -1 : wp
->w_wincol
+ MOUSE_COLOFF
,
4670 wp
->w_height
+ W_WINROW(wp
));
4672 add_to_input_buf(st
, 8);
4673 st
[3] = (char_u
)MOUSE_RELEASE
;
4674 add_to_input_buf(st
, 8);
4676 /* Need to wake up the main loop */
4677 if (gtk_main_level() > 0)
4684 * Called when mouse should be moved to window with focus.
4692 need_mouse_correct
= FALSE
;
4694 if (!(gui
.in_use
&& p_mousef
))
4697 gui_mch_getmouse(&x
, &y
);
4698 /* Don't move the mouse when it's left or right of the Vim window */
4699 if (x
< 0 || x
> Columns
* gui
.char_width
)
4702 # ifdef FEAT_WINDOWS
4703 && Y_2_ROW(y
) >= tabline_height()
4707 if (wp
!= curwin
&& wp
!= NULL
) /* If in other than current window */
4709 validate_cline_row();
4710 gui_mch_setmouse((int)W_ENDCOL(curwin
) * gui
.char_width
- 3,
4711 (W_WINROW(curwin
) + curwin
->w_wrow
) * gui
.char_height
4712 + (gui
.char_height
) / 2);
4717 * Find window where the mouse pointer "y" coordinate is in.
4731 if (row
< 0 || col
< 0) /* before first window */
4733 wp
= mouse_find_win(&row
, &col
);
4734 # ifdef FEAT_MOUSESHAPE
4735 if (State
== HITRETURN
|| State
== ASKMORE
)
4737 if (Y_2_ROW(y
) >= msg_row
)
4738 update_mouseshape(SHAPE_IDX_MOREL
);
4740 update_mouseshape(SHAPE_IDX_MORE
);
4742 else if (row
> wp
->w_height
) /* below status line */
4743 update_mouseshape(SHAPE_IDX_CLINE
);
4744 # ifdef FEAT_VERTSPLIT
4745 else if (!(State
& CMDLINE
) && W_VSEP_WIDTH(wp
) > 0 && col
== wp
->w_width
4746 && (row
!= wp
->w_height
|| !stl_connected(wp
)) && msg_scrolled
== 0)
4747 update_mouseshape(SHAPE_IDX_VSEP
);
4749 else if (!(State
& CMDLINE
) && W_STATUS_HEIGHT(wp
) > 0
4750 && row
== wp
->w_height
&& msg_scrolled
== 0)
4751 update_mouseshape(SHAPE_IDX_STATUS
);
4753 update_mouseshape(-2);
4762 * ":gui" and ":gvim": Change from the terminal version to the GUI version.
4763 * File names may be given to redefine the args list.
4769 char_u
*arg
= eap
->arg
;
4772 * Check for "-f" argument: foreground, don't fork.
4773 * Also don't fork when started with "gvim -f".
4774 * Do fork when using "gui -b".
4775 * Note that Mac OS X will never fork on :gui since it can only fork on
4776 * startup right after scanning the command line.
4779 && (arg
[1] == 'f' || arg
[1] == 'b')
4780 && (arg
[2] == NUL
|| vim_iswhite(arg
[2])))
4782 gui
.dofork
= (arg
[1] == 'b');
4783 eap
->arg
= skipwhite(eap
->arg
+ 2);
4787 /* Clear the command. Needed for when forking+exiting, to avoid part
4788 * of the argument ending up after the shell prompt. */
4789 msg_clr_eos_force();
4792 if (!ends_excmd(*eap
->arg
))
4796 #if ((defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32) \
4797 || defined(FEAT_GUI_PHOTON)) && defined(FEAT_TOOLBAR) \
4798 || defined(FEAT_GUI_MACVIM)) || defined(PROTO)
4800 * This is shared between Athena, Motif and GTK.
4802 static void gfp_setname
__ARGS((char_u
*fname
, void *cookie
));
4805 * Callback function for do_in_runtimepath().
4808 gfp_setname(fname
, cookie
)
4812 char_u
*gfp_buffer
= cookie
;
4814 if (STRLEN(fname
) >= MAXPATHL
)
4817 STRCPY(gfp_buffer
, fname
);
4821 * Find the path of bitmap "name" with extension "ext" in 'runtimepath'.
4822 * Return FAIL for failure and OK if buffer[MAXPATHL] contains the result.
4825 gui_find_bitmap(name
, buffer
, ext
)
4830 if (STRLEN(name
) > MAXPATHL
- 14)
4832 vim_snprintf((char *)buffer
, MAXPATHL
, "bitmaps/%s.%s", name
, ext
);
4833 if (do_in_runtimepath(buffer
, FALSE
, gfp_setname
, buffer
) == FAIL
4839 # if !defined(HAVE_GTK2) || defined(PROTO)
4841 * Given the name of the "icon=" argument, try finding the bitmap file for the
4842 * icon. If it is an absolute path name, use it as it is. Otherwise append
4843 * "ext" and search for it in 'runtimepath'.
4844 * The result is put in "buffer[MAXPATHL]". If something fails "buffer"
4848 gui_find_iconfile(name
, buffer
, ext
)
4853 char_u buf
[MAXPATHL
+ 1];
4855 expand_env(name
, buffer
, MAXPATHL
);
4856 if (!mch_isFullName(buffer
) && gui_find_bitmap(buffer
, buf
, ext
) == OK
)
4857 STRCPY(buffer
, buf
);
4862 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(PROTO)
4870 else if (error_ga
.ga_data
!= NULL
)
4872 /* avoid putting up a message box with blanks only */
4873 for (p
= (char_u
*)error_ga
.ga_data
; *p
!= NUL
; ++p
)
4876 /* Truncate a very long message, it will go off-screen. */
4877 if (STRLEN(p
) > 2000)
4878 STRCPY(p
+ 2000 - 14, "...(truncated)");
4879 (void)do_dialog(VIM_ERROR
, (char_u
*)_("Error"),
4880 p
, (char_u
*)_("&Ok"), 1, NULL
);
4883 ga_clear(&error_ga
);
4888 #if defined(NO_CONSOLE_INPUT) || defined(PROTO)
4890 * Return TRUE if still starting up and there is no place to enter text.
4891 * For GTK and X11 we check if stderr is not a tty, which means we were
4892 * (probably) started from the desktop. Also check stdin, "vim >& file" does
4893 * allow typing on stdin.
4898 return ((!gui
.in_use
|| gui
.starting
)
4900 && !isatty(0) && !isatty(2)
4906 #if defined(FIND_REPLACE_DIALOG) || defined(FEAT_SUN_WORKSHOP) \
4907 || defined(NEED_GUI_UPDATE_SCREEN) \
4910 * Update the current window and the screen.
4918 /* Trigger CursorMoved if the cursor moved. */
4919 if (!finish_op
&& has_cursormoved()
4920 && !equalpos(last_cursormoved
, curwin
->w_cursor
))
4922 apply_autocmds(EVENT_CURSORMOVED
, NULL
, NULL
, FALSE
, curbuf
);
4923 last_cursormoved
= curwin
->w_cursor
;
4926 update_screen(0); /* may need to update the screen */
4928 out_flush(); /* make sure output has been written */
4929 gui_update_cursor(TRUE
, FALSE
);
4934 #if defined(FIND_REPLACE_DIALOG) || defined(PROTO)
4935 static void concat_esc
__ARGS((garray_T
*gap
, char_u
*text
, int what
));
4938 * Get the text to use in a find/replace dialog. Uses the last search pattern
4939 * if the argument is empty.
4940 * Returns an allocated string.
4943 get_find_dialog_text(arg
, wwordp
, mcasep
)
4945 int *wwordp
; /* return: TRUE if \< \> found */
4946 int *mcasep
; /* return: TRUE if \C found */
4951 text
= last_search_pat();
4956 text
= vim_strsave(text
);
4959 int len
= (int)STRLEN(text
);
4963 if (len
>= 2 && STRNCMP(text
, "\\V", 2) == 0)
4965 mch_memmove(text
, text
+ 2, (size_t)(len
- 1));
4969 /* Recognize "\c" and "\C" and remove. */
4970 if (len
>= 2 && *text
== '\\' && (text
[1] == 'c' || text
[1] == 'C'))
4972 *mcasep
= (text
[1] == 'C');
4973 mch_memmove(text
, text
+ 2, (size_t)(len
- 1));
4977 /* Recognize "\<text\>" and remove. */
4979 && STRNCMP(text
, "\\<", 2) == 0
4980 && STRNCMP(text
+ len
- 2, "\\>", 2) == 0)
4983 mch_memmove(text
, text
+ 2, (size_t)(len
- 4));
4984 text
[len
- 4] = NUL
;
4987 /* Recognize "\/" or "\?" and remove. */
4988 for (i
= 0; i
+ 1 < len
; ++i
)
4989 if (text
[i
] == '\\' && (text
[i
+ 1] == '/'
4990 || text
[i
+ 1] == '?'))
4992 mch_memmove(text
+ i
, text
+ i
+ 1, (size_t)(len
- i
));
5001 * Concatenate "text" to grow array "gap", escaping "what" with a backslash.
5004 concat_esc(gap
, text
, what
)
5009 while (*text
!= NUL
)
5012 int l
= (*mb_ptr2len
)(text
);
5017 ga_append(gap
, *text
++);
5022 ga_append(gap
, '\\');
5023 ga_append(gap
, *text
);
5029 * Handle the press of a button in the find-replace dialog.
5030 * Return TRUE when something was added to the input buffer.
5033 gui_do_findrepl(flags
, find_text
, repl_text
, down
)
5034 int flags
; /* one of FRD_REPLACE, FRD_FINDNEXT, etc. */
5037 int down
; /* Search downwards. */
5041 int type
= (flags
& FRD_TYPE_MASK
);
5043 regmatch_T regmatch
;
5044 int save_did_emsg
= did_emsg
;
5045 static int busy
= FALSE
;
5047 /* When the screen is being updated we should not change buffers and
5048 * windows structures, it may cause freed memory to be used. Also don't
5049 * do this recursively (pressing "Find" quickly several times. */
5050 if (updating_screen
|| busy
)
5053 /* refuse replace when text cannot be changed */
5054 if ((type
== FRD_REPLACE
|| type
== FRD_REPLACEALL
) && text_locked())
5059 ga_init2(&ga
, 1, 100);
5060 if (type
== FRD_REPLACEALL
)
5061 ga_concat(&ga
, (char_u
*)"%s/");
5063 ga_concat(&ga
, (char_u
*)"\\V");
5064 if (flags
& FRD_MATCH_CASE
)
5065 ga_concat(&ga
, (char_u
*)"\\C");
5067 ga_concat(&ga
, (char_u
*)"\\c");
5068 if (flags
& FRD_WHOLE_WORD
)
5069 ga_concat(&ga
, (char_u
*)"\\<");
5070 if (type
== FRD_REPLACEALL
|| down
)
5071 concat_esc(&ga
, find_text
, '/'); /* escape slashes */
5073 concat_esc(&ga
, find_text
, '?'); /* escape '?' */
5074 if (flags
& FRD_WHOLE_WORD
)
5075 ga_concat(&ga
, (char_u
*)"\\>");
5077 if (type
== FRD_REPLACEALL
)
5079 ga_concat(&ga
, (char_u
*)"/");
5080 /* escape / and \ */
5081 p
= vim_strsave_escaped(repl_text
, (char_u
*)"/\\");
5085 ga_concat(&ga
, (char_u
*)"/g");
5087 ga_append(&ga
, NUL
);
5089 if (type
== FRD_REPLACE
)
5091 /* Do the replacement when the text at the cursor matches. Thus no
5092 * replacement is done if the cursor was moved! */
5093 regmatch
.regprog
= vim_regcomp(ga
.ga_data
, RE_MAGIC
+ RE_STRING
);
5095 if (regmatch
.regprog
!= NULL
)
5097 p
= ml_get_cursor();
5098 if (vim_regexec_nl(®match
, p
, (colnr_T
)0)
5099 && regmatch
.startp
[0] == p
)
5101 /* Clear the command line to remove any old "No match"
5105 if (u_save_cursor() == OK
)
5107 /* A button was pressed thus undo should be synced. */
5110 del_bytes((long)(regmatch
.endp
[0] - regmatch
.startp
[0]),
5116 MSG(_("No match at cursor, finding next"));
5117 vim_free(regmatch
.regprog
);
5121 if (type
== FRD_REPLACEALL
)
5123 /* A button was pressed, thus undo should be synced. */
5125 do_cmdline_cmd(ga
.ga_data
);
5129 /* Search for the next match. */
5131 do_search(NULL
, down
? '/' : '?', ga
.ga_data
, 1L,
5132 SEARCH_MSG
+ SEARCH_MARK
, NULL
);
5133 msg_scroll
= i
; /* don't let an error message set msg_scroll */
5136 /* Don't want to pass did_emsg to other code, it may cause disabling
5137 * syntax HL if we were busy redrawing. */
5138 did_emsg
= save_did_emsg
;
5140 if (State
& (NORMAL
| INSERT
))
5142 gui_update_screen(); /* update the screen */
5143 msg_didout
= 0; /* overwrite any message */
5144 need_wait_return
= FALSE
; /* don't wait for return */
5147 vim_free(ga
.ga_data
);
5149 return (ga
.ga_len
> 0);
5154 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \
5155 || defined(FEAT_GUI_MSWIN) \
5156 || defined(FEAT_GUI_MAC) \
5158 || defined(FEAT_GUI_MACVIM)
5161 static void gui_wingoto_xy
__ARGS((int x
, int y
));
5164 * Jump to the window at specified point (x, y).
5167 gui_wingoto_xy(x
, y
)
5171 int row
= Y_2_ROW(y
);
5172 int col
= X_2_COL(x
);
5175 if (row
>= 0 && col
>= 0)
5177 wp
= mouse_find_win(&row
, &col
);
5178 if (wp
!= NULL
&& wp
!= curwin
)
5185 * Process file drop. Mouse cursor position, key modifiers, name of files
5186 * and count of files are given. Argument "fnames[count]" has full pathnames
5187 * of dropped files, they will be freed in this function, and caller can't use
5188 * fnames after call this function.
5191 gui_handle_drop(x
, y
, modifiers
, fnames
, count
)
5200 static int entered
= FALSE
;
5203 * This function is called by event handlers. Just in case we get a
5204 * second event before the first one is handled, ignore the second one.
5205 * Not sure if this can ever happen, just in case.
5212 * When the cursor is at the command line, add the file names to the
5213 * command line, don't edit the files.
5215 if (State
& CMDLINE
)
5217 shorten_filenames(fnames
, count
);
5218 for (i
= 0; i
< count
; ++i
)
5220 if (fnames
[i
] != NULL
)
5223 add_to_input_buf((char_u
*)" ", 1);
5225 /* We don't know what command is used thus we can't be sure
5226 * about which characters need to be escaped. Only escape the
5227 * most common ones. */
5228 # ifdef BACKSLASH_IN_FILENAME
5229 p
= vim_strsave_escaped(fnames
[i
], (char_u
*)" \t\"|");
5231 p
= vim_strsave_escaped(fnames
[i
], (char_u
*)"\\ \t\"|");
5234 add_to_input_buf_csi(p
, (int)STRLEN(p
));
5236 vim_free(fnames
[i
]);
5243 /* Go to the window under mouse cursor, then shorten given "fnames" by
5244 * current window, because a window can have local current dir. */
5245 # ifdef FEAT_WINDOWS
5246 gui_wingoto_xy(x
, y
);
5248 shorten_filenames(fnames
, count
);
5250 /* If Shift held down, remember the first item. */
5251 if ((modifiers
& MOUSE_SHIFT
) != 0)
5252 p
= vim_strsave(fnames
[0]);
5256 /* Handle the drop, :edit or :split to get to the file. This also
5257 * frees fnames[]. Skip this if there is only one item it's a
5258 * directory and Shift is held down. */
5259 if (count
== 1 && (modifiers
& MOUSE_SHIFT
) != 0
5260 && mch_isdir(fnames
[0]))
5262 vim_free(fnames
[0]);
5266 handle_drop(count
, fnames
, (modifiers
& MOUSE_CTRL
) != 0);
5268 /* If Shift held down, change to first file's directory. If the first
5269 * item is a directory, change to that directory (and let the explorer
5270 * plugin show the contents). */
5275 if (mch_chdir((char *)p
) == 0)
5276 shorten_fnames(TRUE
);
5278 else if (vim_chdirfile(p
) == OK
)
5279 shorten_fnames(TRUE
);
5283 /* Update the screen display */
5284 update_screen(NOT_VALID
);
5286 gui_update_menus(0);
5290 gui_update_cursor(FALSE
, FALSE
);