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 int un_maximize
= mustset
;
1413 if (!gui
.shell_created
)
1417 /* If not setting to a user specified size and maximized, calculate the
1418 * number of characters that fit in the maximized window. */
1419 if (!mustset
&& gui_mch_maximized())
1426 base_width
= gui_get_base_width();
1427 base_height
= gui_get_base_height();
1429 /* Remember the original window position. */
1430 gui_mch_get_winpos(&x
, &y
);
1432 #ifdef USE_SUN_WORKSHOP
1433 if (!mustset
&& usingSunWorkShop
1434 && workshop_get_width_height(&width
, &height
))
1436 Columns
= (width
- base_width
+ gui
.char_width
- 1) / gui
.char_width
;
1437 Rows
= (height
- base_height
+ gui
.char_height
- 1) / gui
.char_height
;
1442 width
= Columns
* gui
.char_width
+ base_width
;
1443 height
= Rows
* gui
.char_height
+ base_height
;
1448 gui_mch_get_screen_dimensions(&screen_w
, &screen_h
);
1449 if ((direction
& RESIZE_HOR
) && width
> screen_w
)
1451 Columns
= (screen_w
- base_width
) / gui
.char_width
;
1452 if (Columns
< MIN_COLUMNS
)
1453 Columns
= MIN_COLUMNS
;
1454 width
= Columns
* gui
.char_width
+ base_width
;
1459 if ((direction
& RESIZE_VERT
) && height
> screen_h
)
1461 Rows
= (screen_h
- base_height
) / gui
.char_height
;
1463 height
= Rows
* gui
.char_height
+ base_height
;
1469 if (did_adjust
== 2 || (width
+ gui
.char_width
>= screen_w
1470 && height
+ gui
.char_height
>= screen_h
))
1471 /* don't unmaximize if at maximum size */
1472 un_maximize
= FALSE
;
1475 gui
.num_cols
= Columns
;
1476 gui
.num_rows
= Rows
;
1478 min_width
= base_width
+ MIN_COLUMNS
* gui
.char_width
;
1479 min_height
= base_height
+ MIN_LINES
* gui
.char_height
;
1481 min_height
+= tabline_height() * gui
.char_height
;
1487 /* If the window size is smaller than the screen unmaximize the
1488 * window, otherwise resizing won't work. */
1489 gui_mch_get_screen_dimensions(&screen_w
, &screen_h
);
1490 if ((width
+ gui
.char_width
< screen_w
1491 || height
+ gui
.char_height
* 2 < screen_h
)
1492 && gui_mch_maximized())
1493 gui_mch_unmaximize();
1497 gui_mch_set_shellsize(width
, height
, min_width
, min_height
,
1498 base_width
, base_height
, direction
);
1500 if (fit_to_display
&& x
>= 0 && y
>= 0)
1502 /* Some window managers put the Vim window left of/above the screen.
1503 * Only change the position if it wasn't already negative before
1504 * (happens on MS-Windows with a secondary monitor). */
1506 if (gui_mch_get_winpos(&x
, &y
) == OK
&& (x
< 0 || y
< 0))
1507 gui_mch_set_winpos(x
< 0 ? 0 : x
, y
< 0 ? 0 : y
);
1510 gui_position_components(width
);
1511 gui_update_scrollbars(TRUE
);
1512 gui_reset_scroll_region();
1516 * Called when Rows and/or Columns has changed.
1521 gui_reset_scroll_region();
1525 * Make scroll region cover whole screen.
1528 gui_reset_scroll_region()
1530 gui
.scroll_region_top
= 0;
1531 gui
.scroll_region_bot
= gui
.num_rows
- 1;
1532 gui
.scroll_region_left
= 0;
1533 gui
.scroll_region_right
= gui
.num_cols
- 1;
1537 gui_start_highlight(mask
)
1540 if (mask
> HL_ALL
) /* highlight code */
1541 gui
.highlight_mask
= mask
;
1543 gui
.highlight_mask
|= mask
;
1547 gui_stop_highlight(mask
)
1550 if (mask
> HL_ALL
) /* highlight code */
1551 gui
.highlight_mask
= HL_NORMAL
;
1553 gui
.highlight_mask
&= ~mask
;
1557 * Clear a rectangular region of the screen from text pos (row1, col1) to
1558 * (row2, col2) inclusive.
1561 gui_clear_block(row1
, col1
, row2
, col2
)
1567 /* Clear the selection if we are about to write over it */
1568 clip_may_clear_selection(row1
, row2
);
1570 gui_mch_clear_block(row1
, col1
, row2
, col2
);
1572 /* Invalidate cursor if it was in this block */
1573 if ( gui
.cursor_row
>= row1
&& gui
.cursor_row
<= row2
1574 && gui
.cursor_col
>= col1
&& gui
.cursor_col
<= col2
)
1575 gui
.cursor_is_valid
= FALSE
;
1579 * Write code to update the cursor later. This avoids the need to flush the
1580 * output buffer before calling gui_update_cursor().
1583 gui_update_cursor_later()
1585 OUT_STR(IF_EB("\033|s", ESC_STR
"|s"));
1594 int arg1
= 0, arg2
= 0;
1595 /* this doesn't make sense, disabled until someone can explain why it
1596 * would be needed */
1597 #if 0 && (defined(RISCOS) || defined(WIN16))
1598 int force_cursor
= TRUE
; /* JK230798, stop Vim being smart or
1599 our redraw speed will suffer */
1601 int force_cursor
= FALSE
; /* force cursor update */
1603 int force_scrollbar
= FALSE
;
1604 static win_T
*old_curwin
= NULL
;
1606 /* #define DEBUG_GUI_WRITE */
1607 #ifdef DEBUG_GUI_WRITE
1612 printf("gui_write(%d):\n ", len
);
1613 for (i
= 0; i
< len
; i
++)
1622 str
= transchar_byte(s
[i
]);
1623 if (str
[0] && str
[1])
1624 printf("<%s>", (char *)str
);
1626 printf("%s", (char *)str
);
1633 if (s
[0] == ESC
&& s
[1] == '|')
1636 if (VIM_ISDIGIT(*p
))
1638 arg1
= getdigits(&p
);
1644 arg2
= getdigits(&p
);
1651 case 'C': /* Clear screen */
1652 clip_scroll_selection(9999);
1653 gui_mch_clear_all();
1654 gui
.cursor_is_valid
= FALSE
;
1655 force_scrollbar
= TRUE
;
1657 case 'M': /* Move cursor */
1658 gui_set_cursor(arg1
, arg2
);
1660 case 's': /* force cursor (shape) update */
1661 force_cursor
= TRUE
;
1663 case 'R': /* Set scroll region */
1666 gui
.scroll_region_top
= arg1
;
1667 gui
.scroll_region_bot
= arg2
;
1671 gui
.scroll_region_top
= arg2
;
1672 gui
.scroll_region_bot
= arg1
;
1675 #ifdef FEAT_VERTSPLIT
1676 case 'V': /* Set vertical scroll region */
1679 gui
.scroll_region_left
= arg1
;
1680 gui
.scroll_region_right
= arg2
;
1684 gui
.scroll_region_left
= arg2
;
1685 gui
.scroll_region_right
= arg1
;
1689 case 'd': /* Delete line */
1690 gui_delete_lines(gui
.row
, 1);
1692 case 'D': /* Delete lines */
1693 gui_delete_lines(gui
.row
, arg1
);
1695 case 'i': /* Insert line */
1696 gui_insert_lines(gui
.row
, 1);
1698 case 'I': /* Insert lines */
1699 gui_insert_lines(gui
.row
, arg1
);
1701 case '$': /* Clear to end-of-line */
1702 gui_clear_block(gui
.row
, gui
.col
, gui
.row
,
1705 case 'h': /* Turn on highlighting */
1706 gui_start_highlight(arg1
);
1708 case 'H': /* Turn off highlighting */
1709 gui_stop_highlight(arg1
);
1711 case 'f': /* flash the window (visual bell) */
1712 gui_mch_flash(arg1
== 0 ? 20 : arg1
);
1715 p
= s
+ 1; /* Skip the ESC */
1718 len
-= (int)(++p
- s
);
1723 CtrlChar(s
[0]) != 0 /* Ctrl character */
1725 s
[0] < 0x20 /* Ctrl character */
1727 #ifdef FEAT_SIGN_ICONS
1728 && s
[0] != SIGN_BYTE
1729 # ifdef FEAT_NETBEANS_INTG
1730 && s
[0] != MULTISIGN_BYTE
1735 if (s
[0] == '\n') /* NL */
1738 if (gui
.row
< gui
.scroll_region_bot
)
1741 gui_delete_lines(gui
.scroll_region_top
, 1);
1743 else if (s
[0] == '\r') /* CR */
1747 else if (s
[0] == '\b') /* Backspace */
1752 else if (s
[0] == Ctrl_L
) /* cursor-right */
1756 else if (s
[0] == Ctrl_G
) /* Beep */
1760 /* Other Ctrl character: shouldn't happen! */
1762 --len
; /* Skip this char */
1774 #ifdef FEAT_SIGN_ICONS
1776 # ifdef FEAT_NETBEANS_INTG
1777 || *p
== MULTISIGN_BYTE
1785 gui_outstr(s
, (int)(p
- s
));
1790 /* Postponed update of the cursor (won't work if "can_update_cursor" isn't
1793 gui_update_cursor(TRUE
, TRUE
);
1795 /* When switching to another window the dragging must have stopped.
1796 * Required for GTK, dragged_sb isn't reset. */
1797 if (old_curwin
!= curwin
)
1798 gui
.dragged_sb
= SBAR_NONE
;
1800 /* Update the scrollbars after clearing the screen or when switched
1801 * to another window.
1802 * Update the horizontal scrollbar always, it's difficult to check all
1803 * situations where it might change. */
1804 if (force_scrollbar
|| old_curwin
!= curwin
)
1805 gui_update_scrollbars(force_scrollbar
);
1807 gui_update_horiz_scrollbar(FALSE
);
1808 old_curwin
= curwin
;
1811 * We need to make sure this is cleared since Athena doesn't tell us when
1812 * he is done dragging. Do the same for GTK.
1814 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_GTK)
1815 gui
.dragged_sb
= SBAR_NONE
;
1818 gui_mch_flush(); /* In case vim decides to take a nap */
1822 * When ScreenLines[] is invalid, updating the cursor should not be done, it
1823 * produces wrong results. Call gui_dont_update_cursor() before that code and
1824 * gui_can_update_cursor() afterwards.
1827 gui_dont_update_cursor()
1831 /* Undraw the cursor now, we probably can't do it after the change. */
1832 gui_undraw_cursor();
1833 can_update_cursor
= FALSE
;
1838 gui_can_update_cursor()
1840 can_update_cursor
= TRUE
;
1841 /* No need to update the cursor right now, there is always more output
1842 * after scrolling. */
1859 len
= (int)STRLEN(s
);
1866 /* Find out how many chars fit in the current line. */
1868 for (this_len
= 0; this_len
< len
; )
1870 cells
+= (*mb_ptr2cells
)(s
+ this_len
);
1871 if (gui
.col
+ cells
> Columns
)
1873 this_len
+= (*mb_ptr2len
)(s
+ this_len
);
1876 this_len
= len
; /* don't include following composing char */
1880 if (gui
.col
+ len
> Columns
)
1881 this_len
= Columns
- gui
.col
;
1885 (void)gui_outstr_nowrap(s
, this_len
,
1886 0, (guicolor_T
)0, (guicolor_T
)0, 0);
1890 /* fill up for a double-width char that doesn't fit. */
1891 if (len
> 0 && gui
.col
< Columns
)
1892 (void)gui_outstr_nowrap((char_u
*)" ", 1,
1893 0, (guicolor_T
)0, (guicolor_T
)0, 0);
1895 /* The cursor may wrap to the next line. */
1896 if (gui
.col
>= Columns
)
1905 * Output one character (may be one or two display cells).
1906 * Caller must check for valid "off".
1907 * Returns FAIL or OK, just like gui_outstr_nowrap().
1910 gui_screenchar(off
, flags
, fg
, bg
, back
)
1911 int off
; /* Offset from start of screen */
1913 guicolor_T fg
, bg
; /* colors for cursor */
1914 int back
; /* backup this many chars when using bold trick */
1917 char_u buf
[MB_MAXBYTES
+ 1];
1919 /* Don't draw right halve of a double-width UTF-8 char. "cannot happen" */
1920 if (enc_utf8
&& ScreenLines
[off
] == 0)
1923 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
1924 /* Draw UTF-8 multi-byte character. */
1925 return gui_outstr_nowrap(buf
, utfc_char2bytes(off
, buf
),
1926 flags
, fg
, bg
, back
);
1928 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
1930 buf
[0] = ScreenLines
[off
];
1931 buf
[1] = ScreenLines2
[off
];
1932 return gui_outstr_nowrap(buf
, 2, flags
, fg
, bg
, back
);
1935 /* Draw non-multi-byte character or DBCS character. */
1936 return gui_outstr_nowrap(ScreenLines
+ off
,
1937 enc_dbcs
? (*mb_ptr2len
)(ScreenLines
+ off
) : 1,
1938 flags
, fg
, bg
, back
);
1940 return gui_outstr_nowrap(ScreenLines
+ off
, 1, flags
, fg
, bg
, back
);
1946 * Output the string at the given screen position. This is used in place
1947 * of gui_screenchar() where possible because Pango needs as much context
1948 * as possible to work nicely. It's a lot faster as well.
1951 gui_screenstr(off
, len
, flags
, fg
, bg
, back
)
1952 int off
; /* Offset from start of screen */
1953 int len
; /* string length in screen cells */
1955 guicolor_T fg
, bg
; /* colors for cursor */
1956 int back
; /* backup this many chars when using bold trick */
1963 if (len
<= 0) /* "cannot happen"? */
1968 buf
= alloc((unsigned)(len
* MB_MAXBYTES
+ 1));
1970 return OK
; /* not much we could do here... */
1972 for (i
= off
; i
< off
+ len
; ++i
)
1974 if (ScreenLines
[i
] == 0)
1975 continue; /* skip second half of double-width char */
1977 if (ScreenLinesUC
[i
] == 0)
1978 buf
[outlen
++] = ScreenLines
[i
];
1980 outlen
+= utfc_char2bytes(i
, buf
+ outlen
);
1983 buf
[outlen
] = NUL
; /* only to aid debugging */
1984 retval
= gui_outstr_nowrap(buf
, outlen
, flags
, fg
, bg
, back
);
1989 else if (enc_dbcs
== DBCS_JPNU
)
1991 buf
= alloc((unsigned)(len
* 2 + 1));
1993 return OK
; /* not much we could do here... */
1995 for (i
= off
; i
< off
+ len
; ++i
)
1997 buf
[outlen
++] = ScreenLines
[i
];
1999 /* handle double-byte single-width char */
2000 if (ScreenLines
[i
] == 0x8e)
2001 buf
[outlen
++] = ScreenLines2
[i
];
2002 else if (MB_BYTE2LEN(ScreenLines
[i
]) == 2)
2003 buf
[outlen
++] = ScreenLines
[++i
];
2006 buf
[outlen
] = NUL
; /* only to aid debugging */
2007 retval
= gui_outstr_nowrap(buf
, outlen
, flags
, fg
, bg
, back
);
2014 return gui_outstr_nowrap(&ScreenLines
[off
], len
,
2015 flags
, fg
, bg
, back
);
2018 #endif /* HAVE_GTK2 */
2021 * Output the given string at the current cursor position. If the string is
2022 * too long to fit on the line, then it is truncated.
2024 * GUI_MON_IS_CURSOR should only be used when this function is being called to
2025 * actually draw (an inverted) cursor.
2026 * GUI_MON_TRS_CURSOR is used to draw the cursor text with a transparent
2028 * GUI_MON_NOCLEAR is used to avoid clearing the selection when drawing over
2030 * Returns OK, unless "back" is non-zero and using the bold trick, then return
2031 * FAIL (the caller should start drawing "back" chars back).
2034 gui_outstr_nowrap(s
, len
, flags
, fg
, bg
, back
)
2038 guicolor_T fg
, bg
; /* colors for cursor */
2039 int back
; /* backup this many chars when using bold trick */
2041 long_u highlight_mask
;
2042 long_u hl_mask_todo
;
2043 guicolor_T fg_color
;
2044 guicolor_T bg_color
;
2045 guicolor_T sp_color
;
2046 #if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2)
2047 GuiFont font
= NOFONT
;
2048 # ifdef FEAT_XFONTSET
2049 GuiFontset fontset
= NOFONTSET
;
2052 attrentry_T
*aep
= NULL
;
2055 #ifdef FEAT_SIGN_ICONS
2056 int draw_sign
= FALSE
;
2057 # ifdef FEAT_NETBEANS_INTG
2058 int multi_sign
= FALSE
;
2063 len
= (int)STRLEN(s
);
2067 #ifdef FEAT_SIGN_ICONS
2069 # ifdef FEAT_NETBEANS_INTG
2070 || *s
== MULTISIGN_BYTE
2074 # ifdef FEAT_NETBEANS_INTG
2075 if (*s
== MULTISIGN_BYTE
)
2078 /* draw spaces instead */
2080 if (len
== 1 && col
> 0)
2088 if (gui
.highlight_mask
> HL_ALL
)
2090 aep
= syn_gui_attr2entry(gui
.highlight_mask
);
2091 if (aep
== NULL
) /* highlighting not set */
2094 highlight_mask
= aep
->ae_attr
;
2097 highlight_mask
= gui
.highlight_mask
;
2098 hl_mask_todo
= highlight_mask
;
2100 #if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2)
2102 if (aep
!= NULL
&& aep
->ae_u
.gui
.font
!= NOFONT
)
2103 font
= aep
->ae_u
.gui
.font
;
2104 # ifdef FEAT_XFONTSET
2105 else if (aep
!= NULL
&& aep
->ae_u
.gui
.fontset
!= NOFONTSET
)
2106 fontset
= aep
->ae_u
.gui
.fontset
;
2110 # ifdef FEAT_XFONTSET
2111 if (gui
.fontset
!= NOFONTSET
)
2112 fontset
= gui
.fontset
;
2115 if (hl_mask_todo
& (HL_BOLD
| HL_STANDOUT
))
2117 if ((hl_mask_todo
& HL_ITALIC
) && gui
.boldital_font
!= NOFONT
)
2119 font
= gui
.boldital_font
;
2120 hl_mask_todo
&= ~(HL_BOLD
| HL_STANDOUT
| HL_ITALIC
);
2122 else if (gui
.bold_font
!= NOFONT
)
2124 font
= gui
.bold_font
;
2125 hl_mask_todo
&= ~(HL_BOLD
| HL_STANDOUT
);
2128 font
= gui
.norm_font
;
2130 else if ((hl_mask_todo
& HL_ITALIC
) && gui
.ital_font
!= NOFONT
)
2132 font
= gui
.ital_font
;
2133 hl_mask_todo
&= ~HL_ITALIC
;
2136 font
= gui
.norm_font
;
2138 # ifdef FEAT_XFONTSET
2139 if (fontset
!= NOFONTSET
)
2140 gui_mch_set_fontset(fontset
);
2143 gui_mch_set_font(font
);
2149 bg_color
= gui
.back_pixel
;
2150 if ((flags
& GUI_MON_IS_CURSOR
) && gui
.in_focus
)
2152 draw_flags
|= DRAW_CURSOR
;
2157 else if (aep
!= NULL
)
2159 fg_color
= aep
->ae_u
.gui
.fg_color
;
2160 if (fg_color
== INVALCOLOR
)
2161 fg_color
= gui
.norm_pixel
;
2162 bg_color
= aep
->ae_u
.gui
.bg_color
;
2163 if (bg_color
== INVALCOLOR
)
2164 bg_color
= gui
.back_pixel
;
2165 sp_color
= aep
->ae_u
.gui
.sp_color
;
2166 if (sp_color
== INVALCOLOR
)
2167 sp_color
= fg_color
;
2171 fg_color
= gui
.norm_pixel
;
2172 sp_color
= fg_color
;
2175 if (highlight_mask
& (HL_INVERSE
| HL_STANDOUT
))
2177 #if defined(AMIGA) || defined(RISCOS)
2178 gui_mch_set_colors(bg_color
, fg_color
);
2180 gui_mch_set_fg_color(bg_color
);
2181 gui_mch_set_bg_color(fg_color
);
2186 #if defined(AMIGA) || defined(RISCOS)
2187 gui_mch_set_colors(fg_color
, bg_color
);
2189 gui_mch_set_fg_color(fg_color
);
2190 gui_mch_set_bg_color(bg_color
);
2193 gui_mch_set_sp_color(sp_color
);
2195 /* Clear the selection if we are about to write over it */
2196 if (!(flags
& GUI_MON_NOCLEAR
))
2197 clip_may_clear_selection(gui
.row
, gui
.row
);
2200 #ifndef MSWIN16_FASTTEXT
2201 /* If there's no bold font, then fake it */
2202 if (hl_mask_todo
& (HL_BOLD
| HL_STANDOUT
))
2203 draw_flags
|= DRAW_BOLD
;
2207 * When drawing bold or italic characters the spill-over from the left
2208 * neighbor may be destroyed. Let the caller backup to start redrawing
2209 * just after a blank.
2211 if (back
!= 0 && ((draw_flags
& DRAW_BOLD
) || (highlight_mask
& HL_ITALIC
)))
2214 #if defined(RISCOS) || defined(HAVE_GTK2) || defined(FEAT_GUI_MACVIM)
2215 /* If there's no italic font, then fake it.
2216 * For GTK2, we don't need a different font for italic style. */
2217 if (hl_mask_todo
& HL_ITALIC
)
2218 draw_flags
|= DRAW_ITALIC
;
2220 /* Do we underline the text? */
2221 if (hl_mask_todo
& HL_UNDERLINE
)
2222 draw_flags
|= DRAW_UNDERL
;
2224 /* Do we underline the text? */
2225 if ((hl_mask_todo
& HL_UNDERLINE
)
2226 # ifndef MSWIN16_FASTTEXT
2227 || (hl_mask_todo
& HL_ITALIC
)
2230 draw_flags
|= DRAW_UNDERL
;
2232 /* Do we undercurl the text? */
2233 if (hl_mask_todo
& HL_UNDERCURL
)
2234 draw_flags
|= DRAW_UNDERC
;
2236 /* Do we draw transparently? */
2237 if (flags
& GUI_MON_TRS_CURSOR
)
2238 draw_flags
|= DRAW_TRANSP
;
2244 /* The value returned is the length in display cells */
2245 len
= gui_gtk2_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2248 # ifdef FEAT_GUI_MACVIM
2249 if (use_gui_macvim_draw_string
)
2251 /* The value returned is the length in display cells */
2252 len
= gui_macvim_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2258 int start
; /* index of bytes to be drawn */
2259 int cells
; /* cellwidth of bytes to be drawn */
2260 int thislen
; /* length of bytes to be drawin */
2261 int cn
; /* cellwidth of current char */
2262 int i
; /* index of current char */
2263 int c
; /* current char value */
2264 int cl
; /* byte length of current char */
2265 int comping
; /* current char is composing */
2266 int scol
= col
; /* screen column */
2267 int dowide
; /* use 'guifontwide' */
2269 /* Break the string at a composing character, it has to be drawn on
2270 * top of the previous character. */
2273 for (i
= 0; i
< len
; i
+= cl
)
2275 c
= utf_ptr2char(s
+ i
);
2276 cn
= utf_char2cells(c
);
2277 comping
= utf_iscomposing(c
);
2278 if (!comping
) /* count cells from non-composing chars */
2280 cl
= utf_ptr2len(s
+ i
);
2281 if (cl
== 0) /* hit end of string */
2282 len
= i
+ cl
; /* len must be wrong "cannot happen" */
2284 # ifdef FEAT_GUI_MACVIM
2288 # ifdef FEAT_XFONTSET
2289 && fontset
== NOFONTSET
2291 && gui
.wide_font
!= NOFONT
)
2297 /* print the string so far if it's the last character or there is
2298 * a composing character. */
2299 if (i
+ cl
>= len
|| (comping
&& i
> start
) || dowide
2300 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
2302 # ifdef FEAT_XFONTSET
2303 /* No fontset: At least draw char after wide char at
2304 * right position. */
2305 && fontset
== NOFONTSET
2311 if (comping
|| dowide
)
2312 thislen
= i
- start
;
2314 thislen
= i
- start
+ cl
;
2317 gui_mch_draw_string(gui
.row
, scol
, s
+ start
, thislen
,
2318 # ifdef FEAT_GUI_MACVIM
2328 gui_mch_set_font(gui
.wide_font
);
2329 gui_mch_draw_string(gui
.row
, scol
- cn
, s
+ start
, cl
,
2330 # ifdef FEAT_GUI_MACVIM
2333 draw_flags
| DRAW_WIDE
);
2334 gui_mch_set_font(font
);
2338 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
2339 /* No fontset: draw a space to fill the gap after a wide char
2341 if (cn
> 1 && (draw_flags
& DRAW_TRANSP
) == 0
2342 # ifdef FEAT_XFONTSET
2343 && fontset
== NOFONTSET
2346 gui_mch_draw_string(gui
.row
, scol
- 1, (char_u
*)" ",
2350 /* Draw a composing char on top of the previous char. */
2353 # if !defined(FEAT_GUI_MACVIM) && \
2354 (defined(__APPLE_CC__) || defined(__MRC__)) && TARGET_API_MAC_CARBON
2355 /* Carbon ATSUI autodraws composing char over previous char */
2356 gui_mch_draw_string(gui
.row
, scol
, s
+ i
, cl
,
2357 draw_flags
| DRAW_TRANSP
);
2359 gui_mch_draw_string(gui
.row
, scol
- cn
, s
+ i
, cl
,
2360 # ifdef FEAT_GUI_MACVIM
2363 draw_flags
| DRAW_TRANSP
| DRAW_COMP
);
2368 /* The stuff below assumes "len" is the length in screen columns. */
2374 gui_mch_draw_string(gui
.row
, col
, s
, len
,
2375 # ifdef FEAT_GUI_MACVIM
2380 if (enc_dbcs
== DBCS_JPNU
)
2385 /* Get the length in display cells, this can be different from the
2386 * number of bytes for "euc-jp". */
2387 for (i
= 0; i
< len
; i
+= (*mb_ptr2len
)(s
+ i
))
2388 clen
+= (*mb_ptr2cells
)(s
+ i
);
2393 #endif /* !HAVE_GTK2 */
2395 if (!(flags
& (GUI_MON_IS_CURSOR
| GUI_MON_TRS_CURSOR
)))
2396 gui
.col
= col
+ len
;
2398 /* May need to invert it when it's part of the selection. */
2399 if (flags
& GUI_MON_NOCLEAR
)
2400 clip_may_redraw_selection(gui
.row
, col
, len
);
2402 if (!(flags
& (GUI_MON_IS_CURSOR
| GUI_MON_TRS_CURSOR
)))
2404 /* Invalidate the old physical cursor position if we wrote over it */
2405 if (gui
.cursor_row
== gui
.row
2406 && gui
.cursor_col
>= col
2407 && gui
.cursor_col
< col
+ len
)
2408 gui
.cursor_is_valid
= FALSE
;
2411 #ifdef FEAT_SIGN_ICONS
2413 /* Draw the sign on top of the spaces. */
2414 gui_mch_drawsign(gui
.row
, col
, gui
.highlight_mask
);
2415 # ifdef FEAT_NETBEANS_INTG
2417 netbeans_draw_multisign_indicator(gui
.row
);
2425 * Un-draw the cursor. Actually this just redraws the character at the given
2426 * position. The character just before it too, for when it was in bold.
2431 if (gui
.cursor_is_valid
)
2433 #ifdef FEAT_HANGULIN
2434 if (composing_hangul
2435 && gui
.col
== gui
.cursor_col
&& gui
.row
== gui
.cursor_row
)
2436 (void)gui_outstr_nowrap(composing_hangul_buffer
, 2,
2437 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
,
2438 gui
.norm_pixel
, gui
.back_pixel
, 0);
2442 if (gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
,
2443 gui
.cursor_row
, gui
.cursor_col
, GUI_MON_NOCLEAR
)
2444 && gui
.cursor_col
> 0)
2445 (void)gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
- 1,
2446 gui
.cursor_row
, gui
.cursor_col
- 1, GUI_MON_NOCLEAR
);
2447 #ifdef FEAT_HANGULIN
2448 if (composing_hangul
)
2449 (void)gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
+ 1,
2450 gui
.cursor_row
, gui
.cursor_col
+ 1, GUI_MON_NOCLEAR
);
2453 /* Cursor_is_valid is reset when the cursor is undrawn, also reset it
2454 * here in case it wasn't needed to undraw it. */
2455 gui
.cursor_is_valid
= FALSE
;
2460 gui_redraw(x
, y
, w
, h
)
2466 int row1
, col1
, row2
, col2
;
2470 row2
= Y_2_ROW(y
+ h
- 1);
2471 col2
= X_2_COL(x
+ w
- 1);
2473 (void)gui_redraw_block(row1
, col1
, row2
, col2
, GUI_MON_NOCLEAR
);
2476 * We may need to redraw the cursor, but don't take it upon us to change
2477 * its location after a scroll.
2478 * (maybe be more strict even and test col too?)
2479 * These things may be outside the update/clipping region and reality may
2480 * not reflect Vims internal ideas if these operations are clipped away.
2482 if (gui
.row
== gui
.cursor_row
)
2483 gui_update_cursor(TRUE
, TRUE
);
2487 * Draw a rectangular block of characters, from row1 to row2 (inclusive) and
2488 * from col1 to col2 (inclusive).
2489 * Return TRUE when the character before the first drawn character has
2490 * different attributes (may have to be redrawn too).
2493 gui_redraw_block(row1
, col1
, row2
, col2
, flags
)
2498 int flags
; /* flags for gui_outstr_nowrap() */
2500 int old_row
, old_col
;
2508 int orig_col1
, orig_col2
;
2511 /* Don't try to update when ScreenLines is not valid */
2512 if (!screen_cleared
|| ScreenLines
== NULL
)
2515 /* Don't try to draw outside the shell! */
2516 /* Check everything, strange values may be caused by a big border width */
2517 col1
= check_col(col1
);
2518 col2
= check_col(col2
);
2519 row1
= check_row(row1
);
2520 row2
= check_row(row2
);
2522 /* Remember where our cursor was */
2525 old_hl_mask
= gui
.highlight_mask
;
2531 for (gui
.row
= row1
; gui
.row
<= row2
; gui
.row
++)
2534 /* When only half of a double-wide character is in the block, include
2535 * the other half. */
2538 off
= LineOffset
[gui
.row
];
2542 col1
-= dbcs_screen_head_off(ScreenLines
+ off
,
2543 ScreenLines
+ off
+ col1
);
2544 col2
+= dbcs_screen_tail_off(ScreenLines
+ off
,
2545 ScreenLines
+ off
+ col2
);
2549 if (ScreenLines
[off
+ col1
] == 0)
2552 if (col2
+ 1 < Columns
&& ScreenLines
[off
+ col2
+ 1] == 0)
2558 off
= LineOffset
[gui
.row
] + gui
.col
;
2559 len
= col2
- col1
+ 1;
2561 /* Find how many chars back this highlighting starts, or where a space
2562 * is. Needed for when the bold trick is used */
2563 for (back
= 0; back
< col1
; ++back
)
2564 if (ScreenAttrs
[off
- 1 - back
] != ScreenAttrs
[off
]
2565 || ScreenLines
[off
- 1 - back
] == ' ')
2567 retval
= (col1
> 0 && ScreenAttrs
[off
- 1] != 0 && back
== 0
2568 && ScreenLines
[off
- 1] != ' ');
2570 /* Break it up in strings of characters with the same attributes. */
2571 /* Print UTF-8 characters individually. */
2574 first_attr
= ScreenAttrs
[off
];
2575 gui
.highlight_mask
= first_attr
;
2576 #if defined(FEAT_MBYTE) && !defined(HAVE_GTK2)
2577 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
2579 /* output multi-byte character separately */
2580 nback
= gui_screenchar(off
, flags
,
2581 (guicolor_T
)0, (guicolor_T
)0, back
);
2582 if (gui
.col
< Columns
&& ScreenLines
[off
+ 1] == 0)
2587 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
2589 /* output double-byte, single-width character separately */
2590 nback
= gui_screenchar(off
, flags
,
2591 (guicolor_T
)0, (guicolor_T
)0, back
);
2598 for (idx
= 0; idx
< len
; ++idx
)
2600 if (enc_utf8
&& ScreenLines
[off
+ idx
] == 0)
2601 continue; /* skip second half of double-width char */
2602 if (ScreenAttrs
[off
+ idx
] != first_attr
)
2605 /* gui_screenstr() takes care of multibyte chars */
2606 nback
= gui_screenstr(off
, idx
, flags
,
2607 (guicolor_T
)0, (guicolor_T
)0, back
);
2609 for (idx
= 0; idx
< len
&& ScreenAttrs
[off
+ idx
] == first_attr
;
2613 /* Stop at a multi-byte Unicode character. */
2614 if (enc_utf8
&& ScreenLinesUC
[off
+ idx
] != 0)
2616 if (enc_dbcs
== DBCS_JPNU
)
2618 /* Stop at a double-byte single-width char. */
2619 if (ScreenLines
[off
+ idx
] == 0x8e)
2621 if (len
> 1 && (*mb_ptr2len
)(ScreenLines
2623 ++idx
; /* skip second byte of double-byte char */
2627 nback
= gui_outstr_nowrap(ScreenLines
+ off
, idx
, flags
,
2628 (guicolor_T
)0, (guicolor_T
)0, back
);
2633 /* Must back up to start drawing where a bold or italic word
2648 /* Put the cursor back where it was */
2651 gui
.highlight_mask
= (int)old_hl_mask
;
2657 gui_delete_lines(row
, count
)
2664 if (row
+ count
> gui
.scroll_region_bot
)
2665 /* Scrolled out of region, just blank the lines out */
2666 gui_clear_block(row
, gui
.scroll_region_left
,
2667 gui
.scroll_region_bot
, gui
.scroll_region_right
);
2670 gui_mch_delete_lines(row
, count
);
2672 /* If the cursor was in the deleted lines it's now gone. If the
2673 * cursor was in the scrolled lines adjust its position. */
2674 if (gui
.cursor_row
>= row
2675 && gui
.cursor_col
>= gui
.scroll_region_left
2676 && gui
.cursor_col
<= gui
.scroll_region_right
)
2678 if (gui
.cursor_row
< row
+ count
)
2679 gui
.cursor_is_valid
= FALSE
;
2680 else if (gui
.cursor_row
<= gui
.scroll_region_bot
)
2681 gui
.cursor_row
-= count
;
2687 gui_insert_lines(row
, count
)
2694 if (row
+ count
> gui
.scroll_region_bot
)
2695 /* Scrolled out of region, just blank the lines out */
2696 gui_clear_block(row
, gui
.scroll_region_left
,
2697 gui
.scroll_region_bot
, gui
.scroll_region_right
);
2700 gui_mch_insert_lines(row
, count
);
2702 if (gui
.cursor_row
>= gui
.row
2703 && gui
.cursor_col
>= gui
.scroll_region_left
2704 && gui
.cursor_col
<= gui
.scroll_region_right
)
2706 if (gui
.cursor_row
<= gui
.scroll_region_bot
- count
)
2707 gui
.cursor_row
+= count
;
2708 else if (gui
.cursor_row
<= gui
.scroll_region_bot
)
2709 gui
.cursor_is_valid
= FALSE
;
2715 * The main GUI input routine. Waits for a character from the keyboard.
2716 * wtime == -1 Wait forever.
2717 * wtime == 0 Don't wait.
2718 * wtime > 0 Wait wtime milliseconds for a character.
2719 * Returns OK if a character was found to be available within the given time,
2720 * or FAIL otherwise.
2723 gui_wait_for_chars(wtime
)
2729 * If we're going to wait a bit, update the menus and mouse shape for the
2735 gui_update_menus(0);
2740 if (input_available()) /* Got char, return immediately */
2742 if (wtime
== 0) /* Don't wait for char */
2745 /* Before waiting, flush any output to the screen. */
2750 /* Blink when waiting for a character. Probably only does something
2751 * for showmatch() */
2752 gui_mch_start_blink();
2753 retval
= gui_mch_wait_for_chars(wtime
);
2754 gui_mch_stop_blink();
2759 * While we are waiting indefinitely for a character, blink the cursor.
2761 gui_mch_start_blink();
2765 * We may want to trigger the CursorHold event. First wait for
2766 * 'updatetime' and if nothing is typed within that time put the
2767 * K_CURSORHOLD key in the input buffer.
2769 if (gui_mch_wait_for_chars(p_ut
) == OK
)
2772 else if (trigger_cursorhold())
2776 /* Put K_CURSORHOLD in the input buffer. */
2779 buf
[2] = (int)KE_CURSORHOLD
;
2780 add_to_input_buf(buf
, 3);
2788 /* Blocking wait. */
2790 retval
= gui_mch_wait_for_chars(-1L);
2793 gui_mch_stop_blink();
2798 * Fill p[4] with mouse coordinates encoded for check_termcode().
2801 fill_mouse_coord(p
, col
, row
)
2806 p
[0] = (char_u
)(col
/ 128 + ' ' + 1);
2807 p
[1] = (char_u
)(col
% 128 + ' ' + 1);
2808 p
[2] = (char_u
)(row
/ 128 + ' ' + 1);
2809 p
[3] = (char_u
)(row
% 128 + ' ' + 1);
2813 * Generic mouse support function. Add a mouse event to the input buffer with
2814 * the given properties.
2815 * button --- may be any of MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT,
2816 * MOUSE_X1, MOUSE_X2
2817 * MOUSE_DRAG, or MOUSE_RELEASE.
2818 * MOUSE_4 and MOUSE_5 are used for a scroll wheel.
2819 * x, y --- Coordinates of mouse in pixels.
2820 * repeated_click --- TRUE if this click comes only a short time after a
2822 * modifiers --- Bit field which may be any of the following modifiers
2823 * or'ed together: MOUSE_SHIFT | MOUSE_CTRL | MOUSE_ALT.
2824 * This function will ignore drag events where the mouse has not moved to a new
2828 gui_send_mouse_event(button
, x
, y
, repeated_click
, modifiers
)
2835 static int prev_row
= 0, prev_col
= 0;
2836 static int prev_button
= -1;
2837 static int num_clicks
= 1;
2839 enum key_extra button_char
;
2841 #ifdef FEAT_CLIPBOARD
2843 int did_clip
= FALSE
;
2847 * Scrolling may happen at any time, also while a selection is present.
2852 button_char
= KE_X1MOUSE
;
2855 button_char
= KE_X2MOUSE
;
2858 button_char
= KE_MOUSEDOWN
;
2861 button_char
= KE_MOUSEUP
;
2864 /* Don't put events in the input queue now. */
2865 if (hold_gui_events
)
2869 string
[4] = KS_EXTRA
;
2870 string
[5] = (int)button_char
;
2872 /* Pass the pointer coordinates of the scroll event so that we
2873 * know which window to scroll. */
2874 row
= gui_xy2colrow(x
, y
, &col
);
2875 string
[6] = (char_u
)(col
/ 128 + ' ' + 1);
2876 string
[7] = (char_u
)(col
% 128 + ' ' + 1);
2877 string
[8] = (char_u
)(row
/ 128 + ' ' + 1);
2878 string
[9] = (char_u
)(row
% 128 + ' ' + 1);
2881 add_to_input_buf(string
+ 3, 7);
2885 string
[1] = KS_MODIFIER
;
2887 if (modifiers
& MOUSE_SHIFT
)
2888 string
[2] |= MOD_MASK_SHIFT
;
2889 if (modifiers
& MOUSE_CTRL
)
2890 string
[2] |= MOD_MASK_CTRL
;
2891 if (modifiers
& MOUSE_ALT
)
2892 string
[2] |= MOD_MASK_ALT
;
2893 add_to_input_buf(string
, 10);
2899 #ifdef FEAT_CLIPBOARD
2900 /* If a clipboard selection is in progress, handle it */
2901 if (clip_star
.state
== SELECT_IN_PROGRESS
)
2903 clip_process_selection(button
, X_2_COL(x
), Y_2_ROW(y
), repeated_click
);
2907 /* Determine which mouse settings to look for based on the current mode */
2908 switch (get_real_state())
2912 case NORMAL
: checkfor
= MOUSE_NORMAL
; break;
2913 case VISUAL
: checkfor
= MOUSE_VISUAL
; break;
2914 case SELECTMODE
: checkfor
= MOUSE_VISUAL
; break;
2916 case REPLACE
+LANGMAP
:
2917 #ifdef FEAT_VREPLACE
2919 case VREPLACE
+LANGMAP
:
2922 case INSERT
+LANGMAP
: checkfor
= MOUSE_INSERT
; break;
2924 case HITRETURN
: /* At the more- and hit-enter prompt pass the
2925 mouse event for a click on or below the
2927 if (Y_2_ROW(y
) >= msg_row
)
2928 checkfor
= MOUSE_NORMAL
;
2930 checkfor
= MOUSE_RETURN
;
2934 * On the command line, use the clipboard selection on all lines
2935 * but the command line. But not when pasting.
2938 case CMDLINE
+LANGMAP
:
2939 if (Y_2_ROW(y
) < cmdline_row
&& button
!= MOUSE_MIDDLE
)
2940 checkfor
= MOUSE_NONE
;
2942 checkfor
= MOUSE_COMMAND
;
2946 checkfor
= MOUSE_NONE
;
2951 * Allow clipboard selection of text on the command line in "normal"
2952 * modes. Don't do this when dragging the status line, or extending a
2955 if ((State
== NORMAL
|| State
== NORMAL_BUSY
|| (State
& INSERT
))
2956 && Y_2_ROW(y
) >= topframe
->fr_height
2957 # ifdef FEAT_WINDOWS
2958 + firstwin
->w_winrow
2960 && button
!= MOUSE_DRAG
2961 # ifdef FEAT_MOUSESHAPE
2962 && !drag_status_line
2963 # ifdef FEAT_VERTSPLIT
2968 checkfor
= MOUSE_NONE
;
2971 * Use modeless selection when holding CTRL and SHIFT pressed.
2973 if ((modifiers
& MOUSE_CTRL
) && (modifiers
& MOUSE_SHIFT
))
2974 checkfor
= MOUSE_NONEF
;
2977 * In Ex mode, always use modeless selection.
2980 checkfor
= MOUSE_NONE
;
2983 * If the mouse settings say to not use the mouse, use the modeless
2984 * selection. But if Visual is active, assume that only the Visual area
2986 * Exception: On the command line, both the selection is used and a mouse
2989 if (!mouse_has(checkfor
) || checkfor
== MOUSE_COMMAND
)
2992 /* Don't do modeless selection in Visual mode. */
2993 if (checkfor
!= MOUSE_NONEF
&& VIsual_active
&& (State
& NORMAL
))
2998 * When 'mousemodel' is "popup", shift-left is translated to right.
2999 * But not when also using Ctrl.
3001 if (mouse_model_popup() && button
== MOUSE_LEFT
3002 && (modifiers
& MOUSE_SHIFT
) && !(modifiers
& MOUSE_CTRL
))
3004 button
= MOUSE_RIGHT
;
3005 modifiers
&= ~ MOUSE_SHIFT
;
3008 /* If the selection is done, allow the right button to extend it.
3009 * If the selection is cleared, allow the right button to start it
3010 * from the cursor position. */
3011 if (button
== MOUSE_RIGHT
)
3013 if (clip_star
.state
== SELECT_CLEARED
)
3015 if (State
& CMDLINE
)
3022 col
= curwin
->w_wcol
;
3023 row
= curwin
->w_wrow
+ W_WINROW(curwin
);
3025 clip_start_selection(col
, row
, FALSE
);
3027 clip_process_selection(button
, X_2_COL(x
), Y_2_ROW(y
),
3031 /* Allow the left button to start the selection */
3034 /* Only start a drag on a drag event. Otherwise
3035 * we don't get a release event. */
3042 clip_start_selection(X_2_COL(x
), Y_2_ROW(y
), repeated_click
);
3046 else if (button
== MOUSE_LEFT
)
3048 clip_clear_selection();
3053 /* Always allow pasting */
3054 if (button
!= MOUSE_MIDDLE
)
3056 if (!mouse_has(checkfor
) || button
== MOUSE_RELEASE
)
3058 if (checkfor
!= MOUSE_COMMAND
)
3059 button
= MOUSE_LEFT
;
3061 repeated_click
= FALSE
;
3064 if (clip_star
.state
!= SELECT_CLEARED
&& !did_clip
)
3065 clip_clear_selection();
3068 /* Don't put events in the input queue now. */
3069 if (hold_gui_events
)
3072 row
= gui_xy2colrow(x
, y
, &col
);
3075 * If we are dragging and the mouse hasn't moved far enough to be on a
3076 * different character, then don't send an event to vim.
3078 if (button
== MOUSE_DRAG
)
3080 if (row
== prev_row
&& col
== prev_col
)
3082 /* Dragging above the window, set "row" to -1 to cause a scroll. */
3088 * If topline has changed (window scrolled) since the last click, reset
3089 * repeated_click, because we don't want starting Visual mode when
3090 * clicking on a different character in the text.
3092 if (curwin
->w_topline
!= gui_prev_topline
3094 || curwin
->w_topfill
!= gui_prev_topfill
3097 repeated_click
= FALSE
;
3099 string
[0] = CSI
; /* this sequence is recognized by check_termcode() */
3100 string
[1] = KS_MOUSE
;
3101 string
[2] = KE_FILLER
;
3102 if (button
!= MOUSE_DRAG
&& button
!= MOUSE_RELEASE
)
3107 * Handle multiple clicks. They only count if the mouse is still
3108 * pointing at the same character.
3110 if (button
!= prev_button
|| row
!= prev_row
|| col
!= prev_col
)
3112 else if (++num_clicks
> 4)
3117 prev_button
= button
;
3118 gui_prev_topline
= curwin
->w_topline
;
3120 gui_prev_topfill
= curwin
->w_topfill
;
3123 string
[3] = (char_u
)(button
| 0x20);
3124 SET_NUM_MOUSE_CLICKS(string
[3], num_clicks
);
3127 string
[3] = (char_u
)button
;
3129 string
[3] |= modifiers
;
3130 fill_mouse_coord(string
+ 4, col
, row
);
3131 add_to_input_buf(string
, 8);
3140 * We need to make sure this is cleared since Athena doesn't tell us when
3141 * he is done dragging. Neither does GTK+ 2 -- at least for now.
3143 #if defined(FEAT_GUI_ATHENA) || defined(HAVE_GTK2)
3144 gui
.dragged_sb
= SBAR_NONE
;
3149 * Convert x and y coordinate to column and row in text window.
3150 * Corrects for multi-byte character.
3151 * returns column in "*colp" and row as return value;
3154 gui_xy2colrow(x
, y
, colp
)
3159 int col
= check_col(X_2_COL(x
));
3160 int row
= check_row(Y_2_ROW(y
));
3163 *colp
= mb_fix_col(col
, row
);
3170 #if defined(FEAT_MENU) || defined(PROTO)
3172 * Callback function for when a menu entry has been selected.
3178 char_u bytes
[sizeof(long_u
)];
3180 /* Don't put events in the input queue now. */
3181 if (hold_gui_events
)
3186 bytes
[2] = KE_FILLER
;
3187 add_to_input_buf(bytes
, 3);
3188 add_long_to_buf((long_u
)menu
, bytes
);
3189 add_to_input_buf_csi(bytes
, sizeof(long_u
));
3193 static int prev_which_scrollbars
[3];
3196 * Set which components are present.
3197 * If "oldval" is not NULL, "oldval" is the previous value, the new value is
3201 gui_init_which_components(oldval
)
3202 char_u
*oldval UNUSED
;
3205 static int prev_menu_is_active
= -1;
3208 static int prev_toolbar
= -1;
3209 int using_toolbar
= FALSE
;
3211 #ifdef FEAT_GUI_TABLINE
3215 static int prev_footer
= -1;
3216 int using_footer
= FALSE
;
3218 #if defined(FEAT_MENU) && !defined(WIN16)
3219 static int prev_tearoff
= -1;
3220 int using_tearoff
= FALSE
;
3222 static int prev_nocaption
= -1;
3223 int using_caption
= TRUE
;
3228 int grey_old
, grey_new
;
3236 if (oldval
!= NULL
&& gui
.in_use
)
3239 * Check if the menu's go from grey to non-grey or vise versa.
3241 grey_old
= (vim_strchr(oldval
, GO_GREY
) != NULL
);
3242 grey_new
= (vim_strchr(p_go
, GO_GREY
) != NULL
);
3243 if (grey_old
!= grey_new
)
3247 gui_update_menus(MENU_ALL_MODES
);
3251 gui
.menu_is_active
= FALSE
;
3254 for (i
= 0; i
< 3; i
++)
3255 gui
.which_scrollbars
[i
] = FALSE
;
3256 for (p
= p_go
; *p
; p
++)
3260 gui
.which_scrollbars
[SBAR_LEFT
] = TRUE
;
3263 gui
.which_scrollbars
[SBAR_RIGHT
] = TRUE
;
3265 #ifdef FEAT_VERTSPLIT
3267 if (win_hasvertsplit())
3268 gui
.which_scrollbars
[SBAR_LEFT
] = TRUE
;
3271 if (win_hasvertsplit())
3272 gui
.which_scrollbars
[SBAR_RIGHT
] = TRUE
;
3276 gui
.which_scrollbars
[SBAR_BOTTOM
] = TRUE
;
3280 gui
.menu_is_active
= TRUE
;
3284 /* make menu's have grey items, ignored here */
3288 using_toolbar
= TRUE
;
3293 using_footer
= TRUE
;
3297 #if defined(FEAT_MENU) && !defined(WIN16)
3298 using_tearoff
= TRUE
;
3302 using_caption
= FALSE
;
3305 /* Ignore options that are not supported */
3314 #ifdef FEAT_GUI_TABLINE
3315 /* Update the GUI tab line, it may appear or disappear. This may
3316 * cause the non-GUI tab line to disappear or appear. */
3317 using_tabline
= gui_has_tabline();
3318 if (!gui_mch_showing_tabline() != !using_tabline
)
3320 /* We don't want a resize event change "Rows" here, save and
3321 * restore it. Resizing is handled below. */
3323 gui_update_tabline();
3325 need_set_size
|= RESIZE_VERT
;
3328 if (!gui_use_tabline())
3329 redraw_tabline
= TRUE
; /* may draw non-GUI tab line */
3333 for (i
= 0; i
< 3; i
++)
3335 /* The scrollbar needs to be updated when it is shown/unshown and
3336 * when switching tab pages. But the size only changes when it's
3337 * shown/unshown. Thus we need two places to remember whether a
3338 * scrollbar is there or not. */
3339 if (gui
.which_scrollbars
[i
] != prev_which_scrollbars
[i
]
3341 || gui
.which_scrollbars
[i
]
3342 != curtab
->tp_prev_which_scrollbars
[i
]
3346 if (i
== SBAR_BOTTOM
)
3347 gui_mch_enable_scrollbar(&gui
.bottom_sbar
,
3348 gui
.which_scrollbars
[i
]);
3353 gui_do_scrollbar(wp
, i
, gui
.which_scrollbars
[i
]);
3356 if (gui
.which_scrollbars
[i
] != prev_which_scrollbars
[i
])
3358 if (i
== SBAR_BOTTOM
)
3359 need_set_size
|= RESIZE_VERT
;
3361 need_set_size
|= RESIZE_HOR
;
3362 if (gui
.which_scrollbars
[i
])
3367 curtab
->tp_prev_which_scrollbars
[i
] = gui
.which_scrollbars
[i
];
3369 prev_which_scrollbars
[i
] = gui
.which_scrollbars
[i
];
3373 if (gui
.menu_is_active
!= prev_menu_is_active
)
3375 /* We don't want a resize event change "Rows" here, save and
3376 * restore it. Resizing is handled below. */
3378 gui_mch_enable_menu(gui
.menu_is_active
);
3380 prev_menu_is_active
= gui
.menu_is_active
;
3381 need_set_size
|= RESIZE_VERT
;
3382 if (gui
.menu_is_active
)
3388 if (using_toolbar
!= prev_toolbar
)
3390 gui_mch_show_toolbar(using_toolbar
);
3391 prev_toolbar
= using_toolbar
;
3392 need_set_size
|= RESIZE_VERT
;
3398 if (using_footer
!= prev_footer
)
3400 gui_mch_enable_footer(using_footer
);
3401 prev_footer
= using_footer
;
3402 need_set_size
|= RESIZE_VERT
;
3407 #if defined(FEAT_MENU) && !defined(WIN16) && !(defined(WIN3264) && !defined(FEAT_TEAROFF))
3408 if (using_tearoff
!= prev_tearoff
)
3410 gui_mch_toggle_tearoffs(using_tearoff
);
3411 prev_tearoff
= using_tearoff
;
3414 if (using_caption
!= prev_nocaption
)
3416 #if defined(WIN3264)
3417 gui_mch_show_caption(using_caption
);
3419 prev_nocaption
= using_caption
;
3420 need_set_size
= TRUE
;
3422 if (need_set_size
!= 0)
3425 long prev_Columns
= Columns
;
3426 long prev_Rows
= Rows
;
3428 /* Adjust the size of the window to make the text area keep the
3429 * same size and to avoid that part of our window is off-screen
3430 * and a scrollbar can't be used, for example. */
3431 gui_set_shellsize(FALSE
, fix_size
, need_set_size
);
3434 /* GTK has the annoying habit of sending us resize events when
3435 * changing the window size ourselves. This mostly happens when
3436 * waiting for a character to arrive, quite unpredictably, and may
3437 * change Columns and Rows when we don't want it. Wait for a
3438 * character here to avoid this effect.
3439 * If you remove this, please test this command for resizing
3440 * effects (with optional left scrollbar): ":vsp|q|vsp|q|vsp|q".
3441 * Don't do this while starting up though.
3442 * Don't change Rows when adding menu/toolbar/tabline.
3443 * Don't change Columns when adding vertical toolbar. */
3444 if (!gui
.starting
&& need_set_size
!= (RESIZE_VERT
| RESIZE_HOR
))
3446 if ((need_set_size
& RESIZE_VERT
) == 0)
3448 if ((need_set_size
& RESIZE_HOR
) == 0)
3449 Columns
= prev_Columns
;
3453 /* When the console tabline appears or disappears the window positions
3455 if (firstwin
->w_winrow
!= tabline_height())
3456 shell_new_rows(); /* recompute window positions and heights */
3461 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3463 * Return TRUE if the GUI is taking care of the tabline.
3464 * It may still be hidden if 'showtabline' is zero.
3469 return gui
.in_use
&& vim_strchr(p_go
, GO_TABLINE
) != NULL
;
3473 * Return TRUE if the GUI is showing the tabline.
3474 * This uses 'showtabline'.
3479 if (!gui_use_tabline()
3481 || (p_stal
== 1 && first_tabpage
->tp_next
== NULL
))
3487 * Update the tabline.
3488 * This may display/undisplay the tabline and update the labels.
3491 gui_update_tabline()
3493 int showit
= gui_has_tabline();
3494 int shown
= gui_mch_showing_tabline();
3496 if (!gui
.starting
&& starting
== 0)
3498 /* Updating the tabline uses direct GUI commands, flush
3499 * outstanding instructions first. (esp. clear screen) */
3503 if (!showit
!= !shown
)
3504 gui_mch_show_tabline(showit
);
3506 gui_mch_update_tabline();
3508 /* When the tabs change from hidden to shown or from shown to
3509 * hidden the size of the text area should remain the same. */
3510 if (!showit
!= !shown
)
3511 gui_set_shellsize(FALSE
, showit
, RESIZE_VERT
);
3516 * Get the label or tooltip for tab page "tp" into NameBuff[].
3519 get_tabline_label(tp
, tooltip
)
3521 int tooltip
; /* TRUE: get tooltip */
3523 int modified
= FALSE
;
3529 /* Use 'guitablabel' or 'guitabtooltip' if it's set. */
3530 opt
= (tooltip
? &p_gtt
: &p_gtl
);
3533 int use_sandbox
= FALSE
;
3534 int save_called_emsg
= called_emsg
;
3535 char_u res
[MAXPATHL
];
3536 tabpage_T
*save_curtab
;
3537 char_u
*opt_name
= (char_u
*)(tooltip
? "guitabtooltip"
3540 called_emsg
= FALSE
;
3542 printer_page_num
= tabpage_index(tp
);
3544 set_vim_var_nr(VV_LNUM
, printer_page_num
);
3545 use_sandbox
= was_set_insecurely(opt_name
, 0);
3547 /* It's almost as going to the tabpage, but without autocommands. */
3548 curtab
->tp_firstwin
= firstwin
;
3549 curtab
->tp_lastwin
= lastwin
;
3550 curtab
->tp_curwin
= curwin
;
3551 save_curtab
= curtab
;
3553 topframe
= curtab
->tp_topframe
;
3554 firstwin
= curtab
->tp_firstwin
;
3555 lastwin
= curtab
->tp_lastwin
;
3556 curwin
= curtab
->tp_curwin
;
3557 curbuf
= curwin
->w_buffer
;
3559 /* Can't use NameBuff directly, build_stl_str_hl() uses it. */
3560 build_stl_str_hl(curwin
, res
, MAXPATHL
, *opt
, use_sandbox
,
3561 0, (int)Columns
, NULL
, NULL
);
3562 STRCPY(NameBuff
, res
);
3564 /* Back to the original curtab. */
3565 curtab
= save_curtab
;
3566 topframe
= curtab
->tp_topframe
;
3567 firstwin
= curtab
->tp_firstwin
;
3568 lastwin
= curtab
->tp_lastwin
;
3569 curwin
= curtab
->tp_curwin
;
3570 curbuf
= curwin
->w_buffer
;
3573 set_string_option_direct(opt_name
, -1,
3574 (char_u
*)"", OPT_FREE
, SID_ERROR
);
3575 called_emsg
|= save_called_emsg
;
3578 /* If 'guitablabel'/'guitabtooltip' is not set or the result is empty then
3579 * use a default label. */
3580 if (**opt
== NUL
|| *NameBuff
== NUL
)
3582 /* Get the buffer name into NameBuff[] and shorten it. */
3583 get_trans_bufname(tp
== curtab
? curbuf
: tp
->tp_curwin
->w_buffer
);
3585 shorten_dir(NameBuff
);
3587 wp
= (tp
== curtab
) ? firstwin
: tp
->tp_firstwin
;
3588 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
3589 if (bufIsChanged(wp
->w_buffer
))
3591 if (modified
|| wincount
> 1)
3594 vim_snprintf((char *)buf
, sizeof(buf
), "%d", wincount
);
3600 STRMOVE(NameBuff
+ STRLEN(buf
), NameBuff
);
3601 mch_memmove(NameBuff
, buf
, STRLEN(buf
));
3607 * Send the event for clicking to select tab page "nr".
3608 * Returns TRUE if it was done, FALSE when skipped because we are already at
3609 * that tab page or the cmdline window is open.
3612 send_tabline_event(nr
)
3617 if (nr
== tabpage_index(curtab
))
3620 /* Don't put events in the input queue now. */
3627 /* Set it back to the current tab page. */
3628 gui_mch_set_curtab(tabpage_index(curtab
));
3633 string
[1] = KS_TABLINE
;
3634 string
[2] = KE_FILLER
;
3635 add_to_input_buf(string
, 3);
3637 add_to_input_buf_csi(string
, 1);
3642 * Send a tabline menu event
3645 send_tabline_menu_event(tabidx
, event
)
3651 /* Don't put events in the input queue now. */
3652 if (hold_gui_events
)
3656 string
[1] = KS_TABMENU
;
3657 string
[2] = KE_FILLER
;
3658 add_to_input_buf(string
, 3);
3660 string
[1] = (char_u
)(long)event
;
3661 add_to_input_buf_csi(string
, 2);
3670 #if defined(FEAT_WINDOWS) || defined(PROTO)
3672 * Remove all scrollbars. Used before switching to another tab page.
3675 gui_remove_scrollbars()
3680 for (i
= 0; i
< 3; i
++)
3682 if (i
== SBAR_BOTTOM
)
3683 gui_mch_enable_scrollbar(&gui
.bottom_sbar
, FALSE
);
3688 gui_do_scrollbar(wp
, i
, FALSE
);
3691 curtab
->tp_prev_which_scrollbars
[i
] = -1;
3697 gui_create_scrollbar(sb
, type
, wp
)
3702 #ifdef FEAT_GUI_MACVIM
3703 /* This is passed over to another process, make sure it fits in 32 bit */
3704 static int32_t sbar_ident
= 0;
3706 static int sbar_ident
= 0;
3709 sb
->ident
= sbar_ident
++; /* No check for too big, but would it happen? */
3713 #ifdef FEAT_GUI_ATHENA
3720 #ifdef FEAT_VERTSPLIT
3723 sb
->status_height
= 0;
3724 gui_mch_create_scrollbar(sb
, (wp
== NULL
) ? SBAR_HORIZ
: SBAR_VERT
);
3728 * Find the scrollbar with the given index.
3731 gui_find_scrollbar(ident
)
3736 if (gui
.bottom_sbar
.ident
== ident
)
3737 return &gui
.bottom_sbar
;
3740 if (wp
->w_scrollbars
[SBAR_LEFT
].ident
== ident
)
3741 return &wp
->w_scrollbars
[SBAR_LEFT
];
3742 if (wp
->w_scrollbars
[SBAR_RIGHT
].ident
== ident
)
3743 return &wp
->w_scrollbars
[SBAR_RIGHT
];
3749 * For most systems: Put a code in the input buffer for a dragged scrollbar.
3751 * For Win32, Macintosh and GTK+ 2:
3752 * Scrollbars seem to grab focus and vim doesn't read the input queue until
3753 * you stop dragging the scrollbar. We get here each time the scrollbar is
3754 * dragged another pixel, but as far as the rest of vim goes, it thinks
3755 * we're just hanging in the call to DispatchMessage() in
3756 * process_message(). The DispatchMessage() call that hangs was passed a
3757 * mouse button click event in the scrollbar window. -- webb.
3759 * Solution: Do the scrolling right here. But only when allowed.
3760 * Ignore the scrollbars while executing an external command or when there
3761 * are still characters to be processed.
3764 gui_drag_scrollbar(sb
, value
, still_dragging
)
3773 #ifdef USE_ON_FLY_SCROLL
3774 colnr_T old_leftcol
= curwin
->w_leftcol
;
3775 # ifdef FEAT_SCROLLBIND
3776 linenr_T old_topline
= curwin
->w_topline
;
3779 int old_topfill
= curwin
->w_topfill
;
3782 char_u bytes
[sizeof(long_u
)];
3789 /* Don't put events in the input queue now. */
3790 if (hold_gui_events
)
3794 if (cmdwin_type
!= 0 && sb
->wp
!= curwin
)
3801 gui
.dragged_sb
= SBAR_BOTTOM
;
3802 else if (sb
== &sb
->wp
->w_scrollbars
[SBAR_LEFT
])
3803 gui
.dragged_sb
= SBAR_LEFT
;
3805 gui
.dragged_sb
= SBAR_RIGHT
;
3806 gui
.dragged_wp
= sb
->wp
;
3810 gui
.dragged_sb
= SBAR_NONE
;
3812 /* Keep the "dragged_wp" value until after the scrolling, for when the
3813 * moust button is released. GTK2 doesn't send the button-up event. */
3814 gui
.dragged_wp
= NULL
;
3818 /* Vertical sbar info is kept in the first sbar (the left one) */
3820 sb
= &sb
->wp
->w_scrollbars
[0];
3823 * Check validity of value
3827 #ifdef SCROLL_PAST_END
3828 else if (value
> sb
->max
)
3831 if (value
> sb
->max
- sb
->size
+ 1)
3832 value
= sb
->max
- sb
->size
+ 1;
3837 #ifdef USE_ON_FLY_SCROLL
3838 /* When not allowed to do the scrolling right now, return.
3839 * This also checked input_available(), but that causes the first click in
3840 * a scrollbar to be ignored when Vim doesn't have focus. */
3844 #ifdef FEAT_INS_EXPAND
3845 /* Disallow scrolling the current window when the completion popup menu is
3847 if ((sb
->wp
== NULL
|| sb
->wp
== curwin
) && pum_visible())
3851 #ifdef FEAT_RIGHTLEFT
3852 if (sb
->wp
== NULL
&& curwin
->w_p_rl
)
3854 value
= sb
->max
+ 1 - sb
->size
- value
;
3860 if (sb
->wp
!= NULL
) /* vertical scrollbar */
3864 for (wp
= firstwin
; wp
!= sb
->wp
&& wp
!= NULL
; wp
= wp
->w_next
)
3869 if (sb
->wp
!= curwin
)
3873 #ifdef USE_ON_FLY_SCROLL
3874 current_scrollbar
= sb_num
;
3875 scrollbar_value
= value
;
3881 else if (State
& INSERT
)
3886 else if (State
& CMDLINE
)
3888 if (msg_scrolled
== 0)
3894 # ifdef FEAT_FOLDING
3895 /* Value may have been changed for closed fold. */
3896 sb
->value
= sb
->wp
->w_topline
- 1;
3899 /* When dragging one scrollbar and there is another one at the other
3900 * side move the thumb of that one too. */
3901 if (gui
.which_scrollbars
[SBAR_RIGHT
] && gui
.which_scrollbars
[SBAR_LEFT
])
3902 gui_mch_set_scrollbar_thumb(
3903 &sb
->wp
->w_scrollbars
[
3904 sb
== &sb
->wp
->w_scrollbars
[SBAR_RIGHT
]
3905 ? SBAR_LEFT
: SBAR_RIGHT
],
3906 sb
->value
, sb
->size
, sb
->max
);
3910 bytes
[1] = KS_VER_SCROLLBAR
;
3911 bytes
[2] = KE_FILLER
;
3912 bytes
[3] = (char_u
)sb_num
;
3918 #ifdef USE_ON_FLY_SCROLL
3919 scrollbar_value
= value
;
3922 gui_do_horiz_scroll();
3923 else if (State
& INSERT
)
3925 else if (State
& CMDLINE
)
3927 if (msg_scrolled
== 0)
3929 gui_do_horiz_scroll();
3933 if (old_leftcol
!= curwin
->w_leftcol
)
3935 updateWindow(curwin
); /* update window, status and cmdline */
3940 bytes
[1] = KS_HOR_SCROLLBAR
;
3941 bytes
[2] = KE_FILLER
;
3946 #ifdef USE_ON_FLY_SCROLL
3947 # ifdef FEAT_SCROLLBIND
3949 * synchronize other windows, as necessary according to 'scrollbind'
3952 && ((sb
->wp
== NULL
&& curwin
->w_leftcol
!= old_leftcol
)
3953 || (sb
->wp
== curwin
&& (curwin
->w_topline
!= old_topline
3955 || curwin
->w_topfill
!= old_topfill
3959 do_check_scrollbind(TRUE
);
3960 /* need to update the window right here */
3961 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3962 if (wp
->w_redr_type
> 0)
3968 gui_update_cursor(FALSE
, TRUE
);
3970 add_to_input_buf(bytes
, byte_count
);
3971 add_long_to_buf((long_u
)value
, bytes
);
3972 add_to_input_buf_csi(bytes
, sizeof(long_u
));
3981 * Called when something in the window layout has changed.
3984 gui_may_update_scrollbars()
3986 if (gui
.in_use
&& starting
== 0)
3989 gui_init_which_components(NULL
);
3990 gui_update_scrollbars(TRUE
);
3992 need_mouse_correct
= TRUE
;
3996 gui_update_scrollbars(force
)
3997 int force
; /* Force all scrollbars to get updated */
4001 long val
, size
, max
; /* need 32 bits here */
4004 #ifdef FEAT_VERTSPLIT
4005 static win_T
*prev_curwin
= NULL
;
4008 /* Update the horizontal scrollbar */
4009 gui_update_horiz_scrollbar(force
);
4012 /* Return straight away if there is neither a left nor right scrollbar.
4013 * On MS-Windows this is required anyway for scrollwheel messages. */
4014 if (!gui
.which_scrollbars
[SBAR_LEFT
] && !gui
.which_scrollbars
[SBAR_RIGHT
])
4019 * Don't want to update a scrollbar while we're dragging it. But if we
4020 * have both a left and right scrollbar, and we drag one of them, we still
4021 * need to update the other one.
4023 if (!force
&& (gui
.dragged_sb
== SBAR_LEFT
|| gui
.dragged_sb
== SBAR_RIGHT
)
4024 && gui
.which_scrollbars
[SBAR_LEFT
]
4025 && gui
.which_scrollbars
[SBAR_RIGHT
])
4028 * If we have two scrollbars and one of them is being dragged, just
4029 * copy the scrollbar position from the dragged one to the other one.
4031 which_sb
= SBAR_LEFT
+ SBAR_RIGHT
- gui
.dragged_sb
;
4032 if (gui
.dragged_wp
!= NULL
)
4033 gui_mch_set_scrollbar_thumb(
4034 &gui
.dragged_wp
->w_scrollbars
[which_sb
],
4035 gui
.dragged_wp
->w_scrollbars
[0].value
,
4036 gui
.dragged_wp
->w_scrollbars
[0].size
,
4037 gui
.dragged_wp
->w_scrollbars
[0].max
);
4040 /* avoid that moving components around generates events */
4043 for (wp
= firstwin
; wp
!= NULL
; wp
= W_NEXT(wp
))
4045 if (wp
->w_buffer
== NULL
) /* just in case */
4047 /* Skip a scrollbar that is being dragged. */
4048 if (!force
&& (gui
.dragged_sb
== SBAR_LEFT
4049 || gui
.dragged_sb
== SBAR_RIGHT
)
4050 && gui
.dragged_wp
== wp
)
4053 #ifdef SCROLL_PAST_END
4054 max
= wp
->w_buffer
->b_ml
.ml_line_count
- 1;
4056 max
= wp
->w_buffer
->b_ml
.ml_line_count
+ wp
->w_height
- 2;
4058 if (max
< 0) /* empty buffer */
4060 val
= wp
->w_topline
- 1;
4061 size
= wp
->w_height
;
4062 #ifdef SCROLL_PAST_END
4063 if (val
> max
) /* just in case */
4066 if (size
> max
+ 1) /* just in case */
4068 if (val
> max
- size
+ 1)
4069 val
= max
- size
+ 1;
4071 if (val
< 0) /* minimal value is 0 */
4075 * Scrollbar at index 0 (the left one) contains all the information.
4076 * It would be the same info for left and right so we just store it for
4079 sb
= &wp
->w_scrollbars
[0];
4082 * Note: no check for valid w_botline. If it's not valid the
4083 * scrollbars will be updated later anyway.
4085 if (size
< 1 || wp
->w_botline
- 2 > max
)
4088 * This can happen during changing files. Just don't update the
4089 * scrollbar for now.
4091 sb
->height
= 0; /* Force update next time */
4092 if (gui
.which_scrollbars
[SBAR_LEFT
])
4093 gui_do_scrollbar(wp
, SBAR_LEFT
, FALSE
);
4094 if (gui
.which_scrollbars
[SBAR_RIGHT
])
4095 gui_do_scrollbar(wp
, SBAR_RIGHT
, FALSE
);
4098 if (force
|| sb
->height
!= wp
->w_height
4100 || sb
->top
!= wp
->w_winrow
4101 || sb
->status_height
!= wp
->w_status_height
4102 # ifdef FEAT_VERTSPLIT
4103 || sb
->width
!= wp
->w_width
4104 || prev_curwin
!= curwin
4109 /* Height, width or position of scrollbar has changed. For
4110 * vertical split: curwin changed. */
4111 sb
->height
= wp
->w_height
;
4113 sb
->top
= wp
->w_winrow
;
4114 sb
->status_height
= wp
->w_status_height
;
4115 # ifdef FEAT_VERTSPLIT
4116 sb
->width
= wp
->w_width
;
4120 /* Calculate height and position in pixels */
4121 h
= (sb
->height
+ sb
->status_height
) * gui
.char_height
;
4122 y
= sb
->top
* gui
.char_height
+ gui
.border_offset
;
4123 #if defined(FEAT_MENU) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \
4124 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MACVIM))
4125 if (gui
.menu_is_active
)
4126 y
+= gui
.menu_height
;
4129 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_ATHENA))
4130 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
4131 # ifdef FEAT_GUI_ATHENA
4132 y
+= gui
.toolbar_height
;
4134 # ifdef FEAT_GUI_MSWIN
4135 y
+= TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
;
4140 #if defined(FEAT_GUI_TABLINE) && defined(FEAT_GUI_MSWIN)
4141 if (gui_has_tabline())
4142 y
+= gui
.tabline_height
;
4146 if (wp
->w_winrow
== 0)
4149 /* Height of top scrollbar includes width of top border */
4150 h
+= gui
.border_offset
;
4151 y
-= gui
.border_offset
;
4153 if (gui
.which_scrollbars
[SBAR_LEFT
])
4155 gui_mch_set_scrollbar_pos(&wp
->w_scrollbars
[SBAR_LEFT
],
4157 gui
.scrollbar_width
, h
);
4158 gui_do_scrollbar(wp
, SBAR_LEFT
, TRUE
);
4160 if (gui
.which_scrollbars
[SBAR_RIGHT
])
4162 gui_mch_set_scrollbar_pos(&wp
->w_scrollbars
[SBAR_RIGHT
],
4163 gui
.right_sbar_x
, y
,
4164 gui
.scrollbar_width
, h
);
4165 gui_do_scrollbar(wp
, SBAR_RIGHT
, TRUE
);
4169 /* Reduce the number of calls to gui_mch_set_scrollbar_thumb() by
4170 * checking if the thumb moved at least a pixel. Only do this for
4171 * Athena, most other GUIs require the update anyway to make the
4173 #ifdef FEAT_GUI_ATHENA
4177 y
= (val
* (sb
->height
+ 2) * gui
.char_height
+ max
/ 2) / max
;
4178 if (force
|| sb
->pixval
!= y
|| sb
->size
!= size
|| sb
->max
!= max
)
4180 if (force
|| sb
->value
!= val
|| sb
->size
!= size
|| sb
->max
!= max
)
4183 /* Thumb of scrollbar has moved */
4185 #ifdef FEAT_GUI_ATHENA
4190 if (gui
.which_scrollbars
[SBAR_LEFT
]
4191 && (gui
.dragged_sb
!= SBAR_LEFT
|| gui
.dragged_wp
!= wp
))
4192 gui_mch_set_scrollbar_thumb(&wp
->w_scrollbars
[SBAR_LEFT
],
4194 if (gui
.which_scrollbars
[SBAR_RIGHT
]
4195 && (gui
.dragged_sb
!= SBAR_RIGHT
|| gui
.dragged_wp
!= wp
))
4196 gui_mch_set_scrollbar_thumb(&wp
->w_scrollbars
[SBAR_RIGHT
],
4200 #ifdef FEAT_VERTSPLIT
4201 prev_curwin
= curwin
;
4207 * Enable or disable a scrollbar.
4208 * Check for scrollbars for vertically split windows which are not enabled
4212 gui_do_scrollbar(wp
, which
, enable
)
4214 int which
; /* SBAR_LEFT or SBAR_RIGHT */
4215 int enable
; /* TRUE to enable scrollbar */
4217 #ifdef FEAT_VERTSPLIT
4218 int midcol
= curwin
->w_wincol
+ curwin
->w_width
/ 2;
4219 int has_midcol
= (wp
->w_wincol
<= midcol
4220 && wp
->w_wincol
+ wp
->w_width
>= midcol
);
4222 /* Only enable scrollbars that contain the middle column of the current
4224 if (gui
.which_scrollbars
[SBAR_RIGHT
] != gui
.which_scrollbars
[SBAR_LEFT
])
4226 /* Scrollbars only on one side. Don't enable scrollbars that don't
4227 * contain the middle column of the current window. */
4233 /* Scrollbars on both sides. Don't enable scrollbars that neither
4234 * contain the middle column of the current window nor are on the far
4236 if (midcol
> Columns
/ 2)
4238 if (which
== SBAR_LEFT
? wp
->w_wincol
!= 0 : !has_midcol
)
4243 if (which
== SBAR_RIGHT
? wp
->w_wincol
+ wp
->w_width
!= Columns
4249 gui_mch_enable_scrollbar(&wp
->w_scrollbars
[which
], enable
);
4253 * Scroll a window according to the values set in the globals current_scrollbar
4254 * and scrollbar_value. Return TRUE if the cursor in the current window moved
4255 * or FALSE otherwise.
4260 win_T
*wp
, *save_wp
;
4264 linenr_T old_topline
;
4269 for (wp
= firstwin
, i
= 0; i
< current_scrollbar
; wp
= W_NEXT(wp
), i
++)
4273 /* Couldn't find window */
4277 * Compute number of lines to scroll. If zero, nothing to do.
4279 nlines
= (long)scrollbar_value
+ 1 - (long)wp
->w_topline
;
4284 old_topline
= wp
->w_topline
;
4286 old_topfill
= wp
->w_topfill
;
4288 old_cursor
= wp
->w_cursor
;
4290 curbuf
= wp
->w_buffer
;
4292 scrolldown(-nlines
, gui
.dragged_wp
== NULL
);
4294 scrollup(nlines
, gui
.dragged_wp
== NULL
);
4295 /* Reset dragged_wp after using it. "dragged_sb" will have been reset for
4296 * the mouse-up event already, but we still want it to behave like when
4297 * dragging. But not the next click in an arrow. */
4298 if (gui
.dragged_sb
== SBAR_NONE
)
4299 gui
.dragged_wp
= NULL
;
4301 if (old_topline
!= wp
->w_topline
4303 || old_topfill
!= wp
->w_topfill
4309 cursor_correct(); /* fix window for 'so' */
4310 update_topline(); /* avoid up/down jump */
4312 if (old_cursor
.lnum
!= wp
->w_cursor
.lnum
)
4313 coladvance(wp
->w_curswant
);
4314 #ifdef FEAT_SCROLLBIND
4315 wp
->w_scbind_pos
= wp
->w_topline
;
4319 /* Make sure wp->w_leftcol and wp->w_skipcol are correct. */
4323 curbuf
= save_wp
->w_buffer
;
4326 * Don't call updateWindow() when nothing has changed (it will overwrite
4327 * the status line!).
4329 if (old_topline
!= wp
->w_topline
4330 || wp
->w_redr_type
!= 0
4332 || old_topfill
!= wp
->w_topfill
4338 #ifdef FEAT_INS_EXPAND
4342 wp
->w_lines_valid
= 0;
4345 /* Don't set must_redraw here, it may cause the popup menu to
4346 * disappear when losing focus after a scrollbar drag. */
4347 if (wp
->w_redr_type
< type
)
4348 wp
->w_redr_type
= type
;
4349 updateWindow(wp
); /* update window, status line, and cmdline */
4352 #ifdef FEAT_INS_EXPAND
4353 /* May need to redraw the popup menu. */
4358 return (wp
== curwin
&& !equalpos(curwin
->w_cursor
, old_cursor
));
4363 * Horizontal scrollbar stuff:
4367 * Return length of line "lnum" for horizontal scrolling.
4370 scroll_line_len(lnum
)
4382 w
= chartabsize(p
, col
);
4384 if (*p
== NUL
) /* don't count the last character */
4391 /* Remember which line is currently the longest, so that we don't have to
4392 * search for it when scrolling horizontally. */
4393 static linenr_T longest_lnum
= 0;
4396 gui_update_horiz_scrollbar(force
)
4399 long value
, size
, max
; /* need 32 bit ints here */
4401 if (!gui
.which_scrollbars
[SBAR_BOTTOM
])
4404 if (!force
&& gui
.dragged_sb
== SBAR_BOTTOM
)
4407 if (!force
&& curwin
->w_p_wrap
&& gui
.prev_wrap
)
4411 * It is possible for the cursor to be invalid if we're in the middle of
4412 * something (like changing files). If so, don't do anything for now.
4414 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
4416 gui
.bottom_sbar
.value
= -1;
4420 size
= W_WIDTH(curwin
);
4421 if (curwin
->w_p_wrap
)
4424 #ifdef SCROLL_PAST_END
4427 max
= W_WIDTH(curwin
) - 1;
4432 value
= curwin
->w_leftcol
;
4434 /* Calculate maximum for horizontal scrollbar. Check for reasonable
4435 * line numbers, topline and botline can be invalid when displaying is
4437 if (vim_strchr(p_go
, GO_HORSCROLL
) == NULL
4438 && curwin
->w_topline
<= curwin
->w_cursor
.lnum
4439 && curwin
->w_botline
> curwin
->w_cursor
.lnum
4440 && curwin
->w_botline
<= curbuf
->b_ml
.ml_line_count
+ 1)
4445 /* Use maximum of all visible lines. Remember the lnum of the
4446 * longest line, clostest to the cursor line. Used when scrolling
4449 for (lnum
= curwin
->w_topline
; lnum
< curwin
->w_botline
; ++lnum
)
4451 n
= scroll_line_len(lnum
);
4452 if (n
> (colnr_T
)max
)
4455 longest_lnum
= lnum
;
4457 else if (n
== (colnr_T
)max
4458 && abs((int)(lnum
- curwin
->w_cursor
.lnum
))
4459 < abs((int)(longest_lnum
- curwin
->w_cursor
.lnum
)))
4460 longest_lnum
= lnum
;
4464 /* Use cursor line only. */
4465 max
= scroll_line_len(curwin
->w_cursor
.lnum
);
4466 #ifdef FEAT_VIRTUALEDIT
4467 if (virtual_active())
4469 /* May move the cursor even further to the right. */
4470 if (curwin
->w_virtcol
>= (colnr_T
)max
)
4471 max
= curwin
->w_virtcol
;
4475 #ifndef SCROLL_PAST_END
4476 max
+= W_WIDTH(curwin
) - 1;
4478 /* The line number isn't scrolled, thus there is less space when
4479 * 'number' is set (also for 'foldcolumn'). */
4480 size
-= curwin_col_off();
4481 #ifndef SCROLL_PAST_END
4482 max
-= curwin_col_off();
4486 #ifndef SCROLL_PAST_END
4487 if (value
> max
- size
+ 1)
4488 value
= max
- size
+ 1; /* limit the value to allowable range */
4491 #ifdef FEAT_RIGHTLEFT
4494 value
= max
+ 1 - size
- value
;
4502 if (!force
&& value
== gui
.bottom_sbar
.value
&& size
== gui
.bottom_sbar
.size
4503 && max
== gui
.bottom_sbar
.max
)
4506 gui
.bottom_sbar
.value
= value
;
4507 gui
.bottom_sbar
.size
= size
;
4508 gui
.bottom_sbar
.max
= max
;
4509 gui
.prev_wrap
= curwin
->w_p_wrap
;
4511 gui_mch_set_scrollbar_thumb(&gui
.bottom_sbar
, value
, size
, max
);
4515 * Do a horizontal scroll. Return TRUE if the cursor moved, FALSE otherwise.
4518 gui_do_horiz_scroll()
4520 /* no wrapping, no scrolling */
4521 if (curwin
->w_p_wrap
)
4524 if ((long_u
)curwin
->w_leftcol
== scrollbar_value
)
4527 curwin
->w_leftcol
= (colnr_T
)scrollbar_value
;
4529 /* When the line of the cursor is too short, move the cursor to the
4530 * longest visible line. Do a sanity check on "longest_lnum", just in
4532 if (vim_strchr(p_go
, GO_HORSCROLL
) == NULL
4533 && longest_lnum
>= curwin
->w_topline
4534 && longest_lnum
< curwin
->w_botline
4535 && !virtual_active())
4537 if (scrollbar_value
> (long_u
)scroll_line_len(curwin
->w_cursor
.lnum
))
4539 curwin
->w_cursor
.lnum
= longest_lnum
;
4540 curwin
->w_cursor
.col
= 0;
4544 return leftcol_changed();
4548 * Check that none of the colors are the same as the background color
4553 if (gui
.norm_pixel
== gui
.back_pixel
|| gui
.norm_pixel
== INVALCOLOR
)
4555 gui_set_bg_color((char_u
*)"White");
4556 if (gui
.norm_pixel
== gui
.back_pixel
|| gui
.norm_pixel
== INVALCOLOR
)
4557 gui_set_fg_color((char_u
*)"Black");
4562 gui_set_fg_color(name
)
4565 gui
.norm_pixel
= gui_get_color(name
);
4566 hl_set_fg_color_name(vim_strsave(name
));
4570 gui_set_bg_color(name
)
4573 gui
.back_pixel
= gui_get_color(name
);
4574 hl_set_bg_color_name(vim_strsave(name
));
4578 * Allocate a color by name.
4579 * Returns INVALCOLOR and gives an error message when failed.
4589 t
= gui_mch_get_color(name
);
4592 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
4596 EMSG2(_("E254: Cannot allocate color %s"), name
);
4601 * Return the grey value of a color (range 0-255).
4604 gui_get_lightness(pixel
)
4607 long_u rgb
= gui_mch_get_rgb(pixel
);
4609 return (int)( (((rgb
>> 16) & 0xff) * 299)
4610 + (((rgb
>> 8) & 0xff) * 587)
4611 + ((rgb
& 0xff) * 114)) / 1000;
4614 #if defined(FEAT_GUI_X11) || defined(PROTO)
4616 gui_new_scrollbar_colors()
4620 /* Nothing to do if GUI hasn't started yet. */
4626 gui_mch_set_scrollbar_colors(&(wp
->w_scrollbars
[SBAR_LEFT
]));
4627 gui_mch_set_scrollbar_colors(&(wp
->w_scrollbars
[SBAR_RIGHT
]));
4629 gui_mch_set_scrollbar_colors(&gui
.bottom_sbar
);
4634 * Call this when focus has changed.
4637 gui_focus_change(in_focus
)
4641 * Skip this code to avoid drawing the cursor when debugging and switching
4642 * between the debugger window and gvim.
4645 gui
.in_focus
= in_focus
;
4646 out_flush(); /* make sure output has been written */
4647 gui_update_cursor(TRUE
, FALSE
);
4650 xim_set_focus(in_focus
);
4653 /* Put events in the input queue only when allowed.
4654 * ui_focus_change() isn't called directly, because it invokes
4655 * autocommands and that must not happen asynchronously. */
4656 if (!hold_gui_events
)
4661 bytes
[1] = KS_EXTRA
;
4662 bytes
[2] = in_focus
? (int)KE_FOCUSGAINED
: (int)KE_FOCUSLOST
;
4663 add_to_input_buf(bytes
, 3);
4669 * Called when the mouse moved (but not when dragging).
4672 gui_mouse_moved(x
, y
)
4679 /* Ignore this while still starting up. */
4680 if (!gui
.in_use
|| gui
.starting
)
4683 #ifdef FEAT_MOUSESHAPE
4684 /* Get window pointer, and update mouse shape as well. */
4688 /* Only handle this when 'mousefocus' set and ... */
4690 && !hold_gui_events
/* not holding events */
4691 && (State
& (NORMAL
|INSERT
))/* Normal/Visual/Insert mode */
4692 && State
!= HITRETURN
/* but not hit-return prompt */
4693 && msg_scrolled
== 0 /* no scrolled message */
4694 && !need_mouse_correct
/* not moving the pointer */
4695 && gui
.in_focus
) /* gvim in focus */
4697 /* Don't move the mouse when it's left or right of the Vim window */
4698 if (x
< 0 || x
> Columns
* gui
.char_width
)
4700 #ifndef FEAT_MOUSESHAPE
4703 if (wp
== curwin
|| wp
== NULL
)
4704 return; /* still in the same old window, or none at all */
4707 /* Ignore position in the tab pages line. */
4708 if (Y_2_ROW(y
) < tabline_height())
4713 * format a mouse click on status line input
4714 * ala gui_send_mouse_event(0, x, y, 0, 0);
4715 * Trick: Use a column number -1, so that get_pseudo_mouse_code() will
4716 * generate a K_LEFTMOUSE_NM key code.
4720 /* abort the current operator first */
4722 add_to_input_buf(st
, 1);
4727 st
[3] = (char_u
)MOUSE_LEFT
;
4728 fill_mouse_coord(st
+ 4,
4729 #ifdef FEAT_VERTSPLIT
4730 wp
->w_wincol
== 0 ? -1 : wp
->w_wincol
+ MOUSE_COLOFF
,
4734 wp
->w_height
+ W_WINROW(wp
));
4736 add_to_input_buf(st
, 8);
4737 st
[3] = (char_u
)MOUSE_RELEASE
;
4738 add_to_input_buf(st
, 8);
4740 /* Need to wake up the main loop */
4741 if (gtk_main_level() > 0)
4748 * Called when mouse should be moved to window with focus.
4756 need_mouse_correct
= FALSE
;
4758 if (!(gui
.in_use
&& p_mousef
))
4761 gui_mch_getmouse(&x
, &y
);
4762 /* Don't move the mouse when it's left or right of the Vim window */
4763 if (x
< 0 || x
> Columns
* gui
.char_width
)
4766 # ifdef FEAT_WINDOWS
4767 && Y_2_ROW(y
) >= tabline_height()
4771 if (wp
!= curwin
&& wp
!= NULL
) /* If in other than current window */
4773 validate_cline_row();
4774 gui_mch_setmouse((int)W_ENDCOL(curwin
) * gui
.char_width
- 3,
4775 (W_WINROW(curwin
) + curwin
->w_wrow
) * gui
.char_height
4776 + (gui
.char_height
) / 2);
4781 * Find window where the mouse pointer "y" coordinate is in.
4795 if (row
< 0 || col
< 0) /* before first window */
4797 wp
= mouse_find_win(&row
, &col
);
4798 # ifdef FEAT_MOUSESHAPE
4799 if (State
== HITRETURN
|| State
== ASKMORE
)
4801 if (Y_2_ROW(y
) >= msg_row
)
4802 update_mouseshape(SHAPE_IDX_MOREL
);
4804 update_mouseshape(SHAPE_IDX_MORE
);
4806 else if (row
> wp
->w_height
) /* below status line */
4807 update_mouseshape(SHAPE_IDX_CLINE
);
4808 # ifdef FEAT_VERTSPLIT
4809 else if (!(State
& CMDLINE
) && W_VSEP_WIDTH(wp
) > 0 && col
== wp
->w_width
4810 && (row
!= wp
->w_height
|| !stl_connected(wp
)) && msg_scrolled
== 0)
4811 update_mouseshape(SHAPE_IDX_VSEP
);
4813 else if (!(State
& CMDLINE
) && W_STATUS_HEIGHT(wp
) > 0
4814 && row
== wp
->w_height
&& msg_scrolled
== 0)
4815 update_mouseshape(SHAPE_IDX_STATUS
);
4817 update_mouseshape(-2);
4826 * ":gui" and ":gvim": Change from the terminal version to the GUI version.
4827 * File names may be given to redefine the args list.
4833 char_u
*arg
= eap
->arg
;
4836 * Check for "-f" argument: foreground, don't fork.
4837 * Also don't fork when started with "gvim -f".
4838 * Do fork when using "gui -b".
4839 * Note that Mac OS X will never fork on :gui since it can only fork on
4840 * startup right after scanning the command line.
4843 && (arg
[1] == 'f' || arg
[1] == 'b')
4844 && (arg
[2] == NUL
|| vim_iswhite(arg
[2])))
4846 gui
.dofork
= (arg
[1] == 'b');
4847 eap
->arg
= skipwhite(eap
->arg
+ 2);
4851 /* Clear the command. Needed for when forking+exiting, to avoid part
4852 * of the argument ending up after the shell prompt. */
4853 msg_clr_eos_force();
4856 if (!ends_excmd(*eap
->arg
))
4860 #if ((defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32) \
4861 || defined(FEAT_GUI_PHOTON)) && defined(FEAT_TOOLBAR) \
4862 || defined(FEAT_GUI_MACVIM)) || defined(PROTO)
4864 * This is shared between Athena, Motif and GTK.
4866 static void gfp_setname
__ARGS((char_u
*fname
, void *cookie
));
4869 * Callback function for do_in_runtimepath().
4872 gfp_setname(fname
, cookie
)
4876 char_u
*gfp_buffer
= cookie
;
4878 if (STRLEN(fname
) >= MAXPATHL
)
4881 STRCPY(gfp_buffer
, fname
);
4885 * Find the path of bitmap "name" with extension "ext" in 'runtimepath'.
4886 * Return FAIL for failure and OK if buffer[MAXPATHL] contains the result.
4889 gui_find_bitmap(name
, buffer
, ext
)
4894 if (STRLEN(name
) > MAXPATHL
- 14)
4896 vim_snprintf((char *)buffer
, MAXPATHL
, "bitmaps/%s.%s", name
, ext
);
4897 if (do_in_runtimepath(buffer
, FALSE
, gfp_setname
, buffer
) == FAIL
4903 # if !defined(HAVE_GTK2) || defined(PROTO)
4905 * Given the name of the "icon=" argument, try finding the bitmap file for the
4906 * icon. If it is an absolute path name, use it as it is. Otherwise append
4907 * "ext" and search for it in 'runtimepath'.
4908 * The result is put in "buffer[MAXPATHL]". If something fails "buffer"
4912 gui_find_iconfile(name
, buffer
, ext
)
4917 char_u buf
[MAXPATHL
+ 1];
4919 expand_env(name
, buffer
, MAXPATHL
);
4920 if (!mch_isFullName(buffer
) && gui_find_bitmap(buffer
, buf
, ext
) == OK
)
4921 STRCPY(buffer
, buf
);
4926 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(PROTO)
4934 else if (error_ga
.ga_data
!= NULL
)
4936 /* avoid putting up a message box with blanks only */
4937 for (p
= (char_u
*)error_ga
.ga_data
; *p
!= NUL
; ++p
)
4940 /* Truncate a very long message, it will go off-screen. */
4941 if (STRLEN(p
) > 2000)
4942 STRCPY(p
+ 2000 - 14, "...(truncated)");
4943 (void)do_dialog(VIM_ERROR
, (char_u
*)_("Error"),
4944 p
, (char_u
*)_("&Ok"), 1, NULL
);
4947 ga_clear(&error_ga
);
4952 #if defined(NO_CONSOLE_INPUT) || defined(PROTO)
4954 * Return TRUE if still starting up and there is no place to enter text.
4955 * For GTK and X11 we check if stderr is not a tty, which means we were
4956 * (probably) started from the desktop. Also check stdin, "vim >& file" does
4957 * allow typing on stdin.
4962 return ((!gui
.in_use
|| gui
.starting
)
4964 && !isatty(0) && !isatty(2)
4970 #if defined(FIND_REPLACE_DIALOG) || defined(FEAT_SUN_WORKSHOP) \
4971 || defined(NEED_GUI_UPDATE_SCREEN) \
4974 * Update the current window and the screen.
4982 /* Trigger CursorMoved if the cursor moved. */
4983 if (!finish_op
&& has_cursormoved()
4984 && !equalpos(last_cursormoved
, curwin
->w_cursor
))
4986 apply_autocmds(EVENT_CURSORMOVED
, NULL
, NULL
, FALSE
, curbuf
);
4987 last_cursormoved
= curwin
->w_cursor
;
4990 update_screen(0); /* may need to update the screen */
4992 out_flush(); /* make sure output has been written */
4993 gui_update_cursor(TRUE
, FALSE
);
4998 #if defined(FIND_REPLACE_DIALOG) || defined(PROTO)
4999 static void concat_esc
__ARGS((garray_T
*gap
, char_u
*text
, int what
));
5002 * Get the text to use in a find/replace dialog. Uses the last search pattern
5003 * if the argument is empty.
5004 * Returns an allocated string.
5007 get_find_dialog_text(arg
, wwordp
, mcasep
)
5009 int *wwordp
; /* return: TRUE if \< \> found */
5010 int *mcasep
; /* return: TRUE if \C found */
5015 text
= last_search_pat();
5020 text
= vim_strsave(text
);
5023 int len
= (int)STRLEN(text
);
5027 if (len
>= 2 && STRNCMP(text
, "\\V", 2) == 0)
5029 mch_memmove(text
, text
+ 2, (size_t)(len
- 1));
5033 /* Recognize "\c" and "\C" and remove. */
5034 if (len
>= 2 && *text
== '\\' && (text
[1] == 'c' || text
[1] == 'C'))
5036 *mcasep
= (text
[1] == 'C');
5037 mch_memmove(text
, text
+ 2, (size_t)(len
- 1));
5041 /* Recognize "\<text\>" and remove. */
5043 && STRNCMP(text
, "\\<", 2) == 0
5044 && STRNCMP(text
+ len
- 2, "\\>", 2) == 0)
5047 mch_memmove(text
, text
+ 2, (size_t)(len
- 4));
5048 text
[len
- 4] = NUL
;
5051 /* Recognize "\/" or "\?" and remove. */
5052 for (i
= 0; i
+ 1 < len
; ++i
)
5053 if (text
[i
] == '\\' && (text
[i
+ 1] == '/'
5054 || text
[i
+ 1] == '?'))
5056 mch_memmove(text
+ i
, text
+ i
+ 1, (size_t)(len
- i
));
5065 * Concatenate "text" to grow array "gap", escaping "what" with a backslash.
5068 concat_esc(gap
, text
, what
)
5073 while (*text
!= NUL
)
5076 int l
= (*mb_ptr2len
)(text
);
5081 ga_append(gap
, *text
++);
5086 ga_append(gap
, '\\');
5087 ga_append(gap
, *text
);
5093 * Handle the press of a button in the find-replace dialog.
5094 * Return TRUE when something was added to the input buffer.
5097 gui_do_findrepl(flags
, find_text
, repl_text
, down
)
5098 int flags
; /* one of FRD_REPLACE, FRD_FINDNEXT, etc. */
5101 int down
; /* Search downwards. */
5105 int type
= (flags
& FRD_TYPE_MASK
);
5107 regmatch_T regmatch
;
5108 int save_did_emsg
= did_emsg
;
5109 static int busy
= FALSE
;
5111 /* When the screen is being updated we should not change buffers and
5112 * windows structures, it may cause freed memory to be used. Also don't
5113 * do this recursively (pressing "Find" quickly several times. */
5114 if (updating_screen
|| busy
)
5117 /* refuse replace when text cannot be changed */
5118 if ((type
== FRD_REPLACE
|| type
== FRD_REPLACEALL
) && text_locked())
5123 ga_init2(&ga
, 1, 100);
5124 if (type
== FRD_REPLACEALL
)
5125 ga_concat(&ga
, (char_u
*)"%s/");
5127 ga_concat(&ga
, (char_u
*)"\\V");
5128 if (flags
& FRD_MATCH_CASE
)
5129 ga_concat(&ga
, (char_u
*)"\\C");
5131 ga_concat(&ga
, (char_u
*)"\\c");
5132 if (flags
& FRD_WHOLE_WORD
)
5133 ga_concat(&ga
, (char_u
*)"\\<");
5134 if (type
== FRD_REPLACEALL
|| down
)
5135 concat_esc(&ga
, find_text
, '/'); /* escape slashes */
5137 concat_esc(&ga
, find_text
, '?'); /* escape '?' */
5138 if (flags
& FRD_WHOLE_WORD
)
5139 ga_concat(&ga
, (char_u
*)"\\>");
5141 if (type
== FRD_REPLACEALL
)
5143 ga_concat(&ga
, (char_u
*)"/");
5144 /* escape / and \ */
5145 p
= vim_strsave_escaped(repl_text
, (char_u
*)"/\\");
5149 ga_concat(&ga
, (char_u
*)"/g");
5151 ga_append(&ga
, NUL
);
5153 if (type
== FRD_REPLACE
)
5155 /* Do the replacement when the text at the cursor matches. Thus no
5156 * replacement is done if the cursor was moved! */
5157 regmatch
.regprog
= vim_regcomp(ga
.ga_data
, RE_MAGIC
+ RE_STRING
);
5159 if (regmatch
.regprog
!= NULL
)
5161 p
= ml_get_cursor();
5162 if (vim_regexec_nl(®match
, p
, (colnr_T
)0)
5163 && regmatch
.startp
[0] == p
)
5165 /* Clear the command line to remove any old "No match"
5169 if (u_save_cursor() == OK
)
5171 /* A button was pressed thus undo should be synced. */
5174 del_bytes((long)(regmatch
.endp
[0] - regmatch
.startp
[0]),
5180 MSG(_("No match at cursor, finding next"));
5181 vim_free(regmatch
.regprog
);
5185 if (type
== FRD_REPLACEALL
)
5187 /* A button was pressed, thus undo should be synced. */
5189 do_cmdline_cmd(ga
.ga_data
);
5193 /* Search for the next match. */
5195 do_search(NULL
, down
? '/' : '?', ga
.ga_data
, 1L,
5196 SEARCH_MSG
+ SEARCH_MARK
, NULL
);
5197 msg_scroll
= i
; /* don't let an error message set msg_scroll */
5200 /* Don't want to pass did_emsg to other code, it may cause disabling
5201 * syntax HL if we were busy redrawing. */
5202 did_emsg
= save_did_emsg
;
5204 if (State
& (NORMAL
| INSERT
))
5206 gui_update_screen(); /* update the screen */
5207 msg_didout
= 0; /* overwrite any message */
5208 need_wait_return
= FALSE
; /* don't wait for return */
5211 vim_free(ga
.ga_data
);
5213 return (ga
.ga_len
> 0);
5218 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \
5219 || defined(FEAT_GUI_MSWIN) \
5220 || defined(FEAT_GUI_MAC) \
5222 || defined(FEAT_GUI_MACVIM)
5225 static void gui_wingoto_xy
__ARGS((int x
, int y
));
5228 * Jump to the window at specified point (x, y).
5231 gui_wingoto_xy(x
, y
)
5235 int row
= Y_2_ROW(y
);
5236 int col
= X_2_COL(x
);
5239 if (row
>= 0 && col
>= 0)
5241 wp
= mouse_find_win(&row
, &col
);
5242 if (wp
!= NULL
&& wp
!= curwin
)
5249 * Process file drop. Mouse cursor position, key modifiers, name of files
5250 * and count of files are given. Argument "fnames[count]" has full pathnames
5251 * of dropped files, they will be freed in this function, and caller can't use
5252 * fnames after call this function.
5255 gui_handle_drop(x
, y
, modifiers
, fnames
, count
)
5264 static int entered
= FALSE
;
5267 * This function is called by event handlers. Just in case we get a
5268 * second event before the first one is handled, ignore the second one.
5269 * Not sure if this can ever happen, just in case.
5276 * When the cursor is at the command line, add the file names to the
5277 * command line, don't edit the files.
5279 if (State
& CMDLINE
)
5281 shorten_filenames(fnames
, count
);
5282 for (i
= 0; i
< count
; ++i
)
5284 if (fnames
[i
] != NULL
)
5287 add_to_input_buf((char_u
*)" ", 1);
5289 /* We don't know what command is used thus we can't be sure
5290 * about which characters need to be escaped. Only escape the
5291 * most common ones. */
5292 # ifdef BACKSLASH_IN_FILENAME
5293 p
= vim_strsave_escaped(fnames
[i
], (char_u
*)" \t\"|");
5295 p
= vim_strsave_escaped(fnames
[i
], (char_u
*)"\\ \t\"|");
5298 add_to_input_buf_csi(p
, (int)STRLEN(p
));
5300 vim_free(fnames
[i
]);
5307 /* Go to the window under mouse cursor, then shorten given "fnames" by
5308 * current window, because a window can have local current dir. */
5309 # ifdef FEAT_WINDOWS
5310 gui_wingoto_xy(x
, y
);
5312 shorten_filenames(fnames
, count
);
5314 /* If Shift held down, remember the first item. */
5315 if ((modifiers
& MOUSE_SHIFT
) != 0)
5316 p
= vim_strsave(fnames
[0]);
5320 /* Handle the drop, :edit or :split to get to the file. This also
5321 * frees fnames[]. Skip this if there is only one item it's a
5322 * directory and Shift is held down. */
5323 if (count
== 1 && (modifiers
& MOUSE_SHIFT
) != 0
5324 && mch_isdir(fnames
[0]))
5326 vim_free(fnames
[0]);
5330 handle_drop(count
, fnames
, (modifiers
& MOUSE_CTRL
) != 0);
5332 /* If Shift held down, change to first file's directory. If the first
5333 * item is a directory, change to that directory (and let the explorer
5334 * plugin show the contents). */
5339 if (mch_chdir((char *)p
) == 0)
5340 shorten_fnames(TRUE
);
5342 else if (vim_chdirfile(p
) == OK
)
5343 shorten_fnames(TRUE
);
5347 /* Update the screen display */
5348 update_screen(NOT_VALID
);
5350 gui_update_menus(0);
5354 gui_update_cursor(FALSE
, FALSE
);