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 newargv
[0] = argv
[0];
156 * make sure "-f" is in front of potential "--remote" flags, else
157 * they would consume it.
161 for (i
= 1; i
< argc
; i
++) {
162 newargv
[i
+ 1] = argv
[i
];
164 newargv
[argc
+1] = NULL
;
170 fprintf(stderr
, "vim: Mac OS X workaround fork() failed!");
176 /* shut down all the stuff we just started, just to start
177 * it again from the exec :-\ */
180 /* make sure we survive our shell */
183 /* Restarts the vim process, will not return. */
184 execvp(argv
[0], newargv
);
186 /* if we come here, exec has failed. bail. */
193 int pipefd
[2]; /* pipe between parent and child */
197 /* Setup a pipe between the child and the parent, so that the parent
198 * knows when the child has done the setsid() call and is allowed to
200 pipe_error
= (pipe(pipefd
) < 0);
202 if (pid
> 0) /* Parent */
204 /* Give the child some time to do the setsid(), otherwise the
205 * exit() may kill the child too (when starting gvim from inside a
208 ui_delay(300L, TRUE
);
211 /* The read returns when the child closes the pipe (or when
212 * the child dies for some reason). */
214 (void)read(pipefd
[0], &dummy
, (size_t)1);
218 /* When swapping screens we may need to go to the next line, e.g.,
219 * after a hit-enter prompt and using ":gui". */
224 * The parent must skip the normal exit() processing, the child
225 * will do it. For example, GTK messes up signals when exiting.
230 # if defined(HAVE_SETSID) || defined(HAVE_SETPGID)
232 * Change our process group. On some systems/shells a CTRL-C in the
233 * shell where Vim was started would otherwise kill gvim!
235 if (pid
== 0) /* child */
236 # if defined(HAVE_SETSID)
249 # if defined(FEAT_GUI_GNOME) && defined(FEAT_SESSION)
250 /* Tell the session manager our new PID */
257 # if defined(__QNXNTO__)
258 if (gui
.in_use
&& dofork
)
259 procmgr_daemon(0, PROCMGR_DAEMON_KEEPUMASK
| PROCMGR_DAEMON_NOCHDIR
|
260 PROCMGR_DAEMON_NOCLOSE
| PROCMGR_DAEMON_NODEVNULL
);
265 /* If the GUI started successfully, trigger the GUIEnter event, otherwise
266 * the GUIFailed event. */
267 apply_autocmds(gui
.in_use
? EVENT_GUIENTER
: EVENT_GUIFAILED
,
268 NULL
, NULL
, FALSE
, curbuf
);
275 * Call this when vim starts up, whether or not the GUI is started
278 gui_prepare(argc
, argv
)
282 gui
.in_use
= FALSE
; /* No GUI yet (maybe later) */
283 gui
.starting
= FALSE
; /* No GUI yet (maybe later) */
284 gui_mch_prepare(argc
, argv
);
288 * Try initializing the GUI and check if it can be started.
289 * Used from main() to check early if "vim -g" can start the GUI.
290 * Used from gui_init() to prepare for starting the GUI.
291 * Returns FAIL or OK.
296 static int result
= MAYBE
;
301 EMSG(_("E229: Cannot start the GUI"));
305 gui
.shell_created
= FALSE
;
307 gui
.in_focus
= TRUE
; /* so the guicursor setting works */
308 gui
.dragged_sb
= SBAR_NONE
;
309 gui
.dragged_wp
= NULL
;
310 gui
.pointer_hidden
= FALSE
;
313 gui
.num_cols
= Columns
;
316 gui
.cursor_is_valid
= FALSE
;
317 gui
.scroll_region_top
= 0;
318 gui
.scroll_region_bot
= Rows
- 1;
319 gui
.scroll_region_left
= 0;
320 gui
.scroll_region_right
= Columns
- 1;
321 gui
.highlight_mask
= HL_NORMAL
;
325 gui
.border_width
= 0;
327 gui
.norm_font
= NOFONT
;
329 gui
.bold_font
= NOFONT
;
330 gui
.ital_font
= NOFONT
;
331 gui
.boldital_font
= NOFONT
;
332 # ifdef FEAT_XFONTSET
333 gui
.fontset
= NOFONTSET
;
339 # ifdef FONTSET_ALWAYS
340 gui
.menu_fontset
= NOFONTSET
;
342 gui
.menu_font
= NOFONT
;
345 gui
.menu_is_active
= TRUE
; /* default: include menu */
346 # if !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM))
347 gui
.menu_height
= MENU_DEFAULT_HEIGHT
;
351 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA))
352 gui
.toolbar_height
= 0;
354 #if defined(FEAT_FOOTER) && defined(FEAT_GUI_MOTIF)
355 gui
.footer_height
= 0;
357 #ifdef FEAT_BEVAL_TIP
358 gui
.tooltip_fontset
= NOFONTSET
;
361 gui
.scrollbar_width
= gui
.scrollbar_height
= SB_DEFAULT_WIDTH
;
364 #ifdef ALWAYS_USE_GUI
367 result
= gui_mch_init_check();
373 * This is the call which starts the GUI.
379 static int recursive
= 0;
382 * It's possible to use ":gui" in a .gvimrc file. The first halve of this
383 * function will then be executed at the first call, the rest by the
384 * recursive call. This allow the shell to be opened halfway reading a
393 /* If can't initialize, don't try doing the rest */
394 if (gui_init_check() == FAIL
)
402 * Reset 'paste'. It's useful in the terminal, but not in the GUI. It
403 * breaks the Paste toolbar button.
405 set_option_value((char_u
*)"paste", 0L, NULL
, 0);
408 * Set up system-wide default menus.
410 #if defined(SYS_MENU_FILE) && defined(FEAT_MENU)
411 if (vim_strchr(p_go
, GO_NOSYSMENU
) == NULL
)
414 do_source((char_u
*)SYS_MENU_FILE
, FALSE
, DOSO_NONE
);
420 * Switch on the mouse by default, unless the user changed it already.
421 * This can then be changed in the .gvimrc.
423 if (!option_was_set((char_u
*)"mouse"))
424 set_string_option_direct((char_u
*)"mouse", -1,
425 (char_u
*)"a", OPT_FREE
, SID_NONE
);
428 * If -U option given, use only the initializations from that file and
429 * nothing else. Skip all initializations for "-U NONE" or "-u NORC".
431 if (use_gvimrc
!= NULL
)
433 if (STRCMP(use_gvimrc
, "NONE") != 0
434 && STRCMP(use_gvimrc
, "NORC") != 0
435 && do_source(use_gvimrc
, FALSE
, DOSO_NONE
) != OK
)
436 EMSG2(_("E230: Cannot read from \"%s\""), use_gvimrc
);
441 * Get system wide defaults for gvim, only when file name defined.
443 #ifdef SYS_GVIMRC_FILE
444 do_source((char_u
*)SYS_GVIMRC_FILE
, FALSE
, DOSO_NONE
);
448 * Try to read GUI initialization commands from the following
450 * - environment variable GVIMINIT
451 * - the user gvimrc file (~/.gvimrc)
452 * - the second user gvimrc file ($VIM/.gvimrc for Dos)
453 * - the third user gvimrc file ($VIM/.gvimrc for Amiga)
454 * The first that exists is used, the rest is ignored.
456 if (process_env((char_u
*)"GVIMINIT", FALSE
) == FAIL
457 && do_source((char_u
*)USR_GVIMRC_FILE
, TRUE
,
459 #ifdef USR_GVIMRC_FILE2
460 && do_source((char_u
*)USR_GVIMRC_FILE2
, TRUE
,
465 #ifdef USR_GVIMRC_FILE3
466 (void)do_source((char_u
*)USR_GVIMRC_FILE3
, TRUE
, DOSO_GVIMRC
);
471 * Read initialization commands from ".gvimrc" in current
472 * directory. This is only done if the 'exrc' option is set.
473 * Because of security reasons we disallow shell and write
474 * commands now, except for unix if the file is owned by the user
475 * or 'secure' option has been reset in environment of global
477 * Only do this if GVIMRC_FILE is not the same as USR_GVIMRC_FILE,
478 * USR_GVIMRC_FILE2, USR_GVIMRC_FILE3 or SYS_GVIMRC_FILE.
486 /* if ".gvimrc" file is not owned by user, set 'secure'
488 if (mch_stat(GVIMRC_FILE
, &s
) || s
.st_uid
!= getuid())
495 if ( fullpathcmp((char_u
*)USR_GVIMRC_FILE
,
496 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
497 #ifdef SYS_GVIMRC_FILE
498 && fullpathcmp((char_u
*)SYS_GVIMRC_FILE
,
499 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
501 #ifdef USR_GVIMRC_FILE2
502 && fullpathcmp((char_u
*)USR_GVIMRC_FILE2
,
503 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
505 #ifdef USR_GVIMRC_FILE3
506 && fullpathcmp((char_u
*)USR_GVIMRC_FILE3
,
507 (char_u
*)GVIMRC_FILE
, FALSE
) != FPC_SAME
510 do_source((char_u
*)GVIMRC_FILE
, TRUE
, DOSO_GVIMRC
);
513 need_wait_return
= TRUE
;
518 if (need_wait_return
|| msg_didany
)
524 /* If recursive call opened the shell, return here from the first call */
529 * Create the GUI shell.
531 gui
.in_use
= TRUE
; /* Must be set after menus have been set up */
532 if (gui_mch_init() == FAIL
)
535 /* Avoid a delay for an error message that was printed in the terminal
536 * where Vim was started. */
537 emsg_on_display
= FALSE
;
540 need_wait_return
= FALSE
;
544 * Check validity of any generic resources that may have been loaded.
546 if (gui
.border_width
< 0)
547 gui
.border_width
= 0;
550 * Set up the fonts. First use a font specified with "-fn" or "-font".
552 if (font_argument
!= NULL
)
553 set_option_value((char_u
*)"gfn", 0L, (char_u
*)font_argument
, 0);
556 (*p_guifontset
== NUL
557 || gui_init_font(p_guifontset
, TRUE
) == FAIL
) &&
559 gui_init_font(*p_guifont
== NUL
? hl_get_font_name()
560 : p_guifont
, FALSE
) == FAIL
)
562 EMSG(_("E665: Cannot start GUI, no valid font found"));
566 if (gui_get_wide_font() == FAIL
)
567 EMSG(_("E231: 'guifontwide' invalid"));
570 gui
.num_cols
= Columns
;
572 gui_reset_scroll_region();
574 /* Create initial scrollbars */
577 gui_create_scrollbar(&wp
->w_scrollbars
[SBAR_LEFT
], SBAR_LEFT
, wp
);
578 gui_create_scrollbar(&wp
->w_scrollbars
[SBAR_RIGHT
], SBAR_RIGHT
, wp
);
580 gui_create_scrollbar(&gui
.bottom_sbar
, SBAR_BOTTOM
, NULL
);
583 gui_create_initial_menus(root_menu
);
585 #ifdef FEAT_SUN_WORKSHOP
586 if (usingSunWorkShop
)
589 #ifdef FEAT_SIGN_ICONS
593 /* Configure the desired menu and scrollbars */
594 gui_init_which_components(NULL
);
596 /* All components of the GUI have been created now */
597 gui
.shell_created
= TRUE
;
600 /* Set the shell size, adjusted for the screen size. For GTK this only
601 * works after the shell has been opened, thus it is further down. */
602 gui_set_shellsize(FALSE
, TRUE
, RESIZE_BOTH
);
604 #if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)
605 /* Need to set the size of the menubar after all the menus have been
607 gui_mch_compute_menu_height((Widget
)0);
611 * Actually open the GUI shell.
613 if (gui_mch_open() != FAIL
)
621 /* Our GUI can't do bidi. */
624 #if defined(FEAT_GUI_GTK)
625 /* Give GTK+ a chance to put all widget's into place. */
629 /* If there is no 'm' in 'guioptions' we need to remove the menu now.
630 * It was still there to make F10 work. */
631 if (vim_strchr(p_go
, GO_MENUS
) == NULL
)
634 gui_mch_enable_menu(FALSE
);
640 /* Now make sure the shell fits on the screen. */
641 gui_set_shellsize(FALSE
, TRUE
, RESIZE_BOTH
);
643 /* When 'lines' was set while starting up the topframe may have to be
648 /* Always create the Balloon Evaluation area, but disable it when
649 * 'ballooneval' is off */
651 balloonEval
= gui_mch_create_beval_area(gui
.drawarea
, NULL
,
652 &general_beval_cb
, NULL
);
654 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
656 extern Widget textArea
;
657 balloonEval
= gui_mch_create_beval_area(textArea
, NULL
,
658 &general_beval_cb
, NULL
);
662 balloonEval
= gui_mch_create_beval_area(NULL
, NULL
,
663 &general_beval_cb
, NULL
);
668 gui_mch_disable_beval_area(balloonEval
);
671 #ifdef FEAT_NETBEANS_INTG
672 if (starting
== 0 && usingNetbeans
)
673 /* Tell the client that it can start sending commands. */
674 netbeans_startup_done();
676 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
677 if (!im_xim_isvalid_imactivate())
678 EMSG(_("E599: Value of 'imactivatekey' is invalid"));
680 /* When 'cmdheight' was set during startup it may not have taken
690 /* undo gui_mch_init() */
705 /* don't free the fonts, it leads to a BUS error
706 * richard@whitequeen.com Jul 99 */
707 free_highlight_fonts();
713 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_MSWIN) \
714 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MAC) \
715 || defined(PROTO) || defined(FEAT_GUI_MACVIM)
716 # define NEED_GUI_UPDATE_SCREEN 1
718 * Called when the GUI shell is closed by the user. If there are no changed
719 * files Vim exits, otherwise there will be a dialog to ask the user what to
721 * When this function returns, Vim should NOT exit!
726 cmdmod_T save_cmdmod
;
728 save_cmdmod
= cmdmod
;
730 /* Only exit when there are no changed files */
733 cmdmod
.browse
= TRUE
;
735 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
736 cmdmod
.confirm
= TRUE
;
738 /* If there are changed buffers, present the user with a dialog if
739 * possible, otherwise give an error message. */
740 if (!check_changed_any(FALSE
))
744 cmdmod
= save_cmdmod
;
745 gui_update_screen(); /* redraw, window may show changed buffer */
750 * Set the font. "font_list" is a a comma separated list of font names. The
751 * first font name that works is used. If none is found, use the default
753 * If "fontset" is TRUE, the "font_list" is used as one name for the fontset.
754 * Return OK when able to set the font. When it failed FAIL is returned and
755 * the fonts are unchanged.
759 gui_init_font(font_list
, fontset
)
764 char_u font_name
[FONTLEN
];
765 int font_list_empty
= FALSE
;
772 if (*font_list
== NUL
)
773 font_list_empty
= TRUE
;
777 /* When using a fontset, the whole list of fonts is one name. */
779 ret
= gui_mch_init_font(font_list
, TRUE
);
782 while (*font_list
!= NUL
)
784 /* Isolate one comma separated font name. */
785 (void)copy_option_part(&font_list
, font_name
, FONTLEN
, ",");
787 #if defined(FEAT_GUI_MACVIM)
788 /* The font dialog is modeless in Mac OS X, so when
789 * gui_mch_init_font() is called with "*" it brings up the
790 * dialog and returns immediately. In this case we don't want
791 * it to be called again with NULL, so return here. */
792 if (STRCMP(font_name
, "*") == 0) {
793 gui_mch_init_font(font_name
, FALSE
);
798 /* Careful!!! The Win32 version of gui_mch_init_font(), when
799 * called with "*" will change p_guifont to the selected font
800 * name, which frees the old value. This makes font_list
801 * invalid. Thus when OK is returned here, font_list must no
803 if (gui_mch_init_font(font_name
, FALSE
) == OK
)
805 #if defined(FEAT_MBYTE) && !defined(HAVE_GTK2)
806 /* If it's a Unicode font, try setting 'guifontwide' to a
807 * similar double-width font. */
808 if ((p_guifontwide
== NULL
|| *p_guifontwide
== NUL
)
809 && strstr((char *)font_name
, "10646") != NULL
)
810 set_guifontwide(font_name
);
819 && STRCMP(font_list
, "*") != 0
820 && (font_list_empty
|| gui
.norm_font
== NOFONT
))
823 * Couldn't load any font in 'font_list', keep the current font if
824 * there is one. If 'font_list' is empty, or if there is no current
825 * font, tell gui_mch_init_font() to try to find a font we can load.
827 ret
= gui_mch_init_font(NULL
, FALSE
);
833 /* Set normal font as current font */
834 # ifdef FEAT_XFONTSET
835 if (gui
.fontset
!= NOFONTSET
)
836 gui_mch_set_fontset(gui
.fontset
);
839 gui_mch_set_font(gui
.norm_font
);
841 gui_set_shellsize(FALSE
,
853 #if defined(FEAT_MBYTE) || defined(PROTO)
856 * Try setting 'guifontwide' to a font twice as wide as "name".
859 set_guifontwide(name
)
863 char_u wide_name
[FONTLEN
+ 10]; /* room for 2 * width and '*' */
869 for (p
= name
; *p
!= NUL
; ++p
)
875 if (i
== 6) /* font type: change "--" to "-*-" */
880 else if (i
== 12) /* found the width */
886 /* Double the width specification. */
887 sprintf((char *)wp
, "%d%s", i
* 2, p
);
888 font
= gui_mch_get_font(wide_name
, FALSE
);
891 gui_mch_free_font(gui
.wide_font
);
892 gui
.wide_font
= font
;
893 set_string_option_direct((char_u
*)"gfw", -1,
894 wide_name
, OPT_FREE
, 0);
902 # endif /* !HAVE_GTK2 */
905 * Get the font for 'guifontwide'.
906 * Return FAIL for an invalid font name.
911 GuiFont font
= NOFONT
;
912 char_u font_name
[FONTLEN
];
915 if (!gui
.in_use
) /* Can't allocate font yet, assume it's OK. */
916 return OK
; /* Will give an error message later. */
918 if (p_guifontwide
!= NULL
&& *p_guifontwide
!= NUL
)
920 for (p
= p_guifontwide
; *p
!= NUL
; )
922 /* Isolate one comma separated font name. */
923 (void)copy_option_part(&p
, font_name
, FONTLEN
, ",");
924 font
= gui_mch_get_font(font_name
, FALSE
);
932 gui_mch_free_font(gui
.wide_font
);
934 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */
935 if (font
!= NOFONT
&& gui
.norm_font
!= NOFONT
936 && pango_font_description_equal(font
, gui
.norm_font
))
938 gui
.wide_font
= NOFONT
;
939 gui_mch_free_font(font
);
943 gui
.wide_font
= font
;
949 gui_set_cursor(row
, col
)
958 * gui_check_pos - check if the cursor is on the screen.
963 if (gui
.row
>= screen_Rows
)
964 gui
.row
= screen_Rows
- 1;
965 if (gui
.col
>= screen_Columns
)
966 gui
.col
= screen_Columns
- 1;
967 if (gui
.cursor_row
>= screen_Rows
|| gui
.cursor_col
>= screen_Columns
)
968 gui
.cursor_is_valid
= FALSE
;
972 * Redraw the cursor if necessary or when forced.
973 * Careful: The contents of ScreenLines[] must match what is on the screen,
974 * otherwise this goes wrong. May need to call out_flush() first.
977 gui_update_cursor(force
, clear_selection
)
978 int force
; /* when TRUE, update even when not moved */
979 int clear_selection
;/* clear selection under cursor */
986 guicolor_T cfg
, cbg
, cc
; /* cursor fore-/background color */
987 int cattr
; /* cursor attributes */
989 attrentry_T
*aep
= NULL
;
991 /* Don't update the cursor when halfway busy scrolling.
992 * ScreenLines[] isn't valid then. */
993 if (!can_update_cursor
)
997 if (!gui
.cursor_is_valid
|| force
998 || gui
.row
!= gui
.cursor_row
|| gui
.col
!= gui
.cursor_col
)
1000 gui_undraw_cursor();
1003 #ifdef USE_IM_CONTROL
1004 if (gui
.row
!= gui
.cursor_row
|| gui
.col
!= gui
.cursor_col
)
1005 im_set_position(gui
.row
, gui
.col
);
1007 gui
.cursor_row
= gui
.row
;
1008 gui
.cursor_col
= gui
.col
;
1010 /* Only write to the screen after ScreenLines[] has been initialized */
1011 if (!screen_cleared
|| ScreenLines
== NULL
)
1014 /* Clear the selection if we are about to write over it */
1015 if (clear_selection
)
1016 clip_may_clear_selection(gui
.row
, gui
.row
);
1017 /* Check that the cursor is inside the shell (resizing may have made
1019 if (gui
.row
>= screen_Rows
|| gui
.col
>= screen_Columns
)
1022 gui
.cursor_is_valid
= TRUE
;
1025 * How the cursor is drawn depends on the current mode.
1027 idx
= get_shape_idx(FALSE
);
1028 if (State
& LANGMAP
)
1029 id
= shape_table
[idx
].id_lm
;
1031 id
= shape_table
[idx
].id
;
1033 /* get the colors and attributes for the cursor. Default is inverted */
1037 gui_mch_set_blinking(shape_table
[idx
].blinkwait
,
1038 shape_table
[idx
].blinkon
,
1039 shape_table
[idx
].blinkoff
);
1042 cattr
= syn_id2colors(id
, &cfg
, &cbg
);
1043 #if defined(USE_IM_CONTROL) || defined(FEAT_HANGULIN)
1048 if (im_get_status())
1050 iid
= syn_name2id((char_u
*)"CursorIM");
1053 syn_id2colors(iid
, &fg
, &bg
);
1054 if (bg
!= INVALCOLOR
)
1056 if (fg
!= INVALCOLOR
)
1065 * Get the attributes for the character under the cursor.
1066 * When no cursor color was given, use the character color.
1068 attr
= ScreenAttrs
[LineOffset
[gui
.row
] + gui
.col
];
1070 aep
= syn_gui_attr2entry(attr
);
1073 attr
= aep
->ae_attr
;
1074 if (cfg
== INVALCOLOR
)
1075 cfg
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.bg_color
1076 : aep
->ae_u
.gui
.fg_color
);
1077 if (cbg
== INVALCOLOR
)
1078 cbg
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.fg_color
1079 : aep
->ae_u
.gui
.bg_color
);
1081 if (cfg
== INVALCOLOR
)
1082 cfg
= (attr
& HL_INVERSE
) ? gui
.back_pixel
: gui
.norm_pixel
;
1083 if (cbg
== INVALCOLOR
)
1084 cbg
= (attr
& HL_INVERSE
) ? gui
.norm_pixel
: gui
.back_pixel
;
1089 xim_bg_color
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.fg_color
1090 : aep
->ae_u
.gui
.bg_color
);
1091 xim_fg_color
= ((attr
& HL_INVERSE
) ? aep
->ae_u
.gui
.bg_color
1092 : aep
->ae_u
.gui
.fg_color
);
1093 if (xim_bg_color
== INVALCOLOR
)
1094 xim_bg_color
= (attr
& HL_INVERSE
) ? gui
.norm_pixel
1096 if (xim_fg_color
== INVALCOLOR
)
1097 xim_fg_color
= (attr
& HL_INVERSE
) ? gui
.back_pixel
1102 xim_bg_color
= (attr
& HL_INVERSE
) ? gui
.norm_pixel
1104 xim_fg_color
= (attr
& HL_INVERSE
) ? gui
.back_pixel
1109 attr
&= ~HL_INVERSE
;
1110 if (cattr
& HL_INVERSE
)
1116 cattr
&= ~HL_INVERSE
;
1119 * When we don't have window focus, draw a hollow cursor.
1123 gui_mch_draw_hollow_cursor(cbg
);
1127 old_hl_mask
= gui
.highlight_mask
;
1128 if (shape_table
[idx
].shape
== SHAPE_BLOCK
1129 #ifdef FEAT_HANGULIN
1135 * Draw the text character with the cursor colors. Use the
1136 * character attributes plus the cursor attributes.
1138 gui
.highlight_mask
= (cattr
| attr
);
1139 #ifdef FEAT_HANGULIN
1140 if (composing_hangul
)
1141 (void)gui_outstr_nowrap(composing_hangul_buffer
, 2,
1142 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
, cfg
, cbg
, 0);
1145 (void)gui_screenchar(LineOffset
[gui
.row
] + gui
.col
,
1146 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
, cfg
, cbg
, 0);
1150 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT)
1151 int col_off
= FALSE
;
1154 * First draw the partial cursor, then overwrite with the text
1155 * character, using a transparent background.
1157 if (shape_table
[idx
].shape
== SHAPE_VER
)
1159 cur_height
= gui
.char_height
;
1160 cur_width
= (gui
.char_width
* shape_table
[idx
].percentage
1165 cur_height
= (gui
.char_height
* shape_table
[idx
].percentage
1167 cur_width
= gui
.char_width
;
1170 if (has_mbyte
&& (*mb_off2cells
)(LineOffset
[gui
.row
] + gui
.col
,
1171 LineOffset
[gui
.row
] + screen_Columns
) > 1)
1173 /* Double wide character. */
1174 if (shape_table
[idx
].shape
!= SHAPE_VER
)
1175 cur_width
+= gui
.char_width
;
1176 # ifdef FEAT_RIGHTLEFT
1177 if (CURSOR_BAR_RIGHT
)
1179 /* gui.col points to the left halve of the character but
1180 * the vertical line needs to be on the right halve.
1181 * A double-wide horizontal line is also drawn from the
1182 * right halve in gui_mch_draw_part_cursor(). */
1189 gui_mch_draw_part_cursor(cur_width
, cur_height
, cbg
);
1190 #if defined(FEAT_MBYTE) && defined(FEAT_RIGHTLEFT)
1195 #ifndef FEAT_GUI_MSWIN /* doesn't seem to work for MSWindows */
1196 gui
.highlight_mask
= ScreenAttrs
[LineOffset
[gui
.row
] + gui
.col
];
1197 (void)gui_screenchar(LineOffset
[gui
.row
] + gui
.col
,
1198 GUI_MON_TRS_CURSOR
| GUI_MON_NOCLEAR
,
1199 (guicolor_T
)0, (guicolor_T
)0, 0);
1202 gui
.highlight_mask
= old_hl_mask
;
1206 #if defined(FEAT_MENU) || defined(PROTO)
1210 # if !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \
1211 || defined(FEAT_GUI_MACVIM))
1212 if (gui
.menu_is_active
&& gui
.in_use
)
1213 gui_mch_set_menu_pos(0, 0, gui
.menu_width
, gui
.menu_height
);
1219 * Position the various GUI components (text area, menu). The vertical
1220 * scrollbars are NOT handled here. See gui_update_scrollbars().
1224 gui_position_components(total_width
)
1229 int text_area_width
;
1230 int text_area_height
;
1232 /* avoid that moving components around generates events */
1236 if (gui
.which_scrollbars
[SBAR_LEFT
])
1237 text_area_x
+= gui
.scrollbar_width
;
1240 #if defined(FEAT_MENU) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON) \
1241 || defined(FEAT_GUI_MACVIM))
1242 gui
.menu_width
= total_width
;
1243 if (gui
.menu_is_active
)
1244 text_area_y
+= gui
.menu_height
;
1246 #if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_MSWIN)
1247 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
1248 text_area_y
= TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
;
1251 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
1252 || defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_MAC))
1253 if (gui_has_tabline())
1254 text_area_y
+= gui
.tabline_height
;
1257 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA))
1258 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
1260 # ifdef FEAT_GUI_ATHENA
1261 gui_mch_set_toolbar_pos(0, text_area_y
,
1262 gui
.menu_width
, gui
.toolbar_height
);
1264 text_area_y
+= gui
.toolbar_height
;
1268 text_area_width
= gui
.num_cols
* gui
.char_width
+ gui
.border_offset
* 2;
1269 text_area_height
= gui
.num_rows
* gui
.char_height
+ gui
.border_offset
* 2;
1271 gui_mch_set_text_area_pos(text_area_x
,
1275 #if defined(FEAT_XIM) && !defined(HAVE_GTK2)
1276 + xim_get_status_area_height()
1280 gui_position_menu();
1282 if (gui
.which_scrollbars
[SBAR_BOTTOM
])
1283 gui_mch_set_scrollbar_pos(&gui
.bottom_sbar
,
1285 text_area_y
+ text_area_height
,
1287 gui
.scrollbar_height
);
1288 gui
.left_sbar_x
= 0;
1289 gui
.right_sbar_x
= text_area_x
+ text_area_width
;
1295 * Get the width of the widgets and decorations to the side of the text area.
1298 gui_get_base_width()
1302 base_width
= 2 * gui
.border_offset
;
1303 if (gui
.which_scrollbars
[SBAR_LEFT
])
1304 base_width
+= gui
.scrollbar_width
;
1305 if (gui
.which_scrollbars
[SBAR_RIGHT
])
1306 base_width
+= gui
.scrollbar_width
;
1311 * Get the height of the widgets and decorations above and below the text area.
1314 gui_get_base_height()
1318 base_height
= 2 * gui
.border_offset
;
1319 if (gui
.which_scrollbars
[SBAR_BOTTOM
])
1320 base_height
+= gui
.scrollbar_height
;
1322 /* We can't take the sizes properly into account until anything is
1323 * realized. Therefore we recalculate all the values here just before
1324 * setting the size. (--mdcki) */
1325 #elif !defined(FEAT_GUI_MACVIM)
1327 if (gui
.menu_is_active
)
1328 base_height
+= gui
.menu_height
;
1330 # ifdef FEAT_TOOLBAR
1331 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
1332 # if defined(FEAT_GUI_MSWIN) && defined(FEAT_TOOLBAR)
1333 base_height
+= (TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
);
1335 base_height
+= gui
.toolbar_height
;
1338 # if defined(FEAT_GUI_TABLINE) && (defined(FEAT_GUI_MSWIN) \
1339 || defined(FEAT_GUI_MOTIF))
1340 if (gui_has_tabline())
1341 base_height
+= gui
.tabline_height
;
1344 if (vim_strchr(p_go
, GO_FOOTER
) != NULL
)
1345 base_height
+= gui
.footer_height
;
1347 # if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU)
1348 base_height
+= gui_mch_text_area_extra_height();
1355 * Should be called after the GUI shell has been resized. Its arguments are
1356 * the new width and height of the shell in pixels.
1359 gui_resize_shell(pixel_width
, pixel_height
)
1363 static int busy
= FALSE
;
1365 if (!gui
.shell_created
) /* ignore when still initializing */
1369 * Can't resize the screen while it is being redrawn. Remember the new
1370 * size and handle it later.
1372 if (updating_screen
|| busy
)
1374 new_pixel_width
= pixel_width
;
1375 new_pixel_height
= pixel_height
;
1382 /* Flush pending output before redrawing */
1385 gui
.num_cols
= (pixel_width
- gui_get_base_width()) / gui
.char_width
;
1386 gui
.num_rows
= (pixel_height
- gui_get_base_height()
1387 #if !defined(FEAT_GUI_PHOTON) && !defined(FEAT_GUI_MSWIN)
1388 + (gui
.char_height
/ 2)
1390 ) / gui
.char_height
;
1392 gui_position_components(pixel_width
);
1394 gui_reset_scroll_region();
1396 * At the "more" and ":confirm" prompt there is no redraw, put the cursor
1397 * at the last line here (why does it have to be one row too low?).
1399 if (State
== ASKMORE
|| State
== CONFIRM
)
1400 gui
.row
= gui
.num_rows
;
1402 /* Only comparing Rows and Columns may be sufficient, but let's stay on
1404 if (gui
.num_rows
!= screen_Rows
|| gui
.num_cols
!= screen_Columns
1405 || gui
.num_rows
!= Rows
|| gui
.num_cols
!= Columns
)
1408 gui_update_scrollbars(TRUE
);
1409 gui_update_cursor(FALSE
, TRUE
);
1410 #if defined(FEAT_XIM) && !defined(HAVE_GTK2)
1411 xim_set_status_area();
1417 * We could have been called again while redrawing the screen.
1418 * Need to do it all again with the latest size then.
1420 if (new_pixel_height
)
1422 pixel_width
= new_pixel_width
;
1423 pixel_height
= new_pixel_height
;
1424 new_pixel_width
= 0;
1425 new_pixel_height
= 0;
1431 * Check if gui_resize_shell() must be called.
1434 gui_may_resize_shell()
1438 if (new_pixel_height
)
1440 /* careful: gui_resize_shell() may postpone the resize again if we
1441 * were called indirectly by it */
1442 w
= new_pixel_width
;
1443 h
= new_pixel_height
;
1444 new_pixel_width
= 0;
1445 new_pixel_height
= 0;
1446 gui_resize_shell(w
, h
);
1453 Rows
= gui
.num_rows
;
1454 Columns
= gui
.num_cols
;
1459 * Set the size of the Vim shell according to Rows and Columns.
1460 * If "fit_to_display" is TRUE then the size may be reduced to fit the window
1465 gui_set_shellsize(mustset
, fit_to_display
, direction
)
1466 int mustset
; /* set by the user */
1468 int direction
; /* RESIZE_HOR, RESIZE_VER */
1479 if (!gui
.shell_created
)
1483 /* If not setting to a user specified size and maximized, calculate the
1484 * number of characters that fit in the maximized window. */
1485 if (!mustset
&& gui_mch_maximized())
1492 base_width
= gui_get_base_width();
1493 base_height
= gui_get_base_height();
1494 #ifdef USE_SUN_WORKSHOP
1495 if (!mustset
&& usingSunWorkShop
1496 && workshop_get_width_height(&width
, &height
))
1498 Columns
= (width
- base_width
+ gui
.char_width
- 1) / gui
.char_width
;
1499 Rows
= (height
- base_height
+ gui
.char_height
- 1) / gui
.char_height
;
1504 width
= Columns
* gui
.char_width
+ base_width
;
1505 height
= Rows
* gui
.char_height
+ base_height
;
1510 gui_mch_get_screen_dimensions(&screen_w
, &screen_h
);
1511 if ((direction
& RESIZE_HOR
) && width
> screen_w
)
1513 Columns
= (screen_w
- base_width
) / gui
.char_width
;
1514 if (Columns
< MIN_COLUMNS
)
1515 Columns
= MIN_COLUMNS
;
1516 width
= Columns
* gui
.char_width
+ base_width
;
1518 if ((direction
& RESIZE_VERT
) && height
> screen_h
)
1520 Rows
= (screen_h
- base_height
) / gui
.char_height
;
1522 height
= Rows
* gui
.char_height
+ base_height
;
1525 gui
.num_cols
= Columns
;
1526 gui
.num_rows
= Rows
;
1528 min_width
= base_width
+ MIN_COLUMNS
* gui
.char_width
;
1529 min_height
= base_height
+ MIN_LINES
* gui
.char_height
;
1530 # ifdef FEAT_WINDOWS
1531 min_height
+= tabline_height() * gui
.char_height
;
1534 gui_mch_set_shellsize(width
, height
, min_width
, min_height
,
1535 base_width
, base_height
, direction
);
1540 /* Some window managers put the Vim window left of/above the screen. */
1542 if (gui_mch_get_winpos(&x
, &y
) == OK
&& (x
< 0 || y
< 0))
1543 gui_mch_set_winpos(x
< 0 ? 0 : x
, y
< 0 ? 0 : y
);
1546 gui_position_components(width
);
1547 gui_update_scrollbars(TRUE
);
1548 gui_reset_scroll_region();
1552 * Called when Rows and/or Columns has changed.
1557 gui_reset_scroll_region();
1561 * Make scroll region cover whole screen.
1564 gui_reset_scroll_region()
1566 gui
.scroll_region_top
= 0;
1567 gui
.scroll_region_bot
= gui
.num_rows
- 1;
1568 gui
.scroll_region_left
= 0;
1569 gui
.scroll_region_right
= gui
.num_cols
- 1;
1573 gui_start_highlight(mask
)
1576 if (mask
> HL_ALL
) /* highlight code */
1577 gui
.highlight_mask
= mask
;
1579 gui
.highlight_mask
|= mask
;
1583 gui_stop_highlight(mask
)
1586 if (mask
> HL_ALL
) /* highlight code */
1587 gui
.highlight_mask
= HL_NORMAL
;
1589 gui
.highlight_mask
&= ~mask
;
1593 * Clear a rectangular region of the screen from text pos (row1, col1) to
1594 * (row2, col2) inclusive.
1597 gui_clear_block(row1
, col1
, row2
, col2
)
1603 /* Clear the selection if we are about to write over it */
1604 clip_may_clear_selection(row1
, row2
);
1606 gui_mch_clear_block(row1
, col1
, row2
, col2
);
1608 /* Invalidate cursor if it was in this block */
1609 if ( gui
.cursor_row
>= row1
&& gui
.cursor_row
<= row2
1610 && gui
.cursor_col
>= col1
&& gui
.cursor_col
<= col2
)
1611 gui
.cursor_is_valid
= FALSE
;
1615 * Write code to update the cursor later. This avoids the need to flush the
1616 * output buffer before calling gui_update_cursor().
1619 gui_update_cursor_later()
1621 OUT_STR(IF_EB("\033|s", ESC_STR
"|s"));
1630 int arg1
= 0, arg2
= 0;
1631 /* this doesn't make sense, disabled until someone can explain why it
1632 * would be needed */
1633 #if 0 && (defined(RISCOS) || defined(WIN16))
1634 int force_cursor
= TRUE
; /* JK230798, stop Vim being smart or
1635 our redraw speed will suffer */
1637 int force_cursor
= FALSE
; /* force cursor update */
1639 int force_scrollbar
= FALSE
;
1640 static win_T
*old_curwin
= NULL
;
1642 /* #define DEBUG_GUI_WRITE */
1643 #ifdef DEBUG_GUI_WRITE
1648 printf("gui_write(%d):\n ", len
);
1649 for (i
= 0; i
< len
; i
++)
1658 str
= transchar_byte(s
[i
]);
1659 if (str
[0] && str
[1])
1660 printf("<%s>", (char *)str
);
1662 printf("%s", (char *)str
);
1669 if (s
[0] == ESC
&& s
[1] == '|')
1672 if (VIM_ISDIGIT(*p
))
1674 arg1
= getdigits(&p
);
1680 arg2
= getdigits(&p
);
1687 case 'C': /* Clear screen */
1688 clip_scroll_selection(9999);
1689 gui_mch_clear_all();
1690 gui
.cursor_is_valid
= FALSE
;
1691 force_scrollbar
= TRUE
;
1693 case 'M': /* Move cursor */
1694 gui_set_cursor(arg1
, arg2
);
1696 case 's': /* force cursor (shape) update */
1697 force_cursor
= TRUE
;
1699 case 'R': /* Set scroll region */
1702 gui
.scroll_region_top
= arg1
;
1703 gui
.scroll_region_bot
= arg2
;
1707 gui
.scroll_region_top
= arg2
;
1708 gui
.scroll_region_bot
= arg1
;
1711 #ifdef FEAT_VERTSPLIT
1712 case 'V': /* Set vertical scroll region */
1715 gui
.scroll_region_left
= arg1
;
1716 gui
.scroll_region_right
= arg2
;
1720 gui
.scroll_region_left
= arg2
;
1721 gui
.scroll_region_right
= arg1
;
1725 case 'd': /* Delete line */
1726 gui_delete_lines(gui
.row
, 1);
1728 case 'D': /* Delete lines */
1729 gui_delete_lines(gui
.row
, arg1
);
1731 case 'i': /* Insert line */
1732 gui_insert_lines(gui
.row
, 1);
1734 case 'I': /* Insert lines */
1735 gui_insert_lines(gui
.row
, arg1
);
1737 case '$': /* Clear to end-of-line */
1738 gui_clear_block(gui
.row
, gui
.col
, gui
.row
,
1741 case 'h': /* Turn on highlighting */
1742 gui_start_highlight(arg1
);
1744 case 'H': /* Turn off highlighting */
1745 gui_stop_highlight(arg1
);
1747 case 'f': /* flash the window (visual bell) */
1748 gui_mch_flash(arg1
== 0 ? 20 : arg1
);
1751 p
= s
+ 1; /* Skip the ESC */
1754 len
-= (int)(++p
- s
);
1759 CtrlChar(s
[0]) != 0 /* Ctrl character */
1761 s
[0] < 0x20 /* Ctrl character */
1763 #ifdef FEAT_SIGN_ICONS
1764 && s
[0] != SIGN_BYTE
1765 # ifdef FEAT_NETBEANS_INTG
1766 && s
[0] != MULTISIGN_BYTE
1771 if (s
[0] == '\n') /* NL */
1774 if (gui
.row
< gui
.scroll_region_bot
)
1777 gui_delete_lines(gui
.scroll_region_top
, 1);
1779 else if (s
[0] == '\r') /* CR */
1783 else if (s
[0] == '\b') /* Backspace */
1788 else if (s
[0] == Ctrl_L
) /* cursor-right */
1792 else if (s
[0] == Ctrl_G
) /* Beep */
1796 /* Other Ctrl character: shouldn't happen! */
1798 --len
; /* Skip this char */
1810 #ifdef FEAT_SIGN_ICONS
1812 # ifdef FEAT_NETBEANS_INTG
1813 || *p
== MULTISIGN_BYTE
1821 gui_outstr(s
, (int)(p
- s
));
1826 /* Postponed update of the cursor (won't work if "can_update_cursor" isn't
1829 gui_update_cursor(TRUE
, TRUE
);
1831 /* When switching to another window the dragging must have stopped.
1832 * Required for GTK, dragged_sb isn't reset. */
1833 if (old_curwin
!= curwin
)
1834 gui
.dragged_sb
= SBAR_NONE
;
1836 /* Update the scrollbars after clearing the screen or when switched
1837 * to another window.
1838 * Update the horizontal scrollbar always, it's difficult to check all
1839 * situations where it might change. */
1840 if (force_scrollbar
|| old_curwin
!= curwin
)
1841 gui_update_scrollbars(force_scrollbar
);
1843 gui_update_horiz_scrollbar(FALSE
);
1844 old_curwin
= curwin
;
1847 * We need to make sure this is cleared since Athena doesn't tell us when
1848 * he is done dragging. Do the same for GTK.
1850 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_GTK)
1851 gui
.dragged_sb
= SBAR_NONE
;
1854 gui_mch_flush(); /* In case vim decides to take a nap */
1858 * When ScreenLines[] is invalid, updating the cursor should not be done, it
1859 * produces wrong results. Call gui_dont_update_cursor() before that code and
1860 * gui_can_update_cursor() afterwards.
1863 gui_dont_update_cursor()
1867 /* Undraw the cursor now, we probably can't do it after the change. */
1868 gui_undraw_cursor();
1869 can_update_cursor
= FALSE
;
1874 gui_can_update_cursor()
1876 can_update_cursor
= TRUE
;
1877 /* No need to update the cursor right now, there is always more output
1878 * after scrolling. */
1895 len
= (int)STRLEN(s
);
1902 /* Find out how many chars fit in the current line. */
1904 for (this_len
= 0; this_len
< len
; )
1906 cells
+= (*mb_ptr2cells
)(s
+ this_len
);
1907 if (gui
.col
+ cells
> Columns
)
1909 this_len
+= (*mb_ptr2len
)(s
+ this_len
);
1912 this_len
= len
; /* don't include following composing char */
1916 if (gui
.col
+ len
> Columns
)
1917 this_len
= Columns
- gui
.col
;
1921 (void)gui_outstr_nowrap(s
, this_len
,
1922 0, (guicolor_T
)0, (guicolor_T
)0, 0);
1926 /* fill up for a double-width char that doesn't fit. */
1927 if (len
> 0 && gui
.col
< Columns
)
1928 (void)gui_outstr_nowrap((char_u
*)" ", 1,
1929 0, (guicolor_T
)0, (guicolor_T
)0, 0);
1931 /* The cursor may wrap to the next line. */
1932 if (gui
.col
>= Columns
)
1941 * Output one character (may be one or two display cells).
1942 * Caller must check for valid "off".
1943 * Returns FAIL or OK, just like gui_outstr_nowrap().
1946 gui_screenchar(off
, flags
, fg
, bg
, back
)
1947 int off
; /* Offset from start of screen */
1949 guicolor_T fg
, bg
; /* colors for cursor */
1950 int back
; /* backup this many chars when using bold trick */
1953 char_u buf
[MB_MAXBYTES
+ 1];
1955 /* Don't draw right halve of a double-width UTF-8 char. "cannot happen" */
1956 if (enc_utf8
&& ScreenLines
[off
] == 0)
1959 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
1960 /* Draw UTF-8 multi-byte character. */
1961 return gui_outstr_nowrap(buf
, utfc_char2bytes(off
, buf
),
1962 flags
, fg
, bg
, back
);
1964 if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
1966 buf
[0] = ScreenLines
[off
];
1967 buf
[1] = ScreenLines2
[off
];
1968 return gui_outstr_nowrap(buf
, 2, flags
, fg
, bg
, back
);
1971 /* Draw non-multi-byte character or DBCS character. */
1972 return gui_outstr_nowrap(ScreenLines
+ off
,
1973 enc_dbcs
? (*mb_ptr2len
)(ScreenLines
+ off
) : 1,
1974 flags
, fg
, bg
, back
);
1976 return gui_outstr_nowrap(ScreenLines
+ off
, 1, flags
, fg
, bg
, back
);
1982 * Output the string at the given screen position. This is used in place
1983 * of gui_screenchar() where possible because Pango needs as much context
1984 * as possible to work nicely. It's a lot faster as well.
1987 gui_screenstr(off
, len
, flags
, fg
, bg
, back
)
1988 int off
; /* Offset from start of screen */
1989 int len
; /* string length in screen cells */
1991 guicolor_T fg
, bg
; /* colors for cursor */
1992 int back
; /* backup this many chars when using bold trick */
1999 if (len
<= 0) /* "cannot happen"? */
2004 buf
= alloc((unsigned)(len
* MB_MAXBYTES
+ 1));
2006 return OK
; /* not much we could do here... */
2008 for (i
= off
; i
< off
+ len
; ++i
)
2010 if (ScreenLines
[i
] == 0)
2011 continue; /* skip second half of double-width char */
2013 if (ScreenLinesUC
[i
] == 0)
2014 buf
[outlen
++] = ScreenLines
[i
];
2016 outlen
+= utfc_char2bytes(i
, buf
+ outlen
);
2019 buf
[outlen
] = NUL
; /* only to aid debugging */
2020 retval
= gui_outstr_nowrap(buf
, outlen
, flags
, fg
, bg
, back
);
2025 else if (enc_dbcs
== DBCS_JPNU
)
2027 buf
= alloc((unsigned)(len
* 2 + 1));
2029 return OK
; /* not much we could do here... */
2031 for (i
= off
; i
< off
+ len
; ++i
)
2033 buf
[outlen
++] = ScreenLines
[i
];
2035 /* handle double-byte single-width char */
2036 if (ScreenLines
[i
] == 0x8e)
2037 buf
[outlen
++] = ScreenLines2
[i
];
2038 else if (MB_BYTE2LEN(ScreenLines
[i
]) == 2)
2039 buf
[outlen
++] = ScreenLines
[++i
];
2042 buf
[outlen
] = NUL
; /* only to aid debugging */
2043 retval
= gui_outstr_nowrap(buf
, outlen
, flags
, fg
, bg
, back
);
2050 return gui_outstr_nowrap(&ScreenLines
[off
], len
,
2051 flags
, fg
, bg
, back
);
2054 #endif /* HAVE_GTK2 */
2057 * Output the given string at the current cursor position. If the string is
2058 * too long to fit on the line, then it is truncated.
2060 * GUI_MON_IS_CURSOR should only be used when this function is being called to
2061 * actually draw (an inverted) cursor.
2062 * GUI_MON_TRS_CURSOR is used to draw the cursor text with a transparent
2064 * GUI_MON_NOCLEAR is used to avoid clearing the selection when drawing over
2066 * Returns OK, unless "back" is non-zero and using the bold trick, then return
2067 * FAIL (the caller should start drawing "back" chars back).
2070 gui_outstr_nowrap(s
, len
, flags
, fg
, bg
, back
)
2074 guicolor_T fg
, bg
; /* colors for cursor */
2075 int back
; /* backup this many chars when using bold trick */
2077 long_u highlight_mask
;
2078 long_u hl_mask_todo
;
2079 guicolor_T fg_color
;
2080 guicolor_T bg_color
;
2081 guicolor_T sp_color
;
2082 #if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2)
2083 GuiFont font
= NOFONT
;
2084 # ifdef FEAT_XFONTSET
2085 GuiFontset fontset
= NOFONTSET
;
2088 attrentry_T
*aep
= NULL
;
2091 #ifdef FEAT_SIGN_ICONS
2092 int draw_sign
= FALSE
;
2093 # ifdef FEAT_NETBEANS_INTG
2094 int multi_sign
= FALSE
;
2099 len
= (int)STRLEN(s
);
2103 #ifdef FEAT_SIGN_ICONS
2105 # ifdef FEAT_NETBEANS_INTG
2106 || *s
== MULTISIGN_BYTE
2110 # ifdef FEAT_NETBEANS_INTG
2111 if (*s
== MULTISIGN_BYTE
)
2114 /* draw spaces instead */
2116 if (len
== 1 && col
> 0)
2124 if (gui
.highlight_mask
> HL_ALL
)
2126 aep
= syn_gui_attr2entry(gui
.highlight_mask
);
2127 if (aep
== NULL
) /* highlighting not set */
2130 highlight_mask
= aep
->ae_attr
;
2133 highlight_mask
= gui
.highlight_mask
;
2134 hl_mask_todo
= highlight_mask
;
2136 #if !defined(MSWIN16_FASTTEXT) && !defined(HAVE_GTK2)
2138 if (aep
!= NULL
&& aep
->ae_u
.gui
.font
!= NOFONT
)
2139 font
= aep
->ae_u
.gui
.font
;
2140 # ifdef FEAT_XFONTSET
2141 else if (aep
!= NULL
&& aep
->ae_u
.gui
.fontset
!= NOFONTSET
)
2142 fontset
= aep
->ae_u
.gui
.fontset
;
2146 # ifdef FEAT_XFONTSET
2147 if (gui
.fontset
!= NOFONTSET
)
2148 fontset
= gui
.fontset
;
2151 if (hl_mask_todo
& (HL_BOLD
| HL_STANDOUT
))
2153 if ((hl_mask_todo
& HL_ITALIC
) && gui
.boldital_font
!= NOFONT
)
2155 font
= gui
.boldital_font
;
2156 hl_mask_todo
&= ~(HL_BOLD
| HL_STANDOUT
| HL_ITALIC
);
2158 else if (gui
.bold_font
!= NOFONT
)
2160 font
= gui
.bold_font
;
2161 hl_mask_todo
&= ~(HL_BOLD
| HL_STANDOUT
);
2164 font
= gui
.norm_font
;
2166 else if ((hl_mask_todo
& HL_ITALIC
) && gui
.ital_font
!= NOFONT
)
2168 font
= gui
.ital_font
;
2169 hl_mask_todo
&= ~HL_ITALIC
;
2172 font
= gui
.norm_font
;
2174 # ifdef FEAT_XFONTSET
2175 if (fontset
!= NOFONTSET
)
2176 gui_mch_set_fontset(fontset
);
2179 gui_mch_set_font(font
);
2185 bg_color
= gui
.back_pixel
;
2186 if ((flags
& GUI_MON_IS_CURSOR
) && gui
.in_focus
)
2188 draw_flags
|= DRAW_CURSOR
;
2193 else if (aep
!= NULL
)
2195 fg_color
= aep
->ae_u
.gui
.fg_color
;
2196 if (fg_color
== INVALCOLOR
)
2197 fg_color
= gui
.norm_pixel
;
2198 bg_color
= aep
->ae_u
.gui
.bg_color
;
2199 if (bg_color
== INVALCOLOR
)
2200 bg_color
= gui
.back_pixel
;
2201 sp_color
= aep
->ae_u
.gui
.sp_color
;
2202 if (sp_color
== INVALCOLOR
)
2203 sp_color
= fg_color
;
2207 fg_color
= gui
.norm_pixel
;
2208 sp_color
= fg_color
;
2211 if (highlight_mask
& (HL_INVERSE
| HL_STANDOUT
))
2213 #if defined(AMIGA) || defined(RISCOS)
2214 gui_mch_set_colors(bg_color
, fg_color
);
2216 gui_mch_set_fg_color(bg_color
);
2217 gui_mch_set_bg_color(fg_color
);
2222 #if defined(AMIGA) || defined(RISCOS)
2223 gui_mch_set_colors(fg_color
, bg_color
);
2225 gui_mch_set_fg_color(fg_color
);
2226 gui_mch_set_bg_color(bg_color
);
2229 gui_mch_set_sp_color(sp_color
);
2231 /* Clear the selection if we are about to write over it */
2232 if (!(flags
& GUI_MON_NOCLEAR
))
2233 clip_may_clear_selection(gui
.row
, gui
.row
);
2236 #ifndef MSWIN16_FASTTEXT
2237 /* If there's no bold font, then fake it */
2238 if (hl_mask_todo
& (HL_BOLD
| HL_STANDOUT
))
2239 draw_flags
|= DRAW_BOLD
;
2243 * When drawing bold or italic characters the spill-over from the left
2244 * neighbor may be destroyed. Let the caller backup to start redrawing
2245 * just after a blank.
2247 if (back
!= 0 && ((draw_flags
& DRAW_BOLD
) || (highlight_mask
& HL_ITALIC
)))
2250 #if defined(RISCOS) || defined(HAVE_GTK2) || defined(FEAT_GUI_MACVIM)
2251 /* If there's no italic font, then fake it.
2252 * For GTK2, we don't need a different font for italic style. */
2253 if (hl_mask_todo
& HL_ITALIC
)
2254 draw_flags
|= DRAW_ITALIC
;
2256 /* Do we underline the text? */
2257 if (hl_mask_todo
& HL_UNDERLINE
)
2258 draw_flags
|= DRAW_UNDERL
;
2260 /* Do we underline the text? */
2261 if ((hl_mask_todo
& HL_UNDERLINE
)
2262 # ifndef MSWIN16_FASTTEXT
2263 || (hl_mask_todo
& HL_ITALIC
)
2266 draw_flags
|= DRAW_UNDERL
;
2268 /* Do we undercurl the text? */
2269 if (hl_mask_todo
& HL_UNDERCURL
)
2270 draw_flags
|= DRAW_UNDERC
;
2272 /* Do we draw transparently? */
2273 if (flags
& GUI_MON_TRS_CURSOR
)
2274 draw_flags
|= DRAW_TRANSP
;
2280 /* The value returned is the length in display cells */
2281 len
= gui_gtk2_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2282 #elif defined(FEAT_GUI_MACVIM) && defined(FEAT_MBYTE)
2283 /* The value returned is the length in display cells */
2284 len
= gui_macvim_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2289 int start
; /* index of bytes to be drawn */
2290 int cells
; /* cellwidth of bytes to be drawn */
2291 int thislen
; /* length of bytes to be drawin */
2292 int cn
; /* cellwidth of current char */
2293 int i
; /* index of current char */
2294 int c
; /* current char value */
2295 int cl
; /* byte length of current char */
2296 int comping
; /* current char is composing */
2297 int scol
= col
; /* screen column */
2298 int dowide
; /* use 'guifontwide' */
2300 /* Break the string at a composing character, it has to be drawn on
2301 * top of the previous character. */
2304 for (i
= 0; i
< len
; i
+= cl
)
2306 c
= utf_ptr2char(s
+ i
);
2307 cn
= utf_char2cells(c
);
2309 # ifdef FEAT_XFONTSET
2310 && fontset
== NOFONTSET
2312 && gui
.wide_font
!= NOFONT
)
2316 comping
= utf_iscomposing(c
);
2317 if (!comping
) /* count cells from non-composing chars */
2319 cl
= utf_ptr2len(s
+ i
);
2320 if (cl
== 0) /* hit end of string */
2321 len
= i
+ cl
; /* len must be wrong "cannot happen" */
2323 /* print the string so far if it's the last character or there is
2324 * a composing character. */
2325 if (i
+ cl
>= len
|| (comping
&& i
> start
) || dowide
2326 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
2328 # ifdef FEAT_XFONTSET
2329 /* No fontset: At least draw char after wide char at
2330 * right position. */
2331 && fontset
== NOFONTSET
2337 if (comping
|| dowide
)
2338 thislen
= i
- start
;
2340 thislen
= i
- start
+ cl
;
2343 gui_mch_draw_string(gui
.row
, scol
, s
+ start
, thislen
,
2351 gui_mch_set_font(gui
.wide_font
);
2352 gui_mch_draw_string(gui
.row
, scol
- cn
,
2353 s
+ start
, cl
, draw_flags
);
2354 gui_mch_set_font(font
);
2358 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
2359 /* No fontset: draw a space to fill the gap after a wide char
2361 if (cn
> 1 && (draw_flags
& DRAW_TRANSP
) == 0
2362 # ifdef FEAT_XFONTSET
2363 && fontset
== NOFONTSET
2366 gui_mch_draw_string(gui
.row
, scol
- 1, (char_u
*)" ",
2370 /* Draw a composing char on top of the previous char. */
2373 # if (defined(__APPLE_CC__) || defined(__MRC__)) && TARGET_API_MAC_CARBON
2374 /* Carbon ATSUI autodraws composing char over previous char */
2375 gui_mch_draw_string(gui
.row
, scol
, s
+ i
, cl
,
2376 draw_flags
| DRAW_TRANSP
);
2378 gui_mch_draw_string(gui
.row
, scol
- cn
, s
+ i
, cl
,
2379 draw_flags
| DRAW_TRANSP
);
2384 /* The stuff below assumes "len" is the length in screen columns. */
2390 gui_mch_draw_string(gui
.row
, col
, s
, len
, draw_flags
);
2392 if (enc_dbcs
== DBCS_JPNU
)
2397 /* Get the length in display cells, this can be different from the
2398 * number of bytes for "euc-jp". */
2399 for (i
= 0; i
< len
; i
+= (*mb_ptr2len
)(s
+ i
))
2400 clen
+= (*mb_ptr2cells
)(s
+ i
);
2405 #endif /* !HAVE_GTK2 */
2407 if (!(flags
& (GUI_MON_IS_CURSOR
| GUI_MON_TRS_CURSOR
)))
2408 gui
.col
= col
+ len
;
2410 /* May need to invert it when it's part of the selection. */
2411 if (flags
& GUI_MON_NOCLEAR
)
2412 clip_may_redraw_selection(gui
.row
, col
, len
);
2414 if (!(flags
& (GUI_MON_IS_CURSOR
| GUI_MON_TRS_CURSOR
)))
2416 /* Invalidate the old physical cursor position if we wrote over it */
2417 if (gui
.cursor_row
== gui
.row
2418 && gui
.cursor_col
>= col
2419 && gui
.cursor_col
< col
+ len
)
2420 gui
.cursor_is_valid
= FALSE
;
2423 #ifdef FEAT_SIGN_ICONS
2425 /* Draw the sign on top of the spaces. */
2426 gui_mch_drawsign(gui
.row
, col
, gui
.highlight_mask
);
2427 # ifdef FEAT_NETBEANS_INTG
2429 netbeans_draw_multisign_indicator(gui
.row
);
2437 * Un-draw the cursor. Actually this just redraws the character at the given
2438 * position. The character just before it too, for when it was in bold.
2443 if (gui
.cursor_is_valid
)
2445 #ifdef FEAT_HANGULIN
2446 if (composing_hangul
2447 && gui
.col
== gui
.cursor_col
&& gui
.row
== gui
.cursor_row
)
2448 (void)gui_outstr_nowrap(composing_hangul_buffer
, 2,
2449 GUI_MON_IS_CURSOR
| GUI_MON_NOCLEAR
,
2450 gui
.norm_pixel
, gui
.back_pixel
, 0);
2454 if (gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
,
2455 gui
.cursor_row
, gui
.cursor_col
, GUI_MON_NOCLEAR
)
2456 && gui
.cursor_col
> 0)
2457 (void)gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
- 1,
2458 gui
.cursor_row
, gui
.cursor_col
- 1, GUI_MON_NOCLEAR
);
2459 #ifdef FEAT_HANGULIN
2460 if (composing_hangul
)
2461 (void)gui_redraw_block(gui
.cursor_row
, gui
.cursor_col
+ 1,
2462 gui
.cursor_row
, gui
.cursor_col
+ 1, GUI_MON_NOCLEAR
);
2465 /* Cursor_is_valid is reset when the cursor is undrawn, also reset it
2466 * here in case it wasn't needed to undraw it. */
2467 gui
.cursor_is_valid
= FALSE
;
2472 gui_redraw(x
, y
, w
, h
)
2478 int row1
, col1
, row2
, col2
;
2482 row2
= Y_2_ROW(y
+ h
- 1);
2483 col2
= X_2_COL(x
+ w
- 1);
2485 (void)gui_redraw_block(row1
, col1
, row2
, col2
, GUI_MON_NOCLEAR
);
2488 * We may need to redraw the cursor, but don't take it upon us to change
2489 * its location after a scroll.
2490 * (maybe be more strict even and test col too?)
2491 * These things may be outside the update/clipping region and reality may
2492 * not reflect Vims internal ideas if these operations are clipped away.
2494 if (gui
.row
== gui
.cursor_row
)
2495 gui_update_cursor(TRUE
, TRUE
);
2499 * Draw a rectangular block of characters, from row1 to row2 (inclusive) and
2500 * from col1 to col2 (inclusive).
2501 * Return TRUE when the character before the first drawn character has
2502 * different attributes (may have to be redrawn too).
2505 gui_redraw_block(row1
, col1
, row2
, col2
, flags
)
2510 int flags
; /* flags for gui_outstr_nowrap() */
2512 int old_row
, old_col
;
2520 int orig_col1
, orig_col2
;
2523 /* Don't try to update when ScreenLines is not valid */
2524 if (!screen_cleared
|| ScreenLines
== NULL
)
2527 /* Don't try to draw outside the shell! */
2528 /* Check everything, strange values may be caused by a big border width */
2529 col1
= check_col(col1
);
2530 col2
= check_col(col2
);
2531 row1
= check_row(row1
);
2532 row2
= check_row(row2
);
2534 /* Remember where our cursor was */
2537 old_hl_mask
= gui
.highlight_mask
;
2543 for (gui
.row
= row1
; gui
.row
<= row2
; gui
.row
++)
2546 /* When only half of a double-wide character is in the block, include
2547 * the other half. */
2550 off
= LineOffset
[gui
.row
];
2554 col1
-= dbcs_screen_head_off(ScreenLines
+ off
,
2555 ScreenLines
+ off
+ col1
);
2556 col2
+= dbcs_screen_tail_off(ScreenLines
+ off
,
2557 ScreenLines
+ off
+ col2
);
2561 if (ScreenLines
[off
+ col1
] == 0)
2564 if (col2
+ 1 < Columns
&& ScreenLines
[off
+ col2
+ 1] == 0)
2570 off
= LineOffset
[gui
.row
] + gui
.col
;
2571 len
= col2
- col1
+ 1;
2573 /* Find how many chars back this highlighting starts, or where a space
2574 * is. Needed for when the bold trick is used */
2575 for (back
= 0; back
< col1
; ++back
)
2576 if (ScreenAttrs
[off
- 1 - back
] != ScreenAttrs
[off
]
2577 || ScreenLines
[off
- 1 - back
] == ' ')
2579 retval
= (col1
> 0 && ScreenAttrs
[off
- 1] != 0 && back
== 0
2580 && ScreenLines
[off
- 1] != ' ');
2582 /* Break it up in strings of characters with the same attributes. */
2583 /* Print UTF-8 characters individually. */
2586 first_attr
= ScreenAttrs
[off
];
2587 gui
.highlight_mask
= first_attr
;
2588 #if defined(FEAT_MBYTE) && !defined(HAVE_GTK2)
2589 if (enc_utf8
&& ScreenLinesUC
[off
] != 0)
2591 /* output multi-byte character separately */
2592 nback
= gui_screenchar(off
, flags
,
2593 (guicolor_T
)0, (guicolor_T
)0, back
);
2594 if (gui
.col
< Columns
&& ScreenLines
[off
+ 1] == 0)
2599 else if (enc_dbcs
== DBCS_JPNU
&& ScreenLines
[off
] == 0x8e)
2601 /* output double-byte, single-width character separately */
2602 nback
= gui_screenchar(off
, flags
,
2603 (guicolor_T
)0, (guicolor_T
)0, back
);
2610 for (idx
= 0; idx
< len
; ++idx
)
2612 if (enc_utf8
&& ScreenLines
[off
+ idx
] == 0)
2613 continue; /* skip second half of double-width char */
2614 if (ScreenAttrs
[off
+ idx
] != first_attr
)
2617 /* gui_screenstr() takes care of multibyte chars */
2618 nback
= gui_screenstr(off
, idx
, flags
,
2619 (guicolor_T
)0, (guicolor_T
)0, back
);
2621 for (idx
= 0; idx
< len
&& ScreenAttrs
[off
+ idx
] == first_attr
;
2625 /* Stop at a multi-byte Unicode character. */
2626 if (enc_utf8
&& ScreenLinesUC
[off
+ idx
] != 0)
2628 if (enc_dbcs
== DBCS_JPNU
)
2630 /* Stop at a double-byte single-width char. */
2631 if (ScreenLines
[off
+ idx
] == 0x8e)
2633 if (len
> 1 && (*mb_ptr2len
)(ScreenLines
2635 ++idx
; /* skip second byte of double-byte char */
2639 nback
= gui_outstr_nowrap(ScreenLines
+ off
, idx
, flags
,
2640 (guicolor_T
)0, (guicolor_T
)0, back
);
2645 /* Must back up to start drawing where a bold or italic word
2660 /* Put the cursor back where it was */
2663 gui
.highlight_mask
= (int)old_hl_mask
;
2669 gui_delete_lines(row
, count
)
2676 if (row
+ count
> gui
.scroll_region_bot
)
2677 /* Scrolled out of region, just blank the lines out */
2678 gui_clear_block(row
, gui
.scroll_region_left
,
2679 gui
.scroll_region_bot
, gui
.scroll_region_right
);
2682 gui_mch_delete_lines(row
, count
);
2684 /* If the cursor was in the deleted lines it's now gone. If the
2685 * cursor was in the scrolled lines adjust its position. */
2686 if (gui
.cursor_row
>= row
2687 && gui
.cursor_col
>= gui
.scroll_region_left
2688 && gui
.cursor_col
<= gui
.scroll_region_right
)
2690 if (gui
.cursor_row
< row
+ count
)
2691 gui
.cursor_is_valid
= FALSE
;
2692 else if (gui
.cursor_row
<= gui
.scroll_region_bot
)
2693 gui
.cursor_row
-= count
;
2699 gui_insert_lines(row
, count
)
2706 if (row
+ count
> gui
.scroll_region_bot
)
2707 /* Scrolled out of region, just blank the lines out */
2708 gui_clear_block(row
, gui
.scroll_region_left
,
2709 gui
.scroll_region_bot
, gui
.scroll_region_right
);
2712 gui_mch_insert_lines(row
, count
);
2714 if (gui
.cursor_row
>= gui
.row
2715 && gui
.cursor_col
>= gui
.scroll_region_left
2716 && gui
.cursor_col
<= gui
.scroll_region_right
)
2718 if (gui
.cursor_row
<= gui
.scroll_region_bot
- count
)
2719 gui
.cursor_row
+= count
;
2720 else if (gui
.cursor_row
<= gui
.scroll_region_bot
)
2721 gui
.cursor_is_valid
= FALSE
;
2727 * The main GUI input routine. Waits for a character from the keyboard.
2728 * wtime == -1 Wait forever.
2729 * wtime == 0 Don't wait.
2730 * wtime > 0 Wait wtime milliseconds for a character.
2731 * Returns OK if a character was found to be available within the given time,
2732 * or FAIL otherwise.
2735 gui_wait_for_chars(wtime
)
2741 * If we're going to wait a bit, update the menus and mouse shape for the
2747 gui_update_menus(0);
2752 if (input_available()) /* Got char, return immediately */
2754 if (wtime
== 0) /* Don't wait for char */
2757 /* Before waiting, flush any output to the screen. */
2762 /* Blink when waiting for a character. Probably only does something
2763 * for showmatch() */
2764 gui_mch_start_blink();
2765 retval
= gui_mch_wait_for_chars(wtime
);
2766 gui_mch_stop_blink();
2771 * While we are waiting indefinitely for a character, blink the cursor.
2773 gui_mch_start_blink();
2777 * We may want to trigger the CursorHold event. First wait for
2778 * 'updatetime' and if nothing is typed within that time put the
2779 * K_CURSORHOLD key in the input buffer.
2781 if (gui_mch_wait_for_chars(p_ut
) == OK
)
2784 else if (trigger_cursorhold())
2788 /* Put K_CURSORHOLD in the input buffer. */
2791 buf
[2] = (int)KE_CURSORHOLD
;
2792 add_to_input_buf(buf
, 3);
2800 /* Blocking wait. */
2802 retval
= gui_mch_wait_for_chars(-1L);
2805 gui_mch_stop_blink();
2810 * Fill p[4] with mouse coordinates encoded for check_termcode().
2813 fill_mouse_coord(p
, col
, row
)
2818 p
[0] = (char_u
)(col
/ 128 + ' ' + 1);
2819 p
[1] = (char_u
)(col
% 128 + ' ' + 1);
2820 p
[2] = (char_u
)(row
/ 128 + ' ' + 1);
2821 p
[3] = (char_u
)(row
% 128 + ' ' + 1);
2825 * Generic mouse support function. Add a mouse event to the input buffer with
2826 * the given properties.
2827 * button --- may be any of MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT,
2828 * MOUSE_X1, MOUSE_X2
2829 * MOUSE_DRAG, or MOUSE_RELEASE.
2830 * MOUSE_4 and MOUSE_5 are used for a scroll wheel.
2831 * x, y --- Coordinates of mouse in pixels.
2832 * repeated_click --- TRUE if this click comes only a short time after a
2834 * modifiers --- Bit field which may be any of the following modifiers
2835 * or'ed together: MOUSE_SHIFT | MOUSE_CTRL | MOUSE_ALT.
2836 * This function will ignore drag events where the mouse has not moved to a new
2840 gui_send_mouse_event(button
, x
, y
, repeated_click
, modifiers
)
2847 static int prev_row
= 0, prev_col
= 0;
2848 static int prev_button
= -1;
2849 static int num_clicks
= 1;
2851 enum key_extra button_char
;
2853 #ifdef FEAT_CLIPBOARD
2855 int did_clip
= FALSE
;
2859 * Scrolling may happen at any time, also while a selection is present.
2864 button_char
= KE_X1MOUSE
;
2867 button_char
= KE_X2MOUSE
;
2870 button_char
= KE_MOUSEDOWN
;
2873 button_char
= KE_MOUSEUP
;
2876 /* Don't put events in the input queue now. */
2877 if (hold_gui_events
)
2881 string
[4] = KS_EXTRA
;
2882 string
[5] = (int)button_char
;
2884 /* Pass the pointer coordinates of the scroll event so that we
2885 * know which window to scroll. */
2886 row
= gui_xy2colrow(x
, y
, &col
);
2887 string
[6] = (char_u
)(col
/ 128 + ' ' + 1);
2888 string
[7] = (char_u
)(col
% 128 + ' ' + 1);
2889 string
[8] = (char_u
)(row
/ 128 + ' ' + 1);
2890 string
[9] = (char_u
)(row
% 128 + ' ' + 1);
2893 add_to_input_buf(string
+ 3, 7);
2897 string
[1] = KS_MODIFIER
;
2899 if (modifiers
& MOUSE_SHIFT
)
2900 string
[2] |= MOD_MASK_SHIFT
;
2901 if (modifiers
& MOUSE_CTRL
)
2902 string
[2] |= MOD_MASK_CTRL
;
2903 if (modifiers
& MOUSE_ALT
)
2904 string
[2] |= MOD_MASK_ALT
;
2905 add_to_input_buf(string
, 10);
2911 #ifdef FEAT_CLIPBOARD
2912 /* If a clipboard selection is in progress, handle it */
2913 if (clip_star
.state
== SELECT_IN_PROGRESS
)
2915 clip_process_selection(button
, X_2_COL(x
), Y_2_ROW(y
), repeated_click
);
2919 /* Determine which mouse settings to look for based on the current mode */
2920 switch (get_real_state())
2924 case NORMAL
: checkfor
= MOUSE_NORMAL
; break;
2925 case VISUAL
: checkfor
= MOUSE_VISUAL
; break;
2926 case SELECTMODE
: checkfor
= MOUSE_VISUAL
; break;
2928 case REPLACE
+LANGMAP
:
2929 #ifdef FEAT_VREPLACE
2931 case VREPLACE
+LANGMAP
:
2934 case INSERT
+LANGMAP
: checkfor
= MOUSE_INSERT
; break;
2936 case HITRETURN
: /* At the more- and hit-enter prompt pass the
2937 mouse event for a click on or below the
2939 if (Y_2_ROW(y
) >= msg_row
)
2940 checkfor
= MOUSE_NORMAL
;
2942 checkfor
= MOUSE_RETURN
;
2946 * On the command line, use the clipboard selection on all lines
2947 * but the command line. But not when pasting.
2950 case CMDLINE
+LANGMAP
:
2951 if (Y_2_ROW(y
) < cmdline_row
&& button
!= MOUSE_MIDDLE
)
2952 checkfor
= MOUSE_NONE
;
2954 checkfor
= MOUSE_COMMAND
;
2958 checkfor
= MOUSE_NONE
;
2963 * Allow clipboard selection of text on the command line in "normal"
2964 * modes. Don't do this when dragging the status line, or extending a
2967 if ((State
== NORMAL
|| State
== NORMAL_BUSY
|| (State
& INSERT
))
2968 && Y_2_ROW(y
) >= topframe
->fr_height
2969 # ifdef FEAT_WINDOWS
2970 + firstwin
->w_winrow
2972 && button
!= MOUSE_DRAG
2973 # ifdef FEAT_MOUSESHAPE
2974 && !drag_status_line
2975 # ifdef FEAT_VERTSPLIT
2980 checkfor
= MOUSE_NONE
;
2983 * Use modeless selection when holding CTRL and SHIFT pressed.
2985 if ((modifiers
& MOUSE_CTRL
) && (modifiers
& MOUSE_SHIFT
))
2986 checkfor
= MOUSE_NONEF
;
2989 * In Ex mode, always use modeless selection.
2992 checkfor
= MOUSE_NONE
;
2995 * If the mouse settings say to not use the mouse, use the modeless
2996 * selection. But if Visual is active, assume that only the Visual area
2998 * Exception: On the command line, both the selection is used and a mouse
3001 if (!mouse_has(checkfor
) || checkfor
== MOUSE_COMMAND
)
3004 /* Don't do modeless selection in Visual mode. */
3005 if (checkfor
!= MOUSE_NONEF
&& VIsual_active
&& (State
& NORMAL
))
3010 * When 'mousemodel' is "popup", shift-left is translated to right.
3011 * But not when also using Ctrl.
3013 if (mouse_model_popup() && button
== MOUSE_LEFT
3014 && (modifiers
& MOUSE_SHIFT
) && !(modifiers
& MOUSE_CTRL
))
3016 button
= MOUSE_RIGHT
;
3017 modifiers
&= ~ MOUSE_SHIFT
;
3020 /* If the selection is done, allow the right button to extend it.
3021 * If the selection is cleared, allow the right button to start it
3022 * from the cursor position. */
3023 if (button
== MOUSE_RIGHT
)
3025 if (clip_star
.state
== SELECT_CLEARED
)
3027 if (State
& CMDLINE
)
3034 col
= curwin
->w_wcol
;
3035 row
= curwin
->w_wrow
+ W_WINROW(curwin
);
3037 clip_start_selection(col
, row
, FALSE
);
3039 clip_process_selection(button
, X_2_COL(x
), Y_2_ROW(y
),
3043 /* Allow the left button to start the selection */
3046 /* Only start a drag on a drag event. Otherwise
3047 * we don't get a release event. */
3054 clip_start_selection(X_2_COL(x
), Y_2_ROW(y
), repeated_click
);
3058 else if (button
== MOUSE_LEFT
)
3060 clip_clear_selection();
3065 /* Always allow pasting */
3066 if (button
!= MOUSE_MIDDLE
)
3068 if (!mouse_has(checkfor
) || button
== MOUSE_RELEASE
)
3070 if (checkfor
!= MOUSE_COMMAND
)
3071 button
= MOUSE_LEFT
;
3073 repeated_click
= FALSE
;
3076 if (clip_star
.state
!= SELECT_CLEARED
&& !did_clip
)
3077 clip_clear_selection();
3080 /* Don't put events in the input queue now. */
3081 if (hold_gui_events
)
3084 row
= gui_xy2colrow(x
, y
, &col
);
3087 * If we are dragging and the mouse hasn't moved far enough to be on a
3088 * different character, then don't send an event to vim.
3090 if (button
== MOUSE_DRAG
)
3092 if (row
== prev_row
&& col
== prev_col
)
3094 /* Dragging above the window, set "row" to -1 to cause a scroll. */
3100 * If topline has changed (window scrolled) since the last click, reset
3101 * repeated_click, because we don't want starting Visual mode when
3102 * clicking on a different character in the text.
3104 if (curwin
->w_topline
!= gui_prev_topline
3106 || curwin
->w_topfill
!= gui_prev_topfill
3109 repeated_click
= FALSE
;
3111 string
[0] = CSI
; /* this sequence is recognized by check_termcode() */
3112 string
[1] = KS_MOUSE
;
3113 string
[2] = KE_FILLER
;
3114 if (button
!= MOUSE_DRAG
&& button
!= MOUSE_RELEASE
)
3119 * Handle multiple clicks. They only count if the mouse is still
3120 * pointing at the same character.
3122 if (button
!= prev_button
|| row
!= prev_row
|| col
!= prev_col
)
3124 else if (++num_clicks
> 4)
3129 prev_button
= button
;
3130 gui_prev_topline
= curwin
->w_topline
;
3132 gui_prev_topfill
= curwin
->w_topfill
;
3135 string
[3] = (char_u
)(button
| 0x20);
3136 SET_NUM_MOUSE_CLICKS(string
[3], num_clicks
);
3139 string
[3] = (char_u
)button
;
3141 string
[3] |= modifiers
;
3142 fill_mouse_coord(string
+ 4, col
, row
);
3143 add_to_input_buf(string
, 8);
3152 * We need to make sure this is cleared since Athena doesn't tell us when
3153 * he is done dragging. Neither does GTK+ 2 -- at least for now.
3155 #if defined(FEAT_GUI_ATHENA) || defined(HAVE_GTK2)
3156 gui
.dragged_sb
= SBAR_NONE
;
3161 * Convert x and y coordinate to column and row in text window.
3162 * Corrects for multi-byte character.
3163 * returns column in "*colp" and row as return value;
3166 gui_xy2colrow(x
, y
, colp
)
3171 int col
= check_col(X_2_COL(x
));
3172 int row
= check_row(Y_2_ROW(y
));
3175 *colp
= mb_fix_col(col
, row
);
3182 #if defined(FEAT_MENU) || defined(PROTO)
3184 * Callback function for when a menu entry has been selected.
3190 char_u bytes
[sizeof(long_u
)];
3192 /* Don't put events in the input queue now. */
3193 if (hold_gui_events
)
3198 bytes
[2] = KE_FILLER
;
3199 add_to_input_buf(bytes
, 3);
3200 add_long_to_buf((long_u
)menu
, bytes
);
3201 add_to_input_buf_csi(bytes
, sizeof(long_u
));
3205 static int prev_which_scrollbars
[3];
3208 * Set which components are present.
3209 * If "oldval" is not NULL, "oldval" is the previous value, the new value is
3214 gui_init_which_components(oldval
)
3218 static int prev_menu_is_active
= -1;
3221 static int prev_toolbar
= -1;
3222 int using_toolbar
= FALSE
;
3224 #ifdef FEAT_GUI_TABLINE
3228 static int prev_footer
= -1;
3229 int using_footer
= FALSE
;
3231 #if defined(FEAT_MENU) && !defined(WIN16)
3232 static int prev_tearoff
= -1;
3233 int using_tearoff
= FALSE
;
3239 int grey_old
, grey_new
;
3247 if (oldval
!= NULL
&& gui
.in_use
)
3250 * Check if the menu's go from grey to non-grey or vise versa.
3252 grey_old
= (vim_strchr(oldval
, GO_GREY
) != NULL
);
3253 grey_new
= (vim_strchr(p_go
, GO_GREY
) != NULL
);
3254 if (grey_old
!= grey_new
)
3258 gui_update_menus(MENU_ALL_MODES
);
3262 gui
.menu_is_active
= FALSE
;
3265 for (i
= 0; i
< 3; i
++)
3266 gui
.which_scrollbars
[i
] = FALSE
;
3267 for (p
= p_go
; *p
; p
++)
3271 gui
.which_scrollbars
[SBAR_LEFT
] = TRUE
;
3274 gui
.which_scrollbars
[SBAR_RIGHT
] = TRUE
;
3276 #ifdef FEAT_VERTSPLIT
3278 if (win_hasvertsplit())
3279 gui
.which_scrollbars
[SBAR_LEFT
] = TRUE
;
3282 if (win_hasvertsplit())
3283 gui
.which_scrollbars
[SBAR_RIGHT
] = TRUE
;
3287 gui
.which_scrollbars
[SBAR_BOTTOM
] = TRUE
;
3291 gui
.menu_is_active
= TRUE
;
3295 /* make menu's have grey items, ignored here */
3299 using_toolbar
= TRUE
;
3304 using_footer
= TRUE
;
3308 #if defined(FEAT_MENU) && !defined(WIN16)
3309 using_tearoff
= TRUE
;
3313 /* Ignore options that are not supported */
3322 #ifdef FEAT_GUI_TABLINE
3323 /* Update the GUI tab line, it may appear or disappear. This may
3324 * cause the non-GUI tab line to disappear or appear. */
3325 using_tabline
= gui_has_tabline();
3326 if (!gui_mch_showing_tabline() != !using_tabline
)
3328 /* We don't want a resize event change "Rows" here, save and
3329 * restore it. Resizing is handled below. */
3331 gui_update_tabline();
3333 need_set_size
= RESIZE_VERT
;
3336 if (!gui_use_tabline())
3337 redraw_tabline
= TRUE
; /* may draw non-GUI tab line */
3341 for (i
= 0; i
< 3; i
++)
3343 /* The scrollbar needs to be updated when it is shown/unshown and
3344 * when switching tab pages. But the size only changes when it's
3345 * shown/unshown. Thus we need two places to remember whether a
3346 * scrollbar is there or not. */
3347 if (gui
.which_scrollbars
[i
] != prev_which_scrollbars
[i
]
3349 || gui
.which_scrollbars
[i
]
3350 != curtab
->tp_prev_which_scrollbars
[i
]
3354 if (i
== SBAR_BOTTOM
)
3355 gui_mch_enable_scrollbar(&gui
.bottom_sbar
,
3356 gui
.which_scrollbars
[i
]);
3361 gui_do_scrollbar(wp
, i
, gui
.which_scrollbars
[i
]);
3364 if (gui
.which_scrollbars
[i
] != prev_which_scrollbars
[i
])
3366 if (i
== SBAR_BOTTOM
)
3367 need_set_size
= RESIZE_VERT
;
3369 need_set_size
= RESIZE_HOR
;
3370 if (gui
.which_scrollbars
[i
])
3375 curtab
->tp_prev_which_scrollbars
[i
] = gui
.which_scrollbars
[i
];
3377 prev_which_scrollbars
[i
] = gui
.which_scrollbars
[i
];
3381 if (gui
.menu_is_active
!= prev_menu_is_active
)
3383 /* We don't want a resize event change "Rows" here, save and
3384 * restore it. Resizing is handled below. */
3386 gui_mch_enable_menu(gui
.menu_is_active
);
3388 prev_menu_is_active
= gui
.menu_is_active
;
3389 need_set_size
= RESIZE_VERT
;
3390 if (gui
.menu_is_active
)
3396 if (using_toolbar
!= prev_toolbar
)
3398 gui_mch_show_toolbar(using_toolbar
);
3399 prev_toolbar
= using_toolbar
;
3400 need_set_size
= RESIZE_VERT
;
3406 if (using_footer
!= prev_footer
)
3408 gui_mch_enable_footer(using_footer
);
3409 prev_footer
= using_footer
;
3410 need_set_size
= RESIZE_VERT
;
3415 #if defined(FEAT_MENU) && !defined(WIN16) && !(defined(WIN3264) && !defined(FEAT_TEAROFF))
3416 if (using_tearoff
!= prev_tearoff
)
3418 gui_mch_toggle_tearoffs(using_tearoff
);
3419 prev_tearoff
= using_tearoff
;
3427 /* Adjust the size of the window to make the text area keep the
3428 * same size and to avoid that part of our window is off-screen
3429 * and a scrollbar can't be used, for example. */
3430 gui_set_shellsize(FALSE
, fix_size
, need_set_size
);
3433 /* GTK has the annoying habit of sending us resize events when
3434 * changing the window size ourselves. This mostly happens when
3435 * waiting for a character to arrive, quite unpredictably, and may
3436 * change Columns and Rows when we don't want it. Wait for a
3437 * character here to avoid this effect.
3438 * If you remove this, please test this command for resizing
3439 * effects (with optional left scrollbar): ":vsp|q|vsp|q|vsp|q".
3440 * Don't do this while starting up though.
3441 * And don't change Rows, it may have be reduced intentionally
3442 * when adding menu/toolbar/tabline. */
3449 /* When the console tabline appears or disappears the window positions
3451 if (firstwin
->w_winrow
!= tabline_height())
3452 shell_new_rows(); /* recompute window positions and heights */
3457 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
3459 * Return TRUE if the GUI is taking care of the tabline.
3460 * It may still be hidden if 'showtabline' is zero.
3465 return gui
.in_use
&& vim_strchr(p_go
, GO_TABLINE
) != NULL
;
3469 * Return TRUE if the GUI is showing the tabline.
3470 * This uses 'showtabline'.
3475 if (!gui_use_tabline()
3477 || (p_stal
== 1 && first_tabpage
->tp_next
== NULL
))
3483 * Update the tabline.
3484 * This may display/undisplay the tabline and update the labels.
3487 gui_update_tabline()
3489 int showit
= gui_has_tabline();
3490 int shown
= gui_mch_showing_tabline();
3492 if (!gui
.starting
&& starting
== 0)
3494 /* Updating the tabline uses direct GUI commands, flush
3495 * outstanding instructions first. (esp. clear screen) */
3499 if (!showit
!= !shown
)
3500 gui_mch_show_tabline(showit
);
3502 gui_mch_update_tabline();
3504 /* When the tabs change from hidden to shown or from shown to
3505 * hidden the size of the text area should remain the same. */
3506 if (!showit
!= !shown
)
3507 gui_set_shellsize(FALSE
, showit
, RESIZE_VERT
);
3512 * Get the label or tooltip for tab page "tp" into NameBuff[].
3515 get_tabline_label(tp
, tooltip
)
3517 int tooltip
; /* TRUE: get tooltip */
3519 int modified
= FALSE
;
3525 /* Use 'guitablabel' or 'guitabtooltip' if it's set. */
3526 opt
= (tooltip
? &p_gtt
: &p_gtl
);
3529 int use_sandbox
= FALSE
;
3530 int save_called_emsg
= called_emsg
;
3531 char_u res
[MAXPATHL
];
3532 tabpage_T
*save_curtab
;
3533 char_u
*opt_name
= (char_u
*)(tooltip
? "guitabtooltip"
3536 called_emsg
= FALSE
;
3538 printer_page_num
= tabpage_index(tp
);
3540 set_vim_var_nr(VV_LNUM
, printer_page_num
);
3541 use_sandbox
= was_set_insecurely(opt_name
, 0);
3543 /* It's almost as going to the tabpage, but without autocommands. */
3544 curtab
->tp_firstwin
= firstwin
;
3545 curtab
->tp_lastwin
= lastwin
;
3546 curtab
->tp_curwin
= curwin
;
3547 save_curtab
= curtab
;
3549 topframe
= curtab
->tp_topframe
;
3550 firstwin
= curtab
->tp_firstwin
;
3551 lastwin
= curtab
->tp_lastwin
;
3552 curwin
= curtab
->tp_curwin
;
3553 curbuf
= curwin
->w_buffer
;
3555 /* Can't use NameBuff directly, build_stl_str_hl() uses it. */
3556 build_stl_str_hl(curwin
, res
, MAXPATHL
, *opt
, use_sandbox
,
3557 0, (int)Columns
, NULL
, NULL
);
3558 STRCPY(NameBuff
, res
);
3560 /* Back to the original curtab. */
3561 curtab
= save_curtab
;
3562 topframe
= curtab
->tp_topframe
;
3563 firstwin
= curtab
->tp_firstwin
;
3564 lastwin
= curtab
->tp_lastwin
;
3565 curwin
= curtab
->tp_curwin
;
3566 curbuf
= curwin
->w_buffer
;
3569 set_string_option_direct(opt_name
, -1,
3570 (char_u
*)"", OPT_FREE
, SID_ERROR
);
3571 called_emsg
|= save_called_emsg
;
3574 /* If 'guitablabel'/'guitabtooltip' is not set or the result is empty then
3575 * use a default label. */
3576 if (**opt
== NUL
|| *NameBuff
== NUL
)
3578 /* Get the buffer name into NameBuff[] and shorten it. */
3579 get_trans_bufname(tp
== curtab
? curbuf
: tp
->tp_curwin
->w_buffer
);
3581 shorten_dir(NameBuff
);
3583 wp
= (tp
== curtab
) ? firstwin
: tp
->tp_firstwin
;
3584 for (wincount
= 0; wp
!= NULL
; wp
= wp
->w_next
, ++wincount
)
3585 if (bufIsChanged(wp
->w_buffer
))
3587 if (modified
|| wincount
> 1)
3590 vim_snprintf((char *)buf
, sizeof(buf
), "%d", wincount
);
3596 mch_memmove(NameBuff
+ STRLEN(buf
), NameBuff
, STRLEN(NameBuff
) + 1);
3597 mch_memmove(NameBuff
, buf
, STRLEN(buf
));
3603 * Send the event for clicking to select tab page "nr".
3604 * Returns TRUE if it was done, FALSE when skipped because we are already at
3605 * that tab page or the cmdline window is open.
3608 send_tabline_event(nr
)
3613 if (nr
== tabpage_index(curtab
))
3616 /* Don't put events in the input queue now. */
3623 /* Set it back to the current tab page. */
3624 gui_mch_set_curtab(tabpage_index(curtab
));
3629 string
[1] = KS_TABLINE
;
3630 string
[2] = KE_FILLER
;
3631 add_to_input_buf(string
, 3);
3633 add_to_input_buf_csi(string
, 1);
3638 * Send a tabline menu event
3641 send_tabline_menu_event(tabidx
, event
)
3647 /* Don't put events in the input queue now. */
3648 if (hold_gui_events
)
3652 string
[1] = KS_TABMENU
;
3653 string
[2] = KE_FILLER
;
3654 add_to_input_buf(string
, 3);
3656 string
[1] = (char_u
)(long)event
;
3657 add_to_input_buf_csi(string
, 2);
3666 #if defined(FEAT_WINDOWS) || defined(PROTO)
3668 * Remove all scrollbars. Used before switching to another tab page.
3671 gui_remove_scrollbars()
3676 for (i
= 0; i
< 3; i
++)
3678 if (i
== SBAR_BOTTOM
)
3679 gui_mch_enable_scrollbar(&gui
.bottom_sbar
, FALSE
);
3684 gui_do_scrollbar(wp
, i
, FALSE
);
3687 curtab
->tp_prev_which_scrollbars
[i
] = -1;
3693 gui_create_scrollbar(sb
, type
, wp
)
3698 static int sbar_ident
= 0;
3700 sb
->ident
= sbar_ident
++; /* No check for too big, but would it happen? */
3704 #ifdef FEAT_GUI_ATHENA
3711 #ifdef FEAT_VERTSPLIT
3714 sb
->status_height
= 0;
3715 gui_mch_create_scrollbar(sb
, (wp
== NULL
) ? SBAR_HORIZ
: SBAR_VERT
);
3719 * Find the scrollbar with the given index.
3722 gui_find_scrollbar(ident
)
3727 if (gui
.bottom_sbar
.ident
== ident
)
3728 return &gui
.bottom_sbar
;
3731 if (wp
->w_scrollbars
[SBAR_LEFT
].ident
== ident
)
3732 return &wp
->w_scrollbars
[SBAR_LEFT
];
3733 if (wp
->w_scrollbars
[SBAR_RIGHT
].ident
== ident
)
3734 return &wp
->w_scrollbars
[SBAR_RIGHT
];
3740 * For most systems: Put a code in the input buffer for a dragged scrollbar.
3742 * For Win32, Macintosh and GTK+ 2:
3743 * Scrollbars seem to grab focus and vim doesn't read the input queue until
3744 * you stop dragging the scrollbar. We get here each time the scrollbar is
3745 * dragged another pixel, but as far as the rest of vim goes, it thinks
3746 * we're just hanging in the call to DispatchMessage() in
3747 * process_message(). The DispatchMessage() call that hangs was passed a
3748 * mouse button click event in the scrollbar window. -- webb.
3750 * Solution: Do the scrolling right here. But only when allowed.
3751 * Ignore the scrollbars while executing an external command or when there
3752 * are still characters to be processed.
3755 gui_drag_scrollbar(sb
, value
, still_dragging
)
3764 #ifdef USE_ON_FLY_SCROLL
3765 colnr_T old_leftcol
= curwin
->w_leftcol
;
3766 # ifdef FEAT_SCROLLBIND
3767 linenr_T old_topline
= curwin
->w_topline
;
3770 int old_topfill
= curwin
->w_topfill
;
3773 char_u bytes
[sizeof(long_u
)];
3780 /* Don't put events in the input queue now. */
3781 if (hold_gui_events
)
3785 if (cmdwin_type
!= 0 && sb
->wp
!= curwin
)
3792 gui
.dragged_sb
= SBAR_BOTTOM
;
3793 else if (sb
== &sb
->wp
->w_scrollbars
[SBAR_LEFT
])
3794 gui
.dragged_sb
= SBAR_LEFT
;
3796 gui
.dragged_sb
= SBAR_RIGHT
;
3797 gui
.dragged_wp
= sb
->wp
;
3801 gui
.dragged_sb
= SBAR_NONE
;
3803 /* Keep the "dragged_wp" value until after the scrolling, for when the
3804 * moust button is released. GTK2 doesn't send the button-up event. */
3805 gui
.dragged_wp
= NULL
;
3809 /* Vertical sbar info is kept in the first sbar (the left one) */
3811 sb
= &sb
->wp
->w_scrollbars
[0];
3814 * Check validity of value
3818 #ifdef SCROLL_PAST_END
3819 else if (value
> sb
->max
)
3822 if (value
> sb
->max
- sb
->size
+ 1)
3823 value
= sb
->max
- sb
->size
+ 1;
3828 #ifdef USE_ON_FLY_SCROLL
3829 /* When not allowed to do the scrolling right now, return.
3830 * This also checked input_available(), but that causes the first click in
3831 * a scrollbar to be ignored when Vim doesn't have focus. */
3835 #ifdef FEAT_INS_EXPAND
3836 /* Disallow scrolling the current window when the completion popup menu is
3838 if ((sb
->wp
== NULL
|| sb
->wp
== curwin
) && pum_visible())
3842 #ifdef FEAT_RIGHTLEFT
3843 if (sb
->wp
== NULL
&& curwin
->w_p_rl
)
3845 value
= sb
->max
+ 1 - sb
->size
- value
;
3851 if (sb
->wp
!= NULL
) /* vertical scrollbar */
3855 for (wp
= firstwin
; wp
!= sb
->wp
&& wp
!= NULL
; wp
= wp
->w_next
)
3860 if (sb
->wp
!= curwin
)
3864 #ifdef USE_ON_FLY_SCROLL
3865 current_scrollbar
= sb_num
;
3866 scrollbar_value
= value
;
3872 else if (State
& INSERT
)
3877 else if (State
& CMDLINE
)
3879 if (msg_scrolled
== 0)
3885 # ifdef FEAT_FOLDING
3886 /* Value may have been changed for closed fold. */
3887 sb
->value
= sb
->wp
->w_topline
- 1;
3890 /* When dragging one scrollbar and there is another one at the other
3891 * side move the thumb of that one too. */
3892 if (gui
.which_scrollbars
[SBAR_RIGHT
] && gui
.which_scrollbars
[SBAR_LEFT
])
3893 gui_mch_set_scrollbar_thumb(
3894 &sb
->wp
->w_scrollbars
[
3895 sb
== &sb
->wp
->w_scrollbars
[SBAR_RIGHT
]
3896 ? SBAR_LEFT
: SBAR_RIGHT
],
3897 sb
->value
, sb
->size
, sb
->max
);
3901 bytes
[1] = KS_VER_SCROLLBAR
;
3902 bytes
[2] = KE_FILLER
;
3903 bytes
[3] = (char_u
)sb_num
;
3909 #ifdef USE_ON_FLY_SCROLL
3910 scrollbar_value
= value
;
3913 gui_do_horiz_scroll();
3914 else if (State
& INSERT
)
3916 else if (State
& CMDLINE
)
3918 if (msg_scrolled
== 0)
3920 gui_do_horiz_scroll();
3924 if (old_leftcol
!= curwin
->w_leftcol
)
3926 updateWindow(curwin
); /* update window, status and cmdline */
3931 bytes
[1] = KS_HOR_SCROLLBAR
;
3932 bytes
[2] = KE_FILLER
;
3937 #ifdef USE_ON_FLY_SCROLL
3938 # ifdef FEAT_SCROLLBIND
3940 * synchronize other windows, as necessary according to 'scrollbind'
3943 && ((sb
->wp
== NULL
&& curwin
->w_leftcol
!= old_leftcol
)
3944 || (sb
->wp
== curwin
&& (curwin
->w_topline
!= old_topline
3946 || curwin
->w_topfill
!= old_topfill
3950 do_check_scrollbind(TRUE
);
3951 /* need to update the window right here */
3952 for (wp
= firstwin
; wp
!= NULL
; wp
= wp
->w_next
)
3953 if (wp
->w_redr_type
> 0)
3959 gui_update_cursor(FALSE
, TRUE
);
3961 add_to_input_buf(bytes
, byte_count
);
3962 add_long_to_buf((long_u
)value
, bytes
);
3963 add_to_input_buf_csi(bytes
, sizeof(long_u
));
3972 gui_update_scrollbars(force
)
3973 int force
; /* Force all scrollbars to get updated */
3977 long val
, size
, max
; /* need 32 bits here */
3980 #ifdef FEAT_VERTSPLIT
3981 static win_T
*prev_curwin
= NULL
;
3984 /* Update the horizontal scrollbar */
3985 gui_update_horiz_scrollbar(force
);
3988 /* Return straight away if there is neither a left nor right scrollbar.
3989 * On MS-Windows this is required anyway for scrollwheel messages. */
3990 if (!gui
.which_scrollbars
[SBAR_LEFT
] && !gui
.which_scrollbars
[SBAR_RIGHT
])
3995 * Don't want to update a scrollbar while we're dragging it. But if we
3996 * have both a left and right scrollbar, and we drag one of them, we still
3997 * need to update the other one.
3999 if (!force
&& (gui
.dragged_sb
== SBAR_LEFT
|| gui
.dragged_sb
== SBAR_RIGHT
)
4000 && gui
.which_scrollbars
[SBAR_LEFT
]
4001 && gui
.which_scrollbars
[SBAR_RIGHT
])
4004 * If we have two scrollbars and one of them is being dragged, just
4005 * copy the scrollbar position from the dragged one to the other one.
4007 which_sb
= SBAR_LEFT
+ SBAR_RIGHT
- gui
.dragged_sb
;
4008 if (gui
.dragged_wp
!= NULL
)
4009 gui_mch_set_scrollbar_thumb(
4010 &gui
.dragged_wp
->w_scrollbars
[which_sb
],
4011 gui
.dragged_wp
->w_scrollbars
[0].value
,
4012 gui
.dragged_wp
->w_scrollbars
[0].size
,
4013 gui
.dragged_wp
->w_scrollbars
[0].max
);
4016 /* avoid that moving components around generates events */
4019 for (wp
= firstwin
; wp
!= NULL
; wp
= W_NEXT(wp
))
4021 if (wp
->w_buffer
== NULL
) /* just in case */
4023 /* Skip a scrollbar that is being dragged. */
4024 if (!force
&& (gui
.dragged_sb
== SBAR_LEFT
4025 || gui
.dragged_sb
== SBAR_RIGHT
)
4026 && gui
.dragged_wp
== wp
)
4029 #ifdef SCROLL_PAST_END
4030 max
= wp
->w_buffer
->b_ml
.ml_line_count
- 1;
4032 max
= wp
->w_buffer
->b_ml
.ml_line_count
+ wp
->w_height
- 2;
4034 if (max
< 0) /* empty buffer */
4036 val
= wp
->w_topline
- 1;
4037 size
= wp
->w_height
;
4038 #ifdef SCROLL_PAST_END
4039 if (val
> max
) /* just in case */
4042 if (size
> max
+ 1) /* just in case */
4044 if (val
> max
- size
+ 1)
4045 val
= max
- size
+ 1;
4047 if (val
< 0) /* minimal value is 0 */
4051 * Scrollbar at index 0 (the left one) contains all the information.
4052 * It would be the same info for left and right so we just store it for
4055 sb
= &wp
->w_scrollbars
[0];
4058 * Note: no check for valid w_botline. If it's not valid the
4059 * scrollbars will be updated later anyway.
4061 if (size
< 1 || wp
->w_botline
- 2 > max
)
4064 * This can happen during changing files. Just don't update the
4065 * scrollbar for now.
4067 sb
->height
= 0; /* Force update next time */
4068 if (gui
.which_scrollbars
[SBAR_LEFT
])
4069 gui_do_scrollbar(wp
, SBAR_LEFT
, FALSE
);
4070 if (gui
.which_scrollbars
[SBAR_RIGHT
])
4071 gui_do_scrollbar(wp
, SBAR_RIGHT
, FALSE
);
4074 if (force
|| sb
->height
!= wp
->w_height
4076 || sb
->top
!= wp
->w_winrow
4077 || sb
->status_height
!= wp
->w_status_height
4078 # ifdef FEAT_VERTSPLIT
4079 || sb
->width
!= wp
->w_width
4080 || prev_curwin
!= curwin
4085 /* Height, width or position of scrollbar has changed. For
4086 * vertical split: curwin changed. */
4087 sb
->height
= wp
->w_height
;
4089 sb
->top
= wp
->w_winrow
;
4090 sb
->status_height
= wp
->w_status_height
;
4091 # ifdef FEAT_VERTSPLIT
4092 sb
->width
= wp
->w_width
;
4096 /* Calculate height and position in pixels */
4097 h
= (sb
->height
+ sb
->status_height
) * gui
.char_height
;
4098 y
= sb
->top
* gui
.char_height
+ gui
.border_offset
;
4099 #if defined(FEAT_MENU) && !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MOTIF) \
4100 || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_MACVIM))
4101 if (gui
.menu_is_active
)
4102 y
+= gui
.menu_height
;
4105 #if defined(FEAT_TOOLBAR) && (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_ATHENA))
4106 if (vim_strchr(p_go
, GO_TOOLBAR
) != NULL
)
4107 # ifdef FEAT_GUI_ATHENA
4108 y
+= gui
.toolbar_height
;
4110 # ifdef FEAT_GUI_MSWIN
4111 y
+= TOOLBAR_BUTTON_HEIGHT
+ TOOLBAR_BORDER_HEIGHT
;
4116 #if defined(FEAT_GUI_TABLINE) && defined(FEAT_GUI_MSWIN)
4117 if (gui_has_tabline())
4118 y
+= gui
.tabline_height
;
4122 if (wp
->w_winrow
== 0)
4125 /* Height of top scrollbar includes width of top border */
4126 h
+= gui
.border_offset
;
4127 y
-= gui
.border_offset
;
4129 if (gui
.which_scrollbars
[SBAR_LEFT
])
4131 gui_mch_set_scrollbar_pos(&wp
->w_scrollbars
[SBAR_LEFT
],
4133 gui
.scrollbar_width
, h
);
4134 gui_do_scrollbar(wp
, SBAR_LEFT
, TRUE
);
4136 if (gui
.which_scrollbars
[SBAR_RIGHT
])
4138 gui_mch_set_scrollbar_pos(&wp
->w_scrollbars
[SBAR_RIGHT
],
4139 gui
.right_sbar_x
, y
,
4140 gui
.scrollbar_width
, h
);
4141 gui_do_scrollbar(wp
, SBAR_RIGHT
, TRUE
);
4145 /* Reduce the number of calls to gui_mch_set_scrollbar_thumb() by
4146 * checking if the thumb moved at least a pixel. Only do this for
4147 * Athena, most other GUIs require the update anyway to make the
4149 #ifdef FEAT_GUI_ATHENA
4153 y
= (val
* (sb
->height
+ 2) * gui
.char_height
+ max
/ 2) / max
;
4154 if (force
|| sb
->pixval
!= y
|| sb
->size
!= size
|| sb
->max
!= max
)
4156 if (force
|| sb
->value
!= val
|| sb
->size
!= size
|| sb
->max
!= max
)
4159 /* Thumb of scrollbar has moved */
4161 #ifdef FEAT_GUI_ATHENA
4166 if (gui
.which_scrollbars
[SBAR_LEFT
]
4167 && (gui
.dragged_sb
!= SBAR_LEFT
|| gui
.dragged_wp
!= wp
))
4168 gui_mch_set_scrollbar_thumb(&wp
->w_scrollbars
[SBAR_LEFT
],
4170 if (gui
.which_scrollbars
[SBAR_RIGHT
]
4171 && (gui
.dragged_sb
!= SBAR_RIGHT
|| gui
.dragged_wp
!= wp
))
4172 gui_mch_set_scrollbar_thumb(&wp
->w_scrollbars
[SBAR_RIGHT
],
4176 #ifdef FEAT_VERTSPLIT
4177 prev_curwin
= curwin
;
4183 * Enable or disable a scrollbar.
4184 * Check for scrollbars for vertically split windows which are not enabled
4188 gui_do_scrollbar(wp
, which
, enable
)
4190 int which
; /* SBAR_LEFT or SBAR_RIGHT */
4191 int enable
; /* TRUE to enable scrollbar */
4193 #ifdef FEAT_VERTSPLIT
4194 int midcol
= curwin
->w_wincol
+ curwin
->w_width
/ 2;
4195 int has_midcol
= (wp
->w_wincol
<= midcol
4196 && wp
->w_wincol
+ wp
->w_width
>= midcol
);
4198 /* Only enable scrollbars that contain the middle column of the current
4200 if (gui
.which_scrollbars
[SBAR_RIGHT
] != gui
.which_scrollbars
[SBAR_LEFT
])
4202 /* Scrollbars only on one side. Don't enable scrollbars that don't
4203 * contain the middle column of the current window. */
4209 /* Scrollbars on both sides. Don't enable scrollbars that neither
4210 * contain the middle column of the current window nor are on the far
4212 if (midcol
> Columns
/ 2)
4214 if (which
== SBAR_LEFT
? wp
->w_wincol
!= 0 : !has_midcol
)
4219 if (which
== SBAR_RIGHT
? wp
->w_wincol
+ wp
->w_width
!= Columns
4225 gui_mch_enable_scrollbar(&wp
->w_scrollbars
[which
], enable
);
4229 * Scroll a window according to the values set in the globals current_scrollbar
4230 * and scrollbar_value. Return TRUE if the cursor in the current window moved
4231 * or FALSE otherwise.
4236 win_T
*wp
, *save_wp
;
4240 linenr_T old_topline
;
4245 for (wp
= firstwin
, i
= 0; i
< current_scrollbar
; wp
= W_NEXT(wp
), i
++)
4249 /* Couldn't find window */
4253 * Compute number of lines to scroll. If zero, nothing to do.
4255 nlines
= (long)scrollbar_value
+ 1 - (long)wp
->w_topline
;
4260 old_topline
= wp
->w_topline
;
4262 old_topfill
= wp
->w_topfill
;
4264 old_cursor
= wp
->w_cursor
;
4266 curbuf
= wp
->w_buffer
;
4268 scrolldown(-nlines
, gui
.dragged_wp
== NULL
);
4270 scrollup(nlines
, gui
.dragged_wp
== NULL
);
4271 /* Reset dragged_wp after using it. "dragged_sb" will have been reset for
4272 * the mouse-up event already, but we still want it to behave like when
4273 * dragging. But not the next click in an arrow. */
4274 if (gui
.dragged_sb
== SBAR_NONE
)
4275 gui
.dragged_wp
= NULL
;
4277 if (old_topline
!= wp
->w_topline
4279 || old_topfill
!= wp
->w_topfill
4285 cursor_correct(); /* fix window for 'so' */
4286 update_topline(); /* avoid up/down jump */
4288 if (old_cursor
.lnum
!= wp
->w_cursor
.lnum
)
4289 coladvance(wp
->w_curswant
);
4290 #ifdef FEAT_SCROLLBIND
4291 wp
->w_scbind_pos
= wp
->w_topline
;
4295 /* Make sure wp->w_leftcol and wp->w_skipcol are correct. */
4299 curbuf
= save_wp
->w_buffer
;
4302 * Don't call updateWindow() when nothing has changed (it will overwrite
4303 * the status line!).
4305 if (old_topline
!= wp
->w_topline
4306 || wp
->w_redr_type
!= 0
4308 || old_topfill
!= wp
->w_topfill
4314 #ifdef FEAT_INS_EXPAND
4318 wp
->w_lines_valid
= 0;
4321 /* Don't set must_redraw here, it may cause the popup menu to
4322 * disappear when losing focus after a scrollbar drag. */
4323 if (wp
->w_redr_type
< type
)
4324 wp
->w_redr_type
= type
;
4325 updateWindow(wp
); /* update window, status line, and cmdline */
4328 #ifdef FEAT_INS_EXPAND
4329 /* May need to redraw the popup menu. */
4334 return (wp
== curwin
&& !equalpos(curwin
->w_cursor
, old_cursor
));
4339 * Horizontal scrollbar stuff:
4343 * Return length of line "lnum" for horizontal scrolling.
4346 scroll_line_len(lnum
)
4358 w
= chartabsize(p
, col
);
4360 if (*p
== NUL
) /* don't count the last character */
4367 /* Remember which line is currently the longest, so that we don't have to
4368 * search for it when scrolling horizontally. */
4369 static linenr_T longest_lnum
= 0;
4372 gui_update_horiz_scrollbar(force
)
4375 long value
, size
, max
; /* need 32 bit ints here */
4377 if (!gui
.which_scrollbars
[SBAR_BOTTOM
])
4380 if (!force
&& gui
.dragged_sb
== SBAR_BOTTOM
)
4383 if (!force
&& curwin
->w_p_wrap
&& gui
.prev_wrap
)
4387 * It is possible for the cursor to be invalid if we're in the middle of
4388 * something (like changing files). If so, don't do anything for now.
4390 if (curwin
->w_cursor
.lnum
> curbuf
->b_ml
.ml_line_count
)
4392 gui
.bottom_sbar
.value
= -1;
4396 size
= W_WIDTH(curwin
);
4397 if (curwin
->w_p_wrap
)
4400 #ifdef SCROLL_PAST_END
4403 max
= W_WIDTH(curwin
) - 1;
4408 value
= curwin
->w_leftcol
;
4410 /* Calculate maximum for horizontal scrollbar. Check for reasonable
4411 * line numbers, topline and botline can be invalid when displaying is
4413 if (vim_strchr(p_go
, GO_HORSCROLL
) == NULL
4414 && curwin
->w_topline
<= curwin
->w_cursor
.lnum
4415 && curwin
->w_botline
> curwin
->w_cursor
.lnum
4416 && curwin
->w_botline
<= curbuf
->b_ml
.ml_line_count
+ 1)
4421 /* Use maximum of all visible lines. Remember the lnum of the
4422 * longest line, clostest to the cursor line. Used when scrolling
4425 for (lnum
= curwin
->w_topline
; lnum
< curwin
->w_botline
; ++lnum
)
4427 n
= scroll_line_len(lnum
);
4428 if (n
> (colnr_T
)max
)
4431 longest_lnum
= lnum
;
4433 else if (n
== (colnr_T
)max
4434 && abs((int)(lnum
- curwin
->w_cursor
.lnum
))
4435 < abs((int)(longest_lnum
- curwin
->w_cursor
.lnum
)))
4436 longest_lnum
= lnum
;
4440 /* Use cursor line only. */
4441 max
= scroll_line_len(curwin
->w_cursor
.lnum
);
4442 #ifdef FEAT_VIRTUALEDIT
4443 if (virtual_active())
4445 /* May move the cursor even further to the right. */
4446 if (curwin
->w_virtcol
>= (colnr_T
)max
)
4447 max
= curwin
->w_virtcol
;
4451 #ifndef SCROLL_PAST_END
4452 max
+= W_WIDTH(curwin
) - 1;
4454 /* The line number isn't scrolled, thus there is less space when
4455 * 'number' is set (also for 'foldcolumn'). */
4456 size
-= curwin_col_off();
4457 #ifndef SCROLL_PAST_END
4458 max
-= curwin_col_off();
4462 #ifndef SCROLL_PAST_END
4463 if (value
> max
- size
+ 1)
4464 value
= max
- size
+ 1; /* limit the value to allowable range */
4467 #ifdef FEAT_RIGHTLEFT
4470 value
= max
+ 1 - size
- value
;
4478 if (!force
&& value
== gui
.bottom_sbar
.value
&& size
== gui
.bottom_sbar
.size
4479 && max
== gui
.bottom_sbar
.max
)
4482 gui
.bottom_sbar
.value
= value
;
4483 gui
.bottom_sbar
.size
= size
;
4484 gui
.bottom_sbar
.max
= max
;
4485 gui
.prev_wrap
= curwin
->w_p_wrap
;
4487 gui_mch_set_scrollbar_thumb(&gui
.bottom_sbar
, value
, size
, max
);
4491 * Do a horizontal scroll. Return TRUE if the cursor moved, FALSE otherwise.
4494 gui_do_horiz_scroll()
4496 /* no wrapping, no scrolling */
4497 if (curwin
->w_p_wrap
)
4500 if (curwin
->w_leftcol
== scrollbar_value
)
4503 curwin
->w_leftcol
= (colnr_T
)scrollbar_value
;
4505 /* When the line of the cursor is too short, move the cursor to the
4506 * longest visible line. Do a sanity check on "longest_lnum", just in
4508 if (vim_strchr(p_go
, GO_HORSCROLL
) == NULL
4509 && longest_lnum
>= curwin
->w_topline
4510 && longest_lnum
< curwin
->w_botline
4511 && !virtual_active())
4513 if (scrollbar_value
> scroll_line_len(curwin
->w_cursor
.lnum
))
4515 curwin
->w_cursor
.lnum
= longest_lnum
;
4516 curwin
->w_cursor
.col
= 0;
4520 return leftcol_changed();
4524 * Check that none of the colors are the same as the background color
4529 if (gui
.norm_pixel
== gui
.back_pixel
|| gui
.norm_pixel
== INVALCOLOR
)
4531 gui_set_bg_color((char_u
*)"White");
4532 if (gui
.norm_pixel
== gui
.back_pixel
|| gui
.norm_pixel
== INVALCOLOR
)
4533 gui_set_fg_color((char_u
*)"Black");
4538 gui_set_fg_color(name
)
4541 gui
.norm_pixel
= gui_get_color(name
);
4542 hl_set_fg_color_name(vim_strsave(name
));
4546 gui_set_bg_color(name
)
4549 gui
.back_pixel
= gui_get_color(name
);
4550 hl_set_bg_color_name(vim_strsave(name
));
4554 * Allocate a color by name.
4555 * Returns INVALCOLOR and gives an error message when failed.
4565 t
= gui_mch_get_color(name
);
4568 #if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK)
4572 EMSG2(_("E254: Cannot allocate color %s"), name
);
4577 * Return the grey value of a color (range 0-255).
4580 gui_get_lightness(pixel
)
4583 long_u rgb
= gui_mch_get_rgb(pixel
);
4585 return (int)( (((rgb
>> 16) & 0xff) * 299)
4586 + (((rgb
>> 8) & 0xff) * 587)
4587 + ((rgb
& 0xff) * 114)) / 1000;
4590 #if defined(FEAT_GUI_X11) || defined(PROTO)
4592 gui_new_scrollbar_colors()
4596 /* Nothing to do if GUI hasn't started yet. */
4602 gui_mch_set_scrollbar_colors(&(wp
->w_scrollbars
[SBAR_LEFT
]));
4603 gui_mch_set_scrollbar_colors(&(wp
->w_scrollbars
[SBAR_RIGHT
]));
4605 gui_mch_set_scrollbar_colors(&gui
.bottom_sbar
);
4610 * Call this when focus has changed.
4613 gui_focus_change(in_focus
)
4617 * Skip this code to avoid drawing the cursor when debugging and switching
4618 * between the debugger window and gvim.
4621 gui
.in_focus
= in_focus
;
4622 out_flush(); /* make sure output has been written */
4623 gui_update_cursor(TRUE
, FALSE
);
4626 xim_set_focus(in_focus
);
4629 /* Put events in the input queue only when allowed.
4630 * ui_focus_change() isn't called directly, because it invokes
4631 * autocommands and that must not happen asynchronously. */
4632 if (!hold_gui_events
)
4637 bytes
[1] = KS_EXTRA
;
4638 bytes
[2] = in_focus
? (int)KE_FOCUSGAINED
: (int)KE_FOCUSLOST
;
4639 add_to_input_buf(bytes
, 3);
4645 * Called when the mouse moved (but not when dragging).
4648 gui_mouse_moved(x
, y
)
4655 /* Ignore this while still starting up. */
4656 if (!gui
.in_use
|| gui
.starting
)
4659 #ifdef FEAT_MOUSESHAPE
4660 /* Get window pointer, and update mouse shape as well. */
4664 /* Only handle this when 'mousefocus' set and ... */
4666 && !hold_gui_events
/* not holding events */
4667 && (State
& (NORMAL
|INSERT
))/* Normal/Visual/Insert mode */
4668 && State
!= HITRETURN
/* but not hit-return prompt */
4669 && msg_scrolled
== 0 /* no scrolled message */
4670 && !need_mouse_correct
/* not moving the pointer */
4671 && gui
.in_focus
) /* gvim in focus */
4673 /* Don't move the mouse when it's left or right of the Vim window */
4674 if (x
< 0 || x
> Columns
* gui
.char_width
)
4676 #ifndef FEAT_MOUSESHAPE
4679 if (wp
== curwin
|| wp
== NULL
)
4680 return; /* still in the same old window, or none at all */
4683 /* Ignore position in the tab pages line. */
4684 if (Y_2_ROW(y
) < tabline_height())
4689 * format a mouse click on status line input
4690 * ala gui_send_mouse_event(0, x, y, 0, 0);
4691 * Trick: Use a column number -1, so that get_pseudo_mouse_code() will
4692 * generate a K_LEFTMOUSE_NM key code.
4696 /* abort the current operator first */
4698 add_to_input_buf(st
, 1);
4703 st
[3] = (char_u
)MOUSE_LEFT
;
4704 fill_mouse_coord(st
+ 4,
4705 #ifdef FEAT_VERTSPLIT
4706 wp
->w_wincol
== 0 ? -1 : wp
->w_wincol
+ MOUSE_COLOFF
,
4710 wp
->w_height
+ W_WINROW(wp
));
4712 add_to_input_buf(st
, 8);
4713 st
[3] = (char_u
)MOUSE_RELEASE
;
4714 add_to_input_buf(st
, 8);
4716 /* Need to wake up the main loop */
4717 if (gtk_main_level() > 0)
4724 * Called when mouse should be moved to window with focus.
4732 need_mouse_correct
= FALSE
;
4734 if (!(gui
.in_use
&& p_mousef
))
4737 gui_mch_getmouse(&x
, &y
);
4738 /* Don't move the mouse when it's left or right of the Vim window */
4739 if (x
< 0 || x
> Columns
* gui
.char_width
)
4742 # ifdef FEAT_WINDOWS
4743 && Y_2_ROW(y
) >= tabline_height()
4747 if (wp
!= curwin
&& wp
!= NULL
) /* If in other than current window */
4749 validate_cline_row();
4750 gui_mch_setmouse((int)W_ENDCOL(curwin
) * gui
.char_width
- 3,
4751 (W_WINROW(curwin
) + curwin
->w_wrow
) * gui
.char_height
4752 + (gui
.char_height
) / 2);
4757 * Find window where the mouse pointer "y" coordinate is in.
4772 if (row
< 0 || col
< 0) /* before first window */
4774 wp
= mouse_find_win(&row
, &col
);
4775 # ifdef FEAT_MOUSESHAPE
4776 if (State
== HITRETURN
|| State
== ASKMORE
)
4778 if (Y_2_ROW(y
) >= msg_row
)
4779 update_mouseshape(SHAPE_IDX_MOREL
);
4781 update_mouseshape(SHAPE_IDX_MORE
);
4783 else if (row
> wp
->w_height
) /* below status line */
4784 update_mouseshape(SHAPE_IDX_CLINE
);
4785 # ifdef FEAT_VERTSPLIT
4786 else if (!(State
& CMDLINE
) && W_VSEP_WIDTH(wp
) > 0 && col
== wp
->w_width
4787 && (row
!= wp
->w_height
|| !stl_connected(wp
)) && msg_scrolled
== 0)
4788 update_mouseshape(SHAPE_IDX_VSEP
);
4790 else if (!(State
& CMDLINE
) && W_STATUS_HEIGHT(wp
) > 0
4791 && row
== wp
->w_height
&& msg_scrolled
== 0)
4792 update_mouseshape(SHAPE_IDX_STATUS
);
4794 update_mouseshape(-2);
4803 * ":gui" and ":gvim": Change from the terminal version to the GUI version.
4804 * File names may be given to redefine the args list.
4810 char_u
*arg
= eap
->arg
;
4813 * Check for "-f" argument: foreground, don't fork.
4814 * Also don't fork when started with "gvim -f".
4815 * Do fork when using "gui -b".
4818 && (arg
[1] == 'f' || arg
[1] == 'b')
4819 && (arg
[2] == NUL
|| vim_iswhite(arg
[2])))
4821 gui
.dofork
= (arg
[1] == 'b');
4822 eap
->arg
= skipwhite(eap
->arg
+ 2);
4826 /* Clear the command. Needed for when forking+exiting, to avoid part
4827 * of the argument ending up after the shell prompt. */
4830 /* os x doesn't really support fork(), so we can't fork of a gui
4831 * in an already running vim. see gui_start() for more details.
4835 msg_clr_eos_force();
4838 if (!ends_excmd(*eap
->arg
))
4842 #if ((defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32) \
4843 || defined(FEAT_GUI_PHOTON)) && defined(FEAT_TOOLBAR)) || defined(PROTO)
4845 * This is shared between Athena, Motif and GTK.
4847 static void gfp_setname
__ARGS((char_u
*fname
, void *cookie
));
4850 * Callback function for do_in_runtimepath().
4853 gfp_setname(fname
, cookie
)
4857 char_u
*gfp_buffer
= cookie
;
4859 if (STRLEN(fname
) >= MAXPATHL
)
4862 STRCPY(gfp_buffer
, fname
);
4866 * Find the path of bitmap "name" with extension "ext" in 'runtimepath'.
4867 * Return FAIL for failure and OK if buffer[MAXPATHL] contains the result.
4870 gui_find_bitmap(name
, buffer
, ext
)
4875 if (STRLEN(name
) > MAXPATHL
- 14)
4877 vim_snprintf((char *)buffer
, MAXPATHL
, "bitmaps/%s.%s", name
, ext
);
4878 if (do_in_runtimepath(buffer
, FALSE
, gfp_setname
, buffer
) == FAIL
4884 # if !defined(HAVE_GTK2) || defined(PROTO)
4886 * Given the name of the "icon=" argument, try finding the bitmap file for the
4887 * icon. If it is an absolute path name, use it as it is. Otherwise append
4888 * "ext" and search for it in 'runtimepath'.
4889 * The result is put in "buffer[MAXPATHL]". If something fails "buffer"
4893 gui_find_iconfile(name
, buffer
, ext
)
4898 char_u buf
[MAXPATHL
+ 1];
4900 expand_env(name
, buffer
, MAXPATHL
);
4901 if (!mch_isFullName(buffer
) && gui_find_bitmap(buffer
, buf
, ext
) == OK
)
4902 STRCPY(buffer
, buf
);
4907 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11) || defined(PROTO)
4915 else if (error_ga
.ga_data
!= NULL
)
4917 /* avoid putting up a message box with blanks only */
4918 for (p
= (char_u
*)error_ga
.ga_data
; *p
!= NUL
; ++p
)
4921 /* Truncate a very long message, it will go off-screen. */
4922 if (STRLEN(p
) > 2000)
4923 STRCPY(p
+ 2000 - 14, "...(truncated)");
4924 (void)do_dialog(VIM_ERROR
, (char_u
*)_("Error"),
4925 p
, (char_u
*)_("&Ok"), 1, NULL
);
4928 ga_clear(&error_ga
);
4933 #if defined(NO_CONSOLE_INPUT) || defined(PROTO)
4935 * Return TRUE if still starting up and there is no place to enter text.
4936 * For GTK and X11 we check if stderr is not a tty, which means we were
4937 * (probably) started from the desktop. Also check stdin, "vim >& file" does
4938 * allow typing on stdin.
4943 return ((!gui
.in_use
|| gui
.starting
)
4945 && !isatty(0) && !isatty(2)
4951 #if defined(FIND_REPLACE_DIALOG) || defined(FEAT_SUN_WORKSHOP) \
4952 || defined(NEED_GUI_UPDATE_SCREEN) \
4955 * Update the current window and the screen.
4962 update_screen(0); /* may need to update the screen */
4964 out_flush(); /* make sure output has been written */
4965 gui_update_cursor(TRUE
, FALSE
);
4970 #if defined(FIND_REPLACE_DIALOG) || defined(PROTO)
4971 static void concat_esc
__ARGS((garray_T
*gap
, char_u
*text
, int what
));
4974 * Get the text to use in a find/replace dialog. Uses the last search pattern
4975 * if the argument is empty.
4976 * Returns an allocated string.
4979 get_find_dialog_text(arg
, wwordp
, mcasep
)
4981 int *wwordp
; /* return: TRUE if \< \> found */
4982 int *mcasep
; /* return: TRUE if \C found */
4987 text
= last_search_pat();
4992 text
= vim_strsave(text
);
4995 int len
= (int)STRLEN(text
);
4999 if (len
>= 2 && STRNCMP(text
, "\\V", 2) == 0)
5001 mch_memmove(text
, text
+ 2, (size_t)(len
- 1));
5005 /* Recognize "\c" and "\C" and remove. */
5006 if (len
>= 2 && *text
== '\\' && (text
[1] == 'c' || text
[1] == 'C'))
5008 *mcasep
= (text
[1] == 'C');
5009 mch_memmove(text
, text
+ 2, (size_t)(len
- 1));
5013 /* Recognize "\<text\>" and remove. */
5015 && STRNCMP(text
, "\\<", 2) == 0
5016 && STRNCMP(text
+ len
- 2, "\\>", 2) == 0)
5019 mch_memmove(text
, text
+ 2, (size_t)(len
- 4));
5020 text
[len
- 4] = NUL
;
5023 /* Recognize "\/" or "\?" and remove. */
5024 for (i
= 0; i
+ 1 < len
; ++i
)
5025 if (text
[i
] == '\\' && (text
[i
+ 1] == '/'
5026 || text
[i
+ 1] == '?'))
5028 mch_memmove(text
+ i
, text
+ i
+ 1, (size_t)(len
- i
));
5037 * Concatenate "text" to grow array "gap", escaping "what" with a backslash.
5040 concat_esc(gap
, text
, what
)
5045 while (*text
!= NUL
)
5048 int l
= (*mb_ptr2len
)(text
);
5053 ga_append(gap
, *text
++);
5058 ga_append(gap
, '\\');
5059 ga_append(gap
, *text
);
5065 * Handle the press of a button in the find-replace dialog.
5066 * Return TRUE when something was added to the input buffer.
5069 gui_do_findrepl(flags
, find_text
, repl_text
, down
)
5070 int flags
; /* one of FRD_REPLACE, FRD_FINDNEXT, etc. */
5073 int down
; /* Search downwards. */
5077 int type
= (flags
& FRD_TYPE_MASK
);
5079 regmatch_T regmatch
;
5080 int save_did_emsg
= did_emsg
;
5082 ga_init2(&ga
, 1, 100);
5083 if (type
== FRD_REPLACEALL
)
5084 ga_concat(&ga
, (char_u
*)"%s/");
5086 ga_concat(&ga
, (char_u
*)"\\V");
5087 if (flags
& FRD_MATCH_CASE
)
5088 ga_concat(&ga
, (char_u
*)"\\C");
5090 ga_concat(&ga
, (char_u
*)"\\c");
5091 if (flags
& FRD_WHOLE_WORD
)
5092 ga_concat(&ga
, (char_u
*)"\\<");
5093 if (type
== FRD_REPLACEALL
|| down
)
5094 concat_esc(&ga
, find_text
, '/'); /* escape slashes */
5096 concat_esc(&ga
, find_text
, '?'); /* escape '?' */
5097 if (flags
& FRD_WHOLE_WORD
)
5098 ga_concat(&ga
, (char_u
*)"\\>");
5100 if (type
== FRD_REPLACEALL
)
5102 ga_concat(&ga
, (char_u
*)"/");
5103 /* escape / and \ */
5104 p
= vim_strsave_escaped(repl_text
, (char_u
*)"/\\");
5108 ga_concat(&ga
, (char_u
*)"/g");
5110 ga_append(&ga
, NUL
);
5112 if (type
== FRD_REPLACE
)
5114 /* Do the replacement when the text at the cursor matches. Thus no
5115 * replacement is done if the cursor was moved! */
5116 regmatch
.regprog
= vim_regcomp(ga
.ga_data
, RE_MAGIC
+ RE_STRING
);
5118 if (regmatch
.regprog
!= NULL
)
5120 p
= ml_get_cursor();
5121 if (vim_regexec_nl(®match
, p
, (colnr_T
)0)
5122 && regmatch
.startp
[0] == p
)
5124 /* Clear the command line to remove any old "No match"
5128 if (u_save_cursor() == OK
)
5130 /* A button was pressed thus undo should be synced. */
5133 del_bytes((long)(regmatch
.endp
[0] - regmatch
.startp
[0]),
5139 MSG(_("No match at cursor, finding next"));
5140 vim_free(regmatch
.regprog
);
5144 if (type
== FRD_REPLACEALL
)
5146 /* A button was pressed, thus undo should be synced. */
5148 do_cmdline_cmd(ga
.ga_data
);
5152 /* Search for the next match. */
5154 do_search(NULL
, down
? '/' : '?', ga
.ga_data
, 1L,
5155 SEARCH_MSG
+ SEARCH_MARK
, NULL
);
5156 msg_scroll
= i
; /* don't let an error message set msg_scroll */
5159 /* Don't want to pass did_emsg to other code, it may cause disabling
5160 * syntax HL if we were busy redrawing. */
5161 did_emsg
= save_did_emsg
;
5163 if (State
& (NORMAL
| INSERT
))
5165 gui_update_screen(); /* update the screen */
5166 msg_didout
= 0; /* overwrite any message */
5167 need_wait_return
= FALSE
; /* don't wait for return */
5170 vim_free(ga
.ga_data
);
5171 return (ga
.ga_len
> 0);
5176 #if (defined(FEAT_DND) && defined(FEAT_GUI_GTK)) \
5177 || defined(FEAT_GUI_MSWIN) \
5178 || defined(FEAT_GUI_MAC) \
5180 || defined(FEAT_GUI_MACVIM)
5183 static void gui_wingoto_xy
__ARGS((int x
, int y
));
5186 * Jump to the window at specified point (x, y).
5189 gui_wingoto_xy(x
, y
)
5193 int row
= Y_2_ROW(y
);
5194 int col
= X_2_COL(x
);
5197 if (row
>= 0 && col
>= 0)
5199 wp
= mouse_find_win(&row
, &col
);
5200 if (wp
!= NULL
&& wp
!= curwin
)
5207 * Process file drop. Mouse cursor position, key modifiers, name of files
5208 * and count of files are given. Argument "fnames[count]" has full pathnames
5209 * of dropped files, they will be freed in this function, and caller can't use
5210 * fnames after call this function.
5214 gui_handle_drop(x
, y
, modifiers
, fnames
, count
)
5225 * When the cursor is at the command line, add the file names to the
5226 * command line, don't edit the files.
5228 if (State
& CMDLINE
)
5230 shorten_filenames(fnames
, count
);
5231 for (i
= 0; i
< count
; ++i
)
5233 if (fnames
[i
] != NULL
)
5236 add_to_input_buf((char_u
*)" ", 1);
5238 /* We don't know what command is used thus we can't be sure
5239 * about which characters need to be escaped. Only escape the
5240 * most common ones. */
5241 # ifdef BACKSLASH_IN_FILENAME
5242 p
= vim_strsave_escaped(fnames
[i
], (char_u
*)" \t\"|");
5244 p
= vim_strsave_escaped(fnames
[i
], (char_u
*)"\\ \t\"|");
5247 add_to_input_buf_csi(p
, (int)STRLEN(p
));
5249 vim_free(fnames
[i
]);
5256 /* Go to the window under mouse cursor, then shorten given "fnames" by
5257 * current window, because a window can have local current dir. */
5258 # ifdef FEAT_WINDOWS
5259 gui_wingoto_xy(x
, y
);
5261 shorten_filenames(fnames
, count
);
5263 /* If Shift held down, remember the first item. */
5264 if ((modifiers
& MOUSE_SHIFT
) != 0)
5265 p
= vim_strsave(fnames
[0]);
5269 /* Handle the drop, :edit or :split to get to the file. This also
5270 * frees fnames[]. Skip this if there is only one item it's a
5271 * directory and Shift is held down. */
5272 if (count
== 1 && (modifiers
& MOUSE_SHIFT
) != 0
5273 && mch_isdir(fnames
[0]))
5275 vim_free(fnames
[0]);
5279 handle_drop(count
, fnames
, (modifiers
& MOUSE_CTRL
) != 0);
5281 /* If Shift held down, change to first file's directory. If the first
5282 * item is a directory, change to that directory (and let the explorer
5283 * plugin show the contents). */
5288 if (mch_chdir((char *)p
) == 0)
5289 shorten_fnames(TRUE
);
5291 else if (vim_chdirfile(p
) == OK
)
5292 shorten_fnames(TRUE
);
5296 /* Update the screen display */
5297 update_screen(NOT_VALID
);
5299 gui_update_menus(0);
5303 gui_update_cursor(FALSE
, FALSE
);