October 26th Friday (十月 二十六日 金曜日)

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;
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值