2019-05-25 19:51:39 +02:00
|
|
|
/* vi:set ts=8 sts=4 sw=4 noet:
|
|
|
|
*
|
|
|
|
* VIM - Vi IMproved by Bram Moolenaar
|
|
|
|
*
|
|
|
|
* Do ":help uganda" in Vim to read a list of people who contributed.
|
|
|
|
* Do ":help credits" in Vim to see a list of people who contributed.
|
|
|
|
* See README.txt for an overview of the Vim source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of popup windows. See ":help popup".
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "vim.h"
|
|
|
|
|
2019-07-18 21:43:07 +02:00
|
|
|
#if defined(FEAT_TEXT_PROP) || defined(PROTO)
|
2019-05-25 19:51:39 +02:00
|
|
|
|
2019-05-30 21:24:26 +02:00
|
|
|
typedef struct {
|
|
|
|
char *pp_name;
|
|
|
|
poppos_T pp_val;
|
|
|
|
} poppos_entry_T;
|
|
|
|
|
|
|
|
static poppos_entry_T poppos_entries[] = {
|
|
|
|
{"botleft", POPPOS_BOTLEFT},
|
|
|
|
{"topleft", POPPOS_TOPLEFT},
|
|
|
|
{"botright", POPPOS_BOTRIGHT},
|
|
|
|
{"topright", POPPOS_TOPRIGHT},
|
|
|
|
{"center", POPPOS_CENTER}
|
|
|
|
};
|
|
|
|
|
2019-05-30 19:25:06 +02:00
|
|
|
/*
|
2019-06-02 16:51:21 +02:00
|
|
|
* Get option value for "key", which is "line" or "col".
|
2019-05-30 19:25:06 +02:00
|
|
|
* Handles "cursor+N" and "cursor-N".
|
|
|
|
*/
|
|
|
|
static int
|
2019-05-30 21:24:26 +02:00
|
|
|
popup_options_one(dict_T *dict, char_u *key)
|
2019-05-30 19:25:06 +02:00
|
|
|
{
|
|
|
|
dictitem_T *di;
|
|
|
|
char_u *val;
|
|
|
|
char_u *s;
|
|
|
|
char_u *endp;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
di = dict_find(dict, key, -1);
|
|
|
|
if (di == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
val = tv_get_string(&di->di_tv);
|
|
|
|
if (STRNCMP(val, "cursor", 6) != 0)
|
2019-06-02 16:51:21 +02:00
|
|
|
return dict_get_number_check(dict, key);
|
2019-05-30 19:25:06 +02:00
|
|
|
|
|
|
|
setcursor_mayforce(TRUE);
|
|
|
|
s = val + 6;
|
|
|
|
if (*s != NUL)
|
|
|
|
{
|
2019-06-02 16:51:21 +02:00
|
|
|
endp = s;
|
|
|
|
if (*skipwhite(s) == '+' || *skipwhite(s) == '-')
|
|
|
|
n = strtol((char *)s, (char **)&endp, 10);
|
2019-05-30 19:25:06 +02:00
|
|
|
if (endp != NULL && *skipwhite(endp) != NUL)
|
|
|
|
{
|
|
|
|
semsg(_(e_invexpr2), val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STRCMP(key, "line") == 0)
|
|
|
|
n = screen_screenrow() + 1 + n;
|
|
|
|
else // "col"
|
|
|
|
n = screen_screencol() + 1 + n;
|
|
|
|
|
|
|
|
if (n < 1)
|
|
|
|
n = 1;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2019-05-30 21:24:26 +02:00
|
|
|
static void
|
|
|
|
get_pos_options(win_T *wp, dict_T *dict)
|
|
|
|
{
|
|
|
|
char_u *str;
|
|
|
|
int nr;
|
2019-06-28 04:06:50 +02:00
|
|
|
dictitem_T *di;
|
2019-05-30 21:24:26 +02:00
|
|
|
|
|
|
|
nr = popup_options_one(dict, (char_u *)"line");
|
|
|
|
if (nr > 0)
|
|
|
|
wp->w_wantline = nr;
|
|
|
|
nr = popup_options_one(dict, (char_u *)"col");
|
|
|
|
if (nr > 0)
|
|
|
|
wp->w_wantcol = nr;
|
|
|
|
|
2019-06-28 04:06:50 +02:00
|
|
|
di = dict_find(dict, (char_u *)"fixed", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0;
|
2019-06-02 14:49:56 +02:00
|
|
|
|
2019-05-30 21:24:26 +02:00
|
|
|
str = dict_get_string(dict, (char_u *)"pos", FALSE);
|
|
|
|
if (str != NULL)
|
|
|
|
{
|
|
|
|
for (nr = 0;
|
|
|
|
nr < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
|
|
|
|
++nr)
|
|
|
|
if (STRCMP(str, poppos_entries[nr].pp_name) == 0)
|
|
|
|
{
|
|
|
|
wp->w_popup_pos = poppos_entries[nr].pp_val;
|
|
|
|
nr = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nr != -1)
|
|
|
|
semsg(_(e_invarg2), str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-01 20:16:48 +02:00
|
|
|
static void
|
2019-06-16 22:54:14 +02:00
|
|
|
set_padding_border(dict_T *dict, int *array, char *name, int max_val)
|
2019-06-01 20:16:48 +02:00
|
|
|
{
|
|
|
|
dictitem_T *di;
|
|
|
|
|
|
|
|
di = dict_find(dict, (char_u *)name, -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
if (di->di_tv.v_type != VAR_LIST)
|
|
|
|
emsg(_(e_listreq));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list_T *list = di->di_tv.vval.v_list;
|
|
|
|
listitem_T *li;
|
|
|
|
int i;
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
array[i] = 1;
|
|
|
|
if (list != NULL)
|
|
|
|
for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len;
|
|
|
|
++i, li = li->li_next)
|
|
|
|
{
|
|
|
|
nr = (int)tv_get_number(&li->li_tv);
|
|
|
|
if (nr >= 0)
|
|
|
|
array[i] = nr > max_val ? max_val : nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 19:53:44 +02:00
|
|
|
/*
|
|
|
|
* Used when popup options contain "moved": set default moved values.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_moved_values(win_T *wp)
|
|
|
|
{
|
|
|
|
wp->w_popup_curwin = curwin;
|
|
|
|
wp->w_popup_lnum = curwin->w_cursor.lnum;
|
|
|
|
wp->w_popup_mincol = curwin->w_cursor.col;
|
|
|
|
wp->w_popup_maxcol = curwin->w_cursor.col;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used when popup options contain "moved" with "word" or "WORD".
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_moved_columns(win_T *wp, int flags)
|
|
|
|
{
|
|
|
|
char_u *ptr;
|
|
|
|
int len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR);
|
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
wp->w_popup_mincol = (int)(ptr - ml_get_curline());
|
|
|
|
wp->w_popup_maxcol = wp->w_popup_mincol + len - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-07 18:28:14 +02:00
|
|
|
/*
|
|
|
|
* Used when popup options contain "mousemoved": set default moved values.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_mousemoved_values(win_T *wp)
|
|
|
|
{
|
|
|
|
wp->w_popup_mouse_row = mouse_row;
|
|
|
|
wp->w_popup_mouse_mincol = mouse_col;
|
|
|
|
wp->w_popup_mouse_maxcol = mouse_col;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used when popup options contain "moved" with "word" or "WORD".
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_mousemoved_columns(win_T *wp, int flags)
|
|
|
|
{
|
2019-07-10 21:55:54 +02:00
|
|
|
win_T *textwp;
|
2019-07-07 18:28:14 +02:00
|
|
|
char_u *text;
|
|
|
|
int col;
|
2019-07-10 21:55:54 +02:00
|
|
|
pos_T pos;
|
|
|
|
colnr_T mcol;
|
2019-07-07 18:28:14 +02:00
|
|
|
|
|
|
|
if (find_word_under_cursor(mouse_row, mouse_col, TRUE, flags,
|
2019-07-10 21:55:54 +02:00
|
|
|
&textwp, &pos.lnum, &text, NULL, &col) == OK)
|
2019-07-07 18:28:14 +02:00
|
|
|
{
|
2019-07-10 21:55:54 +02:00
|
|
|
// convert text column to mouse column
|
|
|
|
pos.col = col;
|
|
|
|
pos.coladd = 0;
|
|
|
|
getvcol(textwp, &pos, &mcol, NULL, NULL);
|
|
|
|
wp->w_popup_mouse_mincol = mcol;
|
|
|
|
|
2019-07-12 13:59:20 +02:00
|
|
|
pos.col = col + (colnr_T)STRLEN(text) - 1;
|
2019-07-10 21:55:54 +02:00
|
|
|
getvcol(textwp, &pos, NULL, NULL, &mcol);
|
|
|
|
wp->w_popup_mouse_maxcol = mcol;
|
2019-07-07 18:28:14 +02:00
|
|
|
vim_free(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 23:59:52 +02:00
|
|
|
/*
|
|
|
|
* Return TRUE if "row"/"col" is on the border of the popup.
|
|
|
|
* The values are relative to the top-left corner.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
popup_on_border(win_T *wp, int row, int col)
|
|
|
|
{
|
|
|
|
return (row == 0 && wp->w_popup_border[0] > 0)
|
|
|
|
|| (row == popup_height(wp) - 1 && wp->w_popup_border[2] > 0)
|
|
|
|
|| (col == 0 && wp->w_popup_border[3] > 0)
|
|
|
|
|| (col == popup_width(wp) - 1 && wp->w_popup_border[1] > 0);
|
|
|
|
}
|
|
|
|
|
2019-06-30 18:07:00 +02:00
|
|
|
/*
|
|
|
|
* Return TRUE if "row"/"col" is on the "X" button of the popup.
|
|
|
|
* The values are relative to the top-left corner.
|
|
|
|
* Caller should check w_popup_close is POPCLOSE_BUTTON.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
popup_on_X_button(win_T *wp, int row, int col)
|
|
|
|
{
|
|
|
|
return row == 0 && col == popup_width(wp) - 1;
|
|
|
|
}
|
|
|
|
|
2019-06-13 23:59:52 +02:00
|
|
|
// Values set when dragging a popup window starts.
|
|
|
|
static int drag_start_row;
|
|
|
|
static int drag_start_col;
|
|
|
|
static int drag_start_wantline;
|
|
|
|
static int drag_start_wantcol;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mouse down on border of popup window: start dragging it.
|
|
|
|
* Uses mouse_col and mouse_row.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_start_drag(win_T *wp)
|
|
|
|
{
|
|
|
|
drag_start_row = mouse_row;
|
|
|
|
drag_start_col = mouse_col;
|
|
|
|
// TODO: handle using different corner
|
|
|
|
if (wp->w_wantline == 0)
|
|
|
|
drag_start_wantline = wp->w_winrow + 1;
|
|
|
|
else
|
|
|
|
drag_start_wantline = wp->w_wantline;
|
|
|
|
if (wp->w_wantcol == 0)
|
|
|
|
drag_start_wantcol = wp->w_wincol + 1;
|
|
|
|
else
|
|
|
|
drag_start_wantcol = wp->w_wantcol;
|
2019-06-15 21:46:30 +02:00
|
|
|
|
|
|
|
// Stop centering the popup
|
|
|
|
if (wp->w_popup_pos == POPPOS_CENTER)
|
|
|
|
wp->w_popup_pos = POPPOS_TOPLEFT;
|
2019-06-13 23:59:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mouse moved while dragging a popup window: adjust the window popup position.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_drag(win_T *wp)
|
|
|
|
{
|
|
|
|
// The popup may be closed before dragging stops.
|
|
|
|
if (!win_valid_popup(wp))
|
|
|
|
return;
|
|
|
|
|
|
|
|
wp->w_wantline = drag_start_wantline + (mouse_row - drag_start_row);
|
|
|
|
if (wp->w_wantline < 1)
|
|
|
|
wp->w_wantline = 1;
|
|
|
|
if (wp->w_wantline > Rows)
|
|
|
|
wp->w_wantline = Rows;
|
|
|
|
wp->w_wantcol = drag_start_wantcol + (mouse_col - drag_start_col);
|
|
|
|
if (wp->w_wantcol < 1)
|
|
|
|
wp->w_wantcol = 1;
|
|
|
|
if (wp->w_wantcol > Columns)
|
|
|
|
wp->w_wantcol = Columns;
|
|
|
|
|
|
|
|
popup_adjust_position(wp);
|
|
|
|
}
|
2019-06-12 22:42:41 +02:00
|
|
|
|
2019-06-29 07:41:35 +02:00
|
|
|
/*
|
|
|
|
* Set w_firstline to match the current "wp->w_topline".
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_set_firstline(win_T *wp)
|
|
|
|
{
|
|
|
|
int height = wp->w_height;
|
|
|
|
|
|
|
|
wp->w_firstline = wp->w_topline;
|
|
|
|
popup_adjust_position(wp);
|
|
|
|
|
|
|
|
// we don't want the popup to get smaller, decrement the first line
|
|
|
|
// until it doesn't
|
|
|
|
while (wp->w_firstline > 1 && wp->w_height < height)
|
|
|
|
{
|
|
|
|
--wp->w_firstline;
|
|
|
|
popup_adjust_position(wp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle a click in a popup window, if it is in the scrollbar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_handle_scrollbar_click(win_T *wp, int row, int col)
|
|
|
|
{
|
|
|
|
int height = popup_height(wp);
|
|
|
|
int old_topline = wp->w_topline;
|
|
|
|
|
|
|
|
if (wp->w_has_scrollbar == 0)
|
|
|
|
return;
|
|
|
|
if (row >= wp->w_popup_border[0]
|
|
|
|
&& row < height - wp->w_popup_border[2]
|
2019-07-12 16:35:34 +02:00
|
|
|
&& col == popup_width(wp) - wp->w_popup_border[1] - 1)
|
2019-06-29 07:41:35 +02:00
|
|
|
{
|
|
|
|
if (row >= height / 2)
|
|
|
|
{
|
|
|
|
// Click in lower half, scroll down.
|
|
|
|
if (wp->w_topline < wp->w_buffer->b_ml.ml_line_count)
|
|
|
|
++wp->w_topline;
|
|
|
|
}
|
|
|
|
else if (wp->w_topline > 1)
|
|
|
|
// click on upper half, scroll up.
|
|
|
|
--wp->w_topline;
|
|
|
|
if (wp->w_topline != old_topline)
|
|
|
|
{
|
|
|
|
popup_set_firstline(wp);
|
|
|
|
redraw_win_later(wp, NOT_VALID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 22:42:41 +02:00
|
|
|
#if defined(FEAT_TIMERS)
|
|
|
|
static void
|
|
|
|
popup_add_timeout(win_T *wp, int time)
|
|
|
|
{
|
|
|
|
char_u cbbuf[50];
|
|
|
|
char_u *ptr = cbbuf;
|
|
|
|
typval_T tv;
|
|
|
|
|
|
|
|
vim_snprintf((char *)cbbuf, sizeof(cbbuf),
|
|
|
|
"{_ -> popup_close(%d)}", wp->w_id);
|
|
|
|
if (get_lambda_tv(&ptr, &tv, TRUE) == OK)
|
|
|
|
{
|
|
|
|
wp->w_popup_timer = create_timer(time, 0);
|
|
|
|
wp->w_popup_timer->tr_callback = get_callback(&tv);
|
|
|
|
clear_tv(&tv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-25 19:51:39 +02:00
|
|
|
/*
|
2019-06-16 22:54:14 +02:00
|
|
|
* Shared between popup_create() and f_popup_move().
|
2019-05-25 19:51:39 +02:00
|
|
|
*/
|
|
|
|
static void
|
2019-06-16 22:54:14 +02:00
|
|
|
apply_move_options(win_T *wp, dict_T *d)
|
2019-05-25 19:51:39 +02:00
|
|
|
{
|
2019-06-16 22:54:14 +02:00
|
|
|
int nr;
|
|
|
|
|
|
|
|
if ((nr = dict_get_number(d, (char_u *)"minwidth")) > 0)
|
|
|
|
wp->w_minwidth = nr;
|
|
|
|
if ((nr = dict_get_number(d, (char_u *)"minheight")) > 0)
|
|
|
|
wp->w_minheight = nr;
|
|
|
|
if ((nr = dict_get_number(d, (char_u *)"maxwidth")) > 0)
|
|
|
|
wp->w_maxwidth = nr;
|
|
|
|
if ((nr = dict_get_number(d, (char_u *)"maxheight")) > 0)
|
|
|
|
wp->w_maxheight = nr;
|
|
|
|
get_pos_options(wp, d);
|
|
|
|
}
|
|
|
|
|
2019-07-07 18:28:14 +02:00
|
|
|
static void
|
|
|
|
handle_moved_argument(win_T *wp, dictitem_T *di, int mousemoved)
|
|
|
|
{
|
|
|
|
if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
|
|
|
|
{
|
|
|
|
char_u *s = di->di_tv.vval.v_string;
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (STRCMP(s, "word") == 0)
|
|
|
|
flags = FIND_IDENT | FIND_STRING;
|
|
|
|
else if (STRCMP(s, "WORD") == 0)
|
|
|
|
flags = FIND_STRING;
|
|
|
|
else if (STRCMP(s, "expr") == 0)
|
|
|
|
flags = FIND_IDENT | FIND_STRING | FIND_EVAL;
|
|
|
|
else if (STRCMP(s, "any") != 0)
|
|
|
|
semsg(_(e_invarg2), s);
|
|
|
|
if (flags != 0)
|
|
|
|
{
|
|
|
|
if (mousemoved)
|
|
|
|
set_mousemoved_columns(wp, flags);
|
|
|
|
else
|
|
|
|
set_moved_columns(wp, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (di->di_tv.v_type == VAR_LIST
|
|
|
|
&& di->di_tv.vval.v_list != NULL
|
|
|
|
&& di->di_tv.vval.v_list->lv_len == 2)
|
|
|
|
{
|
|
|
|
list_T *l = di->di_tv.vval.v_list;
|
|
|
|
int mincol = tv_get_number(&l->lv_first->li_tv);
|
|
|
|
int maxcol = tv_get_number(&l->lv_first->li_next->li_tv);
|
|
|
|
|
|
|
|
if (mousemoved)
|
|
|
|
{
|
|
|
|
wp->w_popup_mouse_mincol = mincol;
|
|
|
|
wp->w_popup_mouse_maxcol = maxcol;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wp->w_popup_mincol = mincol;
|
|
|
|
wp->w_popup_maxcol = maxcol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
semsg(_(e_invarg2), tv_get_string(&di->di_tv));
|
|
|
|
}
|
|
|
|
|
2019-06-26 05:13:57 +02:00
|
|
|
static void
|
|
|
|
check_highlight(dict_T *dict, char *name, char_u **pval)
|
|
|
|
{
|
|
|
|
dictitem_T *di;
|
|
|
|
char_u *str;
|
|
|
|
|
|
|
|
di = dict_find(dict, (char_u *)name, -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
if (di->di_tv.v_type != VAR_STRING)
|
|
|
|
semsg(_(e_invargval), name);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str = tv_get_string(&di->di_tv);
|
|
|
|
if (*str != NUL)
|
|
|
|
*pval = vim_strsave(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 21:43:07 +02:00
|
|
|
/*
|
|
|
|
* Scroll to show the line with the cursor. This assumes lines don't wrap.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
popup_show_curline(win_T *wp)
|
|
|
|
{
|
|
|
|
if (wp->w_cursor.lnum < wp->w_topline)
|
|
|
|
wp->w_topline = wp->w_cursor.lnum;
|
|
|
|
else if (wp->w_cursor.lnum >= wp->w_botline)
|
|
|
|
wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1;
|
2019-07-20 16:51:19 +02:00
|
|
|
|
|
|
|
// Don't use "firstline" now.
|
|
|
|
wp->w_firstline = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the sign group name for window "wp".
|
|
|
|
* Returns a pointer to a static buffer, overwritten on the next call.
|
|
|
|
*/
|
|
|
|
static char_u *
|
|
|
|
popup_get_sign_name(win_T *wp)
|
|
|
|
{
|
|
|
|
static char buf[30];
|
|
|
|
|
|
|
|
vim_snprintf(buf, sizeof(buf), "popup-%d", wp->w_id);
|
|
|
|
return (char_u *)buf;
|
2019-07-18 21:43:07 +02:00
|
|
|
}
|
|
|
|
|
2019-07-18 13:46:42 +02:00
|
|
|
/*
|
|
|
|
* Highlight the line with the cursor.
|
|
|
|
* Also scrolls the text to put the cursor line in view.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
popup_highlight_curline(win_T *wp)
|
|
|
|
{
|
2019-07-20 16:51:19 +02:00
|
|
|
int sign_id = 0;
|
|
|
|
char_u *sign_name = popup_get_sign_name(wp);
|
2019-07-18 13:46:42 +02:00
|
|
|
|
2019-07-20 16:51:19 +02:00
|
|
|
buf_delete_signs(wp->w_buffer, (char_u *)"popupmenu");
|
2019-07-18 13:46:42 +02:00
|
|
|
|
|
|
|
if ((wp->w_popup_flags & POPF_CURSORLINE) != 0)
|
|
|
|
{
|
2019-07-18 21:43:07 +02:00
|
|
|
popup_show_curline(wp);
|
2019-07-18 13:46:42 +02:00
|
|
|
|
2019-07-20 16:51:19 +02:00
|
|
|
if (!sign_exists_by_name(sign_name))
|
|
|
|
{
|
|
|
|
char *linehl = "PopupSelected";
|
|
|
|
|
|
|
|
if (syn_name2id((char_u *)linehl) == 0)
|
|
|
|
linehl = "PmenuSel";
|
|
|
|
sign_define_by_name(sign_name, NULL,
|
|
|
|
(char_u *)linehl, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
sign_place(&sign_id, (char_u *)"popupmenu", sign_name,
|
|
|
|
wp->w_buffer, wp->w_cursor.lnum, SIGN_DEF_PRIO);
|
|
|
|
redraw_win_later(wp, NOT_VALID);
|
2019-07-18 13:46:42 +02:00
|
|
|
}
|
2019-07-20 16:51:19 +02:00
|
|
|
else
|
|
|
|
sign_undefine_by_name(sign_name, FALSE);
|
2019-07-18 13:46:42 +02:00
|
|
|
}
|
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
/*
|
|
|
|
* Shared between popup_create() and f_popup_setoptions().
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
apply_general_options(win_T *wp, dict_T *dict)
|
|
|
|
{
|
|
|
|
dictitem_T *di;
|
2019-05-30 22:07:36 +02:00
|
|
|
int nr;
|
|
|
|
char_u *str;
|
2019-05-27 21:54:10 +02:00
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
// TODO: flip
|
2019-05-27 21:54:10 +02:00
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
di = dict_find(dict, (char_u *)"firstline", -1);
|
2019-06-12 22:42:41 +02:00
|
|
|
if (di != NULL)
|
2019-06-16 22:54:14 +02:00
|
|
|
wp->w_firstline = dict_get_number(dict, (char_u *)"firstline");
|
|
|
|
if (wp->w_firstline < 1)
|
|
|
|
wp->w_firstline = 1;
|
2019-06-01 17:13:36 +02:00
|
|
|
|
2019-06-25 05:15:58 +02:00
|
|
|
di = dict_find(dict, (char_u *)"scrollbar", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
wp->w_want_scrollbar = dict_get_number(dict, (char_u *)"scrollbar");
|
|
|
|
|
2019-06-16 20:09:10 +02:00
|
|
|
str = dict_get_string(dict, (char_u *)"title", FALSE);
|
|
|
|
if (str != NULL)
|
|
|
|
{
|
|
|
|
vim_free(wp->w_popup_title);
|
|
|
|
wp->w_popup_title = vim_strsave(str);
|
|
|
|
}
|
|
|
|
|
2019-05-30 22:07:36 +02:00
|
|
|
di = dict_find(dict, (char_u *)"wrap", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
nr = dict_get_number(dict, (char_u *)"wrap");
|
|
|
|
wp->w_p_wrap = nr != 0;
|
|
|
|
}
|
2019-06-01 17:13:36 +02:00
|
|
|
|
2019-06-15 21:46:30 +02:00
|
|
|
di = dict_find(dict, (char_u *)"drag", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
wp->w_popup_drag = dict_get_number(dict, (char_u *)"drag");
|
2019-06-13 23:59:52 +02:00
|
|
|
|
2019-06-30 18:07:00 +02:00
|
|
|
di = dict_find(dict, (char_u *)"close", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
int ok = TRUE;
|
|
|
|
|
|
|
|
if (di->di_tv.v_type == VAR_STRING && di->di_tv.vval.v_string != NULL)
|
|
|
|
{
|
|
|
|
char_u *s = di->di_tv.vval.v_string;
|
|
|
|
|
|
|
|
if (STRCMP(s, "none") == 0)
|
|
|
|
wp->w_popup_close = POPCLOSE_NONE;
|
|
|
|
else if (STRCMP(s, "button") == 0)
|
|
|
|
wp->w_popup_close = POPCLOSE_BUTTON;
|
|
|
|
else if (STRCMP(s, "click") == 0)
|
|
|
|
wp->w_popup_close = POPCLOSE_CLICK;
|
|
|
|
else
|
|
|
|
ok = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok = FALSE;
|
|
|
|
if (!ok)
|
|
|
|
semsg(_(e_invargNval), "close", tv_get_string(&di->di_tv));
|
|
|
|
}
|
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
str = dict_get_string(dict, (char_u *)"highlight", FALSE);
|
|
|
|
if (str != NULL)
|
|
|
|
set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
|
|
|
|
str, OPT_FREE|OPT_LOCAL, 0);
|
2019-06-01 20:16:48 +02:00
|
|
|
|
2019-07-20 16:51:19 +02:00
|
|
|
set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1,
|
|
|
|
(char_u *)"no", OPT_FREE|OPT_LOCAL, 0);
|
2019-06-16 22:54:14 +02:00
|
|
|
set_padding_border(dict, wp->w_popup_padding, "padding", 999);
|
|
|
|
set_padding_border(dict, wp->w_popup_border, "border", 1);
|
2019-06-01 22:15:29 +02:00
|
|
|
|
|
|
|
di = dict_find(dict, (char_u *)"borderhighlight", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
2019-07-17 21:37:32 +02:00
|
|
|
if (di->di_tv.v_type != VAR_LIST || di->di_tv.vval.v_list == NULL)
|
2019-06-01 22:15:29 +02:00
|
|
|
emsg(_(e_listreq));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list_T *list = di->di_tv.vval.v_list;
|
|
|
|
listitem_T *li;
|
2019-06-16 22:54:14 +02:00
|
|
|
int i;
|
2019-06-01 22:15:29 +02:00
|
|
|
|
2019-07-17 21:37:32 +02:00
|
|
|
for (i = 0, li = list->lv_first; i < 4 && i < list->lv_len;
|
|
|
|
++i, li = li->li_next)
|
|
|
|
{
|
|
|
|
str = tv_get_string(&li->li_tv);
|
|
|
|
if (*str != NUL)
|
|
|
|
wp->w_border_highlight[i] = vim_strsave(str);
|
|
|
|
}
|
2019-06-01 22:15:29 +02:00
|
|
|
if (list->lv_len == 1 && wp->w_border_highlight[0] != NULL)
|
|
|
|
for (i = 1; i < 4; ++i)
|
2019-07-17 21:37:32 +02:00
|
|
|
wp->w_border_highlight[i] =
|
2019-06-01 22:15:29 +02:00
|
|
|
vim_strsave(wp->w_border_highlight[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
di = dict_find(dict, (char_u *)"borderchars", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
if (di->di_tv.v_type != VAR_LIST)
|
|
|
|
emsg(_(e_listreq));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list_T *list = di->di_tv.vval.v_list;
|
|
|
|
listitem_T *li;
|
2019-06-16 22:54:14 +02:00
|
|
|
int i;
|
2019-06-01 22:15:29 +02:00
|
|
|
|
|
|
|
if (list != NULL)
|
|
|
|
for (i = 0, li = list->lv_first; i < 8 && i < list->lv_len;
|
|
|
|
++i, li = li->li_next)
|
|
|
|
{
|
|
|
|
str = tv_get_string(&li->li_tv);
|
|
|
|
if (*str != NUL)
|
|
|
|
wp->w_border_char[i] = mb_ptr2char(str);
|
|
|
|
}
|
|
|
|
if (list->lv_len == 1)
|
|
|
|
for (i = 1; i < 8; ++i)
|
|
|
|
wp->w_border_char[i] = wp->w_border_char[0];
|
|
|
|
if (list->lv_len == 2)
|
|
|
|
{
|
|
|
|
for (i = 4; i < 8; ++i)
|
|
|
|
wp->w_border_char[i] = wp->w_border_char[1];
|
|
|
|
for (i = 1; i < 4; ++i)
|
|
|
|
wp->w_border_char[i] = wp->w_border_char[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-02 18:40:06 +02:00
|
|
|
|
2019-06-26 05:13:57 +02:00
|
|
|
check_highlight(dict, "scrollbarhighlight", &wp->w_scrollbar_highlight);
|
|
|
|
check_highlight(dict, "thumbhighlight", &wp->w_thumb_highlight);
|
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
di = dict_find(dict, (char_u *)"zindex", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
wp->w_zindex = dict_get_number(dict, (char_u *)"zindex");
|
|
|
|
if (wp->w_zindex < 1)
|
|
|
|
wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX;
|
|
|
|
if (wp->w_zindex > 32000)
|
|
|
|
wp->w_zindex = 32000;
|
|
|
|
}
|
|
|
|
|
2019-06-23 00:15:57 +02:00
|
|
|
di = dict_find(dict, (char_u *)"mask", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
2019-07-17 21:27:52 +02:00
|
|
|
int ok = FALSE;
|
2019-06-23 00:15:57 +02:00
|
|
|
|
2019-07-17 21:27:52 +02:00
|
|
|
if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL)
|
2019-06-23 00:15:57 +02:00
|
|
|
{
|
|
|
|
listitem_T *li;
|
|
|
|
|
2019-07-17 21:27:52 +02:00
|
|
|
ok = TRUE;
|
2019-06-23 00:15:57 +02:00
|
|
|
for (li = di->di_tv.vval.v_list->lv_first; li != NULL;
|
|
|
|
li = li->li_next)
|
|
|
|
{
|
|
|
|
if (li->li_tv.v_type != VAR_LIST
|
|
|
|
|| li->li_tv.vval.v_list == NULL
|
|
|
|
|| li->li_tv.vval.v_list->lv_len != 4)
|
|
|
|
{
|
|
|
|
ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
wp->w_popup_mask = di->di_tv.vval.v_list;
|
|
|
|
++wp->w_popup_mask->lv_refcount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
semsg(_(e_invargval), "mask");
|
|
|
|
}
|
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
#if defined(FEAT_TIMERS)
|
|
|
|
// Add timer to close the popup after some time.
|
|
|
|
nr = dict_get_number(dict, (char_u *)"time");
|
|
|
|
if (nr > 0)
|
|
|
|
popup_add_timeout(wp, nr);
|
|
|
|
#endif
|
|
|
|
|
2019-06-02 18:40:06 +02:00
|
|
|
di = dict_find(dict, (char_u *)"moved", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
2019-06-02 19:53:44 +02:00
|
|
|
set_moved_values(wp);
|
2019-07-07 18:28:14 +02:00
|
|
|
handle_moved_argument(wp, di, FALSE);
|
|
|
|
}
|
2019-06-02 18:40:06 +02:00
|
|
|
|
2019-07-07 18:28:14 +02:00
|
|
|
di = dict_find(dict, (char_u *)"mousemoved", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
set_mousemoved_values(wp);
|
|
|
|
handle_moved_argument(wp, di, TRUE);
|
2019-06-02 18:40:06 +02:00
|
|
|
}
|
2019-06-08 16:01:13 +02:00
|
|
|
|
2019-07-18 13:46:42 +02:00
|
|
|
di = dict_find(dict, (char_u *)"cursorline", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
if (di->di_tv.v_type == VAR_NUMBER)
|
|
|
|
{
|
|
|
|
if (di->di_tv.vval.v_number != 0)
|
|
|
|
wp->w_popup_flags |= POPF_CURSORLINE;
|
|
|
|
else
|
|
|
|
wp->w_popup_flags &= ~POPF_CURSORLINE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
semsg(_(e_invargval), "cursorline");
|
|
|
|
}
|
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
di = dict_find(dict, (char_u *)"filter", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
callback_T callback = get_callback(&di->di_tv);
|
|
|
|
|
|
|
|
if (callback.cb_name != NULL)
|
|
|
|
{
|
|
|
|
free_callback(&wp->w_filter_cb);
|
|
|
|
set_callback(&wp->w_filter_cb, &callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
di = dict_find(dict, (char_u *)"callback", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
callback_T callback = get_callback(&di->di_tv);
|
|
|
|
|
|
|
|
if (callback.cb_name != NULL)
|
|
|
|
{
|
|
|
|
free_callback(&wp->w_close_cb);
|
|
|
|
set_callback(&wp->w_close_cb, &callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through the options in "dict" and apply them to popup window "wp".
|
2019-07-18 13:46:42 +02:00
|
|
|
* Only used when creating a new popup window.
|
2019-06-16 22:54:14 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
apply_options(win_T *wp, dict_T *dict)
|
|
|
|
{
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
apply_move_options(wp, dict);
|
|
|
|
apply_general_options(wp, dict);
|
|
|
|
|
2019-06-16 20:39:13 +02:00
|
|
|
nr = dict_get_number(dict, (char_u *)"hidden");
|
|
|
|
if (nr > 0)
|
|
|
|
{
|
|
|
|
wp->w_popup_flags |= POPF_HIDDEN;
|
|
|
|
--wp->w_buffer->b_nwindows;
|
|
|
|
}
|
|
|
|
|
2019-06-08 16:01:13 +02:00
|
|
|
popup_mask_refresh = TRUE;
|
2019-07-18 13:46:42 +02:00
|
|
|
popup_highlight_curline(wp);
|
2019-05-25 19:51:39 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 23:32:06 +02:00
|
|
|
/*
|
|
|
|
* Add lines to the popup from a list of strings.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
add_popup_strings(buf_T *buf, list_T *l)
|
|
|
|
{
|
|
|
|
listitem_T *li;
|
|
|
|
linenr_T lnum = 0;
|
|
|
|
char_u *p;
|
|
|
|
|
|
|
|
for (li = l->lv_first; li != NULL; li = li->li_next)
|
|
|
|
if (li->li_tv.v_type == VAR_STRING)
|
|
|
|
{
|
|
|
|
p = li->li_tv.vval.v_string;
|
|
|
|
ml_append_buf(buf, lnum++,
|
|
|
|
p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add lines to the popup from a list of dictionaries.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
add_popup_dicts(buf_T *buf, list_T *l)
|
|
|
|
{
|
|
|
|
listitem_T *li;
|
|
|
|
listitem_T *pli;
|
|
|
|
linenr_T lnum = 0;
|
|
|
|
char_u *p;
|
|
|
|
dict_T *dict;
|
|
|
|
|
|
|
|
// first add the text lines
|
|
|
|
for (li = l->lv_first; li != NULL; li = li->li_next)
|
|
|
|
{
|
|
|
|
if (li->li_tv.v_type != VAR_DICT)
|
|
|
|
{
|
|
|
|
emsg(_(e_dictreq));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dict = li->li_tv.vval.v_dict;
|
|
|
|
p = dict == NULL ? NULL
|
|
|
|
: dict_get_string(dict, (char_u *)"text", FALSE);
|
|
|
|
ml_append_buf(buf, lnum++,
|
|
|
|
p == NULL ? (char_u *)"" : p, (colnr_T)0, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the text properties
|
|
|
|
lnum = 1;
|
|
|
|
for (li = l->lv_first; li != NULL; li = li->li_next, ++lnum)
|
|
|
|
{
|
|
|
|
dictitem_T *di;
|
|
|
|
list_T *plist;
|
|
|
|
|
|
|
|
dict = li->li_tv.vval.v_dict;
|
|
|
|
di = dict_find(dict, (char_u *)"props", -1);
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
|
|
|
if (di->di_tv.v_type != VAR_LIST)
|
|
|
|
{
|
|
|
|
emsg(_(e_listreq));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plist = di->di_tv.vval.v_list;
|
|
|
|
if (plist != NULL)
|
|
|
|
{
|
|
|
|
for (pli = plist->lv_first; pli != NULL; pli = pli->li_next)
|
|
|
|
{
|
|
|
|
if (pli->li_tv.v_type != VAR_DICT)
|
|
|
|
{
|
|
|
|
emsg(_(e_dictreq));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dict = pli->li_tv.vval.v_dict;
|
|
|
|
if (dict != NULL)
|
|
|
|
{
|
|
|
|
int col = dict_get_number(dict, (char_u *)"col");
|
|
|
|
|
|
|
|
prop_add_common( lnum, col, dict, buf, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 23:13:53 +02:00
|
|
|
/*
|
|
|
|
* Get the padding plus border at the top, adjusted to 1 if there is a title.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
popup_top_extra(win_T *wp)
|
|
|
|
{
|
|
|
|
int extra = wp->w_popup_border[0] + wp->w_popup_padding[0];
|
|
|
|
|
|
|
|
if (extra == 0 && wp->w_popup_title != NULL && *wp->w_popup_title != NUL)
|
|
|
|
return 1;
|
|
|
|
return extra;
|
|
|
|
}
|
|
|
|
|
2019-06-12 20:22:27 +02:00
|
|
|
/*
|
|
|
|
* Return the height of popup window "wp", including border and padding.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
popup_height(win_T *wp)
|
|
|
|
{
|
|
|
|
return wp->w_height
|
2019-07-02 23:13:53 +02:00
|
|
|
+ popup_top_extra(wp)
|
2019-06-12 20:22:27 +02:00
|
|
|
+ wp->w_popup_padding[2] + wp->w_popup_border[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-07-02 23:13:53 +02:00
|
|
|
* Return the width of popup window "wp", including border, padding and
|
|
|
|
* scrollbar.
|
2019-06-12 20:22:27 +02:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
popup_width(win_T *wp)
|
|
|
|
{
|
2019-07-13 14:17:51 +02:00
|
|
|
// w_leftcol is how many columns of the core are left of the screen
|
|
|
|
// w_popup_rightoff is how many columns of the core are right of the screen
|
2019-07-02 23:13:53 +02:00
|
|
|
return wp->w_width + wp->w_leftcol
|
2019-06-12 20:22:27 +02:00
|
|
|
+ wp->w_popup_padding[3] + wp->w_popup_border[3]
|
2019-06-29 07:41:35 +02:00
|
|
|
+ wp->w_popup_padding[1] + wp->w_popup_border[1]
|
2019-07-02 23:13:53 +02:00
|
|
|
+ wp->w_has_scrollbar
|
|
|
|
+ wp->w_popup_rightoff;
|
2019-06-16 20:09:10 +02:00
|
|
|
}
|
|
|
|
|
2019-05-27 21:54:10 +02:00
|
|
|
/*
|
|
|
|
* Adjust the position and size of the popup to fit on the screen.
|
|
|
|
*/
|
2019-05-30 00:12:11 +02:00
|
|
|
void
|
2019-05-27 21:54:10 +02:00
|
|
|
popup_adjust_position(win_T *wp)
|
|
|
|
{
|
2019-05-29 23:14:28 +02:00
|
|
|
linenr_T lnum;
|
|
|
|
int wrapped = 0;
|
|
|
|
int maxwidth;
|
2019-07-02 23:13:53 +02:00
|
|
|
int maxspace;
|
2019-05-30 21:24:26 +02:00
|
|
|
int center_vert = FALSE;
|
|
|
|
int center_hor = FALSE;
|
2019-06-02 14:49:56 +02:00
|
|
|
int allow_adjust_left = !wp->w_popup_fixed;
|
2019-06-16 20:09:10 +02:00
|
|
|
int top_extra = popup_top_extra(wp);
|
2019-06-02 15:34:29 +02:00
|
|
|
int right_extra = wp->w_popup_border[1] + wp->w_popup_padding[1];
|
|
|
|
int bot_extra = wp->w_popup_border[2] + wp->w_popup_padding[2];
|
|
|
|
int left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3];
|
|
|
|
int extra_height = top_extra + bot_extra;
|
|
|
|
int extra_width = left_extra + right_extra;
|
2019-06-08 16:01:13 +02:00
|
|
|
int org_winrow = wp->w_winrow;
|
|
|
|
int org_wincol = wp->w_wincol;
|
|
|
|
int org_width = wp->w_width;
|
|
|
|
int org_height = wp->w_height;
|
2019-06-28 04:06:50 +02:00
|
|
|
int org_leftcol = wp->w_leftcol;
|
2019-07-02 23:13:53 +02:00
|
|
|
int org_leftoff = wp->w_popup_leftoff;
|
2019-06-16 20:09:10 +02:00
|
|
|
int minwidth;
|
2019-05-29 23:14:28 +02:00
|
|
|
|
2019-05-30 21:24:26 +02:00
|
|
|
wp->w_winrow = 0;
|
|
|
|
wp->w_wincol = 0;
|
2019-06-28 04:06:50 +02:00
|
|
|
wp->w_leftcol = 0;
|
2019-07-02 23:13:53 +02:00
|
|
|
wp->w_popup_leftoff = 0;
|
|
|
|
wp->w_popup_rightoff = 0;
|
2019-05-30 21:24:26 +02:00
|
|
|
if (wp->w_popup_pos == POPPOS_CENTER)
|
|
|
|
{
|
|
|
|
// center after computing the size
|
|
|
|
center_vert = TRUE;
|
|
|
|
center_hor = TRUE;
|
|
|
|
}
|
2019-05-27 21:54:10 +02:00
|
|
|
else
|
2019-05-30 21:24:26 +02:00
|
|
|
{
|
|
|
|
if (wp->w_wantline == 0)
|
|
|
|
center_vert = TRUE;
|
|
|
|
else if (wp->w_popup_pos == POPPOS_TOPLEFT
|
|
|
|
|| wp->w_popup_pos == POPPOS_TOPRIGHT)
|
|
|
|
{
|
|
|
|
wp->w_winrow = wp->w_wantline - 1;
|
|
|
|
if (wp->w_winrow >= Rows)
|
|
|
|
wp->w_winrow = Rows - 1;
|
|
|
|
}
|
2019-05-27 21:54:10 +02:00
|
|
|
|
2019-05-30 21:24:26 +02:00
|
|
|
if (wp->w_wantcol == 0)
|
|
|
|
center_hor = TRUE;
|
|
|
|
else if (wp->w_popup_pos == POPPOS_TOPLEFT
|
|
|
|
|| wp->w_popup_pos == POPPOS_BOTLEFT)
|
|
|
|
{
|
|
|
|
wp->w_wincol = wp->w_wantcol - 1;
|
|
|
|
if (wp->w_wincol >= Columns - 3)
|
|
|
|
wp->w_wincol = Columns - 3;
|
|
|
|
}
|
|
|
|
}
|
2019-05-27 21:54:10 +02:00
|
|
|
|
2019-05-30 21:24:26 +02:00
|
|
|
// When centering or right aligned, use maximum width.
|
2019-06-02 14:49:56 +02:00
|
|
|
// When left aligned use the space available, but shift to the left when we
|
|
|
|
// hit the right of the screen.
|
2019-07-02 23:13:53 +02:00
|
|
|
maxspace = Columns - wp->w_wincol - left_extra;
|
|
|
|
maxwidth = maxspace;
|
2019-05-29 23:14:28 +02:00
|
|
|
if (wp->w_maxwidth > 0 && maxwidth > wp->w_maxwidth)
|
2019-06-02 14:49:56 +02:00
|
|
|
{
|
|
|
|
allow_adjust_left = FALSE;
|
2019-05-29 23:14:28 +02:00
|
|
|
maxwidth = wp->w_maxwidth;
|
2019-06-02 14:49:56 +02:00
|
|
|
}
|
2019-05-29 23:14:28 +02:00
|
|
|
|
2019-06-12 23:40:01 +02:00
|
|
|
// start at the desired first line
|
2019-07-18 21:43:07 +02:00
|
|
|
if (wp->w_firstline != 0)
|
|
|
|
wp->w_topline = wp->w_firstline;
|
2019-06-12 23:40:01 +02:00
|
|
|
if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count)
|
|
|
|
wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
|
|
|
|
|
2019-05-29 23:14:28 +02:00
|
|
|
// Compute width based on longest text line and the 'wrap' option.
|
2019-06-16 15:32:14 +02:00
|
|
|
// Use a minimum width of one, so that something shows when there is no
|
|
|
|
// text.
|
2019-05-29 23:14:28 +02:00
|
|
|
// TODO: more accurate wrapping
|
2019-06-16 15:32:14 +02:00
|
|
|
wp->w_width = 1;
|
2019-06-12 23:40:01 +02:00
|
|
|
for (lnum = wp->w_topline; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum)
|
2019-05-29 23:14:28 +02:00
|
|
|
{
|
2019-07-09 20:25:25 +02:00
|
|
|
// count Tabs for what they are worth
|
|
|
|
int len = win_linetabsize(wp, ml_get_buf(wp->w_buffer, lnum, FALSE),
|
|
|
|
(colnr_T)MAXCOL);
|
2019-05-29 23:14:28 +02:00
|
|
|
|
2019-06-02 14:49:56 +02:00
|
|
|
if (wp->w_p_wrap)
|
2019-05-29 23:14:28 +02:00
|
|
|
{
|
2019-06-02 14:49:56 +02:00
|
|
|
while (len > maxwidth)
|
|
|
|
{
|
|
|
|
++wrapped;
|
|
|
|
len -= maxwidth;
|
|
|
|
wp->w_width = maxwidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (len > maxwidth
|
|
|
|
&& allow_adjust_left
|
|
|
|
&& (wp->w_popup_pos == POPPOS_TOPLEFT
|
|
|
|
|| wp->w_popup_pos == POPPOS_BOTLEFT))
|
|
|
|
{
|
|
|
|
// adjust leftwise to fit text on screen
|
2019-06-15 22:27:23 +02:00
|
|
|
int shift_by = len - maxwidth;
|
2019-06-02 14:49:56 +02:00
|
|
|
|
2019-06-15 22:27:23 +02:00
|
|
|
if (shift_by > wp->w_wincol)
|
2019-06-02 14:49:56 +02:00
|
|
|
{
|
|
|
|
int truncate_shift = shift_by - wp->w_wincol;
|
2019-06-15 22:27:23 +02:00
|
|
|
|
2019-06-02 14:49:56 +02:00
|
|
|
len -= truncate_shift;
|
|
|
|
shift_by -= truncate_shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
wp->w_wincol -= shift_by;
|
|
|
|
maxwidth += shift_by;
|
2019-05-29 23:14:28 +02:00
|
|
|
wp->w_width = maxwidth;
|
|
|
|
}
|
|
|
|
if (wp->w_width < len)
|
2019-07-13 14:17:51 +02:00
|
|
|
{
|
2019-05-29 23:14:28 +02:00
|
|
|
wp->w_width = len;
|
2019-07-13 14:17:51 +02:00
|
|
|
if (wp->w_maxwidth > 0 && wp->w_width > wp->w_maxwidth)
|
|
|
|
wp->w_width = wp->w_maxwidth;
|
|
|
|
}
|
2019-06-12 23:40:01 +02:00
|
|
|
// do not use the width of lines we're not going to show
|
2019-07-03 23:20:18 +02:00
|
|
|
if (wp->w_maxheight > 0
|
|
|
|
&& lnum - wp->w_topline + 1 + wrapped > wp->w_maxheight)
|
2019-06-12 23:40:01 +02:00
|
|
|
break;
|
2019-05-29 23:14:28 +02:00
|
|
|
}
|
|
|
|
|
2019-06-25 05:15:58 +02:00
|
|
|
wp->w_has_scrollbar = wp->w_want_scrollbar
|
|
|
|
&& (wp->w_topline > 1 || lnum <= wp->w_buffer->b_ml.ml_line_count);
|
|
|
|
|
2019-06-16 20:09:10 +02:00
|
|
|
minwidth = wp->w_minwidth;
|
|
|
|
if (wp->w_popup_title != NULL && *wp->w_popup_title != NUL)
|
|
|
|
{
|
|
|
|
int title_len = vim_strsize(wp->w_popup_title) + 2 - extra_width;
|
|
|
|
|
|
|
|
if (minwidth < title_len)
|
|
|
|
minwidth = title_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minwidth > 0 && wp->w_width < minwidth)
|
|
|
|
wp->w_width = minwidth;
|
2019-05-29 23:14:28 +02:00
|
|
|
if (wp->w_width > maxwidth)
|
2019-07-02 23:13:53 +02:00
|
|
|
{
|
|
|
|
if (wp->w_width > maxspace)
|
|
|
|
// some columns cut off on the right
|
|
|
|
wp->w_popup_rightoff = wp->w_width - maxspace;
|
2019-05-29 23:14:28 +02:00
|
|
|
wp->w_width = maxwidth;
|
2019-07-02 23:13:53 +02:00
|
|
|
}
|
2019-05-30 21:24:26 +02:00
|
|
|
if (center_hor)
|
2019-06-16 19:05:31 +02:00
|
|
|
{
|
|
|
|
wp->w_wincol = (Columns - wp->w_width - extra_width) / 2;
|
|
|
|
if (wp->w_wincol < 0)
|
|
|
|
wp->w_wincol = 0;
|
|
|
|
}
|
2019-05-30 21:24:26 +02:00
|
|
|
else if (wp->w_popup_pos == POPPOS_BOTRIGHT
|
|
|
|
|| wp->w_popup_pos == POPPOS_TOPRIGHT)
|
|
|
|
{
|
2019-06-28 04:06:50 +02:00
|
|
|
int leftoff = wp->w_wantcol - (wp->w_width + extra_width);
|
|
|
|
|
2019-05-30 21:24:26 +02:00
|
|
|
// Right aligned: move to the right if needed.
|
|
|
|
// No truncation, because that would change the height.
|
2019-06-28 04:06:50 +02:00
|
|
|
if (leftoff >= 0)
|
|
|
|
wp->w_wincol = leftoff;
|
|
|
|
else if (wp->w_popup_fixed)
|
|
|
|
{
|
|
|
|
// "col" specifies the right edge, but popup doesn't fit, skip some
|
2019-07-02 23:13:53 +02:00
|
|
|
// columns when displaying the window, minus left border and
|
|
|
|
// padding.
|
|
|
|
if (-leftoff > left_extra)
|
|
|
|
wp->w_leftcol = -leftoff - left_extra;
|
|
|
|
wp->w_width -= wp->w_leftcol;
|
|
|
|
wp->w_popup_leftoff = -leftoff;
|
2019-06-28 04:06:50 +02:00
|
|
|
if (wp->w_width < 0)
|
|
|
|
wp->w_width = 0;
|
|
|
|
}
|
2019-05-30 21:24:26 +02:00
|
|
|
}
|
2019-05-27 21:54:10 +02:00
|
|
|
|
2019-06-12 23:40:01 +02:00
|
|
|
wp->w_height = wp->w_buffer->b_ml.ml_line_count - wp->w_topline
|
|
|
|
+ 1 + wrapped;
|
2019-05-27 21:54:10 +02:00
|
|
|
if (wp->w_minheight > 0 && wp->w_height < wp->w_minheight)
|
|
|
|
wp->w_height = wp->w_minheight;
|
|
|
|
if (wp->w_maxheight > 0 && wp->w_height > wp->w_maxheight)
|
|
|
|
wp->w_height = wp->w_maxheight;
|
|
|
|
if (wp->w_height > Rows - wp->w_winrow)
|
|
|
|
wp->w_height = Rows - wp->w_winrow;
|
2019-05-30 00:12:11 +02:00
|
|
|
|
2019-05-30 21:24:26 +02:00
|
|
|
if (center_vert)
|
2019-06-16 19:05:31 +02:00
|
|
|
{
|
|
|
|
wp->w_winrow = (Rows - wp->w_height - extra_height) / 2;
|
|
|
|
if (wp->w_winrow < 0)
|
|
|
|
wp->w_winrow = 0;
|
|
|
|
}
|
2019-05-30 21:24:26 +02:00
|
|
|
else if (wp->w_popup_pos == POPPOS_BOTRIGHT
|
|
|
|
|| wp->w_popup_pos == POPPOS_BOTLEFT)
|
|
|
|
{
|
2019-06-02 15:34:29 +02:00
|
|
|
if ((wp->w_height + extra_height) <= wp->w_wantline)
|
2019-05-30 21:24:26 +02:00
|
|
|
// bottom aligned: may move down
|
2019-06-02 15:34:29 +02:00
|
|
|
wp->w_winrow = wp->w_wantline - (wp->w_height + extra_height);
|
2019-05-30 21:24:26 +02:00
|
|
|
else
|
|
|
|
// not enough space, make top aligned
|
|
|
|
wp->w_winrow = wp->w_wantline + 1;
|
|
|
|
}
|
|
|
|
|
2019-05-30 00:12:11 +02:00
|
|
|
wp->w_popup_last_changedtick = CHANGEDTICK(wp->w_buffer);
|
2019-06-08 16:01:13 +02:00
|
|
|
|
|
|
|
// Need to update popup_mask if the position or size changed.
|
2019-06-08 17:15:51 +02:00
|
|
|
// And redraw windows that were behind the popup.
|
2019-06-08 16:01:13 +02:00
|
|
|
if (org_winrow != wp->w_winrow
|
|
|
|
|| org_wincol != wp->w_wincol
|
2019-06-28 04:06:50 +02:00
|
|
|
|| org_leftcol != wp->w_leftcol
|
2019-07-02 23:13:53 +02:00
|
|
|
|| org_leftoff != wp->w_popup_leftoff
|
2019-06-08 16:01:13 +02:00
|
|
|
|| org_width != wp->w_width
|
|
|
|
|| org_height != wp->w_height)
|
|
|
|
{
|
2019-06-10 21:24:12 +02:00
|
|
|
redraw_all_later(VALID);
|
2019-06-08 16:01:13 +02:00
|
|
|
popup_mask_refresh = TRUE;
|
|
|
|
}
|
2019-05-27 21:54:10 +02:00
|
|
|
}
|
|
|
|
|
2019-06-02 19:53:44 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TYPE_NORMAL,
|
2019-06-12 22:42:41 +02:00
|
|
|
TYPE_ATCURSOR,
|
2019-07-07 18:28:14 +02:00
|
|
|
TYPE_BEVAL,
|
2019-06-15 21:46:30 +02:00
|
|
|
TYPE_NOTIFICATION,
|
2019-06-16 19:05:31 +02:00
|
|
|
TYPE_DIALOG,
|
2019-07-18 21:43:07 +02:00
|
|
|
TYPE_MENU,
|
|
|
|
TYPE_PREVIEW
|
2019-06-02 19:53:44 +02:00
|
|
|
} create_type_T;
|
|
|
|
|
2019-06-16 15:32:14 +02:00
|
|
|
/*
|
|
|
|
* Make "buf" empty and set the contents to "text".
|
|
|
|
* Used by popup_create() and popup_settext().
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
popup_set_buffer_text(buf_T *buf, typval_T text)
|
|
|
|
{
|
|
|
|
int lnum;
|
|
|
|
|
|
|
|
// Clear the buffer, then replace the lines.
|
|
|
|
curbuf = buf;
|
|
|
|
for (lnum = buf->b_ml.ml_line_count; lnum > 0; --lnum)
|
|
|
|
ml_delete(lnum, FALSE);
|
|
|
|
curbuf = curwin->w_buffer;
|
|
|
|
|
|
|
|
// Add text to the buffer.
|
|
|
|
if (text.v_type == VAR_STRING)
|
|
|
|
{
|
|
|
|
// just a string
|
|
|
|
ml_append_buf(buf, 0, text.vval.v_string, (colnr_T)0, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list_T *l = text.vval.v_list;
|
|
|
|
|
|
|
|
if (l->lv_len > 0)
|
|
|
|
{
|
|
|
|
if (l->lv_first->li_tv.v_type == VAR_STRING)
|
|
|
|
// list of strings
|
|
|
|
add_popup_strings(buf, l);
|
|
|
|
else
|
|
|
|
// list of dictionaries
|
|
|
|
add_popup_dicts(buf, l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete the line that was in the empty buffer
|
|
|
|
curbuf = buf;
|
|
|
|
ml_delete(buf->b_ml.ml_line_count, FALSE);
|
|
|
|
curbuf = curwin->w_buffer;
|
|
|
|
}
|
|
|
|
|
2019-07-18 21:43:07 +02:00
|
|
|
/*
|
|
|
|
* Parse the 'previewpopup' option and apply the values to window "wp" if it
|
|
|
|
* not NULL.
|
|
|
|
* Return FAIL if the parsing fails.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
parse_previewpopup(win_T *wp)
|
|
|
|
{
|
|
|
|
char_u *p;
|
|
|
|
|
|
|
|
for (p = p_pvp; *p != NUL; p += (*p == ',' ? 1 : 0))
|
|
|
|
{
|
|
|
|
char_u *e, *dig;
|
|
|
|
char_u *s = p;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
e = vim_strchr(p, ':');
|
|
|
|
if (e == NULL || e[1] == NUL)
|
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
p = vim_strchr(e, ',');
|
|
|
|
if (p == NULL)
|
|
|
|
p = e + STRLEN(e);
|
|
|
|
dig = e + 1;
|
|
|
|
x = getdigits(&dig);
|
|
|
|
if (dig != p)
|
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
if (STRNCMP(s, "height:", 7) == 0)
|
|
|
|
{
|
|
|
|
if (wp != NULL)
|
|
|
|
{
|
|
|
|
wp->w_minheight = x;
|
|
|
|
wp->w_maxheight = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (STRNCMP(s, "width:", 6) == 0)
|
|
|
|
{
|
|
|
|
if (wp != NULL)
|
|
|
|
{
|
|
|
|
wp->w_minwidth = x;
|
|
|
|
wp->w_maxwidth = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set w_wantline and w_wantcol for the cursor position in the current window.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_set_wantpos(win_T *wp)
|
|
|
|
{
|
|
|
|
setcursor_mayforce(TRUE);
|
|
|
|
wp->w_wantline = curwin->w_winrow + curwin->w_wrow;
|
|
|
|
if (wp->w_wantline == 0) // cursor in first line
|
|
|
|
{
|
|
|
|
wp->w_wantline = 2;
|
|
|
|
wp->w_popup_pos = POPPOS_TOPLEFT;
|
|
|
|
}
|
|
|
|
wp->w_wantcol = curwin->w_wincol + curwin->w_wcol + 1;
|
|
|
|
popup_adjust_position(wp);
|
|
|
|
}
|
|
|
|
|
2019-05-25 19:51:39 +02:00
|
|
|
/*
|
|
|
|
* popup_create({text}, {options})
|
2019-05-30 19:25:06 +02:00
|
|
|
* popup_atcursor({text}, {options})
|
2019-07-18 21:43:07 +02:00
|
|
|
* etc.
|
|
|
|
* When creating a preview window popup "argvars" and "rettv" are NULL.
|
2019-05-25 19:51:39 +02:00
|
|
|
*/
|
2019-06-16 19:05:31 +02:00
|
|
|
static win_T *
|
2019-06-02 19:53:44 +02:00
|
|
|
popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
|
2019-05-25 19:51:39 +02:00
|
|
|
{
|
2019-06-20 02:31:49 +02:00
|
|
|
win_T *wp;
|
|
|
|
tabpage_T *tp = NULL;
|
2019-07-18 21:43:07 +02:00
|
|
|
int tabnr = 0;
|
2019-06-30 22:16:10 +02:00
|
|
|
int new_buffer;
|
|
|
|
buf_T *buf = NULL;
|
2019-07-18 21:43:07 +02:00
|
|
|
dict_T *d = NULL;
|
2019-06-20 02:31:49 +02:00
|
|
|
int nr;
|
|
|
|
int i;
|
2019-05-25 19:51:39 +02:00
|
|
|
|
2019-07-18 21:43:07 +02:00
|
|
|
if (argvars != NULL)
|
2019-06-30 22:16:10 +02:00
|
|
|
{
|
2019-07-20 16:51:19 +02:00
|
|
|
// Check that arguments look OK.
|
2019-07-18 21:43:07 +02:00
|
|
|
if (argvars[0].v_type == VAR_NUMBER)
|
2019-06-30 22:16:10 +02:00
|
|
|
{
|
2019-07-18 21:43:07 +02:00
|
|
|
buf = buflist_findnr( argvars[0].vval.v_number);
|
|
|
|
if (buf == NULL)
|
|
|
|
{
|
|
|
|
semsg(_(e_nobufnr), argvars[0].vval.v_number);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!(argvars[0].v_type == VAR_STRING
|
|
|
|
&& argvars[0].vval.v_string != NULL)
|
|
|
|
&& !(argvars[0].v_type == VAR_LIST
|
|
|
|
&& argvars[0].vval.v_list != NULL))
|
|
|
|
{
|
|
|
|
emsg(_(e_listreq));
|
2019-06-30 22:16:10 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-07-18 21:43:07 +02:00
|
|
|
if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL)
|
|
|
|
{
|
|
|
|
emsg(_(e_dictreq));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
d = argvars[1].vval.v_dict;
|
2019-06-30 22:16:10 +02:00
|
|
|
}
|
2019-05-25 19:51:39 +02:00
|
|
|
|
2019-07-18 21:43:07 +02:00
|
|
|
if (d != NULL)
|
2019-06-20 02:31:49 +02:00
|
|
|
{
|
2019-07-18 21:43:07 +02:00
|
|
|
if (dict_find(d, (char_u *)"tabpage", -1) != NULL)
|
|
|
|
tabnr = (int)dict_get_number(d, (char_u *)"tabpage");
|
|
|
|
else if (type == TYPE_NOTIFICATION)
|
|
|
|
tabnr = -1; // notifications are global by default
|
|
|
|
else
|
|
|
|
tabnr = 0;
|
|
|
|
if (tabnr > 0)
|
2019-06-20 02:31:49 +02:00
|
|
|
{
|
2019-07-18 21:43:07 +02:00
|
|
|
tp = find_tabpage(tabnr);
|
|
|
|
if (tp == NULL)
|
|
|
|
{
|
|
|
|
semsg(_("E997: Tabpage not found: %d"), tabnr);
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-06-20 02:31:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 19:51:39 +02:00
|
|
|
// Create the window and buffer.
|
|
|
|
wp = win_alloc_popup_win();
|
|
|
|
if (wp == NULL)
|
2019-06-16 19:05:31 +02:00
|
|
|
return NULL;
|
2019-07-18 21:43:07 +02:00
|
|
|
if (rettv != NULL)
|
|
|
|
rettv->vval.v_number = wp->w_id;
|
2019-05-30 21:24:26 +02:00
|
|
|
wp->w_popup_pos = POPPOS_TOPLEFT;
|
2019-06-30 22:16:10 +02:00
|
|
|
wp->w_popup_flags = POPF_IS_POPUP;
|
2019-05-25 19:51:39 +02:00
|
|
|
|
2019-06-30 22:16:10 +02:00
|
|
|
if (buf != NULL)
|
|
|
|
{
|
|
|
|
// use existing buffer
|
|
|
|
new_buffer = FALSE;
|
2019-07-01 22:21:01 +02:00
|
|
|
win_init_popup_win(wp, buf);
|
2019-06-30 22:16:10 +02:00
|
|
|
buffer_ensure_loaded(buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// create a new buffer associated with the popup
|
|
|
|
new_buffer = TRUE;
|
|
|
|
buf = buflist_new(NULL, NULL, (linenr_T)0,
|
|
|
|
BLN_NEW|BLN_LISTED|BLN_DUMMY);
|
|
|
|
if (buf == NULL)
|
|
|
|
return NULL;
|
|
|
|
ml_open(buf);
|
2019-05-30 15:22:43 +02:00
|
|
|
|
2019-06-30 22:16:10 +02:00
|
|
|
win_init_popup_win(wp, buf);
|
2019-05-30 15:22:43 +02:00
|
|
|
|
2019-06-30 22:16:10 +02:00
|
|
|
set_local_options_default(wp);
|
|
|
|
set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1,
|
2019-05-25 19:51:39 +02:00
|
|
|
(char_u *)"popup", OPT_FREE|OPT_LOCAL, 0);
|
2019-06-30 22:16:10 +02:00
|
|
|
set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1,
|
2019-07-18 21:43:07 +02:00
|
|
|
(char_u *)"wipe", OPT_FREE|OPT_LOCAL, 0);
|
2019-06-30 22:16:10 +02:00
|
|
|
buf->b_p_ul = -1; // no undo
|
|
|
|
buf->b_p_swf = FALSE; // no swap file
|
|
|
|
buf->b_p_bl = FALSE; // unlisted buffer
|
|
|
|
buf->b_locked = TRUE;
|
|
|
|
wp->w_p_wrap = TRUE; // 'wrap' is default on
|
|
|
|
|
|
|
|
// Avoid that 'buftype' is reset when this buffer is entered.
|
|
|
|
buf->b_p_initialized = TRUE;
|
|
|
|
}
|
2019-05-25 19:51:39 +02:00
|
|
|
|
2019-06-20 02:31:49 +02:00
|
|
|
if (tp != NULL)
|
|
|
|
{
|
|
|
|
// popup on specified tab page
|
|
|
|
wp->w_next = tp->tp_first_popupwin;
|
|
|
|
tp->tp_first_popupwin = wp;
|
|
|
|
}
|
|
|
|
else if (tabnr == 0)
|
2019-05-25 19:51:39 +02:00
|
|
|
{
|
2019-06-15 14:14:31 +02:00
|
|
|
// popup on current tab page
|
2019-05-26 18:48:13 +02:00
|
|
|
wp->w_next = curtab->tp_first_popupwin;
|
|
|
|
curtab->tp_first_popupwin = wp;
|
2019-05-25 19:51:39 +02:00
|
|
|
}
|
2019-06-20 02:31:49 +02:00
|
|
|
else // (tabnr < 0)
|
2019-05-25 19:51:39 +02:00
|
|
|
{
|
2019-06-12 22:42:41 +02:00
|
|
|
win_T *prev = first_popupwin;
|
|
|
|
|
|
|
|
// Global popup: add at the end, so that it gets displayed on top of
|
|
|
|
// older ones with the same zindex. Matters for notifications.
|
|
|
|
if (first_popupwin == NULL)
|
|
|
|
first_popupwin = wp;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (prev->w_next != NULL)
|
|
|
|
prev = prev->w_next;
|
|
|
|
prev->w_next = wp;
|
|
|
|
}
|
2019-05-25 19:51:39 +02:00
|
|
|
}
|
|
|
|
|
2019-07-18 21:43:07 +02:00
|
|
|
if (new_buffer && argvars != NULL)
|
2019-06-30 22:16:10 +02:00
|
|
|
popup_set_buffer_text(buf, argvars[0]);
|
2019-05-25 19:51:39 +02:00
|
|
|
|
2019-07-18 21:43:07 +02:00
|
|
|
if (type == TYPE_ATCURSOR || type == TYPE_PREVIEW)
|
2019-06-02 19:53:44 +02:00
|
|
|
{
|
|
|
|
wp->w_popup_pos = POPPOS_BOTLEFT;
|
2019-07-18 21:43:07 +02:00
|
|
|
popup_set_wantpos(wp);
|
|
|
|
}
|
|
|
|
if (type == TYPE_ATCURSOR)
|
|
|
|
{
|
2019-06-02 19:53:44 +02:00
|
|
|
set_moved_values(wp);
|
|
|
|
set_moved_columns(wp, FIND_STRING);
|
|
|
|
}
|
|
|
|
|
2019-07-07 18:28:14 +02:00
|
|
|
if (type == TYPE_BEVAL)
|
|
|
|
{
|
|
|
|
wp->w_popup_pos = POPPOS_BOTLEFT;
|
|
|
|
|
|
|
|
// by default use the mouse position
|
|
|
|
wp->w_wantline = mouse_row;
|
|
|
|
if (wp->w_wantline <= 0) // mouse on first line
|
|
|
|
{
|
|
|
|
wp->w_wantline = 2;
|
|
|
|
wp->w_popup_pos = POPPOS_TOPLEFT;
|
|
|
|
}
|
|
|
|
wp->w_wantcol = mouse_col + 1;
|
|
|
|
set_mousemoved_values(wp);
|
|
|
|
set_mousemoved_columns(wp, FIND_IDENT + FIND_STRING + FIND_EVAL);
|
|
|
|
}
|
|
|
|
|
2019-06-08 16:01:13 +02:00
|
|
|
// set default values
|
|
|
|
wp->w_zindex = POPUPWIN_DEFAULT_ZINDEX;
|
2019-06-30 18:07:00 +02:00
|
|
|
wp->w_popup_close = POPCLOSE_NONE;
|
2019-06-08 16:01:13 +02:00
|
|
|
|
2019-06-12 22:42:41 +02:00
|
|
|
if (type == TYPE_NOTIFICATION)
|
|
|
|
{
|
|
|
|
win_T *twp, *nextwin;
|
|
|
|
int height = buf->b_ml.ml_line_count + 3;
|
|
|
|
|
|
|
|
// Try to not overlap with another global popup. Guess we need 3
|
|
|
|
// more screen lines than buffer lines.
|
|
|
|
wp->w_wantline = 1;
|
|
|
|
for (twp = first_popupwin; twp != NULL; twp = nextwin)
|
|
|
|
{
|
|
|
|
nextwin = twp->w_next;
|
|
|
|
if (twp != wp
|
|
|
|
&& twp->w_zindex == POPUPWIN_NOTIFICATION_ZINDEX
|
|
|
|
&& twp->w_winrow <= wp->w_wantline - 1 + height
|
|
|
|
&& twp->w_winrow + popup_height(twp) > wp->w_wantline - 1)
|
|
|
|
{
|
|
|
|
// move to below this popup and restart the loop to check for
|
|
|
|
// overlap with other popups
|
|
|
|
wp->w_wantline = twp->w_winrow + popup_height(twp) + 1;
|
|
|
|
nextwin = first_popupwin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wp->w_wantline + height > Rows)
|
|
|
|
{
|
|
|
|
// can't avoid overlap, put on top in the hope that message goes
|
|
|
|
// away soon.
|
|
|
|
wp->w_wantline = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wp->w_wantcol = 10;
|
|
|
|
wp->w_zindex = POPUPWIN_NOTIFICATION_ZINDEX;
|
2019-06-15 14:31:55 +02:00
|
|
|
wp->w_minwidth = 20;
|
|
|
|
wp->w_popup_drag = 1;
|
2019-06-30 18:07:00 +02:00
|
|
|
wp->w_popup_close = POPCLOSE_CLICK;
|
2019-06-12 22:42:41 +02:00
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
wp->w_popup_border[i] = 1;
|
|
|
|
wp->w_popup_padding[1] = 1;
|
|
|
|
wp->w_popup_padding[3] = 1;
|
2019-06-15 14:31:55 +02:00
|
|
|
|
|
|
|
nr = syn_name2id((char_u *)"PopupNotification");
|
2019-06-12 22:42:41 +02:00
|
|
|
set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
|
2019-06-15 14:31:55 +02:00
|
|
|
(char_u *)(nr == 0 ? "WarningMsg" : "PopupNotification"),
|
|
|
|
OPT_FREE|OPT_LOCAL, 0);
|
2019-06-12 22:42:41 +02:00
|
|
|
}
|
|
|
|
|
2019-06-16 19:05:31 +02:00
|
|
|
if (type == TYPE_DIALOG || type == TYPE_MENU)
|
2019-06-15 21:46:30 +02:00
|
|
|
{
|
|
|
|
wp->w_popup_pos = POPPOS_CENTER;
|
|
|
|
wp->w_zindex = POPUPWIN_DIALOG_ZINDEX;
|
|
|
|
wp->w_popup_drag = 1;
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
wp->w_popup_border[i] = 1;
|
2019-07-14 16:28:13 +02:00
|
|
|
wp->w_popup_padding[i] = (i & 1) ? 1 : 0;
|
2019-06-15 21:46:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-16 19:05:31 +02:00
|
|
|
if (type == TYPE_MENU)
|
|
|
|
{
|
|
|
|
typval_T tv;
|
|
|
|
callback_T callback;
|
|
|
|
|
|
|
|
tv.v_type = VAR_STRING;
|
|
|
|
tv.vval.v_string = (char_u *)"popup_filter_menu";
|
|
|
|
callback = get_callback(&tv);
|
|
|
|
if (callback.cb_name != NULL)
|
|
|
|
set_callback(&wp->w_filter_cb, &callback);
|
|
|
|
|
|
|
|
wp->w_p_wrap = 0;
|
2019-07-18 13:46:42 +02:00
|
|
|
wp->w_popup_flags |= POPF_CURSORLINE;
|
2019-06-16 19:05:31 +02:00
|
|
|
}
|
|
|
|
|
2019-07-18 21:43:07 +02:00
|
|
|
if (type == TYPE_PREVIEW)
|
|
|
|
{
|
|
|
|
wp->w_popup_drag = 1;
|
|
|
|
wp->w_popup_close = POPCLOSE_BUTTON;
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
wp->w_popup_border[i] = 1;
|
|
|
|
parse_previewpopup(wp);
|
|
|
|
}
|
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
VIM_CLEAR(wp->w_border_highlight[i]);
|
|
|
|
for (i = 0; i < 8; ++i)
|
|
|
|
wp->w_border_char[i] = 0;
|
2019-06-25 05:15:58 +02:00
|
|
|
wp->w_want_scrollbar = 1;
|
2019-06-28 04:06:50 +02:00
|
|
|
wp->w_popup_fixed = 0;
|
2019-06-16 22:54:14 +02:00
|
|
|
|
2019-07-18 21:43:07 +02:00
|
|
|
if (d != NULL)
|
|
|
|
// Deal with options.
|
|
|
|
apply_options(wp, d);
|
2019-05-25 19:51:39 +02:00
|
|
|
|
2019-06-23 01:03:51 +02:00
|
|
|
#ifdef FEAT_TIMERS
|
2019-06-12 22:42:41 +02:00
|
|
|
if (type == TYPE_NOTIFICATION && wp->w_popup_timer == NULL)
|
|
|
|
popup_add_timeout(wp, 3000);
|
2019-06-23 01:03:51 +02:00
|
|
|
#endif
|
2019-06-12 22:42:41 +02:00
|
|
|
|
2019-05-27 21:54:10 +02:00
|
|
|
popup_adjust_position(wp);
|
2019-05-25 19:51:39 +02:00
|
|
|
|
|
|
|
wp->w_vsep_width = 0;
|
|
|
|
|
|
|
|
redraw_all_later(NOT_VALID);
|
2019-06-08 16:01:13 +02:00
|
|
|
popup_mask_refresh = TRUE;
|
2019-06-16 19:05:31 +02:00
|
|
|
|
|
|
|
return wp;
|
2019-05-25 19:51:39 +02:00
|
|
|
}
|
|
|
|
|
2019-06-10 13:11:22 +02:00
|
|
|
/*
|
|
|
|
* popup_clear()
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
|
|
|
|
{
|
|
|
|
close_all_popups();
|
|
|
|
}
|
|
|
|
|
2019-05-30 19:25:06 +02:00
|
|
|
/*
|
|
|
|
* popup_create({text}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_create(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
2019-06-02 19:53:44 +02:00
|
|
|
popup_create(argvars, rettv, TYPE_NORMAL);
|
2019-05-30 19:25:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* popup_atcursor({text}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_atcursor(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
2019-06-02 19:53:44 +02:00
|
|
|
popup_create(argvars, rettv, TYPE_ATCURSOR);
|
2019-05-30 19:25:06 +02:00
|
|
|
}
|
|
|
|
|
2019-07-07 18:28:14 +02:00
|
|
|
/*
|
|
|
|
* popup_beval({text}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_beval(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
|
|
|
popup_create(argvars, rettv, TYPE_BEVAL);
|
|
|
|
}
|
|
|
|
|
2019-06-01 22:49:29 +02:00
|
|
|
/*
|
|
|
|
* Invoke the close callback for window "wp" with value "result".
|
|
|
|
* Careful: The callback may make "wp" invalid!
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
invoke_popup_callback(win_T *wp, typval_T *result)
|
|
|
|
{
|
|
|
|
typval_T rettv;
|
|
|
|
int dummy;
|
|
|
|
typval_T argv[3];
|
|
|
|
|
|
|
|
argv[0].v_type = VAR_NUMBER;
|
|
|
|
argv[0].vval.v_number = (varnumber_T)wp->w_id;
|
|
|
|
|
|
|
|
if (result != NULL && result->v_type != VAR_UNKNOWN)
|
|
|
|
copy_tv(result, &argv[1]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
argv[1].v_type = VAR_NUMBER;
|
|
|
|
argv[1].vval.v_number = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
argv[2].v_type = VAR_UNKNOWN;
|
|
|
|
|
|
|
|
call_callback(&wp->w_close_cb, -1,
|
|
|
|
&rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL);
|
|
|
|
if (result != NULL)
|
|
|
|
clear_tv(&argv[1]);
|
|
|
|
clear_tv(&rettv);
|
|
|
|
}
|
|
|
|
|
2019-06-02 18:40:06 +02:00
|
|
|
/*
|
|
|
|
* Close popup "wp" and invoke any close callback for it.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
popup_close_and_callback(win_T *wp, typval_T *arg)
|
|
|
|
{
|
|
|
|
int id = wp->w_id;
|
|
|
|
|
|
|
|
if (wp->w_close_cb.cb_name != NULL)
|
|
|
|
// Careful: This may make "wp" invalid.
|
|
|
|
invoke_popup_callback(wp, arg);
|
|
|
|
|
|
|
|
popup_close(id);
|
|
|
|
}
|
|
|
|
|
2019-06-30 18:07:00 +02:00
|
|
|
/*
|
|
|
|
* Close popup "wp" because of a mouse click.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_close_for_mouse_click(win_T *wp)
|
|
|
|
{
|
|
|
|
typval_T res;
|
|
|
|
|
|
|
|
res.v_type = VAR_NUMBER;
|
|
|
|
res.vval.v_number = -2;
|
|
|
|
popup_close_and_callback(wp, &res);
|
|
|
|
}
|
|
|
|
|
2019-07-07 18:28:14 +02:00
|
|
|
static void
|
|
|
|
check_mouse_moved(win_T *wp, win_T *mouse_wp)
|
|
|
|
{
|
|
|
|
// Close the popup when all if these are true:
|
|
|
|
// - the mouse is not on this popup
|
|
|
|
// - "mousemoved" was used
|
|
|
|
// - the mouse is no longer on the same screen row or the mouse column is
|
|
|
|
// outside of the relevant text
|
|
|
|
if (wp != mouse_wp
|
|
|
|
&& wp->w_popup_mouse_row != 0
|
|
|
|
&& (wp->w_popup_mouse_row != mouse_row
|
|
|
|
|| mouse_col < wp->w_popup_mouse_mincol
|
|
|
|
|| mouse_col > wp->w_popup_mouse_maxcol))
|
|
|
|
{
|
|
|
|
typval_T res;
|
|
|
|
|
|
|
|
res.v_type = VAR_NUMBER;
|
|
|
|
res.vval.v_number = -2;
|
2019-07-07 20:43:34 +02:00
|
|
|
// Careful: this makes "wp" invalid.
|
2019-07-07 18:28:14 +02:00
|
|
|
popup_close_and_callback(wp, &res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when the mouse moved: may close a popup with "mousemoved".
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_handle_mouse_moved(void)
|
|
|
|
{
|
2019-07-07 20:43:34 +02:00
|
|
|
win_T *wp, *nextwp;
|
2019-07-07 18:28:14 +02:00
|
|
|
win_T *mouse_wp;
|
|
|
|
int row = mouse_row;
|
|
|
|
int col = mouse_col;
|
|
|
|
|
|
|
|
// find the window where the mouse is in
|
|
|
|
mouse_wp = mouse_find_win(&row, &col, FIND_POPUP);
|
|
|
|
|
2019-07-07 20:43:34 +02:00
|
|
|
for (wp = first_popupwin; wp != NULL; wp = nextwp)
|
|
|
|
{
|
|
|
|
nextwp = wp->w_next;
|
2019-07-07 18:28:14 +02:00
|
|
|
check_mouse_moved(wp, mouse_wp);
|
2019-07-07 20:43:34 +02:00
|
|
|
}
|
|
|
|
for (wp = curtab->tp_first_popupwin; wp != NULL; wp = nextwp)
|
|
|
|
{
|
|
|
|
nextwp = wp->w_next;
|
2019-07-07 18:28:14 +02:00
|
|
|
check_mouse_moved(wp, mouse_wp);
|
2019-07-07 20:43:34 +02:00
|
|
|
}
|
2019-07-07 18:28:14 +02:00
|
|
|
}
|
|
|
|
|
2019-06-16 19:05:31 +02:00
|
|
|
/*
|
|
|
|
* In a filter: check if the typed key is a mouse event that is used for
|
|
|
|
* dragging the popup.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
filter_handle_drag(win_T *wp, int c, typval_T *rettv)
|
|
|
|
{
|
|
|
|
int row = mouse_row;
|
|
|
|
int col = mouse_col;
|
|
|
|
|
|
|
|
if (wp->w_popup_drag
|
|
|
|
&& is_mouse_key(c)
|
|
|
|
&& (wp == popup_dragwin
|
|
|
|
|| wp == mouse_find_win(&row, &col, FIND_POPUP)))
|
|
|
|
// do not consume the key, allow for dragging the popup
|
|
|
|
rettv->vval.v_number = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* popup_filter_menu({text}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_filter_menu(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
|
|
|
int id = tv_get_number(&argvars[0]);
|
|
|
|
win_T *wp = win_id2wp(id);
|
|
|
|
char_u *key = tv_get_string(&argvars[1]);
|
|
|
|
typval_T res;
|
|
|
|
int c;
|
|
|
|
linenr_T old_lnum;
|
|
|
|
|
|
|
|
// If the popup has been closed do not consume the key.
|
|
|
|
if (wp == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
c = *key;
|
|
|
|
if (c == K_SPECIAL && key[1] != NUL)
|
|
|
|
c = TO_SPECIAL(key[1], key[2]);
|
|
|
|
|
|
|
|
// consume all keys until done
|
|
|
|
rettv->vval.v_number = 1;
|
|
|
|
res.v_type = VAR_NUMBER;
|
|
|
|
|
|
|
|
old_lnum = wp->w_cursor.lnum;
|
|
|
|
if ((c == 'k' || c == 'K' || c == K_UP) && wp->w_cursor.lnum > 1)
|
|
|
|
--wp->w_cursor.lnum;
|
|
|
|
if ((c == 'j' || c == 'J' || c == K_DOWN)
|
|
|
|
&& wp->w_cursor.lnum < wp->w_buffer->b_ml.ml_line_count)
|
|
|
|
++wp->w_cursor.lnum;
|
|
|
|
if (old_lnum != wp->w_cursor.lnum)
|
|
|
|
{
|
2019-07-20 16:51:19 +02:00
|
|
|
// caller will call popup_highlight_curline()
|
2019-06-16 19:05:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == 'x' || c == 'X' || c == ESC || c == Ctrl_C)
|
|
|
|
{
|
|
|
|
// Cancelled, invoke callback with -1
|
|
|
|
res.vval.v_number = -1;
|
|
|
|
popup_close_and_callback(wp, &res);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (c == ' ' || c == K_KENTER || c == CAR || c == NL)
|
|
|
|
{
|
|
|
|
// Invoke callback with current index.
|
|
|
|
res.vval.v_number = wp->w_cursor.lnum;
|
|
|
|
popup_close_and_callback(wp, &res);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
filter_handle_drag(wp, c, rettv);
|
|
|
|
}
|
|
|
|
|
2019-06-15 21:46:30 +02:00
|
|
|
/*
|
|
|
|
* popup_filter_yesno({text}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_filter_yesno(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
|
|
|
int id = tv_get_number(&argvars[0]);
|
|
|
|
win_T *wp = win_id2wp(id);
|
|
|
|
char_u *key = tv_get_string(&argvars[1]);
|
|
|
|
typval_T res;
|
2019-06-16 19:05:31 +02:00
|
|
|
int c;
|
2019-06-15 21:46:30 +02:00
|
|
|
|
|
|
|
// If the popup has been closed don't consume the key.
|
|
|
|
if (wp == NULL)
|
|
|
|
return;
|
|
|
|
|
2019-06-16 19:05:31 +02:00
|
|
|
c = *key;
|
|
|
|
if (c == K_SPECIAL && key[1] != NUL)
|
|
|
|
c = TO_SPECIAL(key[1], key[2]);
|
|
|
|
|
2019-06-15 21:46:30 +02:00
|
|
|
// consume all keys until done
|
|
|
|
rettv->vval.v_number = 1;
|
|
|
|
|
2019-06-16 19:05:31 +02:00
|
|
|
if (c == 'y' || c == 'Y')
|
2019-06-15 21:46:30 +02:00
|
|
|
res.vval.v_number = 1;
|
2019-06-16 19:05:31 +02:00
|
|
|
else if (c == 'n' || c == 'N' || c == 'x' || c == 'X' || c == ESC)
|
2019-06-15 21:46:30 +02:00
|
|
|
res.vval.v_number = 0;
|
|
|
|
else
|
|
|
|
{
|
2019-06-16 19:05:31 +02:00
|
|
|
filter_handle_drag(wp, c, rettv);
|
2019-06-15 21:46:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invoke callback
|
|
|
|
res.v_type = VAR_NUMBER;
|
|
|
|
popup_close_and_callback(wp, &res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* popup_dialog({text}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_dialog(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
|
|
|
popup_create(argvars, rettv, TYPE_DIALOG);
|
|
|
|
}
|
|
|
|
|
2019-06-16 19:05:31 +02:00
|
|
|
/*
|
|
|
|
* popup_menu({text}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_menu(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
2019-07-18 13:46:42 +02:00
|
|
|
popup_create(argvars, rettv, TYPE_MENU);
|
2019-06-16 19:05:31 +02:00
|
|
|
}
|
|
|
|
|
2019-06-15 21:46:30 +02:00
|
|
|
/*
|
|
|
|
* popup_notification({text}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_notification(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
|
|
|
popup_create(argvars, rettv, TYPE_NOTIFICATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the popup window with window-ID "id".
|
|
|
|
* If the popup window does not exist NULL is returned.
|
|
|
|
* If the window is not a popup window, and error message is given.
|
|
|
|
*/
|
|
|
|
static win_T *
|
|
|
|
find_popup_win(int id)
|
|
|
|
{
|
|
|
|
win_T *wp = win_id2wp(id);
|
|
|
|
|
2019-06-30 22:16:10 +02:00
|
|
|
if (wp != NULL && !WIN_IS_POPUP(wp))
|
2019-06-15 21:46:30 +02:00
|
|
|
{
|
|
|
|
semsg(_("E993: window %d is not a popup window"), id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return wp;
|
|
|
|
}
|
|
|
|
|
2019-05-25 19:51:39 +02:00
|
|
|
/*
|
|
|
|
* popup_close({id})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_close(typval_T *argvars, typval_T *rettv UNUSED)
|
|
|
|
{
|
2019-05-26 22:17:52 +02:00
|
|
|
int id = (int)tv_get_number(argvars);
|
2019-06-01 22:49:29 +02:00
|
|
|
win_T *wp = find_popup_win(id);
|
2019-05-26 22:17:52 +02:00
|
|
|
|
2019-06-01 22:49:29 +02:00
|
|
|
if (wp != NULL)
|
2019-06-02 18:40:06 +02:00
|
|
|
popup_close_and_callback(wp, &argvars[1]);
|
2019-05-26 22:17:52 +02:00
|
|
|
}
|
2019-05-25 19:51:39 +02:00
|
|
|
|
2019-05-26 22:17:52 +02:00
|
|
|
/*
|
|
|
|
* popup_hide({id})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_hide(typval_T *argvars, typval_T *rettv UNUSED)
|
|
|
|
{
|
|
|
|
int id = (int)tv_get_number(argvars);
|
|
|
|
win_T *wp = find_popup_win(id);
|
|
|
|
|
2019-05-27 10:04:40 +02:00
|
|
|
if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) == 0)
|
2019-05-26 22:17:52 +02:00
|
|
|
{
|
2019-05-27 10:04:40 +02:00
|
|
|
wp->w_popup_flags |= POPF_HIDDEN;
|
2019-05-30 22:32:34 +02:00
|
|
|
--wp->w_buffer->b_nwindows;
|
2019-05-26 22:17:52 +02:00
|
|
|
redraw_all_later(NOT_VALID);
|
2019-06-08 16:01:13 +02:00
|
|
|
popup_mask_refresh = TRUE;
|
2019-05-26 22:17:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* popup_show({id})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_show(typval_T *argvars, typval_T *rettv UNUSED)
|
|
|
|
{
|
|
|
|
int id = (int)tv_get_number(argvars);
|
|
|
|
win_T *wp = find_popup_win(id);
|
|
|
|
|
2019-05-27 10:04:40 +02:00
|
|
|
if (wp != NULL && (wp->w_popup_flags & POPF_HIDDEN) != 0)
|
2019-05-26 22:17:52 +02:00
|
|
|
{
|
2019-05-27 10:04:40 +02:00
|
|
|
wp->w_popup_flags &= ~POPF_HIDDEN;
|
2019-05-30 22:32:34 +02:00
|
|
|
++wp->w_buffer->b_nwindows;
|
2019-05-26 22:17:52 +02:00
|
|
|
redraw_all_later(NOT_VALID);
|
2019-06-08 16:01:13 +02:00
|
|
|
popup_mask_refresh = TRUE;
|
2019-05-26 22:17:52 +02:00
|
|
|
}
|
2019-05-25 19:51:39 +02:00
|
|
|
}
|
|
|
|
|
2019-06-16 15:32:14 +02:00
|
|
|
/*
|
|
|
|
* popup_settext({id}, {text})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED)
|
|
|
|
{
|
|
|
|
int id = (int)tv_get_number(&argvars[0]);
|
|
|
|
win_T *wp = find_popup_win(id);
|
|
|
|
|
|
|
|
if (wp != NULL)
|
|
|
|
{
|
2019-06-30 22:16:10 +02:00
|
|
|
if (argvars[1].v_type != VAR_STRING && argvars[1].v_type != VAR_LIST)
|
|
|
|
semsg(_(e_invarg2), tv_get_string(&argvars[1]));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
popup_set_buffer_text(wp->w_buffer, argvars[1]);
|
|
|
|
popup_adjust_position(wp);
|
|
|
|
}
|
2019-06-16 15:32:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 20:10:06 +02:00
|
|
|
static void
|
2019-05-26 22:17:52 +02:00
|
|
|
popup_free(win_T *wp)
|
2019-05-26 20:10:06 +02:00
|
|
|
{
|
2019-07-20 16:51:19 +02:00
|
|
|
sign_undefine_by_name(popup_get_sign_name(wp), FALSE);
|
2019-05-29 21:44:40 +02:00
|
|
|
wp->w_buffer->b_locked = FALSE;
|
2019-05-26 20:10:06 +02:00
|
|
|
if (wp->w_winrow + wp->w_height >= cmdline_row)
|
|
|
|
clear_cmdline = TRUE;
|
|
|
|
win_free_popup(wp);
|
2019-07-20 16:51:19 +02:00
|
|
|
|
2019-05-26 20:10:06 +02:00
|
|
|
redraw_all_later(NOT_VALID);
|
2019-06-08 16:01:13 +02:00
|
|
|
popup_mask_refresh = TRUE;
|
2019-05-26 20:10:06 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 14:11:23 +02:00
|
|
|
/*
|
|
|
|
* Close a popup window by Window-id.
|
2019-06-01 22:49:29 +02:00
|
|
|
* Does not invoke the callback.
|
2019-05-26 14:11:23 +02:00
|
|
|
*/
|
2019-05-25 19:51:39 +02:00
|
|
|
void
|
2019-05-26 14:11:23 +02:00
|
|
|
popup_close(int id)
|
2019-05-25 19:51:39 +02:00
|
|
|
{
|
|
|
|
win_T *wp;
|
2019-05-26 14:11:23 +02:00
|
|
|
tabpage_T *tp;
|
2019-05-25 19:51:39 +02:00
|
|
|
win_T *prev = NULL;
|
|
|
|
|
2019-05-26 14:11:23 +02:00
|
|
|
// go through global popups
|
2019-05-25 19:51:39 +02:00
|
|
|
for (wp = first_popupwin; wp != NULL; prev = wp, wp = wp->w_next)
|
2019-05-26 14:11:23 +02:00
|
|
|
if (wp->w_id == id)
|
2019-05-25 19:51:39 +02:00
|
|
|
{
|
|
|
|
if (prev == NULL)
|
|
|
|
first_popupwin = wp->w_next;
|
|
|
|
else
|
|
|
|
prev->w_next = wp->w_next;
|
2019-05-26 22:17:52 +02:00
|
|
|
popup_free(wp);
|
2019-05-26 14:11:23 +02:00
|
|
|
return;
|
2019-05-25 19:51:39 +02:00
|
|
|
}
|
|
|
|
|
2019-05-26 14:11:23 +02:00
|
|
|
// go through tab-local popups
|
|
|
|
FOR_ALL_TABPAGES(tp)
|
|
|
|
popup_close_tabpage(tp, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close a popup window with Window-id "id" in tabpage "tp".
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_close_tabpage(tabpage_T *tp, int id)
|
|
|
|
{
|
|
|
|
win_T *wp;
|
2019-05-26 18:48:13 +02:00
|
|
|
win_T **root = &tp->tp_first_popupwin;
|
2019-05-26 14:11:23 +02:00
|
|
|
win_T *prev = NULL;
|
|
|
|
|
|
|
|
for (wp = *root; wp != NULL; prev = wp, wp = wp->w_next)
|
|
|
|
if (wp->w_id == id)
|
|
|
|
{
|
|
|
|
if (prev == NULL)
|
|
|
|
*root = wp->w_next;
|
|
|
|
else
|
|
|
|
prev->w_next = wp->w_next;
|
2019-05-26 22:17:52 +02:00
|
|
|
popup_free(wp);
|
2019-05-26 14:11:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-05-25 19:51:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
close_all_popups(void)
|
|
|
|
{
|
|
|
|
while (first_popupwin != NULL)
|
|
|
|
popup_close(first_popupwin->w_id);
|
2019-05-26 18:48:13 +02:00
|
|
|
while (curtab->tp_first_popupwin != NULL)
|
|
|
|
popup_close(curtab->tp_first_popupwin->w_id);
|
2019-05-25 19:51:39 +02:00
|
|
|
}
|
|
|
|
|
2019-05-27 21:54:10 +02:00
|
|
|
/*
|
|
|
|
* popup_move({id}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_move(typval_T *argvars, typval_T *rettv UNUSED)
|
|
|
|
{
|
2019-06-16 22:54:14 +02:00
|
|
|
dict_T *dict;
|
2019-05-27 21:54:10 +02:00
|
|
|
int id = (int)tv_get_number(argvars);
|
|
|
|
win_T *wp = find_popup_win(id);
|
|
|
|
|
|
|
|
if (wp == NULL)
|
|
|
|
return; // invalid {id}
|
|
|
|
|
|
|
|
if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL)
|
|
|
|
{
|
|
|
|
emsg(_(e_dictreq));
|
|
|
|
return;
|
|
|
|
}
|
2019-06-16 22:54:14 +02:00
|
|
|
dict = argvars[1].vval.v_dict;
|
2019-05-27 21:54:10 +02:00
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
apply_move_options(wp, dict);
|
2019-05-27 21:54:10 +02:00
|
|
|
|
|
|
|
if (wp->w_winrow + wp->w_height >= cmdline_row)
|
|
|
|
clear_cmdline = TRUE;
|
|
|
|
popup_adjust_position(wp);
|
|
|
|
}
|
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
/*
|
|
|
|
* popup_setoptions({id}, {options})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
|
|
|
|
{
|
|
|
|
dict_T *dict;
|
|
|
|
int id = (int)tv_get_number(argvars);
|
|
|
|
win_T *wp = find_popup_win(id);
|
2019-06-25 05:15:58 +02:00
|
|
|
linenr_T old_firstline;
|
2019-06-16 22:54:14 +02:00
|
|
|
|
|
|
|
if (wp == NULL)
|
|
|
|
return; // invalid {id}
|
|
|
|
|
|
|
|
if (argvars[1].v_type != VAR_DICT || argvars[1].vval.v_dict == NULL)
|
|
|
|
{
|
|
|
|
emsg(_(e_dictreq));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dict = argvars[1].vval.v_dict;
|
2019-06-25 05:15:58 +02:00
|
|
|
old_firstline = wp->w_firstline;
|
2019-06-16 22:54:14 +02:00
|
|
|
|
|
|
|
apply_move_options(wp, dict);
|
|
|
|
apply_general_options(wp, dict);
|
|
|
|
|
2019-06-25 05:15:58 +02:00
|
|
|
if (old_firstline != wp->w_firstline)
|
|
|
|
redraw_win_later(wp, NOT_VALID);
|
2019-06-17 20:05:45 +02:00
|
|
|
popup_mask_refresh = TRUE;
|
2019-07-18 13:46:42 +02:00
|
|
|
popup_highlight_curline(wp);
|
2019-06-16 22:54:14 +02:00
|
|
|
popup_adjust_position(wp);
|
|
|
|
}
|
|
|
|
|
2019-05-29 20:26:46 +02:00
|
|
|
/*
|
2019-05-30 21:24:26 +02:00
|
|
|
* popup_getpos({id})
|
2019-05-29 20:26:46 +02:00
|
|
|
*/
|
|
|
|
void
|
2019-05-30 21:24:26 +02:00
|
|
|
f_popup_getpos(typval_T *argvars, typval_T *rettv)
|
2019-05-29 20:26:46 +02:00
|
|
|
{
|
|
|
|
dict_T *dict;
|
|
|
|
int id = (int)tv_get_number(argvars);
|
|
|
|
win_T *wp = find_popup_win(id);
|
2019-06-01 20:16:48 +02:00
|
|
|
int top_extra;
|
|
|
|
int left_extra;
|
2019-05-29 20:26:46 +02:00
|
|
|
|
|
|
|
if (rettv_dict_alloc(rettv) == OK)
|
|
|
|
{
|
|
|
|
if (wp == NULL)
|
|
|
|
return; // invalid {id}
|
2019-06-16 20:09:10 +02:00
|
|
|
top_extra = popup_top_extra(wp);
|
2019-06-01 20:16:48 +02:00
|
|
|
left_extra = wp->w_popup_border[3] + wp->w_popup_padding[3];
|
|
|
|
|
2019-05-29 20:26:46 +02:00
|
|
|
dict = rettv->vval.v_dict;
|
2019-06-01 20:16:48 +02:00
|
|
|
|
2019-05-29 20:26:46 +02:00
|
|
|
dict_add_number(dict, "line", wp->w_winrow + 1);
|
|
|
|
dict_add_number(dict, "col", wp->w_wincol + 1);
|
2019-06-12 22:42:41 +02:00
|
|
|
dict_add_number(dict, "width", wp->w_width + left_extra
|
|
|
|
+ wp->w_popup_border[1] + wp->w_popup_padding[1]);
|
|
|
|
dict_add_number(dict, "height", wp->w_height + top_extra
|
|
|
|
+ wp->w_popup_border[2] + wp->w_popup_padding[2]);
|
2019-06-01 20:16:48 +02:00
|
|
|
|
|
|
|
dict_add_number(dict, "core_line", wp->w_winrow + 1 + top_extra);
|
|
|
|
dict_add_number(dict, "core_col", wp->w_wincol + 1 + left_extra);
|
|
|
|
dict_add_number(dict, "core_width", wp->w_width);
|
|
|
|
dict_add_number(dict, "core_height", wp->w_height);
|
|
|
|
|
2019-06-25 05:15:58 +02:00
|
|
|
dict_add_number(dict, "scrollbar", wp->w_has_scrollbar);
|
2019-06-26 03:40:36 +02:00
|
|
|
dict_add_number(dict, "firstline", wp->w_topline);
|
2019-05-30 14:29:45 +02:00
|
|
|
dict_add_number(dict, "visible",
|
2019-06-02 16:51:21 +02:00
|
|
|
win_valid(wp) && (wp->w_popup_flags & POPF_HIDDEN) == 0);
|
2019-05-30 14:29:45 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-12 21:07:54 +02:00
|
|
|
/*
|
|
|
|
* popup_locate({row}, {col})
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_locate(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
|
|
|
int row = tv_get_number(&argvars[0]) - 1;
|
|
|
|
int col = tv_get_number(&argvars[1]) - 1;
|
|
|
|
win_T *wp;
|
|
|
|
|
|
|
|
wp = mouse_find_win(&row, &col, FIND_POPUP);
|
|
|
|
if (WIN_IS_POPUP(wp))
|
|
|
|
rettv->vval.v_number = wp->w_id;
|
|
|
|
}
|
2019-05-30 14:29:45 +02:00
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
/*
|
|
|
|
* For popup_getoptions(): add a "border" or "padding" entry to "dict".
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
get_padding_border(dict_T *dict, int *array, char *name)
|
|
|
|
{
|
|
|
|
list_T *list;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (array[0] == 0 && array[1] == 0 && array[2] == 0 && array[3] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list = list_alloc();
|
|
|
|
if (list != NULL)
|
|
|
|
{
|
|
|
|
dict_add_list(dict, name, list);
|
|
|
|
if (array[0] != 1 || array[1] != 1 || array[2] != 1 || array[3] != 1)
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
list_append_number(list, array[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For popup_getoptions(): add a "borderhighlight" entry to "dict".
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
get_borderhighlight(dict_T *dict, win_T *wp)
|
|
|
|
{
|
|
|
|
list_T *list;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
if (wp->w_border_highlight[i] != NULL)
|
|
|
|
break;
|
|
|
|
if (i == 4)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list = list_alloc();
|
|
|
|
if (list != NULL)
|
|
|
|
{
|
|
|
|
dict_add_list(dict, "borderhighlight", list);
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
list_append_string(list, wp->w_border_highlight[i], -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For popup_getoptions(): add a "borderchars" entry to "dict".
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
get_borderchars(dict_T *dict, win_T *wp)
|
|
|
|
{
|
|
|
|
list_T *list;
|
|
|
|
int i;
|
|
|
|
char_u buf[NUMBUFLEN];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; ++i)
|
|
|
|
if (wp->w_border_char[i] != 0)
|
|
|
|
break;
|
|
|
|
if (i == 8)
|
|
|
|
return;
|
|
|
|
|
|
|
|
list = list_alloc();
|
|
|
|
if (list != NULL)
|
|
|
|
{
|
|
|
|
dict_add_list(dict, "borderchars", list);
|
|
|
|
for (i = 0; i < 8; ++i)
|
|
|
|
{
|
|
|
|
len = mb_char2bytes(wp->w_border_char[i], buf);
|
|
|
|
list_append_string(list, buf, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-07-07 18:28:14 +02:00
|
|
|
* For popup_getoptions(): add a "moved" and "mousemoved" entry to "dict".
|
2019-06-16 22:54:14 +02:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
get_moved_list(dict_T *dict, win_T *wp)
|
|
|
|
{
|
|
|
|
list_T *list;
|
|
|
|
|
|
|
|
list = list_alloc();
|
|
|
|
if (list != NULL)
|
|
|
|
{
|
|
|
|
dict_add_list(dict, "moved", list);
|
2019-07-07 18:28:14 +02:00
|
|
|
list_append_number(list, wp->w_popup_lnum);
|
2019-06-16 22:54:14 +02:00
|
|
|
list_append_number(list, wp->w_popup_mincol);
|
|
|
|
list_append_number(list, wp->w_popup_maxcol);
|
|
|
|
}
|
2019-07-07 18:28:14 +02:00
|
|
|
list = list_alloc();
|
|
|
|
if (list != NULL)
|
|
|
|
{
|
|
|
|
dict_add_list(dict, "mousemoved", list);
|
|
|
|
list_append_number(list, wp->w_popup_mouse_row);
|
|
|
|
list_append_number(list, wp->w_popup_mouse_mincol);
|
|
|
|
list_append_number(list, wp->w_popup_mouse_maxcol);
|
|
|
|
}
|
2019-06-16 22:54:14 +02:00
|
|
|
}
|
|
|
|
|
2019-05-30 14:29:45 +02:00
|
|
|
/*
|
2019-06-08 16:01:13 +02:00
|
|
|
* popup_getoptions({id})
|
2019-05-30 14:29:45 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
f_popup_getoptions(typval_T *argvars, typval_T *rettv)
|
|
|
|
{
|
|
|
|
dict_T *dict;
|
|
|
|
int id = (int)tv_get_number(argvars);
|
|
|
|
win_T *wp = find_popup_win(id);
|
2019-06-20 02:31:49 +02:00
|
|
|
tabpage_T *tp;
|
2019-05-30 21:24:26 +02:00
|
|
|
int i;
|
2019-05-30 14:29:45 +02:00
|
|
|
|
|
|
|
if (rettv_dict_alloc(rettv) == OK)
|
|
|
|
{
|
|
|
|
if (wp == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dict = rettv->vval.v_dict;
|
|
|
|
dict_add_number(dict, "line", wp->w_wantline);
|
|
|
|
dict_add_number(dict, "col", wp->w_wantcol);
|
|
|
|
dict_add_number(dict, "minwidth", wp->w_minwidth);
|
|
|
|
dict_add_number(dict, "minheight", wp->w_minheight);
|
|
|
|
dict_add_number(dict, "maxheight", wp->w_maxheight);
|
|
|
|
dict_add_number(dict, "maxwidth", wp->w_maxwidth);
|
2019-06-12 23:40:01 +02:00
|
|
|
dict_add_number(dict, "firstline", wp->w_firstline);
|
2019-06-25 05:15:58 +02:00
|
|
|
dict_add_number(dict, "scrollbar", wp->w_want_scrollbar);
|
2019-05-30 14:29:45 +02:00
|
|
|
dict_add_number(dict, "zindex", wp->w_zindex);
|
2019-06-02 14:49:56 +02:00
|
|
|
dict_add_number(dict, "fixed", wp->w_popup_fixed);
|
2019-06-16 22:54:14 +02:00
|
|
|
dict_add_string(dict, "title", wp->w_popup_title);
|
|
|
|
dict_add_number(dict, "wrap", wp->w_p_wrap);
|
|
|
|
dict_add_number(dict, "drag", wp->w_popup_drag);
|
2019-07-20 16:51:19 +02:00
|
|
|
dict_add_number(dict, "cursorline",
|
|
|
|
(wp->w_popup_flags & POPF_CURSORLINE) != 0);
|
2019-06-16 22:54:14 +02:00
|
|
|
dict_add_string(dict, "highlight", wp->w_p_wcr);
|
2019-06-26 05:13:57 +02:00
|
|
|
if (wp->w_scrollbar_highlight != NULL)
|
|
|
|
dict_add_string(dict, "scrollbarhighlight",
|
|
|
|
wp->w_scrollbar_highlight);
|
|
|
|
if (wp->w_thumb_highlight != NULL)
|
|
|
|
dict_add_string(dict, "thumbhighlight", wp->w_thumb_highlight);
|
2019-06-16 22:54:14 +02:00
|
|
|
|
2019-06-20 02:31:49 +02:00
|
|
|
// find the tabpage that holds this popup
|
|
|
|
i = 1;
|
|
|
|
FOR_ALL_TABPAGES(tp)
|
|
|
|
{
|
|
|
|
win_T *p;
|
|
|
|
|
|
|
|
for (p = tp->tp_first_popupwin; p != NULL; p = wp->w_next)
|
|
|
|
if (p->w_id == id)
|
|
|
|
break;
|
|
|
|
if (p != NULL)
|
|
|
|
break;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (tp == NULL)
|
|
|
|
i = -1; // must be global
|
|
|
|
else if (tp == curtab)
|
|
|
|
i = 0;
|
|
|
|
dict_add_number(dict, "tabpage", i);
|
|
|
|
|
2019-06-16 22:54:14 +02:00
|
|
|
get_padding_border(dict, wp->w_popup_padding, "padding");
|
|
|
|
get_padding_border(dict, wp->w_popup_border, "border");
|
|
|
|
get_borderhighlight(dict, wp);
|
|
|
|
get_borderchars(dict, wp);
|
|
|
|
get_moved_list(dict, wp);
|
|
|
|
|
|
|
|
if (wp->w_filter_cb.cb_name != NULL)
|
|
|
|
dict_add_callback(dict, "filter", &wp->w_filter_cb);
|
|
|
|
if (wp->w_close_cb.cb_name != NULL)
|
|
|
|
dict_add_callback(dict, "callback", &wp->w_close_cb);
|
2019-05-30 21:24:26 +02:00
|
|
|
|
|
|
|
for (i = 0; i < (int)(sizeof(poppos_entries) / sizeof(poppos_entry_T));
|
|
|
|
++i)
|
|
|
|
if (wp->w_popup_pos == poppos_entries[i].pp_val)
|
|
|
|
{
|
|
|
|
dict_add_string(dict, "pos",
|
|
|
|
(char_u *)poppos_entries[i].pp_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-30 18:07:00 +02:00
|
|
|
dict_add_string(dict, "close", (char_u *)(
|
|
|
|
wp->w_popup_close == POPCLOSE_BUTTON ? "button"
|
|
|
|
: wp->w_popup_close == POPCLOSE_CLICK ? "click" : "none"));
|
|
|
|
|
2019-05-30 14:29:45 +02:00
|
|
|
# if defined(FEAT_TIMERS)
|
|
|
|
dict_add_number(dict, "time", wp->w_popup_timer != NULL
|
|
|
|
? (long)wp->w_popup_timer->tr_interval : 0L);
|
|
|
|
# endif
|
2019-05-29 20:26:46 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-01 14:15:52 +02:00
|
|
|
|
|
|
|
int
|
2019-06-16 15:50:45 +02:00
|
|
|
error_if_popup_window()
|
2019-06-01 14:15:52 +02:00
|
|
|
{
|
2019-06-30 22:16:10 +02:00
|
|
|
if (WIN_IS_POPUP(curwin))
|
2019-06-01 14:15:52 +02:00
|
|
|
{
|
|
|
|
emsg(_("E994: Not allowed in a popup window"));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-01 17:13:36 +02:00
|
|
|
/*
|
|
|
|
* Reset all the POPF_HANDLED flags in global popup windows and popup windows
|
2019-06-15 14:14:31 +02:00
|
|
|
* in the current tab page.
|
2019-06-01 17:13:36 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_reset_handled()
|
|
|
|
{
|
|
|
|
win_T *wp;
|
|
|
|
|
|
|
|
for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
|
|
|
|
wp->w_popup_flags &= ~POPF_HANDLED;
|
|
|
|
for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
|
|
|
|
wp->w_popup_flags &= ~POPF_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the next visible popup where POPF_HANDLED is not set.
|
|
|
|
* Must have called popup_reset_handled() first.
|
|
|
|
* When "lowest" is TRUE find the popup with the lowest zindex, otherwise the
|
|
|
|
* popup with the highest zindex.
|
|
|
|
*/
|
|
|
|
win_T *
|
|
|
|
find_next_popup(int lowest)
|
|
|
|
{
|
|
|
|
win_T *wp;
|
|
|
|
win_T *found_wp;
|
|
|
|
int found_zindex;
|
|
|
|
|
|
|
|
found_zindex = lowest ? INT_MAX : 0;
|
|
|
|
found_wp = NULL;
|
|
|
|
for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
|
|
|
|
if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0
|
|
|
|
&& (lowest ? wp->w_zindex < found_zindex
|
|
|
|
: wp->w_zindex > found_zindex))
|
|
|
|
{
|
|
|
|
found_zindex = wp->w_zindex;
|
|
|
|
found_wp = wp;
|
|
|
|
}
|
|
|
|
for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
|
|
|
|
if ((wp->w_popup_flags & (POPF_HANDLED|POPF_HIDDEN)) == 0
|
|
|
|
&& (lowest ? wp->w_zindex < found_zindex
|
|
|
|
: wp->w_zindex > found_zindex))
|
|
|
|
{
|
|
|
|
found_zindex = wp->w_zindex;
|
|
|
|
found_wp = wp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_wp != NULL)
|
|
|
|
found_wp->w_popup_flags |= POPF_HANDLED;
|
|
|
|
return found_wp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Invoke the filter callback for window "wp" with typed character "c".
|
|
|
|
* Uses the global "mod_mask" for modifiers.
|
|
|
|
* Returns the return value of the filter.
|
|
|
|
* Careful: The filter may make "wp" invalid!
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
invoke_popup_filter(win_T *wp, int c)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
typval_T rettv;
|
|
|
|
int dummy;
|
|
|
|
typval_T argv[3];
|
|
|
|
char_u buf[NUMBUFLEN];
|
2019-07-18 13:46:42 +02:00
|
|
|
linenr_T old_lnum = wp->w_cursor.lnum;
|
2019-06-01 17:13:36 +02:00
|
|
|
|
2019-06-15 21:46:30 +02:00
|
|
|
// Emergency exit: CTRL-C closes the popup.
|
|
|
|
if (c == Ctrl_C)
|
|
|
|
{
|
|
|
|
rettv.v_type = VAR_NUMBER;
|
|
|
|
rettv.vval.v_number = -1;
|
|
|
|
popup_close_and_callback(wp, &rettv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-06-01 17:13:36 +02:00
|
|
|
argv[0].v_type = VAR_NUMBER;
|
|
|
|
argv[0].vval.v_number = (varnumber_T)wp->w_id;
|
|
|
|
|
|
|
|
// Convert the number to a string, so that the function can use:
|
|
|
|
// if a:c == "\<F2>"
|
|
|
|
buf[special_to_buf(c, mod_mask, TRUE, buf)] = NUL;
|
|
|
|
argv[1].v_type = VAR_STRING;
|
|
|
|
argv[1].vval.v_string = vim_strsave(buf);
|
|
|
|
|
|
|
|
argv[2].v_type = VAR_UNKNOWN;
|
|
|
|
|
2019-06-15 21:46:30 +02:00
|
|
|
// NOTE: The callback might close the popup, thus make "wp" invalid.
|
2019-06-01 17:13:36 +02:00
|
|
|
call_callback(&wp->w_filter_cb, -1,
|
|
|
|
&rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL);
|
2019-07-20 16:51:19 +02:00
|
|
|
if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
|
2019-07-18 13:46:42 +02:00
|
|
|
popup_highlight_curline(wp);
|
|
|
|
|
2019-06-01 17:13:36 +02:00
|
|
|
res = tv_get_number(&rettv);
|
|
|
|
vim_free(argv[1].vval.v_string);
|
|
|
|
clear_tv(&rettv);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when "c" was typed: invoke popup filter callbacks.
|
|
|
|
* Returns TRUE when the character was consumed,
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
popup_do_filter(int c)
|
|
|
|
{
|
|
|
|
int res = FALSE;
|
2019-06-15 21:46:30 +02:00
|
|
|
win_T *wp;
|
2019-06-01 17:13:36 +02:00
|
|
|
|
|
|
|
popup_reset_handled();
|
|
|
|
|
|
|
|
while (!res && (wp = find_next_popup(FALSE)) != NULL)
|
|
|
|
if (wp->w_filter_cb.cb_name != NULL)
|
|
|
|
res = invoke_popup_filter(wp, c);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-06-02 18:40:06 +02:00
|
|
|
/*
|
|
|
|
* Called when the cursor moved: check if any popup needs to be closed if the
|
|
|
|
* cursor moved far enough.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
popup_check_cursor_pos()
|
|
|
|
{
|
|
|
|
win_T *wp;
|
|
|
|
typval_T tv;
|
|
|
|
|
|
|
|
popup_reset_handled();
|
|
|
|
while ((wp = find_next_popup(TRUE)) != NULL)
|
|
|
|
if (wp->w_popup_curwin != NULL
|
|
|
|
&& (curwin != wp->w_popup_curwin
|
|
|
|
|| curwin->w_cursor.lnum != wp->w_popup_lnum
|
|
|
|
|| curwin->w_cursor.col < wp->w_popup_mincol
|
|
|
|
|| curwin->w_cursor.col > wp->w_popup_maxcol))
|
|
|
|
{
|
|
|
|
tv.v_type = VAR_NUMBER;
|
|
|
|
tv.vval.v_number = -1;
|
|
|
|
popup_close_and_callback(wp, &tv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-23 00:15:57 +02:00
|
|
|
/*
|
|
|
|
* Return TRUE if "col" / "line" matches with an entry in w_popup_mask.
|
|
|
|
* "col" and "line" are screen coordinates.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
popup_masked(win_T *wp, int screencol, int screenline)
|
|
|
|
{
|
2019-07-02 23:13:53 +02:00
|
|
|
int col = screencol - wp->w_wincol + 1 + wp->w_popup_leftoff;
|
2019-06-23 00:15:57 +02:00
|
|
|
int line = screenline - wp->w_winrow + 1;
|
|
|
|
listitem_T *lio, *li;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
if (wp->w_popup_mask == NULL)
|
|
|
|
return FALSE;
|
|
|
|
width = popup_width(wp);
|
|
|
|
height = popup_height(wp);
|
|
|
|
|
|
|
|
for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next)
|
|
|
|
{
|
|
|
|
int cols, cole;
|
|
|
|
int lines, linee;
|
|
|
|
|
|
|
|
li = lio->li_tv.vval.v_list->lv_first;
|
|
|
|
cols = tv_get_number(&li->li_tv);
|
|
|
|
if (cols < 0)
|
|
|
|
cols = width + cols + 1;
|
|
|
|
if (col < cols)
|
|
|
|
continue;
|
|
|
|
li = li->li_next;
|
|
|
|
cole = tv_get_number(&li->li_tv);
|
|
|
|
if (cole < 0)
|
|
|
|
cole = width + cole + 1;
|
|
|
|
if (col > cole)
|
|
|
|
continue;
|
|
|
|
li = li->li_next;
|
|
|
|
lines = tv_get_number(&li->li_tv);
|
|
|
|
if (lines < 0)
|
|
|
|
lines = height + lines + 1;
|
|
|
|
if (line < lines)
|
|
|
|
continue;
|
|
|
|
li = li->li_next;
|
|
|
|
linee = tv_get_number(&li->li_tv);
|
|
|
|
if (linee < 0)
|
|
|
|
linee = height + linee + 1;
|
|
|
|
if (line > linee)
|
|
|
|
continue;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set flags in popup_transparent[] for window "wp" to "val".
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_popup_transparent(win_T *wp, int val)
|
|
|
|
{
|
|
|
|
if (wp->w_popup_mask != NULL)
|
|
|
|
{
|
|
|
|
int width = popup_width(wp);
|
|
|
|
int height = popup_height(wp);
|
|
|
|
listitem_T *lio, *li;
|
|
|
|
int cols, cole;
|
|
|
|
int lines, linee;
|
|
|
|
int col, line;
|
|
|
|
|
|
|
|
for (lio = wp->w_popup_mask->lv_first; lio != NULL; lio = lio->li_next)
|
|
|
|
{
|
|
|
|
li = lio->li_tv.vval.v_list->lv_first;
|
|
|
|
cols = tv_get_number(&li->li_tv);
|
|
|
|
if (cols < 0)
|
|
|
|
cols = width + cols + 1;
|
|
|
|
li = li->li_next;
|
|
|
|
cole = tv_get_number(&li->li_tv);
|
|
|
|
if (cole < 0)
|
|
|
|
cole = width + cole + 1;
|
|
|
|
li = li->li_next;
|
|
|
|
lines = tv_get_number(&li->li_tv);
|
|
|
|
if (lines < 0)
|
|
|
|
lines = height + lines + 1;
|
|
|
|
li = li->li_next;
|
|
|
|
linee = tv_get_number(&li->li_tv);
|
|
|
|
if (linee < 0)
|
|
|
|
linee = height + linee + 1;
|
|
|
|
|
|
|
|
--cols;
|
2019-07-02 23:13:53 +02:00
|
|
|
cols -= wp->w_popup_leftoff;
|
2019-06-28 04:06:50 +02:00
|
|
|
if (cols < 0)
|
|
|
|
cols = 0;
|
2019-07-02 23:13:53 +02:00
|
|
|
cole -= wp->w_popup_leftoff;
|
2019-06-23 00:15:57 +02:00
|
|
|
--lines;
|
2019-06-28 04:06:50 +02:00
|
|
|
if (lines < 0)
|
|
|
|
lines = 0;
|
2019-07-12 16:05:45 +02:00
|
|
|
for (line = lines; line < linee
|
|
|
|
&& line + wp->w_winrow < screen_Rows; ++line)
|
|
|
|
for (col = cols; col < cole
|
|
|
|
&& col + wp->w_wincol < screen_Columns; ++col)
|
2019-06-23 00:15:57 +02:00
|
|
|
popup_transparent[(line + wp->w_winrow) * screen_Columns
|
|
|
|
+ col + wp->w_wincol] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-14 19:23:57 +02:00
|
|
|
/*
|
|
|
|
* Update "popup_mask" if needed.
|
|
|
|
* Also recomputes the popup size and positions.
|
|
|
|
* Also updates "popup_visible".
|
|
|
|
* Also marks window lines for redrawing.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
may_update_popup_mask(int type)
|
|
|
|
{
|
|
|
|
win_T *wp;
|
|
|
|
short *mask;
|
|
|
|
int line, col;
|
|
|
|
int redraw_all = FALSE;
|
|
|
|
|
|
|
|
// Need to recompute when switching tabs.
|
|
|
|
// Also recompute when the type is CLEAR or NOT_VALID, something basic
|
|
|
|
// (such as the screen size) must have changed.
|
|
|
|
if (popup_mask_tab != curtab || type >= NOT_VALID)
|
|
|
|
{
|
|
|
|
popup_mask_refresh = TRUE;
|
|
|
|
redraw_all = TRUE;
|
|
|
|
}
|
|
|
|
if (!popup_mask_refresh)
|
|
|
|
{
|
|
|
|
// Check if any buffer has changed.
|
|
|
|
for (wp = first_popupwin; wp != NULL; wp = wp->w_next)
|
|
|
|
if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer))
|
|
|
|
popup_mask_refresh = TRUE;
|
|
|
|
for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
|
|
|
|
if (wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer))
|
|
|
|
popup_mask_refresh = TRUE;
|
|
|
|
if (!popup_mask_refresh)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need to update the mask, something has changed.
|
|
|
|
popup_mask_refresh = FALSE;
|
|
|
|
popup_mask_tab = curtab;
|
|
|
|
popup_visible = FALSE;
|
|
|
|
|
|
|
|
// If redrawing everything, just update "popup_mask".
|
|
|
|
// If redrawing only what is needed, update "popup_mask_next" and then
|
|
|
|
// compare with "popup_mask" to see what changed.
|
|
|
|
if (type >= SOME_VALID)
|
|
|
|
mask = popup_mask;
|
|
|
|
else
|
|
|
|
mask = popup_mask_next;
|
|
|
|
vim_memset(mask, 0, screen_Rows * screen_Columns * sizeof(short));
|
|
|
|
|
|
|
|
// Find the window with the lowest zindex that hasn't been handled yet,
|
|
|
|
// so that the window with a higher zindex overwrites the value in
|
|
|
|
// popup_mask.
|
|
|
|
popup_reset_handled();
|
|
|
|
while ((wp = find_next_popup(TRUE)) != NULL)
|
|
|
|
{
|
2019-07-02 23:13:53 +02:00
|
|
|
int height;
|
|
|
|
int width;
|
2019-06-23 00:15:57 +02:00
|
|
|
|
2019-06-14 19:23:57 +02:00
|
|
|
popup_visible = TRUE;
|
|
|
|
|
|
|
|
// Recompute the position if the text changed.
|
|
|
|
if (redraw_all
|
|
|
|
|| wp->w_popup_last_changedtick != CHANGEDTICK(wp->w_buffer))
|
|
|
|
popup_adjust_position(wp);
|
|
|
|
|
2019-07-02 23:13:53 +02:00
|
|
|
height = popup_height(wp);
|
|
|
|
width = popup_width(wp) - wp->w_popup_leftoff;
|
2019-06-14 19:23:57 +02:00
|
|
|
for (line = wp->w_winrow;
|
2019-06-23 00:15:57 +02:00
|
|
|
line < wp->w_winrow + height && line < screen_Rows; ++line)
|
2019-06-14 19:23:57 +02:00
|
|
|
for (col = wp->w_wincol;
|
2019-06-23 00:15:57 +02:00
|
|
|
col < wp->w_wincol + width && col < screen_Columns; ++col)
|
|
|
|
if (!popup_masked(wp, col, line))
|
|
|
|
mask[line * screen_Columns + col] = wp->w_zindex;
|
2019-06-14 19:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only check which lines are to be updated if not already
|
|
|
|
// updating all lines.
|
|
|
|
if (mask == popup_mask_next)
|
|
|
|
for (line = 0; line < screen_Rows; ++line)
|
|
|
|
{
|
|
|
|
int col_done = 0;
|
|
|
|
|
|
|
|
for (col = 0; col < screen_Columns; ++col)
|
|
|
|
{
|
|
|
|
int off = line * screen_Columns + col;
|
|
|
|
|
|
|
|
if (popup_mask[off] != popup_mask_next[off])
|
|
|
|
{
|
|
|
|
popup_mask[off] = popup_mask_next[off];
|
|
|
|
|
|
|
|
if (line >= cmdline_row)
|
|
|
|
{
|
|
|
|
// the command line needs to be cleared if text below
|
|
|
|
// the popup is now visible.
|
|
|
|
if (!msg_scrolled && popup_mask_next[off] == 0)
|
|
|
|
clear_cmdline = TRUE;
|
|
|
|
}
|
|
|
|
else if (col >= col_done)
|
|
|
|
{
|
|
|
|
linenr_T lnum;
|
|
|
|
int line_cp = line;
|
|
|
|
int col_cp = col;
|
|
|
|
|
|
|
|
// The screen position "line" / "col" needs to be
|
|
|
|
// redrawn. Figure out what window that is and update
|
|
|
|
// w_redraw_top and w_redr_bot. Only needs to be done
|
|
|
|
// once for each window line.
|
|
|
|
wp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP);
|
|
|
|
if (wp != NULL)
|
|
|
|
{
|
|
|
|
if (line_cp >= wp->w_height)
|
|
|
|
// In (or below) status line
|
|
|
|
wp->w_redr_status = TRUE;
|
|
|
|
// compute the position in the buffer line from the
|
|
|
|
// position on the screen
|
|
|
|
else if (mouse_comp_pos(wp, &line_cp, &col_cp,
|
|
|
|
&lnum))
|
|
|
|
// past bottom
|
|
|
|
wp->w_redr_status = TRUE;
|
|
|
|
else
|
|
|
|
redrawWinline(wp, lnum);
|
|
|
|
|
|
|
|
// This line is going to be redrawn, no need to
|
|
|
|
// check until the right side of the window.
|
|
|
|
col_done = wp->w_wincol + wp->w_width - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a string of "len" spaces in IObuff.
|
|
|
|
*/
|
|
|
|
static char_u *
|
|
|
|
get_spaces(int len)
|
|
|
|
{
|
|
|
|
vim_memset(IObuff, ' ', (size_t)len);
|
|
|
|
IObuff[len] = NUL;
|
|
|
|
return IObuff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update popup windows. They are drawn on top of normal windows.
|
|
|
|
* "win_update" is called for each popup window, lowest zindex first.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
update_popups(void (*win_update)(win_T *wp))
|
|
|
|
{
|
|
|
|
win_T *wp;
|
|
|
|
int top_off;
|
2019-07-02 23:13:53 +02:00
|
|
|
int left_extra;
|
2019-06-14 19:23:57 +02:00
|
|
|
int total_width;
|
|
|
|
int total_height;
|
2019-06-16 20:09:10 +02:00
|
|
|
int top_padding;
|
2019-06-14 19:23:57 +02:00
|
|
|
int popup_attr;
|
|
|
|
int border_attr[4];
|
|
|
|
int border_char[8];
|
|
|
|
char_u buf[MB_MAXBYTES];
|
|
|
|
int row;
|
2019-07-03 22:50:41 +02:00
|
|
|
int wincol;
|
2019-07-02 23:13:53 +02:00
|
|
|
int padcol = 0;
|
|
|
|
int padwidth = 0;
|
2019-06-14 19:23:57 +02:00
|
|
|
int i;
|
2019-06-26 04:06:57 +02:00
|
|
|
int sb_thumb_top = 0;
|
|
|
|
int sb_thumb_height = 0;
|
2019-06-26 05:13:57 +02:00
|
|
|
int attr_scroll = 0;
|
|
|
|
int attr_thumb = 0;
|
2019-06-14 19:23:57 +02:00
|
|
|
|
|
|
|
// Find the window with the lowest zindex that hasn't been updated yet,
|
|
|
|
// so that the window with a higher zindex is drawn later, thus goes on
|
|
|
|
// top.
|
|
|
|
popup_reset_handled();
|
|
|
|
while ((wp = find_next_popup(TRUE)) != NULL)
|
|
|
|
{
|
|
|
|
// This drawing uses the zindex of the popup window, so that it's on
|
|
|
|
// top of the text but doesn't draw when another popup with higher
|
|
|
|
// zindex is on top of the character.
|
|
|
|
screen_zindex = wp->w_zindex;
|
|
|
|
|
2019-06-23 00:15:57 +02:00
|
|
|
// Set flags in popup_transparent[] for masked cells.
|
|
|
|
update_popup_transparent(wp, 1);
|
|
|
|
|
2019-06-14 19:23:57 +02:00
|
|
|
// adjust w_winrow and w_wincol for border and padding, since
|
|
|
|
// win_update() doesn't handle them.
|
2019-06-16 20:09:10 +02:00
|
|
|
top_off = popup_top_extra(wp);
|
2019-07-02 23:13:53 +02:00
|
|
|
left_extra = wp->w_popup_padding[3] + wp->w_popup_border[3]
|
|
|
|
- wp->w_popup_leftoff;
|
|
|
|
if (wp->w_wincol + left_extra < 0)
|
|
|
|
left_extra = -wp->w_wincol;
|
2019-06-14 19:23:57 +02:00
|
|
|
wp->w_winrow += top_off;
|
2019-07-02 23:13:53 +02:00
|
|
|
wp->w_wincol += left_extra;
|
2019-06-14 19:23:57 +02:00
|
|
|
|
2019-06-26 01:03:53 +02:00
|
|
|
// Draw the popup text, unless it's off screen.
|
|
|
|
if (wp->w_winrow < screen_Rows && wp->w_wincol < screen_Columns)
|
|
|
|
win_update(wp);
|
2019-06-14 19:23:57 +02:00
|
|
|
|
|
|
|
wp->w_winrow -= top_off;
|
2019-07-02 23:13:53 +02:00
|
|
|
wp->w_wincol -= left_extra;
|
2019-06-14 19:23:57 +02:00
|
|
|
|
2019-07-02 23:13:53 +02:00
|
|
|
total_width = popup_width(wp);
|
|
|
|
total_height = popup_height(wp);
|
2019-06-14 19:23:57 +02:00
|
|
|
popup_attr = get_wcr_attr(wp);
|
|
|
|
|
|
|
|
// We can only use these line drawing characters when 'encoding' is
|
|
|
|
// "utf-8" and 'ambiwidth' is "single".
|
|
|
|
if (enc_utf8 && *p_ambw == 's')
|
|
|
|
{
|
|
|
|
border_char[0] = border_char[2] = 0x2550;
|
|
|
|
border_char[1] = border_char[3] = 0x2551;
|
|
|
|
border_char[4] = 0x2554;
|
|
|
|
border_char[5] = 0x2557;
|
|
|
|
border_char[6] = 0x255d;
|
|
|
|
border_char[7] = 0x255a;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
border_char[0] = border_char[2] = '-';
|
|
|
|
border_char[1] = border_char[3] = '|';
|
|
|
|
for (i = 4; i < 8; ++i)
|
|
|
|
border_char[i] = '+';
|
|
|
|
}
|
|
|
|
for (i = 0; i < 8; ++i)
|
|
|
|
if (wp->w_border_char[i] != 0)
|
|
|
|
border_char[i] = wp->w_border_char[i];
|
|
|
|
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
border_attr[i] = popup_attr;
|
|
|
|
if (wp->w_border_highlight[i] != NULL)
|
|
|
|
border_attr[i] = syn_name2attr(wp->w_border_highlight[i]);
|
|
|
|
}
|
|
|
|
|
2019-07-03 22:50:41 +02:00
|
|
|
wincol = wp->w_wincol - wp->w_popup_leftoff;
|
2019-06-16 20:09:10 +02:00
|
|
|
top_padding = wp->w_popup_padding[0];
|
2019-06-14 19:23:57 +02:00
|
|
|
if (wp->w_popup_border[0] > 0)
|
|
|
|
{
|
|
|
|
// top border
|
|
|
|
screen_fill(wp->w_winrow, wp->w_winrow + 1,
|
2019-07-03 22:50:41 +02:00
|
|
|
wincol < 0 ? 0 : wincol, wincol + total_width,
|
|
|
|
wp->w_popup_border[3] != 0 && wp->w_popup_leftoff == 0
|
2019-06-14 19:23:57 +02:00
|
|
|
? border_char[4] : border_char[0],
|
|
|
|
border_char[0], border_attr[0]);
|
2019-07-03 22:50:41 +02:00
|
|
|
if (wp->w_popup_border[1] > 0 && wp->w_popup_rightoff == 0)
|
2019-06-14 19:23:57 +02:00
|
|
|
{
|
|
|
|
buf[mb_char2bytes(border_char[5], buf)] = NUL;
|
|
|
|
screen_puts(buf, wp->w_winrow,
|
2019-07-03 22:50:41 +02:00
|
|
|
wincol + total_width - 1, border_attr[1]);
|
2019-06-14 19:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-16 20:09:10 +02:00
|
|
|
else if (wp->w_popup_padding[0] == 0 && popup_top_extra(wp) > 0)
|
|
|
|
top_padding = 1;
|
2019-06-14 19:23:57 +02:00
|
|
|
|
2019-07-02 23:13:53 +02:00
|
|
|
if (top_padding > 0 || wp->w_popup_padding[2] > 0)
|
|
|
|
{
|
2019-07-03 22:50:41 +02:00
|
|
|
padcol = wincol + wp->w_popup_border[3];
|
2019-07-02 23:13:53 +02:00
|
|
|
padwidth = wp->w_wincol + total_width - wp->w_popup_border[1]
|
|
|
|
- wp->w_has_scrollbar;
|
|
|
|
if (padcol < 0)
|
|
|
|
{
|
|
|
|
padwidth += padcol;
|
|
|
|
padcol = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-06-16 20:09:10 +02:00
|
|
|
if (top_padding > 0)
|
2019-06-14 19:23:57 +02:00
|
|
|
{
|
|
|
|
// top padding
|
|
|
|
row = wp->w_winrow + wp->w_popup_border[0];
|
2019-07-02 23:13:53 +02:00
|
|
|
screen_fill(row, row + top_padding, padcol, padwidth,
|
2019-06-14 19:23:57 +02:00
|
|
|
' ', ' ', popup_attr);
|
|
|
|
}
|
|
|
|
|
2019-06-16 20:09:10 +02:00
|
|
|
// Title goes on top of border or padding.
|
|
|
|
if (wp->w_popup_title != NULL)
|
|
|
|
screen_puts(wp->w_popup_title, wp->w_winrow, wp->w_wincol + 1,
|
|
|
|
wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr);
|
|
|
|
|
2019-06-25 05:15:58 +02:00
|
|
|
// Compute scrollbar thumb position and size.
|
|
|
|
if (wp->w_has_scrollbar)
|
2019-06-14 19:23:57 +02:00
|
|
|
{
|
2019-06-25 05:15:58 +02:00
|
|
|
linenr_T linecount = wp->w_buffer->b_ml.ml_line_count;
|
|
|
|
|
2019-06-26 03:40:36 +02:00
|
|
|
sb_thumb_height = (wp->w_height * wp->w_height + linecount / 2)
|
|
|
|
/ linecount;
|
2019-06-25 05:15:58 +02:00
|
|
|
if (sb_thumb_height == 0)
|
|
|
|
sb_thumb_height = 1;
|
2019-07-05 20:17:22 +02:00
|
|
|
if (linecount <= wp->w_height)
|
|
|
|
// it just fits, avoid divide by zero
|
|
|
|
sb_thumb_top = 0;
|
|
|
|
else
|
|
|
|
sb_thumb_top = (wp->w_topline - 1
|
|
|
|
+ (linecount / wp->w_height) / 2)
|
2019-06-26 03:40:36 +02:00
|
|
|
* (wp->w_height - sb_thumb_height)
|
|
|
|
/ (linecount - wp->w_height);
|
2019-06-26 05:13:57 +02:00
|
|
|
if (wp->w_scrollbar_highlight != NULL)
|
|
|
|
attr_scroll = syn_name2attr(wp->w_scrollbar_highlight);
|
|
|
|
else
|
|
|
|
attr_scroll = highlight_attr[HLF_PSB];
|
|
|
|
if (wp->w_thumb_highlight != NULL)
|
|
|
|
attr_thumb = syn_name2attr(wp->w_thumb_highlight);
|
|
|
|
else
|
|
|
|
attr_thumb = highlight_attr[HLF_PST];
|
2019-06-25 05:15:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = wp->w_popup_border[0];
|
|
|
|
i < total_height - wp->w_popup_border[2]; ++i)
|
|
|
|
{
|
2019-07-02 23:13:53 +02:00
|
|
|
int pad_left;
|
|
|
|
// left and right padding only needed next to the body
|
|
|
|
int do_padding =
|
|
|
|
i >= wp->w_popup_border[0] + wp->w_popup_padding[0]
|
|
|
|
&& i < total_height - wp->w_popup_border[2]
|
|
|
|
- wp->w_popup_padding[2];
|
|
|
|
|
2019-06-25 05:15:58 +02:00
|
|
|
row = wp->w_winrow + i;
|
|
|
|
|
2019-06-14 19:23:57 +02:00
|
|
|
// left border
|
2019-07-03 22:50:41 +02:00
|
|
|
if (wp->w_popup_border[3] > 0 && wincol >= 0)
|
2019-06-14 19:23:57 +02:00
|
|
|
{
|
|
|
|
buf[mb_char2bytes(border_char[3], buf)] = NUL;
|
2019-07-03 22:50:41 +02:00
|
|
|
screen_puts(buf, row, wincol, border_attr[3]);
|
2019-07-02 23:13:53 +02:00
|
|
|
}
|
|
|
|
if (do_padding && wp->w_popup_padding[3] > 0)
|
|
|
|
{
|
2019-07-03 22:50:41 +02:00
|
|
|
int col = wincol + wp->w_popup_border[3];
|
|
|
|
|
2019-07-02 23:13:53 +02:00
|
|
|
// left padding
|
|
|
|
pad_left = wp->w_popup_padding[3];
|
|
|
|
if (col < 0)
|
|
|
|
{
|
|
|
|
pad_left += col;
|
|
|
|
col = 0;
|
|
|
|
}
|
|
|
|
if (pad_left > 0)
|
|
|
|
screen_puts(get_spaces(pad_left), row, col, popup_attr);
|
2019-06-14 19:23:57 +02:00
|
|
|
}
|
2019-06-25 05:15:58 +02:00
|
|
|
// scrollbar
|
|
|
|
if (wp->w_has_scrollbar)
|
|
|
|
{
|
|
|
|
int line = i - top_off;
|
|
|
|
int scroll_col = wp->w_wincol + total_width - 1
|
|
|
|
- wp->w_popup_border[1];
|
|
|
|
|
|
|
|
if (line >= 0 && line < wp->w_height)
|
|
|
|
screen_putchar(' ', row, scroll_col,
|
|
|
|
line >= sb_thumb_top
|
|
|
|
&& line < sb_thumb_top + sb_thumb_height
|
|
|
|
? attr_thumb : attr_scroll);
|
|
|
|
else
|
|
|
|
screen_putchar(' ', row, scroll_col, popup_attr);
|
|
|
|
}
|
2019-06-14 19:23:57 +02:00
|
|
|
// right border
|
|
|
|
if (wp->w_popup_border[1] > 0)
|
|
|
|
{
|
|
|
|
buf[mb_char2bytes(border_char[1], buf)] = NUL;
|
2019-07-03 22:50:41 +02:00
|
|
|
screen_puts(buf, row, wincol + total_width - 1, border_attr[1]);
|
2019-06-14 19:23:57 +02:00
|
|
|
}
|
|
|
|
// right padding
|
2019-07-02 23:13:53 +02:00
|
|
|
if (do_padding && wp->w_popup_padding[1] > 0)
|
2019-06-14 19:23:57 +02:00
|
|
|
screen_puts(get_spaces(wp->w_popup_padding[1]), row,
|
2019-07-03 22:50:41 +02:00
|
|
|
wincol + wp->w_popup_border[3]
|
2019-07-02 23:13:53 +02:00
|
|
|
+ wp->w_popup_padding[3] + wp->w_width + wp->w_leftcol,
|
|
|
|
popup_attr);
|
2019-06-14 19:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wp->w_popup_padding[2] > 0)
|
|
|
|
{
|
|
|
|
// bottom padding
|
|
|
|
row = wp->w_winrow + wp->w_popup_border[0]
|
|
|
|
+ wp->w_popup_padding[0] + wp->w_height;
|
|
|
|
screen_fill(row, row + wp->w_popup_padding[2],
|
2019-07-02 23:13:53 +02:00
|
|
|
padcol, padwidth, ' ', ' ', popup_attr);
|
2019-06-14 19:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wp->w_popup_border[2] > 0)
|
|
|
|
{
|
|
|
|
// bottom border
|
|
|
|
row = wp->w_winrow + total_height - 1;
|
|
|
|
screen_fill(row , row + 1,
|
2019-07-03 22:50:41 +02:00
|
|
|
wincol < 0 ? 0 : wincol,
|
|
|
|
wincol + total_width,
|
|
|
|
wp->w_popup_border[3] != 0 && wp->w_popup_leftoff == 0
|
2019-06-14 19:23:57 +02:00
|
|
|
? border_char[7] : border_char[2],
|
|
|
|
border_char[2], border_attr[2]);
|
|
|
|
if (wp->w_popup_border[1] > 0)
|
|
|
|
{
|
|
|
|
buf[mb_char2bytes(border_char[6], buf)] = NUL;
|
2019-07-03 22:50:41 +02:00
|
|
|
screen_puts(buf, row, wincol + total_width - 1, border_attr[2]);
|
2019-06-14 19:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 18:07:00 +02:00
|
|
|
if (wp->w_popup_close == POPCLOSE_BUTTON)
|
|
|
|
{
|
|
|
|
// close button goes on top of anything at the top-right corner
|
|
|
|
buf[mb_char2bytes('X', buf)] = NUL;
|
2019-07-03 22:50:41 +02:00
|
|
|
screen_puts(buf, wp->w_winrow, wincol + total_width - 1,
|
2019-06-30 18:07:00 +02:00
|
|
|
wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr);
|
|
|
|
}
|
|
|
|
|
2019-06-23 00:15:57 +02:00
|
|
|
update_popup_transparent(wp, 0);
|
|
|
|
|
2019-06-14 19:23:57 +02:00
|
|
|
// Back to the normal zindex.
|
|
|
|
screen_zindex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-20 03:45:36 +02:00
|
|
|
/*
|
|
|
|
* Mark references in callbacks of one popup window.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
set_ref_in_one_popup(win_T *wp, int copyID)
|
|
|
|
{
|
|
|
|
int abort = FALSE;
|
|
|
|
typval_T tv;
|
|
|
|
|
|
|
|
if (wp->w_close_cb.cb_partial != NULL)
|
|
|
|
{
|
|
|
|
tv.v_type = VAR_PARTIAL;
|
|
|
|
tv.vval.v_partial = wp->w_close_cb.cb_partial;
|
|
|
|
abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
|
|
|
|
}
|
|
|
|
if (wp->w_filter_cb.cb_partial != NULL)
|
|
|
|
{
|
|
|
|
tv.v_type = VAR_PARTIAL;
|
|
|
|
tv.vval.v_partial = wp->w_filter_cb.cb_partial;
|
|
|
|
abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
|
|
|
|
}
|
2019-06-23 01:46:15 +02:00
|
|
|
abort = abort || set_ref_in_list(wp->w_popup_mask, copyID);
|
2019-06-20 03:45:36 +02:00
|
|
|
return abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set reference in callbacks of popup windows.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
set_ref_in_popups(int copyID)
|
|
|
|
{
|
|
|
|
int abort = FALSE;
|
|
|
|
win_T *wp;
|
|
|
|
tabpage_T *tp;
|
|
|
|
|
|
|
|
for (wp = first_popupwin; !abort && wp != NULL; wp = wp->w_next)
|
|
|
|
abort = abort || set_ref_in_one_popup(wp, copyID);
|
|
|
|
|
|
|
|
FOR_ALL_TABPAGES(tp)
|
|
|
|
{
|
|
|
|
for (wp = tp->tp_first_popupwin; !abort && wp != NULL; wp = wp->w_next)
|
|
|
|
abort = abort || set_ref_in_one_popup(wp, copyID);
|
|
|
|
if (abort)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return abort;
|
|
|
|
}
|
2019-07-18 21:43:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find an existing popup used as the preview window, in the current tab page.
|
|
|
|
* Return NULL if not found.
|
|
|
|
*/
|
|
|
|
win_T *
|
|
|
|
popup_find_preview_window(void)
|
|
|
|
{
|
|
|
|
win_T *wp;
|
|
|
|
|
|
|
|
// Preview window popup is always local to tab page.
|
|
|
|
for (wp = curtab->tp_first_popupwin; wp != NULL; wp = wp->w_next)
|
|
|
|
if (wp->w_p_pvw)
|
|
|
|
return wp;
|
|
|
|
return wp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
popup_is_popup(win_T *wp)
|
|
|
|
{
|
|
|
|
return wp->w_popup_flags != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a popup to be used as the preview window.
|
|
|
|
* NOTE: this makes the popup the current window, so that the file can be
|
|
|
|
* edited. However, it must not remain to be the current window, the caller
|
|
|
|
* must make sure of that.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
popup_create_preview_window(void)
|
|
|
|
{
|
|
|
|
win_T *wp = popup_create(NULL, NULL, TYPE_PREVIEW);
|
|
|
|
|
|
|
|
if (wp == NULL)
|
|
|
|
return FAIL;
|
|
|
|
wp->w_p_pvw = TRUE;
|
|
|
|
|
|
|
|
// Set the width to a reasonable value, so that w_topline can be computed.
|
|
|
|
if (wp->w_minwidth > 0)
|
|
|
|
wp->w_width = wp->w_minwidth;
|
|
|
|
else if (wp->w_maxwidth > 0)
|
|
|
|
wp->w_width = wp->w_maxwidth;
|
|
|
|
else
|
|
|
|
wp->w_width = curwin->w_width;
|
|
|
|
|
|
|
|
// Will switch to another buffer soon, dummy one can be wiped.
|
|
|
|
wp->w_buffer->b_locked = FALSE;
|
|
|
|
|
|
|
|
win_enter(wp, FALSE);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
popup_close_preview()
|
|
|
|
{
|
|
|
|
win_T *wp = popup_find_preview_window();
|
|
|
|
|
|
|
|
if (wp != NULL)
|
|
|
|
{
|
|
|
|
typval_T res;
|
|
|
|
|
|
|
|
res.v_type = VAR_NUMBER;
|
|
|
|
res.vval.v_number = -1;
|
|
|
|
popup_close_and_callback(wp, &res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 19:51:39 +02:00
|
|
|
#endif // FEAT_TEXT_PROP
|