diff --git a/lib/libforms/Makefile b/lib/libforms/Makefile index f454766e3971..7ed0abfa1496 100644 --- a/lib/libforms/Makefile +++ b/lib/libforms/Makefile @@ -2,7 +2,7 @@ LIB = forms SRCS = forms.c -CFLAGS += -I. -I${.CURDIR} -Wall +CFLAGS += -I. -I${.CURDIR} -Wall -g beforeinstall: @(cd ${.CURDIR}; cmp -s forms.h ${DESTDIR}/usr/include/forms.h || \ diff --git a/lib/libforms/examples/Makefile b/lib/libforms/examples/Makefile index 3e721fcb19ba..e098b6897c2d 100644 --- a/lib/libforms/examples/Makefile +++ b/lib/libforms/examples/Makefile @@ -3,7 +3,7 @@ NOMAN = yet SRCS = example.c frm.tab.h -CFLAGS = +CFLAGS = -g -static .if exists(${.CURDIR}/../obj) FORMDIR=${.CURDIR}/../obj diff --git a/lib/libforms/examples/example.c b/lib/libforms/examples/example.c index 120dc204c3df..120fdb14efd5 100644 --- a/lib/libforms/examples/example.c +++ b/lib/libforms/examples/example.c @@ -49,6 +49,7 @@ main() } keypad(example.window, TRUE); + print_status("This is the status line"); while (!(res = update_form(&example))); wclear(example.window); diff --git a/lib/libforms/examples/example.frm b/lib/libforms/examples/example.frm index 942bbbf3b8d8..e2ebd8004a44 100644 --- a/lib/libforms/examples/example.frm +++ b/lib/libforms/examples/example.frm @@ -1,103 +1,55 @@ -Colors example { +Colours example { pair = red, yellow pair = blue, white } -Field Title { - attributes = COLOR_PAIR(2) - text = "A Simple Demo" -} +field1 { attributes = A_BLINK|A_BOLD text = "This text is bold and flashy" } -Field field1 { - attributes = A_BLINK|A_BOLD - text = "This text is bold and flashy" -} - -Field field2 { +field2 { + height = 2 + width = 22 text = "This is an input field with a default" } -Field field3 { +field3 { width = 10 default = "This is a default entry" limit = 30 } -Field field4 { - text = "This is a labelled input field" -} +field4 { text = "This is a labelled input field" } -Field field5 { - label = "A temp. label" -} +field5 { label = "A temp. label" } -Field field6 { - text = "Some options to choose from: " -} +field6 { text = "Some options to choose from: " } -Field field7 { - selected = 0 - options = "Choose", "another", "of", "these" -} +field7 { selected = 0 options = "Choose", "another", "of", "these" } -Field field8 { - width = 6 - action = "EXIT" - function = exit_form -} +field8 { width = 6 action = "EXIT" function = exit_form } -Field field9 { +field9 { attributes = COLOR_PAIR(1) highlight = COLOR_PAIR(1)|A_BOLD action = "CANCEL" function = cancel_form } -Link input1 as field3 { - next = input2 - down = input2 -} - -Link input2 as field5 { - next = menu1 - up = input1 - down = menu1 -} - -Link menu1 as field7 { - next = quit - up = input2 - down = quit -} - -Link quit as field8 { - up = menu1 - right = cancel -} - -Link cancel as field9 { - up = input1 - down = input1 - left = quit - right = input1 -} - Form example at 0,0 { - height = 24 + height = 25 width = 80 colortable = example attributes = COLOR_PAIR(1) - Field Title at 0,30 + Title {attributes = COLOR_PAIR(2) text = "A Simple Demo"} at 0,30 - Field field1 at 3,23 - Field field2 at 7, 2 - Field field4 at 11, 2 - Field field6 at 15, 2 + field1 at 3,23 + field2 at 7, 2 + field4 at 11, 2 + field6 at 15, 2 - Field input1 at 7,45 - Field input2 at 11,45 - Field menu1 at 15,45 - Field quit at 20,20 - Field cancel at 20,43 + input1 {field3} at 7,45, next=input2, up=input2, down=input2 + input2 {field5} at 11,45, next=menu1, up=input1, down=menu1 + menu1 {field7} at 15,45, next=quit, up=input2, down=quit + quit {field8} at 20,20, up=menu1, right=cancel + cancel {field9} at 20,43, up=input1, down=input1, left=quit, right=input1 } diff --git a/lib/libforms/forms.c b/lib/libforms/forms.c index ab7b17275148..6787d8ecb1da 100644 --- a/lib/libforms/forms.c +++ b/lib/libforms/forms.c @@ -74,6 +74,11 @@ initfrm(struct form *form) cbreak(); noecho(); + if (!form->height) + form->height = LINES; + if (!form->width) + form->width = COLS; + form->window = newwin(form->height, form->width, form->y, form->x); if (!form->window) { print_status("Couldn't open window, closing form"); @@ -137,8 +142,6 @@ endfrm(struct form *form) int update_form(struct form *form) { - int selattr; - show_form(form); if (form->current_field == -1) @@ -207,7 +210,7 @@ disp_text(struct form *form, int index) struct field *field = &form->field[index]; - if (print_string(form->window, field->y, field->x, + if (print_string(form->window, field->y, field->x, field->height, field->width, field->field.text->text) == ERR) print_status("Illegal scroll in print_string"); } @@ -219,11 +222,11 @@ disp_input(struct form *form, int index) struct field *field = &form->field[index]; if (field->field.input->lbl_flag) { - if (print_string(form->window, field->y, field->x, + if (print_string(form->window, field->y, field->x, field->height, field->width, field->field.input->label) == ERR) print_status("Illegal scroll in print_string"); } else - if (print_string(form->window, field->y, field->x, + if (print_string(form->window, field->y, field->x, field->height, field->width, field->field.input->input) == ERR) print_status("Illegal scroll in print_string"); } @@ -233,7 +236,7 @@ disp_menu(struct form *form, int index) { struct field *field = &form->field[index]; - if (print_string(form->window, field->y, field->x, + if (print_string(form->window, field->y, field->x, field->height, field->width, field->field.menu->options[field->field.menu->selected]) == ERR) print_status("Illegal scroll in print_string"); @@ -244,7 +247,7 @@ disp_action(struct form *form, int index) { struct field *field = &form->field[index]; - if (print_string(form->window, field->y, field->x, + if (print_string(form->window, field->y, field->x, field->height, field->width, field->field.action->text) == ERR) print_status("Illegal scroll in print_string"); @@ -342,9 +345,10 @@ next_field(struct form *form, int ch) static int print_string(WINDOW *window, int y, int x, - int width, char *string) + int height, int fwidth, char *string) { int len; + int width; if (!string) len = -1; @@ -353,18 +357,24 @@ print_string(WINDOW *window, int y, int x, if (wmove(window, y, x) == ERR) return (ERR); - while (width--) { - if (len-- > 0) { - if (waddch(window, *string++) == ERR) - return (ERR); - } else - if (waddch(window, ' ') == ERR) - return (ERR); + while (height--) { + width = fwidth; + while (width--) { + if (len-- > 0) { + if (waddch(window, *string++) == ERR) + return (ERR); + } else + if (waddch(window, ' ') == ERR) + return (ERR); + } + if (wmove(window, ++y, x) == ERR) + return (ERR); + } return (OK); } -static void +void print_status(char *msg) { if (wmove(stdscr, LINES-1, 0) == ERR) { @@ -410,7 +420,7 @@ field_input(struct form *form) ch = wgetch(form->window); if (next_field(form, ch)) { print_string(form->window, field->y, field->x, - field->width, + field->height, field->width, field->field.input->input+DISPOFF); return; } @@ -456,7 +466,7 @@ field_input(struct form *form) beep(); else { ++abspos; - if (cursor++ == field->width) { + if (++cursor == field->width) { ++disp_off; --cursor; } @@ -473,7 +483,7 @@ field_input(struct form *form) } else { beep(); } - print_string(form->window, field->y, field->x, + print_string(form->window, field->y, field->x, field->height, field->width, field->field.input->input+disp_off); } /* Not Reached */ diff --git a/lib/libforms/forms.h b/lib/libforms/forms.h index 094ca7a2027d..36031be3d8b2 100644 --- a/lib/libforms/forms.h +++ b/lib/libforms/forms.h @@ -94,6 +94,7 @@ struct field { int type; int y; int x; + int height; int width; int attr; int selattr; @@ -122,3 +123,4 @@ int initfrm(struct form *); void endfrm(struct form *); void exit_form(void); void cancel_form(void); +void print_status(char *); diff --git a/lib/libforms/internal.h b/lib/libforms/internal.h index b7bdb1e04ebd..6895de2f769e 100644 --- a/lib/libforms/internal.h +++ b/lib/libforms/internal.h @@ -34,6 +34,5 @@ static void disp_input(struct form *, int); static void field_menu(struct form *); static void field_input(struct form *); static void field_action(struct form *); -static int print_string(WINDOW *, int, int, int, char *); -static void print_status(char *); +static int print_string(WINDOW *, int, int, int, int, char *); static int next_field(struct form *form, int);