Upgrade.
Submitted by: Marc van Kempen <wmbfmk@urc.tue.nl>
This commit is contained in:
parent
072506ba00
commit
7f6e7c13b5
@ -1,10 +1,10 @@
|
||||
# Makefile for libdialog
|
||||
# $Id: Makefile,v 1.6 1994/10/28 05:36:38 jkh Exp $
|
||||
# $Id: Makefile,v 1.7 1995/02/15 19:43:49 ache Exp $
|
||||
|
||||
LIB= dialog
|
||||
SRCS= kernel.c rc.c checklist.c inputbox.c menubox.c msgbox.c \
|
||||
lineedit.c radiolist.c textbox.c yesno.c prgbox.c raw_popen.c \
|
||||
fselect.c ui_objects.c dir.c notify.c help.c
|
||||
fselect.c ui_objects.c dir.c notify.c help.c gauge.c
|
||||
|
||||
CFLAGS+= -I${.CURDIR} -Wall -Wstrict-prototypes -DLOCALE
|
||||
|
||||
|
@ -108,7 +108,12 @@ void end_dialog(void);
|
||||
|
||||
/* Additions to libdialog */
|
||||
char *dialog_fselect(char *dir, char *fmask);
|
||||
int dialog_dselect(void);
|
||||
void dialog_notify(char *msg);
|
||||
int dialog_mesgbox(unsigned char *title, unsigned char *prompt, int height, int width);
|
||||
void use_helpfile(char *helpfile);
|
||||
void use_helpline(char *helpline);
|
||||
char *get_helpline(void);
|
||||
void restore_helpline(char *helpline);
|
||||
void dialog_gauge(char *title, char *prompt, int y, int x,
|
||||
int height, int width, int perc);
|
||||
|
@ -34,3 +34,5 @@ typedef struct DirList { /* structure to hold the directory entries
|
||||
#endif
|
||||
|
||||
void get_dir(char *dirname, char *fmask, DirList **dir, int *n);
|
||||
void get_filenames(DirList *d, int n, char ***names, int *nf);
|
||||
void FreeDir(DirList *d, int n);
|
||||
|
@ -89,6 +89,110 @@ FreeNames(char **names, int n)
|
||||
return;
|
||||
} /* FreeNames() */
|
||||
|
||||
int
|
||||
dialog_dselect(void)
|
||||
/*
|
||||
* Desc: starting from the current directory,
|
||||
* choose a new current directory
|
||||
*/
|
||||
{
|
||||
DirList *d = NULL;
|
||||
char **names, old_dir[MAXPATHLEN];
|
||||
WINDOW *ds_win;
|
||||
ButtonObj *okbut, *cancelbut;
|
||||
ListObj *dirs_obj;
|
||||
StringObj *dir_obj;
|
||||
char o_dir[MAXPATHLEN];
|
||||
struct ComposeObj *obj = NULL;
|
||||
int n, nd, okbutton, cancelbutton,
|
||||
quit, cancel, ret;
|
||||
|
||||
ds_win = newwin(LINES-8, COLS-30, 4, 15);
|
||||
if (ds_win == NULL) {
|
||||
fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n",
|
||||
LINES-8, COLS-30, 4, 15);
|
||||
exit(1);
|
||||
}
|
||||
draw_box(ds_win, 0, 0, LINES-8, COLS-30, dialog_attr, border_attr);
|
||||
wattrset(ds_win, dialog_attr);
|
||||
mvwaddstr(ds_win, 0, (COLS-30)/2 - 9, " Directory Select ");
|
||||
draw_shadow(stdscr, 4, 15, LINES-8, COLS-30);
|
||||
display_helpline(ds_win, LINES-9, COLS-30);
|
||||
|
||||
/* the Directory string input field */
|
||||
getcwd(o_dir, MAXPATHLEN);
|
||||
dir_obj = NewStringObj(ds_win, "Directory:", o_dir, 1, 2, COLS-34, MAXPATHLEN-1);
|
||||
AddObj(&obj, STRINGOBJ, (void *) dir_obj);
|
||||
|
||||
/* the list of directories */
|
||||
get_dir(".", "*", &d, &n);
|
||||
get_directories(d, n, &names, &nd);
|
||||
dirs_obj = NewListObj(ds_win, "Directories:", names, o_dir, 5, 2,
|
||||
LINES-15, COLS-48, nd);
|
||||
AddObj(&obj, LISTOBJ, (void *) dirs_obj);
|
||||
|
||||
/* the Ok-button */
|
||||
okbutton = FALSE;
|
||||
okbut = NewButtonObj(ds_win, "Ok", &okbutton, 7, COLS-42);
|
||||
AddObj(&obj, BUTTONOBJ, (void *) okbut);
|
||||
|
||||
/* the Cancel-button */
|
||||
cancelbutton = FALSE;
|
||||
cancelbut = NewButtonObj(ds_win, "Cancel", &cancelbutton, 11, COLS-44);
|
||||
AddObj(&obj, BUTTONOBJ, (void *) cancelbut);
|
||||
|
||||
quit = FALSE;
|
||||
cancel = FALSE;
|
||||
strcpy(old_dir, o_dir);
|
||||
while (!quit) {
|
||||
ret = PollObj(&obj);
|
||||
switch(ret) {
|
||||
case SEL_BUTTON:
|
||||
if (okbutton) {
|
||||
quit = TRUE;
|
||||
}
|
||||
if (cancelbutton) {
|
||||
quit = TRUE;
|
||||
cancel = TRUE;
|
||||
}
|
||||
break;
|
||||
case SEL_CR:
|
||||
if (strcmp(old_dir, o_dir)) {
|
||||
/* the directory was changed, cd into it */
|
||||
if (chdir(o_dir)) {
|
||||
dialog_notify("Could not change into directory");
|
||||
} else {
|
||||
getcwd(o_dir, MAXPATHLEN);
|
||||
strcpy(old_dir, o_dir);
|
||||
RefreshStringObj(dir_obj);
|
||||
}
|
||||
}
|
||||
get_dir(".", "*", &d, &n);
|
||||
FreeNames(names, nd);
|
||||
get_directories(d, n, &names, &nd);
|
||||
UpdateListObj(dirs_obj, names, nd);
|
||||
if (((obj->prev)->obj == (void *) dirs_obj)) {
|
||||
obj=obj->prev;
|
||||
}
|
||||
break;
|
||||
case SEL_ESC:
|
||||
quit = TRUE;
|
||||
cancel = TRUE;
|
||||
break;
|
||||
case KEY_F(1):
|
||||
display_helpfile();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FreeNames(names, nd);
|
||||
DelObj(obj);
|
||||
delwin(ds_win);
|
||||
|
||||
return(cancel);
|
||||
|
||||
} /* dialog_dselect() */
|
||||
|
||||
char *
|
||||
dialog_fselect(char *dir, char *fmask)
|
||||
/*
|
||||
@ -103,7 +207,7 @@ dialog_fselect(char *dir, char *fmask)
|
||||
{
|
||||
DirList *d = NULL;
|
||||
char msg[512];
|
||||
char **names, *ret_name;
|
||||
char **fnames, **dnames, *ret_name;
|
||||
WINDOW *fs_win;
|
||||
int n, nd, nf, ret;
|
||||
StringObj *fm_obj, *dir_obj, *sel_obj;
|
||||
@ -146,14 +250,14 @@ dialog_fselect(char *dir, char *fmask)
|
||||
|
||||
/* Directory list */
|
||||
get_dir(".", fmask, &d, &n); /* read the entire directory */
|
||||
get_directories(d, n, &names, &nd); /* extract the dir-entries */
|
||||
dirs_obj = NewListObj(fs_win, "Directories:", names, o_dir, 5, 2,
|
||||
get_directories(d, n, &dnames, &nd); /* extract the dir-entries */
|
||||
dirs_obj = NewListObj(fs_win, "Directories:", dnames, o_dir, 5, 2,
|
||||
LINES-16, (COLS-20)/2-2, nd);
|
||||
AddObj(&obj, LISTOBJ, (void *) dirs_obj);
|
||||
|
||||
/* Filenames list */
|
||||
get_filenames(d, n, &names, &nf); /* extract the filenames */
|
||||
files_obj = NewListObj(fs_win, "Files:", names, o_sel, 5, (COLS-20)/2+1,
|
||||
get_filenames(d, n, &fnames, &nf); /* extract the filenames */
|
||||
files_obj = NewListObj(fs_win, "Files:", fnames, o_sel, 5, (COLS-20)/2+1,
|
||||
LINES-16, (COLS-20)/2-3, nf);
|
||||
AddObj(&obj, LISTOBJ, (void *) files_obj);
|
||||
|
||||
@ -200,10 +304,12 @@ dialog_fselect(char *dir, char *fmask)
|
||||
strcpy(old_fmask, o_fm);
|
||||
}
|
||||
get_dir(".", o_fm, &d, &n);
|
||||
get_directories(d, n, &names, &nd);
|
||||
UpdateListObj(dirs_obj, names, nd);
|
||||
get_filenames(d, n, &names, &nf);
|
||||
UpdateListObj(files_obj, names, nf);
|
||||
FreeNames(dnames, nd);
|
||||
get_directories(d, n, &dnames, &nd);
|
||||
UpdateListObj(dirs_obj, dnames, nd);
|
||||
FreeNames(fnames, nf);
|
||||
get_filenames(d, n, &fnames, &nf);
|
||||
UpdateListObj(files_obj, fnames, nf);
|
||||
if (((o->prev)->obj == (void *) dirs_obj)) {
|
||||
o=o->prev;
|
||||
}
|
||||
@ -230,6 +336,9 @@ dialog_fselect(char *dir, char *fmask)
|
||||
}
|
||||
}
|
||||
DelObj(obj);
|
||||
FreeNames(dnames, nd);
|
||||
FreeNames(fnames, nf);
|
||||
delwin(fs_win);
|
||||
|
||||
if (cancel || (strlen(o_sel) == 0)) {
|
||||
return(NULL);
|
||||
|
72
gnu/lib/libdialog/gauge.c
Normal file
72
gnu/lib/libdialog/gauge.c
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* gauge.c
|
||||
*
|
||||
* progress indicator for libdialog
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1995, Marc van Kempen
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software may be used, modified, copied, distributed, and
|
||||
* sold, in both source and binary form provided that the above
|
||||
* copyright and these terms are retained, verbatim, as the first
|
||||
* lines of this file. Under no circumstances is the author
|
||||
* responsible for the proper functioning of this software, nor does
|
||||
* the author assume any responsibility for damages incurred with
|
||||
* its use.
|
||||
*/
|
||||
|
||||
#include "dialog.h"
|
||||
|
||||
void
|
||||
dialog_gauge(char *title, char *prompt, int y, int x,
|
||||
int height, int width, int perc)
|
||||
/*
|
||||
* Desc: display a progress bar, progress indicated by <perc>
|
||||
*/
|
||||
{
|
||||
WINDOW *gw;
|
||||
int glen, i;
|
||||
char percs[5];
|
||||
|
||||
gw = newwin(height, width, y, x);
|
||||
if (!gw) {
|
||||
fprintf(stderr, "dialog_gauge: Error creating window (%d, %d, %d, %d)",
|
||||
height, width, y, x);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
draw_box(gw, 0, 0, height, width, dialog_attr, border_attr);
|
||||
draw_shadow(stdscr, y, x, height, width);
|
||||
|
||||
wattrset(gw, title_attr);
|
||||
if (title) {
|
||||
wmove(gw, 0, (width - strlen(title))/2 - 1);
|
||||
waddstr(gw, "[ ");
|
||||
waddstr(gw, title);
|
||||
waddstr(gw, " ]");
|
||||
}
|
||||
wattrset(gw, dialog_attr);
|
||||
if (prompt) {
|
||||
wmove(gw, 1, (width - strlen(prompt))/2 - 1);
|
||||
waddstr(gw, prompt);
|
||||
}
|
||||
|
||||
draw_box(gw, 2, 2, 3, width-4, dialog_attr, border_attr);
|
||||
glen = (int) ((float) perc/100 * (width-6));
|
||||
|
||||
wattrset(gw, dialog_attr);
|
||||
sprintf(percs, "%3d%%", perc);
|
||||
wmove(gw, 5, width/2 - 2);
|
||||
waddstr(gw, percs);
|
||||
|
||||
wattrset(gw, A_BOLD);
|
||||
wmove(gw, 3, 3);
|
||||
for (i=0; i<glen; i++) waddch(gw, ' ');
|
||||
|
||||
wrefresh(gw);
|
||||
|
||||
return;
|
||||
} /* dialog_gauge() */
|
||||
|
@ -69,38 +69,37 @@ display_helpfile(void)
|
||||
if (in_help) return; /* dont call help when you're in help */
|
||||
|
||||
if (_helpfile != NULL) {
|
||||
if (_helpline != NULL) {
|
||||
savehline = _helpline;
|
||||
_helpline = NULL;
|
||||
}
|
||||
if ((w = dupwin(newscr)) == NULL) {
|
||||
dialog_notify("No memory to dup previous screen\n");
|
||||
goto ret;
|
||||
return;
|
||||
}
|
||||
if ((f = fopen(_helpfile, "r")) == NULL) {
|
||||
sprintf(msg, "Can't open helpfile : %s\n", _helpfile);
|
||||
dialog_notify(msg);
|
||||
goto ret;
|
||||
return;
|
||||
}
|
||||
if (fstat(fileno(f), &sb)) {
|
||||
sprintf(msg, "Can't stat helpfile : %s\n", _helpfile);
|
||||
dialog_notify(msg);
|
||||
goto ret;
|
||||
return;
|
||||
}
|
||||
if ((buf = (char *) malloc( sb.st_size )) == NULL) {
|
||||
sprintf(msg, "Could not malloc space for helpfile : %s\n", _helpfile);
|
||||
dialog_notify(msg);
|
||||
goto ret;
|
||||
return;
|
||||
}
|
||||
if (fread(buf, 1, sb.st_size, f) != sb.st_size) {
|
||||
sprintf(msg, "Could not read entire help file : %s", _helpfile);
|
||||
dialog_notify(msg);
|
||||
free(buf);
|
||||
goto ret;
|
||||
return;
|
||||
}
|
||||
buf[sb.st_size] = 0;
|
||||
in_help = TRUE;
|
||||
savehline = get_helpline();
|
||||
use_helpline("Use arrowkeys, PgUp, PgDn, Home and End to move through text");
|
||||
dialog_mesgbox("Online help", buf, LINES-4, COLS-4);
|
||||
restore_helpline(savehline);
|
||||
in_help = FALSE;
|
||||
touchwin(w);
|
||||
wrefresh(w);
|
||||
@ -110,10 +109,6 @@ display_helpfile(void)
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
ret:
|
||||
if (savehline != NULL)
|
||||
_helpline = savehline;
|
||||
|
||||
return;
|
||||
} /* display_helpfile() */
|
||||
|
||||
@ -167,3 +162,33 @@ display_helpline(WINDOW *w, int y, int width)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
char *
|
||||
get_helpline(void)
|
||||
/*
|
||||
* desc: allocate new space, copy the helpline to it and return a pointer to it
|
||||
*/
|
||||
{
|
||||
char *hlp;
|
||||
|
||||
if (_helpline) {
|
||||
hlp = (char *) malloc( strlen(_helpline) + 1 );
|
||||
strcpy(hlp, _helpline);
|
||||
} else {
|
||||
hlp = NULL;
|
||||
}
|
||||
|
||||
return(hlp);
|
||||
} /* get_helpline() */
|
||||
|
||||
void
|
||||
restore_helpline(char *helpline)
|
||||
/*
|
||||
* Desc: set the helpline to <helpline> and free the space allocated to it
|
||||
*/
|
||||
{
|
||||
use_helpline(helpline);
|
||||
free(helpline);
|
||||
|
||||
return;
|
||||
} /* restore_helpline() */
|
||||
|
@ -200,10 +200,11 @@ dialog_mesgbox(unsigned char *title, unsigned char *prompt, int height, int widt
|
||||
if (startline < max_lines - theight) startline++;
|
||||
break;
|
||||
case KEY_RIGHT:
|
||||
hscroll++;
|
||||
hscroll+=5;
|
||||
break;
|
||||
case KEY_LEFT:
|
||||
if (hscroll > 0) hscroll--;
|
||||
if (hscroll > 0) hscroll-=5;
|
||||
if (hscroll < 0) hscroll =0;
|
||||
break;
|
||||
case KEY_PPAGE:
|
||||
if (startline - height > 0) {
|
||||
@ -260,10 +261,11 @@ getnlines(unsigned char *buf)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (*buf)
|
||||
i++;
|
||||
while (*buf) {
|
||||
if (*buf == '\n' || *buf == '\r') {
|
||||
if (*buf == '\n' || *buf == '\r')
|
||||
i++;
|
||||
}
|
||||
buf++;
|
||||
}
|
||||
return(i);
|
||||
|
@ -27,6 +27,7 @@ dialog_notify(char *msg)
|
||||
* Desc: display an error message
|
||||
*/
|
||||
{
|
||||
char *tmphlp;
|
||||
WINDOW *w;
|
||||
|
||||
w = dupwin(newscr);
|
||||
@ -35,7 +36,10 @@ dialog_notify(char *msg)
|
||||
fprintf(stderr, "\ndupwin(newscr) failed, malloc memory corrupted\n");
|
||||
exit(1);
|
||||
}
|
||||
tmphlp = get_helpline();
|
||||
use_helpline("Press enter to continue");
|
||||
dialog_msgbox("Message", msg, -1, -1, TRUE);
|
||||
restore_helpline(tmphlp);
|
||||
touchwin(w);
|
||||
wrefresh(w);
|
||||
delwin(w);
|
||||
|
@ -355,9 +355,13 @@ DrawNames(ListObj *lo)
|
||||
x = lo->x + 1;
|
||||
y = lo->y + 2;
|
||||
h = lo->h - 2;
|
||||
wattrset(lo->win, item_attr);
|
||||
for (i=lo->scroll; i<lo->n && i<lo->scroll+h; i++) {
|
||||
wmove(lo->win, y+i-lo->scroll, x);
|
||||
if (lo->seld[i]) {
|
||||
wattrset(lo->win, A_BOLD);
|
||||
} else {
|
||||
wattrset(lo->win, item_attr);
|
||||
}
|
||||
if (strlen(lo->name[i]) > lo->w-2) {
|
||||
strncpy(tmp, lo->name[i], lo->w-2);
|
||||
tmp[lo->w - 2] = 0;
|
||||
@ -367,6 +371,7 @@ DrawNames(ListObj *lo)
|
||||
for (j=strlen(lo->name[i]); j<lo->w-2; j++) waddstr(lo->win, " ");
|
||||
}
|
||||
}
|
||||
wattrset(lo->win, item_attr);
|
||||
while (i<lo->scroll+h) {
|
||||
wmove(lo->win, y+i-lo->scroll, x);
|
||||
for (j=0; j<lo->w-2; j++) waddstr(lo->win, " ");
|
||||
@ -411,20 +416,33 @@ NewListObj(WINDOW *win, char *title, char **list, char *listelt, int y, int x,
|
||||
*/
|
||||
{
|
||||
ListObj *lo;
|
||||
int i;
|
||||
|
||||
/* Initialize a new object */
|
||||
lo = (ListObj *) malloc( sizeof(ListObj) );
|
||||
if (!lo) {
|
||||
printf("NewListObj: Error malloc'ing ListObj\n");
|
||||
fprintf(stderr, "NewListObj: Error malloc'ing ListObj\n");
|
||||
exit(-1);
|
||||
}
|
||||
lo->title = (char *) malloc( strlen(title) + 1);
|
||||
if (!lo->title) {
|
||||
printf("NewListObj: Error malloc'ing lo->title\n");
|
||||
fprintf(stderr, "NewListObj: Error malloc'ing lo->title\n");
|
||||
exit(-1);
|
||||
}
|
||||
strcpy(lo->title, title);
|
||||
lo->name = list;
|
||||
if (n>0) {
|
||||
lo->seld = (int *) malloc( n * sizeof(int) );
|
||||
if (!lo->seld) {
|
||||
fprintf(stderr, "NewListObj: Error malloc'ing lo->seld\n");
|
||||
exit(-1);
|
||||
}
|
||||
for (i=0; i<n; i++) {
|
||||
lo->seld[i] = FALSE;
|
||||
}
|
||||
} else {
|
||||
lo->seld = NULL;
|
||||
}
|
||||
lo->y = y;
|
||||
lo->x = x;
|
||||
lo->w = w;
|
||||
@ -445,22 +463,30 @@ void
|
||||
UpdateListObj(ListObj *lo, char **list, int n)
|
||||
/*
|
||||
* Desc: Update the list in the listobject with the provided list
|
||||
* Pre: lo->name "has been allocated"
|
||||
* (A i: 0<=i<lo->n: "lo->name[i] has been allocated")
|
||||
* Pre: lo->name "has been freed"
|
||||
* "(A i: 0<=i<lo->n: "lo->name[i] has been freed")"
|
||||
*/
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Free the current names */
|
||||
if (lo->name != NULL) {
|
||||
for (i=0; i<lo->n; i++) {
|
||||
free(lo->name[i]);
|
||||
}
|
||||
free(lo->name);
|
||||
if (lo->seld) {
|
||||
free(lo->seld);
|
||||
}
|
||||
|
||||
/* Rewrite the list in the object */
|
||||
lo->name = list;
|
||||
if (n>0) {
|
||||
lo->seld = (int *) malloc( n * sizeof(int) );
|
||||
if (!lo->seld) {
|
||||
fprintf(stderr, "UpdateListObj: Error malloc'ing lo->seld\n");
|
||||
exit(-1);
|
||||
}
|
||||
for (i=0; i<n; i++) {
|
||||
lo->seld[i] = FALSE;
|
||||
}
|
||||
} else {
|
||||
lo->seld = NULL;
|
||||
}
|
||||
lo->n = n;
|
||||
lo->scroll = 0;
|
||||
lo->sel = 0;
|
||||
@ -478,7 +504,7 @@ SelectListObj(ListObj *lo)
|
||||
* Pre: lo->n >= 1
|
||||
*/
|
||||
{
|
||||
int key, sel_x, sel_y;
|
||||
int key, sel_x, sel_y, quit;
|
||||
char tmp[MAXPATHLEN];
|
||||
char perc[4];
|
||||
|
||||
@ -495,11 +521,16 @@ SelectListObj(ListObj *lo)
|
||||
waddstr(lo->win, lo->name[lo->sel]);
|
||||
|
||||
key = wgetch(lo->win);
|
||||
quit = FALSE;
|
||||
while ((key != '\t') && (key != '\n') && (key != '\r')
|
||||
&& (key != ESC) && (key != KEY_F(1)) && (key != '?')) {
|
||||
&& (key != ESC) && (key != KEY_F(1)) && (key != '?') && !quit) {
|
||||
/* first draw current item in normal video */
|
||||
wmove(lo->win, sel_y, sel_x);
|
||||
wattrset(lo->win, item_attr);
|
||||
if (lo->seld[lo->sel]) {
|
||||
wattrset(lo->win, A_BOLD);
|
||||
} else {
|
||||
wattrset(lo->win, item_attr);
|
||||
}
|
||||
if (strlen(lo->name[lo->sel]) > lo->w - 2) {
|
||||
strncpy(tmp, lo->name[lo->sel], lo->w - 2);
|
||||
tmp[lo->w - 2] = 0;
|
||||
@ -585,6 +616,9 @@ SelectListObj(ListObj *lo)
|
||||
DrawNames(lo);
|
||||
wrefresh(lo->win);
|
||||
break;
|
||||
default:
|
||||
quit = TRUE;
|
||||
break;
|
||||
}
|
||||
/* Draw % indication */
|
||||
sprintf(perc, "(%3d%%)", MIN(100, (int)
|
||||
@ -607,7 +641,7 @@ SelectListObj(ListObj *lo)
|
||||
} else {
|
||||
waddstr(lo->win, lo->name[lo->sel]);
|
||||
}
|
||||
key = wgetch(lo->win);
|
||||
if (!quit) key = wgetch(lo->win);
|
||||
}
|
||||
|
||||
if (key == ESC) {
|
||||
@ -632,20 +666,57 @@ DelListObj(ListObj *lo)
|
||||
* Desc: Free the space occupied by the listobject
|
||||
*/
|
||||
{
|
||||
int i;
|
||||
|
||||
free(lo->title);
|
||||
if (lo->name != NULL) {
|
||||
for (i=0; i<lo->n; i++) {
|
||||
free(lo->name[i]);
|
||||
}
|
||||
free(lo->name);
|
||||
}
|
||||
|
||||
if (lo->seld != NULL) free(lo->seld);
|
||||
free(lo);
|
||||
|
||||
return;
|
||||
} /* DelListObj() */
|
||||
|
||||
void
|
||||
MarkCurrentListObj(ListObj *lo)
|
||||
/*
|
||||
* Desc: mark the current item for the selection list
|
||||
*/
|
||||
{
|
||||
lo->seld[lo->sel] = !(lo->seld[lo->sel]);
|
||||
DrawNames(lo);
|
||||
|
||||
return;
|
||||
} /* MarkCurrentListObj() */
|
||||
|
||||
void
|
||||
MarkAllListObj(ListObj *lo)
|
||||
/*
|
||||
* Desc: mark all items
|
||||
*/
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<lo->n; i++) {
|
||||
lo->seld[i] = TRUE;
|
||||
}
|
||||
DrawNames(lo);
|
||||
|
||||
return;
|
||||
} /* MarkAllListObj() */
|
||||
|
||||
void
|
||||
UnMarkAllListObj(ListObj *lo)
|
||||
/*
|
||||
* Desc: unmark all items
|
||||
*/
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<lo->n; i++) {
|
||||
lo->seld[i] = FALSE;
|
||||
}
|
||||
DrawNames(lo);
|
||||
|
||||
return;
|
||||
} /* UnMarkAllListObj() */
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
|
@ -59,6 +59,7 @@ typedef struct {
|
||||
WINDOW *win; /* the windows it's contained in */
|
||||
char *title; /* the title of the list */
|
||||
char **name; /* the names of the list */
|
||||
int *seld; /* the currently selected names */
|
||||
char *elt; /* the current element in the list list[sel] */
|
||||
int x, y, w, h, n; /* dimensions of list and # of elements (n) */
|
||||
int scroll, sel; /* current position in the list */
|
||||
@ -95,6 +96,9 @@ ListObj *NewListObj(WINDOW *win, char *title, char **list,
|
||||
void UpdateListObj(ListObj *lo, char **list, int n);
|
||||
int SelectListObj(ListObj *lo);
|
||||
void DelListObj(ListObj *obj);
|
||||
void MarkCurrentListObj(ListObj *lo);
|
||||
void MarkAllListObj(ListObj *lo);
|
||||
void UnMarkAllListObj(ListObj *lo);
|
||||
|
||||
void RefreshButtonObj(ButtonObj *bo);
|
||||
ButtonObj *NewButtonObj(WINDOW *win, char *title, int *pushed,
|
||||
|
@ -30,6 +30,11 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
|
||||
{
|
||||
int i, j, x, y, key = 0, button = 0;
|
||||
WINDOW *dialog;
|
||||
char *tmphlp;
|
||||
|
||||
/* disable helpline */
|
||||
tmphlp = get_helpline();
|
||||
use_helpline(NULL);
|
||||
|
||||
if (height < 0)
|
||||
height = strheight(prompt)+4;
|
||||
@ -97,10 +102,12 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
|
||||
case 'Y':
|
||||
case 'y':
|
||||
delwin(dialog);
|
||||
restore_helpline(tmphlp);
|
||||
return 0;
|
||||
case 'N':
|
||||
case 'n':
|
||||
delwin(dialog);
|
||||
restore_helpline(tmphlp);
|
||||
return 1;
|
||||
case KEY_BTAB:
|
||||
case TAB:
|
||||
@ -124,6 +131,7 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
|
||||
case '\r':
|
||||
case '\n':
|
||||
delwin(dialog);
|
||||
restore_helpline(tmphlp);
|
||||
return button;
|
||||
case ESC:
|
||||
break;
|
||||
@ -135,6 +143,7 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
|
||||
}
|
||||
|
||||
delwin(dialog);
|
||||
restore_helpline(tmphlp);
|
||||
return -1; /* ESC pressed */
|
||||
}
|
||||
/* End of dialog_yesno() */
|
||||
|
Loading…
Reference in New Issue
Block a user