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