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