/* 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_check(dict, key);
setcursor_mayforce(TRUE);
s = val + 6;
if (*s != NUL)
{
endp = s;
if (*skipwhite(s) == '+' || *skipwhite(s) == '-')
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(