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