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