blob: 5265b4b9b370938f0467882701b0170169a56efd [file] [log] [blame]
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read a list of people who contributed.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Implementation of popup windows. See ":help popup".
12 */
13
14#include "vim.h"
15
16#ifdef FEAT_TEXT_PROP
17
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +020018typedef struct {
19 char *pp_name;
20 poppos_T pp_val;
21} poppos_entry_T;
22
23static poppos_entry_T poppos_entries[] = {
24 {"botleft", POPPOS_BOTLEFT},
25 {"topleft", POPPOS_TOPLEFT},
26 {"botright", POPPOS_BOTRIGHT},
27 {"topright", POPPOS_TOPRIGHT},
28 {"center", POPPOS_CENTER}
29};
30
Bram Moolenaar4d784b22019-05-25 19:51:39 +020031/*
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +020032 * Get option value for "key", which is "line" or "col".
Bram Moolenaarcc31ad92019-05-30 19:25:06 +020033 * Handles "cursor+N" and "cursor-N".
34 */
35 static int
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +020036popup_options_one(dict_T *dict, char_u *key)
Bram Moolenaarcc31ad92019-05-30 19:25:06 +020037{
38 dictitem_T *di;
39 char_u *val;
40 char_u *s;
41 char_u *endp;
42 int n = 0;
43
44 di = dict_find(dict, key, -1);
45 if (di == NULL)
46 return 0;
47
48 val = tv_get_string(&di->di_tv);
49 if (STRNCMP(val, "cursor", 6) != 0)
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +020050 return dict_get_number_check(dict, key);
Bram Moolenaarcc31ad92019-05-30 19:25:06 +020051
52 setcursor_mayforce(TRUE);
53 s = val + 6;
54 if (*s != NUL)
55 {
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +020056 endp = s;
57 if (*skipwhite(s) == '+' || *skipwhite(s) == '-')
58 n = strtol((char *)s, (char **)&endp, 10);
Bram Moolenaarcc31ad92019-05-30 19:25:06 +020059 if (endp != NULL && *skipwhite(endp) != NUL)
60 {
61 semsg(_(e_invexpr2), val);
62 return 0;
63 }
64 }
65
66 if (STRCMP(key, "line") == 0)
67 n = screen_screenrow() + 1 + n;
68 else // "col"
69 n = screen_screencol() + 1 + n;
70
71 if (n < 1)
72 n = 1;
73 return n;
74}
75
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +020076 static void
77get_pos_options(win_T *wp, dict_T *dict)
78{
79 char_u *str;
80 int nr;
81
82 nr = popup_options_one(dict, (char_u *)"line");
83 if (nr > 0)
84 wp->w_wantline = nr;
85 nr = popup_options_one(dict, (char_u *)"col");
86 if (nr > 0)
87 wp->w_wantcol = nr;
88
Bram Moolenaar042fb4b2019-06-02 14:49:56 +020089 wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0;
90
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +020091 str = dict_get_string(dict, (char_u *)"pos", FALSE);
92 if (str != NULL)
93 {
94 for (nr = 0;
95 nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
96 ++nr)
97 if (STRCMP(str, poppos_entries[nr].pp_name) == 0)
98 {
99 wp->w_popup_pos = poppos_entries[nr].pp_val;
100 nr = -1;
101 break;
102 }
103 if (nr != -1)
104 semsg(_(e_invarg2), str);
105 }
106}
107
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200108 static void
109get_padding_border(dict_T *dict, int *array, char *name, int max_val)
110{
111 dictitem_T *di;
112
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200113 di = dict_find(dict, (char_u *)name, -1);
114 if (di != NULL)
115 {
116 if (di->di_tv.v_type != VAR_LIST)
117 emsg(_(e_listreq));
118 else
119 {
120 list_T *list = di->di_tv.vval.v_list;
121 listitem_T *li;
122 int i;
123 int nr;
124
125 for (i = 0; i < 4; ++i)
126 array[i] = 1;
127 if (list != NULL)
128 for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len;
129 ++i, li = li->li_next)
130 {
131 nr = (int)tv_get_number(&li->li_tv);
132 if (nr >= 0)
133 array[i] = nr > max_val ? max_val : nr;
134 }
135 }
136 }
137}
138
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200139/*
Bram Moolenaar17627312019-06-02 19:53:44 +0200140 * Used when popup options contain "moved": set default moved values.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200141 */
142 static void
Bram Moolenaar17627312019-06-02 19:53:44 +0200143set_moved_values(win_T *wp)
144{
145 wp->w_popup_curwin = curwin;
146 wp->w_popup_lnum = curwin->w_cursor.lnum;
147 wp->w_popup_mincol = curwin->w_cursor.col;
148 wp->w_popup_maxcol = curwin->w_cursor.col;
149}
150
151/*
152 * Used when popup options contain "moved" with "word" or "WORD".
153 */
154 static void
155set_moved_columns(win_T *wp, int flags)
156{
157 char_u *ptr;
158 int len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR);
159
160 if (len > 0)
161 {
162 wp->w_popup_mincol = (int)(ptr - ml_get_curline());
163 wp->w_popup_maxcol = wp->w_popup_mincol + len - 1;
164 }
165}
166
Bram Moolenaarb53fb312019-06-13 23:59:52 +0200167/*
168 * Return TRUE if "row"/"col" is on the border of the popup.
169 * The values are relative to the top-left corner.
170 */
171 int
172popup_on_border(win_T *wp, int row, int col)
173{
174 return (row == 0 && wp->w_popup_border[0] > 0)
175 || (row == popup_height(wp) - 1 && wp->w_popup_border[2] > 0)
176 || (col == 0 && wp->w_popup_border[3] > 0)
177 || (col == popup_width(wp) - 1 && wp->w_popup_border[1] > 0);
178}
179
180// Values set when dragging a popup window starts.
181static int drag_start_row;
182static int drag_start_col;
183static int drag_start_wantline;
184static int drag_start_wantcol;
185
186/*
187 * Mouse down on border of popup window: start dragging it.
188 * Uses mouse_col and mouse_row.
189 */
190 void
191popup_start_drag(win_T *wp)
192{
193 drag_start_row = mouse_row;
194 drag_start_col = mouse_col;
195 // TODO: handle using different corner
196 if (wp->w_wantline == 0)
197 drag_start_wantline = wp->w_winrow + 1;
198 else
199 drag_start_wantline = wp->w_wantline;
200 if (wp->w_wantcol == 0)
201 drag_start_wantcol = wp->w_wincol + 1;
202 else
203 drag_start_wantcol = wp->w_wantcol;
204}
205
206/*
207 * Mouse moved while dragging a popup window: adjust the window popup position.
208 */
209 void
210popup_drag(win_T *wp)
211{
212 // The popup may be closed before dragging stops.
213 if (!win_valid_popup(wp))
214 return;
215
216 wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row);
217 if (wp->w_wantline < 1)
218 wp->w_wantline = 1;
219 if (wp->w_wantline > Rows)
220 wp->w_wantline = Rows;
221 wp->w_wantcol = drag_start_wantcol + (mouse_col - drag_start_col);
222 if (wp->w_wantcol < 1)
223 wp->w_wantcol = 1;
224 if (wp->w_wantcol > Columns)
225 wp->w_wantcol = Columns;
226
227 popup_adjust_position(wp);
228}
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200229
230#if defined(FEAT_TIMERS)
231 static void
232popup_add_timeout(win_T *wp, int time)
233{
234 char_u cbbuf[50];
235 char_u *ptr = cbbuf;
236 typval_T tv;
237
238 vim_snprintf((char *)cbbuf, sizeof(cbbuf),
239 "{_ -> popup_close(%d)}", wp->w_id);
240 if (get_lambda_tv(&ptr, &tv, TRUE) == OK)
241 {
242 wp->w_popup_timer = create_timer(time, 0);
243 wp->w_popup_timer->tr_callback = get_callback(&tv);
244 clear_tv(&tv);
245 }
246}
247#endif
248
Bram Moolenaar17627312019-06-02 19:53:44 +0200249/*
250 * Go through the options in "dict" and apply them to buffer "buf" displayed in
251 * popup window "wp".
252 */
253 static void
254apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict)
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200255{
Bram Moolenaar402502d2019-05-30 22:07:36 +0200256 int nr;
257 char_u *str;
258 dictitem_T *di;
Bram Moolenaar790498b2019-06-01 22:15:29 +0200259 int i;
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200260
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200261 wp->w_minwidth = dict_get_number(dict, (char_u *)"minwidth");
262 wp->w_minheight = dict_get_number(dict, (char_u *)"minheight");
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200263 wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth");
264 wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight");
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200265
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200266 get_pos_options(wp, dict);
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200267
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200268 di = dict_find(dict, (char_u *)"zindex", -1);
269 if (di != NULL)
270 {
271 wp->w_zindex = dict_get_number(dict, (char_u *)"zindex");
272 if (wp->w_zindex < 1)
273 wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX;
274 if (wp->w_zindex > 32000)
275 wp->w_zindex = 32000;
276 }
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200277
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200278#if defined(FEAT_TIMERS)
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200279 // Add timer to close the popup after some time.
280 nr = dict_get_number(dict, (char_u *)"time");
281 if (nr > 0)
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200282 popup_add_timeout(wp, nr);
283#endif
Bram Moolenaar51fe3b12019-05-26 20:10:06 +0200284
Bram Moolenaar402502d2019-05-30 22:07:36 +0200285 // Option values resulting in setting an option.
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200286 str = dict_get_string(dict, (char_u *)"highlight", FALSE);
Bram Moolenaar20c023a2019-05-26 21:03:24 +0200287 if (str != NULL)
288 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
289 str, OPT_FREE|OPT_LOCAL, 0);
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200290
Bram Moolenaar8d241042019-06-12 23:40:01 +0200291 wp->w_firstline = dict_get_number(dict, (char_u *)"firstline");
292 if (wp->w_firstline < 1)
293 wp->w_firstline = 1;
294
Bram Moolenaar402502d2019-05-30 22:07:36 +0200295 di = dict_find(dict, (char_u *)"wrap", -1);
296 if (di != NULL)
297 {
298 nr = dict_get_number(dict, (char_u *)"wrap");
299 wp->w_p_wrap = nr != 0;
300 }
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200301
Bram Moolenaarb53fb312019-06-13 23:59:52 +0200302 wp->w_popup_drag = dict_get_number(dict, (char_u *)"drag");
303
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200304 di = dict_find(dict, (char_u *)"callback", -1);
305 if (di != NULL)
306 {
307 callback_T callback = get_callback(&di->di_tv);
308
309 if (callback.cb_name != NULL)
310 set_callback(&wp->w_close_cb, &callback);
311 }
312
Bram Moolenaarbf0eff02019-06-01 17:13:36 +0200313 di = dict_find(dict, (char_u *)"filter", -1);
314 if (di != NULL)
315 {
316 callback_T callback = get_callback(&di->di_tv);
317
318 if (callback.cb_name != NULL)
319 set_callback(&wp->w_filter_cb, &callback);
320 }
Bram Moolenaar2fd8e352019-06-01 20:16:48 +0200321
322 get_padding_border(dict, wp->w_popup_padding, "padding", 999);
323 get_padding_border(dict, wp->w_popup_border, "border", 1);
Bram Moolenaar790498b2019-06-01 22:15:29 +0200324
325 for (i = 0; i < 4; ++i)
326 VIM_CLEAR(wp->w_border_highlight[i]);
327 di = dict_find(dict, (char_u *)"borderhighlight", -1);
328 if (di != NULL)
329 {
330 if (di->di_tv.v_type != VAR_LIST)
331 emsg(_(e_listreq));
332 else
333 {
334 list_T *list = di->di_tv.vval.v_list;
335 listitem_T *li;
336
337 if (list != NULL)
338 for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len;
339 ++i, li = li->li_next)
340 {
341 str = tv_get_string(&li->li_tv);
342 if (*str != NUL)
343 wp->w_border_highlight[i] = vim_strsave(str);
344 }
345 if (list->lv_len == 1 && wp->w_border_highlight[0] != NULL)
346 for (i = 1; i < 4; ++i)
347 wp->w_border_highlight[i] =
348 vim_strsave(wp->w_border_highlight[0]);
349 }
350 }
351
352 for (i = 0; i < 8; ++i)
353 wp->w_border_char[i] = 0;
354 di = dict_find(dict, (char_u *)"borderchars", -1);
355 if (di != NULL)
356 {
357 if (di->di_tv.v_type != VAR_LIST)
358 emsg(_(e_listreq));
359 else
360 {
361 list_T *list = di->di_tv.vval.v_list;
362 listitem_T *li;
363
364 if (list != NULL)
365 for (i = 0, li = list->lv_first; i < 8 && i < list->lv_len;
366 ++i, li = li->li_next)
367 {
368 str = tv_get_string(&li->li_tv);
369 if (*str != NUL)
370 wp->w_border_char[i] = mb_ptr2char(str);
371 }
372 if (list->lv_len == 1)
373 for (i = 1; i < 8; ++i)
374 wp->w_border_char[i] = wp->w_border_char[0];
375 if (list->lv_len == 2)
376 {
377 for (i = 4; i < 8; ++i)
378 wp->w_border_char[i] = wp->w_border_char[1];
379 for (i = 1; i < 4; ++i)
380 wp->w_border_char[i] = wp->w_border_char[0];
381 }
382 }
383 }
Bram Moolenaar3397f742019-06-02 18:40:06 +0200384
385 di = dict_find(dict, (char_u *)"moved", -1);
386 if (di != NULL)
387 {
Bram Moolenaar17627312019-06-02 19:53:44 +0200388 set_moved_values(wp);
Bram Moolenaar3397f742019-06-02 18:40:06 +0200389 if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
390 {
391 char_u *s = di->di_tv.vval.v_string;
392 int flags = 0;
393
394 if (STRCMP(s, "word") == 0)
395 flags = FIND_IDENT | FIND_STRING;
396 else if (STRCMP(s, "WORD") == 0)
397 flags = FIND_STRING;
398 else if (STRCMP(s, "any") != 0)
399 semsg(_(e_invarg2), s);
400 if (flags != 0)
Bram Moolenaar17627312019-06-02 19:53:44 +0200401 set_moved_columns(wp, flags);
Bram Moolenaar3397f742019-06-02 18:40:06 +0200402 }
403 else if (di->di_tv.v_type == VAR_LIST
404 && di->di_tv.vval.v_list != NULL
405 && di->di_tv.vval.v_list->lv_len == 2)
406 {
407 list_T *l = di->di_tv.vval.v_list;
408
409 wp->w_popup_mincol = tv_get_number(&l->lv_first->li_tv);
410 wp->w_popup_maxcol = tv_get_number(&l->lv_first->li_next->li_tv);
411 }
412 else
413 semsg(_(e_invarg2), tv_get_string(&di->di_tv));
414 }
Bram Moolenaar33796b32019-06-08 16:01:13 +0200415
416 popup_mask_refresh = TRUE;
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200417}
418
419/*
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200420 * Add lines to the popup from a list of strings.
421 */
422 static void
423add_popup_strings(buf_T *buf, list_T *l)
424{
425 listitem_T *li;
426 linenr_T lnum = 0;
427 char_u *p;
428
429 for (li = l->lv_first; li != NULL; li = li->li_next)
430 if (li->li_tv.v_type == VAR_STRING)
431 {
432 p = li->li_tv.vval.v_string;
433 ml_append_buf(buf, lnum++,
434 p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE);
435 }
436}
437
438/*
439 * Add lines to the popup from a list of dictionaries.
440 */
441 static void
442add_popup_dicts(buf_T *buf, list_T *l)
443{
444 listitem_T *li;
445 listitem_T *pli;
446 linenr_T lnum = 0;
447 char_u *p;
448 dict_T *dict;
449
450 // first add the text lines
451 for (li = l->lv_first; li != NULL; li = li->li_next)
452 {
453 if (li->li_tv.v_type != VAR_DICT)
454 {
455 emsg(_(e_dictreq));
456 return;
457 }
458 dict = li->li_tv.vval.v_dict;
459 p = dict == NULL ? NULL
460 : dict_get_string(dict, (char_u *)"text", FALSE);
461 ml_append_buf(buf, lnum++,
462 p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE);
463 }
464
465 // add the text properties
466 lnum = 1;
467 for (li = l->lv_first; li != NULL; li = li->li_next, ++lnum)
468 {
469 dictitem_T *di;
470 list_T *plist;
471
472 dict = li->li_tv.vval.v_dict;
473 di = dict_find(dict, (char_u *)"props", -1);
474 if (di != NULL)
475 {
476 if (di->di_tv.v_type != VAR_LIST)
477 {
478 emsg(_(e_listreq));
479 return;
480 }
481 plist = di->di_tv.vval.v_list;
482 if (plist != NULL)
483 {
484 for (pli = plist->lv_first; pli != NULL; pli = pli->li_next)
485 {
486 if (pli->li_tv.v_type != VAR_DICT)
487 {
488 emsg(_(e_dictreq));
489 return;
490 }
491 dict = pli->li_tv.vval.v_dict;
492 if (dict != NULL)
493 {
494 int col = dict_get_number(dict, (char_u *)"col");
495
496 prop_add_common( lnum, col, dict, buf, NULL);
497 }
498 }
499 }
500 }
501 }
502}
503
504/*
Bram Moolenaar451d4b52019-06-12 20:22:27 +0200505 * Return the height of popup window "wp", including border and padding.
506 */
507 int
508popup_height(win_T *wp)
509{
510 return wp->w_height
511 + wp->w_popup_padding[0] + wp->w_popup_border[0]
512 + wp->w_popup_padding[2] + wp->w_popup_border[2];
513}
514
515/*
516 * Return the width of popup window "wp", including border and padding.
517 */
518 int
519popup_width(win_T *wp)
520{
521 return wp->w_width
522 + wp->w_popup_padding[3] + wp->w_popup_border[3]
523 + wp->w_popup_padding[1] + wp->w_popup_border[1];
524}
525
526/*
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200527 * Adjust the position and size of the popup to fit on the screen.
528 */
Bram Moolenaar17146962019-05-30 00:12:11 +0200529 void
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200530popup_adjust_position(win_T *wp)
531{
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200532 linenr_T lnum;
533 int wrapped = 0;
534 int maxwidth;
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200535 int center_vert = FALSE;
536 int center_hor = FALSE;
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200537 int allow_adjust_left = !wp->w_popup_fixed;
Bram Moolenaar399d8982019-06-02 15:34:29 +0200538 int top_extra = wp->w_popup_border[0] + wp->w_popup_padding[0];
539 int right_extra = wp->w_popup_border[1] + wp->w_popup_padding[1];
540 int bot_extra = wp->w_popup_border[2] + wp->w_popup_padding[2];
541 int left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3];
542 int extra_height = top_extra + bot_extra;
543 int extra_width = left_extra + right_extra;
Bram Moolenaar33796b32019-06-08 16:01:13 +0200544 int org_winrow = wp->w_winrow;
545 int org_wincol = wp->w_wincol;
546 int org_width = wp->w_width;
547 int org_height = wp->w_height;
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200548
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200549 wp->w_winrow = 0;
550 wp->w_wincol = 0;
551 if (wp->w_popup_pos == POPPOS_CENTER)
552 {
553 // center after computing the size
554 center_vert = TRUE;
555 center_hor = TRUE;
556 }
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200557 else
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200558 {
559 if (wp->w_wantline == 0)
560 center_vert = TRUE;
561 else if (wp->w_popup_pos == POPPOS_TOPLEFT
562 || wp->w_popup_pos == POPPOS_TOPRIGHT)
563 {
564 wp->w_winrow = wp->w_wantline - 1;
565 if (wp->w_winrow >= Rows)
566 wp->w_winrow = Rows - 1;
567 }
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200568
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200569 if (wp->w_wantcol == 0)
570 center_hor = TRUE;
571 else if (wp->w_popup_pos == POPPOS_TOPLEFT
572 || wp->w_popup_pos == POPPOS_BOTLEFT)
573 {
574 wp->w_wincol = wp->w_wantcol - 1;
575 if (wp->w_wincol >= Columns - 3)
576 wp->w_wincol = Columns - 3;
577 }
578 }
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200579
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200580 // When centering or right aligned, use maximum width.
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200581 // When left aligned use the space available, but shift to the left when we
582 // hit the right of the screen.
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200583 maxwidth = Columns - wp->w_wincol;
584 if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth)
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200585 {
586 allow_adjust_left = FALSE;
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200587 maxwidth = wp->w_maxwidth;
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200588 }
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200589
Bram Moolenaar8d241042019-06-12 23:40:01 +0200590 // start at the desired first line
591 wp->w_topline = wp->w_firstline;
592 if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count)
593 wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
594
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200595 // Compute width based on longest text line and the 'wrap' option.
596 // TODO: more accurate wrapping
597 wp->w_width = 0;
Bram Moolenaar8d241042019-06-12 23:40:01 +0200598 for (lnum = wp->w_topline; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200599 {
600 int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE));
601
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200602 if (wp->w_p_wrap)
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200603 {
Bram Moolenaar042fb4b2019-06-02 14:49:56 +0200604 while (len > maxwidth)
605 {
606 ++wrapped;
607 len -= maxwidth;
608 wp->w_width = maxwidth;
609 }
610 }
611 else if (len > maxwidth
612 && allow_adjust_left
613 && (wp->w_popup_pos == POPPOS_TOPLEFT
614 || wp->w_popup_pos == POPPOS_BOTLEFT))
615 {
616 // adjust leftwise to fit text on screen
617 int shift_by = ( len - maxwidth );
618
619 if ( shift_by > wp->w_wincol )
620 {
621 int truncate_shift = shift_by - wp->w_wincol;
622 len -= truncate_shift;
623 shift_by -= truncate_shift;
624 }
625
626 wp->w_wincol -= shift_by;
627 maxwidth += shift_by;
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200628 wp->w_width = maxwidth;
629 }
630 if (wp->w_width < len)
631 wp->w_width = len;
Bram Moolenaar8d241042019-06-12 23:40:01 +0200632 // do not use the width of lines we're not going to show
633 if (wp->w_maxheight > 0 && wp->w_buffer->b_ml.ml_line_count
634 - wp->w_topline + 1 + wrapped > wp->w_maxheight)
635 break;
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200636 }
637
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200638 if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth)
639 wp->w_width = wp->w_minwidth;
Bram Moolenaar88c4e1f2019-05-29 23:14:28 +0200640 if (wp->w_width > maxwidth)
641 wp->w_width = maxwidth;
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200642 if (center_hor)
643 wp->w_wincol = (Columns - wp->w_width) / 2;
644 else if (wp->w_popup_pos == POPPOS_BOTRIGHT
645 || wp->w_popup_pos == POPPOS_TOPRIGHT)
646 {
647 // Right aligned: move to the right if needed.
648 // No truncation, because that would change the height.
Bram Moolenaar399d8982019-06-02 15:34:29 +0200649 if (wp->w_width + extra_width < wp->w_wantcol)
650 wp->w_wincol = wp->w_wantcol - (wp->w_width + extra_width);
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200651 }
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200652
Bram Moolenaar8d241042019-06-12 23:40:01 +0200653 wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline
654 + 1 + wrapped;
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200655 if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight)
656 wp->w_height = wp->w_minheight;
657 if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight)
658 wp->w_height = wp->w_maxheight;
659 if (wp->w_height > Rows - wp->w_winrow)
660 wp->w_height = Rows - wp->w_winrow;
Bram Moolenaar17146962019-05-30 00:12:11 +0200661
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200662 if (center_vert)
663 wp->w_winrow = (Rows - wp->w_height) / 2;
664 else if (wp->w_popup_pos == POPPOS_BOTRIGHT
665 || wp->w_popup_pos == POPPOS_BOTLEFT)
666 {
Bram Moolenaar399d8982019-06-02 15:34:29 +0200667 if ((wp->w_height + extra_height) <= wp->w_wantline)
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200668 // bottom aligned: may move down
Bram Moolenaar399d8982019-06-02 15:34:29 +0200669 wp->w_winrow = wp->w_wantline - (wp->w_height + extra_height);
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200670 else
671 // not enough space, make top aligned
672 wp->w_winrow = wp->w_wantline + 1;
673 }
674
Bram Moolenaar17146962019-05-30 00:12:11 +0200675 wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer);
Bram Moolenaar33796b32019-06-08 16:01:13 +0200676
677 // Need to update popup_mask if the position or size changed.
Bram Moolenaaracc682b2019-06-08 17:15:51 +0200678 // And redraw windows that were behind the popup.
Bram Moolenaar33796b32019-06-08 16:01:13 +0200679 if (org_winrow != wp->w_winrow
680 || org_wincol != wp->w_wincol
681 || org_width != wp->w_width
682 || org_height != wp->w_height)
683 {
Bram Moolenaar4c063a02019-06-10 21:24:12 +0200684 redraw_all_later(VALID);
Bram Moolenaar33796b32019-06-08 16:01:13 +0200685 popup_mask_refresh = TRUE;
686 }
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200687}
688
Bram Moolenaar17627312019-06-02 19:53:44 +0200689typedef enum
690{
691 TYPE_NORMAL,
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200692 TYPE_ATCURSOR,
693 TYPE_NOTIFICATION
Bram Moolenaar17627312019-06-02 19:53:44 +0200694} create_type_T;
695
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200696/*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200697 * popup_create({text}, {options})
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200698 * popup_atcursor({text}, {options})
Bram Moolenaar33796b32019-06-08 16:01:13 +0200699 * When called from f_popup_atcursor() "type" is TYPE_ATCURSOR.
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200700 */
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200701 static void
Bram Moolenaar17627312019-06-02 19:53:44 +0200702popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200703{
704 win_T *wp;
705 buf_T *buf;
706 dict_T *d;
707 int nr;
708
709 // Check arguments look OK.
Bram Moolenaar7b29dd82019-06-02 13:22:11 +0200710 if (!(argvars[0].v_type == VAR_STRING && argvars[0].vval.v_string != NULL)
711 && !(argvars[0].v_type == VAR_LIST && argvars[0].vval.v_list != NULL))
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200712 {
713 emsg(_(e_listreq));
714 return;
715 }
716 if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL)
717 {
718 emsg(_(e_dictreq));
719 return;
720 }
721 d = argvars[1].vval.v_dict;
722
723 // Create the window and buffer.
724 wp = win_alloc_popup_win();
725 if (wp == NULL)
726 return;
727 rettv->vval.v_number = wp->w_id;
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200728 wp->w_popup_pos = POPPOS_TOPLEFT;
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200729
730 buf = buflist_new(NULL, NULL, (linenr_T)0, BLN_NEW|BLN_LISTED|BLN_DUMMY);
731 if (buf == NULL)
732 return;
733 ml_open(buf);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +0200734
735 win_init_popup_win(wp, buf);
736
737 set_local_options_default(wp);
Bram Moolenaar20c023a2019-05-26 21:03:24 +0200738 set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1,
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200739 (char_u *)"popup", OPT_FREE|OPT_LOCAL, 0);
Bram Moolenaar20c023a2019-05-26 21:03:24 +0200740 set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1,
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200741 (char_u *)"hide", OPT_FREE|OPT_LOCAL, 0);
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200742 buf->b_p_ul = -1; // no undo
743 buf->b_p_swf = FALSE; // no swap file
744 buf->b_p_bl = FALSE; // unlisted buffer
Bram Moolenaar868b7b62019-05-29 21:44:40 +0200745 buf->b_locked = TRUE;
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +0200746 wp->w_p_wrap = TRUE; // 'wrap' is default on
747
Bram Moolenaar54fabd42019-05-30 19:03:22 +0200748 // Avoid that 'buftype' is reset when this buffer is entered.
749 buf->b_p_initialized = TRUE;
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200750
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200751 if (dict_find(d, (char_u *)"tab", -1) != NULL)
752 nr = (int)dict_get_number(d, (char_u *)"tab");
753 else if (type == TYPE_NOTIFICATION)
754 nr = -1; // notifications are global by default
755 else
756 nr = 0;
757
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200758 if (nr == 0)
759 {
760 // popup on current tab
Bram Moolenaar9c27b1c2019-05-26 18:48:13 +0200761 wp->w_next = curtab->tp_first_popupwin;
762 curtab->tp_first_popupwin = wp;
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200763 }
764 else if (nr < 0)
765 {
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200766 win_T *prev = first_popupwin;
767
768 // Global popup: add at the end, so that it gets displayed on top of
769 // older ones with the same zindex. Matters for notifications.
770 if (first_popupwin == NULL)
771 first_popupwin = wp;
772 else
773 {
774 while (prev->w_next != NULL)
775 prev = prev->w_next;
776 prev->w_next = wp;
777 }
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200778 }
779 else
780 // TODO: find tab page "nr"
781 emsg("Not implemented yet");
782
783 // Add text to the buffer.
784 if (argvars[0].v_type == VAR_STRING)
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200785 {
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200786 // just a string
787 ml_append_buf(buf, 0, argvars[0].vval.v_string, (colnr_T)0, TRUE);
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200788 }
789 else
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200790 {
791 list_T *l = argvars[0].vval.v_list;
792
Bram Moolenaar7b29dd82019-06-02 13:22:11 +0200793 if (l->lv_len > 0)
794 {
795 if (l->lv_first->li_tv.v_type == VAR_STRING)
796 // list of strings
797 add_popup_strings(buf, l);
798 else
799 // list of dictionaries
800 add_popup_dicts(buf, l);
801 }
Bram Moolenaar7a8d0272019-05-26 23:32:06 +0200802 }
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200803
804 // Delete the line of the empty buffer.
805 curbuf = buf;
806 ml_delete(buf->b_ml.ml_line_count, FALSE);
807 curbuf = curwin->w_buffer;
808
Bram Moolenaar17627312019-06-02 19:53:44 +0200809 if (type == TYPE_ATCURSOR)
810 {
811 wp->w_popup_pos = POPPOS_BOTLEFT;
812 setcursor_mayforce(TRUE);
813 wp->w_wantline = screen_screenrow();
814 if (wp->w_wantline == 0) // cursor in first line
815 {
816 wp->w_wantline = 2;
817 wp->w_popup_pos = POPPOS_TOPLEFT;
818 }
819 wp->w_wantcol = screen_screencol() + 1;
820 set_moved_values(wp);
821 set_moved_columns(wp, FIND_STRING);
822 }
823
Bram Moolenaar33796b32019-06-08 16:01:13 +0200824 // set default values
825 wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX;
826
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200827 if (type == TYPE_NOTIFICATION)
828 {
829 win_T *twp, *nextwin;
830 int height = buf->b_ml.ml_line_count + 3;
831 int i;
832
833 // Try to not overlap with another global popup. Guess we need 3
834 // more screen lines than buffer lines.
835 wp->w_wantline = 1;
836 for (twp = first_popupwin; twp != NULL; twp = nextwin)
837 {
838 nextwin = twp->w_next;
839 if (twp != wp
840 && twp->w_zindex == POPUPWIN_NOTIFICATION_ZINDEX
841 && twp->w_winrow <= wp->w_wantline - 1 + height
842 && twp->w_winrow + popup_height(twp) > wp->w_wantline - 1)
843 {
844 // move to below this popup and restart the loop to check for
845 // overlap with other popups
846 wp->w_wantline = twp->w_winrow + popup_height(twp) + 1;
847 nextwin = first_popupwin;
848 }
849 }
850 if (wp->w_wantline + height > Rows)
851 {
852 // can't avoid overlap, put on top in the hope that message goes
853 // away soon.
854 wp->w_wantline = 1;
855 }
856
857 wp->w_wantcol = 10;
858 wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX;
859 for (i = 0; i < 4; ++i)
860 wp->w_popup_border[i] = 1;
861 wp->w_popup_padding[1] = 1;
862 wp->w_popup_padding[3] = 1;
863 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
864 (char_u *)"WarningMsg", OPT_FREE|OPT_LOCAL, 0);
Bram Moolenaarb53fb312019-06-13 23:59:52 +0200865 wp->w_popup_drag = 1;
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200866 }
867
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200868 // Deal with options.
Bram Moolenaar17627312019-06-02 19:53:44 +0200869 apply_options(wp, buf, argvars[1].vval.v_dict);
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200870
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200871 if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL)
872 popup_add_timeout(wp, 3000);
873
Bram Moolenaar60cdb302019-05-27 21:54:10 +0200874 popup_adjust_position(wp);
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200875
876 wp->w_vsep_width = 0;
877
878 redraw_all_later(NOT_VALID);
Bram Moolenaar33796b32019-06-08 16:01:13 +0200879 popup_mask_refresh = TRUE;
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200880}
881
882/*
Bram Moolenaar3ff5f0f2019-06-10 13:11:22 +0200883 * popup_clear()
884 */
885 void
886f_popup_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
887{
888 close_all_popups();
889}
890
891/*
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200892 * popup_create({text}, {options})
893 */
894 void
895f_popup_create(typval_T *argvars, typval_T *rettv)
896{
Bram Moolenaar17627312019-06-02 19:53:44 +0200897 popup_create(argvars, rettv, TYPE_NORMAL);
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200898}
899
900/*
901 * popup_atcursor({text}, {options})
902 */
903 void
904f_popup_atcursor(typval_T *argvars, typval_T *rettv)
905{
Bram Moolenaar17627312019-06-02 19:53:44 +0200906 popup_create(argvars, rettv, TYPE_ATCURSOR);
Bram Moolenaarcc31ad92019-05-30 19:25:06 +0200907}
908
909/*
Bram Moolenaar68d48f42019-06-12 22:42:41 +0200910 * popup_notification({text}, {options})
911 */
912 void
913f_popup_notification(typval_T *argvars, typval_T *rettv)
914{
915 popup_create(argvars, rettv, TYPE_NOTIFICATION);
916}
917
918/*
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200919 * Find the popup window with window-ID "id".
920 * If the popup window does not exist NULL is returned.
921 * If the window is not a popup window, and error message is given.
922 */
923 static win_T *
924find_popup_win(int id)
925{
926 win_T *wp = win_id2wp(id);
927
928 if (wp != NULL && !bt_popup(wp->w_buffer))
929 {
930 semsg(_("E993: window %d is not a popup window"), id);
931 return NULL;
932 }
933 return wp;
934}
935
936/*
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200937 * Invoke the close callback for window "wp" with value "result".
938 * Careful: The callback may make "wp" invalid!
939 */
940 static void
941invoke_popup_callback(win_T *wp, typval_T *result)
942{
943 typval_T rettv;
944 int dummy;
945 typval_T argv[3];
946
947 argv[0].v_type = VAR_NUMBER;
948 argv[0].vval.v_number = (varnumber_T)wp->w_id;
949
950 if (result != NULL && result->v_type != VAR_UNKNOWN)
951 copy_tv(result, &argv[1]);
952 else
953 {
954 argv[1].v_type = VAR_NUMBER;
955 argv[1].vval.v_number = 0;
956 }
957
958 argv[2].v_type = VAR_UNKNOWN;
959
960 call_callback(&wp->w_close_cb, -1,
961 &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL);
962 if (result != NULL)
963 clear_tv(&argv[1]);
964 clear_tv(&rettv);
965}
966
967/*
Bram Moolenaar3397f742019-06-02 18:40:06 +0200968 * Close popup "wp" and invoke any close callback for it.
969 */
970 static void
971popup_close_and_callback(win_T *wp, typval_T *arg)
972{
973 int id = wp->w_id;
974
975 if (wp->w_close_cb.cb_name != NULL)
976 // Careful: This may make "wp" invalid.
977 invoke_popup_callback(wp, arg);
978
979 popup_close(id);
980}
981
982/*
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200983 * popup_close({id})
984 */
985 void
986f_popup_close(typval_T *argvars, typval_T *rettv UNUSED)
987{
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200988 int id = (int)tv_get_number(argvars);
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200989 win_T *wp = find_popup_win(id);
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200990
Bram Moolenaar9eaac892019-06-01 22:49:29 +0200991 if (wp != NULL)
Bram Moolenaar3397f742019-06-02 18:40:06 +0200992 popup_close_and_callback(wp, &argvars[1]);
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +0200993}
994
995/*
996 * popup_hide({id})
997 */
998 void
999f_popup_hide(typval_T *argvars, typval_T *rettv UNUSED)
1000{
1001 int id = (int)tv_get_number(argvars);
1002 win_T *wp = find_popup_win(id);
1003
Bram Moolenaarbf0ecb22019-05-27 10:04:40 +02001004 if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) == 0)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001005 {
Bram Moolenaarbf0ecb22019-05-27 10:04:40 +02001006 wp->w_popup_flags |= POPF_HIDDEN;
Bram Moolenaarc6896e22019-05-30 22:32:34 +02001007 --wp->w_buffer->b_nwindows;
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001008 redraw_all_later(NOT_VALID);
Bram Moolenaar33796b32019-06-08 16:01:13 +02001009 popup_mask_refresh = TRUE;
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001010 }
1011}
1012
1013/*
1014 * popup_show({id})
1015 */
1016 void
1017f_popup_show(typval_T *argvars, typval_T *rettv UNUSED)
1018{
1019 int id = (int)tv_get_number(argvars);
1020 win_T *wp = find_popup_win(id);
1021
Bram Moolenaarbf0ecb22019-05-27 10:04:40 +02001022 if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) != 0)
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001023 {
Bram Moolenaarbf0ecb22019-05-27 10:04:40 +02001024 wp->w_popup_flags &= ~POPF_HIDDEN;
Bram Moolenaarc6896e22019-05-30 22:32:34 +02001025 ++wp->w_buffer->b_nwindows;
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001026 redraw_all_later(NOT_VALID);
Bram Moolenaar33796b32019-06-08 16:01:13 +02001027 popup_mask_refresh = TRUE;
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001028 }
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001029}
1030
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001031 static void
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001032popup_free(win_T *wp)
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001033{
Bram Moolenaar868b7b62019-05-29 21:44:40 +02001034 wp->w_buffer->b_locked = FALSE;
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001035 if (wp->w_winrow + wp->w_height >= cmdline_row)
1036 clear_cmdline = TRUE;
1037 win_free_popup(wp);
1038 redraw_all_later(NOT_VALID);
Bram Moolenaar33796b32019-06-08 16:01:13 +02001039 popup_mask_refresh = TRUE;
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02001040}
1041
Bram Moolenaarec583842019-05-26 14:11:23 +02001042/*
1043 * Close a popup window by Window-id.
Bram Moolenaar9eaac892019-06-01 22:49:29 +02001044 * Does not invoke the callback.
Bram Moolenaarec583842019-05-26 14:11:23 +02001045 */
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001046 void
Bram Moolenaarec583842019-05-26 14:11:23 +02001047popup_close(int id)
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001048{
1049 win_T *wp;
Bram Moolenaarec583842019-05-26 14:11:23 +02001050 tabpage_T *tp;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001051 win_T *prev = NULL;
1052
Bram Moolenaarec583842019-05-26 14:11:23 +02001053 // go through global popups
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001054 for (wp = first_popupwin; wp != NULL; prev = wp, wp = wp->w_next)
Bram Moolenaarec583842019-05-26 14:11:23 +02001055 if (wp->w_id == id)
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001056 {
1057 if (prev == NULL)
1058 first_popupwin = wp->w_next;
1059 else
1060 prev->w_next = wp->w_next;
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001061 popup_free(wp);
Bram Moolenaarec583842019-05-26 14:11:23 +02001062 return;
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001063 }
1064
Bram Moolenaarec583842019-05-26 14:11:23 +02001065 // go through tab-local popups
1066 FOR_ALL_TABPAGES(tp)
1067 popup_close_tabpage(tp, id);
1068}
1069
1070/*
1071 * Close a popup window with Window-id "id" in tabpage "tp".
1072 */
1073 void
1074popup_close_tabpage(tabpage_T *tp, int id)
1075{
1076 win_T *wp;
Bram Moolenaar9c27b1c2019-05-26 18:48:13 +02001077 win_T **root = &tp->tp_first_popupwin;
Bram Moolenaarec583842019-05-26 14:11:23 +02001078 win_T *prev = NULL;
1079
Bram Moolenaarec583842019-05-26 14:11:23 +02001080 for (wp = *root; wp != NULL; prev = wp, wp = wp->w_next)
1081 if (wp->w_id == id)
1082 {
1083 if (prev == NULL)
1084 *root = wp->w_next;
1085 else
1086 prev->w_next = wp->w_next;
Bram Moolenaar2cd0dce2019-05-26 22:17:52 +02001087 popup_free(wp);
Bram Moolenaarec583842019-05-26 14:11:23 +02001088 return;
1089 }
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001090}
1091
1092 void
1093close_all_popups(void)
1094{
1095 while (first_popupwin != NULL)
1096 popup_close(first_popupwin->w_id);
Bram Moolenaar9c27b1c2019-05-26 18:48:13 +02001097 while (curtab->tp_first_popupwin != NULL)
1098 popup_close(curtab->tp_first_popupwin->w_id);
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001099}
1100
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001101/*
1102 * popup_move({id}, {options})
1103 */
1104 void
1105f_popup_move(typval_T *argvars, typval_T *rettv UNUSED)
1106{
1107 dict_T *d;
1108 int nr;
1109 int id = (int)tv_get_number(argvars);
1110 win_T *wp = find_popup_win(id);
1111
1112 if (wp == NULL)
1113 return; // invalid {id}
1114
1115 if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL)
1116 {
1117 emsg(_(e_dictreq));
1118 return;
1119 }
1120 d = argvars[1].vval.v_dict;
1121
1122 if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0)
1123 wp->w_minwidth = nr;
1124 if ((nr = dict_get_number(d, (char_u *)"minheight")) > 0)
1125 wp->w_minheight = nr;
1126 if ((nr = dict_get_number(d, (char_u *)"maxwidth")) > 0)
1127 wp->w_maxwidth = nr;
1128 if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0)
1129 wp->w_maxheight = nr;
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02001130 get_pos_options(wp, d);
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001131
1132 if (wp->w_winrow + wp->w_height >= cmdline_row)
1133 clear_cmdline = TRUE;
1134 popup_adjust_position(wp);
Bram Moolenaar60cdb302019-05-27 21:54:10 +02001135}
1136
Bram Moolenaarbc133542019-05-29 20:26:46 +02001137/*
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02001138 * popup_getpos({id})
Bram Moolenaarbc133542019-05-29 20:26:46 +02001139 */
1140 void
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02001141f_popup_getpos(typval_T *argvars, typval_T *rettv)
Bram Moolenaarbc133542019-05-29 20:26:46 +02001142{
1143 dict_T *dict;
1144 int id = (int)tv_get_number(argvars);
1145 win_T *wp = find_popup_win(id);
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001146 int top_extra;
1147 int left_extra;
Bram Moolenaarbc133542019-05-29 20:26:46 +02001148
1149 if (rettv_dict_alloc(rettv) == OK)
1150 {
1151 if (wp == NULL)
1152 return; // invalid {id}
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001153 top_extra = wp->w_popup_border[0] + wp->w_popup_padding[0];
1154 left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3];
1155
Bram Moolenaarbc133542019-05-29 20:26:46 +02001156 dict = rettv->vval.v_dict;
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001157
Bram Moolenaarbc133542019-05-29 20:26:46 +02001158 dict_add_number(dict, "line", wp->w_winrow + 1);
1159 dict_add_number(dict, "col", wp->w_wincol + 1);
Bram Moolenaar68d48f42019-06-12 22:42:41 +02001160 dict_add_number(dict, "width", wp->w_width + left_extra
1161 + wp->w_popup_border[1] + wp->w_popup_padding[1]);
1162 dict_add_number(dict, "height", wp->w_height + top_extra
1163 + wp->w_popup_border[2] + wp->w_popup_padding[2]);
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02001164
1165 dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra);
1166 dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra);
1167 dict_add_number(dict, "core_width", wp->w_width);
1168 dict_add_number(dict, "core_height", wp->w_height);
1169
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001170 dict_add_number(dict, "visible",
Bram Moolenaarb0ebbda2019-06-02 16:51:21 +02001171 win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0);
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001172 }
1173}
1174
1175/*
Bram Moolenaar33796b32019-06-08 16:01:13 +02001176 * popup_getoptions({id})
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001177 */
1178 void
1179f_popup_getoptions(typval_T *argvars, typval_T *rettv)
1180{
1181 dict_T *dict;
1182 int id = (int)tv_get_number(argvars);
1183 win_T *wp = find_popup_win(id);
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02001184 int i;
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001185
1186 if (rettv_dict_alloc(rettv) == OK)
1187 {
1188 if (wp == NULL)
1189 return;
1190
1191 dict = rettv->vval.v_dict;
1192 dict_add_number(dict, "line", wp->w_wantline);
1193 dict_add_number(dict, "col", wp->w_wantcol);
1194 dict_add_number(dict, "minwidth", wp->w_minwidth);
1195 dict_add_number(dict, "minheight", wp->w_minheight);
1196 dict_add_number(dict, "maxheight", wp->w_maxheight);
1197 dict_add_number(dict, "maxwidth", wp->w_maxwidth);
Bram Moolenaar8d241042019-06-12 23:40:01 +02001198 dict_add_number(dict, "firstline", wp->w_firstline);
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001199 dict_add_number(dict, "zindex", wp->w_zindex);
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02001200 dict_add_number(dict, "fixed", wp->w_popup_fixed);
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02001201
1202 for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
1203 ++i)
1204 if (wp->w_popup_pos == poppos_entries[i].pp_val)
1205 {
1206 dict_add_string(dict, "pos",
1207 (char_u *)poppos_entries[i].pp_name);
1208 break;
1209 }
1210
Bram Moolenaar8c2a6002019-05-30 14:29:45 +02001211# if defined(FEAT_TIMERS)
1212 dict_add_number(dict, "time", wp->w_popup_timer != NULL
1213 ? (long)wp->w_popup_timer->tr_interval : 0L);
1214# endif
Bram Moolenaarbc133542019-05-29 20:26:46 +02001215 }
1216}
Bram Moolenaar815b76b2019-06-01 14:15:52 +02001217
1218 int
1219not_in_popup_window()
1220{
1221 if (bt_popup(curwin->w_buffer))
1222 {
1223 emsg(_("E994: Not allowed in a popup window"));
1224 return TRUE;
1225 }
1226 return FALSE;
1227}
1228
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02001229/*
1230 * Reset all the POPF_HANDLED flags in global popup windows and popup windows
1231 * in the current tab.
1232 */
1233 void
1234popup_reset_handled()
1235{
1236 win_T *wp;
1237
1238 for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
1239 wp->w_popup_flags &= ~POPF_HANDLED;
1240 for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
1241 wp->w_popup_flags &= ~POPF_HANDLED;
1242}
1243
1244/*
1245 * Find the next visible popup where POPF_HANDLED is not set.
1246 * Must have called popup_reset_handled() first.
1247 * When "lowest" is TRUE find the popup with the lowest zindex, otherwise the
1248 * popup with the highest zindex.
1249 */
1250 win_T *
1251find_next_popup(int lowest)
1252{
1253 win_T *wp;
1254 win_T *found_wp;
1255 int found_zindex;
1256
1257 found_zindex = lowest ? INT_MAX : 0;
1258 found_wp = NULL;
1259 for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
1260 if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0
1261 && (lowest ? wp->w_zindex < found_zindex
1262 : wp->w_zindex > found_zindex))
1263 {
1264 found_zindex = wp->w_zindex;
1265 found_wp = wp;
1266 }
1267 for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
1268 if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0
1269 && (lowest ? wp->w_zindex < found_zindex
1270 : wp->w_zindex > found_zindex))
1271 {
1272 found_zindex = wp->w_zindex;
1273 found_wp = wp;
1274 }
1275
1276 if (found_wp != NULL)
1277 found_wp->w_popup_flags |= POPF_HANDLED;
1278 return found_wp;
1279}
1280
1281/*
1282 * Invoke the filter callback for window "wp" with typed character "c".
1283 * Uses the global "mod_mask" for modifiers.
1284 * Returns the return value of the filter.
1285 * Careful: The filter may make "wp" invalid!
1286 */
1287 static int
1288invoke_popup_filter(win_T *wp, int c)
1289{
1290 int res;
1291 typval_T rettv;
1292 int dummy;
1293 typval_T argv[3];
1294 char_u buf[NUMBUFLEN];
1295
1296 argv[0].v_type = VAR_NUMBER;
1297 argv[0].vval.v_number = (varnumber_T)wp->w_id;
1298
1299 // Convert the number to a string, so that the function can use:
1300 // if a:c == "\<F2>"
1301 buf[special_to_buf(c, mod_mask, TRUE, buf)] = NUL;
1302 argv[1].v_type = VAR_STRING;
1303 argv[1].vval.v_string = vim_strsave(buf);
1304
1305 argv[2].v_type = VAR_UNKNOWN;
1306
1307 call_callback(&wp->w_filter_cb, -1,
1308 &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL);
1309 res = tv_get_number(&rettv);
1310 vim_free(argv[1].vval.v_string);
1311 clear_tv(&rettv);
1312 return res;
1313}
1314
1315/*
1316 * Called when "c" was typed: invoke popup filter callbacks.
1317 * Returns TRUE when the character was consumed,
1318 */
1319 int
1320popup_do_filter(int c)
1321{
1322 int res = FALSE;
1323 win_T *wp;
1324
1325 popup_reset_handled();
1326
1327 while (!res && (wp = find_next_popup(FALSE)) != NULL)
1328 if (wp->w_filter_cb.cb_name != NULL)
1329 res = invoke_popup_filter(wp, c);
1330
1331 return res;
1332}
1333
Bram Moolenaar3397f742019-06-02 18:40:06 +02001334/*
1335 * Called when the cursor moved: check if any popup needs to be closed if the
1336 * cursor moved far enough.
1337 */
1338 void
1339popup_check_cursor_pos()
1340{
1341 win_T *wp;
1342 typval_T tv;
1343
1344 popup_reset_handled();
1345 while ((wp = find_next_popup(TRUE)) != NULL)
1346 if (wp->w_popup_curwin != NULL
1347 && (curwin != wp->w_popup_curwin
1348 || curwin->w_cursor.lnum != wp->w_popup_lnum
1349 || curwin->w_cursor.col < wp->w_popup_mincol
1350 || curwin->w_cursor.col > wp->w_popup_maxcol))
1351 {
1352 tv.v_type = VAR_NUMBER;
1353 tv.vval.v_number = -1;
1354 popup_close_and_callback(wp, &tv);
1355 }
1356}
1357
Bram Moolenaara540f8a2019-06-14 19:23:57 +02001358/*
1359 * Update "popup_mask" if needed.
1360 * Also recomputes the popup size and positions.
1361 * Also updates "popup_visible".
1362 * Also marks window lines for redrawing.
1363 */
1364 void
1365may_update_popup_mask(int type)
1366{
1367 win_T *wp;
1368 short *mask;
1369 int line, col;
1370 int redraw_all = FALSE;
1371
1372 // Need to recompute when switching tabs.
1373 // Also recompute when the type is CLEAR or NOT_VALID, something basic
1374 // (such as the screen size) must have changed.
1375 if (popup_mask_tab != curtab || type >= NOT_VALID)
1376 {
1377 popup_mask_refresh = TRUE;
1378 redraw_all = TRUE;
1379 }
1380 if (!popup_mask_refresh)
1381 {
1382 // Check if any buffer has changed.
1383 for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
1384 if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer))
1385 popup_mask_refresh = TRUE;
1386 for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
1387 if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer))
1388 popup_mask_refresh = TRUE;
1389 if (!popup_mask_refresh)
1390 return;
1391 }
1392
1393 // Need to update the mask, something has changed.
1394 popup_mask_refresh = FALSE;
1395 popup_mask_tab = curtab;
1396 popup_visible = FALSE;
1397
1398 // If redrawing everything, just update "popup_mask".
1399 // If redrawing only what is needed, update "popup_mask_next" and then
1400 // compare with "popup_mask" to see what changed.
1401 if (type >= SOME_VALID)
1402 mask = popup_mask;
1403 else
1404 mask = popup_mask_next;
1405 vim_memset(mask, 0, screen_Rows * screen_Columns * sizeof(short));
1406
1407 // Find the window with the lowest zindex that hasn't been handled yet,
1408 // so that the window with a higher zindex overwrites the value in
1409 // popup_mask.
1410 popup_reset_handled();
1411 while ((wp = find_next_popup(TRUE)) != NULL)
1412 {
1413 popup_visible = TRUE;
1414
1415 // Recompute the position if the text changed.
1416 if (redraw_all
1417 || wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer))
1418 popup_adjust_position(wp);
1419
1420 for (line = wp->w_winrow;
1421 line < wp->w_winrow + popup_height(wp)
1422 && line < screen_Rows; ++line)
1423 for (col = wp->w_wincol;
1424 col < wp->w_wincol + popup_width(wp)
1425 && col < screen_Columns; ++col)
1426 mask[line * screen_Columns + col] = wp->w_zindex;
1427 }
1428
1429 // Only check which lines are to be updated if not already
1430 // updating all lines.
1431 if (mask == popup_mask_next)
1432 for (line = 0; line < screen_Rows; ++line)
1433 {
1434 int col_done = 0;
1435
1436 for (col = 0; col < screen_Columns; ++col)
1437 {
1438 int off = line * screen_Columns + col;
1439
1440 if (popup_mask[off] != popup_mask_next[off])
1441 {
1442 popup_mask[off] = popup_mask_next[off];
1443
1444 if (line >= cmdline_row)
1445 {
1446 // the command line needs to be cleared if text below
1447 // the popup is now visible.
1448 if (!msg_scrolled && popup_mask_next[off] == 0)
1449 clear_cmdline = TRUE;
1450 }
1451 else if (col >= col_done)
1452 {
1453 linenr_T lnum;
1454 int line_cp = line;
1455 int col_cp = col;
1456
1457 // The screen position "line" / "col" needs to be
1458 // redrawn. Figure out what window that is and update
1459 // w_redraw_top and w_redr_bot. Only needs to be done
1460 // once for each window line.
1461 wp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP);
1462 if (wp != NULL)
1463 {
1464 if (line_cp >= wp->w_height)
1465 // In (or below) status line
1466 wp->w_redr_status = TRUE;
1467 // compute the position in the buffer line from the
1468 // position on the screen
1469 else if (mouse_comp_pos(wp, &line_cp, &col_cp,
1470 &lnum))
1471 // past bottom
1472 wp->w_redr_status = TRUE;
1473 else
1474 redrawWinline(wp, lnum);
1475
1476 // This line is going to be redrawn, no need to
1477 // check until the right side of the window.
1478 col_done = wp->w_wincol + wp->w_width - 1;
1479 }
1480 }
1481 }
1482 }
1483 }
1484}
1485
1486/*
1487 * Return a string of "len" spaces in IObuff.
1488 */
1489 static char_u *
1490get_spaces(int len)
1491{
1492 vim_memset(IObuff, ' ', (size_t)len);
1493 IObuff[len] = NUL;
1494 return IObuff;
1495}
1496
1497/*
1498 * Update popup windows. They are drawn on top of normal windows.
1499 * "win_update" is called for each popup window, lowest zindex first.
1500 */
1501 void
1502update_popups(void (*win_update)(win_T *wp))
1503{
1504 win_T *wp;
1505 int top_off;
1506 int left_off;
1507 int total_width;
1508 int total_height;
1509 int popup_attr;
1510 int border_attr[4];
1511 int border_char[8];
1512 char_u buf[MB_MAXBYTES];
1513 int row;
1514 int i;
1515
1516 // Find the window with the lowest zindex that hasn't been updated yet,
1517 // so that the window with a higher zindex is drawn later, thus goes on
1518 // top.
1519 popup_reset_handled();
1520 while ((wp = find_next_popup(TRUE)) != NULL)
1521 {
1522 // This drawing uses the zindex of the popup window, so that it's on
1523 // top of the text but doesn't draw when another popup with higher
1524 // zindex is on top of the character.
1525 screen_zindex = wp->w_zindex;
1526
1527 // adjust w_winrow and w_wincol for border and padding, since
1528 // win_update() doesn't handle them.
1529 top_off = wp->w_popup_padding[0] + wp->w_popup_border[0];
1530 left_off = wp->w_popup_padding[3] + wp->w_popup_border[3];
1531 wp->w_winrow += top_off;
1532 wp->w_wincol += left_off;
1533
1534 // Draw the popup text.
1535 win_update(wp);
1536
1537 wp->w_winrow -= top_off;
1538 wp->w_wincol -= left_off;
1539
1540 total_width = wp->w_popup_border[3] + wp->w_popup_padding[3]
1541 + wp->w_width + wp->w_popup_padding[1] + wp->w_popup_border[1];
1542 total_height = wp->w_popup_border[0] + wp->w_popup_padding[0]
1543 + wp->w_height + wp->w_popup_padding[2] + wp->w_popup_border[2];
1544 popup_attr = get_wcr_attr(wp);
1545
1546 // We can only use these line drawing characters when 'encoding' is
1547 // "utf-8" and 'ambiwidth' is "single".
1548 if (enc_utf8 && *p_ambw == 's')
1549 {
1550 border_char[0] = border_char[2] = 0x2550;
1551 border_char[1] = border_char[3] = 0x2551;
1552 border_char[4] = 0x2554;
1553 border_char[5] = 0x2557;
1554 border_char[6] = 0x255d;
1555 border_char[7] = 0x255a;
1556 }
1557 else
1558 {
1559 border_char[0] = border_char[2] = '-';
1560 border_char[1] = border_char[3] = '|';
1561 for (i = 4; i < 8; ++i)
1562 border_char[i] = '+';
1563 }
1564 for (i = 0; i < 8; ++i)
1565 if (wp->w_border_char[i] != 0)
1566 border_char[i] = wp->w_border_char[i];
1567
1568 for (i = 0; i < 4; ++i)
1569 {
1570 border_attr[i] = popup_attr;
1571 if (wp->w_border_highlight[i] != NULL)
1572 border_attr[i] = syn_name2attr(wp->w_border_highlight[i]);
1573 }
1574
1575 if (wp->w_popup_border[0] > 0)
1576 {
1577 // top border
1578 screen_fill(wp->w_winrow, wp->w_winrow + 1,
1579 wp->w_wincol,
1580 wp->w_wincol + total_width,
1581 wp->w_popup_border[3] != 0
1582 ? border_char[4] : border_char[0],
1583 border_char[0], border_attr[0]);
1584 if (wp->w_popup_border[1] > 0)
1585 {
1586 buf[mb_char2bytes(border_char[5], buf)] = NUL;
1587 screen_puts(buf, wp->w_winrow,
1588 wp->w_wincol + total_width - 1, border_attr[1]);
1589 }
1590 }
1591
1592 if (wp->w_popup_padding[0] > 0)
1593 {
1594 // top padding
1595 row = wp->w_winrow + wp->w_popup_border[0];
1596 screen_fill(row, row + wp->w_popup_padding[0],
1597 wp->w_wincol + wp->w_popup_border[3],
1598 wp->w_wincol + total_width - wp->w_popup_border[1],
1599 ' ', ' ', popup_attr);
1600 }
1601
1602 for (row = wp->w_winrow + wp->w_popup_border[0];
1603 row < wp->w_winrow + total_height - wp->w_popup_border[2];
1604 ++row)
1605 {
1606 // left border
1607 if (wp->w_popup_border[3] > 0)
1608 {
1609 buf[mb_char2bytes(border_char[3], buf)] = NUL;
1610 screen_puts(buf, row, wp->w_wincol, border_attr[3]);
1611 }
1612 // left padding
1613 if (wp->w_popup_padding[3] > 0)
1614 screen_puts(get_spaces(wp->w_popup_padding[3]), row,
1615 wp->w_wincol + wp->w_popup_border[3], popup_attr);
1616 // right border
1617 if (wp->w_popup_border[1] > 0)
1618 {
1619 buf[mb_char2bytes(border_char[1], buf)] = NUL;
1620 screen_puts(buf, row,
1621 wp->w_wincol + total_width - 1, border_attr[1]);
1622 }
1623 // right padding
1624 if (wp->w_popup_padding[1] > 0)
1625 screen_puts(get_spaces(wp->w_popup_padding[1]), row,
1626 wp->w_wincol + wp->w_popup_border[3]
1627 + wp->w_popup_padding[3] + wp->w_width, popup_attr);
1628 }
1629
1630 if (wp->w_popup_padding[2] > 0)
1631 {
1632 // bottom padding
1633 row = wp->w_winrow + wp->w_popup_border[0]
1634 + wp->w_popup_padding[0] + wp->w_height;
1635 screen_fill(row, row + wp->w_popup_padding[2],
1636 wp->w_wincol + wp->w_popup_border[3],
1637 wp->w_wincol + total_width - wp->w_popup_border[1],
1638 ' ', ' ', popup_attr);
1639 }
1640
1641 if (wp->w_popup_border[2] > 0)
1642 {
1643 // bottom border
1644 row = wp->w_winrow + total_height - 1;
1645 screen_fill(row , row + 1,
1646 wp->w_wincol,
1647 wp->w_wincol + total_width,
1648 wp->w_popup_border[3] != 0
1649 ? border_char[7] : border_char[2],
1650 border_char[2], border_attr[2]);
1651 if (wp->w_popup_border[1] > 0)
1652 {
1653 buf[mb_char2bytes(border_char[6], buf)] = NUL;
1654 screen_puts(buf, row,
1655 wp->w_wincol + total_width - 1, border_attr[2]);
1656 }
1657 }
1658
1659 // Back to the normal zindex.
1660 screen_zindex = 0;
1661 }
1662}
1663
Bram Moolenaar4d784b22019-05-25 19:51:39 +02001664#endif // FEAT_TEXT_PROP