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