summaryrefslogtreecommitdiffstats
path: root/gnu
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1994-11-16 14:37:37 +0000
committerache <ache@FreeBSD.org>1994-11-16 14:37:37 +0000
commite26dcdfe6d1edef038874549fad1387f81b491ca (patch)
tree6d42ce10ce8c7263feab1c0a86525a16826ae40e /gnu
parent0cbabcf40fb04b5e1dd6d21c9febc638f8734018 (diff)
downloadFreeBSD-src-e26dcdfe6d1edef038874549fad1387f81b491ca.zip
FreeBSD-src-e26dcdfe6d1edef038874549fad1387f81b491ca.tar.gz
Full autosizing support, now you can pass -1, -1 for any
string
Diffstat (limited to 'gnu')
-rw-r--r--gnu/lib/libdialog/checklist.c18
-rw-r--r--gnu/lib/libdialog/dialog.h6
-rw-r--r--gnu/lib/libdialog/inputbox.c10
-rw-r--r--gnu/lib/libdialog/kernel.c50
-rw-r--r--gnu/lib/libdialog/menubox.c25
-rw-r--r--gnu/lib/libdialog/msgbox.c10
-rw-r--r--gnu/lib/libdialog/prgbox.c2
-rw-r--r--gnu/lib/libdialog/radiolist.c27
-rw-r--r--gnu/lib/libdialog/yesno.c10
9 files changed, 134 insertions, 24 deletions
diff --git a/gnu/lib/libdialog/checklist.c b/gnu/lib/libdialog/checklist.c
index cc83d25..f33dfc2 100644
--- a/gnu/lib/libdialog/checklist.c
+++ b/gnu/lib/libdialog/checklist.c
@@ -34,7 +34,7 @@ static int list_width, check_x, item_x;
*/
int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, int item_no, unsigned char **items, unsigned char *result)
{
- int i, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
+ int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
scroll = 0, max_choice, *status;
WINDOW *dialog, *list;
@@ -50,6 +50,22 @@ int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, in
max_choice = MIN(list_height, item_no);
+ check_x = 0;
+ item_x = 0;
+ /* Find length of longest item in order to center checklist */
+ for (i = 0; i < item_no; i++) {
+ check_x = MAX(check_x, strlen(items[i*3]) + strlen(items[i*3 + 1]) + 6);
+ item_x = MAX(item_x, strlen(items[i*3]));
+ }
+ if (height < 0)
+ height = strheight(prompt)+list_height+4+2;
+ if (width < 0) {
+ i = strwidth(prompt);
+ j = strwidth(title);
+ width = MAX(i,j);
+ width = MAX(width,check_x+10)+4;
+ }
+
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
diff --git a/gnu/lib/libdialog/dialog.h b/gnu/lib/libdialog/dialog.h
index f2b5d69..cb7053f 100644
--- a/gnu/lib/libdialog/dialog.h
+++ b/gnu/lib/libdialog/dialog.h
@@ -80,15 +80,17 @@ void draw_shadow(WINDOW *win, int y, int x, int height, int width);
#endif
void draw_box(WINDOW *win, int y, int x, int height, int width, chtype box, chtype border);
int line_edit(WINDOW* dialog, int box_y, int box_x, int box_width, chtype attrs, int first, unsigned char *result);
+int strheight(const char *p);
+int strwidth(const char *p);
void dialog_create_rc(unsigned char *filename);
int dialog_yesno(unsigned char *title, unsigned char *prompt, int height, int width);
-int dialog_prgbox(unsigned char *title, const char *line, int height, int width, int pause, int use_shell);
+int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, int width, int pause, int use_shell);
int dialog_msgbox(unsigned char *title, unsigned char *prompt, int height, int width, int pause);
int dialog_textbox(unsigned char *title, unsigned char *file, int height, int width);
int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, int menu_height, int item_no, unsigned char **items, unsigned char *result);
int dialog_checklist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, int item_no, unsigned char **items, unsigned char *result);
-int dialog_radiolist(char *title, char *prompt, int height, int width, int list_height, int item_no, unsigned char **items, unsigned char *result);
+int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, int item_no, unsigned char **items, unsigned char *result);
int dialog_inputbox(unsigned char *title, unsigned char *prompt, int height, int width, unsigned char *result);
void dialog_clear(void);
void dialog_update(void);
diff --git a/gnu/lib/libdialog/inputbox.c b/gnu/lib/libdialog/inputbox.c
index 197b4df..11e3566 100644
--- a/gnu/lib/libdialog/inputbox.c
+++ b/gnu/lib/libdialog/inputbox.c
@@ -28,11 +28,19 @@
*/
int dialog_inputbox(unsigned char *title, unsigned char *prompt, int height, int width, unsigned char *result)
{
- int i, x, y, box_y, box_x, box_width, first,
+ int i, j, x, y, box_y, box_x, box_width, first,
key = 0, button = -1;
unsigned char instr[MAX_LEN+1];
WINDOW *dialog;
+ if (height < 0)
+ height = strheight(prompt)+2+4;
+ if (width < 0) {
+ i = strwidth(prompt);
+ j = strwidth(title);
+ width = MAX(i,j) + 4;
+ }
+
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
diff --git a/gnu/lib/libdialog/kernel.c b/gnu/lib/libdialog/kernel.c
index 4e30c51..9309fec 100644
--- a/gnu/lib/libdialog/kernel.c
+++ b/gnu/lib/libdialog/kernel.c
@@ -422,3 +422,53 @@ void end_dialog(void)
{
endwin();
}
+
+int strwidth(const char *p)
+{
+ int i = 0, len, incr;
+ const char *start, *s, *s1, *s2;
+
+ for (start = s = p; ; start = (s += incr)) {
+ s1 = strchr(s, '\n');
+ s2 = strstr(s, "\\n");
+ if (s2 == NULL)
+ s = s1;
+ else if (s1 == NULL)
+ s = s2;
+ else
+ s = MIN(s1, s2);
+ if (s == NULL)
+ break;
+ incr = 1 + (s == s2);
+ len = s - start;
+ if (len > i)
+ i = len;
+ }
+ len = strlen(start);
+ if (len > i)
+ i = len;
+ return i;
+}
+
+int strheight(const char *p)
+{
+ int i = 1, incr;
+ const char *s, *s1, *s2;
+
+ for (s = p; ; s += incr) {
+ s1 = strchr(s, '\n');
+ s2 = strstr(s, "\\n");
+ if (s2 == NULL)
+ s = s1;
+ else if (s1 == NULL)
+ s = s2;
+ else
+ s = MIN(s1, s2);
+ if (s == NULL)
+ break;
+ incr = 1 + (s == s2);
+ i++;
+ }
+ return i;
+}
+
diff --git a/gnu/lib/libdialog/menubox.c b/gnu/lib/libdialog/menubox.c
index 5aa5b5b..3dd29e8 100644
--- a/gnu/lib/libdialog/menubox.c
+++ b/gnu/lib/libdialog/menubox.c
@@ -34,12 +34,28 @@ static int menu_width, tag_x, item_x;
*/
int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int width, int menu_height, int item_no, unsigned char **items, unsigned char *result)
{
- int i, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
+ int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
scroll = 0, max_choice;
WINDOW *dialog, *menu;
max_choice = MIN(menu_height, item_no);
+ tag_x = 0;
+ item_x = 0;
+ /* Find length of longest item in order to center menu */
+ for (i = 0; i < item_no; i++) {
+ tag_x = MAX(tag_x, strlen(items[i*2]) + strlen(items[i*2 + 1]) + 2);
+ item_x = MAX(item_x, strlen(items[i*2]));
+ }
+ if (height < 0)
+ height = strheight(prompt)+menu_height+4+2;
+ if (width < 0) {
+ i = strwidth(prompt);
+ j = strwidth(title);
+ width = MAX(i,j);
+ width = MAX(width,tag_x+4)+4;
+ }
+
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
@@ -96,13 +112,6 @@ int dialog_menu(unsigned char *title, unsigned char *prompt, int height, int wid
/* draw a box around the menu items */
draw_box(dialog, box_y, box_x, menu_height+2, menu_width+2, menubox_border_attr, menubox_attr);
- tag_x = 0;
- item_x = 0;
- /* Find length of longest item in order to center menu */
- for (i = 0; i < item_no; i++) {
- tag_x = MAX(tag_x, strlen(items[i*2]) + strlen(items[i*2 + 1]) + 2);
- item_x = MAX(item_x, strlen(items[i*2]));
- }
tag_x = (menu_width - tag_x) / 2;
item_x = tag_x + item_x + 2;
diff --git a/gnu/lib/libdialog/msgbox.c b/gnu/lib/libdialog/msgbox.c
index e405f3b..fda3b40 100644
--- a/gnu/lib/libdialog/msgbox.c
+++ b/gnu/lib/libdialog/msgbox.c
@@ -29,9 +29,17 @@
*/
int dialog_msgbox(unsigned char *title, unsigned char *prompt, int height, int width, int pause)
{
- int i, x, y, key = 0;
+ int i, j, x, y, key = 0;
WINDOW *dialog;
+ if (height < 0)
+ height = strheight(prompt)+2+2*(!!pause);
+ if (width < 0) {
+ i = strwidth(prompt);
+ j = strwidth(title);
+ width = MAX(i,j)+4;
+ }
+
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
diff --git a/gnu/lib/libdialog/prgbox.c b/gnu/lib/libdialog/prgbox.c
index db82589..6726099 100644
--- a/gnu/lib/libdialog/prgbox.c
+++ b/gnu/lib/libdialog/prgbox.c
@@ -27,7 +27,7 @@
* Display a message box. Program will pause and display an "OK" button
* if the parameter 'pause' is non-zero.
*/
-int dialog_prgbox(unsigned char *title, const char *line, int height, int width, int pause, int use_shell)
+int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, int width, int pause, int use_shell)
{
int i, x, y, key = 0;
WINDOW *dialog;
diff --git a/gnu/lib/libdialog/radiolist.c b/gnu/lib/libdialog/radiolist.c
index 5a21518..8b1cf3c 100644
--- a/gnu/lib/libdialog/radiolist.c
+++ b/gnu/lib/libdialog/radiolist.c
@@ -33,9 +33,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_radiolist(char *title, char *prompt, int height, int width, int list_height, int item_no, unsigned char **items, unsigned char *result)
+int dialog_radiolist(unsigned char *title, unsigned char *prompt, int height, int width, int list_height, int item_no, unsigned char **items, unsigned char *result)
{
- int i, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
+ int i, j, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
scroll = 0, max_choice, *status, was_on = 0;
WINDOW *dialog, *list;
@@ -58,6 +58,22 @@ int dialog_radiolist(char *title, char *prompt, int height, int width, int list_
}
max_choice = MIN(list_height, item_no);
+ check_x = 0;
+ item_x = 0;
+ /* Find length of longest item in order to center radiolist */
+ for (i = 0; i < item_no; i++) {
+ check_x = MAX(check_x, strlen(items[i*3]) + strlen(items[i*3 + 1]) + 6);
+ item_x = MAX(item_x, strlen(items[i*3]));
+ }
+ if (height < 0)
+ height = strheight(prompt)+list_height+4+2;
+ if (width < 0) {
+ i = strwidth(prompt);
+ j = strwidth(title);
+ width = MAX(i,j);
+ width = MAX(width,check_x+10)+4;
+ }
+
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
@@ -114,13 +130,6 @@ int dialog_radiolist(char *title, char *prompt, int height, int width, int list_
/* draw a box around the list items */
draw_box(dialog, box_y, box_x, list_height+2, list_width+2, menubox_border_attr, menubox_attr);
- check_x = 0;
- item_x = 0;
- /* Find length of longest item in order to center radiolist */
- for (i = 0; i < item_no; i++) {
- check_x = MAX(check_x, strlen(items[i*3]) + strlen(items[i*3 + 1]) + 6);
- item_x = MAX(item_x, strlen(items[i*3]));
- }
check_x = (list_width - check_x) / 2;
item_x = check_x + item_x + 6;
diff --git a/gnu/lib/libdialog/yesno.c b/gnu/lib/libdialog/yesno.c
index 3f21b5a..1e4f77d 100644
--- a/gnu/lib/libdialog/yesno.c
+++ b/gnu/lib/libdialog/yesno.c
@@ -28,9 +28,17 @@
*/
int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int width)
{
- int i, x, y, key = 0, button = 0;
+ int i, j, x, y, key = 0, button = 0;
WINDOW *dialog;
+ if (height < 0)
+ height = strheight(prompt)+4;
+ if (width < 0) {
+ i = strwidth(prompt);
+ j = strwidth(title);
+ width = MAX(i,j)+4;
+ }
+
/* center dialog box on screen */
x = (COLS - width)/2;
y = (LINES - height)/2;
OpenPOWER on IntegriCloud