Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1418855
  • 博文数量: 430
  • 博客积分: 9995
  • 博客等级: 中将
  • 技术积分: 4388
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-24 18:04
文章存档

2013年(1)

2008年(2)

2007年(14)

2006年(413)

分类: LINUX

2006-05-25 21:09:34

 

                        NEWT---蝾螈

                        ------------Linux下基于文本方式的窗口开发工具库

Newt windowing library version- (C) 1996-2000 Red Hat Software.

Redistributable under the term of the Library

GNU Public License.

Written by Erik Troan

开发者:RedHat

文件在RedHat Linux8.0 第一张安装光盘中文件名是:

                newt-0.51.0-1.i386.rpm     -

                newt-devel-0.51.0-1.i386.rpm

NEWT特点:

  1. NEWT由C语言写成,而不是C++
  2. NEWT所有窗口的生成都是基于堆栈的数据结构,窗口的外观都是统一的模板,不由程序员修改
  3. 输入设备只支持终端键盘

NEWT 提供C语言的应用程序接口(API),它不直接进行低级屏幕操作,是在S-Lang 库上实现的。

NEWT名词说明:

 

组件(Components)
在NEWT中,每一个可显示的项目称为组件。组件主要有两类:Form组件与非Form组件。非Form组件是除Form以外的所有组件。Form逻辑地组织各个组件成为一个功能集。Form是一个容器组件,让其他组件都装在其上。当一个应用准备从用户中获得输入,就要执行newtRunForm(form)语名,这条语名的意思是显示form及在form上的所有组件。Form组件可以包含其他任何组件,也包含其他的Form作为子Form。

 

每一个组件都是由一个属于newtComponent数据类型的变量唯一标志,这一变量必须由生成该组件的函数建立,而不能由程序员自己建立。属于newtComponent数据类型的变量其实只是一个指针。

例:

 定义组件变量-------表单---标签---输入框----按钮

  newtComponent  form,   label,  entry,   button;

 实例化时用相应的语名:

   form=newtForm(NULL, NULL, 0);

   label=newtLabel(2, 1, "请输入住址:");

   entry=newtEntry(18,1,20,”唐山”,NULL,NEWT_FLAG_SCROLL);

   button=newtButton(10, 5, "确认");

 

NEWT程序的开始时要执行

   int newtInit(void); 
函数,这条函数的功能是初使化newt
接下来要做的工作是清除屏幕信息为我们初使化一个干净的屏幕
newtCls();
 
有了开始就不能不先说说结束,语句如下:
newtFinished();
作用是恢复终端在调用newtInit()前的状态,重置原来的输入状态。若没调用这函数,终端需重启才能回到命令行状态。
下面大家看一个例子 
 说明:这个例子是在屏幕上开一个窗口,在窗口上建一个表单(Form),在表单(Form)上填加一个标签(label),一个输入文本框(entry),和两个按钮(button)
例子源程序如下:(entry.c)
#include 
#include 
#include 
#include 
int main(int argc, char *argv[]) 
   {
newtComponent form, label, entry, button_ok, button_cancel; //定义组件
newtComponent co;
char *entryvalue;
newtInit(); //初始化
newtCls();  //清屏幕
newtCenteredWindow(50, 10, "Entry 实例"); //建立窗口
label  = newtLabel(6, 1, "请输入住址:"); //建立标签
entry  = newtEntry(20, 1, "唐山市", 28,
NULL, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); //建立输入框
button_ok = newtButton(8, 6, "确认");//----建立”确定”按钮
button_cancel = newtButton(30, 6, "取消"); //--建立 “取消”按钮
form = newtForm(NULL, NULL, 0); //建立Form
//下面把 label,entry,button_ok,button_cancel 组件加入到Form中
newtFormAddComponents(form, label, entry, 
                      button_ok, button_cancel, NULL); 
co = newtRunForm(form);   //显示form和相关组件并进入循环
//获得输入条的值
if(co == entry || co == button_ok)
entryvalue = strdup(newtEntryGetValue(entry));
else
         entryvalue = strdup("Input cancelled.");
 
newtFormDestroy(form); //关闭Form
newtFinished();//复原
printf("%s\n", entryvalue); //打印结果
free(entryvalue);
}
 
编译方法
# gcc –o  entry entry.c –lnewt
#./entry 
 
 
 
运行结果如下图:

 
    
  
  
  
  
  
 
 
 

 
 
大家看到上面的图形可能认为这样的颜色搭配不好看,想变成自已喜欢的颜色
下面给大家介绍一下颜色的设置
首先大家先看一下NEWT自已默认的调色版:
其中一些英文的意思是
 fg------foreground----前景色 , bg-----background---背景色
const struct newtColors newtDefaultColorPalette = {
         "white", "blue",          /* root fg, bg  根窗口的前景色, 背景色*/
         "black", "lightgray",     /* border fg, bg 边框的前景色, 背景色*/
         "black", "lightgray",     /* window fg, bg  窗口的前景色, 背景色*/
         "white", "black",         /* shadow fg, bg 阴影的前景色, 背景色*/
         "red", "lightgray",       /* title fg, bg  材标题的前景色, 背景色*/
         "lightgray", "red",       /* button fg, bg 按钮的前景色, 背景色*/
         "red", "lightgray",    /* active button fg,bg 活动按钮的前景色,背景色*/
         "yellow", "blue",         /* checkbox fg, bg 复选按钮的前景色,背景色*/
         "blue", "brown",           /*活动复选按钮的前景色,背景色*/
         "yellow", "blue",         /* entry box fg, bg 输入文本框*/
         "blue", "lightgray",      /* label fg, bg 标签*/
         "black", "lightgray",     /* listbox fg, bg 列表框*/
         "yellow", "blue",         /* active listbox fg, bg 活动列表框*/
         "black", "lightgray",     /* textbox fg, bg   文本框 */
         "lightgray", "black",     /* active textbox fg, bg 活动文本框*/
         "white", "blue",          /* help line 提示行*/
         "yellow", "blue",         /* root text 根窗口文本*/
         "blue",                   /* scale full 进度条--100%时的颜色*/
         "red",                    /* scale empty 进度条--%0时的颜色*/
         "blue", "lightgray",      /* disabled entry fg, bg 输入文本不能输入时的颜色*/
         "white", "blue",          /* compact button fg, bg 紧凑按钮*/
         "yellow", "red",        /* active & sel listbox 活动并且选中的列表框*/
         "black", "brown"          /* selected listbox 以经选中的列表框 */
};
大家看清上面的调色版结构了吗?在自已的程序可以这样定义:
struct newtColors whtcolor = {
         "blue", "green",                   /* root fg, bg */
         "black", "brown",                  /* border fg, bg */
         ……..
         …….
         …..
};
这时自已定义的调色版结构 whtcolor
那怎样使有我们定义的调色版呢
newtSetColors(whtcolor); //设置使用我们自已的调色版
颜色大概只有16种如下:
black -------黑色
blue --------蓝色
green -------绿色
cyan   ------蓝绿色,青色
red     ------红色
magenta ----红紫色,洋红
brown ----褐色,棕色
lightgray ---灰白色
darkgray-----灰色
lightblue ----浅蓝色
lightgreen ----浅绿色
lightcyan-----浅青色
lightred-----浅红色
lightmagenta----浅洋红色
yellow-----黄色
white -----白色
 
 
在介绍组件咱们先说一个newt组件结构:
 
struct newtComponent_struct {
    /* common data  组件数据*/
    int height, width; //高,宽大
    int top, left; //这个是在上角坐标
    int takesFocus; //焦点
    int isMapped; //映射
 
    struct componentOps * ops; //组件选项结构变量
 
    newtCallback callback;//组件回调函数
    void * callbackData; //回调函数数据
 
    void * data;//组件数据
} ;
typedef struct newtComponent_struct * newtComponent;//定义组件结构变量
 
(一)----------根窗体
终端所显示的背景,只有不被任何窗口遮盖的部分称为根窗口。一般地,应用不需使用到根窗口,而把文字写到属于自己的窗口上。所有组件都不应放在根窗口上。根窗口只用于显示一些辅助信息,例如程序的作者姓名、版本等。NEWT提供两种在根窗口显示文字的方式,它们是唯一能越出组件自己当前窗口写文字的NEWT函数。
void newtDrawRootText(int left, int top, const char *text);
该函数用于在根窗口指定位置写出text字苻串,left和top为字苻串text的开始处,left是屏幕x坐标,top是屏幕y坐标.
 
(二)---------下面讲------------窗口的建立
建立窗口的函数有两个如下:
int newtOpenWindow(int left, int top, int width, int height,const char * title);
         //开一个窗口
函数参数说明:
         left和top 是窗口左上角坐标,
         width是窗口宽度大小,
         height是窗口高度
         title 是窗口的标题
 
int newtCenteredWindow(int width, int height, const char * title);
         //在屏幕中心开个窗口
函数参数说明:
         width是窗口宽度大小,
         height是窗口高度
         title 是窗口的标题
(三)---------下面讲------------窗口的删除
void newtPopWindow(void);
//这函数删除屏幕最顶层的窗口,并重画被该窗口遮盖的部分。
 
(四)---------下面讲-----------容器Form
newtComponent newtForm(newtComponent vertBar, void * helpTag, int flags); 
//===建立容器Form
----参数说明:
         vertBar是垂直滚动条,
         help是提示信息,通常这两个参数都不会用到,用NULL即可,
         flags标志。该函数返回标志所生成的Form的变量。
 
void newtFormSetTimer(newtComponent form, int millisecs);
//-------设置容器定时器
----参数说明:
form  建立容器的变量
millisecs  毫秒
 
 
void newtFormWatchFd(newtComponent form, int fd, int fdFlags);
 
void newtFormSetSize(newtComponent co);
//设置容器大小
  ----参数说明:
                co 是一个组件变量
newtComponent newtFormGetCurrent(newtComponent co);
//--------------得到窗体
----参数说明:
                co 是一个组件变量
 
void newtFormSetBackground(newtComponent co, int color);
//-----------设置容器背景色
----参数说明:
                co 是一个组件变量
               color 是颜色标号
void newtFormSetCurrent(newtComponent co, newtComponent subco);
 
void newtFormAddComponent(newtComponent form, newtComponent co);
//---向容器中填加组件
 ---参数说明:
form 容器变量
co   组件变量
 
 
 
void newtFormAddComponents(newtComponent form, ...);
//---------向容器中填加更多组件
-----参数说明:
form 为容器变量
……… 更多组件列表
void newtFormSetHeight(newtComponent co, int height);//-------设置容器高
------参数说明:
               co 组件变量
               height 高
void newtFormSetWidth(newtComponent co, int width); //--------设置容器宽
------参数说明:
               co 组件变量
               width 宽
 
newtComponent newtRunForm(newtComponent form); /* obsolete旧的不用了 */
 
void newtFormRun(newtComponent co, struct newtExitStruct * es);
//-------------运行显示容器(这是现在使用的)
------参数说明:
                 co 组件变量
                 *es 退出结构变量
struct newtExitStruct 结构说明
struct newtExitStruct {
     //下面   热键             组件                                定时器
enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY,NEWT_EXIT_TIMER } reason;
  union {
    int watch;//监视
    int key; //键
    newtComponent co;//组件
} u;
} ;
//==========================
void newtDrawForm(newtComponent form);//-------------绘制容器
void newtFormAddHotKey(newtComponent co, int key);//---------向容器填加热键
 
//-------销毁所有在form中的组件和form
void newtFormDestroy(newtComponent form);
 
(五)---------------下面讲--------一些指令
void newtBell(void);//发声
void newtCursorOff(void);//关闭光标显示
void newtCursorOn(void);//显示光标
void newtGetScreenSize(int * cols, int * rows);
 
 
 
(六)-------下面讲-----组件------------按钮
newtComponent newtCompactButton(int left, int top, const char * text);//紧凑按钮
参数说明:
        left ,top 左上角坐标
        text  按钮上显示的字符串
newtComponent newtButton(int left, int top, const char * text);       //按钮
  参数说明:
        left ,top 左上角坐标
        text  按钮上显示的字符串
(七)-------------下面讲-----组件------------检查框
newtComponent newtCheckbox(int left, int top, const char * text, char defValue, 
                             const char * seq, char * result); 
功能:建立一个检查框
参数说明:
               left, top 左上角坐标
               text      检查框上显示的字符
               defValue  检查框选择位置默认显示的字符
               seq       检查框选择位置选中时显示的字符
               result    结果
char newtCheckboxGetValue(newtComponent co);//得到变量字符值
功能:得到检查框返回值
参数说明:
               co 为组件变量
void newtCheckboxSetValue(newtComponent co, char value);//设置变量值
 
void newtCheckboxSetFlags(newtComponent co, int flags, enum newtFlagsSense sense);//设置标志
{标记
enum newtFlagsSense { NEWT_FLAGS_SET, NEWT_FLAGS_RESET, NEWT_FLAGS_TOGGLE };
}
 
(八)--------- ------------下面讲-----组件------------单选按钮
newtComponent newtRadiobutton(int left, int top, const char * text, int isDefault, 
                                newtComponent prevButton); //创建单选按钮
参数说明:
         left,top 组件左上角坐标
         text     组件上显示的字符串
         isDefault 
         prevButton 前一个组件
:
     newtComponent rb[3];
       rb[0] = newtRadiobutton(10, 3, "Choice 1", 1, NULL);
        rb[1] = newtRadiobutton(10, 4, "Choice 2", 0, rb[0]);
        rb[2] = newtRadiobutton(10, 5, "Choice 3", 0, rb[1]);
newtComponent newtRadioGetCurrent(newtComponent setMember);
//得到所选物件的指针-选中的RadioButton组件的标记
 
(九)-----------下面讲­-----组件--------列表项
newtComponent newtListitem(int left, int top, const char * text, int isDefault,  
         newtComponent prevItem, const void * data, int flags); //-新建列表项
 
void newtListitemSet(newtComponent co, const char * text);
void * newtListitemGetData(newtComponent co);
(十)-- -----------下面讲­-----组件--------列表框
newtComponent newtListbox(int left, int top, int height, int flags);//建立列表
void * newtListboxGetCurrent(newtComponent co);
//--得到期ListBox返回的选择标记号(指针型)
void newtListboxSetCurrent(newtComponent co, int num);
void newtListboxSetCurrentByKey(newtComponent co, void * key);
void newtListboxSetEntry(newtComponent co, int num, const char * text);
void newtListboxSetWidth(newtComponent co, int width);//设置列表框宽度
void newtListboxSetData(newtComponent co, int num, void * data);
int newtListboxAppendEntry(newtComponent co, const char * text,const void * data);//向列表框加入数据
int newtListboxInsertEntry(newtComponent co, const char * text, const void * data, void * key);//插入项
int newtListboxDeleteEntry(newtComponent co, void * data); //删除项
void newtListboxClear(newtComponent co); 
/* removes all entries from listbox *//从列表框中移除所有项
void newtListboxGetEntry(newtComponent co, int num, char **text, void **data);
//得到列表框选择的项
/* Returns an array of data pointers from items, last element is NULL */
void **newtListboxGetSelection(newtComponent co, int *numitems);
void newtListboxClearSelection(newtComponent co);//清除所有选中的项
void newtListboxSelectItem(newtComponent co, const void * key,enum newtFlagsSense sense);//选择项
/* Returns number of items currently in listbox. */
int newtListboxItemCount(newtComponent co);//返回表列框中一共有多少项
(十一) -----------下面讲­-----组件--------标签
newtComponent newtLabel(int left, int top, const char * text);
void newtLabelSetText(newtComponent co, const char * text);
 
(十二) -----------下面讲­-----组件--------滚动条
newtComponent newtVerticalScrollbar(int left, int top, int height,       
                 int normalColorset, int thumbColorset); //----滚动条-垂直
void newtScrollbarSet(newtComponent co, int where, int total);
 
 
(十三)-------------下面讲------组件----检查框树
newtComponent newtCheckboxTree(int left, int top, int height, int flags);
newtComponent newtCheckboxTreeMulti(int left, int top, int height, char *seq, int flags);
const void ** newtCheckboxTreeGetSelection(newtComponent co, int *numitems);
const void * newtCheckboxTreeGetCurrent(newtComponent co);//-----------------得到检查列表的返回值
void newtCheckboxTreeSetCurrent(newtComponent co, void * item);
const void ** newtCheckboxTreeGetMultiSelection(newtComponent co, int *numitems, char seqnum);
/* last item is NEWT_ARG_LAST for all of these */
int newtCheckboxTreeAddItem(newtComponent co, 
                              const char * text, const void * data,
                              int flags, int index, ...);
int newtCheckboxTreeAddArray(newtComponent co, 
                               const char * text, const void * data,
                               int flags, int * indexes);
int * newtCheckboxTreeFindItem(newtComponent co, void * data);
void newtCheckboxTreeSetEntry(newtComponent co, const void * data,
                                const char * text);
void newtCheckboxTreeSetWidth(newtComponent co, int width);
char newtCheckboxTreeGetEntryValue(newtComponent co, const void * data);
void newtCheckboxTreeSetEntryValue(newtComponent co, const void * data,
                                      char value);
(十四)--------下面讲--------组件----文本框
newtComponent newtTextboxReflowed(int left, int top, char * text, int width,  //在指定位置显示text内容并建立一个BOX
                                     int flexDown, int flexUp, int flags);
newtComponent newtTextbox(int left, int top, int width, int height, int flags);//文本BOX
void newtTextboxSetText(newtComponent co, const char * text);
void newtTextboxSetHeight(newtComponent co, int height);
int newtTextboxGetNumLines(newtComponent co);
char * newtReflowText(char * text, int width, int flexDown, int flexUp,
                       int * actualWidth, int * actualHeight);
 
 
 
 
 
 
 
 
 
(十五)--------- -下面讲---退出数据结构
struct newtExitStruct {
    enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY,NEWT_EXIT_TIMER } reason;
         union {
         int watch;//监视
         int key; //键
         newtComponent co;//组件
         } u;
} ;
 
(十六)---------下面讲-------组件-----------文本输入框
newtComponent newtEntry(int left, int top, const char * initialValue, int width,
                          char ** resultPtr, int flags);                                        //==文本输入框
void newtEntrySet(newtComponent co, const char * value, int cursorAtEnd);
void newtEntrySetFilter(newtComponent co, newtEntryFilter filter, void * data);
char * newtEntryGetValue(newtComponent co);//得到物件返回的值
void newtEntrySetFlags(newtComponent co, int flags, enum newtFlagsSense sense);
//没置标记
 
(十七)--------下面讲--------组件-----------进度条
newtComponent newtScale(int left, int top, int width, long long fullValue);
//新建进度条组件
void newtScaleSet(newtComponent co, unsigned long long amount);
//设置进度条当前进度      
(十八)-------下面讲---------回调函数
void newtComponentAddCallback(newtComponent co, newtCallback f, void * data);
// 添加回调函数
void newtComponentTakesFocus(newtComponent co, int val);//获得焦点    
 
 
 
 
 
 
 
 
 
 
 
 
 
(十九)----------下面讲-----------------常用标记列表
#define NEWT_FLAG_RETURNEXIT       (1 << 0)//在组件上按回车键时退出--可在Entry输入框中使用
#define NEWT_FLAG_HIDDEN  (1 << 1)//隐藏输入-可在Entry输入框中使用
#define NEWT_FLAG_SCROLL  (1 << 2)//允许滚动输入-可在Entry输入框中使用
#define NEWT_FLAG_DISABLED         (1 << 3) //不允许输入-可在Entry输入框中使用
/* OBSOLETE #define NEWT_FLAG_NOSCROLL      (1 << 4) for listboxes */
#define NEWT_FLAG_BORDER  (1 << 5)//边框-可在Entry输入框中使用
#define NEWT_FLAG_WRAP             (1 << 6) //---1
#define NEWT_FLAG_NOF12            (1 << 7) //---2
#define NEWT_FLAG_MULTIPLE      (1 << 8) //---3
#define NEWT_FLAG_SELECTED         (1 << 9) //---4
#define NEWT_FLAG_CHECKBOX         (1 << 10) //---6
#define NEWT_FLAG_PASSWORD      (1 << 11)  /* 输入密码时的处理 在输入框画*号字符*/ //-可在Entry输入框中使用
#define NEWT_FLAG_SHOWCURSOR    (1 << 12) /* Only applies to listbox for now */
#define NEWT_FD_READ               (1 << 0)
#define NEWT_FD_WRITE              (1 << 1)
#define NEWT_FD_EXCEPT             (1 << 2)
//=============================================================
#define NEWT_CHECKBOXTREE_UNSELECTABLE      (1 << 12)
#define NEWT_CHECKBOXTREE_HIDE_BOX (1 << 13)
 
#define NEWT_CHECKBOXTREE_COLLAPSED         '\0'
#define NEWT_CHECKBOXTREE_EXPANDED '\1'
#define NEWT_CHECKBOXTREE_UNSELECTED        ' '
#define NEWT_CHECKBOXTREE_SELECTED '*'
 
/* Backwards compatibility 向后兼容*/
#define NEWT_LISTBOX_RETURNEXIT NEWT_FLAG_RETURNEXIT
#define NEWT_ENTRY_SCROLL NEWT_FLAG_SCROLL
#define NEWT_ENTRY_HIDDEN NEWT_FLAG_HIDDEN
#define NEWT_ENTRY_RETURNEXIT      NEWT_FLAG_RETURNEXIT
#define NEWT_ENTRY_DISABLED        NEWT_FLAG_DISABLED
 
#define NEWT_TEXTBOX_WRAP NEWT_FLAG_WRAP
#define NEWT_TEXTBOX_SCROLL        NEWT_FLAG_SCROLL
#define NEWT_FORM_NOF12            NEWT_FLAG_NOF12
 
 
 
 
 
(二十)--------------------- 键盘代码
#define NEWT_KEY_TAB                        '\t'     //TAB键
#define NEWT_KEY_ENTER                      '\r' //回车键Enter
#define NEWT_KEY_SUSPEND           '\032'                    /* ctrl - z*/
#define NEWT_KEY_ESCAPE                     ''                       //Esc键
#define NEWT_KEY_RETURN                     NEWT_KEY_ENTER  //回车键
 
#define NEWT_KEY_EXTRA_BASE                 0x8000   //这个0x8000的十进制数是 32768 键盘扫描码基址
#define NEWT_KEY_UP                         NEWT_KEY_EXTRA_BASE + 1      //上===================这是控制区键盘
#define NEWT_KEY_DOWN                       NEWT_KEY_EXTRA_BASE + 2    //下
#define NEWT_KEY_LEFT                       NEWT_KEY_EXTRA_BASE + 4    //左
#define NEWT_KEY_RIGHT                      NEWT_KEY_EXTRA_BASE + 5  //右
#define NEWT_KEY_BKSPC                      NEWT_KEY_EXTRA_BASE + 6  //BackSpace 键
#define NEWT_KEY_DELETE                     NEWT_KEY_EXTRA_BASE + 7  //Delete键
#define NEWT_KEY_HOME                       NEWT_KEY_EXTRA_BASE + 8    //Home 键
#define NEWT_KEY_END                        NEWT_KEY_EXTRA_BASE + 9    //End 键
#define NEWT_KEY_UNTAB                      NEWT_KEY_EXTRA_BASE + 10 //
#define NEWT_KEY_PGUP                       NEWT_KEY_EXTRA_BASE + 11   //Page Up 键
#define NEWT_KEY_PGDN                       NEWT_KEY_EXTRA_BASE + 12   //Page Down 键
#define NEWT_KEY_INSERT                     NEWT_KEY_EXTRA_BASE + 13 // Insert 键
 
#define NEWT_KEY_F1                         NEWT_KEY_EXTRA_BASE + 101  //F1 键===================这是功能键区
#define NEWT_KEY_F2                        NEWT_KEY_EXTRA_BASE + 102  //F2
#define NEWT_KEY_F3                         NEWT_KEY_EXTRA_BASE + 103  //F3
#define NEWT_KEY_F4                         NEWT_KEY_EXTRA_BASE + 104  //F4
#define NEWT_KEY_F5                         NEWT_KEY_EXTRA_BASE + 105  //F5
#define NEWT_KEY_F6                         NEWT_KEY_EXTRA_BASE + 106  //F6
#define NEWT_KEY_F7                         NEWT_KEY_EXTRA_BASE + 107  //F7
#define NEWT_KEY_F8                         NEWT_KEY_EXTRA_BASE + 108  //F8
#define NEWT_KEY_F9                         NEWT_KEY_EXTRA_BASE + 109  //F9
#define NEWT_KEY_F10                        NEWT_KEY_EXTRA_BASE + 110 //F10
#define NEWT_KEY_F11                        NEWT_KEY_EXTRA_BASE + 111 //F11
#define NEWT_KEY_F12                        NEWT_KEY_EXTRA_BASE + 112 //F12
//==============================================================================================
/* not really a key, but newtGetKey returns it */
#define NEWT_KEY_RESIZE                     NEWT_KEY_EXTRA_BASE + 113
 
#define NEWT_ANCHOR_LEFT           (1 << 0)   //左
#define NEWT_ANCHOR_RIGHT          (1 << 1)   //右
#define NEWT_ANCHOR_TOP                     (1 << 2)   //上
#define NEWT_ANCHOR_BOTTOM                  (1 << 3) // 下
 
#define NEWT_GRID_FLAG_GROWX                (1 << 0) //栅格标记
#define NEWT_GRID_FLAG_GROWY                (1 << 1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
(二十二)---------------------------其它
newtGrid newtCreateGrid(int cols, int rows);//--------------------------建立网格
/* TYPE, what, TYPE, what, ..., NULL */
newtGrid newtGridVStacked(enum newtGridElement type, void * what, ...);
newtGrid newtGridVCloseStacked(enum newtGridElement type, void * what, ...);
newtGrid newtGridHStacked(enum newtGridElement type1, void * what1, ...);
newtGrid newtGridHCloseStacked(enum newtGridElement type1, void * what1, ...);
newtGrid newtGridBasicWindow(newtComponent text, newtGrid middle,
                               newtGrid buttons);
newtGrid newtGridSimpleWindow(newtComponent text, newtComponent middle,
                               newtGrid buttons);
void newtGridSetField(newtGrid grid, int col, int row, 
                       enum newtGridElement type, void * val, int padLeft,
                       int padTop, int padRight, int padBottom, int anchor,
                       int flags);
void newtGridPlace(newtGrid grid, int left, int top);
#define newtGridDestroy newtGridFree
void newtGridFree(newtGrid grid, int recurse);
void newtGridGetSize(newtGrid grid, int * width, int * height);
void newtGridWrappedWindow(newtGrid grid, char * title);
void newtGridWrappedWindowAt(newtGrid grid, char * title, int left, int top);
void newtGridAddComponentsToForm(newtGrid grid, newtComponent form, 
                                    int recurse);
 
/* convienve */
newtGrid newtButtonBarv(char * button1, newtComponent * b1comp, va_list args);//=====按钮条
newtGrid newtButtonBar(char * button1, newtComponent * b1comp, ...);
 
/* automatically centered and shrink wrapped */
void newtWinMessage(char * title, char * buttonText, char * text, ...);//=========显示信息框
void newtWinMessagev(char * title, char * buttonText, char * text, 
                      va_list argv);
 
/* having separate calls for these two seems silly, but having two separate
   variable length-arg lists seems like a bad idea as well */
 
/* Returns 0 if F12 was pressed, 1 for button1, 2 for button2 */
int newtWinChoice(char * title, char * button1, char * button2, 
                    char * text, ...);
/* Returns 0 if F12 was pressed, 1 for button1, 2 for button2, 
   3 for button3 */
int newtWinTernary(char * title, char * button1, char * button2, 
                    char * button3, char * message, ...);
 
/* Returns the button number pressed, 0 on F12 */                                      
//=========对话框
int newtWinMenu(char * title, char * text, int suggestedWidth, int flexDown, 
                 int flexUp, int maxListHeight, char ** items, int * listItem,
                 char * button1, ...);
//=======================================================================
struct newtWinEntry {
    char * text;
    char ** value;                 /* may be initialized to set default */
    int flags;
};
 
/* Returns the button number pressed, 0 on F12. The final values are
   dynamically allocated, and need to be freed. */
int newtWinEntries(char * title, char * text, int suggestedWidth, int flexDown, 
                    int flexUp, int dataWidth, 
                    struct newtWinEntry * items, char * button1, ...);
 
 
 
 
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
                                                                          
                            实例                                          
                                                                          
                                                                          
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
第一个实例button.c(按钮)
         /* File: buttons.c */
 
         #include 
         #include 
         #include 
         #include 
 
         int main(int argc, char *argv[]) 
         {
                 int i;
                 //定义组件
                 newtComponent form;
                 newtComponent label_checkbox, label_radiobutton;
                 newtComponent checkbox[3], radiobutton[3];
                 newtComponent button_ok;
                 newtComponent co;
                 char result_checkbox[3];
                 int  result_radiobutton;
 
                 char *str_checkbox[3] = {
                          "计算机",
                          "鼠标",
                          "键盘"
                 };
                 char *str_radiobutton[3] = {
                          "Linux",
                          "Windows",
                          "Macintosh"
                 };
 
 
                 //初始化
                 newtInit();
                 newtCls();
 
                 //建立窗口
                 newtCenteredWindow(78,5, "Buttons Sample");
 
                 //-------------------------------------------
                 //建立Form
                 form = newtForm(NULL, NULL, 0);
 
                 //多选按钮
                 label_checkbox = newtLabel(4, 1, "硬件列表");
                 newtFormAddComponent(form, label_checkbox);
                 for(i=0; i<3; i++){
                          checkbox[i] = newtCheckbox(2, 3 + i, str_checkbox[i],
                                   '#', " *", NULL);
                          newtFormAddComponent(form, checkbox[i]);
                 }
 
                 label_radiobutton = newtLabel(30, 1, "软件列表");
                 newtFormAddComponent(form, label_radiobutton);
 
 
                 radiobutton[0] = newtRadiobutton(30, 3, str_radiobutton[0], 
                          1, NULL);
                  radiobutton[1] = newtRadiobutton(30, 4, str_radiobutton[1], 
                          0, radiobutton[0]);
                 radiobutton[2] = newtRadiobutton(30, 5, str_radiobutton[2], 
                          0, radiobutton[1]);
                 for(i=0; i<3; i++)
                          newtFormAddComponent(form, radiobutton[i]);
 
                 button_ok = newtButton(20, 7, "确认");
                 newtFormAddComponent(form, button_ok);
 
                 //--------------------------------------------
                 //进入循环
                 newtRunForm(form);
 
                 //获取结果
 
                 for(i=0; i<3; i++)
                          result_checkbox[i] = newtCheckboxGetValue(checkbox[i]);
                 co = newtRadioGetCurrent(radiobutton[0]);
                 for(i=0; i<3; i++){
                          if(co == radiobutton[i]) result_radiobutton = i;
                 }
 
 
                 //关闭Form
                 newtFormDestroy(form);
 
                 //复原
                 newtFinished();
 
                 //打印结果
                 printf("硬件选择:\n");
                 for(i=0; i<3; i++)
                          if(result_checkbox[i] == '*')
                                   printf("[*] %s\n", str_checkbox[i]);
                 printf("软件选择:\n");
                 printf("(*) %s\n", str_radiobutton[result_radiobutton]);
 
         }
 
 
 
 
 
运行结果
 
第二个实例 dialog.c
 
         /* File: dialog.c */
 
         #include 
         #include 
 
 
 
         int main(int argc, char *argv[])
         {
                 int rc;
                 char * menuContents[] = { "One", "Two", "Three", 
                          "Four", "Five", NULL };
                 int textWidth;
                 char * entries[10];
                 struct newtWinEntry autoEntries[] = {
                          { "An entry", entries + 0, 0 },
                          { "Another entry", entries + 1, 0 },
                          { "Third entry", entries + 2, 0 },
                          { "Fourth entry", entries + 3, 0 },
                          { NULL, NULL, 0 } };
                 memset(entries, 0, sizeof(entries));
 
                 //初始化
                 newtInit();
                 newtCls();
 
 
                 //信息框
                 newtWinMessage("Simple", "确认", 
                          "This is a simple message window");
                 newtWinChoice("Simple", "确认", "取消", 
                          "This is a simple choice window");
                 rc = newtWinMenu("Test Menu", 
                          "This is a sample invovation of the "
                          "newtWinMenu() call.It may or may not have a scrollbar,"
                          "depending on the need for one.", 50, 5, 5, 3,
                          menuContents, &textWidth, "确认", "取消", NULL);
 
                 rc = newtWinEntries("Text newtWinEntries()", 
                          "This is a sample invovation of "
                          "newtWinEntries() call. It lets you get a lot of input "
                          "quite easily.", 50, 5, 5, 20, autoEntries, "Ok",
                          "Cancel", NULL);
 
                 newtFinished();
         }
运行结果

 

 
 
 
 

 
 
第三个实例 entry.c
 
         #include 
         #include 
         #include 
         #include 
 
         int main(int argc, char *argv[]) 
         {
                 //定义组件
                 newtComponent form, label, entry, button_ok, button_cancel;
                 newtComponent co;
                 char *entryvalue;
 
                 //初始化
                 newtInit();
 
                 //清屏幕
                 newtCls();
 
                 //建立窗口
                 newtCenteredWindow(50, 10, "Entry Sample");
 
                 //-------------------------------------------
                 //建立按钮
                 label  = newtLabel(6, 1, "请输入住址:");
                 entry  = newtEntry(20, 1, "唐山市", 28,
                          NULL, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
 
                 button_ok = newtButton(8, 6, "确认");
                 button_cancel = newtButton(30, 6, "取消");
 
                 //建立Form
                 form = newtForm(NULL, NULL, 0);
 
                 //把按钮加入Form
                 newtFormAddComponents(form, label, entry, 
                          button_ok, button_cancel, NULL);
 
                 //--------------------------------------------
 
                 //进入循环
                 co = newtRunForm(form);
 
                 //获得输入条的值
                 if(co == entry || co == button_ok)
                          entryvalue = strdup(newtEntryGetValue(entry));
                 else
                          entryvalue = strdup("Input cancelled.");
 
                 //关闭Form
                 newtFormDestroy(form);
 
                 //复原
                 newtFinished();
 
                 //打印结果
                 printf("%s\n", entryvalue);
                 free(entryvalue);
         }
运行结果

 
 
第四个实例   helloworld.c
 
         #include 
         #include 
 
         int main(int argc, char *argv[]) 
         {
                 //定义组件
                 newtComponent form, button;
 
                 //初始化
                 newtInit();
 
                 //清屏幕
                 newtCls();
 
                 //在窗口底部写帮助信息
                 newtPushHelpLine("Press button to exit...");
 
                 //建立窗口
                 newtOpenWindow(10, 5, 40, 6, "Hello World!");
 
                 //-------------------------------------------
                 //建立按钮
                 button = newtButton(8, 1, "你好, newt程序员们!");
 
                 //建立Form
                 form = newtForm(NULL, NULL, 0);
 
                 //把按钮加入Form
                 newtFormAddComponents(form, button, NULL);
 
                 //--------------------------------------------
 
                 //进入循环
                 newtRunForm(form);
 
                 //关闭Form
                 newtFormDestroy(form);
 
                 //复原
                 newtFinished();
         }
 
运行结果

 
 
第五个 list.c
 
         /* File: buttons.c */
 
         #include 
         #include 
         #include 
         #include 
 
         int main(int argc, char *argv[]) 
         {
                 int i;
                 //定义组件
                 newtComponent form;
                 newtComponent text, list;
                 newtComponent button_ok, button_cancel;
                 newtComponent co;
                 char *selection;
 
                 char *message =  "请选择你认为最好的操作系统, "
                                   "如果你选择了Windows,  说明你"
                                   "你不了解Linux.";
                 char *str_list[7] = {
                          "Linux",
                          "Windows",
                          "Macintosh",
                          "Solaris",
                          "HP-UX",
                          "BeOS",
                          "OS/2"
                 };
 
 
                 //初始化
                 newtInit();
                 newtCls();
 
                 //建立窗口
                 newtCenteredWindow(50, 18, "List Sample");
 
                 //-------------------------------------------
                 //建立Form
                 form = newtForm(NULL, NULL, 0);
 
                 text = newtTextboxReflowed(10, 1, message, 30, 5, 5, 0);
                 newtFormAddComponent(form, text);
 
                 //建立列表
                 list = newtListbox(8, 5, 8, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT |NEWT_FLAG_BORDER);
                 newtListboxSetWidth(list, 30);
                 for(i=0; i<7; i++)
                          newtListboxAppendEntry(list, 
                                str_list[i], str_list[i]);
                 newtFormAddComponent(form, list);
 
                 //列表
 
                 button_ok = newtButton(20, 14, "确认");
                 newtFormAddComponent(form, button_ok);
 
                 //--------------------------------------------
                 //进入循环
                 newtRunForm(form);
                 selection = strdup((char *)newtListboxGetCurrent(list));
                 //关闭Form
                 newtFormDestroy(form);
                 newtPopWindow();
 
                 newtWinMessage("您的选择", "Ok", selection);
 
                 //复原
                 newtFinished();
 
         }
 
运行结果

 
 
第六个 tree.c
#include 
#include 
#include 
#include 
 
#include "newt.h"
 
int main(void) {
    newtGrid grid;
    newtComponent checktree;
    newtComponent button;
    newtComponent form;
    newtComponent answer;
    void ** result, **ptr;
    int numselected, i, j;
    int * list;
    
    newtInit();
    newtCls();
 
    //checktree = newtCheckboxTreeMulti(-1, -1, 10, " ab", NEWT_FLAG_SCROLL);
    checktree = newtCheckboxTree(-1, -1, 10, NEWT_FLAG_SCROLL);
    newtCheckboxTreeAddItem(checktree, "Numbers", (void *) 2, 0,
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Really really long thing",
                             (void *) 3, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 5", (void *) 5, 
                              NEWT_FLAG_SELECTED, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 6", (void *) 6, 0, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 7", (void *) 7, 
                              NEWT_FLAG_SELECTED, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 8", (void *) 8, 0, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 9", (void *) 9, 0, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 10", (void *) 10,
                              NEWT_FLAG_SELECTED,
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 11", (void *) 11, 0, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 12", (void *) 12,
                              NEWT_FLAG_SELECTED,
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
 
    newtCheckboxTreeAddItem(checktree, "Colors", (void *) 1, 0,
                              0, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Red", (void *) 100, 0,
                              0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "White", (void *) 101, 0,
                              0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Blue", (void *) 102, 0,
                              0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
 
    newtCheckboxTreeAddItem(checktree, "number 4", (void *) 4, 0,
                              3, NEWT_ARG_LAST);
 
    newtCheckboxTreeAddItem(checktree, "Single digit", (void *) 200, 0,
                              1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "One", (void *) 201, 0,
                              1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Two", (void *) 202, 0,
                              1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Three", (void *) 203, 0,
                              1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Four", (void *) 204, 0,
                              1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
 
    newtCheckboxTreeAddItem(checktree, "Double digit", (void *) 300, 0,
                              1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Ten", (void *) 210, 0,
                              1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Eleven", (void *) 211, 0,
                              1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Twelve", (void *) 212, 0,
                              1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Thirteen", (void *) 213, 0,
                              1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
 
    button = newtButton(-1, -1, "Exit");
    
    grid = newtCreateGrid(1, 2);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, checktree, 0, 0, 0, 1, 
                      NEWT_ANCHOR_RIGHT, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, button, 0, 0, 0, 0, 
                      0, 0);
 
    newtGridWrappedWindow(grid, "Checkbox Tree Test");
    newtGridFree(grid, 1);
 
    form = newtForm(NULL, NULL, 0);
    newtFormAddComponents(form, checktree, button, NULL);
 
    answer = newtRunForm(form);
 
    newtFinished();
 
    result = newtCheckboxTreeGetSelection(checktree, &numselected);
    ptr = result;
    if (!result || !numselected)
         printf("none selected\n");
    else
         printf("Current selection (all) (%d):\n", numselected);
    for (i = 0; i < numselected; i++) {
         j = (int) *ptr++;
         printf("%d\n", j);
    }
    result = newtCheckboxTreeGetMultiSelection(checktree, &numselected, 'b');
    ptr = result;
    if (!result || !numselected)
         printf("none selected\n");
    else
         printf("Current selection (b) (%d):\n",numselected);
    for (i = 0; i < numselected; i++) {
         j = (int) *ptr++;
         printf("%d\n", j);
    }
         
    if (result)
         free(result);
 
    list = newtCheckboxTreeFindItem(checktree, (void *) 213);
    printf("path:");
    for (i = 0; list && list[i] != NEWT_ARG_LAST; i++)
        printf(" %d", list[i]);
    printf("\n");
    
    newtFormDestroy(form);
    
    return 0;
}
 
运行结果

 
 
 
第七个 test.c
#include 
#include 
#include 
#include 
 
#include "newt.h"
 
struct callbackInfo {
    newtComponent en;
    char * state;
};
 
void disableCallback(newtComponent co, void * data) {
    struct callbackInfo * cbi = data;
 
    if (*cbi->state == ' ') {
         newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_RESET);
    } else {
         newtEntrySetFlags(cbi->en, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
    }
 
    newtRefresh();
}
 
void suspend(void * d) {
    newtSuspend();
    raise(SIGTSTP);
    newtResume();
}
 
void helpCallback(newtComponent co, void * tag) {
    newtWinMessage("Help", "Ok", tag);
}
//=============================================================================
int main(void) {
    newtComponent b1, b2, r1, r2, r3, e2, e3, l1, l2, l3, scale;
    newtComponent lb, t, rsf, answer, timeLabel;
    newtComponent cs[10];
    newtComponent f, chklist, e1;
    struct callbackInfo cbis[3];
    char results[10];//----------------------------返回值
    char * enr2, * enr3, * scaleVal;
    void ** selectedList;
    int i, numsel;
    char buf[20];//--------------------------------缓冲区
    const char * spinner = "-\\|/\\|/"; //--------------
    const char * spinState;
    struct newtExitStruct es;
 
    newtInit();//---------------------------------初使化
    newtCls(); //---------------------------------清屏
//================================================================================
    newtSetSuspendCallback(suspend, NULL);
    newtSetHelpCallback(helpCallback);
//================================================================================
    newtDrawRootText(0, 0, "Newt test program"); //在根窗体上输出字符串
    newtPushHelpLine(NULL);
    newtDrawRootText(-50, 0, "More root text");  //在根窗体上输出字符串
                 //----------------------------------------------------------------------------
    newtOpenWindow(2, 2, 30, 10, "first window"); //----新建窗口
    newtOpenWindow(10, 5, 65, 16, "window 2");    //----新建窗口
//==================================================================================
    f = newtForm(NULL, "This is some help text", 0); //===============新建一个FORM 表单
    chklist = newtForm(NULL, NULL, 0);//-----------------------------新建一个FORM 表单
 
 
    b1 = newtButton(3, 1, "Exit");     //----按钮
    b2 = newtButton(18, 1, "Update");  //----按钮
    r1 = newtRadiobutton(20, 10, "Choice 1", 0, NULL);//----单选按钮
    r2 = newtRadiobutton(20, 11, "Chc 2", 1, r1);     //----单选按钮
    r3 = newtRadiobutton(20, 12, "Choice 3", 0, r2);  //----单选按钮
    
    rsf = newtForm(NULL, NULL, 0);//-----------------------------新建一个FORM 表单
    newtFormAddComponents(rsf, r1, r2, r3, NULL);//---------------------------------向表单加入物件
    newtFormSetBackground(rsf, NEWT_COLORSET_CHECKBOX);//------------设置表单背景颜色
 
    for (i = 0; i < 10; i++) {
                                            sprintf(buf, "Check %d", i);//--向缓冲区中写入数据
                                            cs[i] = newtCheckbox(3, 10 + i, buf, ' ', NULL, &results[i]);//--建立检查框---一共10项
                                            newtFormAddComponent(chklist, cs[i]);//---向表单中加入组件
    }
 
    l1 = newtLabel(3, 6, "Scale:");   //--------------标签
    l2 = newtLabel(3, 7, "Scrolls:"); //--------------标签
    l3 = newtLabel(3, 8, "Hidden:");  //--------------标签
    e1 = newtEntry(12, 6, "", 20, &scaleVal, 0); //---------------输入框
    e2 = newtEntry(12, 7, "Default", 20, &enr2, NEWT_FLAG_SCROLL);//---输入框
/*    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_HIDDEN); */
    e3 = newtEntry(12, 8, NULL, 20, &enr3, NEWT_FLAG_PASSWORD);  //--------输入框
//======================================================================================
    cbis[0].state = &results[0];
    cbis[0].en = e1;
    newtComponentAddCallback(cs[0], disableCallback, &cbis[0]);
 
    scale = newtScale(3, 14, 32, 100);  //------------------刻度
            newtScaleSet(scale,50);//------------------------------设置刻度值
    newtFormSetHeight(chklist, 3);//-----------设置表单高
 
    newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL);//向表单中填加组件
    newtFormAddComponents(f, rsf, scale, NULL);//向表单中填加组件
 
    lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
                                   NEWT_FLAG_SCROLL | NEWT_FLAG_SHOWCURSOR);
    newtListboxAppendEntry(lb, "First", (void *) 1);
    newtListboxAppendEntry(lb, "Second", (void *) 2);
    newtListboxAppendEntry(lb, "Third", (void *) 3);
    newtListboxAppendEntry(lb, "Fourth", (void *) 4);
    newtListboxAppendEntry(lb, "Sixth", (void *) 6);
    newtListboxAppendEntry(lb, "Seventh", (void *) 7);
    newtListboxAppendEntry(lb, "Eighth", (void *) 8);
    newtListboxAppendEntry(lb, "Ninth", (void *) 9);
    newtListboxAppendEntry(lb, "Tenth", (void *) 10);
 
    newtListboxInsertEntry(lb, "Fifth", (void *) 5, (void *) 4);
    newtListboxInsertEntry(lb, "Eleventh", (void *) 11, (void *) 10);
    newtListboxDeleteEntry(lb, (void *) 11);
 
    spinState = spinner;
    timeLabel = newtLabel(45, 8, "Spinner: -");
 
    t = newtTextbox(45, 10, 17, 5, NEWT_FLAG_WRAP);
    newtTextboxSetText(t, "This is some text does it look okay?\nThis should be alone.\nThis shouldn't be printed");
 
    newtFormAddComponents(f, lb, timeLabel, t, NULL);
    newtRefresh();
    newtFormSetTimer(f, 200);
 
    do {
         newtFormRun(f, &es);
 
         if (es.reason == NEWT_EXIT_COMPONENT && es.u.co == b2) {
             newtScaleSet(scale, atoi(scaleVal));
             newtRefresh();
             answer = NULL;
         } else if (es.reason == NEWT_EXIT_TIMER) {
             spinState++;
             if (!*spinState) spinState = spinner;
             sprintf(buf, "Spinner: %c", *spinState);
             newtLabelSetText(timeLabel, buf);
         }
    } while (es.reason != NEWT_EXIT_COMPONENT || es.u.co == b2);
 
    scaleVal = strdup(scaleVal);
    enr2 = strdup(enr2);
    enr3 = strdup(enr3);
 
    selectedList = newtListboxGetSelection(lb, &numsel);
 
    newtFormDestroy(f);
 
    newtPopWindow();
    newtPopWindow();
    newtFinished();
 
    printf("got string 1: %s\n", scaleVal);
    printf("got string 2: %s\n", enr2);
    printf("got string 3: %s\n", enr3);
 
    if(selectedList) {
         printf("\nSelected listbox items:\n");
         for(i = 0; i < numsel; i++)
             puts(selectedList[i]);
    }
 
    return 0;
}
 
运行结果

 
 
第八个程序 testgrid.c
#include 
#include 
#include 
#include 
 
#include "newt.h"
 
int main(void) {
    newtComponent b1, b2, b3, b4;
    newtComponent answer, f, t;
    newtGrid grid, subgrid;
    char * flowedText;
    int textWidth, textHeight, rc;
    char * menuContents[] = { "One", "Two", "Three", "Four", "Five", NULL };
    char * entries[10];
    struct newtWinEntry autoEntries[] = {
         { "An entry", entries + 0, 0 },
         { "Another entry", entries + 1, 0 },
         { "Third entry", entries + 2, 0 },
         { "Fourth entry", entries + 3, 0 },
         { NULL, NULL, 0 } };
 
    memset(entries, 0, sizeof(entries));
 
    newtInit();
    newtCls();
 
    b1 = newtCheckbox(-1, -1, "An pretty long checkbox for testing", ' ', NULL, NULL);
    b2 = newtButton(-1, -1, "Another Button");
    b3 = newtButton(-1, -1, "But, but");
    b4 = newtButton(-1, -1, "But what?");
 
    f = newtForm(NULL, NULL, 0);
 
    grid = newtCreateGrid(2, 2);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 
                          NEWT_ANCHOR_RIGHT, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
    newtGridSetField(grid, 1, 0, NEWT_GRID_COMPONENT, b3, 0, 0, 0, 0, 0, 0);
    newtGridSetField(grid, 1, 1, NEWT_GRID_COMPONENT, b4, 0, 0, 0, 0, 0, 0);
 
 
    newtFormAddComponents(f, b1, b2, b3, b4, NULL);
 
    newtGridWrappedWindow(grid, "first window");
    newtGridFree(grid, 1);
 
    answer = newtRunForm(f);
         
    newtFormDestroy(f);
    newtPopWindow();
 
    flowedText = newtReflowText("This is a quite a bit of text. It is 40 "
                                   "columns long, so some wrapping should be "
                                   "done. Did you know that the quick, brown "
                                   "fox jumped over the lazy dog?\n\n"
                                   "In other news, it's pretty important that we "
                                   "can properly force a line break.",
                                   40, 5, 5, &textWidth, &textHeight);
    t = newtTextbox(-1, -1, textWidth, textHeight, NEWT_FLAG_WRAP);
    newtTextboxSetText(t, flowedText);
    free(flowedText);
 
    
    b1 = newtButton(-1, -1, "Okay");
    b2 = newtButton(-1, -1, "Cancel");
 
    grid = newtCreateGrid(1, 2);
    subgrid = newtCreateGrid(2, 1);
 
    newtGridSetField(subgrid, 0, 0, NEWT_GRID_COMPONENT, b1, 0, 0, 0, 0, 0, 0);
    newtGridSetField(subgrid, 1, 0, NEWT_GRID_COMPONENT, b2, 0, 0, 0, 0, 0, 0);
 
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, t, 0, 0, 0, 1, 0, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, subgrid, 0, 0, 0, 0, 0,
                          NEWT_GRID_FLAG_GROWX);
    newtGridWrappedWindow(grid, "another example");
    newtGridDestroy(grid, 1);
 
    f = newtForm(NULL, NULL, 0);
    newtFormAddComponents(f, b1, t, b2, NULL);
    answer = newtRunForm(f);
 
    newtPopWindow();
    newtFormDestroy(f);
 
    newtWinMessage("Simple", "Ok", "This is a simple message window");
    newtWinChoice("Simple", "Ok", "Cancel", "This is a simple choice window");
 
    textWidth = 0;
    rc = newtWinMenu("Test Menu", "This is a sample invovation of the "
                      "newtWinMenu() call. It may or may not have a scrollbar, "
                      "depending on the need for one.", 50, 5, 5, 3, 
                       menuContents, &textWidth, "Ok", "Cancel", NULL);
 
    rc = newtWinEntries("Text newtWinEntries()", "This is a sample invovation of "
                      "newtWinEntries() call. It lets you get a lot of input "
                      "quite easily.", 50, 5, 5, 20, autoEntries, "Ok", 
                      "Cancel", NULL);
 
    newtFinished();
 
    printf("rc = 0x%x item = %d\n", rc, textWidth);
 
    return 0;
}
 
运行结果

 
 
第九个   testtree.c
#include 
#include 
#include 
#include 
 
#include "newt.h"
 
int main(void) {
    newtGrid grid;
    newtComponent checktree;
    newtComponent button;
    newtComponent form;
    newtComponent answer;
    void ** result, **ptr;
    int numselected, i, j;
    int * list;
    
    newtInit();
    newtCls();
 
    checktree = newtCheckboxTreeMulti(-1, -1, 10, " ab", NEWT_FLAG_SCROLL);
    newtCheckboxTreeAddItem(checktree, "Numbers", (void *) 2, 0,
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Really really long thing",
                             (void *) 3, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 5", (void *) 5, 
                              NEWT_FLAG_SELECTED, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 6", (void *) 6, 0, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 7", (void *) 7, 
                              NEWT_FLAG_SELECTED, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 8", (void *) 8, 0, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 9", (void *) 9, 0, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 10", (void *) 10,
                              NEWT_FLAG_SELECTED,
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "number 11", (void *) 11, 0, 
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Donuts", (void *) 12,
                              NEWT_FLAG_SELECTED,
                              NEWT_ARG_APPEND, NEWT_ARG_LAST);
 
    newtCheckboxTreeAddItem(checktree, "Bavarian Cream", (void *) 301,
                              NEWT_FLAG_SELECTED,
                              9, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Honey dipped", (void *) 302,
                              NEWT_FLAG_SELECTED,
                              9, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Jelly", (void *) 303,
                              NEWT_FLAG_SELECTED,
                              9, NEWT_ARG_APPEND, NEWT_ARG_LAST);
 
    newtCheckboxTreeAddItem(checktree, "Colors", (void *) 1, 0,
                              0, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Red", (void *) 100, 0,
                              0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "White", (void *) 101, 0,
                              0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Blue", (void *) 102, 0,
                              0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
 
    newtCheckboxTreeAddItem(checktree, "number 4", (void *) 4, 0,
                              3, NEWT_ARG_LAST);
 
    newtCheckboxTreeAddItem(checktree, "Single digit", (void *) 200, 0,
                              1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "One", (void *) 201, 0,
                              1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Two", (void *) 202, 0,
                              1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Three", (void *) 203, 0,
                              1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Four", (void *) 204, 0,
                              1, 0, NEWT_ARG_APPEND, NEWT_ARG_LAST);
 
    newtCheckboxTreeAddItem(checktree, "Double digit", (void *) 300, 0,
                              1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Ten", (void *) 210, 0,
                              1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Eleven", (void *) 211, 0,
                              1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Twelve", (void *) 212, 0,
                              1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
    newtCheckboxTreeAddItem(checktree, "Thirteen", (void *) 213, 0,
                              1, 1, NEWT_ARG_APPEND, NEWT_ARG_LAST);
 
    newtCheckboxTreeSetCurrent(checktree, (void *) 12);
 
    button = newtButton(-1, -1, "Exit");
    
    grid = newtCreateGrid(1, 2);
    newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, checktree, 0, 0, 0, 1, 
                      NEWT_ANCHOR_RIGHT, 0);
    newtGridSetField(grid, 0, 1, NEWT_GRID_COMPONENT, button, 0, 0, 0, 0, 
                      0, 0);
 
    newtGridWrappedWindow(grid, "Checkbox Tree Test");
    newtGridFree(grid, 1);
 
    form = newtForm(NULL, NULL, 0);
    newtFormAddComponents(form, checktree, button, NULL);
 
    answer = newtRunForm(form);
 
    newtFinished();
 
    result = newtCheckboxTreeGetSelection(checktree, &numselected);
    ptr = result;
    if (!result || !numselected)
         printf("none selected\n");
    else
         printf("Current selection (all) (%d):\n", numselected);
    for (i = 0; i < numselected; i++) {
         j = (int) *ptr++;
         printf("%d\n", j);
    }
    result = newtCheckboxTreeGetMultiSelection(checktree, &numselected, 'b');
    ptr = result;
    if (!result || !numselected)
         printf("none selected\n");
    else
         printf("Current selection (b) (%d):\n",numselected);
    for (i = 0; i < numselected; i++) {
         j = (int) *ptr++;
         printf("%d\n", j);
    }
         
    if (result)
         free(result);
 
    list = newtCheckboxTreeFindItem(checktree, (void *) 213);
    printf("path:");
    for (i = 0; list && list[i] != NEWT_ARG_LAST; i++)
        printf(" %d", list[i]);
    printf("\n");
    
    newtFormDestroy(form);
    
    return 0;
}
                                                                                                                                                                                                                                                                  
阅读(5608) | 评论(1) | 转发(0) |
0

上一篇:USB 闪盘引导准备文件

下一篇:YUV

给主人留下些什么吧!~~