2021-11-24 08:42:13 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*
|
2022-01-28 08:14:55 +00:00
|
|
|
* Copyright (c) 2021-2022 Alfonso Sabato Siciliano
|
2021-11-24 08:42:13 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
2022-01-28 08:14:55 +00:00
|
|
|
#include <curses.h>
|
|
|
|
#include <stdlib.h>
|
2021-12-21 15:06:19 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2021-11-24 08:42:13 +00:00
|
|
|
#include "bsddialog.h"
|
|
|
|
#include "bsddialog_theme.h"
|
2022-01-28 08:14:55 +00:00
|
|
|
#include "lib_util.h"
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-03-13 01:34:57 +00:00
|
|
|
#define MIN_HEIGHT VBORDERS + 6 /* 2 buttons 1 text 3 menu */
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
enum menumode {
|
|
|
|
CHECKLISTMODE,
|
|
|
|
MENUMODE,
|
|
|
|
MIXEDLISTMODE,
|
|
|
|
RADIOLISTMODE,
|
|
|
|
SEPARATORMODE
|
|
|
|
};
|
|
|
|
|
|
|
|
struct lineposition {
|
|
|
|
unsigned int maxsepstr;
|
|
|
|
unsigned int maxprefix;
|
|
|
|
unsigned int xselector;
|
|
|
|
unsigned int selectorlen;
|
|
|
|
unsigned int maxdepth;
|
|
|
|
unsigned int xname;
|
|
|
|
unsigned int maxname;
|
|
|
|
unsigned int xdesc;
|
|
|
|
unsigned int maxdesc;
|
|
|
|
unsigned int line;
|
|
|
|
};
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
struct privateitem {
|
|
|
|
bool on;
|
|
|
|
int group;
|
|
|
|
int index;
|
|
|
|
enum menumode type;
|
|
|
|
struct bsddialog_menuitem *item;
|
|
|
|
};
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
static void
|
2022-01-28 08:14:55 +00:00
|
|
|
set_on_output(struct bsddialog_conf *conf, int output, int ngroups,
|
|
|
|
struct bsddialog_menugroup *groups, struct privateitem *pritems)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-01-28 08:14:55 +00:00
|
|
|
int i, j, abs;
|
|
|
|
|
|
|
|
if (output != BSDDIALOG_OK && !conf->menu.on_without_ok)
|
|
|
|
return;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
for(i = abs = 0; i < ngroups; i++) {
|
2021-11-24 08:42:13 +00:00
|
|
|
if (groups[i].type == BSDDIALOG_SEPARATOR) {
|
2022-01-28 08:14:55 +00:00
|
|
|
abs += groups[i].nitems;
|
2021-11-24 08:42:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-28 08:14:55 +00:00
|
|
|
|
|
|
|
for(j = 0; j < (int)groups[i].nitems; j++) {
|
|
|
|
groups[i].items[j].on = pritems[abs].on;
|
|
|
|
abs++;
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
static int getprev(struct privateitem *pritems, int abs)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-01-28 08:14:55 +00:00
|
|
|
int i;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
for (i = abs - 1; i >= 0; i--) {
|
|
|
|
if (pritems[i].type == SEPARATORMODE)
|
2021-11-24 08:42:13 +00:00
|
|
|
continue;
|
2022-01-28 08:14:55 +00:00
|
|
|
return (i);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
2022-01-28 08:14:55 +00:00
|
|
|
|
|
|
|
return (abs);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
static int getnext(int npritems, struct privateitem *pritems, int abs)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-01-28 08:14:55 +00:00
|
|
|
int i;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
for (i = abs + 1; i < npritems; i++) {
|
|
|
|
if (pritems[i].type == SEPARATORMODE)
|
2021-11-24 08:42:13 +00:00
|
|
|
continue;
|
2022-01-28 08:14:55 +00:00
|
|
|
return (i);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
2022-01-28 08:14:55 +00:00
|
|
|
|
|
|
|
return (abs);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
static int
|
|
|
|
getfirst_with_default(int npritems, struct privateitem *pritems, int ngroups,
|
|
|
|
struct bsddialog_menugroup *groups, int *focusgroup, int *focusitem)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-01-28 08:14:55 +00:00
|
|
|
int i, abs;
|
|
|
|
|
|
|
|
if ((abs = getnext(npritems, pritems, -1)) < 0)
|
|
|
|
return (abs);
|
|
|
|
|
|
|
|
if (focusgroup == NULL || focusitem == NULL)
|
|
|
|
return (abs);
|
|
|
|
if (*focusgroup < 0 || *focusgroup >= ngroups)
|
|
|
|
return (abs);
|
|
|
|
if (groups[*focusgroup].type == BSDDIALOG_SEPARATOR)
|
|
|
|
return (abs);
|
|
|
|
if (*focusitem < 0 || *focusitem >= (int)groups[*focusgroup].nitems)
|
|
|
|
return (abs);
|
|
|
|
|
|
|
|
for (i = abs; i < npritems; i++) {
|
|
|
|
if (pritems[i].group == *focusgroup &&
|
|
|
|
pritems[i].index == *focusitem)
|
|
|
|
return (i);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
return (abs);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
static int
|
|
|
|
getfastnext(int menurows, int npritems, struct privateitem *pritems, int abs)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
|
|
|
int a, start, i;
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
start = abs;
|
2021-11-24 08:42:13 +00:00
|
|
|
i = menurows;
|
|
|
|
do {
|
2022-01-28 08:14:55 +00:00
|
|
|
a = abs;
|
|
|
|
abs = getnext(npritems, pritems, abs);
|
2021-11-24 08:42:13 +00:00
|
|
|
i--;
|
2022-01-28 08:14:55 +00:00
|
|
|
} while (abs != a && abs < start + menurows && i > 0);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
return (abs);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
static int
|
|
|
|
getfastprev(int menurows, struct privateitem *pritems, int abs)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
|
|
|
int a, start, i;
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
start = abs;
|
2021-11-24 08:42:13 +00:00
|
|
|
i = menurows;
|
|
|
|
do {
|
2022-01-28 08:14:55 +00:00
|
|
|
a = abs;
|
|
|
|
abs = getprev(pritems, abs);
|
2021-11-24 08:42:13 +00:00
|
|
|
i--;
|
2022-01-28 08:14:55 +00:00
|
|
|
} while (abs != a && abs > start - menurows && i > 0);
|
|
|
|
|
|
|
|
return (abs);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
static int
|
|
|
|
getnextshortcut(struct bsddialog_conf *conf, int npritems,
|
2022-09-03 14:36:16 +00:00
|
|
|
struct privateitem *pritems, int abs, wint_t key)
|
2021-12-13 07:54:07 +00:00
|
|
|
{
|
2022-09-03 14:36:16 +00:00
|
|
|
int i, next;
|
|
|
|
wchar_t wch;
|
2021-12-13 07:54:07 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
next = -1;
|
|
|
|
for (i = 0; i < npritems; i++) {
|
|
|
|
if (pritems[i].type == SEPARATORMODE)
|
2021-12-13 07:54:07 +00:00
|
|
|
continue;
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (conf->menu.no_name)
|
2022-09-03 14:36:16 +00:00
|
|
|
mbtowc(&wch, pritems[i].item->desc, MB_CUR_MAX);
|
2022-01-28 08:14:55 +00:00
|
|
|
else
|
2022-09-03 14:36:16 +00:00
|
|
|
mbtowc(&wch, pritems[i].item->name, MB_CUR_MAX);
|
2022-01-28 08:14:55 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
if (wch == (wchar_t)key) {
|
2022-01-28 08:14:55 +00:00
|
|
|
if (i > abs)
|
|
|
|
return (i);
|
2021-12-13 07:54:07 +00:00
|
|
|
|
2022-03-13 01:34:57 +00:00
|
|
|
if (i < abs && next == -1)
|
2022-01-28 08:14:55 +00:00
|
|
|
next = i;
|
|
|
|
}
|
2021-12-13 07:54:07 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
return (next != -1 ? next : abs);
|
2021-12-13 07:54:07 +00:00
|
|
|
}
|
|
|
|
|
2021-11-24 08:42:13 +00:00
|
|
|
static enum menumode
|
|
|
|
getmode(enum menumode mode, struct bsddialog_menugroup group)
|
|
|
|
{
|
|
|
|
if (mode == MIXEDLISTMODE) {
|
|
|
|
if (group.type == BSDDIALOG_SEPARATOR)
|
|
|
|
mode = SEPARATORMODE;
|
|
|
|
else if (group.type == BSDDIALOG_RADIOLIST)
|
|
|
|
mode = RADIOLISTMODE;
|
|
|
|
else if (group.type == BSDDIALOG_CHECKLIST)
|
|
|
|
mode = CHECKLISTMODE;
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
return (mode);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-03-13 01:34:57 +00:00
|
|
|
drawseparators(struct bsddialog_conf *conf, WINDOW *pad, int linelen,
|
|
|
|
int nitems, struct privateitem *pritems)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-03-13 01:34:57 +00:00
|
|
|
int i, linech, labellen;
|
|
|
|
const char *desc, *name;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-03-13 01:34:57 +00:00
|
|
|
for (i = 0; i < nitems; i++) {
|
|
|
|
if (pritems[i].type != SEPARATORMODE)
|
|
|
|
continue;
|
2021-12-06 10:35:28 +00:00
|
|
|
if (conf->no_lines == false) {
|
|
|
|
wattron(pad, t.menu.desccolor);
|
|
|
|
linech = conf->ascii_lines ? '-' : ACS_HLINE;
|
2022-03-13 01:34:57 +00:00
|
|
|
mvwhline(pad, i, 0, linech, linelen);
|
2021-12-06 10:35:28 +00:00
|
|
|
wattroff(pad, t.menu.desccolor);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
2022-03-13 01:34:57 +00:00
|
|
|
name = pritems[i].item->name;
|
|
|
|
desc = pritems[i].item->desc;
|
2022-09-03 14:36:16 +00:00
|
|
|
labellen = strcols(name) + strcols(desc) + 1;
|
2022-03-13 01:34:57 +00:00
|
|
|
wmove(pad, i, labellen < linelen ? linelen/2 - labellen/2 : 0);
|
2021-12-06 10:35:28 +00:00
|
|
|
wattron(pad, t.menu.namesepcolor);
|
2022-01-28 08:14:55 +00:00
|
|
|
waddstr(pad, name);
|
2021-12-06 10:35:28 +00:00
|
|
|
wattroff(pad, t.menu.namesepcolor);
|
2022-09-03 14:36:16 +00:00
|
|
|
if (strcols(name) > 0 && strcols(desc) > 0)
|
2021-11-24 08:42:13 +00:00
|
|
|
waddch(pad, ' ');
|
2021-12-06 10:35:28 +00:00
|
|
|
wattron(pad, t.menu.descsepcolor);
|
2022-01-28 08:14:55 +00:00
|
|
|
waddstr(pad, desc);
|
2021-12-06 10:35:28 +00:00
|
|
|
wattroff(pad, t.menu.descsepcolor);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
2022-03-13 01:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
drawitem(struct bsddialog_conf *conf, WINDOW *pad, int y,
|
|
|
|
struct lineposition pos, struct privateitem *pritem, bool focus)
|
|
|
|
{
|
|
|
|
int colordesc, colorname, colorshortcut;
|
2022-09-03 14:36:16 +00:00
|
|
|
wchar_t shortcut;
|
2022-03-13 01:34:57 +00:00
|
|
|
struct bsddialog_menuitem *item;
|
|
|
|
|
|
|
|
item = pritem->item;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
/* prefix */
|
2022-03-13 01:34:57 +00:00
|
|
|
if (item->prefix != NULL && item->prefix[0] != '\0')
|
|
|
|
mvwaddstr(pad, y, 0, item->prefix);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
/* selector */
|
|
|
|
wmove(pad, y, pos.xselector);
|
2022-03-13 01:34:57 +00:00
|
|
|
wattron(pad, focus ? t.menu.f_selectorcolor : t.menu.selectorcolor);
|
|
|
|
if (pritem->type == CHECKLISTMODE)
|
2022-01-28 08:14:55 +00:00
|
|
|
wprintw(pad, "[%c]", pritem->on ? 'X' : ' ');
|
2022-03-13 01:34:57 +00:00
|
|
|
if (pritem->type == RADIOLISTMODE)
|
2022-01-28 08:14:55 +00:00
|
|
|
wprintw(pad, "(%c)", pritem->on ? '*' : ' ');
|
2022-03-13 01:34:57 +00:00
|
|
|
wattroff(pad, focus ? t.menu.f_selectorcolor : t.menu.selectorcolor);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
/* name */
|
2022-01-28 08:14:55 +00:00
|
|
|
colorname = focus ? t.menu.f_namecolor : t.menu.namecolor;
|
|
|
|
if (conf->menu.no_name == false) {
|
2021-11-24 08:42:13 +00:00
|
|
|
wattron(pad, colorname);
|
2022-09-25 13:04:33 +00:00
|
|
|
mvwaddstr(pad, y, pos.xname + item->depth, item->name);
|
2021-11-24 08:42:13 +00:00
|
|
|
wattroff(pad, colorname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* description */
|
2022-01-28 08:14:55 +00:00
|
|
|
if (conf->menu.no_name)
|
|
|
|
colordesc = focus ? t.menu.f_namecolor : t.menu.namecolor;
|
|
|
|
else
|
|
|
|
colordesc = focus ? t.menu.f_desccolor : t.menu.desccolor;
|
|
|
|
|
|
|
|
if (conf->menu.no_desc == false) {
|
2021-12-13 07:54:07 +00:00
|
|
|
wattron(pad, colordesc);
|
2021-12-06 10:35:28 +00:00
|
|
|
if (conf->menu.no_name)
|
2022-09-25 13:04:33 +00:00
|
|
|
mvwaddstr(pad, y, pos.xname + item->depth, item->desc);
|
2021-11-24 08:42:13 +00:00
|
|
|
else
|
2022-03-13 01:34:57 +00:00
|
|
|
mvwaddstr(pad, y, pos.xdesc, item->desc);
|
2021-12-13 07:54:07 +00:00
|
|
|
wattroff(pad, colordesc);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
2021-12-13 07:54:07 +00:00
|
|
|
/* shortcut */
|
2022-01-28 08:14:55 +00:00
|
|
|
if (conf->menu.shortcut_buttons == false) {
|
|
|
|
colorshortcut = focus ?
|
|
|
|
t.menu.f_shortcutcolor : t.menu.shortcutcolor;
|
2021-12-13 07:54:07 +00:00
|
|
|
wattron(pad, colorshortcut);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2021-12-13 07:54:07 +00:00
|
|
|
if (conf->menu.no_name)
|
2022-09-03 14:36:16 +00:00
|
|
|
mbtowc(&shortcut, item->desc, MB_CUR_MAX);
|
2021-12-13 07:54:07 +00:00
|
|
|
else
|
2022-09-03 14:36:16 +00:00
|
|
|
mbtowc(&shortcut, item->name, MB_CUR_MAX);
|
2022-09-25 13:04:33 +00:00
|
|
|
mvwaddwch(pad, y, pos.xname + item->depth, shortcut);
|
2022-09-03 14:36:16 +00:00
|
|
|
wattroff(pad, colorshortcut);
|
2022-01-28 08:14:55 +00:00
|
|
|
}
|
2021-12-13 07:54:07 +00:00
|
|
|
|
|
|
|
/* bottom description */
|
2022-01-28 08:14:55 +00:00
|
|
|
move(SCREENLINES - 1, 2);
|
2021-12-13 07:54:07 +00:00
|
|
|
clrtoeol();
|
2022-03-13 01:34:57 +00:00
|
|
|
if (item->bottomdesc != NULL && focus) {
|
2022-09-03 14:36:16 +00:00
|
|
|
attron(t.menu.bottomdesccolor);
|
2022-03-13 01:34:57 +00:00
|
|
|
addstr(item->bottomdesc);
|
2022-09-03 14:36:16 +00:00
|
|
|
attroff(t.menu.bottomdesccolor);
|
2021-11-24 08:42:13 +00:00
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
/* the caller has to call prefresh(menupad, ymenupad, 0, ys, xs, ye, xe); */
|
|
|
|
static void
|
|
|
|
update_menuwin(struct bsddialog_conf *conf, WINDOW *menuwin, int h, int w,
|
|
|
|
int totnitems, unsigned int menurows, int ymenupad)
|
|
|
|
{
|
|
|
|
draw_borders(conf, menuwin, h, w, LOWERED);
|
|
|
|
|
|
|
|
if (totnitems > (int)menurows) {
|
|
|
|
wattron(menuwin, t.dialog.arrowcolor);
|
|
|
|
if (ymenupad > 0)
|
|
|
|
mvwhline(menuwin, 0, 2,
|
|
|
|
conf->ascii_lines ? '^' : ACS_UARROW, 3);
|
|
|
|
|
|
|
|
if ((ymenupad + (int)menurows) < totnitems)
|
|
|
|
mvwhline(menuwin, h-1, 2,
|
|
|
|
conf->ascii_lines ? 'v' : ACS_DARROW, 3);
|
|
|
|
|
|
|
|
mvwprintw(menuwin, h-1, w-6, "%3d%%",
|
|
|
|
100 * (ymenupad + menurows) / totnitems);
|
|
|
|
wattroff(menuwin, t.dialog.arrowcolor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
static int
|
2021-12-06 10:35:28 +00:00
|
|
|
menu_autosize(struct bsddialog_conf *conf, int rows, int cols, int *h, int *w,
|
2022-01-28 08:14:55 +00:00
|
|
|
const char *text, int linelen, unsigned int *menurows, int nitems,
|
2021-11-24 08:42:13 +00:00
|
|
|
struct buttons bs)
|
|
|
|
{
|
2022-01-28 08:14:55 +00:00
|
|
|
int htext, wtext, menusize, notext;
|
|
|
|
|
|
|
|
notext = 2;
|
|
|
|
if (*menurows == BSDDIALOG_AUTOSIZE) {
|
|
|
|
/* algo 1): grows vertically */
|
|
|
|
/* notext = 1; */
|
2022-03-13 01:34:57 +00:00
|
|
|
/* algo 2): grows horizontally, better with little screens */
|
2022-01-28 08:14:55 +00:00
|
|
|
notext += nitems;
|
|
|
|
notext = MIN(notext, widget_max_height(conf) - HBORDERS - 3);
|
|
|
|
} else
|
|
|
|
notext += *menurows;
|
|
|
|
|
2022-09-25 13:04:33 +00:00
|
|
|
if (text_size(conf, rows, cols, text, &bs, notext, linelen + 4, &htext,
|
|
|
|
&wtext) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (cols == BSDDIALOG_AUTOSIZE)
|
2022-03-13 01:34:57 +00:00
|
|
|
*w = widget_min_width(conf, wtext, linelen + 4, &bs);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (rows == BSDDIALOG_AUTOSIZE) {
|
2022-09-25 13:04:33 +00:00
|
|
|
if (*menurows == BSDDIALOG_AUTOSIZE) {
|
2022-01-28 08:14:55 +00:00
|
|
|
menusize = widget_max_height(conf) - HBORDERS -
|
|
|
|
2 /*buttons*/ - htext;
|
|
|
|
menusize = MIN(menusize, nitems + 2);
|
|
|
|
*menurows = menusize - 2 < 0 ? 0 : menusize - 2;
|
2022-09-25 13:04:33 +00:00
|
|
|
} else /* h autosize with fixed menurows */
|
2022-01-28 08:14:55 +00:00
|
|
|
menusize = *menurows + 2;
|
|
|
|
|
|
|
|
*h = widget_min_height(conf, htext, menusize, true);
|
2022-09-25 13:04:33 +00:00
|
|
|
} else { /* fixed rows */
|
|
|
|
if (*menurows == BSDDIALOG_AUTOSIZE) {
|
2022-09-03 14:36:16 +00:00
|
|
|
if (*h - 6 - htext <= 0)
|
|
|
|
*menurows = 0; /* menu_checksize() will check */
|
|
|
|
else
|
|
|
|
*menurows = MIN(*h-6-htext, nitems);
|
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
2022-01-28 08:14:55 +00:00
|
|
|
|
2022-09-25 13:04:33 +00:00
|
|
|
/* avoid menurows overflow and menurows becomes at most menurows */
|
|
|
|
if (*h - 6 - htext <= 0)
|
|
|
|
*menurows = 0; /* menu_checksize() will check */
|
|
|
|
else
|
|
|
|
*menurows = MIN(*h - 6 - htext, (int)*menurows);
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
return (0);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2022-01-28 08:14:55 +00:00
|
|
|
menu_checksize(int rows, int cols, const char *text, int menurows, int nitems,
|
2021-11-24 08:42:13 +00:00
|
|
|
struct buttons bs)
|
|
|
|
{
|
|
|
|
int mincols, textrow, menusize;
|
|
|
|
|
|
|
|
mincols = VBORDERS;
|
|
|
|
/* buttons */
|
2022-09-03 14:36:16 +00:00
|
|
|
mincols += buttons_min_width(bs);
|
2022-01-28 08:14:55 +00:00
|
|
|
/*
|
|
|
|
* linelen check, comment to allow some hidden col otherwise portconfig
|
|
|
|
* could not show big menus like www/apache24
|
|
|
|
*/
|
2021-11-24 08:42:13 +00:00
|
|
|
/* mincols = MAX(mincols, linelen); */
|
|
|
|
|
|
|
|
if (cols < mincols)
|
2022-01-28 08:14:55 +00:00
|
|
|
RETURN_ERROR("Few cols, width < size buttons or "
|
|
|
|
"name + descripion of the items");
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
textrow = text != NULL && text[0] != '\0' ? 1 : 0;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
if (nitems > 0 && menurows == 0)
|
2022-09-03 14:36:16 +00:00
|
|
|
RETURN_ERROR("items > 0 but menurows == 0, if menurows = 0 "
|
|
|
|
"terminal too small");
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
menusize = nitems > 0 ? 3 : 0;
|
|
|
|
if (rows < 2 + 2 + menusize + textrow)
|
|
|
|
RETURN_ERROR("Few lines for this menus");
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
return (0);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2022-01-28 08:14:55 +00:00
|
|
|
do_mixedlist(struct bsddialog_conf *conf, const char *text, int rows, int cols,
|
|
|
|
unsigned int menurows, enum menumode mode, unsigned int ngroups,
|
2021-11-24 08:42:13 +00:00
|
|
|
struct bsddialog_menugroup *groups, int *focuslist, int *focusitem)
|
|
|
|
{
|
2022-01-28 08:14:55 +00:00
|
|
|
bool loop, onetrue, movefocus, automenurows, shortcut_butts;
|
2022-09-03 14:36:16 +00:00
|
|
|
int i, j, y, x, h, w, retval;
|
2022-01-28 08:14:55 +00:00
|
|
|
int ymenupad, ys, ye, xs, xe, abs, next, totnitems;
|
2022-09-03 14:36:16 +00:00
|
|
|
wint_t input;
|
2021-11-24 08:42:13 +00:00
|
|
|
WINDOW *shadow, *widget, *textpad, *menuwin, *menupad;
|
|
|
|
struct buttons bs;
|
|
|
|
struct lineposition pos = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
2022-01-28 08:14:55 +00:00
|
|
|
struct bsddialog_menuitem *item;
|
|
|
|
struct privateitem *pritems;
|
2021-12-13 07:54:07 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
shortcut_butts = conf->menu.shortcut_buttons;
|
2021-12-13 07:54:07 +00:00
|
|
|
|
2022-03-13 01:34:57 +00:00
|
|
|
automenurows = (menurows == BSDDIALOG_AUTOSIZE) ? true : false;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
totnitems = 0;
|
2022-01-28 08:14:55 +00:00
|
|
|
for (i = 0; i < (int)ngroups; i++) {
|
|
|
|
if (getmode(mode, groups[i]) == RADIOLISTMODE ||
|
|
|
|
getmode(mode, groups[i]) == CHECKLISTMODE)
|
2021-11-24 08:42:13 +00:00
|
|
|
pos.selectorlen = 3;
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
for (j = 0; j < (int)groups[i].nitems; j++) {
|
2021-11-24 08:42:13 +00:00
|
|
|
totnitems++;
|
|
|
|
item = &groups[i].items[j];
|
|
|
|
|
|
|
|
if (groups[i].type == BSDDIALOG_SEPARATOR) {
|
|
|
|
pos.maxsepstr = MAX(pos.maxsepstr,
|
2022-09-03 14:36:16 +00:00
|
|
|
strcols(item->name) + strcols(item->desc));
|
2021-11-24 08:42:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
pos.maxprefix = MAX(pos.maxprefix,strcols(item->prefix));
|
2021-12-13 07:54:07 +00:00
|
|
|
pos.maxdepth = MAX(pos.maxdepth, item->depth);
|
2022-09-03 14:36:16 +00:00
|
|
|
pos.maxname = MAX(pos.maxname, strcols(item->name));
|
|
|
|
pos.maxdesc = MAX(pos.maxdesc, strcols(item->desc));
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-06 10:35:28 +00:00
|
|
|
pos.maxname = conf->menu.no_name ? 0 : pos.maxname;
|
|
|
|
pos.maxdesc = conf->menu.no_desc ? 0 : pos.maxdesc;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
pos.xselector = pos.maxprefix + (pos.maxprefix != 0 ? 1 : 0);
|
2022-01-28 08:14:55 +00:00
|
|
|
pos.xname = pos.xselector + pos.selectorlen +
|
|
|
|
(pos.selectorlen > 0 ? 1 : 0);
|
2021-11-24 08:42:13 +00:00
|
|
|
pos.xdesc = pos.maxdepth + pos.xname + pos.maxname;
|
|
|
|
pos.xdesc += (pos.maxname != 0 ? 1 : 0);
|
|
|
|
pos.line = MAX(pos.maxsepstr + 3, pos.xdesc + pos.maxdesc);
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
get_buttons(conf, &bs, BUTTON_OK_LABEL, BUTTON_CANCEL_LABEL);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (menu_autosize(conf, rows, cols, &h, &w, text, pos.line, &menurows,
|
|
|
|
totnitems, bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-11-24 08:42:13 +00:00
|
|
|
if (menu_checksize(h, w, text, menurows, totnitems, bs) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
2021-11-24 08:42:13 +00:00
|
|
|
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
|
|
|
|
if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs,
|
|
|
|
shortcut_butts) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
doupdate();
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
prefresh(textpad, 0, 0, y + 1, x + 1 + TEXTHMARGIN, y + h - menurows,
|
|
|
|
x + 1 + w - TEXTHMARGIN);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
menuwin = new_boxed_window(conf, y + h - 5 - menurows, x + 2,
|
2022-09-03 14:36:16 +00:00
|
|
|
menurows + 2, w - 4, LOWERED);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
menupad = newpad(totnitems, pos.line);
|
2021-12-13 07:54:07 +00:00
|
|
|
wbkgd(menupad, t.dialog.color);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if ((pritems = calloc(totnitems, sizeof (struct privateitem))) == NULL)
|
|
|
|
RETURN_ERROR("Cannot allocate memory for internal menu items");
|
|
|
|
|
|
|
|
abs = 0;
|
|
|
|
for (i = 0; i < (int)ngroups; i++) {
|
|
|
|
onetrue = false;
|
|
|
|
for (j = 0; j < (int)groups[i].nitems; j++) {
|
2021-11-24 08:42:13 +00:00
|
|
|
item = &groups[i].items[j];
|
2022-01-28 08:14:55 +00:00
|
|
|
|
|
|
|
if (getmode(mode, groups[i]) == MENUMODE) {
|
|
|
|
pritems[abs].on = false;
|
|
|
|
} else if (getmode(mode, groups[i]) == RADIOLISTMODE) {
|
|
|
|
pritems[abs].on = onetrue ? false : item->on;
|
|
|
|
if (pritems[abs].on)
|
|
|
|
onetrue = true;
|
|
|
|
} else {
|
|
|
|
pritems[abs].on = item->on;
|
|
|
|
}
|
|
|
|
pritems[abs].group = i;
|
|
|
|
pritems[abs].index = j;
|
|
|
|
pritems[abs].type = getmode(mode, groups[i]);
|
|
|
|
pritems[abs].item = item;
|
|
|
|
|
|
|
|
drawitem(conf, menupad, abs, pos, &pritems[abs], false);
|
|
|
|
abs++;
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-13 01:34:57 +00:00
|
|
|
drawseparators(conf, menupad, MIN((int)pos.line, w-6), totnitems,
|
|
|
|
pritems);
|
2022-01-28 08:14:55 +00:00
|
|
|
abs = getfirst_with_default(totnitems, pritems, ngroups, groups,
|
|
|
|
focuslist, focusitem);
|
|
|
|
if (abs >= 0)
|
|
|
|
drawitem(conf, menupad, abs, pos, &pritems[abs], true);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
ys = y + h - 5 - menurows + 1;
|
|
|
|
ye = y + h - 5 ;
|
2021-12-06 10:35:28 +00:00
|
|
|
if (conf->menu.align_left || (int)pos.line > w - 6) {
|
2021-11-24 08:42:13 +00:00
|
|
|
xs = x + 3;
|
|
|
|
xe = xs + w - 7;
|
2022-01-28 08:14:55 +00:00
|
|
|
} else { /* center */
|
2021-11-24 08:42:13 +00:00
|
|
|
xs = x + 3 + (w-6)/2 - pos.line/2;
|
|
|
|
xe = xs + w - 5;
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
ymenupad = 0;
|
2021-11-24 08:42:13 +00:00
|
|
|
if ((int)(ymenupad + menurows) - 1 < abs)
|
|
|
|
ymenupad = abs - menurows + 1;
|
2022-01-28 08:14:55 +00:00
|
|
|
update_menuwin(conf, menuwin, menurows+2, w-4, totnitems, menurows,
|
|
|
|
ymenupad);
|
2021-11-24 08:42:13 +00:00
|
|
|
wrefresh(menuwin);
|
|
|
|
prefresh(menupad, ymenupad, 0, ys, xs, ye, xe);
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
movefocus = false;
|
2021-11-24 08:42:13 +00:00
|
|
|
loop = true;
|
2022-01-28 08:14:55 +00:00
|
|
|
while (loop) {
|
2022-09-03 14:36:16 +00:00
|
|
|
if (get_wch(&input) == ERR)
|
|
|
|
continue;
|
2021-11-24 08:42:13 +00:00
|
|
|
switch(input) {
|
|
|
|
case KEY_ENTER:
|
|
|
|
case 10: /* Enter */
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = bs.value[bs.curr];
|
2022-01-28 08:14:55 +00:00
|
|
|
if (abs >= 0 && pritems[abs].type == MENUMODE)
|
|
|
|
pritems[abs].on = true;
|
2022-09-03 14:36:16 +00:00
|
|
|
set_on_output(conf, retval, ngroups, groups, pritems);
|
2021-11-24 08:42:13 +00:00
|
|
|
loop = false;
|
|
|
|
break;
|
|
|
|
case 27: /* Esc */
|
2022-01-28 08:14:55 +00:00
|
|
|
if (conf->key.enable_esc) {
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = BSDDIALOG_ESC;
|
2022-01-28 08:14:55 +00:00
|
|
|
if (abs >= 0 && pritems[abs].type == MENUMODE)
|
|
|
|
pritems[abs].on = true;
|
2022-09-03 14:36:16 +00:00
|
|
|
set_on_output(conf, retval, ngroups, groups,
|
2022-01-28 08:14:55 +00:00
|
|
|
pritems);
|
|
|
|
loop = false;
|
|
|
|
}
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
case '\t': /* TAB */
|
|
|
|
bs.curr = (bs.curr + 1) % bs.nbuttons;
|
2022-01-28 08:14:55 +00:00
|
|
|
draw_buttons(widget, bs, shortcut_butts);
|
2021-11-24 08:42:13 +00:00
|
|
|
wrefresh(widget);
|
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
|
|
|
if (bs.curr > 0) {
|
|
|
|
bs.curr--;
|
2022-01-28 08:14:55 +00:00
|
|
|
draw_buttons(widget, bs, shortcut_butts);
|
2021-11-24 08:42:13 +00:00
|
|
|
wrefresh(widget);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
|
|
|
if (bs.curr < (int) bs.nbuttons - 1) {
|
|
|
|
bs.curr++;
|
2022-01-28 08:14:55 +00:00
|
|
|
draw_buttons(widget, bs, shortcut_butts);
|
2021-11-24 08:42:13 +00:00
|
|
|
wrefresh(widget);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_F(1):
|
2022-03-13 01:34:57 +00:00
|
|
|
if (conf->key.f1_file == NULL &&
|
|
|
|
conf->key.f1_message == NULL)
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
if (f1help(conf) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
/* No break, screen size can change */
|
2021-11-24 08:42:13 +00:00
|
|
|
case KEY_RESIZE:
|
2022-01-28 08:14:55 +00:00
|
|
|
/* Important for decreasing screen */
|
|
|
|
hide_widget(y, x, h, w, conf->shadow);
|
2021-11-24 08:42:13 +00:00
|
|
|
refresh();
|
|
|
|
|
|
|
|
if (set_widget_size(conf, rows, cols, &h, &w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
2021-11-24 08:42:13 +00:00
|
|
|
menurows = automenurows ? 0 : menurows;
|
2022-01-28 08:14:55 +00:00
|
|
|
if (menu_autosize(conf, rows, cols, &h, &w, text,
|
|
|
|
pos.line, &menurows, totnitems, bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
|
|
|
if (menu_checksize(h, w, text, menurows, totnitems,
|
|
|
|
bs) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-11-24 08:42:13 +00:00
|
|
|
if (set_widget_position(conf, &y, &x, h, w) != 0)
|
2022-01-28 08:14:55 +00:00
|
|
|
return (BSDDIALOG_ERROR);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
if (update_dialog(conf, shadow, widget, y, x, h, w,
|
|
|
|
textpad, text, &bs, shortcut_butts) != 0)
|
|
|
|
return (BSDDIALOG_ERROR);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
doupdate();
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
prefresh(textpad, 0, 0, y + 1, x + 1 + TEXTHMARGIN,
|
|
|
|
y + h - menurows, x + 1 + w - TEXTHMARGIN);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
wclear(menuwin);
|
|
|
|
mvwin(menuwin, y + h - 5 - menurows, x + 2);
|
|
|
|
wresize(menuwin,menurows+2, w-4);
|
2022-01-28 08:14:55 +00:00
|
|
|
update_menuwin(conf, menuwin, menurows+2, w-4,
|
|
|
|
totnitems, menurows, ymenupad);
|
2021-11-24 08:42:13 +00:00
|
|
|
wrefresh(menuwin);
|
2022-01-28 08:14:55 +00:00
|
|
|
|
2021-11-24 08:42:13 +00:00
|
|
|
ys = y + h - 5 - menurows + 1;
|
|
|
|
ye = y + h - 5 ;
|
2021-12-06 10:35:28 +00:00
|
|
|
if (conf->menu.align_left || (int)pos.line > w - 6) {
|
2021-11-24 08:42:13 +00:00
|
|
|
xs = x + 3;
|
|
|
|
xe = xs + w - 7;
|
2022-01-28 08:14:55 +00:00
|
|
|
} else { /* center */
|
2021-11-24 08:42:13 +00:00
|
|
|
xs = x + 3 + (w-6)/2 - pos.line/2;
|
|
|
|
xe = xs + w - 5;
|
|
|
|
}
|
|
|
|
|
2022-03-13 01:34:57 +00:00
|
|
|
drawseparators(conf, menupad, MIN((int)pos.line, w-6),
|
|
|
|
totnitems, pritems);
|
|
|
|
|
2021-11-24 08:42:13 +00:00
|
|
|
if ((int)(ymenupad + menurows) - 1 < abs)
|
|
|
|
ymenupad = abs - menurows + 1;
|
|
|
|
prefresh(menupad, ymenupad, 0, ys, xs, ye, xe);
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (abs < 0)
|
|
|
|
continue;
|
|
|
|
switch(input) {
|
|
|
|
case KEY_HOME:
|
2022-01-28 08:14:55 +00:00
|
|
|
next = getnext(totnitems, pritems, -1);
|
|
|
|
movefocus = next != abs;
|
|
|
|
break;
|
2021-11-24 08:42:13 +00:00
|
|
|
case KEY_UP:
|
2022-01-28 08:14:55 +00:00
|
|
|
next = getprev(pritems, abs);
|
|
|
|
movefocus = next != abs;
|
|
|
|
break;
|
2021-11-24 08:42:13 +00:00
|
|
|
case KEY_PPAGE:
|
2022-01-28 08:14:55 +00:00
|
|
|
next = getfastprev(menurows, pritems, abs);
|
|
|
|
movefocus = next != abs;
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
case KEY_END:
|
2022-01-28 08:14:55 +00:00
|
|
|
next = getprev(pritems, totnitems);
|
|
|
|
movefocus = next != abs;
|
|
|
|
break;
|
2021-11-24 08:42:13 +00:00
|
|
|
case KEY_DOWN:
|
2022-01-28 08:14:55 +00:00
|
|
|
next = getnext(totnitems, pritems, abs);
|
|
|
|
movefocus = next != abs;
|
|
|
|
break;
|
2021-11-24 08:42:13 +00:00
|
|
|
case KEY_NPAGE:
|
2022-01-28 08:14:55 +00:00
|
|
|
next = getfastnext(menurows, totnitems, pritems, abs);
|
|
|
|
movefocus = next != abs;
|
2021-11-24 08:42:13 +00:00
|
|
|
break;
|
|
|
|
case ' ': /* Space */
|
2022-09-25 13:04:33 +00:00
|
|
|
if (pritems[abs].type == MENUMODE) {
|
|
|
|
retval = bs.value[bs.curr];
|
|
|
|
pritems[abs].on = true;
|
|
|
|
set_on_output(conf, retval, ngroups, groups,
|
|
|
|
pritems);
|
|
|
|
loop = false;
|
|
|
|
} else if (pritems[abs].type == CHECKLISTMODE) {
|
2022-01-28 08:14:55 +00:00
|
|
|
pritems[abs].on = !pritems[abs].on;
|
2022-09-25 13:04:33 +00:00
|
|
|
} else { /* RADIOLISTMODE */
|
2022-01-28 08:14:55 +00:00
|
|
|
for (i = abs - pritems[abs].index;
|
|
|
|
i < totnitems &&
|
|
|
|
pritems[i].group == pritems[abs].group;
|
|
|
|
i++) {
|
|
|
|
if (i != abs && pritems[i].on) {
|
|
|
|
pritems[i].on = false;
|
|
|
|
drawitem(conf, menupad, i, pos,
|
|
|
|
&pritems[i], false);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
2022-03-13 01:34:57 +00:00
|
|
|
}
|
2022-01-28 08:14:55 +00:00
|
|
|
pritems[abs].on = !pritems[abs].on;
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
2022-01-28 08:14:55 +00:00
|
|
|
drawitem(conf, menupad, abs, pos, &pritems[abs], true);
|
2021-11-24 08:42:13 +00:00
|
|
|
prefresh(menupad, ymenupad, 0, ys, xs, ye, xe);
|
2022-01-28 08:14:55 +00:00
|
|
|
break;
|
2021-12-13 07:54:07 +00:00
|
|
|
default:
|
2022-01-28 08:14:55 +00:00
|
|
|
if (shortcut_butts) {
|
|
|
|
if (shortcut_buttons(input, &bs)) {
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = bs.value[bs.curr];
|
2022-01-28 08:14:55 +00:00
|
|
|
if (pritems[abs].type == MENUMODE)
|
|
|
|
pritems[abs].on = true;
|
2022-09-03 14:36:16 +00:00
|
|
|
set_on_output(conf, retval, ngroups,
|
2022-01-28 08:14:55 +00:00
|
|
|
groups, pritems);
|
|
|
|
loop = false;
|
|
|
|
}
|
2021-12-13 07:54:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
/* shourtcut items */
|
|
|
|
next = getnextshortcut(conf, totnitems, pritems, abs,
|
|
|
|
input);
|
|
|
|
movefocus = next != abs;
|
2022-09-03 14:36:16 +00:00
|
|
|
} /* end switch handler */
|
2022-01-28 08:14:55 +00:00
|
|
|
|
|
|
|
if (movefocus) {
|
|
|
|
drawitem(conf, menupad, abs, pos, &pritems[abs], false);
|
|
|
|
abs = next;
|
|
|
|
drawitem(conf, menupad, abs, pos, &pritems[abs], true);
|
2021-12-13 07:54:07 +00:00
|
|
|
if (ymenupad > abs && ymenupad > 0)
|
|
|
|
ymenupad = abs;
|
|
|
|
if ((int)(ymenupad + menurows) <= abs)
|
|
|
|
ymenupad = abs - menurows + 1;
|
2022-01-28 08:14:55 +00:00
|
|
|
update_menuwin(conf, menuwin, menurows+2, w-4,
|
|
|
|
totnitems, menurows, ymenupad);
|
2021-12-13 07:54:07 +00:00
|
|
|
wrefresh(menuwin);
|
|
|
|
prefresh(menupad, ymenupad, 0, ys, xs, ye, xe);
|
2022-01-28 08:14:55 +00:00
|
|
|
movefocus = false;
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
2022-09-03 14:36:16 +00:00
|
|
|
} /* end while handler */
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
if (focuslist != NULL)
|
2022-01-28 08:14:55 +00:00
|
|
|
*focuslist = abs < 0 ? -1 : pritems[abs].group;
|
2021-11-24 08:42:13 +00:00
|
|
|
if (focusitem !=NULL)
|
2022-01-28 08:14:55 +00:00
|
|
|
*focusitem = abs < 0 ? -1 : pritems[abs].index;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
|
|
|
delwin(menupad);
|
|
|
|
delwin(menuwin);
|
2022-01-28 08:14:55 +00:00
|
|
|
end_dialog(conf, shadow, widget, textpad);
|
|
|
|
free(pritems);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
return (retval);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-28 08:14:55 +00:00
|
|
|
/* API */
|
|
|
|
int
|
|
|
|
bsddialog_mixedlist(struct bsddialog_conf *conf, const char *text, int rows,
|
|
|
|
int cols, unsigned int menurows, unsigned int ngroups,
|
|
|
|
struct bsddialog_menugroup *groups, int *focuslist, int *focusitem)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-09-03 14:36:16 +00:00
|
|
|
int retval;
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = do_mixedlist(conf, text, rows, cols, menurows, MIXEDLISTMODE,
|
2021-11-24 08:42:13 +00:00
|
|
|
ngroups, groups, focuslist, focusitem);
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
return (retval);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-01-28 08:14:55 +00:00
|
|
|
bsddialog_checklist(struct bsddialog_conf *conf, const char *text, int rows,
|
|
|
|
int cols, unsigned int menurows, unsigned int nitems,
|
|
|
|
struct bsddialog_menuitem *items, int *focusitem)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-09-03 14:36:16 +00:00
|
|
|
int retval, focuslist = 0;
|
2021-11-24 08:42:13 +00:00
|
|
|
struct bsddialog_menugroup group = {
|
|
|
|
BSDDIALOG_CHECKLIST /* unused */, nitems, items};
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = do_mixedlist(conf, text, rows, cols, menurows, CHECKLISTMODE,
|
2022-01-28 08:14:55 +00:00
|
|
|
1, &group, &focuslist, focusitem);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
return (retval);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-01-28 08:14:55 +00:00
|
|
|
bsddialog_menu(struct bsddialog_conf *conf, const char *text, int rows,
|
|
|
|
int cols, unsigned int menurows, unsigned int nitems,
|
|
|
|
struct bsddialog_menuitem *items, int *focusitem)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-09-03 14:36:16 +00:00
|
|
|
int retval, focuslist = 0;
|
2021-11-24 08:42:13 +00:00
|
|
|
struct bsddialog_menugroup group = {
|
|
|
|
BSDDIALOG_CHECKLIST /* unused */, nitems, items};
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = do_mixedlist(conf, text, rows, cols, menurows, MENUMODE, 1,
|
2022-01-28 08:14:55 +00:00
|
|
|
&group, &focuslist, focusitem);
|
2021-11-24 08:42:13 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
return (retval);
|
2021-11-24 08:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-01-28 08:14:55 +00:00
|
|
|
bsddialog_radiolist(struct bsddialog_conf *conf, const char *text, int rows,
|
|
|
|
int cols, unsigned int menurows, unsigned int nitems,
|
|
|
|
struct bsddialog_menuitem *items, int *focusitem)
|
2021-11-24 08:42:13 +00:00
|
|
|
{
|
2022-09-03 14:36:16 +00:00
|
|
|
int retval, focuslist = 0;
|
2021-11-24 08:42:13 +00:00
|
|
|
struct bsddialog_menugroup group = {
|
|
|
|
BSDDIALOG_RADIOLIST /* unused */, nitems, items};
|
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
retval = do_mixedlist(conf, text, rows, cols, menurows, RADIOLISTMODE,
|
2022-01-28 08:14:55 +00:00
|
|
|
1, &group, &focuslist, focusitem);
|
2021-12-06 10:35:28 +00:00
|
|
|
|
2022-09-03 14:36:16 +00:00
|
|
|
return (retval);
|
2022-03-13 01:34:57 +00:00
|
|
|
}
|