Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read a list of people who contributed. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | * See README.txt for an overview of the Vim source code. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * Implementation of popup windows. See ":help popup". |
| 12 | */ |
| 13 | |
| 14 | #include "vim.h" |
| 15 | |
| 16 | #ifdef FEAT_TEXT_PROP |
| 17 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 18 | typedef struct { |
| 19 | char *pp_name; |
| 20 | poppos_T pp_val; |
| 21 | } poppos_entry_T; |
| 22 | |
| 23 | static poppos_entry_T poppos_entries[] = { |
| 24 | {"botleft", POPPOS_BOTLEFT}, |
| 25 | {"topleft", POPPOS_TOPLEFT}, |
| 26 | {"botright", POPPOS_BOTRIGHT}, |
| 27 | {"topright", POPPOS_TOPRIGHT}, |
| 28 | {"center", POPPOS_CENTER} |
| 29 | }; |
| 30 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 31 | /* |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 32 | * Get option value for "key", which is "line" or "col". |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 33 | * Handles "cursor+N" and "cursor-N". |
| 34 | */ |
| 35 | static int |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 36 | popup_options_one(dict_T *dict, char_u *key) |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 37 | { |
| 38 | dictitem_T *di; |
| 39 | char_u *val; |
| 40 | char_u *s; |
| 41 | char_u *endp; |
| 42 | int n = 0; |
| 43 | |
| 44 | di = dict_find(dict, key, -1); |
| 45 | if (di == NULL) |
| 46 | return 0; |
| 47 | |
| 48 | val = tv_get_string(&di->di_tv); |
| 49 | if (STRNCMP(val, "cursor", 6) != 0) |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 50 | return dict_get_number_check(dict, key); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 51 | |
| 52 | setcursor_mayforce(TRUE); |
| 53 | s = val + 6; |
| 54 | if (*s != NUL) |
| 55 | { |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 56 | endp = s; |
| 57 | if (*skipwhite(s) == '+' || *skipwhite(s) == '-') |
| 58 | n = strtol((char *)s, (char **)&endp, 10); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 59 | if (endp != NULL && *skipwhite(endp) != NUL) |
| 60 | { |
| 61 | semsg(_(e_invexpr2), val); |
| 62 | return 0; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (STRCMP(key, "line") == 0) |
| 67 | n = screen_screenrow() + 1 + n; |
| 68 | else // "col" |
| 69 | n = screen_screencol() + 1 + n; |
| 70 | |
| 71 | if (n < 1) |
| 72 | n = 1; |
| 73 | return n; |
| 74 | } |
| 75 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 76 | static void |
| 77 | get_pos_options(win_T *wp, dict_T *dict) |
| 78 | { |
| 79 | char_u *str; |
| 80 | int nr; |
| 81 | |
| 82 | nr = popup_options_one(dict, (char_u *)"line"); |
| 83 | if (nr > 0) |
| 84 | wp->w_wantline = nr; |
| 85 | nr = popup_options_one(dict, (char_u *)"col"); |
| 86 | if (nr > 0) |
| 87 | wp->w_wantcol = nr; |
| 88 | |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 89 | wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0; |
| 90 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 91 | str = dict_get_string(dict, (char_u *)"pos", FALSE); |
| 92 | if (str != NULL) |
| 93 | { |
| 94 | for (nr = 0; |
| 95 | nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); |
| 96 | ++nr) |
| 97 | if (STRCMP(str, poppos_entries[nr].pp_name) == 0) |
| 98 | { |
| 99 | wp->w_popup_pos = poppos_entries[nr].pp_val; |
| 100 | nr = -1; |
| 101 | break; |
| 102 | } |
| 103 | if (nr != -1) |
| 104 | semsg(_(e_invarg2), str); |
| 105 | } |
| 106 | } |
| 107 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 108 | static void |
| 109 | get_padding_border(dict_T *dict, int *array, char *name, int max_val) |
| 110 | { |
| 111 | dictitem_T *di; |
| 112 | |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 113 | di = dict_find(dict, (char_u *)name, -1); |
| 114 | if (di != NULL) |
| 115 | { |
| 116 | if (di->di_tv.v_type != VAR_LIST) |
| 117 | emsg(_(e_listreq)); |
| 118 | else |
| 119 | { |
| 120 | list_T *list = di->di_tv.vval.v_list; |
| 121 | listitem_T *li; |
| 122 | int i; |
| 123 | int nr; |
| 124 | |
| 125 | for (i = 0; i < 4; ++i) |
| 126 | array[i] = 1; |
| 127 | if (list != NULL) |
| 128 | for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len; |
| 129 | ++i, li = li->li_next) |
| 130 | { |
| 131 | nr = (int)tv_get_number(&li->li_tv); |
| 132 | if (nr >= 0) |
| 133 | array[i] = nr > max_val ? max_val : nr; |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 139 | /* |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 140 | * Used when popup options contain "moved": set default moved values. |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 141 | */ |
| 142 | static void |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 143 | set_moved_values(win_T *wp) |
| 144 | { |
| 145 | wp->w_popup_curwin = curwin; |
| 146 | wp->w_popup_lnum = curwin->w_cursor.lnum; |
| 147 | wp->w_popup_mincol = curwin->w_cursor.col; |
| 148 | wp->w_popup_maxcol = curwin->w_cursor.col; |
| 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Used when popup options contain "moved" with "word" or "WORD". |
| 153 | */ |
| 154 | static void |
| 155 | set_moved_columns(win_T *wp, int flags) |
| 156 | { |
| 157 | char_u *ptr; |
| 158 | int len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR); |
| 159 | |
| 160 | if (len > 0) |
| 161 | { |
| 162 | wp->w_popup_mincol = (int)(ptr - ml_get_curline()); |
| 163 | wp->w_popup_maxcol = wp->w_popup_mincol + len - 1; |
| 164 | } |
| 165 | } |
| 166 | |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 167 | /* |
| 168 | * Return TRUE if "row"/"col" is on the border of the popup. |
| 169 | * The values are relative to the top-left corner. |
| 170 | */ |
| 171 | int |
| 172 | popup_on_border(win_T *wp, int row, int col) |
| 173 | { |
| 174 | return (row == 0 && wp->w_popup_border[0] > 0) |
| 175 | || (row == popup_height(wp) - 1 && wp->w_popup_border[2] > 0) |
| 176 | || (col == 0 && wp->w_popup_border[3] > 0) |
| 177 | || (col == popup_width(wp) - 1 && wp->w_popup_border[1] > 0); |
| 178 | } |
| 179 | |
| 180 | // Values set when dragging a popup window starts. |
| 181 | static int drag_start_row; |
| 182 | static int drag_start_col; |
| 183 | static int drag_start_wantline; |
| 184 | static int drag_start_wantcol; |
| 185 | |
| 186 | /* |
| 187 | * Mouse down on border of popup window: start dragging it. |
| 188 | * Uses mouse_col and mouse_row. |
| 189 | */ |
| 190 | void |
| 191 | popup_start_drag(win_T *wp) |
| 192 | { |
| 193 | drag_start_row = mouse_row; |
| 194 | drag_start_col = mouse_col; |
| 195 | // TODO: handle using different corner |
| 196 | if (wp->w_wantline == 0) |
| 197 | drag_start_wantline = wp->w_winrow + 1; |
| 198 | else |
| 199 | drag_start_wantline = wp->w_wantline; |
| 200 | if (wp->w_wantcol == 0) |
| 201 | drag_start_wantcol = wp->w_wincol + 1; |
| 202 | else |
| 203 | drag_start_wantcol = wp->w_wantcol; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Mouse moved while dragging a popup window: adjust the window popup position. |
| 208 | */ |
| 209 | void |
| 210 | popup_drag(win_T *wp) |
| 211 | { |
| 212 | // The popup may be closed before dragging stops. |
| 213 | if (!win_valid_popup(wp)) |
| 214 | return; |
| 215 | |
| 216 | wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row); |
| 217 | if (wp->w_wantline < 1) |
| 218 | wp->w_wantline = 1; |
| 219 | if (wp->w_wantline > Rows) |
| 220 | wp->w_wantline = Rows; |
| 221 | wp->w_wantcol = drag_start_wantcol + (mouse_col - drag_start_col); |
| 222 | if (wp->w_wantcol < 1) |
| 223 | wp->w_wantcol = 1; |
| 224 | if (wp->w_wantcol > Columns) |
| 225 | wp->w_wantcol = Columns; |
| 226 | |
| 227 | popup_adjust_position(wp); |
| 228 | } |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 229 | |
| 230 | #if defined(FEAT_TIMERS) |
| 231 | static void |
| 232 | popup_add_timeout(win_T *wp, int time) |
| 233 | { |
| 234 | char_u cbbuf[50]; |
| 235 | char_u *ptr = cbbuf; |
| 236 | typval_T tv; |
| 237 | |
| 238 | vim_snprintf((char *)cbbuf, sizeof(cbbuf), |
| 239 | "{_ -> popup_close(%d)}", wp->w_id); |
| 240 | if (get_lambda_tv(&ptr, &tv, TRUE) == OK) |
| 241 | { |
| 242 | wp->w_popup_timer = create_timer(time, 0); |
| 243 | wp->w_popup_timer->tr_callback = get_callback(&tv); |
| 244 | clear_tv(&tv); |
| 245 | } |
| 246 | } |
| 247 | #endif |
| 248 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 249 | /* |
| 250 | * Go through the options in "dict" and apply them to buffer "buf" displayed in |
| 251 | * popup window "wp". |
| 252 | */ |
| 253 | static void |
| 254 | apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 255 | { |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 256 | int nr; |
| 257 | char_u *str; |
| 258 | dictitem_T *di; |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 259 | int i; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 260 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 261 | wp->w_minwidth = dict_get_number(dict, (char_u *)"minwidth"); |
| 262 | wp->w_minheight = dict_get_number(dict, (char_u *)"minheight"); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 263 | wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth"); |
| 264 | wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight"); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 265 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 266 | get_pos_options(wp, dict); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 267 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 268 | di = dict_find(dict, (char_u *)"zindex", -1); |
| 269 | if (di != NULL) |
| 270 | { |
| 271 | wp->w_zindex = dict_get_number(dict, (char_u *)"zindex"); |
| 272 | if (wp->w_zindex < 1) |
| 273 | wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX; |
| 274 | if (wp->w_zindex > 32000) |
| 275 | wp->w_zindex = 32000; |
| 276 | } |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 277 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 278 | #if defined(FEAT_TIMERS) |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 279 | // Add timer to close the popup after some time. |
| 280 | nr = dict_get_number(dict, (char_u *)"time"); |
| 281 | if (nr > 0) |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 282 | popup_add_timeout(wp, nr); |
| 283 | #endif |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 284 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 285 | // Option values resulting in setting an option. |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 286 | str = dict_get_string(dict, (char_u *)"highlight", FALSE); |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 287 | if (str != NULL) |
| 288 | set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
| 289 | str, OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 290 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 291 | wp->w_firstline = dict_get_number(dict, (char_u *)"firstline"); |
| 292 | if (wp->w_firstline < 1) |
| 293 | wp->w_firstline = 1; |
| 294 | |
Bram Moolenaar | 402502d | 2019-05-30 22:07:36 +0200 | [diff] [blame] | 295 | di = dict_find(dict, (char_u *)"wrap", -1); |
| 296 | if (di != NULL) |
| 297 | { |
| 298 | nr = dict_get_number(dict, (char_u *)"wrap"); |
| 299 | wp->w_p_wrap = nr != 0; |
| 300 | } |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 301 | |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 302 | wp->w_popup_drag = dict_get_number(dict, (char_u *)"drag"); |
| 303 | |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 304 | di = dict_find(dict, (char_u *)"callback", -1); |
| 305 | if (di != NULL) |
| 306 | { |
| 307 | callback_T callback = get_callback(&di->di_tv); |
| 308 | |
| 309 | if (callback.cb_name != NULL) |
| 310 | set_callback(&wp->w_close_cb, &callback); |
| 311 | } |
| 312 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 313 | di = dict_find(dict, (char_u *)"filter", -1); |
| 314 | if (di != NULL) |
| 315 | { |
| 316 | callback_T callback = get_callback(&di->di_tv); |
| 317 | |
| 318 | if (callback.cb_name != NULL) |
| 319 | set_callback(&wp->w_filter_cb, &callback); |
| 320 | } |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 321 | |
| 322 | get_padding_border(dict, wp->w_popup_padding, "padding", 999); |
| 323 | get_padding_border(dict, wp->w_popup_border, "border", 1); |
Bram Moolenaar | 790498b | 2019-06-01 22:15:29 +0200 | [diff] [blame] | 324 | |
| 325 | for (i = 0; i < 4; ++i) |
| 326 | VIM_CLEAR(wp->w_border_highlight[i]); |
| 327 | di = dict_find(dict, (char_u *)"borderhighlight", -1); |
| 328 | if (di != NULL) |
| 329 | { |
| 330 | if (di->di_tv.v_type != VAR_LIST) |
| 331 | emsg(_(e_listreq)); |
| 332 | else |
| 333 | { |
| 334 | list_T *list = di->di_tv.vval.v_list; |
| 335 | listitem_T *li; |
| 336 | |
| 337 | if (list != NULL) |
| 338 | for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len; |
| 339 | ++i, li = li->li_next) |
| 340 | { |
| 341 | str = tv_get_string(&li->li_tv); |
| 342 | if (*str != NUL) |
| 343 | wp->w_border_highlight[i] = vim_strsave(str); |
| 344 | } |
| 345 | if (list->lv_len == 1 && wp->w_border_highlight[0] != NULL) |
| 346 | for (i = 1; i < 4; ++i) |
| 347 | wp->w_border_highlight[i] = |
| 348 | vim_strsave(wp->w_border_highlight[0]); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | for (i = 0; i < 8; ++i) |
| 353 | wp->w_border_char[i] = 0; |
| 354 | di = dict_find(dict, (char_u *)"borderchars", -1); |
| 355 | if (di != NULL) |
| 356 | { |
| 357 | if (di->di_tv.v_type != VAR_LIST) |
| 358 | emsg(_(e_listreq)); |
| 359 | else |
| 360 | { |
| 361 | list_T *list = di->di_tv.vval.v_list; |
| 362 | listitem_T *li; |
| 363 | |
| 364 | if (list != NULL) |
| 365 | for (i = 0, li = list->lv_first; i < 8 && i < list->lv_len; |
| 366 | ++i, li = li->li_next) |
| 367 | { |
| 368 | str = tv_get_string(&li->li_tv); |
| 369 | if (*str != NUL) |
| 370 | wp->w_border_char[i] = mb_ptr2char(str); |
| 371 | } |
| 372 | if (list->lv_len == 1) |
| 373 | for (i = 1; i < 8; ++i) |
| 374 | wp->w_border_char[i] = wp->w_border_char[0]; |
| 375 | if (list->lv_len == 2) |
| 376 | { |
| 377 | for (i = 4; i < 8; ++i) |
| 378 | wp->w_border_char[i] = wp->w_border_char[1]; |
| 379 | for (i = 1; i < 4; ++i) |
| 380 | wp->w_border_char[i] = wp->w_border_char[0]; |
| 381 | } |
| 382 | } |
| 383 | } |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 384 | |
| 385 | di = dict_find(dict, (char_u *)"moved", -1); |
| 386 | if (di != NULL) |
| 387 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 388 | set_moved_values(wp); |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 389 | if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL) |
| 390 | { |
| 391 | char_u *s = di->di_tv.vval.v_string; |
| 392 | int flags = 0; |
| 393 | |
| 394 | if (STRCMP(s, "word") == 0) |
| 395 | flags = FIND_IDENT | FIND_STRING; |
| 396 | else if (STRCMP(s, "WORD") == 0) |
| 397 | flags = FIND_STRING; |
| 398 | else if (STRCMP(s, "any") != 0) |
| 399 | semsg(_(e_invarg2), s); |
| 400 | if (flags != 0) |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 401 | set_moved_columns(wp, flags); |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 402 | } |
| 403 | else if (di->di_tv.v_type == VAR_LIST |
| 404 | && di->di_tv.vval.v_list != NULL |
| 405 | && di->di_tv.vval.v_list->lv_len == 2) |
| 406 | { |
| 407 | list_T *l = di->di_tv.vval.v_list; |
| 408 | |
| 409 | wp->w_popup_mincol = tv_get_number(&l->lv_first->li_tv); |
| 410 | wp->w_popup_maxcol = tv_get_number(&l->lv_first->li_next->li_tv); |
| 411 | } |
| 412 | else |
| 413 | semsg(_(e_invarg2), tv_get_string(&di->di_tv)); |
| 414 | } |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 415 | |
| 416 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | /* |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 420 | * Add lines to the popup from a list of strings. |
| 421 | */ |
| 422 | static void |
| 423 | add_popup_strings(buf_T *buf, list_T *l) |
| 424 | { |
| 425 | listitem_T *li; |
| 426 | linenr_T lnum = 0; |
| 427 | char_u *p; |
| 428 | |
| 429 | for (li = l->lv_first; li != NULL; li = li->li_next) |
| 430 | if (li->li_tv.v_type == VAR_STRING) |
| 431 | { |
| 432 | p = li->li_tv.vval.v_string; |
| 433 | ml_append_buf(buf, lnum++, |
| 434 | p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | /* |
| 439 | * Add lines to the popup from a list of dictionaries. |
| 440 | */ |
| 441 | static void |
| 442 | add_popup_dicts(buf_T *buf, list_T *l) |
| 443 | { |
| 444 | listitem_T *li; |
| 445 | listitem_T *pli; |
| 446 | linenr_T lnum = 0; |
| 447 | char_u *p; |
| 448 | dict_T *dict; |
| 449 | |
| 450 | // first add the text lines |
| 451 | for (li = l->lv_first; li != NULL; li = li->li_next) |
| 452 | { |
| 453 | if (li->li_tv.v_type != VAR_DICT) |
| 454 | { |
| 455 | emsg(_(e_dictreq)); |
| 456 | return; |
| 457 | } |
| 458 | dict = li->li_tv.vval.v_dict; |
| 459 | p = dict == NULL ? NULL |
| 460 | : dict_get_string(dict, (char_u *)"text", FALSE); |
| 461 | ml_append_buf(buf, lnum++, |
| 462 | p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE); |
| 463 | } |
| 464 | |
| 465 | // add the text properties |
| 466 | lnum = 1; |
| 467 | for (li = l->lv_first; li != NULL; li = li->li_next, ++lnum) |
| 468 | { |
| 469 | dictitem_T *di; |
| 470 | list_T *plist; |
| 471 | |
| 472 | dict = li->li_tv.vval.v_dict; |
| 473 | di = dict_find(dict, (char_u *)"props", -1); |
| 474 | if (di != NULL) |
| 475 | { |
| 476 | if (di->di_tv.v_type != VAR_LIST) |
| 477 | { |
| 478 | emsg(_(e_listreq)); |
| 479 | return; |
| 480 | } |
| 481 | plist = di->di_tv.vval.v_list; |
| 482 | if (plist != NULL) |
| 483 | { |
| 484 | for (pli = plist->lv_first; pli != NULL; pli = pli->li_next) |
| 485 | { |
| 486 | if (pli->li_tv.v_type != VAR_DICT) |
| 487 | { |
| 488 | emsg(_(e_dictreq)); |
| 489 | return; |
| 490 | } |
| 491 | dict = pli->li_tv.vval.v_dict; |
| 492 | if (dict != NULL) |
| 493 | { |
| 494 | int col = dict_get_number(dict, (char_u *)"col"); |
| 495 | |
| 496 | prop_add_common( lnum, col, dict, buf, NULL); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | /* |
Bram Moolenaar | 451d4b5 | 2019-06-12 20:22:27 +0200 | [diff] [blame] | 505 | * Return the height of popup window "wp", including border and padding. |
| 506 | */ |
| 507 | int |
| 508 | popup_height(win_T *wp) |
| 509 | { |
| 510 | return wp->w_height |
| 511 | + wp->w_popup_padding[0] + wp->w_popup_border[0] |
| 512 | + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * Return the width of popup window "wp", including border and padding. |
| 517 | */ |
| 518 | int |
| 519 | popup_width(win_T *wp) |
| 520 | { |
| 521 | return wp->w_width |
| 522 | + wp->w_popup_padding[3] + wp->w_popup_border[3] |
| 523 | + wp->w_popup_padding[1] + wp->w_popup_border[1]; |
| 524 | } |
| 525 | |
| 526 | /* |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 527 | * Adjust the position and size of the popup to fit on the screen. |
| 528 | */ |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 529 | void |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 530 | popup_adjust_position(win_T *wp) |
| 531 | { |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 532 | linenr_T lnum; |
| 533 | int wrapped = 0; |
| 534 | int maxwidth; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 535 | int center_vert = FALSE; |
| 536 | int center_hor = FALSE; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 537 | int allow_adjust_left = !wp->w_popup_fixed; |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 538 | int top_extra = wp->w_popup_border[0] + wp->w_popup_padding[0]; |
| 539 | int right_extra = wp->w_popup_border[1] + wp->w_popup_padding[1]; |
| 540 | int bot_extra = wp->w_popup_border[2] + wp->w_popup_padding[2]; |
| 541 | int left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
| 542 | int extra_height = top_extra + bot_extra; |
| 543 | int extra_width = left_extra + right_extra; |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 544 | int org_winrow = wp->w_winrow; |
| 545 | int org_wincol = wp->w_wincol; |
| 546 | int org_width = wp->w_width; |
| 547 | int org_height = wp->w_height; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 548 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 549 | wp->w_winrow = 0; |
| 550 | wp->w_wincol = 0; |
| 551 | if (wp->w_popup_pos == POPPOS_CENTER) |
| 552 | { |
| 553 | // center after computing the size |
| 554 | center_vert = TRUE; |
| 555 | center_hor = TRUE; |
| 556 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 557 | else |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 558 | { |
| 559 | if (wp->w_wantline == 0) |
| 560 | center_vert = TRUE; |
| 561 | else if (wp->w_popup_pos == POPPOS_TOPLEFT |
| 562 | || wp->w_popup_pos == POPPOS_TOPRIGHT) |
| 563 | { |
| 564 | wp->w_winrow = wp->w_wantline - 1; |
| 565 | if (wp->w_winrow >= Rows) |
| 566 | wp->w_winrow = Rows - 1; |
| 567 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 568 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 569 | if (wp->w_wantcol == 0) |
| 570 | center_hor = TRUE; |
| 571 | else if (wp->w_popup_pos == POPPOS_TOPLEFT |
| 572 | || wp->w_popup_pos == POPPOS_BOTLEFT) |
| 573 | { |
| 574 | wp->w_wincol = wp->w_wantcol - 1; |
| 575 | if (wp->w_wincol >= Columns - 3) |
| 576 | wp->w_wincol = Columns - 3; |
| 577 | } |
| 578 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 579 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 580 | // When centering or right aligned, use maximum width. |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 581 | // When left aligned use the space available, but shift to the left when we |
| 582 | // hit the right of the screen. |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 583 | maxwidth = Columns - wp->w_wincol; |
| 584 | if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth) |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 585 | { |
| 586 | allow_adjust_left = FALSE; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 587 | maxwidth = wp->w_maxwidth; |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 588 | } |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 589 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 590 | // start at the desired first line |
| 591 | wp->w_topline = wp->w_firstline; |
| 592 | if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) |
| 593 | wp->w_topline = wp->w_buffer->b_ml.ml_line_count; |
| 594 | |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 595 | // Compute width based on longest text line and the 'wrap' option. |
| 596 | // TODO: more accurate wrapping |
| 597 | wp->w_width = 0; |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 598 | 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] | 599 | { |
| 600 | int len = vim_strsize(ml_get_buf(wp->w_buffer, lnum, FALSE)); |
| 601 | |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 602 | if (wp->w_p_wrap) |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 603 | { |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 604 | while (len > maxwidth) |
| 605 | { |
| 606 | ++wrapped; |
| 607 | len -= maxwidth; |
| 608 | wp->w_width = maxwidth; |
| 609 | } |
| 610 | } |
| 611 | else if (len > maxwidth |
| 612 | && allow_adjust_left |
| 613 | && (wp->w_popup_pos == POPPOS_TOPLEFT |
| 614 | || wp->w_popup_pos == POPPOS_BOTLEFT)) |
| 615 | { |
| 616 | // adjust leftwise to fit text on screen |
| 617 | int shift_by = ( len - maxwidth ); |
| 618 | |
| 619 | if ( shift_by > wp->w_wincol ) |
| 620 | { |
| 621 | int truncate_shift = shift_by - wp->w_wincol; |
| 622 | len -= truncate_shift; |
| 623 | shift_by -= truncate_shift; |
| 624 | } |
| 625 | |
| 626 | wp->w_wincol -= shift_by; |
| 627 | maxwidth += shift_by; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 628 | wp->w_width = maxwidth; |
| 629 | } |
| 630 | if (wp->w_width < len) |
| 631 | wp->w_width = len; |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 632 | // do not use the width of lines we're not going to show |
| 633 | if (wp->w_maxheight > 0 && wp->w_buffer->b_ml.ml_line_count |
| 634 | - wp->w_topline + 1 + wrapped > wp->w_maxheight) |
| 635 | break; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 636 | } |
| 637 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 638 | if (wp->w_minwidth > 0 && wp->w_width < wp->w_minwidth) |
| 639 | wp->w_width = wp->w_minwidth; |
Bram Moolenaar | 88c4e1f | 2019-05-29 23:14:28 +0200 | [diff] [blame] | 640 | if (wp->w_width > maxwidth) |
| 641 | wp->w_width = maxwidth; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 642 | if (center_hor) |
| 643 | wp->w_wincol = (Columns - wp->w_width) / 2; |
| 644 | else if (wp->w_popup_pos == POPPOS_BOTRIGHT |
| 645 | || wp->w_popup_pos == POPPOS_TOPRIGHT) |
| 646 | { |
| 647 | // Right aligned: move to the right if needed. |
| 648 | // No truncation, because that would change the height. |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 649 | if (wp->w_width + extra_width < wp->w_wantcol) |
| 650 | wp->w_wincol = wp->w_wantcol - (wp->w_width + extra_width); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 651 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 652 | |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 653 | wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline |
| 654 | + 1 + wrapped; |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 655 | if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight) |
| 656 | wp->w_height = wp->w_minheight; |
| 657 | if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight) |
| 658 | wp->w_height = wp->w_maxheight; |
| 659 | if (wp->w_height > Rows - wp->w_winrow) |
| 660 | wp->w_height = Rows - wp->w_winrow; |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 661 | |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 662 | if (center_vert) |
| 663 | wp->w_winrow = (Rows - wp->w_height) / 2; |
| 664 | else if (wp->w_popup_pos == POPPOS_BOTRIGHT |
| 665 | || wp->w_popup_pos == POPPOS_BOTLEFT) |
| 666 | { |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 667 | if ((wp->w_height + extra_height) <= wp->w_wantline) |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 668 | // bottom aligned: may move down |
Bram Moolenaar | 399d898 | 2019-06-02 15:34:29 +0200 | [diff] [blame] | 669 | wp->w_winrow = wp->w_wantline - (wp->w_height + extra_height); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 670 | else |
| 671 | // not enough space, make top aligned |
| 672 | wp->w_winrow = wp->w_wantline + 1; |
| 673 | } |
| 674 | |
Bram Moolenaar | 1714696 | 2019-05-30 00:12:11 +0200 | [diff] [blame] | 675 | wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 676 | |
| 677 | // Need to update popup_mask if the position or size changed. |
Bram Moolenaar | acc682b | 2019-06-08 17:15:51 +0200 | [diff] [blame] | 678 | // And redraw windows that were behind the popup. |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 679 | if (org_winrow != wp->w_winrow |
| 680 | || org_wincol != wp->w_wincol |
| 681 | || org_width != wp->w_width |
| 682 | || org_height != wp->w_height) |
| 683 | { |
Bram Moolenaar | 4c063a0 | 2019-06-10 21:24:12 +0200 | [diff] [blame] | 684 | redraw_all_later(VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 685 | popup_mask_refresh = TRUE; |
| 686 | } |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 687 | } |
| 688 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 689 | typedef enum |
| 690 | { |
| 691 | TYPE_NORMAL, |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 692 | TYPE_ATCURSOR, |
| 693 | TYPE_NOTIFICATION |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 694 | } create_type_T; |
| 695 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 696 | /* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 697 | * popup_create({text}, {options}) |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 698 | * popup_atcursor({text}, {options}) |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 699 | * When called from f_popup_atcursor() "type" is TYPE_ATCURSOR. |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 700 | */ |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 701 | static void |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 702 | popup_create(typval_T *argvars, typval_T *rettv, create_type_T type) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 703 | { |
| 704 | win_T *wp; |
| 705 | buf_T *buf; |
| 706 | dict_T *d; |
| 707 | int nr; |
| 708 | |
| 709 | // Check arguments look OK. |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 710 | if (!(argvars[0].v_type == VAR_STRING && argvars[0].vval.v_string != NULL) |
| 711 | && !(argvars[0].v_type == VAR_LIST && argvars[0].vval.v_list != NULL)) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 712 | { |
| 713 | emsg(_(e_listreq)); |
| 714 | return; |
| 715 | } |
| 716 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 717 | { |
| 718 | emsg(_(e_dictreq)); |
| 719 | return; |
| 720 | } |
| 721 | d = argvars[1].vval.v_dict; |
| 722 | |
| 723 | // Create the window and buffer. |
| 724 | wp = win_alloc_popup_win(); |
| 725 | if (wp == NULL) |
| 726 | return; |
| 727 | rettv->vval.v_number = wp->w_id; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 728 | wp->w_popup_pos = POPPOS_TOPLEFT; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 729 | |
| 730 | buf = buflist_new(NULL, NULL, (linenr_T)0, BLN_NEW|BLN_LISTED|BLN_DUMMY); |
| 731 | if (buf == NULL) |
| 732 | return; |
| 733 | ml_open(buf); |
Bram Moolenaar | cacc6a5 | 2019-05-30 15:22:43 +0200 | [diff] [blame] | 734 | |
| 735 | win_init_popup_win(wp, buf); |
| 736 | |
| 737 | set_local_options_default(wp); |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 738 | set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1, |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 739 | (char_u *)"popup", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 20c023a | 2019-05-26 21:03:24 +0200 | [diff] [blame] | 740 | set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1, |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 741 | (char_u *)"hide", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 742 | buf->b_p_ul = -1; // no undo |
| 743 | buf->b_p_swf = FALSE; // no swap file |
| 744 | buf->b_p_bl = FALSE; // unlisted buffer |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 745 | buf->b_locked = TRUE; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 746 | wp->w_p_wrap = TRUE; // 'wrap' is default on |
| 747 | |
Bram Moolenaar | 54fabd4 | 2019-05-30 19:03:22 +0200 | [diff] [blame] | 748 | // Avoid that 'buftype' is reset when this buffer is entered. |
| 749 | buf->b_p_initialized = TRUE; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 750 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 751 | if (dict_find(d, (char_u *)"tab", -1) != NULL) |
| 752 | nr = (int)dict_get_number(d, (char_u *)"tab"); |
| 753 | else if (type == TYPE_NOTIFICATION) |
| 754 | nr = -1; // notifications are global by default |
| 755 | else |
| 756 | nr = 0; |
| 757 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 758 | if (nr == 0) |
| 759 | { |
| 760 | // popup on current tab |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 761 | wp->w_next = curtab->tp_first_popupwin; |
| 762 | curtab->tp_first_popupwin = wp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 763 | } |
| 764 | else if (nr < 0) |
| 765 | { |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 766 | win_T *prev = first_popupwin; |
| 767 | |
| 768 | // Global popup: add at the end, so that it gets displayed on top of |
| 769 | // older ones with the same zindex. Matters for notifications. |
| 770 | if (first_popupwin == NULL) |
| 771 | first_popupwin = wp; |
| 772 | else |
| 773 | { |
| 774 | while (prev->w_next != NULL) |
| 775 | prev = prev->w_next; |
| 776 | prev->w_next = wp; |
| 777 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 778 | } |
| 779 | else |
| 780 | // TODO: find tab page "nr" |
| 781 | emsg("Not implemented yet"); |
| 782 | |
| 783 | // Add text to the buffer. |
| 784 | if (argvars[0].v_type == VAR_STRING) |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 785 | { |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 786 | // just a string |
| 787 | ml_append_buf(buf, 0, argvars[0].vval.v_string, (colnr_T)0, TRUE); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 788 | } |
| 789 | else |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 790 | { |
| 791 | list_T *l = argvars[0].vval.v_list; |
| 792 | |
Bram Moolenaar | 7b29dd8 | 2019-06-02 13:22:11 +0200 | [diff] [blame] | 793 | if (l->lv_len > 0) |
| 794 | { |
| 795 | if (l->lv_first->li_tv.v_type == VAR_STRING) |
| 796 | // list of strings |
| 797 | add_popup_strings(buf, l); |
| 798 | else |
| 799 | // list of dictionaries |
| 800 | add_popup_dicts(buf, l); |
| 801 | } |
Bram Moolenaar | 7a8d027 | 2019-05-26 23:32:06 +0200 | [diff] [blame] | 802 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 803 | |
| 804 | // Delete the line of the empty buffer. |
| 805 | curbuf = buf; |
| 806 | ml_delete(buf->b_ml.ml_line_count, FALSE); |
| 807 | curbuf = curwin->w_buffer; |
| 808 | |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 809 | if (type == TYPE_ATCURSOR) |
| 810 | { |
| 811 | wp->w_popup_pos = POPPOS_BOTLEFT; |
| 812 | setcursor_mayforce(TRUE); |
| 813 | wp->w_wantline = screen_screenrow(); |
| 814 | if (wp->w_wantline == 0) // cursor in first line |
| 815 | { |
| 816 | wp->w_wantline = 2; |
| 817 | wp->w_popup_pos = POPPOS_TOPLEFT; |
| 818 | } |
| 819 | wp->w_wantcol = screen_screencol() + 1; |
| 820 | set_moved_values(wp); |
| 821 | set_moved_columns(wp, FIND_STRING); |
| 822 | } |
| 823 | |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 824 | // set default values |
| 825 | wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX; |
| 826 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 827 | if (type == TYPE_NOTIFICATION) |
| 828 | { |
| 829 | win_T *twp, *nextwin; |
| 830 | int height = buf->b_ml.ml_line_count + 3; |
| 831 | int i; |
| 832 | |
| 833 | // Try to not overlap with another global popup. Guess we need 3 |
| 834 | // more screen lines than buffer lines. |
| 835 | wp->w_wantline = 1; |
| 836 | for (twp = first_popupwin; twp != NULL; twp = nextwin) |
| 837 | { |
| 838 | nextwin = twp->w_next; |
| 839 | if (twp != wp |
| 840 | && twp->w_zindex == POPUPWIN_NOTIFICATION_ZINDEX |
| 841 | && twp->w_winrow <= wp->w_wantline - 1 + height |
| 842 | && twp->w_winrow + popup_height(twp) > wp->w_wantline - 1) |
| 843 | { |
| 844 | // move to below this popup and restart the loop to check for |
| 845 | // overlap with other popups |
| 846 | wp->w_wantline = twp->w_winrow + popup_height(twp) + 1; |
| 847 | nextwin = first_popupwin; |
| 848 | } |
| 849 | } |
| 850 | if (wp->w_wantline + height > Rows) |
| 851 | { |
| 852 | // can't avoid overlap, put on top in the hope that message goes |
| 853 | // away soon. |
| 854 | wp->w_wantline = 1; |
| 855 | } |
| 856 | |
| 857 | wp->w_wantcol = 10; |
| 858 | wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX; |
| 859 | for (i = 0; i < 4; ++i) |
| 860 | wp->w_popup_border[i] = 1; |
| 861 | wp->w_popup_padding[1] = 1; |
| 862 | wp->w_popup_padding[3] = 1; |
| 863 | set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, |
| 864 | (char_u *)"WarningMsg", OPT_FREE|OPT_LOCAL, 0); |
Bram Moolenaar | b53fb31 | 2019-06-13 23:59:52 +0200 | [diff] [blame] | 865 | wp->w_popup_drag = 1; |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 866 | } |
| 867 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 868 | // Deal with options. |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 869 | apply_options(wp, buf, argvars[1].vval.v_dict); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 870 | |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 871 | if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL) |
| 872 | popup_add_timeout(wp, 3000); |
| 873 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 874 | popup_adjust_position(wp); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 875 | |
| 876 | wp->w_vsep_width = 0; |
| 877 | |
| 878 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 879 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /* |
Bram Moolenaar | 3ff5f0f | 2019-06-10 13:11:22 +0200 | [diff] [blame] | 883 | * popup_clear() |
| 884 | */ |
| 885 | void |
| 886 | f_popup_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
| 887 | { |
| 888 | close_all_popups(); |
| 889 | } |
| 890 | |
| 891 | /* |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 892 | * popup_create({text}, {options}) |
| 893 | */ |
| 894 | void |
| 895 | f_popup_create(typval_T *argvars, typval_T *rettv) |
| 896 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 897 | popup_create(argvars, rettv, TYPE_NORMAL); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | /* |
| 901 | * popup_atcursor({text}, {options}) |
| 902 | */ |
| 903 | void |
| 904 | f_popup_atcursor(typval_T *argvars, typval_T *rettv) |
| 905 | { |
Bram Moolenaar | 1762731 | 2019-06-02 19:53:44 +0200 | [diff] [blame] | 906 | popup_create(argvars, rettv, TYPE_ATCURSOR); |
Bram Moolenaar | cc31ad9 | 2019-05-30 19:25:06 +0200 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | /* |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 910 | * popup_notification({text}, {options}) |
| 911 | */ |
| 912 | void |
| 913 | f_popup_notification(typval_T *argvars, typval_T *rettv) |
| 914 | { |
| 915 | popup_create(argvars, rettv, TYPE_NOTIFICATION); |
| 916 | } |
| 917 | |
| 918 | /* |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 919 | * Find the popup window with window-ID "id". |
| 920 | * If the popup window does not exist NULL is returned. |
| 921 | * If the window is not a popup window, and error message is given. |
| 922 | */ |
| 923 | static win_T * |
| 924 | find_popup_win(int id) |
| 925 | { |
| 926 | win_T *wp = win_id2wp(id); |
| 927 | |
| 928 | if (wp != NULL && !bt_popup(wp->w_buffer)) |
| 929 | { |
| 930 | semsg(_("E993: window %d is not a popup window"), id); |
| 931 | return NULL; |
| 932 | } |
| 933 | return wp; |
| 934 | } |
| 935 | |
| 936 | /* |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 937 | * Invoke the close callback for window "wp" with value "result". |
| 938 | * Careful: The callback may make "wp" invalid! |
| 939 | */ |
| 940 | static void |
| 941 | invoke_popup_callback(win_T *wp, typval_T *result) |
| 942 | { |
| 943 | typval_T rettv; |
| 944 | int dummy; |
| 945 | typval_T argv[3]; |
| 946 | |
| 947 | argv[0].v_type = VAR_NUMBER; |
| 948 | argv[0].vval.v_number = (varnumber_T)wp->w_id; |
| 949 | |
| 950 | if (result != NULL && result->v_type != VAR_UNKNOWN) |
| 951 | copy_tv(result, &argv[1]); |
| 952 | else |
| 953 | { |
| 954 | argv[1].v_type = VAR_NUMBER; |
| 955 | argv[1].vval.v_number = 0; |
| 956 | } |
| 957 | |
| 958 | argv[2].v_type = VAR_UNKNOWN; |
| 959 | |
| 960 | call_callback(&wp->w_close_cb, -1, |
| 961 | &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
| 962 | if (result != NULL) |
| 963 | clear_tv(&argv[1]); |
| 964 | clear_tv(&rettv); |
| 965 | } |
| 966 | |
| 967 | /* |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 968 | * Close popup "wp" and invoke any close callback for it. |
| 969 | */ |
| 970 | static void |
| 971 | popup_close_and_callback(win_T *wp, typval_T *arg) |
| 972 | { |
| 973 | int id = wp->w_id; |
| 974 | |
| 975 | if (wp->w_close_cb.cb_name != NULL) |
| 976 | // Careful: This may make "wp" invalid. |
| 977 | invoke_popup_callback(wp, arg); |
| 978 | |
| 979 | popup_close(id); |
| 980 | } |
| 981 | |
| 982 | /* |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 983 | * popup_close({id}) |
| 984 | */ |
| 985 | void |
| 986 | f_popup_close(typval_T *argvars, typval_T *rettv UNUSED) |
| 987 | { |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 988 | int id = (int)tv_get_number(argvars); |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 989 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 990 | |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 991 | if (wp != NULL) |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 992 | popup_close_and_callback(wp, &argvars[1]); |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | /* |
| 996 | * popup_hide({id}) |
| 997 | */ |
| 998 | void |
| 999 | f_popup_hide(typval_T *argvars, typval_T *rettv UNUSED) |
| 1000 | { |
| 1001 | int id = (int)tv_get_number(argvars); |
| 1002 | win_T *wp = find_popup_win(id); |
| 1003 | |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1004 | if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) == 0) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1005 | { |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1006 | wp->w_popup_flags |= POPF_HIDDEN; |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 1007 | --wp->w_buffer->b_nwindows; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1008 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1009 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | /* |
| 1014 | * popup_show({id}) |
| 1015 | */ |
| 1016 | void |
| 1017 | f_popup_show(typval_T *argvars, typval_T *rettv UNUSED) |
| 1018 | { |
| 1019 | int id = (int)tv_get_number(argvars); |
| 1020 | win_T *wp = find_popup_win(id); |
| 1021 | |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1022 | if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) != 0) |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1023 | { |
Bram Moolenaar | bf0ecb2 | 2019-05-27 10:04:40 +0200 | [diff] [blame] | 1024 | wp->w_popup_flags &= ~POPF_HIDDEN; |
Bram Moolenaar | c6896e2 | 2019-05-30 22:32:34 +0200 | [diff] [blame] | 1025 | ++wp->w_buffer->b_nwindows; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1026 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1027 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1028 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1029 | } |
| 1030 | |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1031 | static void |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1032 | popup_free(win_T *wp) |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1033 | { |
Bram Moolenaar | 868b7b6 | 2019-05-29 21:44:40 +0200 | [diff] [blame] | 1034 | wp->w_buffer->b_locked = FALSE; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1035 | if (wp->w_winrow + wp->w_height >= cmdline_row) |
| 1036 | clear_cmdline = TRUE; |
| 1037 | win_free_popup(wp); |
| 1038 | redraw_all_later(NOT_VALID); |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1039 | popup_mask_refresh = TRUE; |
Bram Moolenaar | 51fe3b1 | 2019-05-26 20:10:06 +0200 | [diff] [blame] | 1040 | } |
| 1041 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1042 | /* |
| 1043 | * Close a popup window by Window-id. |
Bram Moolenaar | 9eaac89 | 2019-06-01 22:49:29 +0200 | [diff] [blame] | 1044 | * Does not invoke the callback. |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1045 | */ |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1046 | void |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1047 | popup_close(int id) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1048 | { |
| 1049 | win_T *wp; |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1050 | tabpage_T *tp; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1051 | win_T *prev = NULL; |
| 1052 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1053 | // go through global popups |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1054 | for (wp = first_popupwin; wp != NULL; prev = wp, wp = wp->w_next) |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1055 | if (wp->w_id == id) |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1056 | { |
| 1057 | if (prev == NULL) |
| 1058 | first_popupwin = wp->w_next; |
| 1059 | else |
| 1060 | prev->w_next = wp->w_next; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1061 | popup_free(wp); |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1062 | return; |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1063 | } |
| 1064 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1065 | // go through tab-local popups |
| 1066 | FOR_ALL_TABPAGES(tp) |
| 1067 | popup_close_tabpage(tp, id); |
| 1068 | } |
| 1069 | |
| 1070 | /* |
| 1071 | * Close a popup window with Window-id "id" in tabpage "tp". |
| 1072 | */ |
| 1073 | void |
| 1074 | popup_close_tabpage(tabpage_T *tp, int id) |
| 1075 | { |
| 1076 | win_T *wp; |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 1077 | win_T **root = &tp->tp_first_popupwin; |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1078 | win_T *prev = NULL; |
| 1079 | |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1080 | for (wp = *root; wp != NULL; prev = wp, wp = wp->w_next) |
| 1081 | if (wp->w_id == id) |
| 1082 | { |
| 1083 | if (prev == NULL) |
| 1084 | *root = wp->w_next; |
| 1085 | else |
| 1086 | prev->w_next = wp->w_next; |
Bram Moolenaar | 2cd0dce | 2019-05-26 22:17:52 +0200 | [diff] [blame] | 1087 | popup_free(wp); |
Bram Moolenaar | ec58384 | 2019-05-26 14:11:23 +0200 | [diff] [blame] | 1088 | return; |
| 1089 | } |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | void |
| 1093 | close_all_popups(void) |
| 1094 | { |
| 1095 | while (first_popupwin != NULL) |
| 1096 | popup_close(first_popupwin->w_id); |
Bram Moolenaar | 9c27b1c | 2019-05-26 18:48:13 +0200 | [diff] [blame] | 1097 | while (curtab->tp_first_popupwin != NULL) |
| 1098 | popup_close(curtab->tp_first_popupwin->w_id); |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1099 | } |
| 1100 | |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1101 | /* |
| 1102 | * popup_move({id}, {options}) |
| 1103 | */ |
| 1104 | void |
| 1105 | f_popup_move(typval_T *argvars, typval_T *rettv UNUSED) |
| 1106 | { |
| 1107 | dict_T *d; |
| 1108 | int nr; |
| 1109 | int id = (int)tv_get_number(argvars); |
| 1110 | win_T *wp = find_popup_win(id); |
| 1111 | |
| 1112 | if (wp == NULL) |
| 1113 | return; // invalid {id} |
| 1114 | |
| 1115 | if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL) |
| 1116 | { |
| 1117 | emsg(_(e_dictreq)); |
| 1118 | return; |
| 1119 | } |
| 1120 | d = argvars[1].vval.v_dict; |
| 1121 | |
| 1122 | if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0) |
| 1123 | wp->w_minwidth = nr; |
| 1124 | if ((nr = dict_get_number(d, (char_u *)"minheight")) > 0) |
| 1125 | wp->w_minheight = nr; |
| 1126 | if ((nr = dict_get_number(d, (char_u *)"maxwidth")) > 0) |
| 1127 | wp->w_maxwidth = nr; |
| 1128 | if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0) |
| 1129 | wp->w_maxheight = nr; |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1130 | get_pos_options(wp, d); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1131 | |
| 1132 | if (wp->w_winrow + wp->w_height >= cmdline_row) |
| 1133 | clear_cmdline = TRUE; |
| 1134 | popup_adjust_position(wp); |
Bram Moolenaar | 60cdb30 | 2019-05-27 21:54:10 +0200 | [diff] [blame] | 1135 | } |
| 1136 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1137 | /* |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1138 | * popup_getpos({id}) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1139 | */ |
| 1140 | void |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1141 | f_popup_getpos(typval_T *argvars, typval_T *rettv) |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1142 | { |
| 1143 | dict_T *dict; |
| 1144 | int id = (int)tv_get_number(argvars); |
| 1145 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1146 | int top_extra; |
| 1147 | int left_extra; |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1148 | |
| 1149 | if (rettv_dict_alloc(rettv) == OK) |
| 1150 | { |
| 1151 | if (wp == NULL) |
| 1152 | return; // invalid {id} |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1153 | top_extra = wp->w_popup_border[0] + wp->w_popup_padding[0]; |
| 1154 | left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3]; |
| 1155 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1156 | dict = rettv->vval.v_dict; |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1157 | |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1158 | dict_add_number(dict, "line", wp->w_winrow + 1); |
| 1159 | dict_add_number(dict, "col", wp->w_wincol + 1); |
Bram Moolenaar | 68d48f4 | 2019-06-12 22:42:41 +0200 | [diff] [blame] | 1160 | dict_add_number(dict, "width", wp->w_width + left_extra |
| 1161 | + wp->w_popup_border[1] + wp->w_popup_padding[1]); |
| 1162 | dict_add_number(dict, "height", wp->w_height + top_extra |
| 1163 | + wp->w_popup_border[2] + wp->w_popup_padding[2]); |
Bram Moolenaar | 2fd8e35 | 2019-06-01 20:16:48 +0200 | [diff] [blame] | 1164 | |
| 1165 | dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra); |
| 1166 | dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra); |
| 1167 | dict_add_number(dict, "core_width", wp->w_width); |
| 1168 | dict_add_number(dict, "core_height", wp->w_height); |
| 1169 | |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1170 | dict_add_number(dict, "visible", |
Bram Moolenaar | b0ebbda | 2019-06-02 16:51:21 +0200 | [diff] [blame] | 1171 | win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | /* |
Bram Moolenaar | 33796b3 | 2019-06-08 16:01:13 +0200 | [diff] [blame] | 1176 | * popup_getoptions({id}) |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1177 | */ |
| 1178 | void |
| 1179 | f_popup_getoptions(typval_T *argvars, typval_T *rettv) |
| 1180 | { |
| 1181 | dict_T *dict; |
| 1182 | int id = (int)tv_get_number(argvars); |
| 1183 | win_T *wp = find_popup_win(id); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1184 | int i; |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1185 | |
| 1186 | if (rettv_dict_alloc(rettv) == OK) |
| 1187 | { |
| 1188 | if (wp == NULL) |
| 1189 | return; |
| 1190 | |
| 1191 | dict = rettv->vval.v_dict; |
| 1192 | dict_add_number(dict, "line", wp->w_wantline); |
| 1193 | dict_add_number(dict, "col", wp->w_wantcol); |
| 1194 | dict_add_number(dict, "minwidth", wp->w_minwidth); |
| 1195 | dict_add_number(dict, "minheight", wp->w_minheight); |
| 1196 | dict_add_number(dict, "maxheight", wp->w_maxheight); |
| 1197 | dict_add_number(dict, "maxwidth", wp->w_maxwidth); |
Bram Moolenaar | 8d24104 | 2019-06-12 23:40:01 +0200 | [diff] [blame] | 1198 | dict_add_number(dict, "firstline", wp->w_firstline); |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1199 | dict_add_number(dict, "zindex", wp->w_zindex); |
Bram Moolenaar | 042fb4b | 2019-06-02 14:49:56 +0200 | [diff] [blame] | 1200 | dict_add_number(dict, "fixed", wp->w_popup_fixed); |
Bram Moolenaar | ac1f1bc | 2019-05-30 21:24:26 +0200 | [diff] [blame] | 1201 | |
| 1202 | for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T)); |
| 1203 | ++i) |
| 1204 | if (wp->w_popup_pos == poppos_entries[i].pp_val) |
| 1205 | { |
| 1206 | dict_add_string(dict, "pos", |
| 1207 | (char_u *)poppos_entries[i].pp_name); |
| 1208 | break; |
| 1209 | } |
| 1210 | |
Bram Moolenaar | 8c2a600 | 2019-05-30 14:29:45 +0200 | [diff] [blame] | 1211 | # if defined(FEAT_TIMERS) |
| 1212 | dict_add_number(dict, "time", wp->w_popup_timer != NULL |
| 1213 | ? (long)wp->w_popup_timer->tr_interval : 0L); |
| 1214 | # endif |
Bram Moolenaar | bc13354 | 2019-05-29 20:26:46 +0200 | [diff] [blame] | 1215 | } |
| 1216 | } |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 1217 | |
| 1218 | int |
| 1219 | not_in_popup_window() |
| 1220 | { |
| 1221 | if (bt_popup(curwin->w_buffer)) |
| 1222 | { |
| 1223 | emsg(_("E994: Not allowed in a popup window")); |
| 1224 | return TRUE; |
| 1225 | } |
| 1226 | return FALSE; |
| 1227 | } |
| 1228 | |
Bram Moolenaar | bf0eff0 | 2019-06-01 17:13:36 +0200 | [diff] [blame] | 1229 | /* |
| 1230 | * Reset all the POPF_HANDLED flags in global popup windows and popup windows |
| 1231 | * in the current tab. |
| 1232 | */ |
| 1233 | void |
| 1234 | popup_reset_handled() |
| 1235 | { |
| 1236 | win_T *wp; |
| 1237 | |
| 1238 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 1239 | wp->w_popup_flags &= ~POPF_HANDLED; |
| 1240 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 1241 | wp->w_popup_flags &= ~POPF_HANDLED; |
| 1242 | } |
| 1243 | |
| 1244 | /* |
| 1245 | * Find the next visible popup where POPF_HANDLED is not set. |
| 1246 | * Must have called popup_reset_handled() first. |
| 1247 | * When "lowest" is TRUE find the popup with the lowest zindex, otherwise the |
| 1248 | * popup with the highest zindex. |
| 1249 | */ |
| 1250 | win_T * |
| 1251 | find_next_popup(int lowest) |
| 1252 | { |
| 1253 | win_T *wp; |
| 1254 | win_T *found_wp; |
| 1255 | int found_zindex; |
| 1256 | |
| 1257 | found_zindex = lowest ? INT_MAX : 0; |
| 1258 | found_wp = NULL; |
| 1259 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 1260 | if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0 |
| 1261 | && (lowest ? wp->w_zindex < found_zindex |
| 1262 | : wp->w_zindex > found_zindex)) |
| 1263 | { |
| 1264 | found_zindex = wp->w_zindex; |
| 1265 | found_wp = wp; |
| 1266 | } |
| 1267 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 1268 | if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0 |
| 1269 | && (lowest ? wp->w_zindex < found_zindex |
| 1270 | : wp->w_zindex > found_zindex)) |
| 1271 | { |
| 1272 | found_zindex = wp->w_zindex; |
| 1273 | found_wp = wp; |
| 1274 | } |
| 1275 | |
| 1276 | if (found_wp != NULL) |
| 1277 | found_wp->w_popup_flags |= POPF_HANDLED; |
| 1278 | return found_wp; |
| 1279 | } |
| 1280 | |
| 1281 | /* |
| 1282 | * Invoke the filter callback for window "wp" with typed character "c". |
| 1283 | * Uses the global "mod_mask" for modifiers. |
| 1284 | * Returns the return value of the filter. |
| 1285 | * Careful: The filter may make "wp" invalid! |
| 1286 | */ |
| 1287 | static int |
| 1288 | invoke_popup_filter(win_T *wp, int c) |
| 1289 | { |
| 1290 | int res; |
| 1291 | typval_T rettv; |
| 1292 | int dummy; |
| 1293 | typval_T argv[3]; |
| 1294 | char_u buf[NUMBUFLEN]; |
| 1295 | |
| 1296 | argv[0].v_type = VAR_NUMBER; |
| 1297 | argv[0].vval.v_number = (varnumber_T)wp->w_id; |
| 1298 | |
| 1299 | // Convert the number to a string, so that the function can use: |
| 1300 | // if a:c == "\<F2>" |
| 1301 | buf[special_to_buf(c, mod_mask, TRUE, buf)] = NUL; |
| 1302 | argv[1].v_type = VAR_STRING; |
| 1303 | argv[1].vval.v_string = vim_strsave(buf); |
| 1304 | |
| 1305 | argv[2].v_type = VAR_UNKNOWN; |
| 1306 | |
| 1307 | call_callback(&wp->w_filter_cb, -1, |
| 1308 | &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
| 1309 | res = tv_get_number(&rettv); |
| 1310 | vim_free(argv[1].vval.v_string); |
| 1311 | clear_tv(&rettv); |
| 1312 | return res; |
| 1313 | } |
| 1314 | |
| 1315 | /* |
| 1316 | * Called when "c" was typed: invoke popup filter callbacks. |
| 1317 | * Returns TRUE when the character was consumed, |
| 1318 | */ |
| 1319 | int |
| 1320 | popup_do_filter(int c) |
| 1321 | { |
| 1322 | int res = FALSE; |
| 1323 | win_T *wp; |
| 1324 | |
| 1325 | popup_reset_handled(); |
| 1326 | |
| 1327 | while (!res && (wp = find_next_popup(FALSE)) != NULL) |
| 1328 | if (wp->w_filter_cb.cb_name != NULL) |
| 1329 | res = invoke_popup_filter(wp, c); |
| 1330 | |
| 1331 | return res; |
| 1332 | } |
| 1333 | |
Bram Moolenaar | 3397f74 | 2019-06-02 18:40:06 +0200 | [diff] [blame] | 1334 | /* |
| 1335 | * Called when the cursor moved: check if any popup needs to be closed if the |
| 1336 | * cursor moved far enough. |
| 1337 | */ |
| 1338 | void |
| 1339 | popup_check_cursor_pos() |
| 1340 | { |
| 1341 | win_T *wp; |
| 1342 | typval_T tv; |
| 1343 | |
| 1344 | popup_reset_handled(); |
| 1345 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 1346 | if (wp->w_popup_curwin != NULL |
| 1347 | && (curwin != wp->w_popup_curwin |
| 1348 | || curwin->w_cursor.lnum != wp->w_popup_lnum |
| 1349 | || curwin->w_cursor.col < wp->w_popup_mincol |
| 1350 | || curwin->w_cursor.col > wp->w_popup_maxcol)) |
| 1351 | { |
| 1352 | tv.v_type = VAR_NUMBER; |
| 1353 | tv.vval.v_number = -1; |
| 1354 | popup_close_and_callback(wp, &tv); |
| 1355 | } |
| 1356 | } |
| 1357 | |
Bram Moolenaar | a540f8a | 2019-06-14 19:23:57 +0200 | [diff] [blame] | 1358 | /* |
| 1359 | * Update "popup_mask" if needed. |
| 1360 | * Also recomputes the popup size and positions. |
| 1361 | * Also updates "popup_visible". |
| 1362 | * Also marks window lines for redrawing. |
| 1363 | */ |
| 1364 | void |
| 1365 | may_update_popup_mask(int type) |
| 1366 | { |
| 1367 | win_T *wp; |
| 1368 | short *mask; |
| 1369 | int line, col; |
| 1370 | int redraw_all = FALSE; |
| 1371 | |
| 1372 | // Need to recompute when switching tabs. |
| 1373 | // Also recompute when the type is CLEAR or NOT_VALID, something basic |
| 1374 | // (such as the screen size) must have changed. |
| 1375 | if (popup_mask_tab != curtab || type >= NOT_VALID) |
| 1376 | { |
| 1377 | popup_mask_refresh = TRUE; |
| 1378 | redraw_all = TRUE; |
| 1379 | } |
| 1380 | if (!popup_mask_refresh) |
| 1381 | { |
| 1382 | // Check if any buffer has changed. |
| 1383 | for (wp = first_popupwin; wp != NULL; wp = wp->w_next) |
| 1384 | if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 1385 | popup_mask_refresh = TRUE; |
| 1386 | for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next) |
| 1387 | if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 1388 | popup_mask_refresh = TRUE; |
| 1389 | if (!popup_mask_refresh) |
| 1390 | return; |
| 1391 | } |
| 1392 | |
| 1393 | // Need to update the mask, something has changed. |
| 1394 | popup_mask_refresh = FALSE; |
| 1395 | popup_mask_tab = curtab; |
| 1396 | popup_visible = FALSE; |
| 1397 | |
| 1398 | // If redrawing everything, just update "popup_mask". |
| 1399 | // If redrawing only what is needed, update "popup_mask_next" and then |
| 1400 | // compare with "popup_mask" to see what changed. |
| 1401 | if (type >= SOME_VALID) |
| 1402 | mask = popup_mask; |
| 1403 | else |
| 1404 | mask = popup_mask_next; |
| 1405 | vim_memset(mask, 0, screen_Rows * screen_Columns * sizeof(short)); |
| 1406 | |
| 1407 | // Find the window with the lowest zindex that hasn't been handled yet, |
| 1408 | // so that the window with a higher zindex overwrites the value in |
| 1409 | // popup_mask. |
| 1410 | popup_reset_handled(); |
| 1411 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 1412 | { |
| 1413 | popup_visible = TRUE; |
| 1414 | |
| 1415 | // Recompute the position if the text changed. |
| 1416 | if (redraw_all |
| 1417 | || wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer)) |
| 1418 | popup_adjust_position(wp); |
| 1419 | |
| 1420 | for (line = wp->w_winrow; |
| 1421 | line < wp->w_winrow + popup_height(wp) |
| 1422 | && line < screen_Rows; ++line) |
| 1423 | for (col = wp->w_wincol; |
| 1424 | col < wp->w_wincol + popup_width(wp) |
| 1425 | && col < screen_Columns; ++col) |
| 1426 | mask[line * screen_Columns + col] = wp->w_zindex; |
| 1427 | } |
| 1428 | |
| 1429 | // Only check which lines are to be updated if not already |
| 1430 | // updating all lines. |
| 1431 | if (mask == popup_mask_next) |
| 1432 | for (line = 0; line < screen_Rows; ++line) |
| 1433 | { |
| 1434 | int col_done = 0; |
| 1435 | |
| 1436 | for (col = 0; col < screen_Columns; ++col) |
| 1437 | { |
| 1438 | int off = line * screen_Columns + col; |
| 1439 | |
| 1440 | if (popup_mask[off] != popup_mask_next[off]) |
| 1441 | { |
| 1442 | popup_mask[off] = popup_mask_next[off]; |
| 1443 | |
| 1444 | if (line >= cmdline_row) |
| 1445 | { |
| 1446 | // the command line needs to be cleared if text below |
| 1447 | // the popup is now visible. |
| 1448 | if (!msg_scrolled && popup_mask_next[off] == 0) |
| 1449 | clear_cmdline = TRUE; |
| 1450 | } |
| 1451 | else if (col >= col_done) |
| 1452 | { |
| 1453 | linenr_T lnum; |
| 1454 | int line_cp = line; |
| 1455 | int col_cp = col; |
| 1456 | |
| 1457 | // The screen position "line" / "col" needs to be |
| 1458 | // redrawn. Figure out what window that is and update |
| 1459 | // w_redraw_top and w_redr_bot. Only needs to be done |
| 1460 | // once for each window line. |
| 1461 | wp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP); |
| 1462 | if (wp != NULL) |
| 1463 | { |
| 1464 | if (line_cp >= wp->w_height) |
| 1465 | // In (or below) status line |
| 1466 | wp->w_redr_status = TRUE; |
| 1467 | // compute the position in the buffer line from the |
| 1468 | // position on the screen |
| 1469 | else if (mouse_comp_pos(wp, &line_cp, &col_cp, |
| 1470 | &lnum)) |
| 1471 | // past bottom |
| 1472 | wp->w_redr_status = TRUE; |
| 1473 | else |
| 1474 | redrawWinline(wp, lnum); |
| 1475 | |
| 1476 | // This line is going to be redrawn, no need to |
| 1477 | // check until the right side of the window. |
| 1478 | col_done = wp->w_wincol + wp->w_width - 1; |
| 1479 | } |
| 1480 | } |
| 1481 | } |
| 1482 | } |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | /* |
| 1487 | * Return a string of "len" spaces in IObuff. |
| 1488 | */ |
| 1489 | static char_u * |
| 1490 | get_spaces(int len) |
| 1491 | { |
| 1492 | vim_memset(IObuff, ' ', (size_t)len); |
| 1493 | IObuff[len] = NUL; |
| 1494 | return IObuff; |
| 1495 | } |
| 1496 | |
| 1497 | /* |
| 1498 | * Update popup windows. They are drawn on top of normal windows. |
| 1499 | * "win_update" is called for each popup window, lowest zindex first. |
| 1500 | */ |
| 1501 | void |
| 1502 | update_popups(void (*win_update)(win_T *wp)) |
| 1503 | { |
| 1504 | win_T *wp; |
| 1505 | int top_off; |
| 1506 | int left_off; |
| 1507 | int total_width; |
| 1508 | int total_height; |
| 1509 | int popup_attr; |
| 1510 | int border_attr[4]; |
| 1511 | int border_char[8]; |
| 1512 | char_u buf[MB_MAXBYTES]; |
| 1513 | int row; |
| 1514 | int i; |
| 1515 | |
| 1516 | // Find the window with the lowest zindex that hasn't been updated yet, |
| 1517 | // so that the window with a higher zindex is drawn later, thus goes on |
| 1518 | // top. |
| 1519 | popup_reset_handled(); |
| 1520 | while ((wp = find_next_popup(TRUE)) != NULL) |
| 1521 | { |
| 1522 | // This drawing uses the zindex of the popup window, so that it's on |
| 1523 | // top of the text but doesn't draw when another popup with higher |
| 1524 | // zindex is on top of the character. |
| 1525 | screen_zindex = wp->w_zindex; |
| 1526 | |
| 1527 | // adjust w_winrow and w_wincol for border and padding, since |
| 1528 | // win_update() doesn't handle them. |
| 1529 | top_off = wp->w_popup_padding[0] + wp->w_popup_border[0]; |
| 1530 | left_off = wp->w_popup_padding[3] + wp->w_popup_border[3]; |
| 1531 | wp->w_winrow += top_off; |
| 1532 | wp->w_wincol += left_off; |
| 1533 | |
| 1534 | // Draw the popup text. |
| 1535 | win_update(wp); |
| 1536 | |
| 1537 | wp->w_winrow -= top_off; |
| 1538 | wp->w_wincol -= left_off; |
| 1539 | |
| 1540 | total_width = wp->w_popup_border[3] + wp->w_popup_padding[3] |
| 1541 | + wp->w_width + wp->w_popup_padding[1] + wp->w_popup_border[1]; |
| 1542 | total_height = wp->w_popup_border[0] + wp->w_popup_padding[0] |
| 1543 | + wp->w_height + wp->w_popup_padding[2] + wp->w_popup_border[2]; |
| 1544 | popup_attr = get_wcr_attr(wp); |
| 1545 | |
| 1546 | // We can only use these line drawing characters when 'encoding' is |
| 1547 | // "utf-8" and 'ambiwidth' is "single". |
| 1548 | if (enc_utf8 && *p_ambw == 's') |
| 1549 | { |
| 1550 | border_char[0] = border_char[2] = 0x2550; |
| 1551 | border_char[1] = border_char[3] = 0x2551; |
| 1552 | border_char[4] = 0x2554; |
| 1553 | border_char[5] = 0x2557; |
| 1554 | border_char[6] = 0x255d; |
| 1555 | border_char[7] = 0x255a; |
| 1556 | } |
| 1557 | else |
| 1558 | { |
| 1559 | border_char[0] = border_char[2] = '-'; |
| 1560 | border_char[1] = border_char[3] = '|'; |
| 1561 | for (i = 4; i < 8; ++i) |
| 1562 | border_char[i] = '+'; |
| 1563 | } |
| 1564 | for (i = 0; i < 8; ++i) |
| 1565 | if (wp->w_border_char[i] != 0) |
| 1566 | border_char[i] = wp->w_border_char[i]; |
| 1567 | |
| 1568 | for (i = 0; i < 4; ++i) |
| 1569 | { |
| 1570 | border_attr[i] = popup_attr; |
| 1571 | if (wp->w_border_highlight[i] != NULL) |
| 1572 | border_attr[i] = syn_name2attr(wp->w_border_highlight[i]); |
| 1573 | } |
| 1574 | |
| 1575 | if (wp->w_popup_border[0] > 0) |
| 1576 | { |
| 1577 | // top border |
| 1578 | screen_fill(wp->w_winrow, wp->w_winrow + 1, |
| 1579 | wp->w_wincol, |
| 1580 | wp->w_wincol + total_width, |
| 1581 | wp->w_popup_border[3] != 0 |
| 1582 | ? border_char[4] : border_char[0], |
| 1583 | border_char[0], border_attr[0]); |
| 1584 | if (wp->w_popup_border[1] > 0) |
| 1585 | { |
| 1586 | buf[mb_char2bytes(border_char[5], buf)] = NUL; |
| 1587 | screen_puts(buf, wp->w_winrow, |
| 1588 | wp->w_wincol + total_width - 1, border_attr[1]); |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | if (wp->w_popup_padding[0] > 0) |
| 1593 | { |
| 1594 | // top padding |
| 1595 | row = wp->w_winrow + wp->w_popup_border[0]; |
| 1596 | screen_fill(row, row + wp->w_popup_padding[0], |
| 1597 | wp->w_wincol + wp->w_popup_border[3], |
| 1598 | wp->w_wincol + total_width - wp->w_popup_border[1], |
| 1599 | ' ', ' ', popup_attr); |
| 1600 | } |
| 1601 | |
| 1602 | for (row = wp->w_winrow + wp->w_popup_border[0]; |
| 1603 | row < wp->w_winrow + total_height - wp->w_popup_border[2]; |
| 1604 | ++row) |
| 1605 | { |
| 1606 | // left border |
| 1607 | if (wp->w_popup_border[3] > 0) |
| 1608 | { |
| 1609 | buf[mb_char2bytes(border_char[3], buf)] = NUL; |
| 1610 | screen_puts(buf, row, wp->w_wincol, border_attr[3]); |
| 1611 | } |
| 1612 | // left padding |
| 1613 | if (wp->w_popup_padding[3] > 0) |
| 1614 | screen_puts(get_spaces(wp->w_popup_padding[3]), row, |
| 1615 | wp->w_wincol + wp->w_popup_border[3], popup_attr); |
| 1616 | // right border |
| 1617 | if (wp->w_popup_border[1] > 0) |
| 1618 | { |
| 1619 | buf[mb_char2bytes(border_char[1], buf)] = NUL; |
| 1620 | screen_puts(buf, row, |
| 1621 | wp->w_wincol + total_width - 1, border_attr[1]); |
| 1622 | } |
| 1623 | // right padding |
| 1624 | if (wp->w_popup_padding[1] > 0) |
| 1625 | screen_puts(get_spaces(wp->w_popup_padding[1]), row, |
| 1626 | wp->w_wincol + wp->w_popup_border[3] |
| 1627 | + wp->w_popup_padding[3] + wp->w_width, popup_attr); |
| 1628 | } |
| 1629 | |
| 1630 | if (wp->w_popup_padding[2] > 0) |
| 1631 | { |
| 1632 | // bottom padding |
| 1633 | row = wp->w_winrow + wp->w_popup_border[0] |
| 1634 | + wp->w_popup_padding[0] + wp->w_height; |
| 1635 | screen_fill(row, row + wp->w_popup_padding[2], |
| 1636 | wp->w_wincol + wp->w_popup_border[3], |
| 1637 | wp->w_wincol + total_width - wp->w_popup_border[1], |
| 1638 | ' ', ' ', popup_attr); |
| 1639 | } |
| 1640 | |
| 1641 | if (wp->w_popup_border[2] > 0) |
| 1642 | { |
| 1643 | // bottom border |
| 1644 | row = wp->w_winrow + total_height - 1; |
| 1645 | screen_fill(row , row + 1, |
| 1646 | wp->w_wincol, |
| 1647 | wp->w_wincol + total_width, |
| 1648 | wp->w_popup_border[3] != 0 |
| 1649 | ? border_char[7] : border_char[2], |
| 1650 | border_char[2], border_attr[2]); |
| 1651 | if (wp->w_popup_border[1] > 0) |
| 1652 | { |
| 1653 | buf[mb_char2bytes(border_char[6], buf)] = NUL; |
| 1654 | screen_puts(buf, row, |
| 1655 | wp->w_wincol + total_width - 1, border_attr[2]); |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | // Back to the normal zindex. |
| 1660 | screen_zindex = 0; |
| 1661 | } |
| 1662 | } |
| 1663 | |
Bram Moolenaar | 4d784b2 | 2019-05-25 19:51:39 +0200 | [diff] [blame] | 1664 | #endif // FEAT_TEXT_PROP |