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__)
65 static int recursive
= 0;
67 old_term
= vim_strsave(T_NAME
);
70 * Set_termname() will call gui_init() to start the GUI.
71 * Set the "starting" flag, to indicate that the GUI will start.
73 * We don't want to open the GUI shell until after we've read .gvimrc,
74 * otherwise we don't know what font we will use, and hence we don't know
75 * what size the shell should be. So if there are errors in the .gvimrc
76 * file, they will have to go to the terminal: Set full_screen to FALSE.
77 * full_screen will be set to TRUE again by a successful termcapinit().
79 settmode(TMODE_COOK
); /* stop RAW mode */
81 cursor_on(); /* needed for ":gui" in .vimrc */
86 if (!gui
.dofork
|| vim_strchr(p_go
, GO_FORG
) || recursive
)
91 termcapinit((char_u
*)"builtin_gui");
92 gui
.starting
= recursive
- 1;
94 if (!gui
.in_use
) /* failed to start GUI */
96 termcapinit(old_term
); /* back to old term settings */
97 settmode(TMODE_RAW
); /* restart RAW mode */
99 set_title_defaults(); /* set 'title' and 'icon' again */
105 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
107 /* Display error messages in a dialog now. */
111 #if defined(MAY_FORK) && !defined(__QNXNTO__)
113 * Quit the current process and continue in the child.
114 * Makes "gvim file" disconnect from the shell it was started in.
115 * Don't do this when Vim was started with "-f" or the 'f' flag is present
118 if (gui
.in_use
&& dofork
)
125 /* on os x, you have to exec after a fork, otherwise calls to
126 * frameworks will assert (and without corefoundation, you can't start
127 * the gui. what fun.). See CAVEATS at
128 http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/fork.2.html
130 * Since we have to go through this anyways, we might as well use vfork.
131 * But: then we can't detach from our starting shell, so stick with
134 * Kinda sucks to restart vim when doing :gui, so don't fork in that
135 * case (make sure gui.dofork is only set when interpreting argv, not
136 * when doing :gui. Currently, gui.dofork is set to false in ex_gui().
138 * Also doesn't work well if vim starts cscope (or some other
139 * subprocess I guess), because it's not transferred to the newly
140 * exec'd process, leaving an orphaned process (not a zombie process)
141 * behind. The Right Thing is to kill all our child processes before
145 /* stolen from http://paste.lisp.org/display/50906 */
146 extern int *_NSGetArgc(void);
147 extern char ***_NSGetArgv(void);
149 int argc
= *_NSGetArgc();
150 char ** argv
= *_NSGetArgv();
151 char * newargv
[argc
+2];
153 for (i
= 0; i
< argc
; i
++) {
154 newargv
[i
] = argv
[i
];
156 newargv
[argc
] = "-f";
157 newargv
[argc
+1] = NULL
;
163 fprintf(stderr
, "vim: Mac OS X workaround fork() failed!");
169 /* shut down all the stuff we just started, just to start
170 * it again from the exec :-\ */
173 /* make sure we survive our shell */
176 /* Restarts the vim process, will not return. */
177 execvp(argv
[0], newargv
);
179 /* if we come here, exec has failed. bail. */
186 int pipefd
[2]; /* pipe between parent and child */
190 /* Setup a pipe between the child and the parent, so that the parent
191 * knows when the child has done the setsid() call and is allowed to
193 pipe_error
= (pipe(pipefd
) < 0);
195 if (pid
> 0) /* Parent */
197 /* Give the child some time to do the setsid(), otherwise the
198 * exit() may kill the child too (when starting gvim from inside a
201 ui_delay(300L, TRUE
);
204 /* The read returns when the child closes the pipe (or when
205 * the child dies for some reason). */
207 (void)read(pipefd
[0], &dummy
, (size_t)1);
211 /* When swapping screens we may need to go to the next line, e.g.,
212 * after a hit-enter prompt and using ":gui". */
217 * The parent must skip the normal exit() processing, the child
218 * will do it. For example, GTK messes up signals when exiting.
223 # if defined(HAVE_SETSID) || defined(HAVE_SETPGID)
225 * Change our process group. On some systems/shells a CTRL-C in the
226 * shell where Vim was started would otherwise kill gvim!
228 if (pid
== 0) /* child */
229 # if defined(HAVE_SETSID)
242 # if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)
243 /* Tell the session manager our new PID */
250 # if defined(__QNXNTO__)
251 if (gui
.in_use
&& dofork
)
252 procmgr_daemon(0, PROCMGR_DAEMON_KEEPUMASK
| PROCMGR_DAEMON_NOCHDIR
|
253 PROCMGR_DAEMON_NOCLOSE
| PROCMGR_DAEMON_NODEVNULL
);
258 /* If the GUI started successfully, trigger the GUIEnter event, otherwise
259 * the GUIFailed event. */
260 apply_autocmds(gui
.in_use
? EVENT_GUIENTER
: EVENT_GUIFAILED
,
261 NULL
, NULL
, FALSE
, curbuf
);
268 * Call this when vim starts up, whether or not the GUI is started
271 gui_prepare(argc
, argv
)
275 gui
.in_use
= FALSE
; /* No GUI yet (maybe later) */
276 gui
.starting
= FALSE
; /* No GUI yet (maybe later) */
277 gui_mch_prepare(argc
, argv
);
281 * Try initializing the GUI and check if it can be started.
282 * Used from main() to check early if "vim -g" can start the GUI.
283 * Used from gui_init() to prepare for starting the GUI.
284 * Returns FAIL or OK.
289 static int result
= MAYBE
;
294 EMSG(_("E229: Cannot start the GUI"));
298 gui
.shell_created
= FALSE
;
300 gui
.in_focus
= TRUE
; /* so the guicursor setting works */
301 gui
.dragged_sb
= SBAR_NONE
;
302 gui
.dragged_wp
= NULL
;
303 gui
.pointer_hidden
= FALSE
;
306 gui
.num_cols
= Columns
;
309 gui
.cursor_is_valid
= FALSE
;
310 gui
.scroll_region_top
= 0;
311 gui
.scroll_region_bot
= Rows
- 1;
312 gui
.scroll_region_left
= 0;
313 gui
.scroll_region_right
= Columns
- 1;
314 gui
.highlight_mask
= HL_NORMAL
;
318 gui
.border_width
= 0;
320 gui
.norm_font
= NOFONT
;
322 gui
.bold_font
= NOFONT
;
323 gui
.ital_font
= NOFONT
;
324 gui
.boldital_font
= NOFONT
;
325 # ifdef FEAT_XFONTSET
326 gui
.fontset
= NOFONTSET
;
332 # ifdef FONTSET_ALWAYS
333 gui
.menu_fontset
= NOFONTSET
;
335 gui
.menu_font
= NOFONT
;
338 gui
.menu_is_active
= TRUE
; /* default: include menu */
339 # if !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM))
340 gui
.menu_height
= MENU_DEFAULT_HEIGHT
;
344 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA))
345 gui
.toolbar_height
= 0;
347 #if defined(FEAT_FOOTER) && defined(FEAT_GUI_MOTIF)
348 gui
.footer_height
= 0;
350 #ifdef FEAT_BEVAL_TIP
351 gui
.tooltip_fontset
= NOFONTSET
;
354 gui
.scrollbar_width
= gui
.scrollbar_height
= SB_DEFAULT_WIDTH
;
357 #ifdef ALWAYS_USE_GUI
360 result
= gui_mch_init_check();
366 * This is the call which starts the GUI.
372 static int recursive
= 0;
375 * It's possible to use ":gui" in a .gvimrc file. The first halve of this
376 * function will then be executed at the first call, the rest by the
377 * recursive call. This allow the shell to be opened halfway reading a
386 /* If can't initialize, don't try doing the rest */
387 if (gui_init_check() == FAIL
)
395 * Reset 'paste'. It's useful in the terminal, but not in the GUI. It
396 * breaks the Paste toolbar button.
398 set_option_value((char_u
*)"paste", 0L, NULL
, 0);
401 * Set up system-wide default menus.
403 #if defined(SYS_MENU_FILE) && defined(FEAT_MENU)
404 if (vim_strchr(p_go
, GO_NOSYSMENU
) == NULL
)
407 do_source((char_u
*)SYS_MENU_FILE
, FALSE
, DOSO_NONE
);
413 * Switch on the mouse by default, unless the user changed it already.
414 * This can then be changed in the .gvimrc.
416 if (!option_was_set((char_u
*)"mouse"))
417 set_string_option_direct((char_u
*)"mouse", -1,
418 (char_u
*)"a", OPT_FREE
, SID_NONE
);
421 * If -U option given, use only the initializations from that file and
422 * nothing else. Skip all initializations for "-U NONE" or "-u NORC".
424 if (use_gvimrc
!= NULL
)
426 if (STRCMP(use_gvimrc
, "NONE") != 0
427 && STRCMP(use_gvimrc
, "NORC") != 0
428 && do_source(use_gvimrc
, FALSE
, DOSO_NONE
) != OK
)
429 EMSG2(_("E230: Cannot read from \"%s\""), use_gvimrc
);
434 * Get system wide defaults for gvim, only when file name defined.
436 #ifdef SYS_GVIMRC_FILE
437 do_source((char_u
*)SYS_GVIMRC_FILE
, FALSE
, DOSO_NONE
);
441 * Try to read GUI initialization commands from the following
443 * - environment variable GVIMINIT
444 * - the user gvimrc file (~/.gvimrc)
445 * - the second user gvimrc file ($VIM/.gvimrc for Dos)
446 * - the third user gvimrc file ($VIM/.gvimrc for Amiga)
447 * The first that exists is used, the rest is ignored.
449 if (process_env((char_u
*)"GVIMINIT", FALSE
) == FAIL
450 && do_source((char_u
*)USR_GVIMRC_FILE
, TRUE
,
452 #ifdef USR_GVIMRC_FILE2
453 && do_source((char_u
*)USR_GVIMRC_FILE2
, TRUE
,
458 #ifdef USR_GVIMRC_FILE3
459 (void)do_source((char_u
*)USR_GVIMRC_FILE3
, TRUE
, DOSO_GVIMRC
);
464 * Read initialization commands from ".gvimrc" in current
465 * directory. This is only done if the 'exrc' option is set.
466 * Because of security reasons we disallow shell and write
467 * commands now, except for unix if the file is owned by the user
468 * or 'secure' option has been reset in environment of global
470 * Only do this if GVIMRC_FILE is not the same as USR_GVIMRC_FILE,
471 * USR_GVIMRC_FILE2, USR_GVIMRC_FILE3 or SYS_GVIMRC_FILE.
479 /* if ".gvimrc" file is not owned by user, set 'secure'
481 if (mch_stat(GVIMRC_FILE
, &s
) || s
.st_uid
!= getuid())
488 if ( fullpathcmp((char_u
*)USR_GVIMRC_FILE
,
489 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
490 #ifdef SYS_GVIMRC_FILE
491 && fullpathcmp((char_u
*)SYS_GVIMRC_FILE
,
492 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
494 #ifdef USR_GVIMRC_FILE2
495 && fullpathcmp((char_u
*)USR_GVIMRC_FILE2
,
496 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
498 #ifdef USR_GVIMRC_FILE3
499 && fullpathcmp((char_u
*)USR_GVIMRC_FILE3
,
500 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
503 do_source((char_u
*)GVIMRC_FILE
, TRUE
, DOSO_GVIMRC
);
506 need_wait_return
= TRUE
;
511 if (need_wait_return
|| msg_didany
)
517 /* If recursive call opened the shell, return here from the first call */
522 * Create the GUI shell.
524 gui
.in_use
= TRUE
; /* Must be set after menus have been set up */
525 if (gui_mch_init() == FAIL
)
528 /* Avoid a delay for an error message that was printed in the terminal
529 * where Vim was started. */
530 emsg_on_display
= FALSE
;
533 need_wait_return
= FALSE
;
537 * Check validity of any generic resources that may have been loaded.
539 if (gui
.border_width
< 0)
540 gui
.border_width
= 0;
543 * Set up the fonts. First use a font specified with "-fn" or "-font".
545 if (font_argument
!= NULL
)
546 set_option_value((char_u
*)"gfn", 0L, (char_u
*)font_argument
, 0);
549 (*p_guifontset
== NUL
550 || gui_init_font(p_guifontset
, TRUE
) == FAIL
) &&
552 gui_init_font(*p_guifont
== NUL
? hl_get_font_name()
553 : p_guifont
, FALSE
) == FAIL
)
555 EMSG(_("E665: Cannot start GUI, no valid font found"));
559 if (gui_get_wide_font() == FAIL
)
560 EMSG(_("E231: 'guifontwide' invalid"));
563 gui
.num_cols
= Columns
;
565 gui_reset_scroll_region();
567 /* Create initial scrollbars */
570 gui_create_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
], SBAR_LEFT
, wp
);
571 gui_create_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
], SBAR_RIGHT
, wp
);
573 gui_create_scrollbar(&gui
.bottom_sbar
, SBAR_BOTTOM
, NULL
);
576 gui_create_initial_menus(root_menu
);
578 #ifdef FEAT_SUN_WORKSHOP
579 if (usingSunWorkShop
)
582 #ifdef FEAT_SIGN_ICONS
586 /* Configure the desired menu and scrollbars */
587 gui_init_which_components(NULL
);
589 /* All components of the GUI have been created now */
590 gui
.shell_created
= TRUE
;
593 /* Set the shell size, adjusted for the screen size. For GTK this only
594 * works after the shell has been opened, thus it is further down. */
595 gui_set_shellsize(FALSE
, TRUE
, RESIZE_BOTH
);
597 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)
598 /* Need to set the size of the menubar after all the menus have been
600 gui_mch_compute_menu_height((Widget
)0);
604 * Actually open the GUI shell.
606 if (gui_mch_open() != FAIL
)
614 /* Our GUI can't do bidi. */
617 #if defined(FEAT_GUI_GTK)
618 /* Give GTK+ a chance to put all widget's into place. */
622 /* If there is no 'm' in 'guioptions' we need to remove the menu now.
623 * It was still there to make F10 work. */
624 if (vim_strchr(p_go
, GO_MENUS
) == NULL
)
627 gui_mch_enable_menu(FALSE
);
633 /* Now make sure the shell fits on the screen. */
634 gui_set_shellsize(FALSE
, TRUE
, RESIZE_BOTH
);
636 /* When 'lines' was set while starting up the topframe may have to be
641 /* Always create the Balloon Evaluation area, but disable it when
642 * 'ballooneval' is off */
644 balloonEval
= gui_mch_create_beval_area(gui
.drawarea
, NULL
,
645 &general_beval_cb
, NULL
);
647 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
649 extern Widget textArea
;
650 balloonEval
= gui_mch_create_beval_area(textArea
, NULL
,
651 &general_beval_cb
, NULL
);
655 balloonEval
= gui_mch_create_beval_area(NULL
, NULL
,
656 &general_beval_cb
, NULL
);
661 gui_mch_disable_beval_area(balloonEval
);
664 #ifdef FEAT_NETBEANS_INTG
665 if (starting
== 0 && usingNetbeans
)
666 /* Tell the client that it can start sending commands. */
667 netbeans_startup_done();
669 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
670 if (!im_xim_isvalid_imactivate())
671 EMSG(_("E599: Value of 'imactivatekey' is invalid"));
673 /* When 'cmdheight' was set during startup it may not have taken
683 /* undo gui_mch_init() */
698 /* don't free the fonts, it leads to a BUS error
699 * richard@whitequeen.com Jul 99 */
700 free_highlight_fonts();
706 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_MSWIN) \
707 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) \
708 || defined(PROTO) || defined(FEAT_GUI_MACVIM)
709 # define NEED_GUI_UPDATE_SCREEN 1
711 * Called when the GUI shell is closed by the user. If there are no changed
712 * files Vim exits, otherwise there will be a dialog to ask the user what to
714 * When this function returns, Vim should NOT exit!
719 cmdmod_T save_cmdmod
;
721 save_cmdmod
= cmdmod
;
723 /* Only exit when there are no changed files */
726 cmdmod
.browse
= TRUE
;
728 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
729 cmdmod
.confirm
= TRUE
;
731 /* If there are changed buffers, present the user with a dialog if
732 * possible, otherwise give an error message. */
733 if (!check_changed_any(FALSE
))
737 cmdmod
= save_cmdmod
;
738 gui_update_screen(); /* redraw, window may show changed buffer */
743 * Set the font. "font_list" is a a comma separated list of font names. The
744 * first font name that works is used. If none is found, use the default
746 * If "fontset" is TRUE, the "font_list" is used as one name for the fontset.
747 * Return OK when able to set the font. When it failed FAIL is returned and
748 * the fonts are unchanged.
752 gui_init_font(font_list
, fontset
)
757 char_u font_name
[FONTLEN
];
758 int font_list_empty
= FALSE
;
765 if (*font_list
== NUL
)
766 font_list_empty
= TRUE
;
770 /* When using a fontset, the whole list of fonts is one name. */
772 ret
= gui_mch_init_font(font_list
, TRUE
);
775 while (*font_list
!= NUL
)
777 /* Isolate one comma separated font name. */
778 (void)copy_option_part(&font_list
, font_name
, FONTLEN
, ",");
780 #if defined(FEAT_GUI_MACVIM)
781 /* The font dialog is modeless in Mac OS X, so when
782 * gui_mch_init_font() is called with "*" it brings up the
783 * dialog and returns immediately. In this case we don't want
784 * it to be called again with NULL, so return here. */
785 if (STRCMP(font_name
, "*") == 0) {
786 gui_mch_init_font(font_name
, FALSE
);
791 /* Careful!!! The Win32 version of gui_mch_init_font(), when
792 * called with "*" will change p_guifont to the selected font
793 * name, which frees the old value. This makes font_list
794 * invalid. Thus when OK is returned here, font_list must no
796 if (gui_mch_init_font(font_name
, FALSE
) == OK
)
798 #if defined(FEAT_MBYTE) && !defined(HAVE_GTK2)
799 /* If it's a Unicode font, try setting 'guifontwide' to a
800 * similar double-width font. */
801 if ((p_guifontwide
== NULL
|| *p_guifontwide
== NUL
)
802 && strstr((char *)font_name
, "10646") != NULL
)
803 set_guifontwide(font_name
);
812 && STRCMP(font_list
, "*") != 0
813 && (font_list_empty
|| gui
.norm_font
== NOFONT
))
816 * Couldn't load any font in 'font_list', keep the current font if
817 * there is one. If 'font_list' is empty, or if there is no current
818 * font, tell gui_mch_init_font() to try to find a font we can load.
820 ret
= gui_mch_init_font(NULL
, FALSE
);
826 /* Set normal font as current font */
827 # ifdef FEAT_XFONTSET
828 if (gui
.fontset
!= NOFONTSET
)
829 gui_mch_set_fontset(gui
.fontset
);
832 gui_mch_set_font(gui
.norm_font
);
834 gui_set_shellsize(FALSE
,
846 #if defined(FEAT_MBYTE) || defined(PROTO)
849 * Try setting 'guifontwide' to a font twice as wide as "name".
852 set_guifontwide(name
)
856 char_u wide_name
[FONTLEN
+ 10]; /* room for 2 * width and '*' */
862 for (p
= name
; *p
!= NUL
; ++p
)
868 if (i
== 6) /* font type: change "--" to "-*-" */
873 else if (i
== 12) /* found the width */
879 /* Double the width specification. */
880 sprintf((char *)wp
, "%d%s", i
* 2, p
);
881 font
= gui_mch_get_font(wide_name
, FALSE
);
884 gui_mch_free_font(gui
.wide_font
);
885 gui
.wide_font
= font
;
886 set_string_option_direct((char_u
*)"gfw", -1,
887 wide_name
, OPT_FREE
, 0);
895 # endif /* !HAVE_GTK2 */
898 * Get the font for 'guifontwide'.
899 * Return FAIL for an invalid font name.
904 GuiFont font
= NOFONT
;
905 char_u font_name
[FONTLEN
];
908 if (!gui
.in_use
) /* Can't allocate font yet, assume it's OK. */
909 return OK
; /* Will give an error message later. */
911 if (p_guifontwide
!= NULL
&& *p_guifontwide
!= NUL
)
913 for (p
= p_guifontwide
; *p
!= NUL
; )
915 /* Isolate one comma separated font name. */
916 (void)copy_option_part(&p
, font_name
, FONTLEN
, ",");
917 font
= gui_mch_get_font(font_name
, FALSE
);
925 gui_mch_free_font(gui
.wide_font
);
927 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */
928 if (font
!= NOFONT
&& gui
.norm_font
!= NOFONT
929 && pango_font_description_equal(font
, gui
.norm_font
))
931 gui
.wide_font
= NOFONT
;
932 gui_mch_free_font(font
);
936 gui
.wide_font
= font
;
942 gui_set_cursor(row
, col
)
951 * gui_check_pos - check if the cursor is on the screen.
956 if (gui
.row
>= screen_Rows
)
957 gui
.row
= screen_Rows
- 1;
958 if (gui
.col
>= screen_Columns
)
959 gui
.col
= screen_Columns
- 1;
960 if (gui
.cursor_row
>= screen_Rows
|| gui
.cursor_col
>= screen_Columns
)
961 gui
.cursor_is_valid
= FALSE
;
965 * Redraw the cursor if necessary or when forced.
966 * Careful: The contents of ScreenLines[] must match what is on the screen,
967 * otherwise this goes wrong. May need to call out_flush() first.
970 gui_update_cursor(force
, clear_selection
)
971 int force
; /* when TRUE, update even when not moved */
972 int clear_selection
;/* clear selection under cursor */
979 guicolor_T cfg
, cbg
, cc
; /* cursor fore-/background color */
980 int cattr
; /* cursor attributes */
982 attrentry_T
*aep
= NULL
;
984 /* Don't update the cursor when halfway busy scrolling.
985 * ScreenLines[] isn't valid then. */
986 if (!can_update_cursor
)
990 if (!gui
.cursor_is_valid
|| force
991 || gui
.row
!= gui
.cursor_row
|| gui
.col
!= gui
.cursor_col
)
996 #ifdef USE_IM_CONTROL
997 if (gui
.row
!= gui
.cursor_row
|| gui
.col
!= gui
.cursor_col
)
998 im_set_position(gui
.row
, gui
.col
);
1000 gui
.cursor_row
= gui
.row
;
1001 gui
.cursor_col
= gui
.col
;
1003 /* Only write to the screen after ScreenLines[] has been initialized */
1004 if (!screen_cleared
|| ScreenLines
== NULL
)
1007 /* Clear the selection if we are about to write over it */
1008 if (clear_selection
)
1009 clip_may_clear_selection(gui
.row
, gui
.row
);
1010 /* Check that the cursor is inside the shell (resizing may have made
1012 if (gui
.row
>= screen_Rows
|| gui
.col
>= screen_Columns
)
1015 gui
.cursor_is_valid
= TRUE
;
1018 * How the cursor is drawn depends on the current mode.
1020 idx
= get_shape_idx(FALSE
);
1021 if (State
& LANGMAP
)
1022 id
= shape_table
[idx
].id_lm
;
1024 id
= shape_table
[idx
].id
;
1026 /* get the colors and attributes for the cursor. Default is inverted */
1030 gui_mch_set_blinking(shape_table
[idx
].blinkwait
,
1031 shape_table
[idx
].blinkon
,
1032 shape_table
[idx
].blinkoff
);
1035 cattr
= syn_id2colors(id
, &cfg
, &cbg
);
1036 #if defined(USE_IM_CONTROL) || defined(FEAT_HANGULIN)
1041 if (im_get_status())
1043 iid
= syn_name2id((char_u
*)"CursorIM");
1046 syn_id2colors(iid
, &fg
, &bg
);
1047 if (bg
!= INVALCOLOR
)
1049 if (fg
!= INVALCOLOR
)
1058 * Get the attributes for the character under the cursor.
1059 * When no cursor color was given, use the character color.
1061 attr
= ScreenAttrs
[LineOffset
[gui
.row
] + gui
.col
];
1063 aep
= syn_gui_attr2entry(attr
);
1066 attr
= aep
->ae_attr
;
1067 if (cfg
== INVALCOLOR
)
1068 cfg
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.bg_color
1069 : aep
->ae_u
.gui
.fg_color
);
1070 if (cbg
== INVALCOLOR
)
1071 cbg
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.fg_color
1072 : aep
->ae_u
.gui
.bg_color
);
1074 if (cfg
== INVALCOLOR
)
1075 cfg
= (attr
& HL_INVERSE
) ? gui
.back_pixel
: gui
.norm_pixel
;
1076 if (cbg
== INVALCOLOR
)
1077 cbg
= (attr
& HL_INVERSE
) ? gui
.norm_pixel
: gui
.back_pixel
;
1082 xim_bg_color
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.fg_color
1083 : aep
->ae_u
.gui
.bg_color
);
1084 xim_fg_color
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.bg_color
1085 : aep
->ae_u
.gui
.fg_color
);
1086 if (xim_bg_color
== INVALCOLOR
)
1087 xim_bg_color
= (attr
& HL_INVERSE
) ? gui
.norm_pixel
1089 if (xim_fg_color
== INVALCOLOR
)
1090 xim_fg_color
= (attr
& HL_INVERSE
) ? gui
.back_pixel
1095 xim_bg_color
= (attr
& HL_INVERSE
) ? gui
.norm_pixel
1097 xim_fg_color
= (attr
& HL_INVERSE
) ? gui
.back_pixel
1102 attr
&= ~HL_INVERSE
;
1103 if (cattr
& HL_INVERSE
)
1109 cattr
&= ~HL_INVERSE
;
1112 * When we don't have window focus, draw a hollow cursor.
1116 gui_mch_draw_hollow_cursor(cbg
);
1120 old_hl_mask
= gui
.highlight_mask
;
1121 if (shape_table
[idx
].shape
== SHAPE_BLOCK
1122 #ifdef FEAT_HANGULIN
1128 * Draw the text character with the cursor colors. Use the
1129 * character attributes plus the cursor attributes.
1131 gui
.highlight_mask
= (cattr
| attr
);
1132 #ifdef FEAT_HANGULIN
1133 if (composing_hangul
)
1134 (void)gui_outstr_nowrap(composing_hangul_buffer
, 2,
1135 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
, cfg
, cbg
, 0);
1138 (void)gui_screenchar(LineOffset
[gui
.row
] + gui
.col
,
1139 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
, cfg
, cbg
, 0);
1143 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT)
1144 int col_off
= FALSE
;
1147 * First draw the partial cursor, then overwrite with the text
1148 * character, using a transparent background.
1150 if (shape_table
[idx
].shape
== SHAPE_VER
)
1152 cur_height
= gui
.char_height
;
1153 cur_width
= (gui
.char_width
* shape_table
[idx
].percentage
1158 cur_height
= (gui
.char_height
* shape_table
[idx
].percentage
1160 cur_width
= gui
.char_width
;
1163 if (has_mbyte
&& (*mb_off2cells
)(LineOffset
[gui
.row
] + gui
.col
,
1164 LineOffset
[gui
.row
] + screen_Columns
) > 1)
1166 /* Double wide character. */
1167 if (shape_table
[idx
].shape
!= SHAPE_VER
)
1168 cur_width
+= gui
.char_width
;
1169 # ifdef FEAT_RIGHTLEFT
1170 if (CURSOR_BAR_RIGHT
)
1172 /* gui.col points to the left halve of the character but
1173 * the vertical line needs to be on the right halve.
1174 * A double-wide horizontal line is also drawn from the
1175 * right halve in gui_mch_draw_part_cursor(). */
1182 gui_mch_draw_part_cursor(cur_width
, cur_height
, cbg
);
1183 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT)
1188 #ifndef FEAT_GUI_MSWIN /* doesn't seem to work for MSWindows */
1189 gui
.highlight_mask
= ScreenAttrs
[LineOffset
[gui
.row
] + gui
.col
];
1190 (void)gui_screenchar(LineOffset
[gui
.row
] + gui
.col
,
1191 GUI_MON_TRS_CURSOR
| GUI_MON_NOCLEAR
,
1192 (guicolor_T
)0, (guicolor_T
)0, 0);
1195 gui
.highlight_mask
= old_hl_mask
;
1199 #if defined(FEAT_MENU) || defined(PROTO)
1203 # if !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \
1204 || defined(FEAT_GUI_MACVIM))
1205 if (gui
.menu_is_active
&& gui
.in_use
)
1206 gui_mch_set_menu_pos(0, 0, gui
.menu_width
, gui
.menu_height
);
1212 * Position the various GUI components (text area, menu). The vertical
1213 * scrollbars are NOT handled here. See gui_update_scrollbars().
1217 gui_position_components(total_width
)
1222 int text_area_width
;
1223 int text_area_height
;
1225 /* avoid that moving components around generates events */
1229 if (gui
.which_scrollbars
[SBAR_LEFT
])
1230 text_area_x
+= gui
.scrollbar_width
;
1233 #if defined(FEAT_MENU) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON) \
1234 || defined(FEAT_GUI_MACVIM))
1235 gui
.menu_width
= total_width
;
1236 if (gui
.menu_is_active
)
1237 text_area_y
+= gui
.menu_height
;
1239 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_MSWIN)
1240 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
1241 text_area_y
= TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
;
1244 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
1245 || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_MAC))
1246 if (gui_has_tabline())
1247 text_area_y
+= gui
.tabline_height
;
1250 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA))
1251 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
1253 # ifdef FEAT_GUI_ATHENA
1254 gui_mch_set_toolbar_pos(0, text_area_y
,
1255 gui
.menu_width
, gui
.toolbar_height
);
1257 text_area_y
+= gui
.toolbar_height
;
1261 text_area_width
= gui
.num_cols
* gui
.char_width
+ gui
.border_offset
* 2;
1262 text_area_height
= gui
.num_rows
* gui
.char_height
+ gui
.border_offset
* 2;
1264 gui_mch_set_text_area_pos(text_area_x
,
1268 #if defined(FEAT_XIM) && !defined(HAVE_GTK2)
1269 + xim_get_status_area_height()
1273 gui_position_menu();
1275 if (gui
.which_scrollbars
[SBAR_BOTTOM
])
1276 gui_mch_set_scrollbar_pos(&gui
.bottom_sbar
,
1278 text_area_y
+ text_area_height
,
1280 gui
.scrollbar_height
);
1281 gui
.left_sbar_x
= 0;
1282 gui
.right_sbar_x
= text_area_x
+ text_area_width
;
1288 * Get the width of the widgets and decorations to the side of the text area.
1291 gui_get_base_width()
1295 base_width
= 2 * gui
.border_offset
;
1296 if (gui
.which_scrollbars
[SBAR_LEFT
])
1297 base_width
+= gui
.scrollbar_width
;
1298 if (gui
.which_scrollbars
[SBAR_RIGHT
])
1299 base_width
+= gui
.scrollbar_width
;
1304 * Get the height of the widgets and decorations above and below the text area.
1307 gui_get_base_height()
1311 base_height
= 2 * gui
.border_offset
;
1312 if (gui
.which_scrollbars
[SBAR_BOTTOM
])
1313 base_height
+= gui
.scrollbar_height
;
1315 /* We can't take the sizes properly into account until anything is
1316 * realized. Therefore we recalculate all the values here just before
1317 * setting the size. (--mdcki) */
1318 #elif !defined(FEAT_GUI_MACVIM)
1320 if (gui
.menu_is_active
)
1321 base_height
+= gui
.menu_height
;
1323 # ifdef FEAT_TOOLBAR
1324 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
1325 # if defined(FEAT_GUI_MSWIN) && defined(FEAT_TOOLBAR)
1326 base_height
+= (TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
);
1328 base_height
+= gui
.toolbar_height
;
1331 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
1332 || defined(FEAT_GUI_MOTIF))
1333 if (gui_has_tabline())
1334 base_height
+= gui
.tabline_height
;
1337 if (vim_strchr(p_go
, GO_FOOTER
) != NULL
)
1338 base_height
+= gui
.footer_height
;
1340 # if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)
1341 base_height
+= gui_mch_text_area_extra_height();
1348 * Should be called after the GUI shell has been resized. Its arguments are
1349 * the new width and height of the shell in pixels.
1352 gui_resize_shell(pixel_width
, pixel_height
)
1356 static int busy
= FALSE
;
1358 if (!gui
.shell_created
) /* ignore when still initializing */
1362 * Can't resize the screen while it is being redrawn. Remember the new
1363 * size and handle it later.
1365 if (updating_screen
|| busy
)
1367 new_pixel_width
= pixel_width
;
1368 new_pixel_height
= pixel_height
;
1375 /* Flush pending output before redrawing */
1378 gui
.num_cols
= (pixel_width
- gui_get_base_width()) / gui
.char_width
;
1379 gui
.num_rows
= (pixel_height
- gui_get_base_height()
1380 #if !defined(FEAT_GUI_PHOTON) && !defined(FEAT_GUI_MSWIN)
1381 + (gui
.char_height
/ 2)
1383 ) / gui
.char_height
;
1385 gui_position_components(pixel_width
);
1387 gui_reset_scroll_region();
1389 * At the "more" and ":confirm" prompt there is no redraw, put the cursor
1390 * at the last line here (why does it have to be one row too low?).
1392 if (State
== ASKMORE
|| State
== CONFIRM
)
1393 gui
.row
= gui
.num_rows
;
1395 /* Only comparing Rows and Columns may be sufficient, but let's stay on
1397 if (gui
.num_rows
!= screen_Rows
|| gui
.num_cols
!= screen_Columns
1398 || gui
.num_rows
!= Rows
|| gui
.num_cols
!= Columns
)
1401 gui_update_scrollbars(TRUE
);
1402 gui_update_cursor(FALSE
, TRUE
);
1403 #if defined(FEAT_XIM) && !defined(HAVE_GTK2)
1404 xim_set_status_area();
1410 * We could have been called again while redrawing the screen.
1411 * Need to do it all again with the latest size then.
1413 if (new_pixel_height
)
1415 pixel_width
= new_pixel_width
;
1416 pixel_height
= new_pixel_height
;
1417 new_pixel_width
= 0;
1418 new_pixel_height
= 0;
1424 * Check if gui_resize_shell() must be called.
1427 gui_may_resize_shell()
1431 if (new_pixel_height
)
1433 /* careful: gui_resize_shell() may postpone the resize again if we
1434 * were called indirectly by it */
1435 w
= new_pixel_width
;
1436 h
= new_pixel_height
;
1437 new_pixel_width
= 0;
1438 new_pixel_height
= 0;
1439 gui_resize_shell(w
, h
);
1446 Rows
= gui
.num_rows
;
1447 Columns
= gui
.num_cols
;
1452 * Set the size of the Vim shell according to Rows and Columns.
1453 * If "fit_to_display" is TRUE then the size may be reduced to fit the window
1458 gui_set_shellsize(mustset
, fit_to_display
, direction
)
1459 int mustset
; /* set by the user */
1461 int direction
; /* RESIZE_HOR, RESIZE_VER */
1472 if (!gui
.shell_created
)
1476 /* If not setting to a user specified size and maximized, calculate the
1477 * number of characters that fit in the maximized window. */
1478 if (!mustset
&& gui_mch_maximized())
1485 base_width
= gui_get_base_width();
1486 base_height
= gui_get_base_height();
1487 #ifdef USE_SUN_WORKSHOP
1488 if (!mustset
&& usingSunWorkShop
1489 && workshop_get_width_height(&width
, &height
))
1491 Columns
= (width
- base_width
+ gui
.char_width
- 1) / gui
.char_width
;
1492 Rows
= (height
- base_height
+ gui
.char_height
- 1) / gui
.char_height
;
1497 width
= Columns
* gui
.char_width
+ base_width
;
1498 height
= Rows
* gui
.char_height
+ base_height
;
1503 gui_mch_get_screen_dimensions(&screen_w
, &screen_h
);
1504 if ((direction
& RESIZE_HOR
) && width
> screen_w
)
1506 Columns
= (screen_w
- base_width
) / gui
.char_width
;
1507 if (Columns
< MIN_COLUMNS
)
1508 Columns
= MIN_COLUMNS
;
1509 width
= Columns
* gui
.char_width
+ base_width
;
1511 if ((direction
& RESIZE_VERT
) && height
> screen_h
)
1513 Rows
= (screen_h
- base_height
) / gui
.char_height
;
1515 height
= Rows
* gui
.char_height
+ base_height
;
1518 gui
.num_cols
= Columns
;
1519 gui
.num_rows
= Rows
;
1521 min_width
= base_width
+ MIN_COLUMNS
* gui
.char_width
;
1522 min_height
= base_height
+ MIN_LINES
* gui
.char_height
;
1523 # ifdef FEAT_WINDOWS
1524 min_height
+= tabline_height() * gui
.char_height
;
1527 gui_mch_set_shellsize(width
, height
, min_width
, min_height
,
1528 base_width
, base_height
, direction
);
1533 /* Some window managers put the Vim window left of/above the screen. */
1535 if (gui_mch_get_winpos(&x
, &y
) == OK
&& (x
< 0 || y
< 0))
1536 gui_mch_set_winpos(x
< 0 ? 0 : x
, y
< 0 ? 0 : y
);
1539 gui_position_components(width
);
1540 gui_update_scrollbars(TRUE
);
1541 gui_reset_scroll_region();
1545 * Called when Rows and/or Columns has changed.
1550 gui_reset_scroll_region();
1554 * Make scroll region cover whole screen.
1557 gui_reset_scroll_region()
1559 gui
.scroll_region_top
= 0;
1560 gui
.scroll_region_bot
= gui
.num_rows
- 1;
1561 gui
.scroll_region_left
= 0;
1562 gui
.scroll_region_right
= gui
.num_cols
- 1;
1566 gui_start_highlight(mask
)
1569 if (mask
> HL_ALL
) /* highlight code */
1570 gui
.highlight_mask
= mask
;
1572 gui
.highlight_mask
|= mask
;
1576 gui_stop_highlight(mask
)
1579 if (mask
> HL_ALL
) /* highlight code */
1580 gui
.highlight_mask
= HL_NORMAL
;
1582 gui
.highlight_mask
&= ~mask
;
1586 * Clear a rectangular region of the screen from text pos (row1, col1) to
1587 * (row2, col2) inclusive.
1590 gui_clear_block(row1
, col1
, row2
, col2
)
1596 /* Clear the selection if we are about to write over it */
1597 clip_may_clear_selection(row1
, row2
);
1599 gui_mch_clear_block(row1
, col1
, row2
, col2
);
1601 /* Invalidate cursor if it was in this block */
1602 if ( gui
.cursor_row
>= row1
&& gui
.cursor_row
<= row2
1603 && gui
.cursor_col
>= col1
&& gui
.cursor_col
<= col2
)
1604 gui
.cursor_is_valid
= FALSE
;
1608 * Write code to update the cursor later. This avoids the need to flush the
1609 * output buffer before calling gui_update_cursor().
1612 gui_update_cursor_later()
1614 OUT_STR(IF_EB("\033|s", ESC_STR
"|s"));
1623 int arg1
= 0, arg2
= 0;
1624 /* this doesn't make sense, disabled until someone can explain why it
1625 * would be needed */
1626 #if 0 && (defined(RISCOS) || defined(WIN16))
1627 int force_cursor
= TRUE
; /* JK230798, stop Vim being smart or
1628 our redraw speed will suffer */
1630 int force_cursor
= FALSE
; /* force cursor update */
1632 int force_scrollbar
= FALSE
;
1633 static win_T
*old_curwin
= NULL
;
1635 /* #define DEBUG_GUI_WRITE */
1636 #ifdef DEBUG_GUI_WRITE
1641 printf("gui_write(%d):\n ", len
);
1642 for (i
= 0; i
< len
; i
++)
1651 str
= transchar_byte(s
[i
]);
1652 if (str
[0] && str
[1])
1653 printf("<%s>", (char *)str
);
1655 printf("%s", (char *)str
);
1662 if (s
[0] == ESC
&& s
[1] == '|')
1665 if (VIM_ISDIGIT(*p
))
1667 arg1
= getdigits(&p
);
1673 arg2
= getdigits(&p
);
1680 case 'C': /* Clear screen */
1681 clip_scroll_selection(9999);
1682 gui_mch_clear_all();
1683 gui
.cursor_is_valid
= FALSE
;
1684 force_scrollbar
= TRUE
;
1686 case 'M': /* Move cursor */
1687 gui_set_cursor(arg1
, arg2
);
1689 case 's': /* force cursor (shape) update */
1690 force_cursor
= TRUE
;
1692 case 'R': /* Set scroll region */
1695 gui
.scroll_region_top
= arg1
;
1696 gui
.scroll_region_bot
= arg2
;
1700 gui
.scroll_region_top
= arg2
;
1701 gui
.scroll_region_bot
= arg1
;
1704 #ifdef FEAT_VERTSPLIT
1705 case 'V': /* Set vertical scroll region */
1708 gui
.scroll_region_left
= arg1
;
1709 gui
.scroll_region_right
= arg2
;
1713 gui
.scroll_region_left
= arg2
;
1714 gui
.scroll_region_right
= arg1
;
1718 case 'd': /* Delete line */
1719 gui_delete_lines(gui
.row
, 1);
1721 case 'D': /* Delete lines */
1722 gui_delete_lines(gui
.row
, arg1
);
1724 case 'i': /* Insert line */
1725 gui_insert_lines(gui
.row
, 1);
1727 case 'I': /* Insert lines */
1728 gui_insert_lines(gui
.row
, arg1
);
1730 case '$': /* Clear to end-of-line */
1731 gui_clear_block(gui
.row
, gui
.col
, gui
.row
,
1734 case 'h': /* Turn on highlighting */
1735 gui_start_highlight(arg1
);
1737 case 'H': /* Turn off highlighting */
1738 gui_stop_highlight(arg1
);
1740 case 'f': /* flash the window (visual bell) */
1741 gui_mch_flash(arg1
== 0 ? 20 : arg1
);
1744 p
= s
+ 1; /* Skip the ESC */
1747 len
-= (int)(++p
- s
);
1752 CtrlChar(s
[0]) != 0 /* Ctrl character */
1754 s
[0] < 0x20 /* Ctrl character */
1756 #ifdef FEAT_SIGN_ICONS
1757 && s
[0] != SIGN_BYTE
1758 # ifdef FEAT_NETBEANS_INTG
1759 && s
[0] != MULTISIGN_BYTE
1764 if (s
[0] == '\n') /* NL */
1767 if (gui
.row
< gui
.scroll_region_bot
)
1770 gui_delete_lines(gui
.scroll_region_top
, 1);
1772 else if (s
[0] == '\r') /* CR */
1776 else if (s
[0] == '\b') /* Backspace */
1781 else if (s
[0] == Ctrl_L
) /* cursor-right */
1785 else if (s
[0] == Ctrl_G
) /* Beep */
1789 /* Other Ctrl character: shouldn't happen! */
1791 --len
; /* Skip this char */
1803 #ifdef FEAT_SIGN_ICONS
1805 # ifdef FEAT_NETBEANS_INTG
1806 || *p
== MULTISIGN_BYTE
1814 gui_outstr(s
, (int)(p
- s
));
1819 /* Postponed update of the cursor (won't work if "can_update_cursor" isn't
1822 gui_update_cursor(TRUE
, TRUE
);
1824 /* When switching to another window the dragging must have stopped.
1825 * Required for GTK, dragged_sb isn't reset. */
1826 if (old_curwin
!= curwin
)
1827 gui
.dragged_sb
= SBAR_NONE
;
1829 /* Update the scrollbars after clearing the screen or when switched
1830 * to another window.
1831 * Update the horizontal scrollbar always, it's difficult to check all
1832 * situations where it might change. */
1833 if (force_scrollbar
|| old_curwin
!= curwin
)
1834 gui_update_scrollbars(force_scrollbar
);
1836 gui_update_horiz_scrollbar(FALSE
);
1837 old_curwin
= curwin
;
1840 * We need to make sure this is cleared since Athena doesn't tell us when
1841 * he is done dragging. Do the same for GTK.
1843 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_GTK)
1844 gui
.dragged_sb
= SBAR_NONE
;
1847 gui_mch_flush(); /* In case vim decides to take a nap */
1851 * When ScreenLines[] is invalid, updating the cursor should not be done, it
1852 * produces wrong results. Call gui_dont_update_cursor() before that code and
1853 * gui_can_update_cursor() afterwards.
1856 gui_dont_update_cursor()
1860 /* Undraw the cursor now, we probably can't do it after the change. */
1861 gui_undraw_cursor();
1862 can_update_cursor
= FALSE
;
1867 gui_can_update_cursor()
1869 can_update_cursor
= TRUE
;
1870 /* No need to update the cursor right now, there is always more output
1871 * after scrolling. */
1888 len
= (int)STRLEN(s
);
1895 /* Find out how many chars fit in the current line. */
1897 for (this_len
= 0; this_len
< len
; )
1899 cells
+= (*mb_ptr2cells
)(s
+ this_len
);
1900 if (gui
.col
+ cells
> Columns
)
1902 this_len
+= (*mb_ptr2len
)(s
+ this_len
);
1905 this_len
= len
; /* don't include following composing char */
1909 if (gui
.col
+ len
> Columns
)
1910 this_len
= Columns
- gui
.col
;
1914 (void)gui_outstr_nowrap(s
, this_len
,
1915 0, (guicolor_T
)0, (guicolor_T
)0, 0);
1919 /* fill up for a double-width char that doesn't fit. */
1920 if (len
> 0 && gui
.col
< Columns
)
1921 (void)gui_outstr_nowrap((char_u
*)" ", 1,
1922 0, (guicolor_T
)0, (guicolor_T
)0, 0);
1924 /* The cursor may wrap to the next line. */
1925 if (gui
.col
>= Columns
)
1934 * Output one character (may be one or two display cells).
1935 * Caller must check for valid "off".
1936 * Returns FAIL or OK, just like gui_outstr_nowrap().
1939 gui_screenchar(off
, flags
, fg
, bg
, back
)
1940 int off
; /* Offset from start of screen */
1942 guicolor_T fg
, bg
; /* colors for cursor */
1943 int back
; /* backup this many chars when using bold trick */
1946 char_u buf
[MB_MAXBYTES
+ 1];
1948 /* Don't draw right halve of a double-width UTF-8 char. "cannot happen" */
1949 if (enc_utf8
&& ScreenLines
[off
] == 0)
1952 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
1953 /* Draw UTF-8 multi-byte character. */
1954 return gui_outstr_nowrap(buf
, utfc_char2bytes(off
, buf
),
1955 flags
, fg
, bg
, back
);
1957 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
1959 buf
[0] = ScreenLines
[off
];
1960 buf
[1] = ScreenLines2
[off
];
1961 return gui_outstr_nowrap(buf
, 2, flags
, fg
, bg
, back
);
1964 /* Draw non-multi-byte character or DBCS character. */
1965 return gui_outstr_nowrap(ScreenLines
+ off
,
1966 enc_dbcs
? (*mb_ptr2len
)(ScreenLines
+ off
) : 1,
1967 flags
, fg
, bg
, back
);
1969 return gui_outstr_nowrap(ScreenLines
+ off
, 1, flags
, fg
, bg
, back
);
1975 * Output the string at the given screen position. This is used in place
1976 * of gui_screenchar() where possible because Pango needs as much context
1977 * as possible to work nicely. It's a lot faster as well.
1980 gui_screenstr(off
, len
, flags
, fg
, bg
, back
)
1981 int off
; /* Offset from start of screen */
1982 int len
; /* string length in screen cells */
1984 guicolor_T fg
, bg
; /* colors for cursor */
1985 int back
; /* backup this many chars when using bold trick */
1992 if (len
<= 0) /* "cannot happen"? */
1997 buf
= alloc((unsigned)(len
* MB_MAXBYTES
+ 1));
1999 return OK
; /* not much we could do here... */
2001 for (i
= off
; i
< off
+ len
; ++i
)
2003 if (ScreenLines
[i
] == 0)
2004 continue; /* skip second half of double-width char */
2006 if (ScreenLinesUC
[i
] == 0)
2007 buf
[outlen
++] = ScreenLines
[i
];
2009 outlen
+= utfc_char2bytes(i
, buf
+ outlen
);
2012 buf
[outlen
] = NUL
; /* only to aid debugging */
2013 retval
= gui_outstr_nowrap(buf
, outlen
, flags
, fg
, bg
, back
);
2018 else if (enc_dbcs
== DBCS_JPNU
)
2020 buf
= alloc((unsigned)(len
* 2 + 1));
2022 return OK
; /* not much we could do here... */
2024 for (i
= off
; i
< off
+ len
; ++i
)
2026 buf
[outlen
++] = ScreenLines
[i
];
2028 /* handle double-byte single-width char */
2029 if (ScreenLines
[i
] == 0x8e)
2030 buf
[outlen
++] = ScreenLines2
[i
];
2031 else if (MB_BYTE2LEN(ScreenLines
[i
]) == 2)
2032 buf
[outlen
++] = ScreenLines
[++i
];
2035 buf
[outlen
] = NUL
; /* only to aid debugging */
2036 retval
= gui_outstr_nowrap(buf
, outlen
, flags
, fg
, bg
, back
);
2043 return gui_outstr_nowrap(&ScreenLines
[off
], len
,
2044 flags
, fg
, bg
, back
);
2047 #endif /* HAVE_GTK2 */
2050 * Output the given string at the current cursor position. If the string is
2051 * too long to fit on the line, then it is truncated.
2053 * GUI_MON_IS_CURSOR should only be used when this function is being called to
2054 * actually draw (an inverted) cursor.
2055 * GUI_MON_TRS_CURSOR is used to draw the cursor text with a transparent
2057 * GUI_MON_NOCLEAR is used to avoid clearing the selection when drawing over
2059 * Returns OK, unless "back" is non-zero and using the bold trick, then return
2060 * FAIL (the caller should start drawing "back" chars back).
2063 gui_outstr_nowrap(s
, len
, flags
, fg
, bg
, back
)
2067 guicolor_T fg
, bg
; /* colors for cursor */
2068 int back
; /* backup this many chars when using bold trick */
2070 long_u highlight_mask
;
2071 long_u hl_mask_todo
;
2072 guicolor_T fg_color
;
2073 guicolor_T bg_color
;
2074 guicolor_T sp_color
;
2075 #if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2)
2076 GuiFont font
= NOFONT
;
2077 # ifdef FEAT_XFONTSET
2078 GuiFontset fontset
= NOFONTSET
;
2081 attrentry_T
*aep
= NULL
;
2084 #ifdef FEAT_SIGN_ICONS
2085 int draw_sign
= FALSE
;
2086 # ifdef FEAT_NETBEANS_INTG
2087 int multi_sign
= FALSE
;
2092 len
= (int)STRLEN(s
);
2096 #ifdef FEAT_SIGN_ICONS
2098 # ifdef FEAT_NETBEANS_INTG
2099 || *s
== MULTISIGN_BYTE
2103 # ifdef FEAT_NETBEANS_INTG
2104 if (*s
== MULTISIGN_BYTE
)
2107 /* draw spaces instead */
2109 if (len
== 1 && col
> 0)
2117 if (gui
.highlight_mask
> HL_ALL
)
2119 aep
= syn_gui_attr2entry(gui
.highlight_mask
);
2120 if (aep
== NULL
) /* highlighting not set */
2123 highlight_mask
= aep
->ae_attr
;
2126 highlight_mask
= gui
.highlight_mask
;
2127 hl_mask_todo
= highlight_mask
;
2129 #if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2)
2131 if (aep
!= NULL
&& aep
->ae_u
.gui
.font
!= NOFONT
)
2132 font
= aep
->ae_u
.gui
.font
;
2133 # ifdef FEAT_XFONTSET
2134 else if (aep
!= NULL
&& aep
->ae_u
.gui
.fontset
!= NOFONTSET
)
2135 fontset
= aep
->ae_u
.gui
.fontset
;
2139 # ifdef FEAT_XFONTSET
2140 if (gui
.fontset
!= NOFONTSET
)
2141 fontset
= gui
.fontset
;
2144 if (hl_mask_todo
& (HL_BOLD
| HL_STANDOUT
))
2146 if ((hl_mask_todo
& HL_ITALIC
) && gui
.boldital_font
!= NOFONT
)
2148 font
= gui
.boldital_font
;
2149 hl_mask_todo
&= ~(HL_BOLD
| HL_STANDOUT
| HL_ITALIC
);
2151 else if (gui
.bold_font
!= NOFONT
)
2153 font
= gui
.bold_font
;
2154 hl_mask_todo
&= ~(HL_BOLD
| HL_STANDOUT
);
2157 font
= gui
.norm_font
;
2159 else if ((hl_mask_todo
& HL_ITALIC
) && gui
.ital_font
!= NOFONT
)
2161 font
= gui
.ital_font
;
2162 hl_mask_todo
&= ~HL_ITALIC
;
2165 font
= gui
.norm_font
;
2167 # ifdef FEAT_XFONTSET
2168 if (fontset
!= NOFONTSET
)
2169 gui_mch_set_fontset(fontset
);
2172 gui_mch_set_font(font
);
2178 bg_color
= gui
.back_pixel
;
2179 if ((flags
& GUI_MON_IS_CURSOR
) && gui
.in_focus
)
2181 draw_flags
|= DRAW_CURSOR
;
2186 else if (aep
!= NULL
)
2188 fg_color
= aep
->ae_u
.gui
.fg_color
;
2189 if (fg_color
== INVALCOLOR
)
2190 fg_color
= gui
.norm_pixel
;
2191 bg_color
= aep
->ae_u
.gui
.bg_color
;
2192 if (bg_color
== INVALCOLOR
)
2193 bg_color
= gui
.back_pixel
;
2194 sp_color
= aep
->ae_u
.gui
.sp_color
;
2195 if (sp_color
== INVALCOLOR
)
2196 sp_color
= fg_color
;
2200 fg_color
= gui
.norm_pixel
;
2201 sp_color
= fg_color
;
2204 if (highlight_mask
& (HL_INVERSE
| HL_STANDOUT
))
2206 #if defined(AMIGA) || defined(RISCOS)
2207 gui_mch_set_colors(bg_color
, fg_color
);
2209 gui_mch_set_fg_color(bg_color
);
2210 gui_mch_set_bg_color(fg_color
);
2215 #if defined(AMIGA) || defined(RISCOS)
2216 gui_mch_set_colors(fg_color
, bg_color
);
2218 gui_mch_set_fg_color(fg_color
);
2219 gui_mch_set_bg_color(bg_color
);
2222 gui_mch_set_sp_color(sp_color
);
2224 /* Clear the selection if we are about to write over it */
2225 if (!(flags
& GUI_MON_NOCLEAR
))
2226 clip_may_clear_selection(gui
.row
, gui
.row
);
2229 #ifndef MSWIN16_FASTTEXT
2230 /* If there's no bold font, then fake it */
2231 if (hl_mask_todo
& (HL_BOLD
| HL_STANDOUT
))
2232 draw_flags
|= DRAW_BOLD
;
2236 * When drawing bold or italic characters the spill-over from the left
2237 * neighbor may be destroyed. Let the caller backup to start redrawing
2238 * just after a blank.
2240 if (back
!= 0 && ((draw_flags
& DRAW_BOLD
) || (highlight_mask
& HL_ITALIC
)))
2243 #if defined(RISCOS) || defined(HAVE_GTK2) || defined(FEAT_GUI_MACVIM)
2244 /* If there's no italic font, then fake it.
2245 * For GTK2, we don't need a different font for italic style. */
2246 if (hl_mask_todo
& HL_ITALIC
)
2247 draw_flags
|= DRAW_ITALIC
;
2249 /* Do we underline the text? */
2250 if (hl_mask_todo
& HL_UNDERLINE
)
2251 draw_flags
|= DRAW_UNDERL
;
2253 /* Do we underline the text? */
2254 if ((hl_mask_todo
& HL_UNDERLINE
)
2255 # ifndef MSWIN16_FASTTEXT
2256 || (hl_mask_todo
& HL_ITALIC
)
2259 draw_flags
|= DRAW_UNDERL
;
2261 /* Do we undercurl the text? */
2262 if (hl_mask_todo
& HL_UNDERCURL
)
2263 draw_flags
|= DRAW_UNDERC
;
2265 /* Do we draw transparently? */
2266 if (flags
& GUI_MON_TRS_CURSOR
)
2267 draw_flags
|= DRAW_TRANSP
;
2273 /* The value returned is the length in display cells */
2274 len
= gui_gtk2_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2275 #elif defined(FEAT_GUI_MACVIM) && defined(FEAT_MBYTE)
2276 /* The value returned is the length in display cells */
2277 len
= gui_macvim_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2282 int start
; /* index of bytes to be drawn */
2283 int cells
; /* cellwidth of bytes to be drawn */
2284 int thislen
; /* length of bytes to be drawin */
2285 int cn
; /* cellwidth of current char */
2286 int i
; /* index of current char */
2287 int c
; /* current char value */
2288 int cl
; /* byte length of current char */
2289 int comping
; /* current char is composing */
2290 int scol
= col
; /* screen column */
2291 int dowide
; /* use 'guifontwide' */
2293 /* Break the string at a composing character, it has to be drawn on
2294 * top of the previous character. */
2297 for (i
= 0; i
< len
; i
+= cl
)
2299 c
= utf_ptr2char(s
+ i
);
2300 cn
= utf_char2cells(c
);
2302 # ifdef FEAT_XFONTSET
2303 && fontset
== NOFONTSET
2305 && gui
.wide_font
!= NOFONT
)
2309 comping
= utf_iscomposing(c
);
2310 if (!comping
) /* count cells from non-composing chars */
2312 cl
= utf_ptr2len(s
+ i
);
2313 if (cl
== 0) /* hit end of string */
2314 len
= i
+ cl
; /* len must be wrong "cannot happen" */
2316 /* print the string so far if it's the last character or there is
2317 * a composing character. */
2318 if (i
+ cl
>= len
|| (comping
&& i
> start
) || dowide
2319 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
2321 # ifdef FEAT_XFONTSET
2322 /* No fontset: At least draw char after wide char at
2323 * right position. */
2324 && fontset
== NOFONTSET
2330 if (comping
|| dowide
)
2331 thislen
= i
- start
;
2333 thislen
= i
- start
+ cl
;
2336 gui_mch_draw_string(gui
.row
, scol
, s
+ start
, thislen
,
2344 gui_mch_set_font(gui
.wide_font
);
2345 gui_mch_draw_string(gui
.row
, scol
- cn
,
2346 s
+ start
, cl
, draw_flags
);
2347 gui_mch_set_font(font
);
2351 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
2352 /* No fontset: draw a space to fill the gap after a wide char
2354 if (cn
> 1 && (draw_flags
& DRAW_TRANSP
) == 0
2355 # ifdef FEAT_XFONTSET
2356 && fontset
== NOFONTSET
2359 gui_mch_draw_string(gui
.row
, scol
- 1, (char_u
*)" ",
2363 /* Draw a composing char on top of the previous char. */
2366 # if (defined(__APPLE_CC__) || defined(__MRC__)) && TARGET_API_MAC_CARBON
2367 /* Carbon ATSUI autodraws composing char over previous char */
2368 gui_mch_draw_string(gui
.row
, scol
, s
+ i
, cl
,
2369 draw_flags
| DRAW_TRANSP
);
2371 gui_mch_draw_string(gui
.row
, scol
- cn
, s
+ i
, cl
,
2372 draw_flags
| DRAW_TRANSP
);
2377 /* The stuff below assumes "len" is the length in screen columns. */
2383 gui_mch_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2385 if (enc_dbcs
== DBCS_JPNU
)
2390 /* Get the length in display cells, this can be different from the
2391 * number of bytes for "euc-jp". */
2392 for (i
= 0; i
< len
; i
+= (*mb_ptr2len
)(s
+ i
))
2393 clen
+= (*mb_ptr2cells
)(s
+ i
);
2398 #endif /* !HAVE_GTK2 */
2400 if (!(flags
& (GUI_MON_IS_CURSOR
| GUI_MON_TRS_CURSOR
)))
2401 gui
.col
= col
+ len
;
2403 /* May need to invert it when it's part of the selection. */
2404 if (flags
& GUI_MON_NOCLEAR
)
2405 clip_may_redraw_selection(gui
.row
, col
, len
);
2407 if (!(flags
& (GUI_MON_IS_CURSOR
| GUI_MON_TRS_CURSOR
)))
2409 /* Invalidate the old physical cursor position if we wrote over it */
2410 if (gui
.cursor_row
== gui
.row
2411 && gui
.cursor_col
>= col
2412 && gui
.cursor_col
< col
+ len
)
2413 gui
.cursor_is_valid
= FALSE
;
2416 #ifdef FEAT_SIGN_ICONS
2418 /* Draw the sign on top of the spaces. */
2419 gui_mch_drawsign(gui
.row
, col
, gui
.highlight_mask
);
2420 # ifdef FEAT_NETBEANS_INTG
2422 netbeans_draw_multisign_indicator(gui
.row
);
2430 * Un-draw the cursor. Actually this just redraws the character at the given
2431 * position. The character just before it too, for when it was in bold.
2436 if (gui
.cursor_is_valid
)
2438 #ifdef FEAT_HANGULIN
2439 if (composing_hangul
2440 && gui
.col
== gui
.cursor_col
&& gui
.row
== gui
.cursor_row
)
2441 (void)gui_outstr_nowrap(composing_hangul_buffer
, 2,
2442 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
,
2443 gui
.norm_pixel
, gui
.back_pixel
, 0);
2447 if (gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
,
2448 gui
.cursor_row
, gui
.cursor_col
, GUI_MON_NOCLEAR
)
2449 && gui
.cursor_col
> 0)
2450 (void)gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
- 1,
2451 gui
.cursor_row
, gui
.cursor_col
- 1, GUI_MON_NOCLEAR
);
2452 #ifdef FEAT_HANGULIN
2453 if (composing_hangul
)
2454 (void)gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
+ 1,
2455 gui
.cursor_row
, gui
.cursor_col
+ 1, GUI_MON_NOCLEAR
);
2458 /* Cursor_is_valid is reset when the cursor is undrawn, also reset it
2459 * here in case it wasn't needed to undraw it. */
2460 gui
.cursor_is_valid
= FALSE
;
2465 gui_redraw(x
, y
, w
, h
)
2471 int row1
, col1
, row2
, col2
;
2475 row2
= Y_2_ROW(y
+ h
- 1);
2476 col2
= X_2_COL(x
+ w
- 1);
2478 (void)gui_redraw_block(row1
, col1
, row2
, col2
, GUI_MON_NOCLEAR
);
2481 * We may need to redraw the cursor, but don't take it upon us to change
2482 * its location after a scroll.
2483 * (maybe be more strict even and test col too?)
2484 * These things may be outside the update/clipping region and reality may
2485 * not reflect Vims internal ideas if these operations are clipped away.
2487 if (gui
.row
== gui
.cursor_row
)
2488 gui_update_cursor(TRUE
, TRUE
);
2492 * Draw a rectangular block of characters, from row1 to row2 (inclusive) and
2493 * from col1 to col2 (inclusive).
2494 * Return TRUE when the character before the first drawn character has
2495 * different attributes (may have to be redrawn too).
2498 gui_redraw_block(row1
, col1
, row2
, col2
, flags
)
2503 int flags
; /* flags for gui_outstr_nowrap() */
2505 int old_row
, old_col
;
2513 int orig_col1
, orig_col2
;
2516 /* Don't try to update when ScreenLines is not valid */
2517 if (!screen_cleared
|| ScreenLines
== NULL
)
2520 /* Don't try to draw outside the shell! */
2521 /* Check everything, strange values may be caused by a big border width */
2522 col1
= check_col(col1
);
2523 col2
= check_col(col2
);
2524 row1
= check_row(row1
);
2525 row2
= check_row(row2
);
2527 /* Remember where our cursor was */
2530 old_hl_mask
= gui
.highlight_mask
;
2536 for (gui
.row
= row1
; gui
.row
<= row2
; gui
.row
++)
2539 /* When only half of a double-wide character is in the block, include
2540 * the other half. */
2543 off
= LineOffset
[gui
.row
];
2547 col1
-= dbcs_screen_head_off(ScreenLines
+ off
,
2548 ScreenLines
+ off
+ col1
);
2549 col2
+= dbcs_screen_tail_off(ScreenLines
+ off
,
2550 ScreenLines
+ off
+ col2
);
2554 if (ScreenLines
[off
+ col1
] == 0)
2557 if (col2
+ 1 < Columns
&& ScreenLines
[off
+ col2
+ 1] == 0)
2563 off
= LineOffset
[gui
.row
] + gui
.col
;
2564 len
= col2
- col1
+ 1;
2566 /* Find how many chars back this highlighting starts, or where a space
2567 * is. Needed for when the bold trick is used */
2568 for (back
= 0; back
< col1
; ++back
)
2569 if (ScreenAttrs
[off
- 1 - back
] != ScreenAttrs
[off
]
2570 || ScreenLines
[off
- 1 - back
] == ' ')
2572 retval
= (col1
> 0 && ScreenAttrs
[off
- 1] != 0 && back
== 0
2573 && ScreenLines
[off
- 1] != ' ');
2575 /* Break it up in strings of characters with the same attributes. */
2576 /* Print UTF-8 characters individually. */
2579 first_attr
= ScreenAttrs
[off
];
2580 gui
.highlight_mask
= first_attr
;
2581 #if defined(FEAT_MBYTE) && !defined(HAVE_GTK2)
2582 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
2584 /* output multi-byte character separately */
2585 nback
= gui_screenchar(off
, flags
,
2586 (guicolor_T
)0, (guicolor_T
)0, back
);
2587 if (gui
.col
< Columns
&& ScreenLines
[off
+ 1] == 0)
2592 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
2594 /* output double-byte, single-width character separately */
2595 nback
= gui_screenchar(off
, flags
,
2596 (guicolor_T
)0, (guicolor_T
)0, back
);
2603 for (idx
= 0; idx
< len
; ++idx
)
2605 if (enc_utf8
&& ScreenLines
[off
+ idx
] == 0)
2606 continue; /* skip second half of double-width char */
2607 if (ScreenAttrs
[off
+ idx
] != first_attr
)
2610 /* gui_screenstr() takes care of multibyte chars */
2611 nback
= gui_screenstr(off
, idx
, flags
,
2612 (guicolor_T
)0, (guicolor_T
)0, back
);
2614 for (idx
= 0; idx
< len
&& ScreenAttrs
[off
+ idx
] == first_attr
;
2618 /* Stop at a multi-byte Unicode character. */
2619 if (enc_utf8
&& ScreenLinesUC
[off
+ idx
] != 0)
2621 if (enc_dbcs
== DBCS_JPNU
)
2623 /* Stop at a double-byte single-width char. */
2624 if (ScreenLines
[off
+ idx
] == 0x8e)
2626 if (len
> 1 && (*mb_ptr2len
)(ScreenLines
2628 ++idx
; /* skip second byte of double-byte char */
2632 nback
= gui_outstr_nowrap(ScreenLines
+ off
, idx
, flags
,
2633 (guicolor_T
)0, (guicolor_T
)0, back
);
2638 /* Must back up to start drawing where a bold or italic word
2653 /* Put the cursor back where it was */
2656 gui
.highlight_mask
= (int)old_hl_mask
;
2662 gui_delete_lines(row
, count
)
2669 if (row
+ count
> gui
.scroll_region_bot
)
2670 /* Scrolled out of region, just blank the lines out */
2671 gui_clear_block(row
, gui
.scroll_region_left
,
2672 gui
.scroll_region_bot
, gui
.scroll_region_right
);
2675 gui_mch_delete_lines(row
, count
);
2677 /* If the cursor was in the deleted lines it's now gone. If the
2678 * cursor was in the scrolled lines adjust its position. */
2679 if (gui
.cursor_row
>= row
2680 && gui
.cursor_col
>= gui
.scroll_region_left
2681 && gui
.cursor_col
<= gui
.scroll_region_right
)
2683 if (gui
.cursor_row
< row
+ count
)
2684 gui
.cursor_is_valid
= FALSE
;
2685 else if (gui
.cursor_row
<= gui
.scroll_region_bot
)
2686 gui
.cursor_row
-= count
;
2692 gui_insert_lines(row
, count
)
2699 if (row
+ count
> gui
.scroll_region_bot
)
2700 /* Scrolled out of region, just blank the lines out */
2701 gui_clear_block(row
, gui
.scroll_region_left
,
2702 gui
.scroll_region_bot
, gui
.scroll_region_right
);
2705 gui_mch_insert_lines(row
, count
);
2707 if (gui
.cursor_row
>= gui
.row
2708 && gui
.cursor_col
>= gui
.scroll_region_left
2709 && gui
.cursor_col
<= gui
.scroll_region_right
)
2711 if (gui
.cursor_row
<= gui
.scroll_region_bot
- count
)
2712 gui
.cursor_row
+= count
;
2713 else if (gui
.cursor_row
<= gui
.scroll_region_bot
)
2714 gui
.cursor_is_valid
= FALSE
;
2720 * The main GUI input routine. Waits for a character from the keyboard.
2721 * wtime == -1 Wait forever.
2722 * wtime == 0 Don't wait.
2723 * wtime > 0 Wait wtime milliseconds for a character.
2724 * Returns OK if a character was found to be available within the given time,
2725 * or FAIL otherwise.
2728 gui_wait_for_chars(wtime
)
2734 * If we're going to wait a bit, update the menus and mouse shape for the
2740 gui_update_menus(0);
2745 if (input_available()) /* Got char, return immediately */
2747 if (wtime
== 0) /* Don't wait for char */
2750 /* Before waiting, flush any output to the screen. */
2755 /* Blink when waiting for a character. Probably only does something
2756 * for showmatch() */
2757 gui_mch_start_blink();
2758 retval
= gui_mch_wait_for_chars(wtime
);
2759 gui_mch_stop_blink();
2764 * While we are waiting indefinitely for a character, blink the cursor.
2766 gui_mch_start_blink();
2770 * We may want to trigger the CursorHold event. First wait for
2771 * 'updatetime' and if nothing is typed within that time put the
2772 * K_CURSORHOLD key in the input buffer.
2774 if (gui_mch_wait_for_chars(p_ut
) == OK
)
2777 else if (trigger_cursorhold())
2781 /* Put K_CURSORHOLD in the input buffer. */
2784 buf
[2] = (int)KE_CURSORHOLD
;
2785 add_to_input_buf(buf
, 3);
2793 /* Blocking wait. */
2795 retval
= gui_mch_wait_for_chars(-1L);
2798 gui_mch_stop_blink();
2803 * Fill p[4] with mouse coordinates encoded for check_termcode().
2806 fill_mouse_coord(p
, col
, row
)
2811 p
[0] = (char_u
)(col
/ 128 + ' ' + 1);
2812 p
[1] = (char_u
)(col
% 128 + ' ' + 1);
2813 p
[2] = (char_u
)(row
/ 128 + ' ' + 1);
2814 p
[3] = (char_u
)(row
% 128 + ' ' + 1);
2818 * Generic mouse support function. Add a mouse event to the input buffer with
2819 * the given properties.
2820 * button --- may be any of MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT,
2821 * MOUSE_X1, MOUSE_X2
2822 * MOUSE_DRAG, or MOUSE_RELEASE.
2823 * MOUSE_4 and MOUSE_5 are used for a scroll wheel.
2824 * x, y --- Coordinates of mouse in pixels.
2825 * repeated_click --- TRUE if this click comes only a short time after a
2827 * modifiers --- Bit field which may be any of the following modifiers
2828 * or'ed together: MOUSE_SHIFT | MOUSE_CTRL | MOUSE_ALT.
2829 * This function will ignore drag events where the mouse has not moved to a new
2833 gui_send_mouse_event(button
, x
, y
, repeated_click
, modifiers
)
2840 static int prev_row
= 0, prev_col
= 0;
2841 static int prev_button
= -1;
2842 static int num_clicks
= 1;
2844 enum key_extra button_char
;
2846 #ifdef FEAT_CLIPBOARD
2848 int did_clip
= FALSE
;
2852 * Scrolling may happen at any time, also while a selection is present.
2857 button_char
= KE_X1MOUSE
;
2860 button_char
= KE_X2MOUSE
;
2863 button_char
= KE_MOUSEDOWN
;
2866 button_char
= KE_MOUSEUP
;
2869 /* Don't put events in the input queue now. */
2870 if (hold_gui_events
)
2874 string
[4] = KS_EXTRA
;
2875 string
[5] = (int)button_char
;
2877 /* Pass the pointer coordinates of the scroll event so that we
2878 * know which window to scroll. */
2879 row
= gui_xy2colrow(x
, y
, &col
);
2880 string
[6] = (char_u
)(col
/ 128 + ' ' + 1);
2881 string
[7] = (char_u
)(col
% 128 + ' ' + 1);
2882 string
[8] = (char_u
)(row
/ 128 + ' ' + 1);
2883 string
[9] = (char_u
)(row
% 128 + ' ' + 1);
2886 add_to_input_buf(string
+ 3, 7);
2890 string
[1] = KS_MODIFIER
;
2892 if (modifiers
& MOUSE_SHIFT
)
2893 string
[2] |= MOD_MASK_SHIFT
;
2894 if (modifiers
& MOUSE_CTRL
)
2895 string
[2] |= MOD_MASK_CTRL
;
2896 if (modifiers
& MOUSE_ALT
)
2897 string
[2] |= MOD_MASK_ALT
;
2898 add_to_input_buf(string
, 10);
2904 #ifdef FEAT_CLIPBOARD
2905 /* If a clipboard selection is in progress, handle it */
2906 if (clip_star
.state
== SELECT_IN_PROGRESS
)
2908 clip_process_selection(button
, X_2_COL(x
), Y_2_ROW(y
), repeated_click
);
2912 /* Determine which mouse settings to look for based on the current mode */
2913 switch (get_real_state())
2917 case NORMAL
: checkfor
= MOUSE_NORMAL
; break;
2918 case VISUAL
: checkfor
= MOUSE_VISUAL
; break;
2919 case SELECTMODE
: checkfor
= MOUSE_VISUAL
; break;
2921 case REPLACE
+LANGMAP
:
2922 #ifdef FEAT_VREPLACE
2924 case VREPLACE
+LANGMAP
:
2927 case INSERT
+LANGMAP
: checkfor
= MOUSE_INSERT
; break;
2929 case HITRETURN
: /* At the more- and hit-enter prompt pass the
2930 mouse event for a click on or below the
2932 if (Y_2_ROW(y
) >= msg_row
)
2933 checkfor
= MOUSE_NORMAL
;
2935 checkfor
= MOUSE_RETURN
;
2939 * On the command line, use the clipboard selection on all lines
2940 * but the command line. But not when pasting.
2943 case CMDLINE
+LANGMAP
:
2944 if (Y_2_ROW(y
) < cmdline_row
&& button
!= MOUSE_MIDDLE
)
2945 checkfor
= MOUSE_NONE
;
2947 checkfor
= MOUSE_COMMAND
;
2951 checkfor
= MOUSE_NONE
;
2956 * Allow clipboard selection of text on the command line in "normal"
2957 * modes. Don't do this when dragging the status line, or extending a
2960 if ((State
== NORMAL
|| State
== NORMAL_BUSY
|| (State
& INSERT
))
2961 && Y_2_ROW(y
) >= topframe
->fr_height
2962 # ifdef FEAT_WINDOWS
2963 + firstwin
->w_winrow
2965 && button
!= MOUSE_DRAG
2966 # ifdef FEAT_MOUSESHAPE
2967 && !drag_status_line
2968 # ifdef FEAT_VERTSPLIT
2973 checkfor
= MOUSE_NONE
;
2976 * Use modeless selection when holding CTRL and SHIFT pressed.
2978 if ((modifiers
& MOUSE_CTRL
) && (modifiers
& MOUSE_SHIFT
))
2979 checkfor
= MOUSE_NONEF
;
2982 * In Ex mode, always use modeless selection.
2985 checkfor
= MOUSE_NONE
;
2988 * If the mouse settings say to not use the mouse, use the modeless
2989 * selection. But if Visual is active, assume that only the Visual area
2991 * Exception: On the command line, both the selection is used and a mouse
2994 if (!mouse_has(checkfor
) || checkfor
== MOUSE_COMMAND
)
2997 /* Don't do modeless selection in Visual mode. */
2998 if (checkfor
!= MOUSE_NONEF
&& VIsual_active
&& (State
& NORMAL
))
3003 * When 'mousemodel' is "popup", shift-left is translated to right.
3004 * But not when also using Ctrl.
3006 if (mouse_model_popup() && button
== MOUSE_LEFT
3007 && (modifiers
& MOUSE_SHIFT
) && !(modifiers
& MOUSE_CTRL
))
3009 button
= MOUSE_RIGHT
;
3010 modifiers
&= ~ MOUSE_SHIFT
;
3013 /* If the selection is done, allow the right button to extend it.
3014 * If the selection is cleared, allow the right button to start it
3015 * from the cursor position. */
3016 if (button
== MOUSE_RIGHT
)
3018 if (clip_star
.state
== SELECT_CLEARED
)
3020 if (State
& CMDLINE
)
3027 col
= curwin
->w_wcol
;
3028 row
= curwin
->w_wrow
+ W_WINROW(curwin
);
3030 clip_start_selection(col
, row
, FALSE
);
3032 clip_process_selection(button
, X_2_COL(x
), Y_2_ROW(y
),
3036 /* Allow the left button to start the selection */
3039 /* Only start a drag on a drag event. Otherwise
3040 * we don't get a release event. */
3047 clip_start_selection(X_2_COL(x
), Y_2_ROW(y
), repeated_click
);
3051 else if (button
== MOUSE_LEFT
)
3053 clip_clear_selection();
3058 /* Always allow pasting */
3059 if (button
!= MOUSE_MIDDLE
)
3061 if (!mouse_has(checkfor
) || button
== MOUSE_RELEASE
)
3063 if (checkfor
!= MOUSE_COMMAND
)
3064 button
= MOUSE_LEFT
;
3066 repeated_click
= FALSE
;
3069 if (clip_star
.state
!= SELECT_CLEARED
&& !did_clip
)
3070 clip_clear_selection();
3073 /* Don't put events in the input queue now. */
3074 if (hold_gui_events
)
3077 row
= gui_xy2colrow(x
, y
, &col
);
3080 * If we are dragging and the mouse hasn't moved far enough to be on a
3081 * different character, then don't send an event to vim.
3083 if (button
== MOUSE_DRAG
)
3085 if (row
== prev_row
&& col
== prev_col
)
3087 /* Dragging above the window, set "row" to -1 to cause a scroll. */
3093 * If topline has changed (window scrolled) since the last click, reset
3094 * repeated_click, because we don't want starting Visual mode when
3095 * clicking on a different character in the text.
3097 if (curwin
->w_topline
!= gui_prev_topline
3099 || curwin
->w_topfill
!= gui_prev_topfill
3102 repeated_click
= FALSE
;
3104 string
[0] = CSI
; /* this sequence is recognized by check_termcode() */
3105 string
[1] = KS_MOUSE
;
3106 string
[2] = KE_FILLER
;
3107 if (button
!= MOUSE_DRAG
&& button
!= MOUSE_RELEASE
)
3112 * Handle multiple clicks. They only count if the mouse is still
3113 * pointing at the same character.
3115 if (button
!= prev_button
|| row
!= prev_row
|| col
!= prev_col
)
3117 else if (++num_clicks
> 4)
3122 prev_button
= button
;
3123 gui_prev_topline
= curwin
->w_topline
;
3125 gui_prev_topfill
= curwin
->w_topfill
;
3128 string
[3] = (char_u
)(button
| 0x20);
3129 SET_NUM_MOUSE_CLICKS(string
[3], num_clicks
);
3132 string
[3] = (char_u
)button
;
3134 string
[3] |= modifiers
;
3135 fill_mouse_coord(string
+ 4, col
, row
);
3136 add_to_input_buf(string
, 8);
3145 * We need to make sure this is cleared since Athena doesn't tell us when
3146 * he is done dragging. Neither does GTK+ 2 -- at least for now.
3148 #if defined(FEAT_GUI_ATHENA) || defined(HAVE_GTK2)
3149 gui
.dragged_sb
= SBAR_NONE
;
3154 * Convert x and y coordinate to column and row in text window.
3155 * Corrects for multi-byte character.
3156 * returns column in "*colp" and row as return value;
3159 gui_xy2colrow(x
, y
, colp
)
3164 int col
= check_col(X_2_COL(x
));
3165 int row
= check_row(Y_2_ROW(y
));
3168 *colp
= mb_fix_col(col
, row
);
3175 #if defined(FEAT_MENU) || defined(PROTO)
3177 * Callback function for when a menu entry has been selected.
3183 char_u bytes
[sizeof(long_u
)];
3185 /* Don't put events in the input queue now. */
3186 if (hold_gui_events
)
3191 bytes
[2] = KE_FILLER
;
3192 add_to_input_buf(bytes
, 3);
3193 add_long_to_buf((long_u
)menu
, bytes
);
3194 add_to_input_buf_csi(bytes
, sizeof(long_u
));
3198 static int prev_which_scrollbars
[3];
3201 * Set which components are present.
3202 * If "oldval" is not NULL, "oldval" is the previous value, the new value is
3207 gui_init_which_components(oldval
)
3211 static int prev_menu_is_active
= -1;
3214 static int prev_toolbar
= -1;
3215 int using_toolbar
= FALSE
;
3217 #ifdef FEAT_GUI_TABLINE
3221 static int prev_footer
= -1;
3222 int using_footer
= FALSE
;
3224 #if defined(FEAT_MENU) && !defined(WIN16)
3225 static int prev_tearoff
= -1;
3226 int using_tearoff
= FALSE
;
3232 int grey_old
, grey_new
;
3240 if (oldval
!= NULL
&& gui
.in_use
)
3243 * Check if the menu's go from grey to non-grey or vise versa.
3245 grey_old
= (vim_strchr(oldval
, GO_GREY
) != NULL
);
3246 grey_new
= (vim_strchr(p_go
, GO_GREY
) != NULL
);
3247 if (grey_old
!= grey_new
)
3251 gui_update_menus(MENU_ALL_MODES
);
3255 gui
.menu_is_active
= FALSE
;
3258 for (i
= 0; i
< 3; i
++)
3259 gui
.which_scrollbars
[i
] = FALSE
;
3260 for (p
= p_go
; *p
; p
++)
3264 gui
.which_scrollbars
[SBAR_LEFT
] = TRUE
;
3267 gui
.which_scrollbars
[SBAR_RIGHT
] = TRUE
;
3269 #ifdef FEAT_VERTSPLIT
3271 if (win_hasvertsplit())
3272 gui
.which_scrollbars
[SBAR_LEFT
] = TRUE
;
3275 if (win_hasvertsplit())
3276 gui
.which_scrollbars
[SBAR_RIGHT
] = TRUE
;
3280 gui
.which_scrollbars
[SBAR_BOTTOM
] = TRUE
;
3284 gui
.menu_is_active
= TRUE
;
3288 /* make menu's have grey items, ignored here */
3292 using_toolbar
= TRUE
;
3297 using_footer
= TRUE
;
3301 #if defined(FEAT_MENU) && !defined(WIN16)
3302 using_tearoff
= TRUE
;
3306 /* Ignore options that are not supported */
3315 #ifdef FEAT_GUI_TABLINE
3316 /* Update the GUI tab line, it may appear or disappear. This may
3317 * cause the non-GUI tab line to disappear or appear. */
3318 using_tabline
= gui_has_tabline();
3319 if (!gui_mch_showing_tabline() != !using_tabline
)
3321 /* We don't want a resize event change "Rows" here, save and
3322 * restore it. Resizing is handled below. */
3324 gui_update_tabline();
3326 need_set_size
= RESIZE_VERT
;
3329 if (!gui_use_tabline())
3330 redraw_tabline
= TRUE
; /* may draw non-GUI tab line */
3334 for (i
= 0; i
< 3; i
++)
3336 /* The scrollbar needs to be updated when it is shown/unshown and
3337 * when switching tab pages. But the size only changes when it's
3338 * shown/unshown. Thus we need two places to remember whether a
3339 * scrollbar is there or not. */
3340 if (gui
.which_scrollbars
[i
] != prev_which_scrollbars
[i
]
3342 || gui
.which_scrollbars
[i
]
3343 != curtab
->tp_prev_which_scrollbars
[i
]
3347 if (i
== SBAR_BOTTOM
)
3348 gui_mch_enable_scrollbar(&gui
.bottom_sbar
,
3349 gui
.which_scrollbars
[i
]);
3354 gui_do_scrollbar(wp
, i
, gui
.which_scrollbars
[i
]);
3357 if (gui
.which_scrollbars
[i
] != prev_which_scrollbars
[i
])
3359 if (i
== SBAR_BOTTOM
)
3360 need_set_size
= RESIZE_VERT
;
3362 need_set_size
= RESIZE_HOR
;
3363 if (gui
.which_scrollbars
[i
])
3368 curtab
->tp_prev_which_scrollbars
[i
] = gui
.which_scrollbars
[i
];
3370 prev_which_scrollbars
[i
] = gui
.which_scrollbars
[i
];
3374 if (gui
.menu_is_active
!= prev_menu_is_active
)
3376 /* We don't want a resize event change "Rows" here, save and
3377 * restore it. Resizing is handled below. */
3379 gui_mch_enable_menu(gui
.menu_is_active
);
3381 prev_menu_is_active
= gui
.menu_is_active
;
3382 need_set_size
= RESIZE_VERT
;
3383 if (gui
.menu_is_active
)
3389 if (using_toolbar
!= prev_toolbar
)
3391 gui_mch_show_toolbar(using_toolbar
);
3392 prev_toolbar
= using_toolbar
;
3393 need_set_size
= RESIZE_VERT
;
3399 if (using_footer
!= prev_footer
)
3401 gui_mch_enable_footer(using_footer
);
3402 prev_footer
= using_footer
;
3403 need_set_size
= RESIZE_VERT
;
3408 #if defined(FEAT_MENU) && !defined(WIN16) && !(defined(WIN3264) && !defined(FEAT_TEAROFF))
3409 if (using_tearoff
!= prev_tearoff
)
3411 gui_mch_toggle_tearoffs(using_tearoff
);
3412 prev_tearoff
= using_tearoff
;
3420 /* Adjust the size of the window to make the text area keep the
3421 * same size and to avoid that part of our window is off-screen
3422 * and a scrollbar can't be used, for example. */
3423 gui_set_shellsize(FALSE
, fix_size
, need_set_size
);
3426 /* GTK has the annoying habit of sending us resize events when
3427 * changing the window size ourselves. This mostly happens when
3428 * waiting for a character to arrive, quite unpredictably, and may
3429 * change Columns and Rows when we don't want it. Wait for a
3430 * character here to avoid this effect.
3431 * If you remove this, please test this command for resizing
3432 * effects (with optional left scrollbar): ":vsp|q|vsp|q|vsp|q".
3433 * Don't do this while starting up though.
3434 * And don't change Rows, it may have be reduced intentionally
3435 * when adding menu/toolbar/tabline. */
3442 /* When the console tabline appears or disappears the window positions
3444 if (firstwin
->w_winrow
!= tabline_height())
3445 shell_new_rows(); /* recompute window positions and heights */
3450 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3452 * Return TRUE if the GUI is taking care of the tabline.
3453 * It may still be hidden if 'showtabline' is zero.
3458 return gui
.in_use
&& vim_strchr(p_go
, GO_TABLINE
) != NULL
;
3462 * Return TRUE if the GUI is showing the tabline.
3463 * This uses 'showtabline'.
3468 if (!gui_use_tabline()
3470 || (p_stal
== 1 && first_tabpage
->tp_next
== NULL
))
3476 * Update the tabline.
3477 * This may display/undisplay the tabline and update the labels.
3480 gui_update_tabline()
3482 int showit
= gui_has_tabline();
3483 int shown
= gui_mch_showing_tabline();
3485 if (!gui
.starting
&& starting
== 0)
3487 /* Updating the tabline uses direct GUI commands, flush
3488 * outstanding instructions first. (esp. clear screen) */
3492 if (!showit
!= !shown
)
3493 gui_mch_show_tabline(showit
);
3495 gui_mch_update_tabline();
3497 /* When the tabs change from hidden to shown or from shown to
3498 * hidden the size of the text area should remain the same. */
3499 if (!showit
!= !shown
)
3500 gui_set_shellsize(FALSE
, showit
, RESIZE_VERT
);
3505 * Get the label or tooltip for tab page "tp" into NameBuff[].
3508 get_tabline_label(tp
, tooltip
)
3510 int tooltip
; /* TRUE: get tooltip */
3512 int modified
= FALSE
;
3518 /* Use 'guitablabel' or 'guitabtooltip' if it's set. */
3519 opt
= (tooltip
? &p_gtt
: &p_gtl
);
3522 int use_sandbox
= FALSE
;
3523 int save_called_emsg
= called_emsg
;
3524 char_u res
[MAXPATHL
];
3525 tabpage_T
*save_curtab
;
3526 char_u
*opt_name
= (char_u
*)(tooltip
? "guitabtooltip"
3529 called_emsg
= FALSE
;
3531 printer_page_num
= tabpage_index(tp
);
3533 set_vim_var_nr(VV_LNUM
, printer_page_num
);
3534 use_sandbox
= was_set_insecurely(opt_name
, 0);
3536 /* It's almost as going to the tabpage, but without autocommands. */
3537 curtab
->tp_firstwin
= firstwin
;
3538 curtab
->tp_lastwin
= lastwin
;
3539 curtab
->tp_curwin
= curwin
;
3540 save_curtab
= curtab
;
3542 topframe
= curtab
->tp_topframe
;
3543 firstwin
= curtab
->tp_firstwin
;
3544 lastwin
= curtab
->tp_lastwin
;
3545 curwin
= curtab
->tp_curwin
;
3546 curbuf
= curwin
->w_buffer
;
3548 /* Can't use NameBuff directly, build_stl_str_hl() uses it. */
3549 build_stl_str_hl(curwin
, res
, MAXPATHL
, *opt
, use_sandbox
,
3550 0, (int)Columns
, NULL
, NULL
);
3551 STRCPY(NameBuff
, res
);
3553 /* Back to the original curtab. */
3554 curtab
= save_curtab
;
3555 topframe
= curtab
->tp_topframe
;
3556 firstwin
= curtab
->tp_firstwin
;
3557 lastwin
= curtab
->tp_lastwin
;
3558 curwin
= curtab
->tp_curwin
;
3559 curbuf
= curwin
->w_buffer
;
3562 set_string_option_direct(opt_name
, -1,
3563 (char_u
*)"", OPT_FREE
, SID_ERROR
);
3564 called_emsg
|= save_called_emsg
;
3567 /* If 'guitablabel'/'guitabtooltip' is not set or the result is empty then
3568 * use a default label. */
3569 if (**opt
== NUL
|| *NameBuff
== NUL
)
3571 /* Get the buffer name into NameBuff[] and shorten it. */
3572 get_trans_bufname(tp
== curtab
? curbuf
: tp
->tp_curwin
->w_buffer
);
3574 shorten_dir(NameBuff
);
3576 wp
= (tp
== curtab
) ? firstwin
: tp
->tp_firstwin
;
3577 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
3578 if (bufIsChanged(wp
->w_buffer
))
3580 if (modified
|| wincount
> 1)
3583 vim_snprintf((char *)buf
, sizeof(buf
), "%d", wincount
);
3589 mch_memmove(NameBuff
+ STRLEN(buf
), NameBuff
, STRLEN(NameBuff
) + 1);
3590 mch_memmove(NameBuff
, buf
, STRLEN(buf
));
3596 * Send the event for clicking to select tab page "nr".
3597 * Returns TRUE if it was done, FALSE when skipped because we are already at
3598 * that tab page or the cmdline window is open.
3601 send_tabline_event(nr
)
3606 if (nr
== tabpage_index(curtab
))
3609 /* Don't put events in the input queue now. */
3616 /* Set it back to the current tab page. */
3617 gui_mch_set_curtab(tabpage_index(curtab
));
3622 string
[1] = KS_TABLINE
;
3623 string
[2] = KE_FILLER
;
3624 add_to_input_buf(string
, 3);
3626 add_to_input_buf_csi(string
, 1);
3631 * Send a tabline menu event
3634 send_tabline_menu_event(tabidx
, event
)
3640 /* Don't put events in the input queue now. */
3641 if (hold_gui_events
)
3645 string
[1] = KS_TABMENU
;
3646 string
[2] = KE_FILLER
;
3647 add_to_input_buf(string
, 3);
3649 string
[1] = (char_u
)(long)event
;
3650 add_to_input_buf_csi(string
, 2);
3659 #if defined(FEAT_WINDOWS) || defined(PROTO)
3661 * Remove all scrollbars. Used before switching to another tab page.
3664 gui_remove_scrollbars()
3669 for (i
= 0; i
< 3; i
++)
3671 if (i
== SBAR_BOTTOM
)
3672 gui_mch_enable_scrollbar(&gui
.bottom_sbar
, FALSE
);
3677 gui_do_scrollbar(wp
, i
, FALSE
);
3680 curtab
->tp_prev_which_scrollbars
[i
] = -1;
3686 gui_create_scrollbar(sb
, type
, wp
)
3691 static int sbar_ident
= 0;
3693 sb
->ident
= sbar_ident
++; /* No check for too big, but would it happen? */
3697 #ifdef FEAT_GUI_ATHENA
3704 #ifdef FEAT_VERTSPLIT
3707 sb
->status_height
= 0;
3708 gui_mch_create_scrollbar(sb
, (wp
== NULL
) ? SBAR_HORIZ
: SBAR_VERT
);
3712 * Find the scrollbar with the given index.
3715 gui_find_scrollbar(ident
)
3720 if (gui
.bottom_sbar
.ident
== ident
)
3721 return &gui
.bottom_sbar
;
3724 if (wp
->w_scrollbars
[SBAR_LEFT
].ident
== ident
)
3725 return &wp
->w_scrollbars
[SBAR_LEFT
];
3726 if (wp
->w_scrollbars
[SBAR_RIGHT
].ident
== ident
)
3727 return &wp
->w_scrollbars
[SBAR_RIGHT
];
3733 * For most systems: Put a code in the input buffer for a dragged scrollbar.
3735 * For Win32, Macintosh and GTK+ 2:
3736 * Scrollbars seem to grab focus and vim doesn't read the input queue until
3737 * you stop dragging the scrollbar. We get here each time the scrollbar is
3738 * dragged another pixel, but as far as the rest of vim goes, it thinks
3739 * we're just hanging in the call to DispatchMessage() in
3740 * process_message(). The DispatchMessage() call that hangs was passed a
3741 * mouse button click event in the scrollbar window. -- webb.
3743 * Solution: Do the scrolling right here. But only when allowed.
3744 * Ignore the scrollbars while executing an external command or when there
3745 * are still characters to be processed.
3748 gui_drag_scrollbar(sb
, value
, still_dragging
)
3757 #ifdef USE_ON_FLY_SCROLL
3758 colnr_T old_leftcol
= curwin
->w_leftcol
;
3759 # ifdef FEAT_SCROLLBIND
3760 linenr_T old_topline
= curwin
->w_topline
;
3763 int old_topfill
= curwin
->w_topfill
;
3766 char_u bytes
[sizeof(long_u
)];
3773 /* Don't put events in the input queue now. */
3774 if (hold_gui_events
)
3778 if (cmdwin_type
!= 0 && sb
->wp
!= curwin
)
3785 gui
.dragged_sb
= SBAR_BOTTOM
;
3786 else if (sb
== &sb
->wp
->w_scrollbars
[SBAR_LEFT
])
3787 gui
.dragged_sb
= SBAR_LEFT
;
3789 gui
.dragged_sb
= SBAR_RIGHT
;
3790 gui
.dragged_wp
= sb
->wp
;
3794 gui
.dragged_sb
= SBAR_NONE
;
3796 /* Keep the "dragged_wp" value until after the scrolling, for when the
3797 * moust button is released. GTK2 doesn't send the button-up event. */
3798 gui
.dragged_wp
= NULL
;
3802 /* Vertical sbar info is kept in the first sbar (the left one) */
3804 sb
= &sb
->wp
->w_scrollbars
[0];
3807 * Check validity of value
3811 #ifdef SCROLL_PAST_END
3812 else if (value
> sb
->max
)
3815 if (value
> sb
->max
- sb
->size
+ 1)
3816 value
= sb
->max
- sb
->size
+ 1;
3821 #ifdef USE_ON_FLY_SCROLL
3822 /* When not allowed to do the scrolling right now, return. */
3823 if (dont_scroll
|| input_available())
3826 #ifdef FEAT_INS_EXPAND
3827 /* Disallow scrolling the current window when the completion popup menu is
3829 if ((sb
->wp
== NULL
|| sb
->wp
== curwin
) && pum_visible())
3833 #ifdef FEAT_RIGHTLEFT
3834 if (sb
->wp
== NULL
&& curwin
->w_p_rl
)
3836 value
= sb
->max
+ 1 - sb
->size
- value
;
3842 if (sb
->wp
!= NULL
) /* vertical scrollbar */
3846 for (wp
= firstwin
; wp
!= sb
->wp
&& wp
!= NULL
; wp
= wp
->w_next
)
3851 if (sb
->wp
!= curwin
)
3855 #ifdef USE_ON_FLY_SCROLL
3856 current_scrollbar
= sb_num
;
3857 scrollbar_value
= value
;
3863 else if (State
& INSERT
)
3868 else if (State
& CMDLINE
)
3870 if (msg_scrolled
== 0)
3876 # ifdef FEAT_FOLDING
3877 /* Value may have been changed for closed fold. */
3878 sb
->value
= sb
->wp
->w_topline
- 1;
3881 /* When dragging one scrollbar and there is another one at the other
3882 * side move the thumb of that one too. */
3883 if (gui
.which_scrollbars
[SBAR_RIGHT
] && gui
.which_scrollbars
[SBAR_LEFT
])
3884 gui_mch_set_scrollbar_thumb(
3885 &sb
->wp
->w_scrollbars
[
3886 sb
== &sb
->wp
->w_scrollbars
[SBAR_RIGHT
]
3887 ? SBAR_LEFT
: SBAR_RIGHT
],
3888 sb
->value
, sb
->size
, sb
->max
);
3892 bytes
[1] = KS_VER_SCROLLBAR
;
3893 bytes
[2] = KE_FILLER
;
3894 bytes
[3] = (char_u
)sb_num
;
3900 #ifdef USE_ON_FLY_SCROLL
3901 scrollbar_value
= value
;
3904 gui_do_horiz_scroll();
3905 else if (State
& INSERT
)
3907 else if (State
& CMDLINE
)
3909 if (msg_scrolled
== 0)
3911 gui_do_horiz_scroll();
3915 if (old_leftcol
!= curwin
->w_leftcol
)
3917 updateWindow(curwin
); /* update window, status and cmdline */
3922 bytes
[1] = KS_HOR_SCROLLBAR
;
3923 bytes
[2] = KE_FILLER
;
3928 #ifdef USE_ON_FLY_SCROLL
3929 # ifdef FEAT_SCROLLBIND
3931 * synchronize other windows, as necessary according to 'scrollbind'
3934 && ((sb
->wp
== NULL
&& curwin
->w_leftcol
!= old_leftcol
)
3935 || (sb
->wp
== curwin
&& (curwin
->w_topline
!= old_topline
3937 || curwin
->w_topfill
!= old_topfill
3941 do_check_scrollbind(TRUE
);
3942 /* need to update the window right here */
3943 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3944 if (wp
->w_redr_type
> 0)
3950 gui_update_cursor(FALSE
, TRUE
);
3952 add_to_input_buf(bytes
, byte_count
);
3953 add_long_to_buf((long_u
)value
, bytes
);
3954 add_to_input_buf_csi(bytes
, sizeof(long_u
));
3963 gui_update_scrollbars(force
)
3964 int force
; /* Force all scrollbars to get updated */
3968 long val
, size
, max
; /* need 32 bits here */
3971 #ifdef FEAT_VERTSPLIT
3972 static win_T
*prev_curwin
= NULL
;
3975 /* Update the horizontal scrollbar */
3976 gui_update_horiz_scrollbar(force
);
3979 /* Return straight away if there is neither a left nor right scrollbar.
3980 * On MS-Windows this is required anyway for scrollwheel messages. */
3981 if (!gui
.which_scrollbars
[SBAR_LEFT
] && !gui
.which_scrollbars
[SBAR_RIGHT
])
3986 * Don't want to update a scrollbar while we're dragging it. But if we
3987 * have both a left and right scrollbar, and we drag one of them, we still
3988 * need to update the other one.
3990 if (!force
&& (gui
.dragged_sb
== SBAR_LEFT
|| gui
.dragged_sb
== SBAR_RIGHT
)
3991 && gui
.which_scrollbars
[SBAR_LEFT
]
3992 && gui
.which_scrollbars
[SBAR_RIGHT
])
3995 * If we have two scrollbars and one of them is being dragged, just
3996 * copy the scrollbar position from the dragged one to the other one.
3998 which_sb
= SBAR_LEFT
+ SBAR_RIGHT
- gui
.dragged_sb
;
3999 if (gui
.dragged_wp
!= NULL
)
4000 gui_mch_set_scrollbar_thumb(
4001 &gui
.dragged_wp
->w_scrollbars
[which_sb
],
4002 gui
.dragged_wp
->w_scrollbars
[0].value
,
4003 gui
.dragged_wp
->w_scrollbars
[0].size
,
4004 gui
.dragged_wp
->w_scrollbars
[0].max
);
4007 /* avoid that moving components around generates events */
4010 for (wp
= firstwin
; wp
!= NULL
; wp
= W_NEXT(wp
))
4012 if (wp
->w_buffer
== NULL
) /* just in case */
4014 /* Skip a scrollbar that is being dragged. */
4015 if (!force
&& (gui
.dragged_sb
== SBAR_LEFT
4016 || gui
.dragged_sb
== SBAR_RIGHT
)
4017 && gui
.dragged_wp
== wp
)
4020 #ifdef SCROLL_PAST_END
4021 max
= wp
->w_buffer
->b_ml
.ml_line_count
- 1;
4023 max
= wp
->w_buffer
->b_ml
.ml_line_count
+ wp
->w_height
- 2;
4025 if (max
< 0) /* empty buffer */
4027 val
= wp
->w_topline
- 1;
4028 size
= wp
->w_height
;
4029 #ifdef SCROLL_PAST_END
4030 if (val
> max
) /* just in case */
4033 if (size
> max
+ 1) /* just in case */
4035 if (val
> max
- size
+ 1)
4036 val
= max
- size
+ 1;
4038 if (val
< 0) /* minimal value is 0 */
4042 * Scrollbar at index 0 (the left one) contains all the information.
4043 * It would be the same info for left and right so we just store it for
4046 sb
= &wp
->w_scrollbars
[0];
4049 * Note: no check for valid w_botline. If it's not valid the
4050 * scrollbars will be updated later anyway.
4052 if (size
< 1 || wp
->w_botline
- 2 > max
)
4055 * This can happen during changing files. Just don't update the
4056 * scrollbar for now.
4058 sb
->height
= 0; /* Force update next time */
4059 if (gui
.which_scrollbars
[SBAR_LEFT
])
4060 gui_do_scrollbar(wp
, SBAR_LEFT
, FALSE
);
4061 if (gui
.which_scrollbars
[SBAR_RIGHT
])
4062 gui_do_scrollbar(wp
, SBAR_RIGHT
, FALSE
);
4065 if (force
|| sb
->height
!= wp
->w_height
4067 || sb
->top
!= wp
->w_winrow
4068 || sb
->status_height
!= wp
->w_status_height
4069 # ifdef FEAT_VERTSPLIT
4070 || sb
->width
!= wp
->w_width
4071 || prev_curwin
!= curwin
4076 /* Height, width or position of scrollbar has changed. For
4077 * vertical split: curwin changed. */
4078 sb
->height
= wp
->w_height
;
4080 sb
->top
= wp
->w_winrow
;
4081 sb
->status_height
= wp
->w_status_height
;
4082 # ifdef FEAT_VERTSPLIT
4083 sb
->width
= wp
->w_width
;
4087 /* Calculate height and position in pixels */
4088 h
= (sb
->height
+ sb
->status_height
) * gui
.char_height
;
4089 y
= sb
->top
* gui
.char_height
+ gui
.border_offset
;
4090 #if defined(FEAT_MENU) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \
4091 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MACVIM))
4092 if (gui
.menu_is_active
)
4093 y
+= gui
.menu_height
;
4096 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_ATHENA))
4097 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
4098 # ifdef FEAT_GUI_ATHENA
4099 y
+= gui
.toolbar_height
;
4101 # ifdef FEAT_GUI_MSWIN
4102 y
+= TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
;
4107 #if defined(FEAT_GUI_TABLINE) && defined(FEAT_GUI_MSWIN)
4108 if (gui_has_tabline())
4109 y
+= gui
.tabline_height
;
4113 if (wp
->w_winrow
== 0)
4116 /* Height of top scrollbar includes width of top border */
4117 h
+= gui
.border_offset
;
4118 y
-= gui
.border_offset
;
4120 if (gui
.which_scrollbars
[SBAR_LEFT
])
4122 gui_mch_set_scrollbar_pos(&wp
->w_scrollbars
[SBAR_LEFT
],
4124 gui
.scrollbar_width
, h
);
4125 gui_do_scrollbar(wp
, SBAR_LEFT
, TRUE
);
4127 if (gui
.which_scrollbars
[SBAR_RIGHT
])
4129 gui_mch_set_scrollbar_pos(&wp
->w_scrollbars
[SBAR_RIGHT
],
4130 gui
.right_sbar_x
, y
,
4131 gui
.scrollbar_width
, h
);
4132 gui_do_scrollbar(wp
, SBAR_RIGHT
, TRUE
);
4136 /* Reduce the number of calls to gui_mch_set_scrollbar_thumb() by
4137 * checking if the thumb moved at least a pixel. Only do this for
4138 * Athena, most other GUIs require the update anyway to make the
4140 #ifdef FEAT_GUI_ATHENA
4144 y
= (val
* (sb
->height
+ 2) * gui
.char_height
+ max
/ 2) / max
;
4145 if (force
|| sb
->pixval
!= y
|| sb
->size
!= size
|| sb
->max
!= max
)
4147 if (force
|| sb
->value
!= val
|| sb
->size
!= size
|| sb
->max
!= max
)
4150 /* Thumb of scrollbar has moved */
4152 #ifdef FEAT_GUI_ATHENA
4157 if (gui
.which_scrollbars
[SBAR_LEFT
]
4158 && (gui
.dragged_sb
!= SBAR_LEFT
|| gui
.dragged_wp
!= wp
))
4159 gui_mch_set_scrollbar_thumb(&wp
->w_scrollbars
[SBAR_LEFT
],
4161 if (gui
.which_scrollbars
[SBAR_RIGHT
]
4162 && (gui
.dragged_sb
!= SBAR_RIGHT
|| gui
.dragged_wp
!= wp
))
4163 gui_mch_set_scrollbar_thumb(&wp
->w_scrollbars
[SBAR_RIGHT
],
4167 #ifdef FEAT_VERTSPLIT
4168 prev_curwin
= curwin
;
4174 * Enable or disable a scrollbar.
4175 * Check for scrollbars for vertically split windows which are not enabled
4179 gui_do_scrollbar(wp
, which
, enable
)
4181 int which
; /* SBAR_LEFT or SBAR_RIGHT */
4182 int enable
; /* TRUE to enable scrollbar */
4184 #ifdef FEAT_VERTSPLIT
4185 int midcol
= curwin
->w_wincol
+ curwin
->w_width
/ 2;
4186 int has_midcol
= (wp
->w_wincol
<= midcol
4187 && wp
->w_wincol
+ wp
->w_width
>= midcol
);
4189 /* Only enable scrollbars that contain the middle column of the current
4191 if (gui
.which_scrollbars
[SBAR_RIGHT
] != gui
.which_scrollbars
[SBAR_LEFT
])
4193 /* Scrollbars only on one side. Don't enable scrollbars that don't
4194 * contain the middle column of the current window. */
4200 /* Scrollbars on both sides. Don't enable scrollbars that neither
4201 * contain the middle column of the current window nor are on the far
4203 if (midcol
> Columns
/ 2)
4205 if (which
== SBAR_LEFT
? wp
->w_wincol
!= 0 : !has_midcol
)
4210 if (which
== SBAR_RIGHT
? wp
->w_wincol
+ wp
->w_width
!= Columns
4216 gui_mch_enable_scrollbar(&wp
->w_scrollbars
[which
], enable
);
4220 * Scroll a window according to the values set in the globals current_scrollbar
4221 * and scrollbar_value. Return TRUE if the cursor in the current window moved
4222 * or FALSE otherwise.
4227 win_T
*wp
, *save_wp
;
4231 linenr_T old_topline
;
4236 for (wp
= firstwin
, i
= 0; i
< current_scrollbar
; wp
= W_NEXT(wp
), i
++)
4240 /* Couldn't find window */
4244 * Compute number of lines to scroll. If zero, nothing to do.
4246 nlines
= (long)scrollbar_value
+ 1 - (long)wp
->w_topline
;
4251 old_topline
= wp
->w_topline
;
4253 old_topfill
= wp
->w_topfill
;
4255 old_cursor
= wp
->w_cursor
;
4257 curbuf
= wp
->w_buffer
;
4259 scrolldown(-nlines
, gui
.dragged_wp
== NULL
);
4261 scrollup(nlines
, gui
.dragged_wp
== NULL
);
4262 /* Reset dragged_wp after using it. "dragged_sb" will have been reset for
4263 * the mouse-up event already, but we still want it to behave like when
4264 * dragging. But not the next click in an arrow. */
4265 if (gui
.dragged_sb
== SBAR_NONE
)
4266 gui
.dragged_wp
= NULL
;
4268 if (old_topline
!= wp
->w_topline
4270 || old_topfill
!= wp
->w_topfill
4276 cursor_correct(); /* fix window for 'so' */
4277 update_topline(); /* avoid up/down jump */
4279 if (old_cursor
.lnum
!= wp
->w_cursor
.lnum
)
4280 coladvance(wp
->w_curswant
);
4281 #ifdef FEAT_SCROLLBIND
4282 wp
->w_scbind_pos
= wp
->w_topline
;
4286 /* Make sure wp->w_leftcol and wp->w_skipcol are correct. */
4290 curbuf
= save_wp
->w_buffer
;
4293 * Don't call updateWindow() when nothing has changed (it will overwrite
4294 * the status line!).
4296 if (old_topline
!= wp
->w_topline
4297 || wp
->w_redr_type
!= 0
4299 || old_topfill
!= wp
->w_topfill
4305 #ifdef FEAT_INS_EXPAND
4309 wp
->w_lines_valid
= 0;
4312 /* Don't set must_redraw here, it may cause the popup menu to
4313 * disappear when losing focus after a scrollbar drag. */
4314 if (wp
->w_redr_type
< type
)
4315 wp
->w_redr_type
= type
;
4316 updateWindow(wp
); /* update window, status line, and cmdline */
4319 #ifdef FEAT_INS_EXPAND
4320 /* May need to redraw the popup menu. */
4325 return (wp
== curwin
&& !equalpos(curwin
->w_cursor
, old_cursor
));
4330 * Horizontal scrollbar stuff:
4334 * Return length of line "lnum" for horizontal scrolling.
4337 scroll_line_len(lnum
)
4349 w
= chartabsize(p
, col
);
4351 if (*p
== NUL
) /* don't count the last character */
4358 /* Remember which line is currently the longest, so that we don't have to
4359 * search for it when scrolling horizontally. */
4360 static linenr_T longest_lnum
= 0;
4363 gui_update_horiz_scrollbar(force
)
4366 long value
, size
, max
; /* need 32 bit ints here */
4368 if (!gui
.which_scrollbars
[SBAR_BOTTOM
])
4371 if (!force
&& gui
.dragged_sb
== SBAR_BOTTOM
)
4374 if (!force
&& curwin
->w_p_wrap
&& gui
.prev_wrap
)
4378 * It is possible for the cursor to be invalid if we're in the middle of
4379 * something (like changing files). If so, don't do anything for now.
4381 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
4383 gui
.bottom_sbar
.value
= -1;
4387 size
= W_WIDTH(curwin
);
4388 if (curwin
->w_p_wrap
)
4391 #ifdef SCROLL_PAST_END
4394 max
= W_WIDTH(curwin
) - 1;
4399 value
= curwin
->w_leftcol
;
4401 /* Calculate maximum for horizontal scrollbar. Check for reasonable
4402 * line numbers, topline and botline can be invalid when displaying is
4404 if (vim_strchr(p_go
, GO_HORSCROLL
) == NULL
4405 && curwin
->w_topline
<= curwin
->w_cursor
.lnum
4406 && curwin
->w_botline
> curwin
->w_cursor
.lnum
4407 && curwin
->w_botline
<= curbuf
->b_ml
.ml_line_count
+ 1)
4412 /* Use maximum of all visible lines. Remember the lnum of the
4413 * longest line, clostest to the cursor line. Used when scrolling
4416 for (lnum
= curwin
->w_topline
; lnum
< curwin
->w_botline
; ++lnum
)
4418 n
= scroll_line_len(lnum
);
4419 if (n
> (colnr_T
)max
)
4422 longest_lnum
= lnum
;
4424 else if (n
== (colnr_T
)max
4425 && abs((int)(lnum
- curwin
->w_cursor
.lnum
))
4426 < abs((int)(longest_lnum
- curwin
->w_cursor
.lnum
)))
4427 longest_lnum
= lnum
;
4431 /* Use cursor line only. */
4432 max
= scroll_line_len(curwin
->w_cursor
.lnum
);
4433 #ifdef FEAT_VIRTUALEDIT
4434 if (virtual_active())
4436 /* May move the cursor even further to the right. */
4437 if (curwin
->w_virtcol
>= (colnr_T
)max
)
4438 max
= curwin
->w_virtcol
;
4442 #ifndef SCROLL_PAST_END
4443 max
+= W_WIDTH(curwin
) - 1;
4445 /* The line number isn't scrolled, thus there is less space when
4446 * 'number' is set (also for 'foldcolumn'). */
4447 size
-= curwin_col_off();
4448 #ifndef SCROLL_PAST_END
4449 max
-= curwin_col_off();
4453 #ifndef SCROLL_PAST_END
4454 if (value
> max
- size
+ 1)
4455 value
= max
- size
+ 1; /* limit the value to allowable range */
4458 #ifdef FEAT_RIGHTLEFT
4461 value
= max
+ 1 - size
- value
;
4469 if (!force
&& value
== gui
.bottom_sbar
.value
&& size
== gui
.bottom_sbar
.size
4470 && max
== gui
.bottom_sbar
.max
)
4473 gui
.bottom_sbar
.value
= value
;
4474 gui
.bottom_sbar
.size
= size
;
4475 gui
.bottom_sbar
.max
= max
;
4476 gui
.prev_wrap
= curwin
->w_p_wrap
;
4478 gui_mch_set_scrollbar_thumb(&gui
.bottom_sbar
, value
, size
, max
);
4482 * Do a horizontal scroll. Return TRUE if the cursor moved, FALSE otherwise.
4485 gui_do_horiz_scroll()
4487 /* no wrapping, no scrolling */
4488 if (curwin
->w_p_wrap
)
4491 if (curwin
->w_leftcol
== scrollbar_value
)
4494 curwin
->w_leftcol
= (colnr_T
)scrollbar_value
;
4496 /* When the line of the cursor is too short, move the cursor to the
4497 * longest visible line. Do a sanity check on "longest_lnum", just in
4499 if (vim_strchr(p_go
, GO_HORSCROLL
) == NULL
4500 && longest_lnum
>= curwin
->w_topline
4501 && longest_lnum
< curwin
->w_botline
4502 && !virtual_active())
4504 if (scrollbar_value
> scroll_line_len(curwin
->w_cursor
.lnum
))
4506 curwin
->w_cursor
.lnum
= longest_lnum
;
4507 curwin
->w_cursor
.col
= 0;
4511 return leftcol_changed();
4515 * Check that none of the colors are the same as the background color
4520 if (gui
.norm_pixel
== gui
.back_pixel
|| gui
.norm_pixel
== INVALCOLOR
)
4522 gui_set_bg_color((char_u
*)"White");
4523 if (gui
.norm_pixel
== gui
.back_pixel
|| gui
.norm_pixel
== INVALCOLOR
)
4524 gui_set_fg_color((char_u
*)"Black");
4529 gui_set_fg_color(name
)
4532 gui
.norm_pixel
= gui_get_color(name
);
4533 hl_set_fg_color_name(vim_strsave(name
));
4537 gui_set_bg_color(name
)
4540 gui
.back_pixel
= gui_get_color(name
);
4541 hl_set_bg_color_name(vim_strsave(name
));
4545 * Allocate a color by name.
4546 * Returns INVALCOLOR and gives an error message when failed.
4556 t
= gui_mch_get_color(name
);
4559 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
4563 EMSG2(_("E254: Cannot allocate color %s"), name
);
4568 * Return the grey value of a color (range 0-255).
4571 gui_get_lightness(pixel
)
4574 long_u rgb
= gui_mch_get_rgb(pixel
);
4576 return (int)( (((rgb
>> 16) & 0xff) * 299)
4577 + (((rgb
>> 8) & 0xff) * 587)
4578 + ((rgb
& 0xff) * 114)) / 1000;
4581 #if defined(FEAT_GUI_X11) || defined(PROTO)
4583 gui_new_scrollbar_colors()
4587 /* Nothing to do if GUI hasn't started yet. */
4593 gui_mch_set_scrollbar_colors(&(wp
->w_scrollbars
[SBAR_LEFT
]));
4594 gui_mch_set_scrollbar_colors(&(wp
->w_scrollbars
[SBAR_RIGHT
]));
4596 gui_mch_set_scrollbar_colors(&gui
.bottom_sbar
);
4601 * Call this when focus has changed.
4604 gui_focus_change(in_focus
)
4608 * Skip this code to avoid drawing the cursor when debugging and switching
4609 * between the debugger window and gvim.
4612 gui
.in_focus
= in_focus
;
4613 out_flush(); /* make sure output has been written */
4614 gui_update_cursor(TRUE
, FALSE
);
4617 xim_set_focus(in_focus
);
4620 /* Put events in the input queue only when allowed.
4621 * ui_focus_change() isn't called directly, because it invokes
4622 * autocommands and that must not happen asynchronously. */
4623 if (!hold_gui_events
)
4628 bytes
[1] = KS_EXTRA
;
4629 bytes
[2] = in_focus
? (int)KE_FOCUSGAINED
: (int)KE_FOCUSLOST
;
4630 add_to_input_buf(bytes
, 3);
4636 * Called when the mouse moved (but not when dragging).
4639 gui_mouse_moved(x
, y
)
4646 /* Ignore this while still starting up. */
4647 if (!gui
.in_use
|| gui
.starting
)
4650 #ifdef FEAT_MOUSESHAPE
4651 /* Get window pointer, and update mouse shape as well. */
4655 /* Only handle this when 'mousefocus' set and ... */
4657 && !hold_gui_events
/* not holding events */
4658 && (State
& (NORMAL
|INSERT
))/* Normal/Visual/Insert mode */
4659 && State
!= HITRETURN
/* but not hit-return prompt */
4660 && msg_scrolled
== 0 /* no scrolled message */
4661 && !need_mouse_correct
/* not moving the pointer */
4662 && gui
.in_focus
) /* gvim in focus */
4664 /* Don't move the mouse when it's left or right of the Vim window */
4665 if (x
< 0 || x
> Columns
* gui
.char_width
)
4667 #ifndef FEAT_MOUSESHAPE
4670 if (wp
== curwin
|| wp
== NULL
)
4671 return; /* still in the same old window, or none at all */
4674 /* Ignore position in the tab pages line. */
4675 if (Y_2_ROW(y
) < tabline_height())
4680 * format a mouse click on status line input
4681 * ala gui_send_mouse_event(0, x, y, 0, 0);
4682 * Trick: Use a column number -1, so that get_pseudo_mouse_code() will
4683 * generate a K_LEFTMOUSE_NM key code.
4687 /* abort the current operator first */
4689 add_to_input_buf(st
, 1);
4694 st
[3] = (char_u
)MOUSE_LEFT
;
4695 fill_mouse_coord(st
+ 4,
4696 #ifdef FEAT_VERTSPLIT
4697 wp
->w_wincol
== 0 ? -1 : wp
->w_wincol
+ MOUSE_COLOFF
,
4701 wp
->w_height
+ W_WINROW(wp
));
4703 add_to_input_buf(st
, 8);
4704 st
[3] = (char_u
)MOUSE_RELEASE
;
4705 add_to_input_buf(st
, 8);
4707 /* Need to wake up the main loop */
4708 if (gtk_main_level() > 0)
4715 * Called when mouse should be moved to window with focus.
4723 need_mouse_correct
= FALSE
;
4725 if (!(gui
.in_use
&& p_mousef
))
4728 gui_mch_getmouse(&x
, &y
);
4729 /* Don't move the mouse when it's left or right of the Vim window */
4730 if (x
< 0 || x
> Columns
* gui
.char_width
)
4733 # ifdef FEAT_WINDOWS
4734 && Y_2_ROW(y
) >= tabline_height()
4738 if (wp
!= curwin
&& wp
!= NULL
) /* If in other than current window */
4740 validate_cline_row();
4741 gui_mch_setmouse((int)W_ENDCOL(curwin
) * gui
.char_width
- 3,
4742 (W_WINROW(curwin
) + curwin
->w_wrow
) * gui
.char_height
4743 + (gui
.char_height
) / 2);
4748 * Find window where the mouse pointer "y" coordinate is in.
4763 if (row
< 0 || col
< 0) /* before first window */
4765 wp
= mouse_find_win(&row
, &col
);
4766 # ifdef FEAT_MOUSESHAPE
4767 if (State
== HITRETURN
|| State
== ASKMORE
)
4769 if (Y_2_ROW(y
) >= msg_row
)
4770 update_mouseshape(SHAPE_IDX_MOREL
);
4772 update_mouseshape(SHAPE_IDX_MORE
);
4774 else if (row
> wp
->w_height
) /* below status line */
4775 update_mouseshape(SHAPE_IDX_CLINE
);
4776 # ifdef FEAT_VERTSPLIT
4777 else if (!(State
& CMDLINE
) && W_VSEP_WIDTH(wp
) > 0 && col
== wp
->w_width
4778 && (row
!= wp
->w_height
|| !stl_connected(wp
)) && msg_scrolled
== 0)
4779 update_mouseshape(SHAPE_IDX_VSEP
);
4781 else if (!(State
& CMDLINE
) && W_STATUS_HEIGHT(wp
) > 0
4782 && row
== wp
->w_height
&& msg_scrolled
== 0)
4783 update_mouseshape(SHAPE_IDX_STATUS
);
4785 update_mouseshape(-2);
4794 * ":gui" and ":gvim": Change from the terminal version to the GUI version.
4795 * File names may be given to redefine the args list.
4801 char_u
*arg
= eap
->arg
;
4804 * Check for "-f" argument: foreground, don't fork.
4805 * Also don't fork when started with "gvim -f".
4806 * Do fork when using "gui -b".
4809 && (arg
[1] == 'f' || arg
[1] == 'b')
4810 && (arg
[2] == NUL
|| vim_iswhite(arg
[2])))
4812 gui
.dofork
= (arg
[1] == 'b');
4813 eap
->arg
= skipwhite(eap
->arg
+ 2);
4817 /* Clear the command. Needed for when forking+exiting, to avoid part
4818 * of the argument ending up after the shell prompt. */
4821 /* os x doesn't really support fork(), so we can't fork of a gui
4822 * in an already running vim. see gui_start() for more details.
4826 msg_clr_eos_force();
4829 if (!ends_excmd(*eap
->arg
))
4833 #if ((defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32) \
4834 || defined(FEAT_GUI_PHOTON)) && defined(FEAT_TOOLBAR)) || defined(PROTO)
4836 * This is shared between Athena, Motif and GTK.
4838 static void gfp_setname
__ARGS((char_u
*fname
, void *cookie
));
4841 * Callback function for do_in_runtimepath().
4844 gfp_setname(fname
, cookie
)
4848 char_u
*gfp_buffer
= cookie
;
4850 if (STRLEN(fname
) >= MAXPATHL
)
4853 STRCPY(gfp_buffer
, fname
);
4857 * Find the path of bitmap "name" with extension "ext" in 'runtimepath'.
4858 * Return FAIL for failure and OK if buffer[MAXPATHL] contains the result.
4861 gui_find_bitmap(name
, buffer
, ext
)
4866 if (STRLEN(name
) > MAXPATHL
- 14)
4868 vim_snprintf((char *)buffer
, MAXPATHL
, "bitmaps/%s.%s", name
, ext
);
4869 if (do_in_runtimepath(buffer
, FALSE
, gfp_setname
, buffer
) == FAIL
4875 # if !defined(HAVE_GTK2) || defined(PROTO)
4877 * Given the name of the "icon=" argument, try finding the bitmap file for the
4878 * icon. If it is an absolute path name, use it as it is. Otherwise append
4879 * "ext" and search for it in 'runtimepath'.
4880 * The result is put in "buffer[MAXPATHL]". If something fails "buffer"
4884 gui_find_iconfile(name
, buffer
, ext
)
4889 char_u buf
[MAXPATHL
+ 1];
4891 expand_env(name
, buffer
, MAXPATHL
);
4892 if (!mch_isFullName(buffer
) && gui_find_bitmap(buffer
, buf
, ext
) == OK
)
4893 STRCPY(buffer
, buf
);
4898 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(PROTO)
4906 else if (error_ga
.ga_data
!= NULL
)
4908 /* avoid putting up a message box with blanks only */
4909 for (p
= (char_u
*)error_ga
.ga_data
; *p
!= NUL
; ++p
)
4912 /* Truncate a very long message, it will go off-screen. */
4913 if (STRLEN(p
) > 2000)
4914 STRCPY(p
+ 2000 - 14, "...(truncated)");
4915 (void)do_dialog(VIM_ERROR
, (char_u
*)_("Error"),
4916 p
, (char_u
*)_("&Ok"), 1, NULL
);
4919 ga_clear(&error_ga
);
4924 #if defined(NO_CONSOLE_INPUT) || defined(PROTO)
4926 * Return TRUE if still starting up and there is no place to enter text.
4927 * For GTK and X11 we check if stderr is not a tty, which means we were
4928 * (probably) started from the desktop. Also check stdin, "vim >& file" does
4929 * allow typing on stdin.
4934 return ((!gui
.in_use
|| gui
.starting
)
4936 && !isatty(0) && !isatty(2)
4942 #if defined(FIND_REPLACE_DIALOG) || defined(FEAT_SUN_WORKSHOP) \
4943 || defined(NEED_GUI_UPDATE_SCREEN) \
4946 * Update the current window and the screen.
4953 update_screen(0); /* may need to update the screen */
4955 out_flush(); /* make sure output has been written */
4956 gui_update_cursor(TRUE
, FALSE
);
4961 #if defined(FIND_REPLACE_DIALOG) || defined(PROTO)
4962 static void concat_esc
__ARGS((garray_T
*gap
, char_u
*text
, int what
));
4965 * Get the text to use in a find/replace dialog. Uses the last search pattern
4966 * if the argument is empty.
4967 * Returns an allocated string.
4970 get_find_dialog_text(arg
, wwordp
, mcasep
)
4972 int *wwordp
; /* return: TRUE if \< \> found */
4973 int *mcasep
; /* return: TRUE if \C found */
4978 text
= last_search_pat();
4983 text
= vim_strsave(text
);
4986 int len
= (int)STRLEN(text
);
4990 if (len
>= 2 && STRNCMP(text
, "\\V", 2) == 0)
4992 mch_memmove(text
, text
+ 2, (size_t)(len
- 1));
4996 /* Recognize "\c" and "\C" and remove. */
4997 if (len
>= 2 && *text
== '\\' && (text
[1] == 'c' || text
[1] == 'C'))
4999 *mcasep
= (text
[1] == 'C');
5000 mch_memmove(text
, text
+ 2, (size_t)(len
- 1));
5004 /* Recognize "\<text\>" and remove. */
5006 && STRNCMP(text
, "\\<", 2) == 0
5007 && STRNCMP(text
+ len
- 2, "\\>", 2) == 0)
5010 mch_memmove(text
, text
+ 2, (size_t)(len
- 4));
5011 text
[len
- 4] = NUL
;
5014 /* Recognize "\/" or "\?" and remove. */
5015 for (i
= 0; i
+ 1 < len
; ++i
)
5016 if (text
[i
] == '\\' && (text
[i
+ 1] == '/'
5017 || text
[i
+ 1] == '?'))
5019 mch_memmove(text
+ i
, text
+ i
+ 1, (size_t)(len
- i
));
5028 * Concatenate "text" to grow array "gap", escaping "what" with a backslash.
5031 concat_esc(gap
, text
, what
)
5036 while (*text
!= NUL
)
5039 int l
= (*mb_ptr2len
)(text
);
5044 ga_append(gap
, *text
++);
5049 ga_append(gap
, '\\');
5050 ga_append(gap
, *text
);
5056 * Handle the press of a button in the find-replace dialog.
5057 * Return TRUE when something was added to the input buffer.
5060 gui_do_findrepl(flags
, find_text
, repl_text
, down
)
5061 int flags
; /* one of FRD_REPLACE, FRD_FINDNEXT, etc. */
5064 int down
; /* Search downwards. */
5068 int type
= (flags
& FRD_TYPE_MASK
);
5070 regmatch_T regmatch
;
5071 int save_did_emsg
= did_emsg
;
5073 ga_init2(&ga
, 1, 100);
5074 if (type
== FRD_REPLACEALL
)
5075 ga_concat(&ga
, (char_u
*)"%s/");
5077 ga_concat(&ga
, (char_u
*)"\\V");
5078 if (flags
& FRD_MATCH_CASE
)
5079 ga_concat(&ga
, (char_u
*)"\\C");
5081 ga_concat(&ga
, (char_u
*)"\\c");
5082 if (flags
& FRD_WHOLE_WORD
)
5083 ga_concat(&ga
, (char_u
*)"\\<");
5084 if (type
== FRD_REPLACEALL
|| down
)
5085 concat_esc(&ga
, find_text
, '/'); /* escape slashes */
5087 concat_esc(&ga
, find_text
, '?'); /* escape '?' */
5088 if (flags
& FRD_WHOLE_WORD
)
5089 ga_concat(&ga
, (char_u
*)"\\>");
5091 if (type
== FRD_REPLACEALL
)
5093 ga_concat(&ga
, (char_u
*)"/");
5094 /* escape / and \ */
5095 p
= vim_strsave_escaped(repl_text
, (char_u
*)"/\\");
5099 ga_concat(&ga
, (char_u
*)"/g");
5101 ga_append(&ga
, NUL
);
5103 if (type
== FRD_REPLACE
)
5105 /* Do the replacement when the text at the cursor matches. Thus no
5106 * replacement is done if the cursor was moved! */
5107 regmatch
.regprog
= vim_regcomp(ga
.ga_data
, RE_MAGIC
+ RE_STRING
);
5109 if (regmatch
.regprog
!= NULL
)
5111 p
= ml_get_cursor();
5112 if (vim_regexec_nl(®match
, p
, (colnr_T
)0)
5113 && regmatch
.startp
[0] == p
)
5115 /* Clear the command line to remove any old "No match"
5119 if (u_save_cursor() == OK
)
5121 /* A button was pressed thus undo should be synced. */
5124 del_bytes((long)(regmatch
.endp
[0] - regmatch
.startp
[0]),
5130 MSG(_("No match at cursor, finding next"));
5131 vim_free(regmatch
.regprog
);
5135 if (type
== FRD_REPLACEALL
)
5137 /* A button was pressed, thus undo should be synced. */
5139 do_cmdline_cmd(ga
.ga_data
);
5143 /* Search for the next match. */
5145 do_search(NULL
, down
? '/' : '?', ga
.ga_data
, 1L,
5146 SEARCH_MSG
+ SEARCH_MARK
);
5147 msg_scroll
= i
; /* don't let an error message set msg_scroll */
5150 /* Don't want to pass did_emsg to other code, it may cause disabling
5151 * syntax HL if we were busy redrawing. */
5152 did_emsg
= save_did_emsg
;
5154 if (State
& (NORMAL
| INSERT
))
5156 gui_update_screen(); /* update the screen */
5157 msg_didout
= 0; /* overwrite any message */
5158 need_wait_return
= FALSE
; /* don't wait for return */
5161 vim_free(ga
.ga_data
);
5162 return (ga
.ga_len
> 0);
5167 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \
5168 || defined(FEAT_GUI_MSWIN) \
5169 || defined(FEAT_GUI_MAC) \
5171 || defined(FEAT_GUI_MACVIM)
5174 static void gui_wingoto_xy
__ARGS((int x
, int y
));
5177 * Jump to the window at specified point (x, y).
5180 gui_wingoto_xy(x
, y
)
5184 int row
= Y_2_ROW(y
);
5185 int col
= X_2_COL(x
);
5188 if (row
>= 0 && col
>= 0)
5190 wp
= mouse_find_win(&row
, &col
);
5191 if (wp
!= NULL
&& wp
!= curwin
)
5198 * Process file drop. Mouse cursor position, key modifiers, name of files
5199 * and count of files are given. Argument "fnames[count]" has full pathnames
5200 * of dropped files, they will be freed in this function, and caller can't use
5201 * fnames after call this function.
5205 gui_handle_drop(x
, y
, modifiers
, fnames
, count
)
5216 * When the cursor is at the command line, add the file names to the
5217 * command line, don't edit the files.
5219 if (State
& CMDLINE
)
5221 shorten_filenames(fnames
, count
);
5222 for (i
= 0; i
< count
; ++i
)
5224 if (fnames
[i
] != NULL
)
5227 add_to_input_buf((char_u
*)" ", 1);
5229 /* We don't know what command is used thus we can't be sure
5230 * about which characters need to be escaped. Only escape the
5231 * most common ones. */
5232 # ifdef BACKSLASH_IN_FILENAME
5233 p
= vim_strsave_escaped(fnames
[i
], (char_u
*)" \t\"|");
5235 p
= vim_strsave_escaped(fnames
[i
], (char_u
*)"\\ \t\"|");
5238 add_to_input_buf_csi(p
, (int)STRLEN(p
));
5240 vim_free(fnames
[i
]);
5247 /* Go to the window under mouse cursor, then shorten given "fnames" by
5248 * current window, because a window can have local current dir. */
5249 # ifdef FEAT_WINDOWS
5250 gui_wingoto_xy(x
, y
);
5252 shorten_filenames(fnames
, count
);
5254 /* If Shift held down, remember the first item. */
5255 if ((modifiers
& MOUSE_SHIFT
) != 0)
5256 p
= vim_strsave(fnames
[0]);
5260 /* Handle the drop, :edit or :split to get to the file. This also
5261 * frees fnames[]. Skip this if there is only one item it's a
5262 * directory and Shift is held down. */
5263 if (count
== 1 && (modifiers
& MOUSE_SHIFT
) != 0
5264 && mch_isdir(fnames
[0]))
5266 vim_free(fnames
[0]);
5270 handle_drop(count
, fnames
, (modifiers
& MOUSE_CTRL
) != 0);
5272 /* If Shift held down, change to first file's directory. If the first
5273 * item is a directory, change to that directory (and let the explorer
5274 * plugin show the contents). */
5279 if (mch_chdir((char *)p
) == 0)
5280 shorten_fnames(TRUE
);
5282 else if (vim_chdirfile(p
) == OK
)
5283 shorten_fnames(TRUE
);
5287 /* Update the screen display */
5288 update_screen(NOT_VALID
);
5290 gui_update_menus(0);
5294 gui_update_cursor(FALSE
, FALSE
);