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 | |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 16 | #if defined(FEAT_TEXT_PROP) || defined(PROTO) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 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; |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 81 | dictitem_T *di; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 82 | |
| 83 | nr = popup_options_one(dict, (char_u *)"line"); |
| 84 | if (nr > 0) |
| 85 | wp->w_wantline = nr; |
| 86 | nr = popup_options_one(dict, (char_u *)"col"); |
| 87 | if (nr > 0) |
| 88 | wp->w_wantcol = nr; |
| 89 | |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 90 | di = dict_find(dict, (char_u *)"fixed", -1); |
| 91 | if (di != NULL) |
| 92 | wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 93 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 94 | str = dict_get_string(dict, (char_u *)"pos", FALSE); |
| 95 | if (str != NULL) |
| 96 | { |
| 97 | for (nr = 0; |
| 98 | nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); |
| 99 | ++nr) |
| 100 | if (STRCMP(str, poppos_entries[nr].pp_name) == 0) |
| 101 | { |
| 102 | wp->w_popup_pos = poppos_entries[nr].pp_val; |
| 103 | nr = -1; |
| 104 | break; |
| 105 | } |
| 106 | if (nr != -1) |
| 107 | semsg(_(e_invarg2), str); |
| 108 | } |
| 109 | } |
| 110 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 111 | static void |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 112 | 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] | 113 | { |
| 114 | dictitem_T *di; |
| 115 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 116 | di = dict_find(dict, (char_u *)name, -1); |
| 117 | if (di != NULL) |
| 118 | { |
| 119 | if (di->di_tv.v_type != VAR_LIST) |
| 120 | emsg(_(e_listreq)); |
| 121 | else |
| 122 | { |
| 123 | list_T *list = di->di_tv.vval.v_list; |
| 124 | listitem_T *li; |
| 125 | int i; |
| 126 | int nr; |
| 127 | |
| 128 | for (i = 0; i < 4; ++i) |
| 129 | array[i] = 1; |
| 130 | if (list != NULL) |
| 131 | for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len; |
| 132 | ++i, li = li->li_next) |
| 133 | { |
| 134 | nr = (int)tv_get_number(&li->li_tv); |
| 135 | if (nr >= 0) |
| 136 | array[i] = nr > max_val ? max_val : nr; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 142 | /* |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 143 | * Used when popup options contain "moved": set default moved values. |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 144 | */ |
| 145 | static void |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 146 | set_moved_values(win_T *wp) |
| 147 | { |
| 148 | wp->w_popup_curwin = curwin; |
| 149 | wp->w_popup_lnum = curwin->w_cursor.lnum; |
| 150 | wp->w_popup_mincol = curwin->w_cursor.col; |
| 151 | wp->w_popup_maxcol = curwin->w_cursor.col; |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Used when popup options contain "moved" with "word" or "WORD". |
| 156 | */ |
| 157 | static void |
| 158 | set_moved_columns(win_T *wp, int flags) |
| 159 | { |
| 160 | char_u *ptr; |
| 161 | int len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR); |
| 162 | |
| 163 | if (len > 0) |
| 164 | { |
| 165 | wp->w_popup_mincol = (int)(ptr - ml_get_curline()); |
| 166 | wp->w_popup_maxcol = wp->w_popup_mincol + len - 1; |
| 167 | } |
| 168 | } |
| 169 | |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 170 | /* |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 171 | * Used when popup options contain "mousemoved": set default moved values. |
| 172 | */ |
| 173 | static void |
| 174 | set_mousemoved_values(win_T *wp) |
| 175 | { |
| 176 | wp->w_popup_mouse_row = mouse_row; |
| 177 | wp->w_popup_mouse_mincol = mouse_col; |
| 178 | wp->w_popup_mouse_maxcol = mouse_col; |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * Used when popup options contain "moved" with "word" or "WORD". |
| 183 | */ |
| 184 | static void |
| 185 | set_mousemoved_columns(win_T *wp, int flags) |
| 186 | { |
Bram Moolenaar | b05caa7 | 2019-07-10 21:55:54 +0200 | [diff] [blame] | 187 | win_T *textwp; |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 188 | char_u *text; |
| 189 | int col; |
Bram Moolenaar | b05caa7 | 2019-07-10 21:55:54 +0200 | [diff] [blame] | 190 | pos_T pos; |
| 191 | colnr_T mcol; |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 192 | |
| 193 | if (find_word_under_cursor(mouse_row, mouse_col, TRUE, flags, |
Bram Moolenaar | b05caa7 | 2019-07-10 21:55:54 +0200 | [diff] [blame] | 194 | &textwp, &pos.lnum, &text, NULL, &col) == OK) |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 195 | { |
Bram Moolenaar | b05caa7 | 2019-07-10 21:55:54 +0200 | [diff] [blame] | 196 | // convert text column to mouse column |
| 197 | pos.col = col; |
| 198 | pos.coladd = 0; |
| 199 | getvcol(textwp, &pos, &mcol, NULL, NULL); |
| 200 | wp->w_popup_mouse_mincol = mcol; |
| 201 | |
Bram Moolenaar | 1072768 | 2019-07-12 13:59:20 +0200 | [diff] [blame] | 202 | pos.col = col + (colnr_T)STRLEN(text) - 1; |
Bram Moolenaar | b05caa7 | 2019-07-10 21:55:54 +0200 | [diff] [blame] | 203 | getvcol(textwp, &pos, NULL, NULL, &mcol); |
| 204 | wp->w_popup_mouse_maxcol = mcol; |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 205 | vim_free(text); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /* |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 210 | * Return TRUE if "row"/"col" is on the border of the popup. |
| 211 | * The values are relative to the top-left corner. |
| 212 | */ |
| 213 | int |
| 214 | popup_on_border(win_T *wp, int row, int col) |
| 215 | { |
| 216 | return (row == 0 && wp->w_popup_border[0] > 0) |
| 217 | || (row == popup_height(wp) - 1 && wp->w_popup_border[2] > 0) |
| 218 | || (col == 0 && wp->w_popup_border[3] > 0) |
| 219 | || (col == popup_width(wp) - 1 && wp->w_popup_border[1] > 0); |
| 220 | } |
| 221 | |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 222 | /* |
| 223 | * Return TRUE if "row"/"col" is on the "X" button of the popup. |
| 224 | * The values are relative to the top-left corner. |
| 225 | * Caller should check w_popup_close is POPCLOSE_BUTTON. |
| 226 | */ |
| 227 | int |
| 228 | popup_on_X_button(win_T *wp, int row, int col) |
| 229 | { |
| 230 | return row == 0 && col == popup_width(wp) - 1; |
| 231 | } |
| 232 | |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 233 | // Values set when dragging a popup window starts. |
| 234 | static int drag_start_row; |
| 235 | static int drag_start_col; |
| 236 | static int drag_start_wantline; |
| 237 | static int drag_start_wantcol; |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 238 | static int drag_on_resize_handle; |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 239 | |
| 240 | /* |
| 241 | * Mouse down on border of popup window: start dragging it. |
| 242 | * Uses mouse_col and mouse_row. |
| 243 | */ |
| 244 | void |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 245 | popup_start_drag(win_T *wp, int row, int col) |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 246 | { |
| 247 | drag_start_row = mouse_row; |
| 248 | drag_start_col = mouse_col; |
| 249 | // TODO: handle using different corner |
| 250 | if (wp->w_wantline == 0) |
| 251 | drag_start_wantline = wp->w_winrow + 1; |
| 252 | else |
| 253 | drag_start_wantline = wp->w_wantline; |
| 254 | if (wp->w_wantcol == 0) |
| 255 | drag_start_wantcol = wp->w_wincol + 1; |
| 256 | else |
| 257 | drag_start_wantcol = wp->w_wantcol; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 258 | |
| 259 | // Stop centering the popup |
| 260 | if (wp->w_popup_pos == POPPOS_CENTER) |
| 261 | wp->w_popup_pos = POPPOS_TOPLEFT; |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 262 | |
| 263 | drag_on_resize_handle = wp->w_popup_border[1] > 0 |
| 264 | && wp->w_popup_border[2] > 0 |
| 265 | && row == popup_height(wp) - 1 |
| 266 | && col == popup_width(wp) - 1; |
| 267 | |
| 268 | if (wp->w_popup_pos != POPPOS_TOPLEFT && drag_on_resize_handle) |
| 269 | { |
| 270 | if (wp->w_popup_pos == POPPOS_TOPRIGHT |
| 271 | || wp->w_popup_pos == POPPOS_BOTRIGHT) |
| 272 | wp->w_wantcol = wp->w_wincol + 1; |
| 273 | if (wp->w_popup_pos == POPPOS_BOTLEFT) |
| 274 | wp->w_wantline = wp->w_winrow + 1; |
| 275 | wp->w_popup_pos = POPPOS_TOPLEFT; |
| 276 | } |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /* |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 280 | * Mouse moved while dragging a popup window: adjust the window popup position |
| 281 | * or resize. |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 282 | */ |
| 283 | void |
| 284 | popup_drag(win_T *wp) |
| 285 | { |
| 286 | // The popup may be closed before dragging stops. |
| 287 | if (!win_valid_popup(wp)) |
| 288 | return; |
| 289 | |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 290 | if ((wp->w_popup_flags & POPF_RESIZE) && drag_on_resize_handle) |
| 291 | { |
| 292 | int width_inc = mouse_col - drag_start_col; |
| 293 | int height_inc = mouse_row - drag_start_row; |
| 294 | |
| 295 | if (width_inc != 0) |
| 296 | { |
| 297 | int width = wp->w_width + width_inc; |
| 298 | |
| 299 | if (width < 1) |
| 300 | width = 1; |
| 301 | wp->w_minwidth = width; |
| 302 | wp->w_maxwidth = width; |
| 303 | drag_start_col = mouse_col; |
| 304 | } |
| 305 | |
| 306 | if (height_inc != 0) |
| 307 | { |
| 308 | int height = wp->w_height + height_inc; |
| 309 | |
| 310 | if (height < 1) |
| 311 | height = 1; |
| 312 | wp->w_minheight = height; |
| 313 | wp->w_maxheight = height; |
| 314 | drag_start_row = mouse_row; |
| 315 | } |
| 316 | |
| 317 | popup_adjust_position(wp); |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | if (!(wp->w_popup_flags & POPF_DRAG)) |
| 322 | return; |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 323 | wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row); |
| 324 | if (wp->w_wantline < 1) |
| 325 | wp->w_wantline = 1; |
| 326 | if (wp->w_wantline > Rows) |
| 327 | wp->w_wantline = Rows; |
| 328 | wp->w_wantcol = drag_start_wantcol + (mouse_col - drag_start_col); |
| 329 | if (wp->w_wantcol < 1) |
| 330 | wp->w_wantcol = 1; |
| 331 | if (wp->w_wantcol > Columns) |
| 332 | wp->w_wantcol = Columns; |
| 333 | |
| 334 | popup_adjust_position(wp); |
| 335 | } |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 336 | |
Bram Moolenaar | f9c85f5 | 2019-06-29 07:41:35 +0200 | [diff] [blame] | 337 | /* |
| 338 | * Set w_firstline to match the current "wp->w_topline". |
| 339 | */ |
| 340 | void |
| 341 | popup_set_firstline(win_T *wp) |
| 342 | { |
| 343 | int height = wp->w_height; |
| 344 | |
| 345 | wp->w_firstline = wp->w_topline; |
| 346 | popup_adjust_position(wp); |
| 347 | |
| 348 | // we don't want the popup to get smaller, decrement the first line |
| 349 | // until it doesn't |
| 350 | while (wp->w_firstline > 1 && wp->w_height < height) |
| 351 | { |
| 352 | --wp->w_firstline; |
| 353 | popup_adjust_position(wp); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | /* |
Bram Moolenaar | 13b11ed | 2019-08-01 15:52:45 +0200 | [diff] [blame] | 358 | * Return TRUE if the position is in the popup window scrollbar. |
| 359 | */ |
| 360 | int |
| 361 | popup_is_in_scrollbar(win_T *wp, int row, int col) |
| 362 | { |
| 363 | return wp->w_has_scrollbar |
| 364 | && row >= wp->w_popup_border[0] |
| 365 | && row < popup_height(wp) - wp->w_popup_border[2] |
| 366 | && col == popup_width(wp) - wp->w_popup_border[1] - 1; |
| 367 | } |
| 368 | |
| 369 | |
| 370 | /* |
Bram Moolenaar | f9c85f5 | 2019-06-29 07:41:35 +0200 | [diff] [blame] | 371 | * Handle a click in a popup window, if it is in the scrollbar. |
| 372 | */ |
| 373 | void |
| 374 | popup_handle_scrollbar_click(win_T *wp, int row, int col) |
| 375 | { |
| 376 | int height = popup_height(wp); |
| 377 | int old_topline = wp->w_topline; |
| 378 | |
Bram Moolenaar | 13b11ed | 2019-08-01 15:52:45 +0200 | [diff] [blame] | 379 | if (popup_is_in_scrollbar(wp, row, col)) |
Bram Moolenaar | f9c85f5 | 2019-06-29 07:41:35 +0200 | [diff] [blame] | 380 | { |
| 381 | if (row >= height / 2) |
| 382 | { |
| 383 | // Click in lower half, scroll down. |
| 384 | if (wp->w_topline < wp->w_buffer->b_ml.ml_line_count) |
| 385 | ++wp->w_topline; |
| 386 | } |
| 387 | else if (wp->w_topline > 1) |
| 388 | // click on upper half, scroll up. |
| 389 | --wp->w_topline; |
| 390 | if (wp->w_topline != old_topline) |
| 391 | { |
| 392 | popup_set_firstline(wp); |
| 393 | redraw_win_later(wp, NOT_VALID); |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 398 | #if defined(FEAT_TIMERS) |
| 399 | static void |
| 400 | popup_add_timeout(win_T *wp, int time) |
| 401 | { |
| 402 | char_u cbbuf[50]; |
| 403 | char_u *ptr = cbbuf; |
| 404 | typval_T tv; |
| 405 | |
| 406 | vim_snprintf((char *)cbbuf, sizeof(cbbuf), |
| 407 | "{_ -> popup_close(%d)}", wp->w_id); |
| 408 | if (get_lambda_tv(&ptr, &tv, TRUE) == OK) |
| 409 | { |
| 410 | wp->w_popup_timer = create_timer(time, 0); |
| 411 | wp->w_popup_timer->tr_callback = get_callback(&tv); |
| 412 | clear_tv(&tv); |
| 413 | } |
| 414 | } |
| 415 | #endif |
| 416 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 417 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 418 | * Shared between popup_create() and f_popup_move(). |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 419 | */ |
| 420 | static void |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 421 | apply_move_options(win_T *wp, dict_T *d) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 422 | { |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 423 | int nr; |
| 424 | |
| 425 | if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0) |
| 426 | wp->w_minwidth = nr; |
| 427 | if ((nr = dict_get_number(d, (char_u *)"minheight")) > 0) |
| 428 | wp->w_minheight = nr; |
| 429 | if ((nr = dict_get_number(d, (char_u *)"maxwidth")) > 0) |
| 430 | wp->w_maxwidth = nr; |
| 431 | if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0) |
| 432 | wp->w_maxheight = nr; |
| 433 | get_pos_options(wp, d); |
| 434 | } |
| 435 | |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 436 | static void |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 437 | handle_moved_argument(win_T *wp, dictitem_T *di, int mousemoved) |
| 438 | { |
| 439 | if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL) |
| 440 | { |
| 441 | char_u *s = di->di_tv.vval.v_string; |
| 442 | int flags = 0; |
| 443 | |
| 444 | if (STRCMP(s, "word") == 0) |
| 445 | flags = FIND_IDENT | FIND_STRING; |
| 446 | else if (STRCMP(s, "WORD") == 0) |
| 447 | flags = FIND_STRING; |
| 448 | else if (STRCMP(s, "expr") == 0) |
| 449 | flags = FIND_IDENT | FIND_STRING | FIND_EVAL; |
| 450 | else if (STRCMP(s, "any") != 0) |
| 451 | semsg(_(e_invarg2), s); |
| 452 | if (flags != 0) |
| 453 | { |
| 454 | if (mousemoved) |
| 455 | set_mousemoved_columns(wp, flags); |
| 456 | else |
| 457 | set_moved_columns(wp, flags); |
| 458 | } |
| 459 | } |
| 460 | else if (di->di_tv.v_type == VAR_LIST |
| 461 | && di->di_tv.vval.v_list != NULL |
| 462 | && di->di_tv.vval.v_list->lv_len == 2) |
| 463 | { |
| 464 | list_T *l = di->di_tv.vval.v_list; |
| 465 | int mincol = tv_get_number(&l->lv_first->li_tv); |
| 466 | int maxcol = tv_get_number(&l->lv_first->li_next->li_tv); |
| 467 | |
| 468 | if (mousemoved) |
| 469 | { |
| 470 | wp->w_popup_mouse_mincol = mincol; |
| 471 | wp->w_popup_mouse_maxcol = maxcol; |
| 472 | } |
| 473 | else |
| 474 | { |
| 475 | wp->w_popup_mincol = mincol; |
| 476 | wp->w_popup_maxcol = maxcol; |
| 477 | } |
| 478 | } |
| 479 | else |
| 480 | semsg(_(e_invarg2), tv_get_string(&di->di_tv)); |
| 481 | } |
| 482 | |
| 483 | static void |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 484 | check_highlight(dict_T *dict, char *name, char_u **pval) |
| 485 | { |
| 486 | dictitem_T *di; |
| 487 | char_u *str; |
| 488 | |
| 489 | di = dict_find(dict, (char_u *)name, -1); |
| 490 | if (di != NULL) |
| 491 | { |
| 492 | if (di->di_tv.v_type != VAR_STRING) |
| 493 | semsg(_(e_invargval), name); |
| 494 | else |
| 495 | { |
| 496 | str = tv_get_string(&di->di_tv); |
| 497 | if (*str != NUL) |
| 498 | *pval = vim_strsave(str); |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 503 | /* |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 504 | * Scroll to show the line with the cursor. This assumes lines don't wrap. |
| 505 | */ |
| 506 | static void |
| 507 | popup_show_curline(win_T *wp) |
| 508 | { |
| 509 | if (wp->w_cursor.lnum < wp->w_topline) |
| 510 | wp->w_topline = wp->w_cursor.lnum; |
| 511 | else if (wp->w_cursor.lnum >= wp->w_botline) |
| 512 | wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1; |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 513 | |
| 514 | // Don't use "firstline" now. |
| 515 | wp->w_firstline = 0; |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * Get the sign group name for window "wp". |
| 520 | * Returns a pointer to a static buffer, overwritten on the next call. |
| 521 | */ |
| 522 | static char_u * |
| 523 | popup_get_sign_name(win_T *wp) |
| 524 | { |
| 525 | static char buf[30]; |
| 526 | |
| 527 | vim_snprintf(buf, sizeof(buf), "popup-%d", wp->w_id); |
| 528 | return (char_u *)buf; |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /* |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 532 | * Highlight the line with the cursor. |
| 533 | * Also scrolls the text to put the cursor line in view. |
| 534 | */ |
| 535 | static void |
| 536 | popup_highlight_curline(win_T *wp) |
| 537 | { |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 538 | int sign_id = 0; |
| 539 | char_u *sign_name = popup_get_sign_name(wp); |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 540 | |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 541 | buf_delete_signs(wp->w_buffer, (char_u *)"popupmenu"); |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 542 | |
| 543 | if ((wp->w_popup_flags & POPF_CURSORLINE) != 0) |
| 544 | { |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 545 | popup_show_curline(wp); |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 546 | |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 547 | if (!sign_exists_by_name(sign_name)) |
| 548 | { |
| 549 | char *linehl = "PopupSelected"; |
| 550 | |
| 551 | if (syn_name2id((char_u *)linehl) == 0) |
| 552 | linehl = "PmenuSel"; |
| 553 | sign_define_by_name(sign_name, NULL, |
| 554 | (char_u *)linehl, NULL, NULL); |
| 555 | } |
| 556 | |
| 557 | sign_place(&sign_id, (char_u *)"popupmenu", sign_name, |
| 558 | wp->w_buffer, wp->w_cursor.lnum, SIGN_DEF_PRIO); |
| 559 | redraw_win_later(wp, NOT_VALID); |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 560 | } |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 561 | else |
| 562 | sign_undefine_by_name(sign_name, FALSE); |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 566 | * Shared between popup_create() and f_popup_setoptions(). |
| 567 | */ |
| 568 | static void |
| 569 | apply_general_options(win_T *wp, dict_T *dict) |
| 570 | { |
| 571 | dictitem_T *di; |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 572 | int nr; |
| 573 | char_u *str; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 574 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 575 | // TODO: flip |
| 576 | |
| 577 | di = dict_find(dict, (char_u *)"firstline", -1); |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 578 | if (di != NULL) |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 579 | wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); |
| 580 | if (wp->w_firstline < 1) |
| 581 | wp->w_firstline = 1; |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 582 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 583 | di = dict_find(dict, (char_u *)"scrollbar", -1); |
| 584 | if (di != NULL) |
| 585 | wp->w_want_scrollbar = dict_get_number(dict, (char_u *)"scrollbar"); |
| 586 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 587 | str = dict_get_string(dict, (char_u *)"title", FALSE); |
| 588 | if (str != NULL) |
| 589 | { |
| 590 | vim_free(wp->w_popup_title); |
| 591 | wp->w_popup_title = vim_strsave(str); |
| 592 | } |
| 593 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 594 | di = dict_find(dict, (char_u *)"wrap", -1); |
| 595 | if (di != NULL) |
| 596 | { |
| 597 | nr = dict_get_number(dict, (char_u *)"wrap"); |
| 598 | wp->w_p_wrap = nr != 0; |
| 599 | } |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 600 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 601 | di = dict_find(dict, (char_u *)"drag", -1); |
| 602 | if (di != NULL) |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 603 | { |
| 604 | nr = dict_get_number(dict, (char_u *)"drag"); |
| 605 | if (nr) |
| 606 | wp->w_popup_flags |= POPF_DRAG; |
| 607 | else |
| 608 | wp->w_popup_flags &= ~POPF_DRAG; |
| 609 | } |
| 610 | |
| 611 | di = dict_find(dict, (char_u *)"resize", -1); |
| 612 | if (di != NULL) |
| 613 | { |
| 614 | nr = dict_get_number(dict, (char_u *)"resize"); |
| 615 | if (nr) |
| 616 | wp->w_popup_flags |= POPF_RESIZE; |
| 617 | else |
| 618 | wp->w_popup_flags &= ~POPF_RESIZE; |
| 619 | } |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 620 | |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 621 | di = dict_find(dict, (char_u *)"close", -1); |
| 622 | if (di != NULL) |
| 623 | { |
| 624 | int ok = TRUE; |
| 625 | |
| 626 | if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL) |
| 627 | { |
| 628 | char_u *s = di->di_tv.vval.v_string; |
| 629 | |
| 630 | if (STRCMP(s, "none") == 0) |
| 631 | wp->w_popup_close = POPCLOSE_NONE; |
| 632 | else if (STRCMP(s, "button") == 0) |
| 633 | wp->w_popup_close = POPCLOSE_BUTTON; |
| 634 | else if (STRCMP(s, "click") == 0) |
| 635 | wp->w_popup_close = POPCLOSE_CLICK; |
| 636 | else |
| 637 | ok = FALSE; |
| 638 | } |
| 639 | else |
| 640 | ok = FALSE; |
| 641 | if (!ok) |
| 642 | semsg(_(e_invargNval), "close", tv_get_string(&di->di_tv)); |
| 643 | } |
| 644 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 645 | str = dict_get_string(dict, (char_u *)"highlight", FALSE); |
| 646 | if (str != NULL) |
| 647 | set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
| 648 | str, OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 649 | |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 650 | set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1, |
| 651 | (char_u *)"no", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 652 | set_padding_border(dict, wp->w_popup_padding, "padding", 999); |
| 653 | set_padding_border(dict, wp->w_popup_border, "border", 1); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 654 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 655 | di = dict_find(dict, (char_u *)"borderhighlight", -1); |
| 656 | if (di != NULL) |
| 657 | { |
Bram Moolenaar | 403d090 | 2019-07-17 21:37:32 +0200 | [diff] [blame] | 658 | if (di->di_tv.v_type != VAR_LIST || di->di_tv.vval.v_list == NULL) |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 659 | emsg(_(e_listreq)); |
| 660 | else |
| 661 | { |
| 662 | list_T *list = di->di_tv.vval.v_list; |
| 663 | listitem_T *li; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 664 | int i; |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 665 | |
Bram Moolenaar | 403d090 | 2019-07-17 21:37:32 +0200 | [diff] [blame] | 666 | for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len; |
| 667 | ++i, li = li->li_next) |
| 668 | { |
| 669 | str = tv_get_string(&li->li_tv); |
| 670 | if (*str != NUL) |
| 671 | wp->w_border_highlight[i] = vim_strsave(str); |
| 672 | } |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 673 | if (list->lv_len == 1 && wp->w_border_highlight[0] != NULL) |
| 674 | for (i = 1; i < 4; ++i) |
Bram Moolenaar | 403d090 | 2019-07-17 21:37:32 +0200 | [diff] [blame] | 675 | wp->w_border_highlight[i] = |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 676 | vim_strsave(wp->w_border_highlight[0]); |
| 677 | } |
| 678 | } |
| 679 | |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 680 | di = dict_find(dict, (char_u *)"borderchars", -1); |
| 681 | if (di != NULL) |
| 682 | { |
| 683 | if (di->di_tv.v_type != VAR_LIST) |
| 684 | emsg(_(e_listreq)); |
| 685 | else |
| 686 | { |
| 687 | list_T *list = di->di_tv.vval.v_list; |
| 688 | listitem_T *li; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 689 | int i; |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 690 | |
| 691 | if (list != NULL) |
| 692 | for (i = 0, li = list->lv_first; i < 8 && i < list->lv_len; |
| 693 | ++i, li = li->li_next) |
| 694 | { |
| 695 | str = tv_get_string(&li->li_tv); |
| 696 | if (*str != NUL) |
| 697 | wp->w_border_char[i] = mb_ptr2char(str); |
| 698 | } |
| 699 | if (list->lv_len == 1) |
| 700 | for (i = 1; i < 8; ++i) |
| 701 | wp->w_border_char[i] = wp->w_border_char[0]; |
| 702 | if (list->lv_len == 2) |
| 703 | { |
| 704 | for (i = 4; i < 8; ++i) |
| 705 | wp->w_border_char[i] = wp->w_border_char[1]; |
| 706 | for (i = 1; i < 4; ++i) |
| 707 | wp->w_border_char[i] = wp->w_border_char[0]; |
| 708 | } |
| 709 | } |
| 710 | } |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 711 | |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 712 | check_highlight(dict, "scrollbarhighlight", &wp->w_scrollbar_highlight); |
| 713 | check_highlight(dict, "thumbhighlight", &wp->w_thumb_highlight); |
| 714 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 715 | di = dict_find(dict, (char_u *)"zindex", -1); |
| 716 | if (di != NULL) |
| 717 | { |
| 718 | wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); |
| 719 | if (wp->w_zindex < 1) |
| 720 | wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX; |
| 721 | if (wp->w_zindex > 32000) |
| 722 | wp->w_zindex = 32000; |
| 723 | } |
| 724 | |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 725 | di = dict_find(dict, (char_u *)"mask", -1); |
| 726 | if (di != NULL) |
| 727 | { |
Bram Moolenaar | cfdbc5a | 2019-07-17 21:27:52 +0200 | [diff] [blame] | 728 | int ok = FALSE; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 729 | |
Bram Moolenaar | cfdbc5a | 2019-07-17 21:27:52 +0200 | [diff] [blame] | 730 | if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL) |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 731 | { |
| 732 | listitem_T *li; |
| 733 | |
Bram Moolenaar | cfdbc5a | 2019-07-17 21:27:52 +0200 | [diff] [blame] | 734 | ok = TRUE; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 735 | for (li = di->di_tv.vval.v_list->lv_first; li != NULL; |
| 736 | li = li->li_next) |
| 737 | { |
| 738 | if (li->li_tv.v_type != VAR_LIST |
| 739 | || li->li_tv.vval.v_list == NULL |
| 740 | || li->li_tv.vval.v_list->lv_len != 4) |
| 741 | { |
| 742 | ok = FALSE; |
| 743 | break; |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | if (ok) |
| 748 | { |
| 749 | wp->w_popup_mask = di->di_tv.vval.v_list; |
| 750 | ++wp->w_popup_mask->lv_refcount; |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 751 | VIM_CLEAR(wp->w_popup_mask_cells); |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 752 | } |
| 753 | else |
| 754 | semsg(_(e_invargval), "mask"); |
| 755 | } |
| 756 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 757 | #if defined(FEAT_TIMERS) |
| 758 | // Add timer to close the popup after some time. |
| 759 | nr = dict_get_number(dict, (char_u *)"time"); |
| 760 | if (nr > 0) |
| 761 | popup_add_timeout(wp, nr); |
| 762 | #endif |
| 763 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 764 | di = dict_find(dict, (char_u *)"moved", -1); |
| 765 | if (di != NULL) |
| 766 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 767 | set_moved_values(wp); |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 768 | handle_moved_argument(wp, di, FALSE); |
| 769 | } |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 770 | |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 771 | di = dict_find(dict, (char_u *)"mousemoved", -1); |
| 772 | if (di != NULL) |
| 773 | { |
| 774 | set_mousemoved_values(wp); |
| 775 | handle_moved_argument(wp, di, TRUE); |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 776 | } |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 777 | |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 778 | di = dict_find(dict, (char_u *)"cursorline", -1); |
| 779 | if (di != NULL) |
| 780 | { |
| 781 | if (di->di_tv.v_type == VAR_NUMBER) |
| 782 | { |
| 783 | if (di->di_tv.vval.v_number != 0) |
| 784 | wp->w_popup_flags |= POPF_CURSORLINE; |
| 785 | else |
| 786 | wp->w_popup_flags &= ~POPF_CURSORLINE; |
| 787 | } |
| 788 | else |
| 789 | semsg(_(e_invargval), "cursorline"); |
| 790 | } |
| 791 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 792 | di = dict_find(dict, (char_u *)"filter", -1); |
| 793 | if (di != NULL) |
| 794 | { |
| 795 | callback_T callback = get_callback(&di->di_tv); |
| 796 | |
| 797 | if (callback.cb_name != NULL) |
| 798 | { |
| 799 | free_callback(&wp->w_filter_cb); |
| 800 | set_callback(&wp->w_filter_cb, &callback); |
| 801 | } |
| 802 | } |
Bram Moolenaar | 749fa0a | 2019-08-03 16:18:07 +0200 | [diff] [blame^] | 803 | di = dict_find(dict, (char_u *)"mapping", -1); |
| 804 | if (di != NULL) |
| 805 | { |
| 806 | nr = dict_get_number(dict, (char_u *)"mapping"); |
| 807 | if (nr) |
| 808 | wp->w_popup_flags |= POPF_MAPPING; |
| 809 | else |
| 810 | wp->w_popup_flags &= ~POPF_MAPPING; |
| 811 | } |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 812 | |
| 813 | di = dict_find(dict, (char_u *)"callback", -1); |
| 814 | if (di != NULL) |
| 815 | { |
| 816 | callback_T callback = get_callback(&di->di_tv); |
| 817 | |
| 818 | if (callback.cb_name != NULL) |
| 819 | { |
| 820 | free_callback(&wp->w_close_cb); |
| 821 | set_callback(&wp->w_close_cb, &callback); |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | /* |
| 827 | * Go through the options in "dict" and apply them to popup window "wp". |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 828 | * Only used when creating a new popup window. |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 829 | */ |
| 830 | static void |
| 831 | apply_options(win_T *wp, dict_T *dict) |
| 832 | { |
| 833 | int nr; |
| 834 | |
| 835 | apply_move_options(wp, dict); |
| 836 | apply_general_options(wp, dict); |
| 837 | |
Bram Moolenaar | 6313c4f | 2019-06-16 20:39:13 +0200 | [diff] [blame] | 838 | nr = dict_get_number(dict, (char_u *)"hidden"); |
| 839 | if (nr > 0) |
| 840 | { |
| 841 | wp->w_popup_flags |= POPF_HIDDEN; |
| 842 | --wp->w_buffer->b_nwindows; |
| 843 | } |
| 844 | |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 845 | popup_mask_refresh = TRUE; |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 846 | popup_highlight_curline(wp); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | /* |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 850 | * Add lines to the popup from a list of strings. |
| 851 | */ |
| 852 | static void |
| 853 | add_popup_strings(buf_T *buf, list_T *l) |
| 854 | { |
| 855 | listitem_T *li; |
| 856 | linenr_T lnum = 0; |
| 857 | char_u *p; |
| 858 | |
| 859 | for (li = l->lv_first; li != NULL; li = li->li_next) |
| 860 | if (li->li_tv.v_type == VAR_STRING) |
| 861 | { |
| 862 | p = li->li_tv.vval.v_string; |
| 863 | ml_append_buf(buf, lnum++, |
| 864 | p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | /* |
| 869 | * Add lines to the popup from a list of dictionaries. |
| 870 | */ |
| 871 | static void |
| 872 | add_popup_dicts(buf_T *buf, list_T *l) |
| 873 | { |
| 874 | listitem_T *li; |
| 875 | listitem_T *pli; |
| 876 | linenr_T lnum = 0; |
| 877 | char_u *p; |
| 878 | dict_T *dict; |
| 879 | |
| 880 | // first add the text lines |
| 881 | for (li = l->lv_first; li != NULL; li = li->li_next) |
| 882 | { |
| 883 | if (li->li_tv.v_type != VAR_DICT) |
| 884 | { |
| 885 | emsg(_(e_dictreq)); |
| 886 | return; |
| 887 | } |
| 888 | dict = li->li_tv.vval.v_dict; |
| 889 | p = dict == NULL ? NULL |
| 890 | : dict_get_string(dict, (char_u *)"text", FALSE); |
| 891 | ml_append_buf(buf, lnum++, |
| 892 | p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE); |
| 893 | } |
| 894 | |
| 895 | // add the text properties |
| 896 | lnum = 1; |
| 897 | for (li = l->lv_first; li != NULL; li = li->li_next, ++lnum) |
| 898 | { |
| 899 | dictitem_T *di; |
| 900 | list_T *plist; |
| 901 | |
| 902 | dict = li->li_tv.vval.v_dict; |
| 903 | di = dict_find(dict, (char_u *)"props", -1); |
| 904 | if (di != NULL) |
| 905 | { |
| 906 | if (di->di_tv.v_type != VAR_LIST) |
| 907 | { |
| 908 | emsg(_(e_listreq)); |
| 909 | return; |
| 910 | } |
| 911 | plist = di->di_tv.vval.v_list; |
| 912 | if (plist != NULL) |
| 913 | { |
| 914 | for (pli = plist->lv_first; pli != NULL; pli = pli->li_next) |
| 915 | { |
| 916 | if (pli->li_tv.v_type != VAR_DICT) |
| 917 | { |
| 918 | emsg(_(e_dictreq)); |
| 919 | return; |
| 920 | } |
| 921 | dict = pli->li_tv.vval.v_dict; |
| 922 | if (dict != NULL) |
| 923 | { |
| 924 | int col = dict_get_number(dict, (char_u *)"col"); |
| 925 | |
| 926 | prop_add_common( lnum, col, dict, buf, NULL); |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | /* |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 935 | * Get the padding plus border at the top, adjusted to 1 if there is a title. |
| 936 | */ |
| 937 | static int |
| 938 | popup_top_extra(win_T *wp) |
| 939 | { |
| 940 | int extra = wp->w_popup_border[0] + wp->w_popup_padding[0]; |
| 941 | |
| 942 | if (extra == 0 && wp->w_popup_title != NULL && *wp->w_popup_title != NUL) |
| 943 | return 1; |
| 944 | return extra; |
| 945 | } |
| 946 | |
| 947 | /* |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 948 | * Return the height of popup window "wp", including border and padding. |
| 949 | */ |
| 950 | int |
| 951 | popup_height(win_T *wp) |
| 952 | { |
| 953 | return wp->w_height |
| 954 | + popup_top_extra(wp) |
| 955 | + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
| 956 | } |
| 957 | |
| 958 | /* |
| 959 | * Return the width of popup window "wp", including border, padding and |
| 960 | * scrollbar. |
| 961 | */ |
| 962 | int |
| 963 | popup_width(win_T *wp) |
| 964 | { |
Bram Moolenaar | 017c269 | 2019-07-13 14:17:51 +0200 | [diff] [blame] | 965 | // w_leftcol is how many columns of the core are left of the screen |
| 966 | // w_popup_rightoff is how many columns of the core are right of the screen |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 967 | return wp->w_width + wp->w_leftcol |
| 968 | + wp->w_popup_padding[3] + wp->w_popup_border[3] |
| 969 | + wp->w_popup_padding[1] + wp->w_popup_border[1] |
| 970 | + wp->w_has_scrollbar |
| 971 | + wp->w_popup_rightoff; |
| 972 | } |
| 973 | |
| 974 | /* |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 975 | * Adjust the position and size of the popup to fit on the screen. |
| 976 | */ |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 977 | void |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 978 | popup_adjust_position(win_T *wp) |
| 979 | { |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 980 | linenr_T lnum; |
| 981 | int wrapped = 0; |
| 982 | int maxwidth; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 983 | int maxspace; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 984 | int center_vert = FALSE; |
| 985 | int center_hor = FALSE; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 986 | int allow_adjust_left = !wp->w_popup_fixed; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 987 | int top_extra = popup_top_extra(wp); |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 988 | int right_extra = wp->w_popup_border[1] + wp->w_popup_padding[1]; |
| 989 | int bot_extra = wp->w_popup_border[2] + wp->w_popup_padding[2]; |
| 990 | int left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
| 991 | int extra_height = top_extra + bot_extra; |
| 992 | int extra_width = left_extra + right_extra; |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 993 | int org_winrow = wp->w_winrow; |
| 994 | int org_wincol = wp->w_wincol; |
| 995 | int org_width = wp->w_width; |
| 996 | int org_height = wp->w_height; |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 997 | int org_leftcol = wp->w_leftcol; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 998 | int org_leftoff = wp->w_popup_leftoff; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 999 | int minwidth; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1000 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1001 | wp->w_winrow = 0; |
| 1002 | wp->w_wincol = 0; |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 1003 | wp->w_leftcol = 0; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 1004 | wp->w_popup_leftoff = 0; |
| 1005 | wp->w_popup_rightoff = 0; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1006 | if (wp->w_popup_pos == POPPOS_CENTER) |
| 1007 | { |
| 1008 | // center after computing the size |
| 1009 | center_vert = TRUE; |
| 1010 | center_hor = TRUE; |
| 1011 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1012 | else |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1013 | { |
| 1014 | if (wp->w_wantline == 0) |
| 1015 | center_vert = TRUE; |
| 1016 | else if (wp->w_popup_pos == POPPOS_TOPLEFT |
| 1017 | || wp->w_popup_pos == POPPOS_TOPRIGHT) |
| 1018 | { |
| 1019 | wp->w_winrow = wp->w_wantline - 1; |
| 1020 | if (wp->w_winrow >= Rows) |
| 1021 | wp->w_winrow = Rows - 1; |
| 1022 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1023 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1024 | if (wp->w_wantcol == 0) |
| 1025 | center_hor = TRUE; |
| 1026 | else if (wp->w_popup_pos == POPPOS_TOPLEFT |
| 1027 | || wp->w_popup_pos == POPPOS_BOTLEFT) |
| 1028 | { |
| 1029 | wp->w_wincol = wp->w_wantcol - 1; |
| 1030 | if (wp->w_wincol >= Columns - 3) |
| 1031 | wp->w_wincol = Columns - 3; |
| 1032 | } |
| 1033 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1034 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1035 | // When centering or right aligned, use maximum width. |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1036 | // When left aligned use the space available, but shift to the left when we |
| 1037 | // hit the right of the screen. |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 1038 | maxspace = Columns - wp->w_wincol - left_extra; |
| 1039 | maxwidth = maxspace; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1040 | if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1041 | { |
| 1042 | allow_adjust_left = FALSE; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1043 | maxwidth = wp->w_maxwidth; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1044 | } |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1045 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 1046 | // start at the desired first line |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1047 | if (wp->w_firstline != 0) |
| 1048 | wp->w_topline = wp->w_firstline; |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 1049 | if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) |
| 1050 | wp->w_topline = wp->w_buffer->b_ml.ml_line_count; |
| 1051 | |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1052 | // Compute width based on longest text line and the 'wrap' option. |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1053 | // Use a minimum width of one, so that something shows when there is no |
| 1054 | // text. |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1055 | // TODO: more accurate wrapping |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1056 | wp->w_width = 1; |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 1057 | 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] | 1058 | { |
Bram Moolenaar | 331bafd | 2019-07-20 17:46:05 +0200 | [diff] [blame] | 1059 | int len; |
| 1060 | int w_width = wp->w_width; |
| 1061 | |
| 1062 | // Count Tabs for what they are worth and compute the length based on |
| 1063 | // the maximum width (matters when 'showbreak' is set). |
| 1064 | if (wp->w_width < maxwidth) |
| 1065 | wp->w_width = maxwidth; |
| 1066 | len = win_linetabsize(wp, ml_get_buf(wp->w_buffer, lnum, FALSE), |
Bram Moolenaar | e089c3f | 2019-07-09 20:25:25 +0200 | [diff] [blame] | 1067 | (colnr_T)MAXCOL); |
Bram Moolenaar | 331bafd | 2019-07-20 17:46:05 +0200 | [diff] [blame] | 1068 | wp->w_width = w_width; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1069 | |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1070 | if (wp->w_p_wrap) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1071 | { |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1072 | while (len > maxwidth) |
| 1073 | { |
| 1074 | ++wrapped; |
| 1075 | len -= maxwidth; |
| 1076 | wp->w_width = maxwidth; |
| 1077 | } |
| 1078 | } |
| 1079 | else if (len > maxwidth |
| 1080 | && allow_adjust_left |
| 1081 | && (wp->w_popup_pos == POPPOS_TOPLEFT |
| 1082 | || wp->w_popup_pos == POPPOS_BOTLEFT)) |
| 1083 | { |
| 1084 | // adjust leftwise to fit text on screen |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 1085 | int shift_by = len - maxwidth; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1086 | |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 1087 | if (shift_by > wp->w_wincol) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1088 | { |
| 1089 | int truncate_shift = shift_by - wp->w_wincol; |
Bram Moolenaar | 51c3131 | 2019-06-15 22:27:23 +0200 | [diff] [blame] | 1090 | |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1091 | len -= truncate_shift; |
| 1092 | shift_by -= truncate_shift; |
| 1093 | } |
| 1094 | |
| 1095 | wp->w_wincol -= shift_by; |
| 1096 | maxwidth += shift_by; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1097 | wp->w_width = maxwidth; |
| 1098 | } |
| 1099 | if (wp->w_width < len) |
Bram Moolenaar | 017c269 | 2019-07-13 14:17:51 +0200 | [diff] [blame] | 1100 | { |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1101 | wp->w_width = len; |
Bram Moolenaar | 017c269 | 2019-07-13 14:17:51 +0200 | [diff] [blame] | 1102 | if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth) |
| 1103 | wp->w_width = wp->w_maxwidth; |
| 1104 | } |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 1105 | // do not use the width of lines we're not going to show |
Bram Moolenaar | e296e31 | 2019-07-03 23:20:18 +0200 | [diff] [blame] | 1106 | if (wp->w_maxheight > 0 |
| 1107 | && lnum - wp->w_topline + 1 + wrapped > wp->w_maxheight) |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 1108 | break; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1109 | } |
| 1110 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1111 | wp->w_has_scrollbar = wp->w_want_scrollbar |
| 1112 | && (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count); |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1113 | if (wp->w_has_scrollbar) |
| 1114 | ++right_extra; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1115 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 1116 | minwidth = wp->w_minwidth; |
| 1117 | if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL) |
| 1118 | { |
| 1119 | int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width; |
| 1120 | |
| 1121 | if (minwidth < title_len) |
| 1122 | minwidth = title_len; |
| 1123 | } |
| 1124 | |
| 1125 | if (minwidth > 0 && wp->w_width < minwidth) |
| 1126 | wp->w_width = minwidth; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1127 | if (wp->w_width > maxwidth) |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 1128 | { |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1129 | if (wp->w_width > maxspace && !wp->w_p_wrap) |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 1130 | // some columns cut off on the right |
| 1131 | wp->w_popup_rightoff = wp->w_width - maxspace; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 1132 | wp->w_width = maxwidth; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 1133 | } |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1134 | if (center_hor) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1135 | { |
| 1136 | wp->w_wincol = (Columns - wp->w_width - extra_width) / 2; |
| 1137 | if (wp->w_wincol < 0) |
| 1138 | wp->w_wincol = 0; |
| 1139 | } |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1140 | else if (wp->w_popup_pos == POPPOS_BOTRIGHT |
| 1141 | || wp->w_popup_pos == POPPOS_TOPRIGHT) |
| 1142 | { |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 1143 | int leftoff = wp->w_wantcol - (wp->w_width + extra_width); |
| 1144 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1145 | // Right aligned: move to the right if needed. |
| 1146 | // No truncation, because that would change the height. |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 1147 | if (leftoff >= 0) |
| 1148 | wp->w_wincol = leftoff; |
| 1149 | else if (wp->w_popup_fixed) |
| 1150 | { |
| 1151 | // "col" specifies the right edge, but popup doesn't fit, skip some |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 1152 | // columns when displaying the window, minus left border and |
| 1153 | // padding. |
| 1154 | if (-leftoff > left_extra) |
| 1155 | wp->w_leftcol = -leftoff - left_extra; |
| 1156 | wp->w_width -= wp->w_leftcol; |
| 1157 | wp->w_popup_leftoff = -leftoff; |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 1158 | if (wp->w_width < 0) |
| 1159 | wp->w_width = 0; |
| 1160 | } |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1161 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1162 | |
Bram Moolenaar | 8edf0e3 | 2019-07-30 21:19:26 +0200 | [diff] [blame] | 1163 | if (wp->w_p_wrap || (!wp->w_popup_fixed |
| 1164 | && (wp->w_popup_pos == POPPOS_TOPLEFT |
| 1165 | || wp->w_popup_pos == POPPOS_BOTLEFT))) |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1166 | { |
| 1167 | int want_col = 0; |
| 1168 | |
Bram Moolenaar | 8c8b88d | 2019-07-30 20:32:41 +0200 | [diff] [blame] | 1169 | // try to show the right border and any scrollbar |
| 1170 | want_col = left_extra + wp->w_width + right_extra; |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1171 | if (want_col > 0 && wp->w_wincol > 0 |
| 1172 | && wp->w_wincol + want_col >= Columns) |
| 1173 | { |
| 1174 | wp->w_wincol = Columns - want_col; |
| 1175 | if (wp->w_wincol < 0) |
| 1176 | wp->w_wincol = 0; |
| 1177 | } |
| 1178 | } |
| 1179 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 1180 | wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline |
| 1181 | + 1 + wrapped; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1182 | if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) |
| 1183 | wp->w_height = wp->w_minheight; |
| 1184 | if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) |
| 1185 | wp->w_height = wp->w_maxheight; |
| 1186 | if (wp->w_height > Rows - wp->w_winrow) |
| 1187 | wp->w_height = Rows - wp->w_winrow; |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 1188 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1189 | if (center_vert) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1190 | { |
| 1191 | wp->w_winrow = (Rows - wp->w_height - extra_height) / 2; |
| 1192 | if (wp->w_winrow < 0) |
| 1193 | wp->w_winrow = 0; |
| 1194 | } |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1195 | else if (wp->w_popup_pos == POPPOS_BOTRIGHT |
| 1196 | || wp->w_popup_pos == POPPOS_BOTLEFT) |
| 1197 | { |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 1198 | if ((wp->w_height + extra_height) <= wp->w_wantline) |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1199 | // bottom aligned: may move down |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 1200 | wp->w_winrow = wp->w_wantline - (wp->w_height + extra_height); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1201 | else |
| 1202 | // not enough space, make top aligned |
| 1203 | wp->w_winrow = wp->w_wantline + 1; |
| 1204 | } |
| 1205 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 1206 | wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1207 | |
| 1208 | // Need to update popup_mask if the position or size changed. |
Bram Moolenaar | acc682b | 2019-06-08 17:15:51 +0200 | [diff] [blame] | 1209 | // And redraw windows that were behind the popup. |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1210 | if (org_winrow != wp->w_winrow |
| 1211 | || org_wincol != wp->w_wincol |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 1212 | || org_leftcol != wp->w_leftcol |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 1213 | || org_leftoff != wp->w_popup_leftoff |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1214 | || org_width != wp->w_width |
| 1215 | || org_height != wp->w_height) |
| 1216 | { |
Bram Moolenaar | 4c063a0 | 2019-06-10 21:24:12 +0200 | [diff] [blame] | 1217 | redraw_all_later(VALID); |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1218 | redraw_win_later(wp, NOT_VALID); |
| 1219 | if (wp->w_popup_flags & POPF_ON_CMDLINE) |
| 1220 | clear_cmdline = TRUE; |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1221 | popup_mask_refresh = TRUE; |
| 1222 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1223 | } |
| 1224 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1225 | typedef enum |
| 1226 | { |
| 1227 | TYPE_NORMAL, |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1228 | TYPE_ATCURSOR, |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1229 | TYPE_BEVAL, |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1230 | TYPE_NOTIFICATION, |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1231 | TYPE_DIALOG, |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1232 | TYPE_MENU, |
| 1233 | TYPE_PREVIEW |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1234 | } create_type_T; |
| 1235 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1236 | /* |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1237 | * Make "buf" empty and set the contents to "text". |
| 1238 | * Used by popup_create() and popup_settext(). |
| 1239 | */ |
| 1240 | static void |
| 1241 | popup_set_buffer_text(buf_T *buf, typval_T text) |
| 1242 | { |
| 1243 | int lnum; |
| 1244 | |
| 1245 | // Clear the buffer, then replace the lines. |
| 1246 | curbuf = buf; |
| 1247 | for (lnum = buf->b_ml.ml_line_count; lnum > 0; --lnum) |
| 1248 | ml_delete(lnum, FALSE); |
| 1249 | curbuf = curwin->w_buffer; |
| 1250 | |
| 1251 | // Add text to the buffer. |
| 1252 | if (text.v_type == VAR_STRING) |
| 1253 | { |
| 1254 | // just a string |
| 1255 | ml_append_buf(buf, 0, text.vval.v_string, (colnr_T)0, TRUE); |
| 1256 | } |
| 1257 | else |
| 1258 | { |
| 1259 | list_T *l = text.vval.v_list; |
| 1260 | |
| 1261 | if (l->lv_len > 0) |
| 1262 | { |
| 1263 | if (l->lv_first->li_tv.v_type == VAR_STRING) |
| 1264 | // list of strings |
| 1265 | add_popup_strings(buf, l); |
| 1266 | else |
| 1267 | // list of dictionaries |
| 1268 | add_popup_dicts(buf, l); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | // delete the line that was in the empty buffer |
| 1273 | curbuf = buf; |
| 1274 | ml_delete(buf->b_ml.ml_line_count, FALSE); |
| 1275 | curbuf = curwin->w_buffer; |
| 1276 | } |
| 1277 | |
| 1278 | /* |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1279 | * Parse the 'previewpopup' option and apply the values to window "wp" if it |
| 1280 | * not NULL. |
| 1281 | * Return FAIL if the parsing fails. |
| 1282 | */ |
| 1283 | int |
| 1284 | parse_previewpopup(win_T *wp) |
| 1285 | { |
| 1286 | char_u *p; |
| 1287 | |
| 1288 | for (p = p_pvp; *p != NUL; p += (*p == ',' ? 1 : 0)) |
| 1289 | { |
| 1290 | char_u *e, *dig; |
| 1291 | char_u *s = p; |
| 1292 | int x; |
| 1293 | |
| 1294 | e = vim_strchr(p, ':'); |
| 1295 | if (e == NULL || e[1] == NUL) |
| 1296 | return FAIL; |
| 1297 | |
| 1298 | p = vim_strchr(e, ','); |
| 1299 | if (p == NULL) |
| 1300 | p = e + STRLEN(e); |
| 1301 | dig = e + 1; |
| 1302 | x = getdigits(&dig); |
| 1303 | if (dig != p) |
| 1304 | return FAIL; |
| 1305 | |
| 1306 | if (STRNCMP(s, "height:", 7) == 0) |
| 1307 | { |
| 1308 | if (wp != NULL) |
| 1309 | { |
| 1310 | wp->w_minheight = x; |
| 1311 | wp->w_maxheight = x; |
| 1312 | } |
| 1313 | } |
| 1314 | else if (STRNCMP(s, "width:", 6) == 0) |
| 1315 | { |
| 1316 | if (wp != NULL) |
| 1317 | { |
| 1318 | wp->w_minwidth = x; |
| 1319 | wp->w_maxwidth = x; |
| 1320 | } |
| 1321 | } |
| 1322 | else |
| 1323 | return FAIL; |
| 1324 | } |
| 1325 | return OK; |
| 1326 | } |
| 1327 | |
| 1328 | /* |
| 1329 | * Set w_wantline and w_wantcol for the cursor position in the current window. |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1330 | * Keep at least "width" columns from the right of the screen. |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1331 | */ |
| 1332 | void |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1333 | popup_set_wantpos(win_T *wp, int width) |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1334 | { |
| 1335 | setcursor_mayforce(TRUE); |
| 1336 | wp->w_wantline = curwin->w_winrow + curwin->w_wrow; |
| 1337 | if (wp->w_wantline == 0) // cursor in first line |
| 1338 | { |
| 1339 | wp->w_wantline = 2; |
| 1340 | wp->w_popup_pos = POPPOS_TOPLEFT; |
| 1341 | } |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1342 | |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1343 | wp->w_wantcol = curwin->w_wincol + curwin->w_wcol + 1; |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1344 | if (wp->w_wantcol > Columns - width) |
| 1345 | { |
| 1346 | wp->w_wantcol = Columns - width; |
| 1347 | if (wp->w_wantcol < 1) |
| 1348 | wp->w_wantcol = 1; |
| 1349 | } |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1350 | popup_adjust_position(wp); |
| 1351 | } |
| 1352 | |
| 1353 | /* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1354 | * popup_create({text}, {options}) |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1355 | * popup_atcursor({text}, {options}) |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1356 | * etc. |
| 1357 | * When creating a preview window popup "argvars" and "rettv" are NULL. |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1358 | */ |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1359 | static win_T * |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1360 | popup_create(typval_T *argvars, typval_T *rettv, create_type_T type) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1361 | { |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1362 | win_T *wp; |
| 1363 | tabpage_T *tp = NULL; |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1364 | int tabnr = 0; |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1365 | int new_buffer; |
| 1366 | buf_T *buf = NULL; |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1367 | dict_T *d = NULL; |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1368 | int nr; |
| 1369 | int i; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1370 | |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1371 | if (argvars != NULL) |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1372 | { |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 1373 | // Check that arguments look OK. |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1374 | if (argvars[0].v_type == VAR_NUMBER) |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1375 | { |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1376 | buf = buflist_findnr( argvars[0].vval.v_number); |
| 1377 | if (buf == NULL) |
| 1378 | { |
| 1379 | semsg(_(e_nobufnr), argvars[0].vval.v_number); |
| 1380 | return NULL; |
| 1381 | } |
| 1382 | } |
| 1383 | else if (!(argvars[0].v_type == VAR_STRING |
| 1384 | && argvars[0].vval.v_string != NULL) |
| 1385 | && !(argvars[0].v_type == VAR_LIST |
| 1386 | && argvars[0].vval.v_list != NULL)) |
| 1387 | { |
| 1388 | emsg(_(e_listreq)); |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1389 | return NULL; |
| 1390 | } |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1391 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1392 | { |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1393 | emsg(_(e_dictreq)); |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1394 | return NULL; |
| 1395 | } |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1396 | d = argvars[1].vval.v_dict; |
| 1397 | } |
| 1398 | |
| 1399 | if (d != NULL) |
| 1400 | { |
| 1401 | if (dict_find(d, (char_u *)"tabpage", -1) != NULL) |
| 1402 | tabnr = (int)dict_get_number(d, (char_u *)"tabpage"); |
| 1403 | else if (type == TYPE_NOTIFICATION) |
| 1404 | tabnr = -1; // notifications are global by default |
| 1405 | else |
| 1406 | tabnr = 0; |
| 1407 | if (tabnr > 0) |
| 1408 | { |
| 1409 | tp = find_tabpage(tabnr); |
| 1410 | if (tp == NULL) |
| 1411 | { |
| 1412 | semsg(_("E997: Tabpage not found: %d"), tabnr); |
| 1413 | return NULL; |
| 1414 | } |
| 1415 | } |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1416 | } |
| 1417 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1418 | // Create the window and buffer. |
| 1419 | wp = win_alloc_popup_win(); |
| 1420 | if (wp == NULL) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1421 | return NULL; |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1422 | if (rettv != NULL) |
| 1423 | rettv->vval.v_number = wp->w_id; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1424 | wp->w_popup_pos = POPPOS_TOPLEFT; |
Bram Moolenaar | 749fa0a | 2019-08-03 16:18:07 +0200 | [diff] [blame^] | 1425 | wp->w_popup_flags = POPF_IS_POPUP | POPF_MAPPING; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1426 | |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1427 | if (buf != NULL) |
| 1428 | { |
| 1429 | // use existing buffer |
| 1430 | new_buffer = FALSE; |
Bram Moolenaar | 7866b87 | 2019-07-01 22:21:01 +0200 | [diff] [blame] | 1431 | win_init_popup_win(wp, buf); |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1432 | buffer_ensure_loaded(buf); |
| 1433 | } |
| 1434 | else |
| 1435 | { |
| 1436 | // create a new buffer associated with the popup |
| 1437 | new_buffer = TRUE; |
| 1438 | buf = buflist_new(NULL, NULL, (linenr_T)0, |
| 1439 | BLN_NEW|BLN_LISTED|BLN_DUMMY); |
| 1440 | if (buf == NULL) |
| 1441 | return NULL; |
| 1442 | ml_open(buf); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 1443 | |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1444 | win_init_popup_win(wp, buf); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 1445 | |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1446 | set_local_options_default(wp); |
| 1447 | set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1, |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1448 | (char_u *)"popup", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1449 | set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1, |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1450 | (char_u *)"wipe", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1451 | buf->b_p_ul = -1; // no undo |
| 1452 | buf->b_p_swf = FALSE; // no swap file |
| 1453 | buf->b_p_bl = FALSE; // unlisted buffer |
| 1454 | buf->b_locked = TRUE; |
| 1455 | wp->w_p_wrap = TRUE; // 'wrap' is default on |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1456 | |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1457 | // Avoid that 'buftype' is reset when this buffer is entered. |
| 1458 | buf->b_p_initialized = TRUE; |
| 1459 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1460 | |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1461 | if (tp != NULL) |
| 1462 | { |
| 1463 | // popup on specified tab page |
| 1464 | wp->w_next = tp->tp_first_popupwin; |
| 1465 | tp->tp_first_popupwin = wp; |
| 1466 | } |
| 1467 | else if (tabnr == 0) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1468 | { |
Bram Moolenaar | fc06cbb | 2019-06-15 14:14:31 +0200 | [diff] [blame] | 1469 | // popup on current tab page |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 1470 | wp->w_next = curtab->tp_first_popupwin; |
| 1471 | curtab->tp_first_popupwin = wp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1472 | } |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 1473 | else // (tabnr < 0) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1474 | { |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1475 | win_T *prev = first_popupwin; |
| 1476 | |
| 1477 | // Global popup: add at the end, so that it gets displayed on top of |
| 1478 | // older ones with the same zindex. Matters for notifications. |
| 1479 | if (first_popupwin == NULL) |
| 1480 | first_popupwin = wp; |
| 1481 | else |
| 1482 | { |
| 1483 | while (prev->w_next != NULL) |
| 1484 | prev = prev->w_next; |
| 1485 | prev->w_next = wp; |
| 1486 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1487 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1488 | |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1489 | if (new_buffer && argvars != NULL) |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1490 | popup_set_buffer_text(buf, argvars[0]); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1491 | |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1492 | if (type == TYPE_ATCURSOR || type == TYPE_PREVIEW) |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1493 | { |
| 1494 | wp->w_popup_pos = POPPOS_BOTLEFT; |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1495 | } |
| 1496 | if (type == TYPE_ATCURSOR) |
| 1497 | { |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1498 | popup_set_wantpos(wp, 0); |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1499 | set_moved_values(wp); |
| 1500 | set_moved_columns(wp, FIND_STRING); |
| 1501 | } |
| 1502 | |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1503 | if (type == TYPE_BEVAL) |
| 1504 | { |
| 1505 | wp->w_popup_pos = POPPOS_BOTLEFT; |
| 1506 | |
| 1507 | // by default use the mouse position |
| 1508 | wp->w_wantline = mouse_row; |
| 1509 | if (wp->w_wantline <= 0) // mouse on first line |
| 1510 | { |
| 1511 | wp->w_wantline = 2; |
| 1512 | wp->w_popup_pos = POPPOS_TOPLEFT; |
| 1513 | } |
| 1514 | wp->w_wantcol = mouse_col + 1; |
| 1515 | set_mousemoved_values(wp); |
| 1516 | set_mousemoved_columns(wp, FIND_IDENT + FIND_STRING + FIND_EVAL); |
| 1517 | } |
| 1518 | |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1519 | // set default values |
| 1520 | wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX; |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 1521 | wp->w_popup_close = POPCLOSE_NONE; |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1522 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1523 | if (type == TYPE_NOTIFICATION) |
| 1524 | { |
| 1525 | win_T *twp, *nextwin; |
| 1526 | int height = buf->b_ml.ml_line_count + 3; |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1527 | |
| 1528 | // Try to not overlap with another global popup. Guess we need 3 |
| 1529 | // more screen lines than buffer lines. |
| 1530 | wp->w_wantline = 1; |
| 1531 | for (twp = first_popupwin; twp != NULL; twp = nextwin) |
| 1532 | { |
| 1533 | nextwin = twp->w_next; |
| 1534 | if (twp != wp |
| 1535 | && twp->w_zindex == POPUPWIN_NOTIFICATION_ZINDEX |
| 1536 | && twp->w_winrow <= wp->w_wantline - 1 + height |
| 1537 | && twp->w_winrow + popup_height(twp) > wp->w_wantline - 1) |
| 1538 | { |
| 1539 | // move to below this popup and restart the loop to check for |
| 1540 | // overlap with other popups |
| 1541 | wp->w_wantline = twp->w_winrow + popup_height(twp) + 1; |
| 1542 | nextwin = first_popupwin; |
| 1543 | } |
| 1544 | } |
| 1545 | if (wp->w_wantline + height > Rows) |
| 1546 | { |
| 1547 | // can't avoid overlap, put on top in the hope that message goes |
| 1548 | // away soon. |
| 1549 | wp->w_wantline = 1; |
| 1550 | } |
| 1551 | |
| 1552 | wp->w_wantcol = 10; |
| 1553 | wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX; |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1554 | wp->w_minwidth = 20; |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 1555 | wp->w_popup_flags |= POPF_DRAG; |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 1556 | wp->w_popup_close = POPCLOSE_CLICK; |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1557 | for (i = 0; i < 4; ++i) |
| 1558 | wp->w_popup_border[i] = 1; |
| 1559 | wp->w_popup_padding[1] = 1; |
| 1560 | wp->w_popup_padding[3] = 1; |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1561 | |
| 1562 | nr = syn_name2id((char_u *)"PopupNotification"); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1563 | set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
Bram Moolenaar | dfa97f2 | 2019-06-15 14:31:55 +0200 | [diff] [blame] | 1564 | (char_u *)(nr == 0 ? "WarningMsg" : "PopupNotification"), |
| 1565 | OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1566 | } |
| 1567 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1568 | if (type == TYPE_DIALOG || type == TYPE_MENU) |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1569 | { |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1570 | wp->w_popup_pos = POPPOS_CENTER; |
| 1571 | wp->w_zindex = POPUPWIN_DIALOG_ZINDEX; |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 1572 | wp->w_popup_flags |= POPF_DRAG; |
Bram Moolenaar | 749fa0a | 2019-08-03 16:18:07 +0200 | [diff] [blame^] | 1573 | wp->w_popup_flags &= ~POPF_MAPPING; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1574 | for (i = 0; i < 4; ++i) |
| 1575 | { |
| 1576 | wp->w_popup_border[i] = 1; |
Bram Moolenaar | 0346413 | 2019-07-14 16:28:13 +0200 | [diff] [blame] | 1577 | wp->w_popup_padding[i] = (i & 1) ? 1 : 0; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1578 | } |
| 1579 | } |
| 1580 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1581 | if (type == TYPE_MENU) |
| 1582 | { |
| 1583 | typval_T tv; |
| 1584 | callback_T callback; |
| 1585 | |
| 1586 | tv.v_type = VAR_STRING; |
| 1587 | tv.vval.v_string = (char_u *)"popup_filter_menu"; |
| 1588 | callback = get_callback(&tv); |
| 1589 | if (callback.cb_name != NULL) |
| 1590 | set_callback(&wp->w_filter_cb, &callback); |
| 1591 | |
| 1592 | wp->w_p_wrap = 0; |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 1593 | wp->w_popup_flags |= POPF_CURSORLINE; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1594 | } |
| 1595 | |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1596 | if (type == TYPE_PREVIEW) |
| 1597 | { |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 1598 | wp->w_popup_flags |= POPF_DRAG | POPF_RESIZE; |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1599 | wp->w_popup_close = POPCLOSE_BUTTON; |
| 1600 | for (i = 0; i < 4; ++i) |
| 1601 | wp->w_popup_border[i] = 1; |
| 1602 | parse_previewpopup(wp); |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1603 | popup_set_wantpos(wp, wp->w_minwidth); |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1604 | } |
| 1605 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1606 | for (i = 0; i < 4; ++i) |
| 1607 | VIM_CLEAR(wp->w_border_highlight[i]); |
| 1608 | for (i = 0; i < 8; ++i) |
| 1609 | wp->w_border_char[i] = 0; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 1610 | wp->w_want_scrollbar = 1; |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 1611 | wp->w_popup_fixed = 0; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 1612 | |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 1613 | if (d != NULL) |
| 1614 | // Deal with options. |
| 1615 | apply_options(wp, d); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1616 | |
Bram Moolenaar | 0fcf26b | 2019-06-23 01:03:51 +0200 | [diff] [blame] | 1617 | #ifdef FEAT_TIMERS |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1618 | if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL) |
| 1619 | popup_add_timeout(wp, 3000); |
Bram Moolenaar | 0fcf26b | 2019-06-23 01:03:51 +0200 | [diff] [blame] | 1620 | #endif |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1621 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1622 | popup_adjust_position(wp); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1623 | |
| 1624 | wp->w_vsep_width = 0; |
| 1625 | |
| 1626 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1627 | popup_mask_refresh = TRUE; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1628 | |
| 1629 | return wp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | /* |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 1633 | * popup_clear() |
| 1634 | */ |
| 1635 | void |
| 1636 | f_popup_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
| 1637 | { |
| 1638 | close_all_popups(); |
| 1639 | } |
| 1640 | |
| 1641 | /* |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1642 | * popup_create({text}, {options}) |
| 1643 | */ |
| 1644 | void |
| 1645 | f_popup_create(typval_T *argvars, typval_T *rettv) |
| 1646 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1647 | popup_create(argvars, rettv, TYPE_NORMAL); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | /* |
| 1651 | * popup_atcursor({text}, {options}) |
| 1652 | */ |
| 1653 | void |
| 1654 | f_popup_atcursor(typval_T *argvars, typval_T *rettv) |
| 1655 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 1656 | popup_create(argvars, rettv, TYPE_ATCURSOR); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /* |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1660 | * popup_beval({text}, {options}) |
| 1661 | */ |
| 1662 | void |
| 1663 | f_popup_beval(typval_T *argvars, typval_T *rettv) |
| 1664 | { |
| 1665 | popup_create(argvars, rettv, TYPE_BEVAL); |
| 1666 | } |
| 1667 | |
| 1668 | /* |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1669 | * Invoke the close callback for window "wp" with value "result". |
| 1670 | * Careful: The callback may make "wp" invalid! |
| 1671 | */ |
| 1672 | static void |
| 1673 | invoke_popup_callback(win_T *wp, typval_T *result) |
| 1674 | { |
| 1675 | typval_T rettv; |
| 1676 | int dummy; |
| 1677 | typval_T argv[3]; |
| 1678 | |
| 1679 | argv[0].v_type = VAR_NUMBER; |
| 1680 | argv[0].vval.v_number = (varnumber_T)wp->w_id; |
| 1681 | |
| 1682 | if (result != NULL && result->v_type != VAR_UNKNOWN) |
| 1683 | copy_tv(result, &argv[1]); |
| 1684 | else |
| 1685 | { |
| 1686 | argv[1].v_type = VAR_NUMBER; |
| 1687 | argv[1].vval.v_number = 0; |
| 1688 | } |
| 1689 | |
| 1690 | argv[2].v_type = VAR_UNKNOWN; |
| 1691 | |
| 1692 | call_callback(&wp->w_close_cb, -1, |
| 1693 | &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
| 1694 | if (result != NULL) |
| 1695 | clear_tv(&argv[1]); |
| 1696 | clear_tv(&rettv); |
| 1697 | } |
| 1698 | |
| 1699 | /* |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1700 | * Close popup "wp" and invoke any close callback for it. |
| 1701 | */ |
| 1702 | static void |
| 1703 | popup_close_and_callback(win_T *wp, typval_T *arg) |
| 1704 | { |
| 1705 | int id = wp->w_id; |
| 1706 | |
| 1707 | if (wp->w_close_cb.cb_name != NULL) |
| 1708 | // Careful: This may make "wp" invalid. |
| 1709 | invoke_popup_callback(wp, arg); |
| 1710 | |
| 1711 | popup_close(id); |
| 1712 | } |
| 1713 | |
| 1714 | /* |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 1715 | * Close popup "wp" because of a mouse click. |
| 1716 | */ |
| 1717 | void |
| 1718 | popup_close_for_mouse_click(win_T *wp) |
| 1719 | { |
| 1720 | typval_T res; |
| 1721 | |
| 1722 | res.v_type = VAR_NUMBER; |
| 1723 | res.vval.v_number = -2; |
| 1724 | popup_close_and_callback(wp, &res); |
| 1725 | } |
| 1726 | |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1727 | static void |
| 1728 | check_mouse_moved(win_T *wp, win_T *mouse_wp) |
| 1729 | { |
| 1730 | // Close the popup when all if these are true: |
| 1731 | // - the mouse is not on this popup |
| 1732 | // - "mousemoved" was used |
| 1733 | // - the mouse is no longer on the same screen row or the mouse column is |
| 1734 | // outside of the relevant text |
| 1735 | if (wp != mouse_wp |
| 1736 | && wp->w_popup_mouse_row != 0 |
| 1737 | && (wp->w_popup_mouse_row != mouse_row |
| 1738 | || mouse_col < wp->w_popup_mouse_mincol |
| 1739 | || mouse_col > wp->w_popup_mouse_maxcol)) |
| 1740 | { |
| 1741 | typval_T res; |
| 1742 | |
| 1743 | res.v_type = VAR_NUMBER; |
| 1744 | res.vval.v_number = -2; |
Bram Moolenaar | 3e35d05 | 2019-07-07 20:43:34 +0200 | [diff] [blame] | 1745 | // Careful: this makes "wp" invalid. |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1746 | popup_close_and_callback(wp, &res); |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | /* |
| 1751 | * Called when the mouse moved: may close a popup with "mousemoved". |
| 1752 | */ |
| 1753 | void |
| 1754 | popup_handle_mouse_moved(void) |
| 1755 | { |
Bram Moolenaar | 3e35d05 | 2019-07-07 20:43:34 +0200 | [diff] [blame] | 1756 | win_T *wp, *nextwp; |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1757 | win_T *mouse_wp; |
| 1758 | int row = mouse_row; |
| 1759 | int col = mouse_col; |
| 1760 | |
| 1761 | // find the window where the mouse is in |
| 1762 | mouse_wp = mouse_find_win(&row, &col, FIND_POPUP); |
| 1763 | |
Bram Moolenaar | 3e35d05 | 2019-07-07 20:43:34 +0200 | [diff] [blame] | 1764 | for (wp = first_popupwin; wp != NULL; wp = nextwp) |
| 1765 | { |
| 1766 | nextwp = wp->w_next; |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1767 | check_mouse_moved(wp, mouse_wp); |
Bram Moolenaar | 3e35d05 | 2019-07-07 20:43:34 +0200 | [diff] [blame] | 1768 | } |
| 1769 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = nextwp) |
| 1770 | { |
| 1771 | nextwp = wp->w_next; |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1772 | check_mouse_moved(wp, mouse_wp); |
Bram Moolenaar | 3e35d05 | 2019-07-07 20:43:34 +0200 | [diff] [blame] | 1773 | } |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 1774 | } |
| 1775 | |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 1776 | /* |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1777 | * In a filter: check if the typed key is a mouse event that is used for |
| 1778 | * dragging the popup. |
| 1779 | */ |
| 1780 | static void |
| 1781 | filter_handle_drag(win_T *wp, int c, typval_T *rettv) |
| 1782 | { |
| 1783 | int row = mouse_row; |
| 1784 | int col = mouse_col; |
| 1785 | |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 1786 | if ((wp->w_popup_flags & POPF_DRAG) |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1787 | && is_mouse_key(c) |
| 1788 | && (wp == popup_dragwin |
| 1789 | || wp == mouse_find_win(&row, &col, FIND_POPUP))) |
| 1790 | // do not consume the key, allow for dragging the popup |
| 1791 | rettv->vval.v_number = 0; |
| 1792 | } |
| 1793 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1794 | /* |
| 1795 | * popup_filter_menu({text}, {options}) |
| 1796 | */ |
| 1797 | void |
| 1798 | f_popup_filter_menu(typval_T *argvars, typval_T *rettv) |
| 1799 | { |
| 1800 | int id = tv_get_number(&argvars[0]); |
| 1801 | win_T *wp = win_id2wp(id); |
| 1802 | char_u *key = tv_get_string(&argvars[1]); |
| 1803 | typval_T res; |
| 1804 | int c; |
| 1805 | linenr_T old_lnum; |
| 1806 | |
| 1807 | // If the popup has been closed do not consume the key. |
| 1808 | if (wp == NULL) |
| 1809 | return; |
| 1810 | |
| 1811 | c = *key; |
| 1812 | if (c == K_SPECIAL && key[1] != NUL) |
| 1813 | c = TO_SPECIAL(key[1], key[2]); |
| 1814 | |
| 1815 | // consume all keys until done |
| 1816 | rettv->vval.v_number = 1; |
| 1817 | res.v_type = VAR_NUMBER; |
| 1818 | |
| 1819 | old_lnum = wp->w_cursor.lnum; |
| 1820 | if ((c == 'k' || c == 'K' || c == K_UP) && wp->w_cursor.lnum > 1) |
| 1821 | --wp->w_cursor.lnum; |
| 1822 | if ((c == 'j' || c == 'J' || c == K_DOWN) |
| 1823 | && wp->w_cursor.lnum < wp->w_buffer->b_ml.ml_line_count) |
| 1824 | ++wp->w_cursor.lnum; |
| 1825 | if (old_lnum != wp->w_cursor.lnum) |
| 1826 | { |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 1827 | // caller will call popup_highlight_curline() |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1828 | return; |
| 1829 | } |
| 1830 | |
| 1831 | if (c == 'x' || c == 'X' || c == ESC || c == Ctrl_C) |
| 1832 | { |
| 1833 | // Cancelled, invoke callback with -1 |
| 1834 | res.vval.v_number = -1; |
| 1835 | popup_close_and_callback(wp, &res); |
| 1836 | return; |
| 1837 | } |
| 1838 | if (c == ' ' || c == K_KENTER || c == CAR || c == NL) |
| 1839 | { |
| 1840 | // Invoke callback with current index. |
| 1841 | res.vval.v_number = wp->w_cursor.lnum; |
| 1842 | popup_close_and_callback(wp, &res); |
| 1843 | return; |
| 1844 | } |
| 1845 | |
| 1846 | filter_handle_drag(wp, c, rettv); |
| 1847 | } |
| 1848 | |
| 1849 | /* |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1850 | * popup_filter_yesno({text}, {options}) |
| 1851 | */ |
| 1852 | void |
| 1853 | f_popup_filter_yesno(typval_T *argvars, typval_T *rettv) |
| 1854 | { |
| 1855 | int id = tv_get_number(&argvars[0]); |
| 1856 | win_T *wp = win_id2wp(id); |
| 1857 | char_u *key = tv_get_string(&argvars[1]); |
| 1858 | typval_T res; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1859 | int c; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1860 | |
| 1861 | // If the popup has been closed don't consume the key. |
| 1862 | if (wp == NULL) |
| 1863 | return; |
| 1864 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1865 | c = *key; |
| 1866 | if (c == K_SPECIAL && key[1] != NUL) |
| 1867 | c = TO_SPECIAL(key[1], key[2]); |
| 1868 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1869 | // consume all keys until done |
| 1870 | rettv->vval.v_number = 1; |
| 1871 | |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1872 | if (c == 'y' || c == 'Y') |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1873 | res.vval.v_number = 1; |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1874 | else if (c == 'n' || c == 'N' || c == 'x' || c == 'X' || c == ESC) |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1875 | res.vval.v_number = 0; |
| 1876 | else |
| 1877 | { |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1878 | filter_handle_drag(wp, c, rettv); |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1879 | return; |
| 1880 | } |
| 1881 | |
| 1882 | // Invoke callback |
| 1883 | res.v_type = VAR_NUMBER; |
| 1884 | popup_close_and_callback(wp, &res); |
| 1885 | } |
| 1886 | |
| 1887 | /* |
| 1888 | * popup_dialog({text}, {options}) |
| 1889 | */ |
| 1890 | void |
| 1891 | f_popup_dialog(typval_T *argvars, typval_T *rettv) |
| 1892 | { |
| 1893 | popup_create(argvars, rettv, TYPE_DIALOG); |
| 1894 | } |
| 1895 | |
| 1896 | /* |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1897 | * popup_menu({text}, {options}) |
| 1898 | */ |
| 1899 | void |
| 1900 | f_popup_menu(typval_T *argvars, typval_T *rettv) |
| 1901 | { |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 1902 | popup_create(argvars, rettv, TYPE_MENU); |
Bram Moolenaar | a730e55 | 2019-06-16 19:05:31 +0200 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | /* |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1906 | * popup_notification({text}, {options}) |
| 1907 | */ |
| 1908 | void |
| 1909 | f_popup_notification(typval_T *argvars, typval_T *rettv) |
| 1910 | { |
| 1911 | popup_create(argvars, rettv, TYPE_NOTIFICATION); |
| 1912 | } |
| 1913 | |
| 1914 | /* |
| 1915 | * Find the popup window with window-ID "id". |
| 1916 | * If the popup window does not exist NULL is returned. |
| 1917 | * If the window is not a popup window, and error message is given. |
| 1918 | */ |
| 1919 | static win_T * |
| 1920 | find_popup_win(int id) |
| 1921 | { |
| 1922 | win_T *wp = win_id2wp(id); |
| 1923 | |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1924 | if (wp != NULL && !WIN_IS_POPUP(wp)) |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 1925 | { |
| 1926 | semsg(_("E993: window %d is not a popup window"), id); |
| 1927 | return NULL; |
| 1928 | } |
| 1929 | return wp; |
| 1930 | } |
| 1931 | |
| 1932 | /* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1933 | * popup_close({id}) |
| 1934 | */ |
| 1935 | void |
| 1936 | f_popup_close(typval_T *argvars, typval_T *rettv UNUSED) |
| 1937 | { |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1938 | int id = (int)tv_get_number(argvars); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1939 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1940 | |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1941 | if (wp != NULL) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1942 | popup_close_and_callback(wp, &argvars[1]); |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | /* |
| 1946 | * popup_hide({id}) |
| 1947 | */ |
| 1948 | void |
| 1949 | f_popup_hide(typval_T *argvars, typval_T *rettv UNUSED) |
| 1950 | { |
| 1951 | int id = (int)tv_get_number(argvars); |
| 1952 | win_T *wp = find_popup_win(id); |
| 1953 | |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1954 | if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) == 0) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1955 | { |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1956 | wp->w_popup_flags |= POPF_HIDDEN; |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 1957 | --wp->w_buffer->b_nwindows; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1958 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1959 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | /* |
| 1964 | * popup_show({id}) |
| 1965 | */ |
| 1966 | void |
| 1967 | f_popup_show(typval_T *argvars, typval_T *rettv UNUSED) |
| 1968 | { |
| 1969 | int id = (int)tv_get_number(argvars); |
| 1970 | win_T *wp = find_popup_win(id); |
| 1971 | |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1972 | if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) != 0) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1973 | { |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1974 | wp->w_popup_flags &= ~POPF_HIDDEN; |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 1975 | ++wp->w_buffer->b_nwindows; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1976 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1977 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1978 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1979 | } |
| 1980 | |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 1981 | /* |
| 1982 | * popup_settext({id}, {text}) |
| 1983 | */ |
| 1984 | void |
| 1985 | f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED) |
| 1986 | { |
| 1987 | int id = (int)tv_get_number(&argvars[0]); |
| 1988 | win_T *wp = find_popup_win(id); |
| 1989 | |
| 1990 | if (wp != NULL) |
| 1991 | { |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1992 | if (argvars[1].v_type != VAR_STRING && argvars[1].v_type != VAR_LIST) |
| 1993 | semsg(_(e_invarg2), tv_get_string(&argvars[1])); |
| 1994 | else |
| 1995 | { |
| 1996 | popup_set_buffer_text(wp->w_buffer, argvars[1]); |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 1997 | redraw_win_later(wp, NOT_VALID); |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 1998 | popup_adjust_position(wp); |
| 1999 | } |
Bram Moolenaar | dc2ce58 | 2019-06-16 15:32:14 +0200 | [diff] [blame] | 2000 | } |
| 2001 | } |
| 2002 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 2003 | static void |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 2004 | popup_free(win_T *wp) |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 2005 | { |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 2006 | sign_undefine_by_name(popup_get_sign_name(wp), FALSE); |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 2007 | wp->w_buffer->b_locked = FALSE; |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 2008 | if (wp->w_winrow + popup_height(wp) >= cmdline_row) |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 2009 | clear_cmdline = TRUE; |
| 2010 | win_free_popup(wp); |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 2011 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 2012 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 2013 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 2014 | } |
| 2015 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2016 | /* |
| 2017 | * Close a popup window by Window-id. |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 2018 | * Does not invoke the callback. |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2019 | */ |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2020 | void |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2021 | popup_close(int id) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2022 | { |
| 2023 | win_T *wp; |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2024 | tabpage_T *tp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2025 | win_T *prev = NULL; |
| 2026 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2027 | // go through global popups |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2028 | for (wp = first_popupwin; wp != NULL; prev = wp, wp = wp->w_next) |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2029 | if (wp->w_id == id) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2030 | { |
| 2031 | if (prev == NULL) |
| 2032 | first_popupwin = wp->w_next; |
| 2033 | else |
| 2034 | prev->w_next = wp->w_next; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 2035 | popup_free(wp); |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2036 | return; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2037 | } |
| 2038 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2039 | // go through tab-local popups |
| 2040 | FOR_ALL_TABPAGES(tp) |
| 2041 | popup_close_tabpage(tp, id); |
| 2042 | } |
| 2043 | |
| 2044 | /* |
| 2045 | * Close a popup window with Window-id "id" in tabpage "tp". |
| 2046 | */ |
| 2047 | void |
| 2048 | popup_close_tabpage(tabpage_T *tp, int id) |
| 2049 | { |
| 2050 | win_T *wp; |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 2051 | win_T **root = &tp->tp_first_popupwin; |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2052 | win_T *prev = NULL; |
| 2053 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2054 | for (wp = *root; wp != NULL; prev = wp, wp = wp->w_next) |
| 2055 | if (wp->w_id == id) |
| 2056 | { |
| 2057 | if (prev == NULL) |
| 2058 | *root = wp->w_next; |
| 2059 | else |
| 2060 | prev->w_next = wp->w_next; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 2061 | popup_free(wp); |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 2062 | return; |
| 2063 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | void |
| 2067 | close_all_popups(void) |
| 2068 | { |
| 2069 | while (first_popupwin != NULL) |
| 2070 | popup_close(first_popupwin->w_id); |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 2071 | while (curtab->tp_first_popupwin != NULL) |
| 2072 | popup_close(curtab->tp_first_popupwin->w_id); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 2073 | } |
| 2074 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 2075 | /* |
| 2076 | * popup_move({id}, {options}) |
| 2077 | */ |
| 2078 | void |
| 2079 | f_popup_move(typval_T *argvars, typval_T *rettv UNUSED) |
| 2080 | { |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2081 | dict_T *dict; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 2082 | int id = (int)tv_get_number(argvars); |
| 2083 | win_T *wp = find_popup_win(id); |
| 2084 | |
| 2085 | if (wp == NULL) |
| 2086 | return; // invalid {id} |
| 2087 | |
| 2088 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 2089 | { |
| 2090 | emsg(_(e_dictreq)); |
| 2091 | return; |
| 2092 | } |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2093 | dict = argvars[1].vval.v_dict; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 2094 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2095 | apply_move_options(wp, dict); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 2096 | |
| 2097 | if (wp->w_winrow + wp->w_height >= cmdline_row) |
| 2098 | clear_cmdline = TRUE; |
| 2099 | popup_adjust_position(wp); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 2100 | } |
| 2101 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 2102 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2103 | * popup_setoptions({id}, {options}) |
| 2104 | */ |
| 2105 | void |
| 2106 | f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED) |
| 2107 | { |
| 2108 | dict_T *dict; |
| 2109 | int id = (int)tv_get_number(argvars); |
| 2110 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2111 | linenr_T old_firstline; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2112 | |
| 2113 | if (wp == NULL) |
| 2114 | return; // invalid {id} |
| 2115 | |
| 2116 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 2117 | { |
| 2118 | emsg(_(e_dictreq)); |
| 2119 | return; |
| 2120 | } |
| 2121 | dict = argvars[1].vval.v_dict; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2122 | old_firstline = wp->w_firstline; |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2123 | |
| 2124 | apply_move_options(wp, dict); |
| 2125 | apply_general_options(wp, dict); |
| 2126 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2127 | if (old_firstline != wp->w_firstline) |
| 2128 | redraw_win_later(wp, NOT_VALID); |
Bram Moolenaar | ad24a71 | 2019-06-17 20:05:45 +0200 | [diff] [blame] | 2129 | popup_mask_refresh = TRUE; |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 2130 | popup_highlight_curline(wp); |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2131 | popup_adjust_position(wp); |
| 2132 | } |
| 2133 | |
| 2134 | /* |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 2135 | * popup_getpos({id}) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 2136 | */ |
| 2137 | void |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 2138 | f_popup_getpos(typval_T *argvars, typval_T *rettv) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 2139 | { |
| 2140 | dict_T *dict; |
| 2141 | int id = (int)tv_get_number(argvars); |
| 2142 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 2143 | int top_extra; |
| 2144 | int left_extra; |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 2145 | |
| 2146 | if (rettv_dict_alloc(rettv) == OK) |
| 2147 | { |
| 2148 | if (wp == NULL) |
| 2149 | return; // invalid {id} |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2150 | top_extra = popup_top_extra(wp); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 2151 | left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
| 2152 | |
Bram Moolenaar | 7b73d7e | 2019-07-26 21:26:34 +0200 | [diff] [blame] | 2153 | // we know how much space we need, avoid resizing halfway |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 2154 | dict = rettv->vval.v_dict; |
Bram Moolenaar | 7b73d7e | 2019-07-26 21:26:34 +0200 | [diff] [blame] | 2155 | hash_lock_size(&dict->dv_hashtab, 11); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 2156 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 2157 | dict_add_number(dict, "line", wp->w_winrow + 1); |
| 2158 | dict_add_number(dict, "col", wp->w_wincol + 1); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 2159 | dict_add_number(dict, "width", wp->w_width + left_extra |
| 2160 | + wp->w_popup_border[1] + wp->w_popup_padding[1]); |
| 2161 | dict_add_number(dict, "height", wp->w_height + top_extra |
| 2162 | + wp->w_popup_border[2] + wp->w_popup_padding[2]); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 2163 | |
| 2164 | dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra); |
| 2165 | dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra); |
| 2166 | dict_add_number(dict, "core_width", wp->w_width); |
| 2167 | dict_add_number(dict, "core_height", wp->w_height); |
| 2168 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2169 | dict_add_number(dict, "scrollbar", wp->w_has_scrollbar); |
Bram Moolenaar | 68acb41 | 2019-06-26 03:40:36 +0200 | [diff] [blame] | 2170 | dict_add_number(dict, "firstline", wp->w_topline); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 2171 | dict_add_number(dict, "visible", |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 2172 | win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0); |
Bram Moolenaar | 7b73d7e | 2019-07-26 21:26:34 +0200 | [diff] [blame] | 2173 | |
| 2174 | hash_unlock(&dict->dv_hashtab); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 2175 | } |
| 2176 | } |
Bram Moolenaar | b4f0628 | 2019-07-12 21:07:54 +0200 | [diff] [blame] | 2177 | /* |
| 2178 | * popup_locate({row}, {col}) |
| 2179 | */ |
| 2180 | void |
| 2181 | f_popup_locate(typval_T *argvars, typval_T *rettv) |
| 2182 | { |
| 2183 | int row = tv_get_number(&argvars[0]) - 1; |
| 2184 | int col = tv_get_number(&argvars[1]) - 1; |
| 2185 | win_T *wp; |
| 2186 | |
| 2187 | wp = mouse_find_win(&row, &col, FIND_POPUP); |
| 2188 | if (WIN_IS_POPUP(wp)) |
| 2189 | rettv->vval.v_number = wp->w_id; |
| 2190 | } |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 2191 | |
| 2192 | /* |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2193 | * For popup_getoptions(): add a "border" or "padding" entry to "dict". |
| 2194 | */ |
| 2195 | static void |
| 2196 | get_padding_border(dict_T *dict, int *array, char *name) |
| 2197 | { |
| 2198 | list_T *list; |
| 2199 | int i; |
| 2200 | |
| 2201 | if (array[0] == 0 && array[1] == 0 && array[2] == 0 && array[3] == 0) |
| 2202 | return; |
| 2203 | |
| 2204 | list = list_alloc(); |
| 2205 | if (list != NULL) |
| 2206 | { |
| 2207 | dict_add_list(dict, name, list); |
| 2208 | if (array[0] != 1 || array[1] != 1 || array[2] != 1 || array[3] != 1) |
| 2209 | for (i = 0; i < 4; ++i) |
| 2210 | list_append_number(list, array[i]); |
| 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | /* |
| 2215 | * For popup_getoptions(): add a "borderhighlight" entry to "dict". |
| 2216 | */ |
| 2217 | static void |
| 2218 | get_borderhighlight(dict_T *dict, win_T *wp) |
| 2219 | { |
| 2220 | list_T *list; |
| 2221 | int i; |
| 2222 | |
| 2223 | for (i = 0; i < 4; ++i) |
| 2224 | if (wp->w_border_highlight[i] != NULL) |
| 2225 | break; |
| 2226 | if (i == 4) |
| 2227 | return; |
| 2228 | |
| 2229 | list = list_alloc(); |
| 2230 | if (list != NULL) |
| 2231 | { |
| 2232 | dict_add_list(dict, "borderhighlight", list); |
| 2233 | for (i = 0; i < 4; ++i) |
| 2234 | list_append_string(list, wp->w_border_highlight[i], -1); |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | /* |
| 2239 | * For popup_getoptions(): add a "borderchars" entry to "dict". |
| 2240 | */ |
| 2241 | static void |
| 2242 | get_borderchars(dict_T *dict, win_T *wp) |
| 2243 | { |
| 2244 | list_T *list; |
| 2245 | int i; |
| 2246 | char_u buf[NUMBUFLEN]; |
| 2247 | int len; |
| 2248 | |
| 2249 | for (i = 0; i < 8; ++i) |
| 2250 | if (wp->w_border_char[i] != 0) |
| 2251 | break; |
| 2252 | if (i == 8) |
| 2253 | return; |
| 2254 | |
| 2255 | list = list_alloc(); |
| 2256 | if (list != NULL) |
| 2257 | { |
| 2258 | dict_add_list(dict, "borderchars", list); |
| 2259 | for (i = 0; i < 8; ++i) |
| 2260 | { |
| 2261 | len = mb_char2bytes(wp->w_border_char[i], buf); |
| 2262 | list_append_string(list, buf, len); |
| 2263 | } |
| 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | /* |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 2268 | * For popup_getoptions(): add a "moved" and "mousemoved" entry to "dict". |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2269 | */ |
| 2270 | static void |
| 2271 | get_moved_list(dict_T *dict, win_T *wp) |
| 2272 | { |
| 2273 | list_T *list; |
| 2274 | |
| 2275 | list = list_alloc(); |
| 2276 | if (list != NULL) |
| 2277 | { |
| 2278 | dict_add_list(dict, "moved", list); |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 2279 | list_append_number(list, wp->w_popup_lnum); |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2280 | list_append_number(list, wp->w_popup_mincol); |
| 2281 | list_append_number(list, wp->w_popup_maxcol); |
| 2282 | } |
Bram Moolenaar | b3d17a2 | 2019-07-07 18:28:14 +0200 | [diff] [blame] | 2283 | list = list_alloc(); |
| 2284 | if (list != NULL) |
| 2285 | { |
| 2286 | dict_add_list(dict, "mousemoved", list); |
| 2287 | list_append_number(list, wp->w_popup_mouse_row); |
| 2288 | list_append_number(list, wp->w_popup_mouse_mincol); |
| 2289 | list_append_number(list, wp->w_popup_mouse_maxcol); |
| 2290 | } |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | /* |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 2294 | * popup_getoptions({id}) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 2295 | */ |
| 2296 | void |
| 2297 | f_popup_getoptions(typval_T *argvars, typval_T *rettv) |
| 2298 | { |
| 2299 | dict_T *dict; |
| 2300 | int id = (int)tv_get_number(argvars); |
| 2301 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 2302 | tabpage_T *tp; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 2303 | int i; |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 2304 | |
| 2305 | if (rettv_dict_alloc(rettv) == OK) |
| 2306 | { |
| 2307 | if (wp == NULL) |
| 2308 | return; |
| 2309 | |
| 2310 | dict = rettv->vval.v_dict; |
| 2311 | dict_add_number(dict, "line", wp->w_wantline); |
| 2312 | dict_add_number(dict, "col", wp->w_wantcol); |
| 2313 | dict_add_number(dict, "minwidth", wp->w_minwidth); |
| 2314 | dict_add_number(dict, "minheight", wp->w_minheight); |
| 2315 | dict_add_number(dict, "maxheight", wp->w_maxheight); |
| 2316 | dict_add_number(dict, "maxwidth", wp->w_maxwidth); |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 2317 | dict_add_number(dict, "firstline", wp->w_firstline); |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2318 | dict_add_number(dict, "scrollbar", wp->w_want_scrollbar); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 2319 | dict_add_number(dict, "zindex", wp->w_zindex); |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 2320 | dict_add_number(dict, "fixed", wp->w_popup_fixed); |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2321 | dict_add_string(dict, "title", wp->w_popup_title); |
| 2322 | dict_add_number(dict, "wrap", wp->w_p_wrap); |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 2323 | dict_add_number(dict, "drag", (wp->w_popup_flags & POPF_DRAG) != 0); |
| 2324 | dict_add_number(dict, "resize", (wp->w_popup_flags & POPF_RESIZE) != 0); |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 2325 | dict_add_number(dict, "cursorline", |
| 2326 | (wp->w_popup_flags & POPF_CURSORLINE) != 0); |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2327 | dict_add_string(dict, "highlight", wp->w_p_wcr); |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 2328 | if (wp->w_scrollbar_highlight != NULL) |
| 2329 | dict_add_string(dict, "scrollbarhighlight", |
| 2330 | wp->w_scrollbar_highlight); |
| 2331 | if (wp->w_thumb_highlight != NULL) |
| 2332 | dict_add_string(dict, "thumbhighlight", wp->w_thumb_highlight); |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2333 | |
Bram Moolenaar | a3fce62 | 2019-06-20 02:31:49 +0200 | [diff] [blame] | 2334 | // find the tabpage that holds this popup |
| 2335 | i = 1; |
| 2336 | FOR_ALL_TABPAGES(tp) |
| 2337 | { |
| 2338 | win_T *p; |
| 2339 | |
| 2340 | for (p = tp->tp_first_popupwin; p != NULL; p = wp->w_next) |
| 2341 | if (p->w_id == id) |
| 2342 | break; |
| 2343 | if (p != NULL) |
| 2344 | break; |
| 2345 | ++i; |
| 2346 | } |
| 2347 | if (tp == NULL) |
| 2348 | i = -1; // must be global |
| 2349 | else if (tp == curtab) |
| 2350 | i = 0; |
| 2351 | dict_add_number(dict, "tabpage", i); |
| 2352 | |
Bram Moolenaar | ae94315 | 2019-06-16 22:54:14 +0200 | [diff] [blame] | 2353 | get_padding_border(dict, wp->w_popup_padding, "padding"); |
| 2354 | get_padding_border(dict, wp->w_popup_border, "border"); |
| 2355 | get_borderhighlight(dict, wp); |
| 2356 | get_borderchars(dict, wp); |
| 2357 | get_moved_list(dict, wp); |
| 2358 | |
| 2359 | if (wp->w_filter_cb.cb_name != NULL) |
| 2360 | dict_add_callback(dict, "filter", &wp->w_filter_cb); |
| 2361 | if (wp->w_close_cb.cb_name != NULL) |
| 2362 | dict_add_callback(dict, "callback", &wp->w_close_cb); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 2363 | |
| 2364 | for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); |
| 2365 | ++i) |
| 2366 | if (wp->w_popup_pos == poppos_entries[i].pp_val) |
| 2367 | { |
| 2368 | dict_add_string(dict, "pos", |
| 2369 | (char_u *)poppos_entries[i].pp_name); |
| 2370 | break; |
| 2371 | } |
| 2372 | |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 2373 | dict_add_string(dict, "close", (char_u *)( |
| 2374 | wp->w_popup_close == POPCLOSE_BUTTON ? "button" |
| 2375 | : wp->w_popup_close == POPCLOSE_CLICK ? "click" : "none")); |
| 2376 | |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 2377 | # if defined(FEAT_TIMERS) |
| 2378 | dict_add_number(dict, "time", wp->w_popup_timer != NULL |
| 2379 | ? (long)wp->w_popup_timer->tr_interval : 0L); |
| 2380 | # endif |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 2381 | } |
| 2382 | } |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 2383 | |
| 2384 | int |
Bram Moolenaar | 8cdbd5b | 2019-06-16 15:50:45 +0200 | [diff] [blame] | 2385 | error_if_popup_window() |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 2386 | { |
Bram Moolenaar | 5b8cfed | 2019-06-30 22:16:10 +0200 | [diff] [blame] | 2387 | if (WIN_IS_POPUP(curwin)) |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 2388 | { |
| 2389 | emsg(_("E994: Not allowed in a popup window")); |
| 2390 | return TRUE; |
| 2391 | } |
| 2392 | return FALSE; |
| 2393 | } |
| 2394 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 2395 | /* |
| 2396 | * 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] | 2397 | * in the current tab page. |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 2398 | */ |
| 2399 | void |
| 2400 | popup_reset_handled() |
| 2401 | { |
| 2402 | win_T *wp; |
| 2403 | |
| 2404 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 2405 | wp->w_popup_flags &= ~POPF_HANDLED; |
| 2406 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 2407 | wp->w_popup_flags &= ~POPF_HANDLED; |
| 2408 | } |
| 2409 | |
| 2410 | /* |
| 2411 | * Find the next visible popup where POPF_HANDLED is not set. |
| 2412 | * Must have called popup_reset_handled() first. |
| 2413 | * When "lowest" is TRUE find the popup with the lowest zindex, otherwise the |
| 2414 | * popup with the highest zindex. |
| 2415 | */ |
| 2416 | win_T * |
| 2417 | find_next_popup(int lowest) |
| 2418 | { |
| 2419 | win_T *wp; |
| 2420 | win_T *found_wp; |
| 2421 | int found_zindex; |
| 2422 | |
| 2423 | found_zindex = lowest ? INT_MAX : 0; |
| 2424 | found_wp = NULL; |
| 2425 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 2426 | if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0 |
| 2427 | && (lowest ? wp->w_zindex < found_zindex |
| 2428 | : wp->w_zindex > found_zindex)) |
| 2429 | { |
| 2430 | found_zindex = wp->w_zindex; |
| 2431 | found_wp = wp; |
| 2432 | } |
| 2433 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 2434 | if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0 |
| 2435 | && (lowest ? wp->w_zindex < found_zindex |
| 2436 | : wp->w_zindex > found_zindex)) |
| 2437 | { |
| 2438 | found_zindex = wp->w_zindex; |
| 2439 | found_wp = wp; |
| 2440 | } |
| 2441 | |
| 2442 | if (found_wp != NULL) |
| 2443 | found_wp->w_popup_flags |= POPF_HANDLED; |
| 2444 | return found_wp; |
| 2445 | } |
| 2446 | |
| 2447 | /* |
| 2448 | * Invoke the filter callback for window "wp" with typed character "c". |
| 2449 | * Uses the global "mod_mask" for modifiers. |
| 2450 | * Returns the return value of the filter. |
| 2451 | * Careful: The filter may make "wp" invalid! |
| 2452 | */ |
| 2453 | static int |
| 2454 | invoke_popup_filter(win_T *wp, int c) |
| 2455 | { |
| 2456 | int res; |
| 2457 | typval_T rettv; |
| 2458 | int dummy; |
| 2459 | typval_T argv[3]; |
| 2460 | char_u buf[NUMBUFLEN]; |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 2461 | linenr_T old_lnum = wp->w_cursor.lnum; |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 2462 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 2463 | // Emergency exit: CTRL-C closes the popup. |
| 2464 | if (c == Ctrl_C) |
| 2465 | { |
| 2466 | rettv.v_type = VAR_NUMBER; |
| 2467 | rettv.vval.v_number = -1; |
| 2468 | popup_close_and_callback(wp, &rettv); |
| 2469 | return 1; |
| 2470 | } |
| 2471 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 2472 | argv[0].v_type = VAR_NUMBER; |
| 2473 | argv[0].vval.v_number = (varnumber_T)wp->w_id; |
| 2474 | |
| 2475 | // Convert the number to a string, so that the function can use: |
| 2476 | // if a:c == "\<F2>" |
| 2477 | buf[special_to_buf(c, mod_mask, TRUE, buf)] = NUL; |
| 2478 | argv[1].v_type = VAR_STRING; |
| 2479 | argv[1].vval.v_string = vim_strsave(buf); |
| 2480 | |
| 2481 | argv[2].v_type = VAR_UNKNOWN; |
| 2482 | |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 2483 | // NOTE: The callback might close the popup, thus make "wp" invalid. |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 2484 | call_callback(&wp->w_filter_cb, -1, |
| 2485 | &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
Bram Moolenaar | cb5ff34 | 2019-07-20 16:51:19 +0200 | [diff] [blame] | 2486 | if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum) |
Bram Moolenaar | df9c6ca | 2019-07-18 13:46:42 +0200 | [diff] [blame] | 2487 | popup_highlight_curline(wp); |
| 2488 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 2489 | res = tv_get_number(&rettv); |
| 2490 | vim_free(argv[1].vval.v_string); |
| 2491 | clear_tv(&rettv); |
| 2492 | return res; |
| 2493 | } |
| 2494 | |
| 2495 | /* |
| 2496 | * Called when "c" was typed: invoke popup filter callbacks. |
| 2497 | * Returns TRUE when the character was consumed, |
| 2498 | */ |
| 2499 | int |
| 2500 | popup_do_filter(int c) |
| 2501 | { |
| 2502 | int res = FALSE; |
Bram Moolenaar | a42d945 | 2019-06-15 21:46:30 +0200 | [diff] [blame] | 2503 | win_T *wp; |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 2504 | |
| 2505 | popup_reset_handled(); |
| 2506 | |
| 2507 | while (!res && (wp = find_next_popup(FALSE)) != NULL) |
| 2508 | if (wp->w_filter_cb.cb_name != NULL) |
| 2509 | res = invoke_popup_filter(wp, c); |
| 2510 | |
| 2511 | return res; |
| 2512 | } |
| 2513 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 2514 | /* |
Bram Moolenaar | 749fa0a | 2019-08-03 16:18:07 +0200 | [diff] [blame^] | 2515 | * Return TRUE if there is a popup visible with a filter callback and the |
| 2516 | * "mapping" property off. |
| 2517 | */ |
| 2518 | int |
| 2519 | popup_no_mapping(void) |
| 2520 | { |
| 2521 | int round; |
| 2522 | win_T *wp; |
| 2523 | |
| 2524 | for (round = 1; round <= 2; ++round) |
| 2525 | for (wp = round == 1 ? first_popupwin : curtab->tp_first_popupwin; |
| 2526 | wp != NULL; wp = wp->w_next) |
| 2527 | if (wp->w_filter_cb.cb_name != NULL |
| 2528 | && (wp->w_popup_flags & (POPF_HIDDEN | POPF_MAPPING)) == 0) |
| 2529 | return TRUE; |
| 2530 | return FALSE; |
| 2531 | } |
| 2532 | |
| 2533 | /* |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 2534 | * Called when the cursor moved: check if any popup needs to be closed if the |
| 2535 | * cursor moved far enough. |
| 2536 | */ |
| 2537 | void |
| 2538 | popup_check_cursor_pos() |
| 2539 | { |
| 2540 | win_T *wp; |
| 2541 | typval_T tv; |
| 2542 | |
| 2543 | popup_reset_handled(); |
| 2544 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 2545 | if (wp->w_popup_curwin != NULL |
| 2546 | && (curwin != wp->w_popup_curwin |
| 2547 | || curwin->w_cursor.lnum != wp->w_popup_lnum |
| 2548 | || curwin->w_cursor.col < wp->w_popup_mincol |
| 2549 | || curwin->w_cursor.col > wp->w_popup_maxcol)) |
| 2550 | { |
| 2551 | tv.v_type = VAR_NUMBER; |
| 2552 | tv.vval.v_number = -1; |
| 2553 | popup_close_and_callback(wp, &tv); |
| 2554 | } |
| 2555 | } |
| 2556 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2557 | /* |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2558 | * Update "w_popup_mask_cells". |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2559 | */ |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2560 | static void |
| 2561 | popup_update_mask(win_T *wp, int width, int height) |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2562 | { |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2563 | listitem_T *lio, *li; |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2564 | char_u *cells; |
| 2565 | int row, col; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2566 | |
| 2567 | if (wp->w_popup_mask == NULL) |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2568 | return; |
| 2569 | if (wp->w_popup_mask_cells != NULL |
| 2570 | && wp->w_popup_mask_height == height |
| 2571 | && wp->w_popup_mask_width == width) |
| 2572 | return; // cache is still valid |
| 2573 | |
| 2574 | vim_free(wp->w_popup_mask_cells); |
| 2575 | wp->w_popup_mask_cells = alloc_clear(width * height); |
| 2576 | if (wp->w_popup_mask_cells == NULL) |
| 2577 | return; |
| 2578 | cells = wp->w_popup_mask_cells; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2579 | |
| 2580 | for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next) |
| 2581 | { |
| 2582 | int cols, cole; |
| 2583 | int lines, linee; |
| 2584 | |
| 2585 | li = lio->li_tv.vval.v_list->lv_first; |
| 2586 | cols = tv_get_number(&li->li_tv); |
| 2587 | if (cols < 0) |
| 2588 | cols = width + cols + 1; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2589 | li = li->li_next; |
| 2590 | cole = tv_get_number(&li->li_tv); |
| 2591 | if (cole < 0) |
| 2592 | cole = width + cole + 1; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2593 | li = li->li_next; |
| 2594 | lines = tv_get_number(&li->li_tv); |
| 2595 | if (lines < 0) |
| 2596 | lines = height + lines + 1; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2597 | li = li->li_next; |
| 2598 | linee = tv_get_number(&li->li_tv); |
| 2599 | if (linee < 0) |
| 2600 | linee = height + linee + 1; |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2601 | |
| 2602 | for (row = lines - 1; row < linee && row < height; ++row) |
| 2603 | for (col = cols - 1; col < cole && col < width; ++col) |
| 2604 | cells[row * width + col] = 1; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2605 | } |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | /* |
| 2609 | * Return TRUE if "col" / "line" matches with an entry in w_popup_mask. |
| 2610 | * "col" and "line" are screen coordinates. |
| 2611 | */ |
| 2612 | static int |
| 2613 | popup_masked(win_T *wp, int width, int height, int screencol, int screenline) |
| 2614 | { |
| 2615 | int col = screencol - wp->w_wincol + wp->w_popup_leftoff; |
| 2616 | int line = screenline - wp->w_winrow; |
| 2617 | |
| 2618 | return col >= 0 && col < width |
| 2619 | && line >= 0 && line < height |
| 2620 | && wp->w_popup_mask_cells[line * width + col]; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | /* |
| 2624 | * Set flags in popup_transparent[] for window "wp" to "val". |
| 2625 | */ |
| 2626 | static void |
| 2627 | update_popup_transparent(win_T *wp, int val) |
| 2628 | { |
| 2629 | if (wp->w_popup_mask != NULL) |
| 2630 | { |
| 2631 | int width = popup_width(wp); |
| 2632 | int height = popup_height(wp); |
| 2633 | listitem_T *lio, *li; |
| 2634 | int cols, cole; |
| 2635 | int lines, linee; |
| 2636 | int col, line; |
| 2637 | |
| 2638 | for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next) |
| 2639 | { |
| 2640 | li = lio->li_tv.vval.v_list->lv_first; |
| 2641 | cols = tv_get_number(&li->li_tv); |
| 2642 | if (cols < 0) |
| 2643 | cols = width + cols + 1; |
| 2644 | li = li->li_next; |
| 2645 | cole = tv_get_number(&li->li_tv); |
| 2646 | if (cole < 0) |
| 2647 | cole = width + cole + 1; |
| 2648 | li = li->li_next; |
| 2649 | lines = tv_get_number(&li->li_tv); |
| 2650 | if (lines < 0) |
| 2651 | lines = height + lines + 1; |
| 2652 | li = li->li_next; |
| 2653 | linee = tv_get_number(&li->li_tv); |
| 2654 | if (linee < 0) |
| 2655 | linee = height + linee + 1; |
| 2656 | |
| 2657 | --cols; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2658 | cols -= wp->w_popup_leftoff; |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 2659 | if (cols < 0) |
| 2660 | cols = 0; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2661 | cole -= wp->w_popup_leftoff; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2662 | --lines; |
Bram Moolenaar | 711d02c | 2019-06-28 04:06:50 +0200 | [diff] [blame] | 2663 | if (lines < 0) |
| 2664 | lines = 0; |
Bram Moolenaar | b420747 | 2019-07-12 16:05:45 +0200 | [diff] [blame] | 2665 | for (line = lines; line < linee |
| 2666 | && line + wp->w_winrow < screen_Rows; ++line) |
| 2667 | for (col = cols; col < cole |
| 2668 | && col + wp->w_wincol < screen_Columns; ++col) |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2669 | popup_transparent[(line + wp->w_winrow) * screen_Columns |
| 2670 | + col + wp->w_wincol] = val; |
| 2671 | } |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | /* |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2676 | * Update "popup_mask" if needed. |
| 2677 | * Also recomputes the popup size and positions. |
| 2678 | * Also updates "popup_visible". |
| 2679 | * Also marks window lines for redrawing. |
| 2680 | */ |
| 2681 | void |
| 2682 | may_update_popup_mask(int type) |
| 2683 | { |
| 2684 | win_T *wp; |
| 2685 | short *mask; |
| 2686 | int line, col; |
| 2687 | int redraw_all = FALSE; |
| 2688 | |
| 2689 | // Need to recompute when switching tabs. |
| 2690 | // Also recompute when the type is CLEAR or NOT_VALID, something basic |
| 2691 | // (such as the screen size) must have changed. |
| 2692 | if (popup_mask_tab != curtab || type >= NOT_VALID) |
| 2693 | { |
| 2694 | popup_mask_refresh = TRUE; |
| 2695 | redraw_all = TRUE; |
| 2696 | } |
| 2697 | if (!popup_mask_refresh) |
| 2698 | { |
| 2699 | // Check if any buffer has changed. |
| 2700 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 2701 | if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 2702 | popup_mask_refresh = TRUE; |
| 2703 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 2704 | if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 2705 | popup_mask_refresh = TRUE; |
| 2706 | if (!popup_mask_refresh) |
| 2707 | return; |
| 2708 | } |
| 2709 | |
| 2710 | // Need to update the mask, something has changed. |
| 2711 | popup_mask_refresh = FALSE; |
| 2712 | popup_mask_tab = curtab; |
| 2713 | popup_visible = FALSE; |
| 2714 | |
| 2715 | // If redrawing everything, just update "popup_mask". |
| 2716 | // If redrawing only what is needed, update "popup_mask_next" and then |
| 2717 | // compare with "popup_mask" to see what changed. |
| 2718 | if (type >= SOME_VALID) |
| 2719 | mask = popup_mask; |
| 2720 | else |
| 2721 | mask = popup_mask_next; |
| 2722 | vim_memset(mask, 0, screen_Rows * screen_Columns * sizeof(short)); |
| 2723 | |
| 2724 | // Find the window with the lowest zindex that hasn't been handled yet, |
| 2725 | // so that the window with a higher zindex overwrites the value in |
| 2726 | // popup_mask. |
| 2727 | popup_reset_handled(); |
| 2728 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 2729 | { |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2730 | int width; |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2731 | int height; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2732 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2733 | popup_visible = TRUE; |
| 2734 | |
| 2735 | // Recompute the position if the text changed. |
| 2736 | if (redraw_all |
| 2737 | || wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 2738 | popup_adjust_position(wp); |
| 2739 | |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2740 | width = popup_width(wp); |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2741 | height = popup_height(wp); |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2742 | popup_update_mask(wp, width, height); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2743 | for (line = wp->w_winrow; |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2744 | line < wp->w_winrow + height && line < screen_Rows; ++line) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2745 | for (col = wp->w_wincol; |
Bram Moolenaar | e865dcb | 2019-07-26 22:15:50 +0200 | [diff] [blame] | 2746 | col < wp->w_wincol + width - wp->w_popup_leftoff |
| 2747 | && col < screen_Columns; ++col) |
| 2748 | if (wp->w_popup_mask_cells == NULL |
| 2749 | || !popup_masked(wp, width, height, col, line)) |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2750 | mask[line * screen_Columns + col] = wp->w_zindex; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | // Only check which lines are to be updated if not already |
| 2754 | // updating all lines. |
| 2755 | if (mask == popup_mask_next) |
Bram Moolenaar | 9d5ffce | 2019-07-26 21:01:29 +0200 | [diff] [blame] | 2756 | { |
| 2757 | int *plines_cache = ALLOC_CLEAR_MULT(int, Rows); |
| 2758 | win_T *prev_wp = NULL; |
| 2759 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2760 | for (line = 0; line < screen_Rows; ++line) |
| 2761 | { |
| 2762 | int col_done = 0; |
| 2763 | |
| 2764 | for (col = 0; col < screen_Columns; ++col) |
| 2765 | { |
| 2766 | int off = line * screen_Columns + col; |
| 2767 | |
| 2768 | if (popup_mask[off] != popup_mask_next[off]) |
| 2769 | { |
| 2770 | popup_mask[off] = popup_mask_next[off]; |
| 2771 | |
| 2772 | if (line >= cmdline_row) |
| 2773 | { |
| 2774 | // the command line needs to be cleared if text below |
| 2775 | // the popup is now visible. |
| 2776 | if (!msg_scrolled && popup_mask_next[off] == 0) |
| 2777 | clear_cmdline = TRUE; |
| 2778 | } |
| 2779 | else if (col >= col_done) |
| 2780 | { |
| 2781 | linenr_T lnum; |
| 2782 | int line_cp = line; |
| 2783 | int col_cp = col; |
| 2784 | |
| 2785 | // The screen position "line" / "col" needs to be |
| 2786 | // redrawn. Figure out what window that is and update |
| 2787 | // w_redraw_top and w_redr_bot. Only needs to be done |
| 2788 | // once for each window line. |
| 2789 | wp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP); |
| 2790 | if (wp != NULL) |
| 2791 | { |
Bram Moolenaar | 9d5ffce | 2019-07-26 21:01:29 +0200 | [diff] [blame] | 2792 | if (wp != prev_wp) |
| 2793 | { |
| 2794 | vim_memset(plines_cache, 0, sizeof(int) * Rows); |
| 2795 | prev_wp = wp; |
| 2796 | } |
| 2797 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2798 | if (line_cp >= wp->w_height) |
| 2799 | // In (or below) status line |
| 2800 | wp->w_redr_status = TRUE; |
| 2801 | // compute the position in the buffer line from the |
| 2802 | // position on the screen |
| 2803 | else if (mouse_comp_pos(wp, &line_cp, &col_cp, |
Bram Moolenaar | 9d5ffce | 2019-07-26 21:01:29 +0200 | [diff] [blame] | 2804 | &lnum, plines_cache)) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2805 | // past bottom |
| 2806 | wp->w_redr_status = TRUE; |
| 2807 | else |
| 2808 | redrawWinline(wp, lnum); |
| 2809 | |
| 2810 | // This line is going to be redrawn, no need to |
| 2811 | // check until the right side of the window. |
| 2812 | col_done = wp->w_wincol + wp->w_width - 1; |
| 2813 | } |
| 2814 | } |
| 2815 | } |
| 2816 | } |
| 2817 | } |
Bram Moolenaar | 9d5ffce | 2019-07-26 21:01:29 +0200 | [diff] [blame] | 2818 | |
| 2819 | vim_free(plines_cache); |
| 2820 | } |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | /* |
| 2824 | * Return a string of "len" spaces in IObuff. |
| 2825 | */ |
| 2826 | static char_u * |
| 2827 | get_spaces(int len) |
| 2828 | { |
| 2829 | vim_memset(IObuff, ' ', (size_t)len); |
| 2830 | IObuff[len] = NUL; |
| 2831 | return IObuff; |
| 2832 | } |
| 2833 | |
| 2834 | /* |
| 2835 | * Update popup windows. They are drawn on top of normal windows. |
| 2836 | * "win_update" is called for each popup window, lowest zindex first. |
| 2837 | */ |
| 2838 | void |
| 2839 | update_popups(void (*win_update)(win_T *wp)) |
| 2840 | { |
| 2841 | win_T *wp; |
| 2842 | int top_off; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2843 | int left_extra; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2844 | int total_width; |
| 2845 | int total_height; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2846 | int top_padding; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2847 | int popup_attr; |
| 2848 | int border_attr[4]; |
| 2849 | int border_char[8]; |
| 2850 | char_u buf[MB_MAXBYTES]; |
| 2851 | int row; |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 2852 | int wincol; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2853 | int padcol = 0; |
| 2854 | int padwidth = 0; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2855 | int i; |
Bram Moolenaar | 6efd76a | 2019-06-26 04:06:57 +0200 | [diff] [blame] | 2856 | int sb_thumb_top = 0; |
| 2857 | int sb_thumb_height = 0; |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 2858 | int attr_scroll = 0; |
| 2859 | int attr_thumb = 0; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2860 | |
| 2861 | // Find the window with the lowest zindex that hasn't been updated yet, |
| 2862 | // so that the window with a higher zindex is drawn later, thus goes on |
| 2863 | // top. |
| 2864 | popup_reset_handled(); |
| 2865 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 2866 | { |
| 2867 | // This drawing uses the zindex of the popup window, so that it's on |
| 2868 | // top of the text but doesn't draw when another popup with higher |
| 2869 | // zindex is on top of the character. |
| 2870 | screen_zindex = wp->w_zindex; |
| 2871 | |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 2872 | // Set flags in popup_transparent[] for masked cells. |
| 2873 | update_popup_transparent(wp, 1); |
| 2874 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2875 | // adjust w_winrow and w_wincol for border and padding, since |
| 2876 | // win_update() doesn't handle them. |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2877 | top_off = popup_top_extra(wp); |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2878 | left_extra = wp->w_popup_padding[3] + wp->w_popup_border[3] |
| 2879 | - wp->w_popup_leftoff; |
| 2880 | if (wp->w_wincol + left_extra < 0) |
| 2881 | left_extra = -wp->w_wincol; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2882 | wp->w_winrow += top_off; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2883 | wp->w_wincol += left_extra; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2884 | |
Bram Moolenaar | c2a4316 | 2019-06-26 01:03:53 +0200 | [diff] [blame] | 2885 | // Draw the popup text, unless it's off screen. |
| 2886 | if (wp->w_winrow < screen_Rows && wp->w_wincol < screen_Columns) |
| 2887 | win_update(wp); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2888 | |
| 2889 | wp->w_winrow -= top_off; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2890 | wp->w_wincol -= left_extra; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2891 | |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2892 | total_width = popup_width(wp); |
| 2893 | total_height = popup_height(wp); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2894 | popup_attr = get_wcr_attr(wp); |
| 2895 | |
Bram Moolenaar | 13d5c3f | 2019-07-28 21:42:38 +0200 | [diff] [blame] | 2896 | if (wp->w_winrow + total_height > cmdline_row) |
| 2897 | wp->w_popup_flags |= POPF_ON_CMDLINE; |
| 2898 | else |
| 2899 | wp->w_popup_flags &= ~POPF_ON_CMDLINE; |
| 2900 | |
| 2901 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2902 | // We can only use these line drawing characters when 'encoding' is |
| 2903 | // "utf-8" and 'ambiwidth' is "single". |
| 2904 | if (enc_utf8 && *p_ambw == 's') |
| 2905 | { |
| 2906 | border_char[0] = border_char[2] = 0x2550; |
| 2907 | border_char[1] = border_char[3] = 0x2551; |
| 2908 | border_char[4] = 0x2554; |
| 2909 | border_char[5] = 0x2557; |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 2910 | border_char[6] = (wp->w_popup_flags & POPF_RESIZE) |
| 2911 | ? 0x21f2 : 0x255d; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2912 | border_char[7] = 0x255a; |
| 2913 | } |
| 2914 | else |
| 2915 | { |
| 2916 | border_char[0] = border_char[2] = '-'; |
| 2917 | border_char[1] = border_char[3] = '|'; |
| 2918 | for (i = 4; i < 8; ++i) |
| 2919 | border_char[i] = '+'; |
Bram Moolenaar | 9bcb70c | 2019-08-01 21:11:05 +0200 | [diff] [blame] | 2920 | if (wp->w_popup_flags & POPF_RESIZE) |
| 2921 | border_char[6] = '@'; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2922 | } |
| 2923 | for (i = 0; i < 8; ++i) |
| 2924 | if (wp->w_border_char[i] != 0) |
| 2925 | border_char[i] = wp->w_border_char[i]; |
| 2926 | |
| 2927 | for (i = 0; i < 4; ++i) |
| 2928 | { |
| 2929 | border_attr[i] = popup_attr; |
| 2930 | if (wp->w_border_highlight[i] != NULL) |
| 2931 | border_attr[i] = syn_name2attr(wp->w_border_highlight[i]); |
| 2932 | } |
| 2933 | |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 2934 | wincol = wp->w_wincol - wp->w_popup_leftoff; |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2935 | top_padding = wp->w_popup_padding[0]; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2936 | if (wp->w_popup_border[0] > 0) |
| 2937 | { |
| 2938 | // top border |
| 2939 | screen_fill(wp->w_winrow, wp->w_winrow + 1, |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 2940 | wincol < 0 ? 0 : wincol, wincol + total_width, |
| 2941 | wp->w_popup_border[3] != 0 && wp->w_popup_leftoff == 0 |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2942 | ? border_char[4] : border_char[0], |
| 2943 | border_char[0], border_attr[0]); |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 2944 | if (wp->w_popup_border[1] > 0 && wp->w_popup_rightoff == 0) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2945 | { |
| 2946 | buf[mb_char2bytes(border_char[5], buf)] = NUL; |
| 2947 | screen_puts(buf, wp->w_winrow, |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 2948 | wincol + total_width - 1, border_attr[1]); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2949 | } |
| 2950 | } |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2951 | else if (wp->w_popup_padding[0] == 0 && popup_top_extra(wp) > 0) |
| 2952 | top_padding = 1; |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2953 | |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2954 | if (top_padding > 0 || wp->w_popup_padding[2] > 0) |
| 2955 | { |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 2956 | padcol = wincol + wp->w_popup_border[3]; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2957 | padwidth = wp->w_wincol + total_width - wp->w_popup_border[1] |
| 2958 | - wp->w_has_scrollbar; |
| 2959 | if (padcol < 0) |
| 2960 | { |
| 2961 | padwidth += padcol; |
| 2962 | padcol = 0; |
| 2963 | } |
| 2964 | } |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2965 | if (top_padding > 0) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2966 | { |
| 2967 | // top padding |
| 2968 | row = wp->w_winrow + wp->w_popup_border[0]; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 2969 | screen_fill(row, row + top_padding, padcol, padwidth, |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2970 | ' ', ' ', popup_attr); |
| 2971 | } |
| 2972 | |
Bram Moolenaar | eb2310d | 2019-06-16 20:09:10 +0200 | [diff] [blame] | 2973 | // Title goes on top of border or padding. |
| 2974 | if (wp->w_popup_title != NULL) |
| 2975 | screen_puts(wp->w_popup_title, wp->w_winrow, wp->w_wincol + 1, |
| 2976 | wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr); |
| 2977 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2978 | // Compute scrollbar thumb position and size. |
| 2979 | if (wp->w_has_scrollbar) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 2980 | { |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2981 | linenr_T linecount = wp->w_buffer->b_ml.ml_line_count; |
| 2982 | |
Bram Moolenaar | 68acb41 | 2019-06-26 03:40:36 +0200 | [diff] [blame] | 2983 | sb_thumb_height = (wp->w_height * wp->w_height + linecount / 2) |
| 2984 | / linecount; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 2985 | if (sb_thumb_height == 0) |
| 2986 | sb_thumb_height = 1; |
Bram Moolenaar | 437a746 | 2019-07-05 20:17:22 +0200 | [diff] [blame] | 2987 | if (linecount <= wp->w_height) |
| 2988 | // it just fits, avoid divide by zero |
| 2989 | sb_thumb_top = 0; |
| 2990 | else |
| 2991 | sb_thumb_top = (wp->w_topline - 1 |
| 2992 | + (linecount / wp->w_height) / 2) |
Bram Moolenaar | 68acb41 | 2019-06-26 03:40:36 +0200 | [diff] [blame] | 2993 | * (wp->w_height - sb_thumb_height) |
| 2994 | / (linecount - wp->w_height); |
Bram Moolenaar | 4cd583c | 2019-06-26 05:13:57 +0200 | [diff] [blame] | 2995 | if (wp->w_scrollbar_highlight != NULL) |
| 2996 | attr_scroll = syn_name2attr(wp->w_scrollbar_highlight); |
| 2997 | else |
| 2998 | attr_scroll = highlight_attr[HLF_PSB]; |
| 2999 | if (wp->w_thumb_highlight != NULL) |
| 3000 | attr_thumb = syn_name2attr(wp->w_thumb_highlight); |
| 3001 | else |
| 3002 | attr_thumb = highlight_attr[HLF_PST]; |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | for (i = wp->w_popup_border[0]; |
| 3006 | i < total_height - wp->w_popup_border[2]; ++i) |
| 3007 | { |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 3008 | int pad_left; |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 3009 | // left and right padding only needed next to the body |
| 3010 | int do_padding = |
| 3011 | i >= wp->w_popup_border[0] + wp->w_popup_padding[0] |
| 3012 | && i < total_height - wp->w_popup_border[2] |
| 3013 | - wp->w_popup_padding[2]; |
| 3014 | |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 3015 | row = wp->w_winrow + i; |
| 3016 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3017 | // left border |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 3018 | if (wp->w_popup_border[3] > 0 && wincol >= 0) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3019 | { |
| 3020 | buf[mb_char2bytes(border_char[3], buf)] = NUL; |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 3021 | screen_puts(buf, row, wincol, border_attr[3]); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3022 | } |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 3023 | if (do_padding && wp->w_popup_padding[3] > 0) |
| 3024 | { |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 3025 | int col = wincol + wp->w_popup_border[3]; |
| 3026 | |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 3027 | // left padding |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 3028 | pad_left = wp->w_popup_padding[3]; |
| 3029 | if (col < 0) |
| 3030 | { |
| 3031 | pad_left += col; |
| 3032 | col = 0; |
| 3033 | } |
| 3034 | if (pad_left > 0) |
| 3035 | screen_puts(get_spaces(pad_left), row, col, popup_attr); |
| 3036 | } |
Bram Moolenaar | 75fb085 | 2019-06-25 05:15:58 +0200 | [diff] [blame] | 3037 | // scrollbar |
| 3038 | if (wp->w_has_scrollbar) |
| 3039 | { |
| 3040 | int line = i - top_off; |
| 3041 | int scroll_col = wp->w_wincol + total_width - 1 |
| 3042 | - wp->w_popup_border[1]; |
| 3043 | |
| 3044 | if (line >= 0 && line < wp->w_height) |
| 3045 | screen_putchar(' ', row, scroll_col, |
| 3046 | line >= sb_thumb_top |
| 3047 | && line < sb_thumb_top + sb_thumb_height |
| 3048 | ? attr_thumb : attr_scroll); |
| 3049 | else |
| 3050 | screen_putchar(' ', row, scroll_col, popup_attr); |
| 3051 | } |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3052 | // right border |
| 3053 | if (wp->w_popup_border[1] > 0) |
| 3054 | { |
| 3055 | buf[mb_char2bytes(border_char[1], buf)] = NUL; |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 3056 | screen_puts(buf, row, wincol + total_width - 1, border_attr[1]); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3057 | } |
| 3058 | // right padding |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 3059 | if (do_padding && wp->w_popup_padding[1] > 0) |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3060 | screen_puts(get_spaces(wp->w_popup_padding[1]), row, |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 3061 | wincol + wp->w_popup_border[3] |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 3062 | + wp->w_popup_padding[3] + wp->w_width + wp->w_leftcol, |
| 3063 | popup_attr); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | if (wp->w_popup_padding[2] > 0) |
| 3067 | { |
| 3068 | // bottom padding |
| 3069 | row = wp->w_winrow + wp->w_popup_border[0] |
| 3070 | + wp->w_popup_padding[0] + wp->w_height; |
| 3071 | screen_fill(row, row + wp->w_popup_padding[2], |
Bram Moolenaar | d529ba5 | 2019-07-02 23:13:53 +0200 | [diff] [blame] | 3072 | padcol, padwidth, ' ', ' ', popup_attr); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3073 | } |
| 3074 | |
| 3075 | if (wp->w_popup_border[2] > 0) |
| 3076 | { |
| 3077 | // bottom border |
| 3078 | row = wp->w_winrow + total_height - 1; |
| 3079 | screen_fill(row , row + 1, |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 3080 | wincol < 0 ? 0 : wincol, |
| 3081 | wincol + total_width, |
| 3082 | wp->w_popup_border[3] != 0 && wp->w_popup_leftoff == 0 |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3083 | ? border_char[7] : border_char[2], |
| 3084 | border_char[2], border_attr[2]); |
| 3085 | if (wp->w_popup_border[1] > 0) |
| 3086 | { |
| 3087 | buf[mb_char2bytes(border_char[6], buf)] = NUL; |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 3088 | screen_puts(buf, row, wincol + total_width - 1, border_attr[2]); |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3089 | } |
| 3090 | } |
| 3091 | |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 3092 | if (wp->w_popup_close == POPCLOSE_BUTTON) |
| 3093 | { |
| 3094 | // close button goes on top of anything at the top-right corner |
| 3095 | buf[mb_char2bytes('X', buf)] = NUL; |
Bram Moolenaar | ba45f1f | 2019-07-03 22:50:41 +0200 | [diff] [blame] | 3096 | screen_puts(buf, wp->w_winrow, wincol + total_width - 1, |
Bram Moolenaar | 2e62b56 | 2019-06-30 18:07:00 +0200 | [diff] [blame] | 3097 | wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr); |
| 3098 | } |
| 3099 | |
Bram Moolenaar | c662ec9 | 2019-06-23 00:15:57 +0200 | [diff] [blame] | 3100 | update_popup_transparent(wp, 0); |
| 3101 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 3102 | // Back to the normal zindex. |
| 3103 | screen_zindex = 0; |
| 3104 | } |
| 3105 | } |
| 3106 | |
Bram Moolenaar | 75a1a94 | 2019-06-20 03:45:36 +0200 | [diff] [blame] | 3107 | /* |
| 3108 | * Mark references in callbacks of one popup window. |
| 3109 | */ |
| 3110 | static int |
| 3111 | set_ref_in_one_popup(win_T *wp, int copyID) |
| 3112 | { |
| 3113 | int abort = FALSE; |
| 3114 | typval_T tv; |
| 3115 | |
| 3116 | if (wp->w_close_cb.cb_partial != NULL) |
| 3117 | { |
| 3118 | tv.v_type = VAR_PARTIAL; |
| 3119 | tv.vval.v_partial = wp->w_close_cb.cb_partial; |
| 3120 | abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); |
| 3121 | } |
| 3122 | if (wp->w_filter_cb.cb_partial != NULL) |
| 3123 | { |
| 3124 | tv.v_type = VAR_PARTIAL; |
| 3125 | tv.vval.v_partial = wp->w_filter_cb.cb_partial; |
| 3126 | abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); |
| 3127 | } |
Bram Moolenaar | 7be3ab2 | 2019-06-23 01:46:15 +0200 | [diff] [blame] | 3128 | abort = abort || set_ref_in_list(wp->w_popup_mask, copyID); |
Bram Moolenaar | 75a1a94 | 2019-06-20 03:45:36 +0200 | [diff] [blame] | 3129 | return abort; |
| 3130 | } |
| 3131 | |
| 3132 | /* |
| 3133 | * Set reference in callbacks of popup windows. |
| 3134 | */ |
| 3135 | int |
| 3136 | set_ref_in_popups(int copyID) |
| 3137 | { |
| 3138 | int abort = FALSE; |
| 3139 | win_T *wp; |
| 3140 | tabpage_T *tp; |
| 3141 | |
| 3142 | for (wp = first_popupwin; !abort && wp != NULL; wp = wp->w_next) |
| 3143 | abort = abort || set_ref_in_one_popup(wp, copyID); |
| 3144 | |
| 3145 | FOR_ALL_TABPAGES(tp) |
| 3146 | { |
| 3147 | for (wp = tp->tp_first_popupwin; !abort && wp != NULL; wp = wp->w_next) |
| 3148 | abort = abort || set_ref_in_one_popup(wp, copyID); |
| 3149 | if (abort) |
| 3150 | break; |
| 3151 | } |
| 3152 | return abort; |
| 3153 | } |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 3154 | |
| 3155 | /* |
| 3156 | * Find an existing popup used as the preview window, in the current tab page. |
| 3157 | * Return NULL if not found. |
| 3158 | */ |
| 3159 | win_T * |
| 3160 | popup_find_preview_window(void) |
| 3161 | { |
| 3162 | win_T *wp; |
| 3163 | |
| 3164 | // Preview window popup is always local to tab page. |
| 3165 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 3166 | if (wp->w_p_pvw) |
| 3167 | return wp; |
Bram Moolenaar | 56c0c47 | 2019-07-28 17:57:43 +0200 | [diff] [blame] | 3168 | return NULL; |
| 3169 | } |
| 3170 | |
| 3171 | void |
| 3172 | f_popup_getpreview(typval_T *argvars UNUSED, typval_T *rettv) |
| 3173 | { |
| 3174 | win_T *wp = popup_find_preview_window(); |
| 3175 | |
| 3176 | rettv->vval.v_number = wp == NULL ? 0 : wp->w_id; |
Bram Moolenaar | 7964873 | 2019-07-18 21:43:07 +0200 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | int |
| 3180 | popup_is_popup(win_T *wp) |
| 3181 | { |
| 3182 | return wp->w_popup_flags != 0; |
| 3183 | } |
| 3184 | |
| 3185 | /* |
| 3186 | * Create a popup to be used as the preview window. |
| 3187 | * NOTE: this makes the popup the current window, so that the file can be |
| 3188 | * edited. However, it must not remain to be the current window, the caller |
| 3189 | * must make sure of that. |
| 3190 | */ |
| 3191 | int |
| 3192 | popup_create_preview_window(void) |
| 3193 | { |
| 3194 | win_T *wp = popup_create(NULL, NULL, TYPE_PREVIEW); |
| 3195 | |
| 3196 | if (wp == NULL) |
| 3197 | return FAIL; |
| 3198 | wp->w_p_pvw = TRUE; |
| 3199 | |
| 3200 | // Set the width to a reasonable value, so that w_topline can be computed. |
| 3201 | if (wp->w_minwidth > 0) |
| 3202 | wp->w_width = wp->w_minwidth; |
| 3203 | else if (wp->w_maxwidth > 0) |
| 3204 | wp->w_width = wp->w_maxwidth; |
| 3205 | else |
| 3206 | wp->w_width = curwin->w_width; |
| 3207 | |
| 3208 | // Will switch to another buffer soon, dummy one can be wiped. |
| 3209 | wp->w_buffer->b_locked = FALSE; |
| 3210 | |
| 3211 | win_enter(wp, FALSE); |
| 3212 | return OK; |
| 3213 | } |
| 3214 | |
| 3215 | void |
| 3216 | popup_close_preview() |
| 3217 | { |
| 3218 | win_T *wp = popup_find_preview_window(); |
| 3219 | |
| 3220 | if (wp != NULL) |
| 3221 | { |
| 3222 | typval_T res; |
| 3223 | |
| 3224 | res.v_type = VAR_NUMBER; |
| 3225 | res.vval.v_number = -1; |
| 3226 | popup_close_and_callback(wp, &res); |
| 3227 | } |
| 3228 | } |
| 3229 | |
Bram Moolenaar | 90f3e7a | 2019-08-01 22:40:44 +0200 | [diff] [blame] | 3230 | /* |
| 3231 | * Set the title of the popup window to the file name. |
| 3232 | */ |
| 3233 | void |
| 3234 | popup_set_title(win_T *wp) |
| 3235 | { |
| 3236 | if (wp->w_buffer->b_fname != NULL) |
| 3237 | { |
| 3238 | char_u dirname[MAXPATHL]; |
| 3239 | size_t len; |
| 3240 | |
| 3241 | mch_dirname(dirname, MAXPATHL); |
| 3242 | shorten_buf_fname(wp->w_buffer, dirname, FALSE); |
| 3243 | |
| 3244 | vim_free(wp->w_popup_title); |
| 3245 | len = STRLEN(wp->w_buffer->b_fname) + 3; |
| 3246 | wp->w_popup_title = alloc((int)len); |
| 3247 | if (wp->w_popup_title != NULL) |
| 3248 | vim_snprintf((char *)wp->w_popup_title, len, " %s ", |
| 3249 | wp->w_buffer->b_fname); |
| 3250 | redraw_win_later(wp, VALID); |
| 3251 | } |
| 3252 | } |
| 3253 | |
| 3254 | /* |
| 3255 | * If there is a preview window, update the title. |
| 3256 | * Used after changing directory. |
| 3257 | */ |
| 3258 | void |
| 3259 | popup_update_preview_title(void) |
| 3260 | { |
| 3261 | win_T *wp = popup_find_preview_window(); |
| 3262 | |
| 3263 | if (wp != NULL) |
| 3264 | popup_set_title(wp); |
| 3265 | } |
| 3266 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 3267 | #endif // FEAT_TEXT_PROP |