#include <newt.h>
#include <stdio.h>
void rootwin_show()
{
newtCls();
/*请观察left,top为正数,为负数地情形*/
newtDrawRootText(0, 0, "左上角");
newtDrawRootText(-6, 0, "右上角");
newtDrawRootText(0, -3, "左下角");
newtDrawRootText(-6, -3, "右下角");
/*注意helpline缺省时的内容*/
newtPushHelpLine(NULL);
newtRefresh();
sleep(10);
newtPushHelpLine("我的帮助行");
newtRefresh();
sleep(3);
newtPopHelpLine();
newtRefresh();
sleep(1);
}
void label_button()
{
newtComponent form, label, entry, button,cb;
char * entryValue;
newtCls();
newtCenteredWindow(50,10,"输入与标签演示");
/*left,top是相对于中心窗口而言*/
label = newtLabel(10, 1, "请输入:");
entry = newtEntry(19, 1, NULL, 20, &entryValue,
NEWT_FLAG_SCROLL);
newtEntrySet(entry,"\0",0);
button = newtButton(10, 5, "完全按钮");
cb=newtCompactButton(25,5,"紧缩按钮");
form = newtForm(NULL,NULL, 0);
newtFormAddComponents(form, label, entry, button,cb, NULL);
newtRunForm(form);
if(*entryValue!='\0')
{
newtDrawRootText(0,0,"你输入了:");
newtDrawRootText(12,0,entryValue);
}
else
newtDrawRootText(0,0,"无输入!");
newtRefresh();
newtFormDestroy(form);
sleep(5);
}
void check_radio()
{
newtComponent form, checkbox, rb[3], button,lable1,lable2;
char cbValue,cv[2];
int i;
newtCls();
newtOpenWindow(10, 8, 40, 11, "检查盒与单选盒演示");
lable1 = newtLabel(2, 1, "检查盒:");
checkbox = newtCheckbox(10, 1, "A checkbox", ' ', " *X", &cbValue);
lable2 = newtLabel(2, 4, "单选盒:");
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]);
button = newtButton(15, 7, "退出");
form = newtForm(NULL, NULL, 0);
newtFormAddComponent(form, checkbox);
newtFormAddComponent(form, lable1);
newtFormAddComponent(form, lable2);
for (i = 0; i < 3; i++)
newtFormAddComponent(form, rb[i]);
newtFormAddComponent(form, button);
newtPushHelpLine("<空格健>选择");
newtRefresh();
newtRunForm(form);
for (i = 0; i < 3; i++)
if (newtRadioGetCurrent(rb[0]) == rb[i])
{ newtDrawRootText(0, 0, "单选盒:");
newtDrawRootText(9, 0, "第");
if(i==0)newtDrawRootText(11, 0,"1");
if(i==1)newtDrawRootText(11, 0,"2");
if(i==2)newtDrawRootText(11, 0,"3");
newtDrawRootText(12, 0, "个");
}
newtDrawRootText(0, 3, "检查盒状态:");
cv[0]=cbValue;cv[1]='\0';
newtDrawRootText(13, 3, cv);
newtRefresh();
newtFormDestroy(form);
sleep(5);
}
void test()
{
char message[] = "This is a pretty long message. It will be displayed "
"in a newt textbox, and illustrates how to construct "
"a textbox from arbitrary text which may not have "
"very good line breaks.\n\n"
"Notice how literal \\n characters are respected, and "
"may be used to force line breaks and blank lines.";
newtComponent form, text, button;
newtCls();
text = newtTextboxReflowed(1, 1, message, 30, 5, 5, 0);
button = newtButton(12, newtTextboxGetNumLines(text) + 2, "退出");
newtOpenWindow(10, 5, 37,
newtTextboxGetNumLines(text) + 7, "文本盒");
form = newtForm(NULL, NULL, 0);
newtFormAddComponents(form, text, button, NULL);
newtRunForm(form);
newtFormDestroy(form);
}
main()
{
newtComponent ls,fm;
int p = 1, q = 2, r = 3, s = 4, t = 5, *u;
newtInit();
do {
newtCls();
newtRefresh();
newtDrawRootText(0,0,"这是我的一个NEWT演示程序");
newtCenteredWindow(50,10,"请选择");
ls = newtListbox(18,3,5,NEWT_FLAG_RETURNEXIT);
newtListboxAppendEntry(ls,"根窗口演示",&p);
newtListboxAppendEntry(ls,"输入盒与按钮",&q);
newtListboxAppendEntry(ls,"检查盒与单选盒",&r);
newtListboxAppendEntry(ls,"文本盒",&s);
newtListboxAppendEntry(ls,"退出 ",&t);
newtPushHelpLine(" Move using the arrow keys and press ENTER to select");
fm = newtForm(NULL,NULL,0);
newtFormAddComponents(fm,ls,NULL);
newtRunForm(fm);
u = newtListboxGetCurrent(ls);
newtPopWindow();
newtFormDestroy(fm);
switch(*u) {
case 1:
rootwin_show();
break;
case 2:
label_button();
break;
case 3:
check_radio();
break;
case 4:
test();
break;
case 5:
newtFinished();
exit(0);
}
} while(1);
}
|