1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-12 09:58:36 +00:00

Next round of changes - make dialog boxes drawable at arbitrary X,Y locations

and add selection traversal callbacks so context-sensitive behavior can
even be implemented for individual menu items.  These work around the two
largest issues holding me back with some of my sysinstall changes.
This commit is contained in:
Jordan K. Hubbard 1996-01-01 03:43:58 +00:00
parent 961c0bd1a8
commit 738c371d22
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=13135
11 changed files with 127 additions and 84 deletions

View File

@ -36,8 +36,9 @@ static int list_width, check_x, item_x;
/*
* Display a dialog box with a list of options that can be turned on or off
*/
int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int width,
int list_height, int item_no, void *it, unsigned char *result)
int
dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int width,
int list_height, int item_no, void *it, unsigned char *result)
{
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
l, k, scroll = 0, max_choice, *status;
@ -70,7 +71,7 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
/* Initializes status */
for (i = 0; i < item_no; i++) {
status[i] = ditems[i].checked ? (*ditems[i].checked)(&ditems[i]) : FALSE;
status[i] = ditems[i].checked ? ditems[i].checked(&ditems[i]) : FALSE;
items[i*3] = ditems[i].prompt;
items[i*3 + 1] = ditems[i].title;
items[i*3 + 2] = status[i] ? "on" : "off";
@ -179,10 +180,10 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
if (ditems && result) {
cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]);
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? (*ditems[CANCEL_BUTTON].checked)(&ditems[CANCEL_BUTTON]) : FALSE);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : FALSE);
okButton = toupper(ditems[OK_BUTTON].prompt[0]);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? (*ditems[OK_BUTTON].checked)(&ditems[OK_BUTTON]) : TRUE);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : TRUE);
}
else {
cancelButton = 'C';
@ -198,7 +199,7 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
/* Shortcut to OK? */
if (toupper(key) == okButton) {
if (ditems && result && ditems[OK_BUTTON].fire) {
if ((*ditems[OK_BUTTON].fire)(&ditems[OK_BUTTON]) == DITEM_FAILURE)
if (ditems[OK_BUTTON].fire(&ditems[OK_BUTTON]) == DITEM_FAILURE)
continue;
else
delwin(dialog);
@ -218,7 +219,7 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
/* Shortcut to cancel? */
else if (toupper(key) == cancelButton) {
if (ditems && result && ditems[CANCEL_BUTTON].fire) {
if ((*ditems[CANCEL_BUTTON].fire)(&ditems[CANCEL_BUTTON]) == DITEM_FAILURE)
if (ditems[CANCEL_BUTTON].fire(&ditems[CANCEL_BUTTON]) == DITEM_FAILURE)
continue;
}
delwin(dialog);
@ -266,13 +267,15 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
getyx(dialog, cur_y, cur_x); /* Save cursor position */
if (list_height > 1) {
/* De-highlight current last item before scrolling up */
print_item(list, items[(scroll+max_choice-1)*3], items[(scroll+max_choice-1)*3 + 1], status[scroll+max_choice-1], max_choice-1, FALSE, DREF(ditems, scroll + max_choice - 1));
print_item(list, items[(scroll+max_choice-1)*3], items[(scroll+max_choice-1)*3 + 1],
status[scroll+max_choice-1], max_choice-1, FALSE, DREF(ditems, scroll + max_choice - 1));
scrollok(list, TRUE);
scroll(list);
scrollok(list, FALSE);
}
scroll++;
print_item(list, items[(scroll+max_choice-1)*3], items[(scroll+max_choice-1)*3 + 1], status[scroll+max_choice-1], max_choice-1, TRUE, DREF(ditems, scroll + max_choice - 1));
print_item(list, items[(scroll+max_choice-1)*3], items[(scroll+max_choice-1)*3 + 1],
status[scroll+max_choice-1], max_choice-1, TRUE, DREF(ditems, scroll + max_choice - 1));
wnoutrefresh(list);
print_arrows(dialog, scroll, list_height, item_no, box_x, box_y, check_x + 4, cur_x, cur_y);
wrefresh(dialog);
@ -287,7 +290,7 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
if (ditems) {
if (ditems[scroll+choice].fire) {
int st = (*ditems[scroll+choice].fire)(&ditems[scroll+choice]);
int st = ditems[scroll+choice].fire(&ditems[scroll+choice]);
if (st == DITEM_LEAVE_MENU) {
/* Allow a fire action to take us out of the menu */
@ -299,7 +302,7 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
else if (st == DITEM_REDRAW) {
for (i = 0; i < max_choice; i++) {
status[scroll + i] = ditems[scroll + i].checked ?
(*ditems[scroll + i].checked)(&ditems[scroll + i]) : FALSE;
ditems[scroll + i].checked(&ditems[scroll + i]) : FALSE;
print_item(list, items[(scroll+i)*3], items[(scroll+i)*3 + 1], status[scroll+i], i, i == choice,
DREF(ditems, scroll + i));
}
@ -309,7 +312,7 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
}
}
status[scroll+choice] = ditems[scroll+choice].checked ?
(*ditems[scroll+choice].checked)(&ditems[scroll+choice]) : FALSE;
ditems[scroll+choice].checked(&ditems[scroll+choice]) : FALSE;
lbra = ditems[scroll+choice].lbra;
rbra = ditems[scroll+choice].rbra;
mark = ditems[scroll+choice].mark;
@ -392,15 +395,15 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
if (ditems && result) {
if (button) {
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? (*ditems[OK_BUTTON].checked)(&ditems[OK_BUTTON]) : !button);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? (*ditems[CANCEL_BUTTON].checked)(&ditems[CANCEL_BUTTON]) : button);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
}
else {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? (*ditems[CANCEL_BUTTON].checked)(&ditems[CANCEL_BUTTON]) : button);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? (*ditems[OK_BUTTON].checked)(&ditems[OK_BUTTON]) : !button);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
}
}
else {
@ -421,7 +424,7 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
case '\r':
if (!button && result) {
if (ditems && ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire) {
if ((*ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire)(&ditems[button ? CANCEL_BUTTON : OK_BUTTON]) ==
if (ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire(&ditems[button ? CANCEL_BUTTON : OK_BUTTON]) ==
DITEM_FAILURE)
continue;
}
@ -470,8 +473,9 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
/*
* Print list item
*/
static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int status, int choice, int selected,
dialogMenuItem *me)
static void
print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int status, int choice, int selected,
dialogMenuItem *me)
{
int i;
@ -494,5 +498,8 @@ static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int
wmove(win, choice, item_x);
wattrset(win, selected ? item_selected_attr : item_attr);
waddstr(win, item);
/* If have a selection handler for this, call it */
if (me && me->selected)
me->selected(me, selected);
}
/* End of print_item() */

View File

@ -11,7 +11,7 @@
.\" nor does the author assume any responsibility for damages incurred with
.\" its use.
.\"
.\" $Id$
.\" $Id: dialog.3,v 1.1 1995/12/23 01:10:15 jkh Exp $
.\"
.Dd December 18, 1995
.Dt dialog 3
@ -63,6 +63,7 @@ typedef struct _dmenu_item {
char *\fBtitle\fR;
int (*\fBchecked\fR)(struct _dmenu_item *self);
int (*\fBfire\fR)(struct _dmenu_item *self);
int (*\fBselected\fR)(struct _dmenu_item *self, int is_selected);
void *\fBdata\fR;
char \fBlbra\fR, \fBmark\fR, \fBrbra\fR;
} \fBdialogMenuItem\fR;
@ -72,20 +73,29 @@ The \fBprompt\fR and \fBtitle\fR strings are pretty much self-explanatory,
and the \fBchecked\fR and \fBfire\fR function pointers provide optional
display and action hooks (the \fBdata\fR variable being available for
the convenience of those hooks) when more tightly coupled feedback between
a menu object and user code is required. A number of clever tricks for
simulating various kinds of item types can also be done by adjusting the
values of \fBlbra\fR (default: '['), \fB\mark\fR (default: '*' for radio
menus, 'X' for check menus) and \fBrbra\fR (default: ']') and declaring
a reasonable \fBchecked\fR hook, which should return TRUE for the `marked' state
and FALSE for `unmarked.' If an item has a \fBfire\fR hook associated
with it, it will also be called whenever the item is "toggled" in some way
and should return one of the following codes:
a menu object and user code is required. The \fBselected\fR hook also
allows you to verify whether or not a given item is selected (the cursor is
over it) for implementing pretty much any possible context-sensitive
behavior. A number of clever tricks for simulating various kinds of item
types can also be done by adjusting the values of \fBlbra\fR
(default: '['), \fB\mark\fR (default: '*' for radio menus, 'X' for check menus)
and \fBrbra\fR (default: ']') and declaring a reasonable \fBchecked\fR hook,
which should return TRUE for the `marked' state and FALSE for `unmarked.'
If an item has a \fBfire\fR hook associated with it, it will also be called
whenever the item is "toggled" in some way and should return one of the
following codes:
.nf
#define DITEM_SUCCESS 0 /* Successful completion */
#define DITEM_FAILURE -1 /* Failed to "fire" */
#define DITEM_LEAVE_MENU -2 /* Treat selection as "Ok" */
#define DITEM_REDRAW -3 /* Menu has changed, redraw it */
Two special globals also exist for putting a dialog at any arbitrary
X,Y location (the early designers rather short-sightedly made no provisions
for this). If set to zero, the default centering behavior will be in
effect.
.fi
.Sh SYNOPSIS

View File

@ -54,6 +54,7 @@ typedef struct _dmenu_item {
char *title;
int (*checked)(struct _dmenu_item *self);
int (*fire)(struct _dmenu_item *self);
void (*selected)(struct _dmenu_item *self, int is_selected);
void *data;
char lbra, mark, rbra;
} dialogMenuItem;
@ -68,6 +69,7 @@ typedef struct _dmenu_item {
#define FALSE (0)
#endif
extern int DialogX, DialogY;
/*
* Attribute names

View File

@ -47,8 +47,8 @@ int dialog_inputbox(unsigned char *title, unsigned char *prompt, int height, int
if (height > LINES)
height = LINES;
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
x = DialogX ? DialogX : (COLS - width)/2;
y = DialogY ? DialogY : (LINES - height)/2;
#ifdef HAVE_NCURSES
if (use_shadow)

View File

@ -85,6 +85,11 @@
#include "colors.h"
#endif
/* These are two "secret" globals that can be fiddled to make a dialog
* come up someplace other than a "centered" calculation for X,Y
*/
int DialogX, DialogY;
/*
* Do some initialization for dialog
*/
@ -114,6 +119,7 @@ void init_dialog(void)
/* Set screen to screen attribute */
dialog_clear_norefresh();
DialogX = DialogY = 0;
}
/* End of init_dialog() */

View File

@ -25,18 +25,22 @@
#include "dialog.priv.h"
#include <ncurses.h>
static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int choice, int selected);
static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int choice, int selected,
dialogMenuItem *me);
#define DREF(di, item) ((di) ? &((di)[(item)]) : NULL)
static int menu_width, tag_x, item_x;
/*
* Display a menu for choosing among a number of options
*/
int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, int menu_height,
int item_no, void *it, unsigned char *result, int *ch, int *sc)
int
dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, int menu_height,
int item_no, void *it, unsigned char *result, int *ch, int *sc)
{
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
l, k, scroll = 0, max_choice, redraw_menu = FALSE;
l, k, scroll = 0, max_choice, redraw_menu = FALSE;
char okButton, cancelButton;
WINDOW *dialog, *menu;
unsigned char **items;
@ -92,8 +96,8 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
if (height > LINES)
height = LINES;
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
x = DialogX ? DialogX : (COLS - width)/2;
y = DialogY ? DialogY : (LINES - height)/2;
#ifdef HAVE_NCURSES
if (use_shadow)
@ -152,7 +156,7 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
/* Print the menu */
for (i = 0; i < max_choice; i++)
print_item(menu, items[(scroll+i)*2], items[(scroll+i)*2 + 1], i, i == choice);
print_item(menu, items[(scroll+i)*2], items[(scroll+i)*2 + 1], i, i == choice, DREF(ditems, scroll + i));
wnoutrefresh(menu);
print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y);
@ -164,10 +168,10 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
if (ditems && result) {
cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]);
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? (*ditems[CANCEL_BUTTON].checked)(&ditems[CANCEL_BUTTON]) : FALSE);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : FALSE);
okButton = toupper(ditems[OK_BUTTON].prompt[0]);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? (*ditems[OK_BUTTON].checked)(&ditems[OK_BUTTON]) : TRUE);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : TRUE);
}
else {
cancelButton = 'C';
@ -184,7 +188,7 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
/* Shortcut to OK? */
if (toupper(key) == okButton) {
if (ditems && result && ditems[OK_BUTTON].fire) {
if ((*ditems[OK_BUTTON].fire)(&ditems[OK_BUTTON]) == DITEM_FAILURE)
if (ditems[OK_BUTTON].fire(&ditems[OK_BUTTON]) == DITEM_FAILURE)
continue;
else
delwin(dialog);
@ -198,7 +202,7 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
/* Shortcut to cancel? */
else if (toupper(key) == cancelButton) {
if (ditems && result && ditems[CANCEL_BUTTON].fire) {
if ((*ditems[CANCEL_BUTTON].fire)(&ditems[CANCEL_BUTTON]) == DITEM_FAILURE)
if (ditems[CANCEL_BUTTON].fire(&ditems[CANCEL_BUTTON]) == DITEM_FAILURE)
continue;
}
delwin(dialog);
@ -221,13 +225,13 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
getyx(dialog, cur_y, cur_x); /* Save cursor position */
if (menu_height > 1) {
/* De-highlight current first item before scrolling down */
print_item(menu, items[scroll*2], items[scroll*2 + 1], 0, FALSE);
print_item(menu, items[scroll*2], items[scroll*2 + 1], 0, FALSE, DREF(ditems, scroll));
scrollok(menu, TRUE);
wscrl(menu, -1);
scrollok(menu, FALSE);
}
scroll--;
print_item(menu, items[scroll*2], items[scroll*2 + 1], 0, TRUE);
print_item(menu, items[scroll*2], items[scroll*2 + 1], 0, TRUE, DREF(ditems, scroll));
wnoutrefresh(menu);
print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y);
wrefresh(dialog);
@ -244,13 +248,15 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
getyx(dialog, cur_y, cur_x); /* Save cursor position */
if (menu_height > 1) {
/* De-highlight current last item before scrolling up */
print_item(menu, items[(scroll+max_choice-1)*2], items[(scroll+max_choice-1)*2 + 1], max_choice-1, FALSE);
print_item(menu, items[(scroll + max_choice - 1) * 2], items[(scroll + max_choice - 1) * 2 + 1],
max_choice-1, FALSE, DREF(ditems, scroll + max_choice - 1));
scrollok(menu, TRUE);
scroll(menu);
scrollok(menu, FALSE);
}
scroll++;
print_item(menu, items[(scroll+max_choice-1)*2], items[(scroll+max_choice-1)*2 + 1], max_choice-1, TRUE);
print_item(menu, items[(scroll + max_choice - 1) * 2], items[(scroll + max_choice - 1) * 2 + 1],
max_choice - 1, TRUE, DREF(ditems, scroll + max_choice - 1));
wnoutrefresh(menu);
print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y);
wrefresh(dialog);
@ -263,11 +269,13 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
if (i != choice) {
/* De-highlight current item */
getyx(dialog, cur_y, cur_x); /* Save cursor position */
print_item(menu, items[(scroll+choice)*2], items[(scroll+choice)*2 + 1], choice, FALSE);
print_item(menu, items[(scroll + choice) * 2], items[(scroll + choice) * 2 + 1], choice, FALSE,
DREF(ditems, scroll + choice));
/* Highlight new item */
choice = i;
print_item(menu, items[(scroll+choice)*2], items[(scroll+choice)*2 + 1], choice, TRUE);
print_item(menu, items[(scroll + choice) * 2], items[(scroll + choice) * 2 + 1], choice, TRUE,
DREF(ditems, scroll + choice));
wnoutrefresh(menu);
wmove(dialog, cur_y, cur_x); /* Restore cursor to previous position */
wrefresh(dialog);
@ -322,15 +330,15 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
if (ditems && result) {
if (button) {
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? (*ditems[OK_BUTTON].checked)(&ditems[OK_BUTTON]) : !button);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? (*ditems[CANCEL_BUTTON].checked)(&ditems[CANCEL_BUTTON]) : button);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
}
else {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? (*ditems[CANCEL_BUTTON].checked)(&ditems[CANCEL_BUTTON]) : button);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? (*ditems[OK_BUTTON].checked)(&ditems[OK_BUTTON]) : !button);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
}
}
else {
@ -351,7 +359,7 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
case '\n':
if (!button) {
if (ditems && ditems[scroll + choice].fire) {
if ((*ditems[scroll + choice].fire)(&ditems[scroll + choice]) == DITEM_FAILURE)
if (ditems[scroll + choice].fire(&ditems[scroll + choice]) == DITEM_FAILURE)
continue;
}
else if (result)
@ -371,8 +379,8 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
if (redraw_menu) {
for (i = 0; i < max_choice; i++) {
print_item(menu, items[(scroll+i)*2],
items[(scroll+i)*2 + 1], i, i == choice);
print_item(menu, items[(scroll + i) * 2], items[(scroll + i) * 2 + 1], i, i == choice,
DREF(ditems, scroll + i));
}
wnoutrefresh(menu);
print_arrows(dialog, scroll, menu_height, item_no, box_x, box_y, tag_x, cur_x, cur_y);
@ -390,7 +398,8 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
/*
* Print menu item
*/
static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int choice, int selected)
static void
print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int choice, int selected, dialogMenuItem *me)
{
int i;
@ -407,6 +416,11 @@ static void print_item(WINDOW *win, unsigned char *tag, unsigned char *item, int
wmove(win, choice, item_x);
wattrset(win, selected ? item_selected_attr : item_attr);
waddstr(win, item);
/* If have a selection handler for this, call it */
if (me && me->selected) {
wrefresh(win);
me->selected(me, selected);
}
}
/* End of print_item() */

View File

@ -53,8 +53,8 @@ int dialog_msgbox(unsigned char *title, unsigned char *prompt, int height, int w
if (height > LINES)
height = LINES;
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
x = DialogX ? DialogX : (COLS - width)/2;
y = DialogY ? DialogY : (LINES - height)/2;
#ifdef HAVE_NCURSES
if (use_shadow)

View File

@ -49,8 +49,8 @@ int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, i
if (height > LINES)
height = LINES;
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
x = DialogX ? DialogX : (COLS - width)/2;
y = DialogY ? DialogY : (LINES - height)/2;
#ifdef HAVE_NCURSES
if (use_shadow)

View File

@ -26,8 +26,7 @@
#include "dialog.priv.h"
static void print_item(WINDOW *win, char *tag, char *item, int status, int choice, int selected,
dialogMenuItem *me);
static void print_item(WINDOW *win, char *tag, char *item, int status, int choice, int selected, dialogMenuItem *me);
#define DREF(di, item) ((di) ? &((di)[(item)]) : NULL)
@ -37,11 +36,12 @@ static int list_width, check_x, item_x;
/*
* Display a dialog box with a list of options that can be turned on or off
*/
int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height,
int item_no, void *it, unsigned char *result)
int
dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height,
int item_no, void *it, unsigned char *result)
{
int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
l, k, scroll = 0, max_choice, *status, was_on = 0;
l, k, scroll = 0, max_choice, *status, was_on = 0;
int redraw_menu = FALSE;
char okButton, cancelButton;
WINDOW *dialog, *list;
@ -78,7 +78,7 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
items = (unsigned char **)alloca((item_no * 3) * sizeof(unsigned char *));
/* Initializes status */
for (i = 0; i < item_no; i++) {
status[i] = ditems[i].checked ? (*ditems[i].checked)(&ditems[i]) : FALSE;
status[i] = ditems[i].checked ? ditems[i].checked(&ditems[i]) : FALSE;
if (status[i]) {
if (was_on)
status[i] = FALSE;
@ -118,8 +118,8 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
if (height > LINES)
height = LINES;
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
x = DialogX ? DialogX : (COLS - width)/2;
y = DialogY ? DialogY : (LINES - height)/2;
#ifdef HAVE_NCURSES
if (use_shadow)
@ -189,10 +189,10 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
if (ditems && result) {
cancelButton = toupper(ditems[CANCEL_BUTTON].prompt[0]);
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? (*ditems[CANCEL_BUTTON].checked)(&ditems[CANCEL_BUTTON]) : FALSE);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : FALSE);
okButton = toupper(ditems[OK_BUTTON].prompt[0]);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? (*ditems[OK_BUTTON].checked)(&ditems[OK_BUTTON]) : TRUE);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : TRUE);
}
else {
cancelButton = 'C';
@ -208,7 +208,7 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
/* See if its the short-cut to "OK" */
if (toupper(key) == okButton) {
if (ditems && result && ditems[OK_BUTTON].fire) {
if ((*ditems[OK_BUTTON].fire)(&ditems[OK_BUTTON]) == DITEM_FAILURE)
if (ditems[OK_BUTTON].fire(&ditems[OK_BUTTON]) == DITEM_FAILURE)
continue;
else
delwin(dialog);
@ -228,7 +228,7 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
/* Shortcut to cancel */
else if (toupper(key) == cancelButton) {
if (ditems && result && ditems[CANCEL_BUTTON].fire) {
if ((*ditems[CANCEL_BUTTON].fire)(&ditems[CANCEL_BUTTON]) == DITEM_FAILURE)
if (ditems[CANCEL_BUTTON].fire(&ditems[CANCEL_BUTTON]) == DITEM_FAILURE)
continue;
}
delwin(dialog);
@ -297,7 +297,7 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
continue;
else if (ditems) {
if (ditems[scroll + choice].fire) {
int st = (*ditems[scroll + choice].fire)(&ditems[scroll + choice]);
int st = ditems[scroll + choice].fire(&ditems[scroll + choice]);
if (st == DITEM_LEAVE_MENU) {
/* Allow a fire action to take us out of the menu */
@ -308,7 +308,7 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
continue;
}
for (i = 0; i < item_no; i++)
status[i] = ditems[i].checked ? (*ditems[i].checked)(&ditems[i]) : FALSE;
status[i] = ditems[i].checked ? ditems[i].checked(&ditems[i]) : FALSE;
}
else {
for (i = 0; i < item_no; i++)
@ -383,15 +383,15 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
if (ditems && result) {
if (button) {
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? (*ditems[OK_BUTTON].checked)(&ditems[OK_BUTTON]) : !button);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? (*ditems[CANCEL_BUTTON].checked)(&ditems[CANCEL_BUTTON]) : button);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
}
else {
print_button(dialog, ditems[CANCEL_BUTTON].prompt, y, x + strlen(ditems[OK_BUTTON].prompt) + 5,
ditems[CANCEL_BUTTON].checked ? (*ditems[CANCEL_BUTTON].checked)(&ditems[CANCEL_BUTTON]) : button);
ditems[CANCEL_BUTTON].checked ? ditems[CANCEL_BUTTON].checked(&ditems[CANCEL_BUTTON]) : button);
print_button(dialog, ditems[OK_BUTTON].prompt, y, x,
ditems[OK_BUTTON].checked ? (*ditems[OK_BUTTON].checked)(&ditems[OK_BUTTON]) : !button);
ditems[OK_BUTTON].checked ? ditems[OK_BUTTON].checked(&ditems[OK_BUTTON]) : !button);
}
}
else {
@ -412,7 +412,8 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
case '\n':
if (!button && result) {
if (ditems && ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire) {
if ((*ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire)(&ditems[button ? CANCEL_BUTTON : OK_BUTTON]) == DITEM_FAILURE)
if (ditems[button ? CANCEL_BUTTON : OK_BUTTON].fire(&ditems[button ? CANCEL_BUTTON : OK_BUTTON]) ==
DITEM_FAILURE)
continue;
}
else {
@ -459,8 +460,8 @@ int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, in
/*
* Print list item
*/
static void print_item(WINDOW *win, char *tag, char *item, int status, int choice, int selected,
dialogMenuItem *me)
static void
print_item(WINDOW *win, char *tag, char *item, int status, int choice, int selected, dialogMenuItem *me)
{
int i;
@ -483,5 +484,8 @@ static void print_item(WINDOW *win, char *tag, char *item, int status, int choic
wmove(win, choice, item_x);
wattrset(win, selected ? item_selected_attr : item_attr);
waddstr(win, item);
/* If have a selection handler for this, call it */
if (me && me->selected)
me->selected(me, selected);
}
/* End of print_item() */

View File

@ -89,8 +89,8 @@ int dialog_textbox(unsigned char *title, unsigned char *file, int height, int wi
if (height > LINES)
height = LINES;
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
x = DialogX ? DialogX : (COLS - width)/2;
y = DialogY ? DialogY : (LINES - height)/2;
#ifdef HAVE_NCURSES
if (use_shadow)

View File

@ -50,8 +50,8 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
if (height > LINES)
height = LINES;
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
x = DialogX ? DialogX : (COLS - width)/2;
y = DialogY ? DialogY : (LINES - height)/2;
#ifdef HAVE_NCURSES
if (use_shadow)