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