Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1 | /* 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 Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 18 | typedef struct { |
| 19 | char *pp_name; |
| 20 | poppos_T pp_val; |
| 21 | } poppos_entry_T; |
| 22 | |
| 23 | static 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 Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 31 | /* |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 32 | * Get option value for "key", which is "line" or "col". |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 33 | * Handles "cursor+N" and "cursor-N". |
| 34 | */ |
| 35 | static int |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 36 | popup_options_one(dict_T *dict, char_u *key) |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 37 | { |
| 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 Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 50 | return dict_get_number_check(dict, key); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 51 | |
| 52 | setcursor_mayforce(TRUE); |
| 53 | s = val + 6; |
| 54 | if (*s != NUL) |
| 55 | { |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 56 | endp = s; |
| 57 | if (*skipwhite(s) == '+' || *skipwhite(s) == '-') |
| 58 | n = strtol((char *)s, (char **)&endp, 10); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 59 | 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 Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 76 | static void |
| 77 | get_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 Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 89 | wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0; |
| 90 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 91 | 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 Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 108 | static void |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 109 | set_padding_border(dict_T *dict, int *array, char *name, int max_val) |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 110 | { |
| 111 | dictitem_T *di; |
| 112 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 113 | 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 Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 139 | /* |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 140 | * Used when popup options contain "moved": set default moved values. |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 141 | */ |
| 142 | static void |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 143 | set_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 |
| 155 | set_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 Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 167 | /* |
| 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 |
| 172 | popup_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. |
| 181 | static int drag_start_row; |
| 182 | static int drag_start_col; |
| 183 | static int drag_start_wantline; |
| 184 | static 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 |
| 191 | popup_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; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 204 | |
| 205 | // Stop centering the popup |
| 206 | if (wp->w_popup_pos == POPPOS_CENTER) |
| 207 | wp->w_popup_pos = POPPOS_TOPLEFT; |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /* |
| 211 | * Mouse moved while dragging a popup window: adjust the window popup position. |
| 212 | */ |
| 213 | void |
| 214 | popup_drag(win_T *wp) |
| 215 | { |
| 216 | // The popup may be closed before dragging stops. |
| 217 | if (!win_valid_popup(wp)) |
| 218 | return; |
| 219 | |
| 220 | wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row); |
| 221 | if (wp->w_wantline < 1) |
| 222 | wp->w_wantline = 1; |
| 223 | if (wp->w_wantline > Rows) |
| 224 | wp->w_wantline = Rows; |
| 225 | wp->w_wantcol = drag_start_wantcol + (mouse_col - drag_start_col); |
| 226 | if (wp->w_wantcol < 1) |
| 227 | wp->w_wantcol = 1; |
| 228 | if (wp->w_wantcol > Columns) |
| 229 | wp->w_wantcol = Columns; |
| 230 | |
| 231 | popup_adjust_position(wp); |
| 232 | } |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 233 | |
| 234 | #if defined(FEAT_TIMERS) |
| 235 | static void |
| 236 | popup_add_timeout(win_T *wp, int time) |
| 237 | { |
| 238 | char_u cbbuf[50]; |
| 239 | char_u *ptr = cbbuf; |
| 240 | typval_T tv; |
| 241 | |
| 242 | vim_snprintf((char *)cbbuf, sizeof(cbbuf), |
| 243 | "{_ -> popup_close(%d)}", wp->w_id); |
| 244 | if (get_lambda_tv(&ptr, &tv, TRUE) == OK) |
| 245 | { |
| 246 | wp->w_popup_timer = create_timer(time, 0); |
| 247 | wp->w_popup_timer->tr_callback = get_callback(&tv); |
| 248 | clear_tv(&tv); |
| 249 | } |
| 250 | } |
| 251 | #endif |
| 252 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 253 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 254 | * Shared between popup_create() and f_popup_move(). |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 255 | */ |
| 256 | static void |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 257 | apply_move_options(win_T *wp, dict_T *d) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 258 | { |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 259 | int nr; |
| 260 | |
| 261 | if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0) |
| 262 | wp->w_minwidth = nr; |
| 263 | if ((nr = dict_get_number(d, (char_u *)"minheight")) > 0) |
| 264 | wp->w_minheight = nr; |
| 265 | if ((nr = dict_get_number(d, (char_u *)"maxwidth")) > 0) |
| 266 | wp->w_maxwidth = nr; |
| 267 | if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0) |
| 268 | wp->w_maxheight = nr; |
| 269 | get_pos_options(wp, d); |
| 270 | } |
| 271 | |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 272 | static void |
| 273 | check_highlight(dict_T *dict, char *name, char_u **pval) |
| 274 | { |
| 275 | dictitem_T *di; |
| 276 | char_u *str; |
| 277 | |
| 278 | di = dict_find(dict, (char_u *)name, -1); |
| 279 | if (di != NULL) |
| 280 | { |
| 281 | if (di->di_tv.v_type != VAR_STRING) |
| 282 | semsg(_(e_invargval), name); |
| 283 | else |
| 284 | { |
| 285 | str = tv_get_string(&di->di_tv); |
| 286 | if (*str != NUL) |
| 287 | *pval = vim_strsave(str); |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 292 | /* |
| 293 | * Shared between popup_create() and f_popup_setoptions(). |
| 294 | */ |
| 295 | static void |
| 296 | apply_general_options(win_T *wp, dict_T *dict) |
| 297 | { |
| 298 | dictitem_T *di; |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 299 | int nr; |
| 300 | char_u *str; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 301 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 302 | // TODO: flip |
| 303 | |
| 304 | di = dict_find(dict, (char_u *)"firstline", -1); |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 305 | if (di != NULL) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 306 | wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); |
| 307 | if (wp->w_firstline < 1) |
| 308 | wp->w_firstline = 1; |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 309 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 310 | di = dict_find(dict, (char_u *)"scrollbar", -1); |
| 311 | if (di != NULL) |
| 312 | wp->w_want_scrollbar = dict_get_number(dict, (char_u *)"scrollbar"); |
| 313 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 314 | str = dict_get_string(dict, (char_u *)"title", FALSE); |
| 315 | if (str != NULL) |
| 316 | { |
| 317 | vim_free(wp->w_popup_title); |
| 318 | wp->w_popup_title = vim_strsave(str); |
| 319 | } |
| 320 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 321 | di = dict_find(dict, (char_u *)"wrap", -1); |
| 322 | if (di != NULL) |
| 323 | { |
| 324 | nr = dict_get_number(dict, (char_u *)"wrap"); |
| 325 | wp->w_p_wrap = nr != 0; |
| 326 | } |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 327 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 328 | di = dict_find(dict, (char_u *)"drag", -1); |
| 329 | if (di != NULL) |
| 330 | wp->w_popup_drag = dict_get_number(dict, (char_u *)"drag"); |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 331 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 332 | str = dict_get_string(dict, (char_u *)"highlight", FALSE); |
| 333 | if (str != NULL) |
| 334 | set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
| 335 | str, OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 336 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 337 | set_padding_border(dict, wp->w_popup_padding, "padding", 999); |
| 338 | set_padding_border(dict, wp->w_popup_border, "border", 1); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 339 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 340 | di = dict_find(dict, (char_u *)"borderhighlight", -1); |
| 341 | if (di != NULL) |
| 342 | { |
| 343 | if (di->di_tv.v_type != VAR_LIST) |
| 344 | emsg(_(e_listreq)); |
| 345 | else |
| 346 | { |
| 347 | list_T *list = di->di_tv.vval.v_list; |
| 348 | listitem_T *li; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 349 | int i; |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 350 | |
| 351 | if (list != NULL) |
| 352 | for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len; |
| 353 | ++i, li = li->li_next) |
| 354 | { |
| 355 | str = tv_get_string(&li->li_tv); |
| 356 | if (*str != NUL) |
| 357 | wp->w_border_highlight[i] = vim_strsave(str); |
| 358 | } |
| 359 | if (list->lv_len == 1 && wp->w_border_highlight[0] != NULL) |
| 360 | for (i = 1; i < 4; ++i) |
| 361 | wp->w_border_highlight[i] = |
| 362 | vim_strsave(wp->w_border_highlight[0]); |
| 363 | } |
| 364 | } |
| 365 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 366 | di = dict_find(dict, (char_u *)"borderchars", -1); |
| 367 | if (di != NULL) |
| 368 | { |
| 369 | if (di->di_tv.v_type != VAR_LIST) |
| 370 | emsg(_(e_listreq)); |
| 371 | else |
| 372 | { |
| 373 | list_T *list = di->di_tv.vval.v_list; |
| 374 | listitem_T *li; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 375 | int i; |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 376 | |
| 377 | if (list != NULL) |
| 378 | for (i = 0, li = list->lv_first; i < 8 && i < list->lv_len; |
| 379 | ++i, li = li->li_next) |
| 380 | { |
| 381 | str = tv_get_string(&li->li_tv); |
| 382 | if (*str != NUL) |
| 383 | wp->w_border_char[i] = mb_ptr2char(str); |
| 384 | } |
| 385 | if (list->lv_len == 1) |
| 386 | for (i = 1; i < 8; ++i) |
| 387 | wp->w_border_char[i] = wp->w_border_char[0]; |
| 388 | if (list->lv_len == 2) |
| 389 | { |
| 390 | for (i = 4; i < 8; ++i) |
| 391 | wp->w_border_char[i] = wp->w_border_char[1]; |
| 392 | for (i = 1; i < 4; ++i) |
| 393 | wp->w_border_char[i] = wp->w_border_char[0]; |
| 394 | } |
| 395 | } |
| 396 | } |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 397 | |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 398 | check_highlight(dict, "scrollbarhighlight", &wp->w_scrollbar_highlight); |
| 399 | check_highlight(dict, "thumbhighlight", &wp->w_thumb_highlight); |
| 400 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 401 | di = dict_find(dict, (char_u *)"zindex", -1); |
| 402 | if (di != NULL) |
| 403 | { |
| 404 | wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); |
| 405 | if (wp->w_zindex < 1) |
| 406 | wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX; |
| 407 | if (wp->w_zindex > 32000) |
| 408 | wp->w_zindex = 32000; |
| 409 | } |
| 410 | |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 411 | di = dict_find(dict, (char_u *)"mask", -1); |
| 412 | if (di != NULL) |
| 413 | { |
| 414 | int ok = TRUE; |
| 415 | |
| 416 | if (di->di_tv.v_type != VAR_LIST) |
| 417 | ok = FALSE; |
| 418 | else if (di->di_tv.vval.v_list != NULL) |
| 419 | { |
| 420 | listitem_T *li; |
| 421 | |
| 422 | for (li = di->di_tv.vval.v_list->lv_first; li != NULL; |
| 423 | li = li->li_next) |
| 424 | { |
| 425 | if (li->li_tv.v_type != VAR_LIST |
| 426 | || li->li_tv.vval.v_list == NULL |
| 427 | || li->li_tv.vval.v_list->lv_len != 4) |
| 428 | { |
| 429 | ok = FALSE; |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | if (ok) |
| 435 | { |
| 436 | wp->w_popup_mask = di->di_tv.vval.v_list; |
| 437 | ++wp->w_popup_mask->lv_refcount; |
| 438 | } |
| 439 | else |
| 440 | semsg(_(e_invargval), "mask"); |
| 441 | } |
| 442 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 443 | #if defined(FEAT_TIMERS) |
| 444 | // Add timer to close the popup after some time. |
| 445 | nr = dict_get_number(dict, (char_u *)"time"); |
| 446 | if (nr > 0) |
| 447 | popup_add_timeout(wp, nr); |
| 448 | #endif |
| 449 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 450 | di = dict_find(dict, (char_u *)"moved", -1); |
| 451 | if (di != NULL) |
| 452 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 453 | set_moved_values(wp); |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 454 | if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL) |
| 455 | { |
| 456 | char_u *s = di->di_tv.vval.v_string; |
| 457 | int flags = 0; |
| 458 | |
| 459 | if (STRCMP(s, "word") == 0) |
| 460 | flags = FIND_IDENT | FIND_STRING; |
| 461 | else if (STRCMP(s, "WORD") == 0) |
| 462 | flags = FIND_STRING; |
| 463 | else if (STRCMP(s, "any") != 0) |
| 464 | semsg(_(e_invarg2), s); |
| 465 | if (flags != 0) |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 466 | set_moved_columns(wp, flags); |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 467 | } |
| 468 | else if (di->di_tv.v_type == VAR_LIST |
| 469 | && di->di_tv.vval.v_list != NULL |
| 470 | && di->di_tv.vval.v_list->lv_len == 2) |
| 471 | { |
| 472 | list_T *l = di->di_tv.vval.v_list; |
| 473 | |
| 474 | wp->w_popup_mincol = tv_get_number(&l->lv_first->li_tv); |
| 475 | wp->w_popup_maxcol = tv_get_number(&l->lv_first->li_next->li_tv); |
| 476 | } |
| 477 | else |
| 478 | semsg(_(e_invarg2), tv_get_string(&di->di_tv)); |
| 479 | } |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 480 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 481 | di = dict_find(dict, (char_u *)"filter", -1); |
| 482 | if (di != NULL) |
| 483 | { |
| 484 | callback_T callback = get_callback(&di->di_tv); |
| 485 | |
| 486 | if (callback.cb_name != NULL) |
| 487 | { |
| 488 | free_callback(&wp->w_filter_cb); |
| 489 | set_callback(&wp->w_filter_cb, &callback); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | di = dict_find(dict, (char_u *)"callback", -1); |
| 494 | if (di != NULL) |
| 495 | { |
| 496 | callback_T callback = get_callback(&di->di_tv); |
| 497 | |
| 498 | if (callback.cb_name != NULL) |
| 499 | { |
| 500 | free_callback(&wp->w_close_cb); |
| 501 | set_callback(&wp->w_close_cb, &callback); |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | /* |
| 507 | * Go through the options in "dict" and apply them to popup window "wp". |
| 508 | */ |
| 509 | static void |
| 510 | apply_options(win_T *wp, dict_T *dict) |
| 511 | { |
| 512 | int nr; |
| 513 | |
| 514 | apply_move_options(wp, dict); |
| 515 | apply_general_options(wp, dict); |
| 516 | |
Bram Moolenaar | 6313c4f | 2019-06-16 20:39:13 +0200 | [diff] [blame] | 517 | nr = dict_get_number(dict, (char_u *)"hidden"); |
| 518 | if (nr > 0) |
| 519 | { |
| 520 | wp->w_popup_flags |= POPF_HIDDEN; |
| 521 | --wp->w_buffer->b_nwindows; |
| 522 | } |
| 523 | |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 524 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /* |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 528 | * Add lines to the popup from a list of strings. |
| 529 | */ |
| 530 | static void |
| 531 | add_popup_strings(buf_T *buf, list_T *l) |
| 532 | { |
| 533 | listitem_T *li; |
| 534 | linenr_T lnum = 0; |
| 535 | char_u *p; |
| 536 | |
| 537 | for (li = l->lv_first; li != NULL; li = li->li_next) |
| 538 | if (li->li_tv.v_type == VAR_STRING) |
| 539 | { |
| 540 | p = li->li_tv.vval.v_string; |
| 541 | ml_append_buf(buf, lnum++, |
| 542 | p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /* |
| 547 | * Add lines to the popup from a list of dictionaries. |
| 548 | */ |
| 549 | static void |
| 550 | add_popup_dicts(buf_T *buf, list_T *l) |
| 551 | { |
| 552 | listitem_T *li; |
| 553 | listitem_T *pli; |
| 554 | linenr_T lnum = 0; |
| 555 | char_u *p; |
| 556 | dict_T *dict; |
| 557 | |
| 558 | // first add the text lines |
| 559 | for (li = l->lv_first; li != NULL; li = li->li_next) |
| 560 | { |
| 561 | if (li->li_tv.v_type != VAR_DICT) |
| 562 | { |
| 563 | emsg(_(e_dictreq)); |
| 564 | return; |
| 565 | } |
| 566 | dict = li->li_tv.vval.v_dict; |
| 567 | p = dict == NULL ? NULL |
| 568 | : dict_get_string(dict, (char_u *)"text", FALSE); |
| 569 | ml_append_buf(buf, lnum++, |
| 570 | p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE); |
| 571 | } |
| 572 | |
| 573 | // add the text properties |
| 574 | lnum = 1; |
| 575 | for (li = l->lv_first; li != NULL; li = li->li_next, ++lnum) |
| 576 | { |
| 577 | dictitem_T *di; |
| 578 | list_T *plist; |
| 579 | |
| 580 | dict = li->li_tv.vval.v_dict; |
| 581 | di = dict_find(dict, (char_u *)"props", -1); |
| 582 | if (di != NULL) |
| 583 | { |
| 584 | if (di->di_tv.v_type != VAR_LIST) |
| 585 | { |
| 586 | emsg(_(e_listreq)); |
| 587 | return; |
| 588 | } |
| 589 | plist = di->di_tv.vval.v_list; |
| 590 | if (plist != NULL) |
| 591 | { |
| 592 | for (pli = plist->lv_first; pli != NULL; pli = pli->li_next) |
| 593 | { |
| 594 | if (pli->li_tv.v_type != VAR_DICT) |
| 595 | { |
| 596 | emsg(_(e_dictreq)); |
| 597 | return; |
| 598 | } |
| 599 | dict = pli->li_tv.vval.v_dict; |
| 600 | if (dict != NULL) |
| 601 | { |
| 602 | int col = dict_get_number(dict, (char_u *)"col"); |
| 603 | |
| 604 | prop_add_common( lnum, col, dict, buf, NULL); |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | /* |
Bram Moolenaar | 451d4b5 | 2019-06-12 20:22:27 +0200 | [diff] [blame] | 613 | * Return the height of popup window "wp", including border and padding. |
| 614 | */ |
| 615 | int |
| 616 | popup_height(win_T *wp) |
| 617 | { |
| 618 | return wp->w_height |
| 619 | + wp->w_popup_padding[0] + wp->w_popup_border[0] |
| 620 | + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
| 621 | } |
| 622 | |
| 623 | /* |
| 624 | * Return the width of popup window "wp", including border and padding. |
| 625 | */ |
| 626 | int |
| 627 | popup_width(win_T *wp) |
| 628 | { |
| 629 | return wp->w_width |
| 630 | + wp->w_popup_padding[3] + wp->w_popup_border[3] |
| 631 | + wp->w_popup_padding[1] + wp->w_popup_border[1]; |
| 632 | } |
| 633 | |
| 634 | /* |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 635 | * Get the padding plus border at the top, adjusted to 1 if there is a title. |
| 636 | */ |
| 637 | static int |
| 638 | popup_top_extra(win_T *wp) |
| 639 | { |
| 640 | int extra = wp->w_popup_border[0] + wp->w_popup_padding[0]; |
| 641 | |
| 642 | if (extra == 0 && wp->w_popup_title != NULL && *wp->w_popup_title != NUL) |
| 643 | return 1; |
| 644 | return extra; |
| 645 | } |
| 646 | |
| 647 | /* |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 648 | * Adjust the position and size of the popup to fit on the screen. |
| 649 | */ |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 650 | void |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 651 | popup_adjust_position(win_T *wp) |
| 652 | { |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 653 | linenr_T lnum; |
| 654 | int wrapped = 0; |
| 655 | int maxwidth; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 656 | int center_vert = FALSE; |
| 657 | int center_hor = FALSE; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 658 | int allow_adjust_left = !wp->w_popup_fixed; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 659 | int top_extra = popup_top_extra(wp); |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 660 | int right_extra = wp->w_popup_border[1] + wp->w_popup_padding[1]; |
| 661 | int bot_extra = wp->w_popup_border[2] + wp->w_popup_padding[2]; |
| 662 | int left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
| 663 | int extra_height = top_extra + bot_extra; |
| 664 | int extra_width = left_extra + right_extra; |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 665 | int org_winrow = wp->w_winrow; |
| 666 | int org_wincol = wp->w_wincol; |
| 667 | int org_width = wp->w_width; |
| 668 | int org_height = wp->w_height; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 669 | int minwidth; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 670 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 671 | wp->w_winrow = 0; |
| 672 | wp->w_wincol = 0; |
| 673 | if (wp->w_popup_pos == POPPOS_CENTER) |
| 674 | { |
| 675 | // center after computing the size |
| 676 | center_vert = TRUE; |
| 677 | center_hor = TRUE; |
| 678 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 679 | else |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 680 | { |
| 681 | if (wp->w_wantline == 0) |
| 682 | center_vert = TRUE; |
| 683 | else if (wp->w_popup_pos == POPPOS_TOPLEFT |
| 684 | || wp->w_popup_pos == POPPOS_TOPRIGHT) |
| 685 | { |
| 686 | wp->w_winrow = wp->w_wantline - 1; |
| 687 | if (wp->w_winrow >= Rows) |
| 688 | wp->w_winrow = Rows - 1; |
| 689 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 690 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 691 | if (wp->w_wantcol == 0) |
| 692 | center_hor = TRUE; |
| 693 | else if (wp->w_popup_pos == POPPOS_TOPLEFT |
| 694 | || wp->w_popup_pos == POPPOS_BOTLEFT) |
| 695 | { |
| 696 | wp->w_wincol = wp->w_wantcol - 1; |
| 697 | if (wp->w_wincol >= Columns - 3) |
| 698 | wp->w_wincol = Columns - 3; |
| 699 | } |
| 700 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 701 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 702 | // When centering or right aligned, use maximum width. |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 703 | // When left aligned use the space available, but shift to the left when we |
| 704 | // hit the right of the screen. |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 705 | maxwidth = Columns - wp->w_wincol - left_extra; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 706 | if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 707 | { |
| 708 | allow_adjust_left = FALSE; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 709 | maxwidth = wp->w_maxwidth; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 710 | } |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 711 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 712 | // start at the desired first line |
| 713 | wp->w_topline = wp->w_firstline; |
| 714 | if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) |
| 715 | wp->w_topline = wp->w_buffer->b_ml.ml_line_count; |
| 716 | |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 717 | // Compute width based on longest text line and the 'wrap' option. |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 718 | // Use a minimum width of one, so that something shows when there is no |
| 719 | // text. |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 720 | // TODO: more accurate wrapping |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 721 | wp->w_width = 1; |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 722 | for (lnum = wp->w_topline; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 723 | { |
| 724 | int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE)); |
| 725 | |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 726 | if (wp->w_p_wrap) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 727 | { |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 728 | while (len > maxwidth) |
| 729 | { |
| 730 | ++wrapped; |
| 731 | len -= maxwidth; |
| 732 | wp->w_width = maxwidth; |
| 733 | } |
| 734 | } |
| 735 | else if (len > maxwidth |
| 736 | && allow_adjust_left |
| 737 | && (wp->w_popup_pos == POPPOS_TOPLEFT |
| 738 | || wp->w_popup_pos == POPPOS_BOTLEFT)) |
| 739 | { |
| 740 | // adjust leftwise to fit text on screen |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 741 | int shift_by = len - maxwidth; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 742 | |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 743 | if (shift_by > wp->w_wincol) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 744 | { |
| 745 | int truncate_shift = shift_by - wp->w_wincol; |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 746 | |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 747 | len -= truncate_shift; |
| 748 | shift_by -= truncate_shift; |
| 749 | } |
| 750 | |
| 751 | wp->w_wincol -= shift_by; |
| 752 | maxwidth += shift_by; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 753 | wp->w_width = maxwidth; |
| 754 | } |
| 755 | if (wp->w_width < len) |
| 756 | wp->w_width = len; |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 757 | // do not use the width of lines we're not going to show |
| 758 | if (wp->w_maxheight > 0 && wp->w_buffer->b_ml.ml_line_count |
| 759 | - wp->w_topline + 1 + wrapped > wp->w_maxheight) |
| 760 | break; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 761 | } |
| 762 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 763 | wp->w_has_scrollbar = wp->w_want_scrollbar |
| 764 | && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count); |
| 765 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 766 | minwidth = wp->w_minwidth; |
| 767 | if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL) |
| 768 | { |
| 769 | int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width; |
| 770 | |
| 771 | if (minwidth < title_len) |
| 772 | minwidth = title_len; |
| 773 | } |
| 774 | |
| 775 | if (minwidth > 0 && wp->w_width < minwidth) |
| 776 | wp->w_width = minwidth; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 777 | if (wp->w_width > maxwidth) |
| 778 | wp->w_width = maxwidth; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 779 | if (center_hor) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 780 | { |
| 781 | wp->w_wincol = (Columns - wp->w_width - extra_width) / 2; |
| 782 | if (wp->w_wincol < 0) |
| 783 | wp->w_wincol = 0; |
| 784 | } |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 785 | else if (wp->w_popup_pos == POPPOS_BOTRIGHT |
| 786 | || wp->w_popup_pos == POPPOS_TOPRIGHT) |
| 787 | { |
| 788 | // Right aligned: move to the right if needed. |
| 789 | // No truncation, because that would change the height. |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 790 | if (wp->w_width + extra_width < wp->w_wantcol) |
| 791 | wp->w_wincol = wp->w_wantcol - (wp->w_width + extra_width); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 792 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 793 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 794 | wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline |
| 795 | + 1 + wrapped; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 796 | if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) |
| 797 | wp->w_height = wp->w_minheight; |
| 798 | if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) |
| 799 | wp->w_height = wp->w_maxheight; |
| 800 | if (wp->w_height > Rows - wp->w_winrow) |
| 801 | wp->w_height = Rows - wp->w_winrow; |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 802 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 803 | if (center_vert) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 804 | { |
| 805 | wp->w_winrow = (Rows - wp->w_height - extra_height) / 2; |
| 806 | if (wp->w_winrow < 0) |
| 807 | wp->w_winrow = 0; |
| 808 | } |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 809 | else if (wp->w_popup_pos == POPPOS_BOTRIGHT |
| 810 | || wp->w_popup_pos == POPPOS_BOTLEFT) |
| 811 | { |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 812 | if ((wp->w_height + extra_height) <= wp->w_wantline) |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 813 | // bottom aligned: may move down |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 814 | wp->w_winrow = wp->w_wantline - (wp->w_height + extra_height); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 815 | else |
| 816 | // not enough space, make top aligned |
| 817 | wp->w_winrow = wp->w_wantline + 1; |
| 818 | } |
| 819 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 820 | wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 821 | |
| 822 | // Need to update popup_mask if the position or size changed. |
Bram Moolenaar | acc682b | 2019-06-08 17:15:51 +0200 | [diff] [blame] | 823 | // And redraw windows that were behind the popup. |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 824 | if (org_winrow != wp->w_winrow |
| 825 | || org_wincol != wp->w_wincol |
| 826 | || org_width != wp->w_width |
| 827 | || org_height != wp->w_height) |
| 828 | { |
Bram Moolenaar | 4c063a0 | 2019-06-10 21:24:12 +0200 | [diff] [blame] | 829 | redraw_all_later(VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 830 | popup_mask_refresh = TRUE; |
| 831 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 832 | } |
| 833 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 834 | typedef enum |
| 835 | { |
| 836 | TYPE_NORMAL, |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 837 | TYPE_ATCURSOR, |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 838 | TYPE_NOTIFICATION, |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 839 | TYPE_DIALOG, |
| 840 | TYPE_MENU |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 841 | } create_type_T; |
| 842 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 843 | /* |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 844 | * Make "buf" empty and set the contents to "text". |
| 845 | * Used by popup_create() and popup_settext(). |
| 846 | */ |
| 847 | static void |
| 848 | popup_set_buffer_text(buf_T *buf, typval_T text) |
| 849 | { |
| 850 | int lnum; |
| 851 | |
| 852 | // Clear the buffer, then replace the lines. |
| 853 | curbuf = buf; |
| 854 | for (lnum = buf->b_ml.ml_line_count; lnum > 0; --lnum) |
| 855 | ml_delete(lnum, FALSE); |
| 856 | curbuf = curwin->w_buffer; |
| 857 | |
| 858 | // Add text to the buffer. |
| 859 | if (text.v_type == VAR_STRING) |
| 860 | { |
| 861 | // just a string |
| 862 | ml_append_buf(buf, 0, text.vval.v_string, (colnr_T)0, TRUE); |
| 863 | } |
| 864 | else |
| 865 | { |
| 866 | list_T *l = text.vval.v_list; |
| 867 | |
| 868 | if (l->lv_len > 0) |
| 869 | { |
| 870 | if (l->lv_first->li_tv.v_type == VAR_STRING) |
| 871 | // list of strings |
| 872 | add_popup_strings(buf, l); |
| 873 | else |
| 874 | // list of dictionaries |
| 875 | add_popup_dicts(buf, l); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | // delete the line that was in the empty buffer |
| 880 | curbuf = buf; |
| 881 | ml_delete(buf->b_ml.ml_line_count, FALSE); |
| 882 | curbuf = curwin->w_buffer; |
| 883 | } |
| 884 | |
| 885 | /* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 886 | * popup_create({text}, {options}) |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 887 | * popup_atcursor({text}, {options}) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 888 | */ |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 889 | static win_T * |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 890 | popup_create(typval_T *argvars, typval_T *rettv, create_type_T type) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 891 | { |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 892 | win_T *wp; |
| 893 | tabpage_T *tp = NULL; |
| 894 | int tabnr; |
| 895 | buf_T *buf; |
| 896 | dict_T *d; |
| 897 | int nr; |
| 898 | int i; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 899 | |
| 900 | // Check arguments look OK. |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 901 | if (!(argvars[0].v_type == VAR_STRING && argvars[0].vval.v_string != NULL) |
| 902 | && !(argvars[0].v_type == VAR_LIST && argvars[0].vval.v_list != NULL)) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 903 | { |
| 904 | emsg(_(e_listreq)); |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 905 | return NULL; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 906 | } |
| 907 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 908 | { |
| 909 | emsg(_(e_dictreq)); |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 910 | return NULL; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 911 | } |
| 912 | d = argvars[1].vval.v_dict; |
| 913 | |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 914 | if (dict_find(d, (char_u *)"tabpage", -1) != NULL) |
| 915 | tabnr = (int)dict_get_number(d, (char_u *)"tabpage"); |
| 916 | else if (type == TYPE_NOTIFICATION) |
| 917 | tabnr = -1; // notifications are global by default |
| 918 | else |
| 919 | tabnr = 0; |
| 920 | if (tabnr > 0) |
| 921 | { |
| 922 | tp = find_tabpage(tabnr); |
| 923 | if (tp == NULL) |
| 924 | { |
Bram Moolenaar | b2cda0d | 2019-06-24 05:06:36 +0200 | [diff] [blame] | 925 | semsg(_("E997: Tabpage not found: %d"), tabnr); |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 926 | return NULL; |
| 927 | } |
| 928 | } |
| 929 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 930 | // Create the window and buffer. |
| 931 | wp = win_alloc_popup_win(); |
| 932 | if (wp == NULL) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 933 | return NULL; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 934 | rettv->vval.v_number = wp->w_id; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 935 | wp->w_popup_pos = POPPOS_TOPLEFT; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 936 | |
| 937 | buf = buflist_new(NULL, NULL, (linenr_T)0, BLN_NEW|BLN_LISTED|BLN_DUMMY); |
| 938 | if (buf == NULL) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 939 | return NULL; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 940 | ml_open(buf); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 941 | |
| 942 | win_init_popup_win(wp, buf); |
| 943 | |
| 944 | set_local_options_default(wp); |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 945 | set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1, |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 946 | (char_u *)"popup", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 947 | set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1, |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 948 | (char_u *)"hide", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 949 | buf->b_p_ul = -1; // no undo |
| 950 | buf->b_p_swf = FALSE; // no swap file |
| 951 | buf->b_p_bl = FALSE; // unlisted buffer |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 952 | buf->b_locked = TRUE; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 953 | wp->w_p_wrap = TRUE; // 'wrap' is default on |
| 954 | |
Bram Moolenaar | 54fabd4 | 2019-05-30 19:03:22 +0200 | [diff] [blame] | 955 | // Avoid that 'buftype' is reset when this buffer is entered. |
| 956 | buf->b_p_initialized = TRUE; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 957 | |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 958 | if (tp != NULL) |
| 959 | { |
| 960 | // popup on specified tab page |
| 961 | wp->w_next = tp->tp_first_popupwin; |
| 962 | tp->tp_first_popupwin = wp; |
| 963 | } |
| 964 | else if (tabnr == 0) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 965 | { |
Bram Moolenaar | fc06cbb | 2019-06-15 14:14:31 +0200 | [diff] [blame] | 966 | // popup on current tab page |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 967 | wp->w_next = curtab->tp_first_popupwin; |
| 968 | curtab->tp_first_popupwin = wp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 969 | } |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 970 | else // (tabnr < 0) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 971 | { |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 972 | win_T *prev = first_popupwin; |
| 973 | |
| 974 | // Global popup: add at the end, so that it gets displayed on top of |
| 975 | // older ones with the same zindex. Matters for notifications. |
| 976 | if (first_popupwin == NULL) |
| 977 | first_popupwin = wp; |
| 978 | else |
| 979 | { |
| 980 | while (prev->w_next != NULL) |
| 981 | prev = prev->w_next; |
| 982 | prev->w_next = wp; |
| 983 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 984 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 985 | |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 986 | popup_set_buffer_text(buf, argvars[0]); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 987 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 988 | if (type == TYPE_ATCURSOR) |
| 989 | { |
| 990 | wp->w_popup_pos = POPPOS_BOTLEFT; |
| 991 | setcursor_mayforce(TRUE); |
| 992 | wp->w_wantline = screen_screenrow(); |
| 993 | if (wp->w_wantline == 0) // cursor in first line |
| 994 | { |
| 995 | wp->w_wantline = 2; |
| 996 | wp->w_popup_pos = POPPOS_TOPLEFT; |
| 997 | } |
| 998 | wp->w_wantcol = screen_screencol() + 1; |
| 999 | set_moved_values(wp); |
| 1000 | set_moved_columns(wp, FIND_STRING); |
| 1001 | } |
| 1002 | |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1003 | // set default values |
| 1004 | wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX; |
| 1005 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1006 | if (type == TYPE_NOTIFICATION) |
| 1007 | { |
| 1008 | win_T *twp, *nextwin; |
| 1009 | int height = buf->b_ml.ml_line_count + 3; |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1010 | |
| 1011 | // Try to not overlap with another global popup. Guess we need 3 |
| 1012 | // more screen lines than buffer lines. |
| 1013 | wp->w_wantline = 1; |
| 1014 | for (twp = first_popupwin; twp != NULL; twp = nextwin) |
| 1015 | { |
| 1016 | nextwin = twp->w_next; |
| 1017 | if (twp != wp |
| 1018 | && twp->w_zindex == POPUPWIN_NOTIFICATION_ZINDEX |
| 1019 | && twp->w_winrow <= wp->w_wantline - 1 + height |
| 1020 | && twp->w_winrow + popup_height(twp) > wp->w_wantline - 1) |
| 1021 | { |
| 1022 | // move to below this popup and restart the loop to check for |
| 1023 | // overlap with other popups |
| 1024 | wp->w_wantline = twp->w_winrow + popup_height(twp) + 1; |
| 1025 | nextwin = first_popupwin; |
| 1026 | } |
| 1027 | } |
| 1028 | if (wp->w_wantline + height > Rows) |
| 1029 | { |
| 1030 | // can't avoid overlap, put on top in the hope that message goes |
| 1031 | // away soon. |
| 1032 | wp->w_wantline = 1; |
| 1033 | } |
| 1034 | |
| 1035 | wp->w_wantcol = 10; |
| 1036 | wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX; |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1037 | wp->w_minwidth = 20; |
| 1038 | wp->w_popup_drag = 1; |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1039 | for (i = 0; i < 4; ++i) |
| 1040 | wp->w_popup_border[i] = 1; |
| 1041 | wp->w_popup_padding[1] = 1; |
| 1042 | wp->w_popup_padding[3] = 1; |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1043 | |
| 1044 | nr = syn_name2id((char_u *)"PopupNotification"); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1045 | set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1046 | (char_u *)(nr == 0 ? "WarningMsg" : "PopupNotification"), |
| 1047 | OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1048 | } |
| 1049 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1050 | if (type == TYPE_DIALOG || type == TYPE_MENU) |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1051 | { |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1052 | wp->w_popup_pos = POPPOS_CENTER; |
| 1053 | wp->w_zindex = POPUPWIN_DIALOG_ZINDEX; |
| 1054 | wp->w_popup_drag = 1; |
| 1055 | for (i = 0; i < 4; ++i) |
| 1056 | { |
| 1057 | wp->w_popup_border[i] = 1; |
| 1058 | wp->w_popup_padding[i] = 1; |
| 1059 | } |
| 1060 | } |
| 1061 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1062 | if (type == TYPE_MENU) |
| 1063 | { |
| 1064 | typval_T tv; |
| 1065 | callback_T callback; |
| 1066 | |
| 1067 | tv.v_type = VAR_STRING; |
| 1068 | tv.vval.v_string = (char_u *)"popup_filter_menu"; |
| 1069 | callback = get_callback(&tv); |
| 1070 | if (callback.cb_name != NULL) |
| 1071 | set_callback(&wp->w_filter_cb, &callback); |
| 1072 | |
| 1073 | wp->w_p_wrap = 0; |
| 1074 | } |
| 1075 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1076 | for (i = 0; i < 4; ++i) |
| 1077 | VIM_CLEAR(wp->w_border_highlight[i]); |
| 1078 | for (i = 0; i < 8; ++i) |
| 1079 | wp->w_border_char[i] = 0; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1080 | wp->w_want_scrollbar = 1; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1081 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1082 | // Deal with options. |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1083 | apply_options(wp, argvars[1].vval.v_dict); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1084 | |
Bram Moolenaar | 0fcf26b | 2019-06-23 01:03:51 +0200 | [diff] [blame] | 1085 | #ifdef FEAT_TIMERS |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1086 | if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL) |
| 1087 | popup_add_timeout(wp, 3000); |
Bram Moolenaar | 0fcf26b | 2019-06-23 01:03:51 +0200 | [diff] [blame] | 1088 | #endif |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1089 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1090 | popup_adjust_position(wp); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1091 | |
| 1092 | wp->w_vsep_width = 0; |
| 1093 | |
| 1094 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1095 | popup_mask_refresh = TRUE; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1096 | |
| 1097 | return wp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /* |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1101 | * popup_clear() |
| 1102 | */ |
| 1103 | void |
| 1104 | f_popup_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
| 1105 | { |
| 1106 | close_all_popups(); |
| 1107 | } |
| 1108 | |
| 1109 | /* |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1110 | * popup_create({text}, {options}) |
| 1111 | */ |
| 1112 | void |
| 1113 | f_popup_create(typval_T *argvars, typval_T *rettv) |
| 1114 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1115 | popup_create(argvars, rettv, TYPE_NORMAL); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /* |
| 1119 | * popup_atcursor({text}, {options}) |
| 1120 | */ |
| 1121 | void |
| 1122 | f_popup_atcursor(typval_T *argvars, typval_T *rettv) |
| 1123 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1124 | popup_create(argvars, rettv, TYPE_ATCURSOR); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | /* |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1128 | * Invoke the close callback for window "wp" with value "result". |
| 1129 | * Careful: The callback may make "wp" invalid! |
| 1130 | */ |
| 1131 | static void |
| 1132 | invoke_popup_callback(win_T *wp, typval_T *result) |
| 1133 | { |
| 1134 | typval_T rettv; |
| 1135 | int dummy; |
| 1136 | typval_T argv[3]; |
| 1137 | |
| 1138 | argv[0].v_type = VAR_NUMBER; |
| 1139 | argv[0].vval.v_number = (varnumber_T)wp->w_id; |
| 1140 | |
| 1141 | if (result != NULL && result->v_type != VAR_UNKNOWN) |
| 1142 | copy_tv(result, &argv[1]); |
| 1143 | else |
| 1144 | { |
| 1145 | argv[1].v_type = VAR_NUMBER; |
| 1146 | argv[1].vval.v_number = 0; |
| 1147 | } |
| 1148 | |
| 1149 | argv[2].v_type = VAR_UNKNOWN; |
| 1150 | |
| 1151 | call_callback(&wp->w_close_cb, -1, |
| 1152 | &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
| 1153 | if (result != NULL) |
| 1154 | clear_tv(&argv[1]); |
| 1155 | clear_tv(&rettv); |
| 1156 | } |
| 1157 | |
| 1158 | /* |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1159 | * Close popup "wp" and invoke any close callback for it. |
| 1160 | */ |
| 1161 | static void |
| 1162 | popup_close_and_callback(win_T *wp, typval_T *arg) |
| 1163 | { |
| 1164 | int id = wp->w_id; |
| 1165 | |
| 1166 | if (wp->w_close_cb.cb_name != NULL) |
| 1167 | // Careful: This may make "wp" invalid. |
| 1168 | invoke_popup_callback(wp, arg); |
| 1169 | |
| 1170 | popup_close(id); |
| 1171 | } |
| 1172 | |
| 1173 | /* |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1174 | * In a filter: check if the typed key is a mouse event that is used for |
| 1175 | * dragging the popup. |
| 1176 | */ |
| 1177 | static void |
| 1178 | filter_handle_drag(win_T *wp, int c, typval_T *rettv) |
| 1179 | { |
| 1180 | int row = mouse_row; |
| 1181 | int col = mouse_col; |
| 1182 | |
| 1183 | if (wp->w_popup_drag |
| 1184 | && is_mouse_key(c) |
| 1185 | && (wp == popup_dragwin |
| 1186 | || wp == mouse_find_win(&row, &col, FIND_POPUP))) |
| 1187 | // do not consume the key, allow for dragging the popup |
| 1188 | rettv->vval.v_number = 0; |
| 1189 | } |
| 1190 | |
| 1191 | static void |
| 1192 | popup_highlight_curline(win_T *wp) |
| 1193 | { |
| 1194 | int id; |
| 1195 | char buf[100]; |
| 1196 | |
| 1197 | match_delete(wp, 1, FALSE); |
| 1198 | |
| 1199 | id = syn_name2id((char_u *)"PopupSelected"); |
| 1200 | vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum); |
| 1201 | match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"), |
| 1202 | (char_u *)buf, 10, 1, NULL, NULL); |
| 1203 | } |
| 1204 | |
| 1205 | /* |
| 1206 | * popup_filter_menu({text}, {options}) |
| 1207 | */ |
| 1208 | void |
| 1209 | f_popup_filter_menu(typval_T *argvars, typval_T *rettv) |
| 1210 | { |
| 1211 | int id = tv_get_number(&argvars[0]); |
| 1212 | win_T *wp = win_id2wp(id); |
| 1213 | char_u *key = tv_get_string(&argvars[1]); |
| 1214 | typval_T res; |
| 1215 | int c; |
| 1216 | linenr_T old_lnum; |
| 1217 | |
| 1218 | // If the popup has been closed do not consume the key. |
| 1219 | if (wp == NULL) |
| 1220 | return; |
| 1221 | |
| 1222 | c = *key; |
| 1223 | if (c == K_SPECIAL && key[1] != NUL) |
| 1224 | c = TO_SPECIAL(key[1], key[2]); |
| 1225 | |
| 1226 | // consume all keys until done |
| 1227 | rettv->vval.v_number = 1; |
| 1228 | res.v_type = VAR_NUMBER; |
| 1229 | |
| 1230 | old_lnum = wp->w_cursor.lnum; |
| 1231 | if ((c == 'k' || c == 'K' || c == K_UP) && wp->w_cursor.lnum > 1) |
| 1232 | --wp->w_cursor.lnum; |
| 1233 | if ((c == 'j' || c == 'J' || c == K_DOWN) |
| 1234 | && wp->w_cursor.lnum < wp->w_buffer->b_ml.ml_line_count) |
| 1235 | ++wp->w_cursor.lnum; |
| 1236 | if (old_lnum != wp->w_cursor.lnum) |
| 1237 | { |
| 1238 | popup_highlight_curline(wp); |
| 1239 | return; |
| 1240 | } |
| 1241 | |
| 1242 | if (c == 'x' || c == 'X' || c == ESC || c == Ctrl_C) |
| 1243 | { |
| 1244 | // Cancelled, invoke callback with -1 |
| 1245 | res.vval.v_number = -1; |
| 1246 | popup_close_and_callback(wp, &res); |
| 1247 | return; |
| 1248 | } |
| 1249 | if (c == ' ' || c == K_KENTER || c == CAR || c == NL) |
| 1250 | { |
| 1251 | // Invoke callback with current index. |
| 1252 | res.vval.v_number = wp->w_cursor.lnum; |
| 1253 | popup_close_and_callback(wp, &res); |
| 1254 | return; |
| 1255 | } |
| 1256 | |
| 1257 | filter_handle_drag(wp, c, rettv); |
| 1258 | } |
| 1259 | |
| 1260 | /* |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1261 | * popup_filter_yesno({text}, {options}) |
| 1262 | */ |
| 1263 | void |
| 1264 | f_popup_filter_yesno(typval_T *argvars, typval_T *rettv) |
| 1265 | { |
| 1266 | int id = tv_get_number(&argvars[0]); |
| 1267 | win_T *wp = win_id2wp(id); |
| 1268 | char_u *key = tv_get_string(&argvars[1]); |
| 1269 | typval_T res; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1270 | int c; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1271 | |
| 1272 | // If the popup has been closed don't consume the key. |
| 1273 | if (wp == NULL) |
| 1274 | return; |
| 1275 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1276 | c = *key; |
| 1277 | if (c == K_SPECIAL && key[1] != NUL) |
| 1278 | c = TO_SPECIAL(key[1], key[2]); |
| 1279 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1280 | // consume all keys until done |
| 1281 | rettv->vval.v_number = 1; |
| 1282 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1283 | if (c == 'y' || c == 'Y') |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1284 | res.vval.v_number = 1; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1285 | else if (c == 'n' || c == 'N' || c == 'x' || c == 'X' || c == ESC) |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1286 | res.vval.v_number = 0; |
| 1287 | else |
| 1288 | { |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1289 | filter_handle_drag(wp, c, rettv); |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1290 | return; |
| 1291 | } |
| 1292 | |
| 1293 | // Invoke callback |
| 1294 | res.v_type = VAR_NUMBER; |
| 1295 | popup_close_and_callback(wp, &res); |
| 1296 | } |
| 1297 | |
| 1298 | /* |
| 1299 | * popup_dialog({text}, {options}) |
| 1300 | */ |
| 1301 | void |
| 1302 | f_popup_dialog(typval_T *argvars, typval_T *rettv) |
| 1303 | { |
| 1304 | popup_create(argvars, rettv, TYPE_DIALOG); |
| 1305 | } |
| 1306 | |
| 1307 | /* |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1308 | * popup_menu({text}, {options}) |
| 1309 | */ |
| 1310 | void |
| 1311 | f_popup_menu(typval_T *argvars, typval_T *rettv) |
| 1312 | { |
| 1313 | win_T *wp = popup_create(argvars, rettv, TYPE_MENU); |
| 1314 | |
| 1315 | if (wp != NULL) |
| 1316 | popup_highlight_curline(wp); |
| 1317 | } |
| 1318 | |
| 1319 | /* |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1320 | * popup_notification({text}, {options}) |
| 1321 | */ |
| 1322 | void |
| 1323 | f_popup_notification(typval_T *argvars, typval_T *rettv) |
| 1324 | { |
| 1325 | popup_create(argvars, rettv, TYPE_NOTIFICATION); |
| 1326 | } |
| 1327 | |
| 1328 | /* |
| 1329 | * Find the popup window with window-ID "id". |
| 1330 | * If the popup window does not exist NULL is returned. |
| 1331 | * If the window is not a popup window, and error message is given. |
| 1332 | */ |
| 1333 | static win_T * |
| 1334 | find_popup_win(int id) |
| 1335 | { |
| 1336 | win_T *wp = win_id2wp(id); |
| 1337 | |
| 1338 | if (wp != NULL && !bt_popup(wp->w_buffer)) |
| 1339 | { |
| 1340 | semsg(_("E993: window %d is not a popup window"), id); |
| 1341 | return NULL; |
| 1342 | } |
| 1343 | return wp; |
| 1344 | } |
| 1345 | |
| 1346 | /* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1347 | * popup_close({id}) |
| 1348 | */ |
| 1349 | void |
| 1350 | f_popup_close(typval_T *argvars, typval_T *rettv UNUSED) |
| 1351 | { |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1352 | int id = (int)tv_get_number(argvars); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1353 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1354 | |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1355 | if (wp != NULL) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1356 | popup_close_and_callback(wp, &argvars[1]); |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | /* |
| 1360 | * popup_hide({id}) |
| 1361 | */ |
| 1362 | void |
| 1363 | f_popup_hide(typval_T *argvars, typval_T *rettv UNUSED) |
| 1364 | { |
| 1365 | int id = (int)tv_get_number(argvars); |
| 1366 | win_T *wp = find_popup_win(id); |
| 1367 | |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1368 | if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) == 0) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1369 | { |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1370 | wp->w_popup_flags |= POPF_HIDDEN; |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 1371 | --wp->w_buffer->b_nwindows; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1372 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1373 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | /* |
| 1378 | * popup_show({id}) |
| 1379 | */ |
| 1380 | void |
| 1381 | f_popup_show(typval_T *argvars, typval_T *rettv UNUSED) |
| 1382 | { |
| 1383 | int id = (int)tv_get_number(argvars); |
| 1384 | win_T *wp = find_popup_win(id); |
| 1385 | |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1386 | if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) != 0) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1387 | { |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1388 | wp->w_popup_flags &= ~POPF_HIDDEN; |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 1389 | ++wp->w_buffer->b_nwindows; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1390 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1391 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1392 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1393 | } |
| 1394 | |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1395 | /* |
| 1396 | * popup_settext({id}, {text}) |
| 1397 | */ |
| 1398 | void |
| 1399 | f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED) |
| 1400 | { |
| 1401 | int id = (int)tv_get_number(&argvars[0]); |
| 1402 | win_T *wp = find_popup_win(id); |
| 1403 | |
| 1404 | if (wp != NULL) |
| 1405 | { |
| 1406 | popup_set_buffer_text(wp->w_buffer, argvars[1]); |
| 1407 | popup_adjust_position(wp); |
| 1408 | } |
| 1409 | } |
| 1410 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1411 | static void |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1412 | popup_free(win_T *wp) |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1413 | { |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 1414 | wp->w_buffer->b_locked = FALSE; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1415 | if (wp->w_winrow + wp->w_height >= cmdline_row) |
| 1416 | clear_cmdline = TRUE; |
| 1417 | win_free_popup(wp); |
| 1418 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1419 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1420 | } |
| 1421 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1422 | /* |
| 1423 | * Close a popup window by Window-id. |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1424 | * Does not invoke the callback. |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1425 | */ |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1426 | void |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1427 | popup_close(int id) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1428 | { |
| 1429 | win_T *wp; |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1430 | tabpage_T *tp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1431 | win_T *prev = NULL; |
| 1432 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1433 | // go through global popups |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1434 | for (wp = first_popupwin; wp != NULL; prev = wp, wp = wp->w_next) |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1435 | if (wp->w_id == id) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1436 | { |
| 1437 | if (prev == NULL) |
| 1438 | first_popupwin = wp->w_next; |
| 1439 | else |
| 1440 | prev->w_next = wp->w_next; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1441 | popup_free(wp); |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1442 | return; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1443 | } |
| 1444 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1445 | // go through tab-local popups |
| 1446 | FOR_ALL_TABPAGES(tp) |
| 1447 | popup_close_tabpage(tp, id); |
| 1448 | } |
| 1449 | |
| 1450 | /* |
| 1451 | * Close a popup window with Window-id "id" in tabpage "tp". |
| 1452 | */ |
| 1453 | void |
| 1454 | popup_close_tabpage(tabpage_T *tp, int id) |
| 1455 | { |
| 1456 | win_T *wp; |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 1457 | win_T **root = &tp->tp_first_popupwin; |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1458 | win_T *prev = NULL; |
| 1459 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1460 | for (wp = *root; wp != NULL; prev = wp, wp = wp->w_next) |
| 1461 | if (wp->w_id == id) |
| 1462 | { |
| 1463 | if (prev == NULL) |
| 1464 | *root = wp->w_next; |
| 1465 | else |
| 1466 | prev->w_next = wp->w_next; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1467 | popup_free(wp); |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1468 | return; |
| 1469 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | void |
| 1473 | close_all_popups(void) |
| 1474 | { |
| 1475 | while (first_popupwin != NULL) |
| 1476 | popup_close(first_popupwin->w_id); |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 1477 | while (curtab->tp_first_popupwin != NULL) |
| 1478 | popup_close(curtab->tp_first_popupwin->w_id); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1479 | } |
| 1480 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1481 | /* |
| 1482 | * popup_move({id}, {options}) |
| 1483 | */ |
| 1484 | void |
| 1485 | f_popup_move(typval_T *argvars, typval_T *rettv UNUSED) |
| 1486 | { |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1487 | dict_T *dict; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1488 | int id = (int)tv_get_number(argvars); |
| 1489 | win_T *wp = find_popup_win(id); |
| 1490 | |
| 1491 | if (wp == NULL) |
| 1492 | return; // invalid {id} |
| 1493 | |
| 1494 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 1495 | { |
| 1496 | emsg(_(e_dictreq)); |
| 1497 | return; |
| 1498 | } |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1499 | dict = argvars[1].vval.v_dict; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1500 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1501 | apply_move_options(wp, dict); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1502 | |
| 1503 | if (wp->w_winrow + wp->w_height >= cmdline_row) |
| 1504 | clear_cmdline = TRUE; |
| 1505 | popup_adjust_position(wp); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1506 | } |
| 1507 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1508 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1509 | * popup_setoptions({id}, {options}) |
| 1510 | */ |
| 1511 | void |
| 1512 | f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED) |
| 1513 | { |
| 1514 | dict_T *dict; |
| 1515 | int id = (int)tv_get_number(argvars); |
| 1516 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1517 | linenr_T old_firstline; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1518 | |
| 1519 | if (wp == NULL) |
| 1520 | return; // invalid {id} |
| 1521 | |
| 1522 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 1523 | { |
| 1524 | emsg(_(e_dictreq)); |
| 1525 | return; |
| 1526 | } |
| 1527 | dict = argvars[1].vval.v_dict; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1528 | old_firstline = wp->w_firstline; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1529 | |
| 1530 | apply_move_options(wp, dict); |
| 1531 | apply_general_options(wp, dict); |
| 1532 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1533 | if (old_firstline != wp->w_firstline) |
| 1534 | redraw_win_later(wp, NOT_VALID); |
Bram Moolenaar | ad24a71 | 2019-06-17 20:05:45 +0200 | [diff] [blame] | 1535 | popup_mask_refresh = TRUE; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1536 | popup_adjust_position(wp); |
| 1537 | } |
| 1538 | |
| 1539 | /* |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1540 | * popup_getpos({id}) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1541 | */ |
| 1542 | void |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1543 | f_popup_getpos(typval_T *argvars, typval_T *rettv) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1544 | { |
| 1545 | dict_T *dict; |
| 1546 | int id = (int)tv_get_number(argvars); |
| 1547 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1548 | int top_extra; |
| 1549 | int left_extra; |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1550 | |
| 1551 | if (rettv_dict_alloc(rettv) == OK) |
| 1552 | { |
| 1553 | if (wp == NULL) |
| 1554 | return; // invalid {id} |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 1555 | top_extra = popup_top_extra(wp); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1556 | left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
| 1557 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1558 | dict = rettv->vval.v_dict; |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1559 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1560 | dict_add_number(dict, "line", wp->w_winrow + 1); |
| 1561 | dict_add_number(dict, "col", wp->w_wincol + 1); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1562 | dict_add_number(dict, "width", wp->w_width + left_extra |
| 1563 | + wp->w_popup_border[1] + wp->w_popup_padding[1]); |
| 1564 | dict_add_number(dict, "height", wp->w_height + top_extra |
| 1565 | + wp->w_popup_border[2] + wp->w_popup_padding[2]); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1566 | |
| 1567 | dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra); |
| 1568 | dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra); |
| 1569 | dict_add_number(dict, "core_width", wp->w_width); |
| 1570 | dict_add_number(dict, "core_height", wp->w_height); |
| 1571 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1572 | dict_add_number(dict, "scrollbar", wp->w_has_scrollbar); |
Bram Moolenaar | 68acb41 | 2019-06-26 03:40:36 +0200 | [diff] [blame] | 1573 | dict_add_number(dict, "firstline", wp->w_topline); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1574 | dict_add_number(dict, "visible", |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 1575 | win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1580 | * For popup_getoptions(): add a "border" or "padding" entry to "dict". |
| 1581 | */ |
| 1582 | static void |
| 1583 | get_padding_border(dict_T *dict, int *array, char *name) |
| 1584 | { |
| 1585 | list_T *list; |
| 1586 | int i; |
| 1587 | |
| 1588 | if (array[0] == 0 && array[1] == 0 && array[2] == 0 && array[3] == 0) |
| 1589 | return; |
| 1590 | |
| 1591 | list = list_alloc(); |
| 1592 | if (list != NULL) |
| 1593 | { |
| 1594 | dict_add_list(dict, name, list); |
| 1595 | if (array[0] != 1 || array[1] != 1 || array[2] != 1 || array[3] != 1) |
| 1596 | for (i = 0; i < 4; ++i) |
| 1597 | list_append_number(list, array[i]); |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | /* |
| 1602 | * For popup_getoptions(): add a "borderhighlight" entry to "dict". |
| 1603 | */ |
| 1604 | static void |
| 1605 | get_borderhighlight(dict_T *dict, win_T *wp) |
| 1606 | { |
| 1607 | list_T *list; |
| 1608 | int i; |
| 1609 | |
| 1610 | for (i = 0; i < 4; ++i) |
| 1611 | if (wp->w_border_highlight[i] != NULL) |
| 1612 | break; |
| 1613 | if (i == 4) |
| 1614 | return; |
| 1615 | |
| 1616 | list = list_alloc(); |
| 1617 | if (list != NULL) |
| 1618 | { |
| 1619 | dict_add_list(dict, "borderhighlight", list); |
| 1620 | for (i = 0; i < 4; ++i) |
| 1621 | list_append_string(list, wp->w_border_highlight[i], -1); |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | /* |
| 1626 | * For popup_getoptions(): add a "borderchars" entry to "dict". |
| 1627 | */ |
| 1628 | static void |
| 1629 | get_borderchars(dict_T *dict, win_T *wp) |
| 1630 | { |
| 1631 | list_T *list; |
| 1632 | int i; |
| 1633 | char_u buf[NUMBUFLEN]; |
| 1634 | int len; |
| 1635 | |
| 1636 | for (i = 0; i < 8; ++i) |
| 1637 | if (wp->w_border_char[i] != 0) |
| 1638 | break; |
| 1639 | if (i == 8) |
| 1640 | return; |
| 1641 | |
| 1642 | list = list_alloc(); |
| 1643 | if (list != NULL) |
| 1644 | { |
| 1645 | dict_add_list(dict, "borderchars", list); |
| 1646 | for (i = 0; i < 8; ++i) |
| 1647 | { |
| 1648 | len = mb_char2bytes(wp->w_border_char[i], buf); |
| 1649 | list_append_string(list, buf, len); |
| 1650 | } |
| 1651 | } |
| 1652 | } |
| 1653 | |
| 1654 | /* |
| 1655 | * For popup_getoptions(): add a "moved" entry to "dict". |
| 1656 | */ |
| 1657 | static void |
| 1658 | get_moved_list(dict_T *dict, win_T *wp) |
| 1659 | { |
| 1660 | list_T *list; |
| 1661 | |
| 1662 | list = list_alloc(); |
| 1663 | if (list != NULL) |
| 1664 | { |
| 1665 | dict_add_list(dict, "moved", list); |
| 1666 | list_append_number(list, wp->w_popup_mincol); |
| 1667 | list_append_number(list, wp->w_popup_maxcol); |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | /* |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1672 | * popup_getoptions({id}) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1673 | */ |
| 1674 | void |
| 1675 | f_popup_getoptions(typval_T *argvars, typval_T *rettv) |
| 1676 | { |
| 1677 | dict_T *dict; |
| 1678 | int id = (int)tv_get_number(argvars); |
| 1679 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1680 | tabpage_T *tp; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1681 | int i; |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1682 | |
| 1683 | if (rettv_dict_alloc(rettv) == OK) |
| 1684 | { |
| 1685 | if (wp == NULL) |
| 1686 | return; |
| 1687 | |
| 1688 | dict = rettv->vval.v_dict; |
| 1689 | dict_add_number(dict, "line", wp->w_wantline); |
| 1690 | dict_add_number(dict, "col", wp->w_wantcol); |
| 1691 | dict_add_number(dict, "minwidth", wp->w_minwidth); |
| 1692 | dict_add_number(dict, "minheight", wp->w_minheight); |
| 1693 | dict_add_number(dict, "maxheight", wp->w_maxheight); |
| 1694 | dict_add_number(dict, "maxwidth", wp->w_maxwidth); |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 1695 | dict_add_number(dict, "firstline", wp->w_firstline); |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1696 | dict_add_number(dict, "scrollbar", wp->w_want_scrollbar); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1697 | dict_add_number(dict, "zindex", wp->w_zindex); |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1698 | dict_add_number(dict, "fixed", wp->w_popup_fixed); |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1699 | dict_add_string(dict, "title", wp->w_popup_title); |
| 1700 | dict_add_number(dict, "wrap", wp->w_p_wrap); |
| 1701 | dict_add_number(dict, "drag", wp->w_popup_drag); |
| 1702 | dict_add_string(dict, "highlight", wp->w_p_wcr); |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 1703 | if (wp->w_scrollbar_highlight != NULL) |
| 1704 | dict_add_string(dict, "scrollbarhighlight", |
| 1705 | wp->w_scrollbar_highlight); |
| 1706 | if (wp->w_thumb_highlight != NULL) |
| 1707 | dict_add_string(dict, "thumbhighlight", wp->w_thumb_highlight); |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1708 | |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1709 | // find the tabpage that holds this popup |
| 1710 | i = 1; |
| 1711 | FOR_ALL_TABPAGES(tp) |
| 1712 | { |
| 1713 | win_T *p; |
| 1714 | |
| 1715 | for (p = tp->tp_first_popupwin; p != NULL; p = wp->w_next) |
| 1716 | if (p->w_id == id) |
| 1717 | break; |
| 1718 | if (p != NULL) |
| 1719 | break; |
| 1720 | ++i; |
| 1721 | } |
| 1722 | if (tp == NULL) |
| 1723 | i = -1; // must be global |
| 1724 | else if (tp == curtab) |
| 1725 | i = 0; |
| 1726 | dict_add_number(dict, "tabpage", i); |
| 1727 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1728 | get_padding_border(dict, wp->w_popup_padding, "padding"); |
| 1729 | get_padding_border(dict, wp->w_popup_border, "border"); |
| 1730 | get_borderhighlight(dict, wp); |
| 1731 | get_borderchars(dict, wp); |
| 1732 | get_moved_list(dict, wp); |
| 1733 | |
| 1734 | if (wp->w_filter_cb.cb_name != NULL) |
| 1735 | dict_add_callback(dict, "filter", &wp->w_filter_cb); |
| 1736 | if (wp->w_close_cb.cb_name != NULL) |
| 1737 | dict_add_callback(dict, "callback", &wp->w_close_cb); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1738 | |
| 1739 | for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); |
| 1740 | ++i) |
| 1741 | if (wp->w_popup_pos == poppos_entries[i].pp_val) |
| 1742 | { |
| 1743 | dict_add_string(dict, "pos", |
| 1744 | (char_u *)poppos_entries[i].pp_name); |
| 1745 | break; |
| 1746 | } |
| 1747 | |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1748 | # if defined(FEAT_TIMERS) |
| 1749 | dict_add_number(dict, "time", wp->w_popup_timer != NULL |
| 1750 | ? (long)wp->w_popup_timer->tr_interval : 0L); |
| 1751 | # endif |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1752 | } |
| 1753 | } |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 1754 | |
| 1755 | int |
Bram Moolenaar | 8cdbd5b | 2019-06-16 15:50:45 +0200 | [diff] [blame] | 1756 | error_if_popup_window() |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 1757 | { |
| 1758 | if (bt_popup(curwin->w_buffer)) |
| 1759 | { |
| 1760 | emsg(_("E994: Not allowed in a popup window")); |
| 1761 | return TRUE; |
| 1762 | } |
| 1763 | return FALSE; |
| 1764 | } |
| 1765 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1766 | /* |
| 1767 | * Reset all the POPF_HANDLED flags in global popup windows and popup windows |
Bram Moolenaar | fc06cbb | 2019-06-15 14:14:31 +0200 | [diff] [blame] | 1768 | * in the current tab page. |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1769 | */ |
| 1770 | void |
| 1771 | popup_reset_handled() |
| 1772 | { |
| 1773 | win_T *wp; |
| 1774 | |
| 1775 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 1776 | wp->w_popup_flags &= ~POPF_HANDLED; |
| 1777 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 1778 | wp->w_popup_flags &= ~POPF_HANDLED; |
| 1779 | } |
| 1780 | |
| 1781 | /* |
| 1782 | * Find the next visible popup where POPF_HANDLED is not set. |
| 1783 | * Must have called popup_reset_handled() first. |
| 1784 | * When "lowest" is TRUE find the popup with the lowest zindex, otherwise the |
| 1785 | * popup with the highest zindex. |
| 1786 | */ |
| 1787 | win_T * |
| 1788 | find_next_popup(int lowest) |
| 1789 | { |
| 1790 | win_T *wp; |
| 1791 | win_T *found_wp; |
| 1792 | int found_zindex; |
| 1793 | |
| 1794 | found_zindex = lowest ? INT_MAX : 0; |
| 1795 | found_wp = NULL; |
| 1796 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 1797 | if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0 |
| 1798 | && (lowest ? wp->w_zindex < found_zindex |
| 1799 | : wp->w_zindex > found_zindex)) |
| 1800 | { |
| 1801 | found_zindex = wp->w_zindex; |
| 1802 | found_wp = wp; |
| 1803 | } |
| 1804 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 1805 | if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0 |
| 1806 | && (lowest ? wp->w_zindex < found_zindex |
| 1807 | : wp->w_zindex > found_zindex)) |
| 1808 | { |
| 1809 | found_zindex = wp->w_zindex; |
| 1810 | found_wp = wp; |
| 1811 | } |
| 1812 | |
| 1813 | if (found_wp != NULL) |
| 1814 | found_wp->w_popup_flags |= POPF_HANDLED; |
| 1815 | return found_wp; |
| 1816 | } |
| 1817 | |
| 1818 | /* |
| 1819 | * Invoke the filter callback for window "wp" with typed character "c". |
| 1820 | * Uses the global "mod_mask" for modifiers. |
| 1821 | * Returns the return value of the filter. |
| 1822 | * Careful: The filter may make "wp" invalid! |
| 1823 | */ |
| 1824 | static int |
| 1825 | invoke_popup_filter(win_T *wp, int c) |
| 1826 | { |
| 1827 | int res; |
| 1828 | typval_T rettv; |
| 1829 | int dummy; |
| 1830 | typval_T argv[3]; |
| 1831 | char_u buf[NUMBUFLEN]; |
| 1832 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1833 | // Emergency exit: CTRL-C closes the popup. |
| 1834 | if (c == Ctrl_C) |
| 1835 | { |
| 1836 | rettv.v_type = VAR_NUMBER; |
| 1837 | rettv.vval.v_number = -1; |
| 1838 | popup_close_and_callback(wp, &rettv); |
| 1839 | return 1; |
| 1840 | } |
| 1841 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1842 | argv[0].v_type = VAR_NUMBER; |
| 1843 | argv[0].vval.v_number = (varnumber_T)wp->w_id; |
| 1844 | |
| 1845 | // Convert the number to a string, so that the function can use: |
| 1846 | // if a:c == "\<F2>" |
| 1847 | buf[special_to_buf(c, mod_mask, TRUE, buf)] = NUL; |
| 1848 | argv[1].v_type = VAR_STRING; |
| 1849 | argv[1].vval.v_string = vim_strsave(buf); |
| 1850 | |
| 1851 | argv[2].v_type = VAR_UNKNOWN; |
| 1852 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1853 | // NOTE: The callback might close the popup, thus make "wp" invalid. |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1854 | call_callback(&wp->w_filter_cb, -1, |
| 1855 | &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
| 1856 | res = tv_get_number(&rettv); |
| 1857 | vim_free(argv[1].vval.v_string); |
| 1858 | clear_tv(&rettv); |
| 1859 | return res; |
| 1860 | } |
| 1861 | |
| 1862 | /* |
| 1863 | * Called when "c" was typed: invoke popup filter callbacks. |
| 1864 | * Returns TRUE when the character was consumed, |
| 1865 | */ |
| 1866 | int |
| 1867 | popup_do_filter(int c) |
| 1868 | { |
| 1869 | int res = FALSE; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1870 | win_T *wp; |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1871 | |
| 1872 | popup_reset_handled(); |
| 1873 | |
| 1874 | while (!res && (wp = find_next_popup(FALSE)) != NULL) |
| 1875 | if (wp->w_filter_cb.cb_name != NULL) |
| 1876 | res = invoke_popup_filter(wp, c); |
| 1877 | |
| 1878 | return res; |
| 1879 | } |
| 1880 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1881 | /* |
| 1882 | * Called when the cursor moved: check if any popup needs to be closed if the |
| 1883 | * cursor moved far enough. |
| 1884 | */ |
| 1885 | void |
| 1886 | popup_check_cursor_pos() |
| 1887 | { |
| 1888 | win_T *wp; |
| 1889 | typval_T tv; |
| 1890 | |
| 1891 | popup_reset_handled(); |
| 1892 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 1893 | if (wp->w_popup_curwin != NULL |
| 1894 | && (curwin != wp->w_popup_curwin |
| 1895 | || curwin->w_cursor.lnum != wp->w_popup_lnum |
| 1896 | || curwin->w_cursor.col < wp->w_popup_mincol |
| 1897 | || curwin->w_cursor.col > wp->w_popup_maxcol)) |
| 1898 | { |
| 1899 | tv.v_type = VAR_NUMBER; |
| 1900 | tv.vval.v_number = -1; |
| 1901 | popup_close_and_callback(wp, &tv); |
| 1902 | } |
| 1903 | } |
| 1904 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 1905 | /* |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 1906 | * Return TRUE if "col" / "line" matches with an entry in w_popup_mask. |
| 1907 | * "col" and "line" are screen coordinates. |
| 1908 | */ |
| 1909 | static int |
| 1910 | popup_masked(win_T *wp, int screencol, int screenline) |
| 1911 | { |
| 1912 | int col = screencol - wp->w_wincol + 1; |
| 1913 | int line = screenline - wp->w_winrow + 1; |
| 1914 | listitem_T *lio, *li; |
| 1915 | int width, height; |
| 1916 | |
| 1917 | if (wp->w_popup_mask == NULL) |
| 1918 | return FALSE; |
| 1919 | width = popup_width(wp); |
| 1920 | height = popup_height(wp); |
| 1921 | |
| 1922 | for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next) |
| 1923 | { |
| 1924 | int cols, cole; |
| 1925 | int lines, linee; |
| 1926 | |
| 1927 | li = lio->li_tv.vval.v_list->lv_first; |
| 1928 | cols = tv_get_number(&li->li_tv); |
| 1929 | if (cols < 0) |
| 1930 | cols = width + cols + 1; |
| 1931 | if (col < cols) |
| 1932 | continue; |
| 1933 | li = li->li_next; |
| 1934 | cole = tv_get_number(&li->li_tv); |
| 1935 | if (cole < 0) |
| 1936 | cole = width + cole + 1; |
| 1937 | if (col > cole) |
| 1938 | continue; |
| 1939 | li = li->li_next; |
| 1940 | lines = tv_get_number(&li->li_tv); |
| 1941 | if (lines < 0) |
| 1942 | lines = height + lines + 1; |
| 1943 | if (line < lines) |
| 1944 | continue; |
| 1945 | li = li->li_next; |
| 1946 | linee = tv_get_number(&li->li_tv); |
| 1947 | if (linee < 0) |
| 1948 | linee = height + linee + 1; |
| 1949 | if (line > linee) |
| 1950 | continue; |
| 1951 | return TRUE; |
| 1952 | } |
| 1953 | return FALSE; |
| 1954 | } |
| 1955 | |
| 1956 | /* |
| 1957 | * Set flags in popup_transparent[] for window "wp" to "val". |
| 1958 | */ |
| 1959 | static void |
| 1960 | update_popup_transparent(win_T *wp, int val) |
| 1961 | { |
| 1962 | if (wp->w_popup_mask != NULL) |
| 1963 | { |
| 1964 | int width = popup_width(wp); |
| 1965 | int height = popup_height(wp); |
| 1966 | listitem_T *lio, *li; |
| 1967 | int cols, cole; |
| 1968 | int lines, linee; |
| 1969 | int col, line; |
| 1970 | |
| 1971 | for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next) |
| 1972 | { |
| 1973 | li = lio->li_tv.vval.v_list->lv_first; |
| 1974 | cols = tv_get_number(&li->li_tv); |
| 1975 | if (cols < 0) |
| 1976 | cols = width + cols + 1; |
| 1977 | li = li->li_next; |
| 1978 | cole = tv_get_number(&li->li_tv); |
| 1979 | if (cole < 0) |
| 1980 | cole = width + cole + 1; |
| 1981 | li = li->li_next; |
| 1982 | lines = tv_get_number(&li->li_tv); |
| 1983 | if (lines < 0) |
| 1984 | lines = height + lines + 1; |
| 1985 | li = li->li_next; |
| 1986 | linee = tv_get_number(&li->li_tv); |
| 1987 | if (linee < 0) |
| 1988 | linee = height + linee + 1; |
| 1989 | |
| 1990 | --cols; |
| 1991 | --lines; |
| 1992 | for (line = lines; line < linee && line < screen_Rows; ++line) |
| 1993 | for (col = cols; col < cole && col < screen_Columns; ++col) |
| 1994 | popup_transparent[(line + wp->w_winrow) * screen_Columns |
| 1995 | + col + wp->w_wincol] = val; |
| 1996 | } |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | /* |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2001 | * Update "popup_mask" if needed. |
| 2002 | * Also recomputes the popup size and positions. |
| 2003 | * Also updates "popup_visible". |
| 2004 | * Also marks window lines for redrawing. |
| 2005 | */ |
| 2006 | void |
| 2007 | may_update_popup_mask(int type) |
| 2008 | { |
| 2009 | win_T *wp; |
| 2010 | short *mask; |
| 2011 | int line, col; |
| 2012 | int redraw_all = FALSE; |
| 2013 | |
| 2014 | // Need to recompute when switching tabs. |
| 2015 | // Also recompute when the type is CLEAR or NOT_VALID, something basic |
| 2016 | // (such as the screen size) must have changed. |
| 2017 | if (popup_mask_tab != curtab || type >= NOT_VALID) |
| 2018 | { |
| 2019 | popup_mask_refresh = TRUE; |
| 2020 | redraw_all = TRUE; |
| 2021 | } |
| 2022 | if (!popup_mask_refresh) |
| 2023 | { |
| 2024 | // Check if any buffer has changed. |
| 2025 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 2026 | if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 2027 | popup_mask_refresh = TRUE; |
| 2028 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 2029 | if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 2030 | popup_mask_refresh = TRUE; |
| 2031 | if (!popup_mask_refresh) |
| 2032 | return; |
| 2033 | } |
| 2034 | |
| 2035 | // Need to update the mask, something has changed. |
| 2036 | popup_mask_refresh = FALSE; |
| 2037 | popup_mask_tab = curtab; |
| 2038 | popup_visible = FALSE; |
| 2039 | |
| 2040 | // If redrawing everything, just update "popup_mask". |
| 2041 | // If redrawing only what is needed, update "popup_mask_next" and then |
| 2042 | // compare with "popup_mask" to see what changed. |
| 2043 | if (type >= SOME_VALID) |
| 2044 | mask = popup_mask; |
| 2045 | else |
| 2046 | mask = popup_mask_next; |
| 2047 | vim_memset(mask, 0, screen_Rows * screen_Columns * sizeof(short)); |
| 2048 | |
| 2049 | // Find the window with the lowest zindex that hasn't been handled yet, |
| 2050 | // so that the window with a higher zindex overwrites the value in |
| 2051 | // popup_mask. |
| 2052 | popup_reset_handled(); |
| 2053 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 2054 | { |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2055 | int height = popup_height(wp); |
| 2056 | int width = popup_width(wp); |
| 2057 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2058 | popup_visible = TRUE; |
| 2059 | |
| 2060 | // Recompute the position if the text changed. |
| 2061 | if (redraw_all |
| 2062 | || wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 2063 | popup_adjust_position(wp); |
| 2064 | |
| 2065 | for (line = wp->w_winrow; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2066 | line < wp->w_winrow + height && line < screen_Rows; ++line) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2067 | for (col = wp->w_wincol; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2068 | col < wp->w_wincol + width && col < screen_Columns; ++col) |
| 2069 | if (!popup_masked(wp, col, line)) |
| 2070 | mask[line * screen_Columns + col] = wp->w_zindex; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | // Only check which lines are to be updated if not already |
| 2074 | // updating all lines. |
| 2075 | if (mask == popup_mask_next) |
| 2076 | for (line = 0; line < screen_Rows; ++line) |
| 2077 | { |
| 2078 | int col_done = 0; |
| 2079 | |
| 2080 | for (col = 0; col < screen_Columns; ++col) |
| 2081 | { |
| 2082 | int off = line * screen_Columns + col; |
| 2083 | |
| 2084 | if (popup_mask[off] != popup_mask_next[off]) |
| 2085 | { |
| 2086 | popup_mask[off] = popup_mask_next[off]; |
| 2087 | |
| 2088 | if (line >= cmdline_row) |
| 2089 | { |
| 2090 | // the command line needs to be cleared if text below |
| 2091 | // the popup is now visible. |
| 2092 | if (!msg_scrolled && popup_mask_next[off] == 0) |
| 2093 | clear_cmdline = TRUE; |
| 2094 | } |
| 2095 | else if (col >= col_done) |
| 2096 | { |
| 2097 | linenr_T lnum; |
| 2098 | int line_cp = line; |
| 2099 | int col_cp = col; |
| 2100 | |
| 2101 | // The screen position "line" / "col" needs to be |
| 2102 | // redrawn. Figure out what window that is and update |
| 2103 | // w_redraw_top and w_redr_bot. Only needs to be done |
| 2104 | // once for each window line. |
| 2105 | wp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP); |
| 2106 | if (wp != NULL) |
| 2107 | { |
| 2108 | if (line_cp >= wp->w_height) |
| 2109 | // In (or below) status line |
| 2110 | wp->w_redr_status = TRUE; |
| 2111 | // compute the position in the buffer line from the |
| 2112 | // position on the screen |
| 2113 | else if (mouse_comp_pos(wp, &line_cp, &col_cp, |
| 2114 | &lnum)) |
| 2115 | // past bottom |
| 2116 | wp->w_redr_status = TRUE; |
| 2117 | else |
| 2118 | redrawWinline(wp, lnum); |
| 2119 | |
| 2120 | // This line is going to be redrawn, no need to |
| 2121 | // check until the right side of the window. |
| 2122 | col_done = wp->w_wincol + wp->w_width - 1; |
| 2123 | } |
| 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | /* |
| 2131 | * Return a string of "len" spaces in IObuff. |
| 2132 | */ |
| 2133 | static char_u * |
| 2134 | get_spaces(int len) |
| 2135 | { |
| 2136 | vim_memset(IObuff, ' ', (size_t)len); |
| 2137 | IObuff[len] = NUL; |
| 2138 | return IObuff; |
| 2139 | } |
| 2140 | |
| 2141 | /* |
| 2142 | * Update popup windows. They are drawn on top of normal windows. |
| 2143 | * "win_update" is called for each popup window, lowest zindex first. |
| 2144 | */ |
| 2145 | void |
| 2146 | update_popups(void (*win_update)(win_T *wp)) |
| 2147 | { |
| 2148 | win_T *wp; |
| 2149 | int top_off; |
| 2150 | int left_off; |
| 2151 | int total_width; |
| 2152 | int total_height; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2153 | int top_padding; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2154 | int popup_attr; |
| 2155 | int border_attr[4]; |
| 2156 | int border_char[8]; |
| 2157 | char_u buf[MB_MAXBYTES]; |
| 2158 | int row; |
| 2159 | int i; |
Bram Moolenaar | 6efd76a | 2019-06-26 04:06:57 +0200 | [diff] [blame] | 2160 | int sb_thumb_top = 0; |
| 2161 | int sb_thumb_height = 0; |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 2162 | int attr_scroll = 0; |
| 2163 | int attr_thumb = 0; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2164 | |
| 2165 | // Find the window with the lowest zindex that hasn't been updated yet, |
| 2166 | // so that the window with a higher zindex is drawn later, thus goes on |
| 2167 | // top. |
| 2168 | popup_reset_handled(); |
| 2169 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 2170 | { |
| 2171 | // This drawing uses the zindex of the popup window, so that it's on |
| 2172 | // top of the text but doesn't draw when another popup with higher |
| 2173 | // zindex is on top of the character. |
| 2174 | screen_zindex = wp->w_zindex; |
| 2175 | |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2176 | // Set flags in popup_transparent[] for masked cells. |
| 2177 | update_popup_transparent(wp, 1); |
| 2178 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2179 | // adjust w_winrow and w_wincol for border and padding, since |
| 2180 | // win_update() doesn't handle them. |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2181 | top_off = popup_top_extra(wp); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2182 | left_off = wp->w_popup_padding[3] + wp->w_popup_border[3]; |
| 2183 | wp->w_winrow += top_off; |
| 2184 | wp->w_wincol += left_off; |
| 2185 | |
Bram Moolenaar | c2a4316 | 2019-06-26 01:03:53 +0200 | [diff] [blame] | 2186 | // Draw the popup text, unless it's off screen. |
| 2187 | if (wp->w_winrow < screen_Rows && wp->w_wincol < screen_Columns) |
| 2188 | win_update(wp); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2189 | |
| 2190 | wp->w_winrow -= top_off; |
| 2191 | wp->w_wincol -= left_off; |
| 2192 | |
| 2193 | total_width = wp->w_popup_border[3] + wp->w_popup_padding[3] |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2194 | + wp->w_width + wp->w_popup_padding[1] + wp->w_popup_border[1] |
| 2195 | + wp->w_has_scrollbar; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2196 | total_height = popup_top_extra(wp) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2197 | + wp->w_height + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
| 2198 | popup_attr = get_wcr_attr(wp); |
| 2199 | |
| 2200 | // We can only use these line drawing characters when 'encoding' is |
| 2201 | // "utf-8" and 'ambiwidth' is "single". |
| 2202 | if (enc_utf8 && *p_ambw == 's') |
| 2203 | { |
| 2204 | border_char[0] = border_char[2] = 0x2550; |
| 2205 | border_char[1] = border_char[3] = 0x2551; |
| 2206 | border_char[4] = 0x2554; |
| 2207 | border_char[5] = 0x2557; |
| 2208 | border_char[6] = 0x255d; |
| 2209 | border_char[7] = 0x255a; |
| 2210 | } |
| 2211 | else |
| 2212 | { |
| 2213 | border_char[0] = border_char[2] = '-'; |
| 2214 | border_char[1] = border_char[3] = '|'; |
| 2215 | for (i = 4; i < 8; ++i) |
| 2216 | border_char[i] = '+'; |
| 2217 | } |
| 2218 | for (i = 0; i < 8; ++i) |
| 2219 | if (wp->w_border_char[i] != 0) |
| 2220 | border_char[i] = wp->w_border_char[i]; |
| 2221 | |
| 2222 | for (i = 0; i < 4; ++i) |
| 2223 | { |
| 2224 | border_attr[i] = popup_attr; |
| 2225 | if (wp->w_border_highlight[i] != NULL) |
| 2226 | border_attr[i] = syn_name2attr(wp->w_border_highlight[i]); |
| 2227 | } |
| 2228 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2229 | top_padding = wp->w_popup_padding[0]; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2230 | if (wp->w_popup_border[0] > 0) |
| 2231 | { |
| 2232 | // top border |
| 2233 | screen_fill(wp->w_winrow, wp->w_winrow + 1, |
| 2234 | wp->w_wincol, |
| 2235 | wp->w_wincol + total_width, |
| 2236 | wp->w_popup_border[3] != 0 |
| 2237 | ? border_char[4] : border_char[0], |
| 2238 | border_char[0], border_attr[0]); |
| 2239 | if (wp->w_popup_border[1] > 0) |
| 2240 | { |
| 2241 | buf[mb_char2bytes(border_char[5], buf)] = NUL; |
| 2242 | screen_puts(buf, wp->w_winrow, |
| 2243 | wp->w_wincol + total_width - 1, border_attr[1]); |
| 2244 | } |
| 2245 | } |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2246 | else if (wp->w_popup_padding[0] == 0 && popup_top_extra(wp) > 0) |
| 2247 | top_padding = 1; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2248 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2249 | if (top_padding > 0) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2250 | { |
| 2251 | // top padding |
| 2252 | row = wp->w_winrow + wp->w_popup_border[0]; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2253 | screen_fill(row, row + top_padding, |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2254 | wp->w_wincol + wp->w_popup_border[3], |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2255 | wp->w_wincol + total_width - wp->w_popup_border[1] |
| 2256 | - wp->w_has_scrollbar, |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2257 | ' ', ' ', popup_attr); |
| 2258 | } |
| 2259 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2260 | // Title goes on top of border or padding. |
| 2261 | if (wp->w_popup_title != NULL) |
| 2262 | screen_puts(wp->w_popup_title, wp->w_winrow, wp->w_wincol + 1, |
| 2263 | wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr); |
| 2264 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2265 | // Compute scrollbar thumb position and size. |
| 2266 | if (wp->w_has_scrollbar) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2267 | { |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2268 | linenr_T linecount = wp->w_buffer->b_ml.ml_line_count; |
| 2269 | |
Bram Moolenaar | 68acb41 | 2019-06-26 03:40:36 +0200 | [diff] [blame] | 2270 | sb_thumb_height = (wp->w_height * wp->w_height + linecount / 2) |
| 2271 | / linecount; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2272 | if (sb_thumb_height == 0) |
| 2273 | sb_thumb_height = 1; |
Bram Moolenaar | 68acb41 | 2019-06-26 03:40:36 +0200 | [diff] [blame] | 2274 | sb_thumb_top = (wp->w_topline - 1 + (linecount / wp->w_height) / 2) |
| 2275 | * (wp->w_height - sb_thumb_height) |
| 2276 | / (linecount - wp->w_height); |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 2277 | if (wp->w_scrollbar_highlight != NULL) |
| 2278 | attr_scroll = syn_name2attr(wp->w_scrollbar_highlight); |
| 2279 | else |
| 2280 | attr_scroll = highlight_attr[HLF_PSB]; |
| 2281 | if (wp->w_thumb_highlight != NULL) |
| 2282 | attr_thumb = syn_name2attr(wp->w_thumb_highlight); |
| 2283 | else |
| 2284 | attr_thumb = highlight_attr[HLF_PST]; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | for (i = wp->w_popup_border[0]; |
| 2288 | i < total_height - wp->w_popup_border[2]; ++i) |
| 2289 | { |
| 2290 | row = wp->w_winrow + i; |
| 2291 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2292 | // left border |
| 2293 | if (wp->w_popup_border[3] > 0) |
| 2294 | { |
| 2295 | buf[mb_char2bytes(border_char[3], buf)] = NUL; |
| 2296 | screen_puts(buf, row, wp->w_wincol, border_attr[3]); |
| 2297 | } |
| 2298 | // left padding |
| 2299 | if (wp->w_popup_padding[3] > 0) |
| 2300 | screen_puts(get_spaces(wp->w_popup_padding[3]), row, |
| 2301 | wp->w_wincol + wp->w_popup_border[3], popup_attr); |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2302 | // scrollbar |
| 2303 | if (wp->w_has_scrollbar) |
| 2304 | { |
| 2305 | int line = i - top_off; |
| 2306 | int scroll_col = wp->w_wincol + total_width - 1 |
| 2307 | - wp->w_popup_border[1]; |
| 2308 | |
| 2309 | if (line >= 0 && line < wp->w_height) |
| 2310 | screen_putchar(' ', row, scroll_col, |
| 2311 | line >= sb_thumb_top |
| 2312 | && line < sb_thumb_top + sb_thumb_height |
| 2313 | ? attr_thumb : attr_scroll); |
| 2314 | else |
| 2315 | screen_putchar(' ', row, scroll_col, popup_attr); |
| 2316 | } |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2317 | // right border |
| 2318 | if (wp->w_popup_border[1] > 0) |
| 2319 | { |
| 2320 | buf[mb_char2bytes(border_char[1], buf)] = NUL; |
| 2321 | screen_puts(buf, row, |
| 2322 | wp->w_wincol + total_width - 1, border_attr[1]); |
| 2323 | } |
| 2324 | // right padding |
| 2325 | if (wp->w_popup_padding[1] > 0) |
| 2326 | screen_puts(get_spaces(wp->w_popup_padding[1]), row, |
| 2327 | wp->w_wincol + wp->w_popup_border[3] |
| 2328 | + wp->w_popup_padding[3] + wp->w_width, popup_attr); |
| 2329 | } |
| 2330 | |
| 2331 | if (wp->w_popup_padding[2] > 0) |
| 2332 | { |
| 2333 | // bottom padding |
| 2334 | row = wp->w_winrow + wp->w_popup_border[0] |
| 2335 | + wp->w_popup_padding[0] + wp->w_height; |
| 2336 | screen_fill(row, row + wp->w_popup_padding[2], |
| 2337 | wp->w_wincol + wp->w_popup_border[3], |
| 2338 | wp->w_wincol + total_width - wp->w_popup_border[1], |
| 2339 | ' ', ' ', popup_attr); |
| 2340 | } |
| 2341 | |
| 2342 | if (wp->w_popup_border[2] > 0) |
| 2343 | { |
| 2344 | // bottom border |
| 2345 | row = wp->w_winrow + total_height - 1; |
| 2346 | screen_fill(row , row + 1, |
| 2347 | wp->w_wincol, |
| 2348 | wp->w_wincol + total_width, |
| 2349 | wp->w_popup_border[3] != 0 |
| 2350 | ? border_char[7] : border_char[2], |
| 2351 | border_char[2], border_attr[2]); |
| 2352 | if (wp->w_popup_border[1] > 0) |
| 2353 | { |
| 2354 | buf[mb_char2bytes(border_char[6], buf)] = NUL; |
| 2355 | screen_puts(buf, row, |
| 2356 | wp->w_wincol + total_width - 1, border_attr[2]); |
| 2357 | } |
| 2358 | } |
| 2359 | |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2360 | update_popup_transparent(wp, 0); |
| 2361 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2362 | // Back to the normal zindex. |
| 2363 | screen_zindex = 0; |
| 2364 | } |
| 2365 | } |
| 2366 | |
Bram Moolenaar | 75a1a94 | 2019-06-20 03:45:36 +0200 | [diff] [blame] | 2367 | /* |
| 2368 | * Mark references in callbacks of one popup window. |
| 2369 | */ |
| 2370 | static int |
| 2371 | set_ref_in_one_popup(win_T *wp, int copyID) |
| 2372 | { |
| 2373 | int abort = FALSE; |
| 2374 | typval_T tv; |
| 2375 | |
| 2376 | if (wp->w_close_cb.cb_partial != NULL) |
| 2377 | { |
| 2378 | tv.v_type = VAR_PARTIAL; |
| 2379 | tv.vval.v_partial = wp->w_close_cb.cb_partial; |
| 2380 | abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); |
| 2381 | } |
| 2382 | if (wp->w_filter_cb.cb_partial != NULL) |
| 2383 | { |
| 2384 | tv.v_type = VAR_PARTIAL; |
| 2385 | tv.vval.v_partial = wp->w_filter_cb.cb_partial; |
| 2386 | abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); |
| 2387 | } |
Bram Moolenaar | 7be3ab2 | 2019-06-23 01:46:15 +0200 | [diff] [blame] | 2388 | abort = abort || set_ref_in_list(wp->w_popup_mask, copyID); |
Bram Moolenaar | 75a1a94 | 2019-06-20 03:45:36 +0200 | [diff] [blame] | 2389 | return abort; |
| 2390 | } |
| 2391 | |
| 2392 | /* |
| 2393 | * Set reference in callbacks of popup windows. |
| 2394 | */ |
| 2395 | int |
| 2396 | set_ref_in_popups(int copyID) |
| 2397 | { |
| 2398 | int abort = FALSE; |
| 2399 | win_T *wp; |
| 2400 | tabpage_T *tp; |
| 2401 | |
| 2402 | for (wp = first_popupwin; !abort && wp != NULL; wp = wp->w_next) |
| 2403 | abort = abort || set_ref_in_one_popup(wp, copyID); |
| 2404 | |
| 2405 | FOR_ALL_TABPAGES(tp) |
| 2406 | { |
| 2407 | for (wp = tp->tp_first_popupwin; !abort && wp != NULL; wp = wp->w_next) |
| 2408 | abort = abort || set_ref_in_one_popup(wp, copyID); |
| 2409 | if (abort) |
| 2410 | break; |
| 2411 | } |
| 2412 | return abort; |
| 2413 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2414 | #endif // FEAT_TEXT_PROP |