/* 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"
#ifdef FEAT_TEXT_PROP
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}
};
/*
* Get option value for"key", which is "line" or "col".
* Handles "cursor+N" and "cursor-N".
*/
static int
popup_options_one(dict_T *dict, char_u *key)
{
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)
return dict_get_number(dict, key);
setcursor_mayforce(TRUE);
s = val + 6;
if (*s != NUL)
{
n = strtol((char *)s, (char **)&endp, 10);
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;
}
static void
get_pos_options(win_T *wp, dict_T *dict)
{
char_u *str;
int nr;
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;
wp->w_popup_fixed = dict_get_number(dict, (char_u *)"fixed") != 0;
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);
}
}
static void
get_padding_border(dict_T *dict, int *array, char *name, int max_val)
{
dictitem_T *di;
vim_memset(array, 0, sizeof(int) * 4);
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