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