October 26th Friday (十月 二十六日 金曜日)
2007-11-30 20:59
381 查看
The set_field_fore() and set_field_back() is used to set the foreground and background of a field.
The field_fore() and field_back() get the foreground and background of a field. The set_field_pad()
can set a pad(default value is space) into field. The field_pad() can get the pad value from a field.
The set_field_opts(), field_opts_on(), field_opts_off(), and field_opts() is similar to the option
functions of menu.
The status of a form is told if the form data is modified. You can use set_field_status() and
field_status() set or get the status. The set_field_userptr() and field_userptr() are similer to
the panel and the menu.
The set_field_type() is used to set a type vaild checker for a field. The field_type() can get a type
vaild checker from a field.
The TYPE_ENUM field type is special.
int set_field_type(FIELD *field, TYPE_ENUM, char **valuelist, int checkcase, int checkunique);
With TYPE_ENUM, the valuelist must point a series of strings which end up with NULL. The checkcase
parameter is used as the switch of case-sensitive. The checkunique is used as the switch of unique
match value.
#include <form.h>
#define STARTX 15
#define STARTY 4
#define WIDTH 25
#define N_FIELDS 3
int main(){
FIELD *field[N_FIELDS];
FORM *my_form;
int ch, i;
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
init_pair(1, COLOR_WHITE, COLOR_BLUE);
init_pair(2, COLOR_WHITE, COLOR_BLUE);
for(i=0; i<N_FIELDS-1; i++)
field[i] = new_field(1, WIDTH, STARTY + i*2, STARTX, 0, 0);
field[N_FIELDS-1]=NULL;
set_field_fore(field[0], COLOR_PAIR(1));
set_field_back(field[0], COLOR_PAIR(1));
field_opts_off(field[0], O_AUTOSKIP);
set_field_fore(field[1], A_UNDERLINE);
set_field_back(field[1], COLOR_PAIR(1));
field_opts_off(field[0], O_ACTIVE);
field_opts_off(field[1], O_PUBLIC);
field_opts_off(field[1], O_AUTOSKIP);
my_form = new_form(field);
post_form(my_form);
refresh();
set_field_just(field[0], JUSTIFY_CENTER);
set_field_buffer(field[0], 0, "This is a static field");
mvprintw(STARTY, STARTX - 10, "Field 1:");
mvprintw(STARTY + 2, STARTX - 10, "Field 2:");
refresh();
while((ch=getch()) != KEY_F(12)){
switch(ch){
case KEY_DOWN:
form_driver(my_form, REQ_NEXT_FIELD);
form_driver(my_form, REQ_END_LINE);
break;
case KEY_UP:
form_driver(my_form, REQ_PREV_FIELD);
form_driver(my_form, REQ_END_LINE);
break;
default:
form_driver(my_form, ch); //display the normal character.
break;
}
}
unpost_form(my_form);
free_form(my_form);
free_field(field[0]);
free_field(field[1]);
endwin();
return 0;
}
The field_fore() and field_back() get the foreground and background of a field. The set_field_pad()
can set a pad(default value is space) into field. The field_pad() can get the pad value from a field.
The set_field_opts(), field_opts_on(), field_opts_off(), and field_opts() is similar to the option
functions of menu.
The status of a form is told if the form data is modified. You can use set_field_status() and
field_status() set or get the status. The set_field_userptr() and field_userptr() are similer to
the panel and the menu.
The set_field_type() is used to set a type vaild checker for a field. The field_type() can get a type
vaild checker from a field.
The TYPE_ENUM field type is special.
int set_field_type(FIELD *field, TYPE_ENUM, char **valuelist, int checkcase, int checkunique);
With TYPE_ENUM, the valuelist must point a series of strings which end up with NULL. The checkcase
parameter is used as the switch of case-sensitive. The checkunique is used as the switch of unique
match value.
#include <form.h>
#define STARTX 15
#define STARTY 4
#define WIDTH 25
#define N_FIELDS 3
int main(){
FIELD *field[N_FIELDS];
FORM *my_form;
int ch, i;
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
init_pair(1, COLOR_WHITE, COLOR_BLUE);
init_pair(2, COLOR_WHITE, COLOR_BLUE);
for(i=0; i<N_FIELDS-1; i++)
field[i] = new_field(1, WIDTH, STARTY + i*2, STARTX, 0, 0);
field[N_FIELDS-1]=NULL;
set_field_fore(field[0], COLOR_PAIR(1));
set_field_back(field[0], COLOR_PAIR(1));
field_opts_off(field[0], O_AUTOSKIP);
set_field_fore(field[1], A_UNDERLINE);
set_field_back(field[1], COLOR_PAIR(1));
field_opts_off(field[0], O_ACTIVE);
field_opts_off(field[1], O_PUBLIC);
field_opts_off(field[1], O_AUTOSKIP);
my_form = new_form(field);
post_form(my_form);
refresh();
set_field_just(field[0], JUSTIFY_CENTER);
set_field_buffer(field[0], 0, "This is a static field");
mvprintw(STARTY, STARTX - 10, "Field 1:");
mvprintw(STARTY + 2, STARTX - 10, "Field 2:");
refresh();
while((ch=getch()) != KEY_F(12)){
switch(ch){
case KEY_DOWN:
form_driver(my_form, REQ_NEXT_FIELD);
form_driver(my_form, REQ_END_LINE);
break;
case KEY_UP:
form_driver(my_form, REQ_PREV_FIELD);
form_driver(my_form, REQ_END_LINE);
break;
default:
form_driver(my_form, ch); //display the normal character.
break;
}
}
unpost_form(my_form);
free_form(my_form);
free_field(field[0]);
free_field(field[1]);
endwin();
return 0;
}
相关文章推荐
- 2008 October 24th Friday (十月 二十四日 金曜日)
- October 12th Friday (十月 十二日 金曜日
- 2008 September 26th Friday (九月 二十六日 金曜日)
- 2008 October 17th Friday (十月 十七日 金曜日)
- 2008 October 10th Friday (十月 十日 金曜日)
- June 26th Friday (六月 二十六日 金曜日)
- October 19th Friday (十月 十九日 金曜日)
- 2008 October 31th Friday (十月 三十一日 金曜日)
- October 10th Wednesday (十月 十日 水曜日)
- October 23th Tuesday (十月 二十三日 火曜日)
- December 7th Friday (十二月 七日 金曜日)
- 2008 January 18th Friday (一月 十八日 金曜日)
- 2008 March 21th Friday (三月 二十一日 金曜日)
- 2008 May 26th Monday (五月 二十六日 月曜日)
- 2008 August 1st Friday (八月 一日 金曜日)
- 2008 September 12th Friday (九月 十二日 金曜日)
- 2008 October 14th Tuesday (十月 十四日 火曜日)
- 2008 October 27th Monday (十月 二十七日 月曜日)
- 2008 November 26th Wednesday (十一月 二十六日 水曜日)
- April 17th Friday (四月 十七日 金曜日)