1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#include <iostream>
extern "C" {
#include <newt.h>
#include <cstdio>
}
using namespace std;
int main( void )
{
// init
newtInit( );
newtCls( );
// impressum on root window
newtDrawRootText( 0, 0, "SMERP newt client" );
newtDrawRootText( 70, 0, "(C)2011" );
// context sensitive help text
newtPushHelpLine( "<Tab>/<Shift-Tab> between elements | <Space> selects" );
// a window containing our form
newtOpenWindow( 10, 3, 60, 18, "form1" );
// a spinner to indicate network activity
const char *spinner = "-\\|/";
const char *spinState = spinner;
char spinBuffer[3];
newtDrawRootText( -1, 0, "*" );
// construct the components of the form and the form itself
newtComponent form, label1, inputline1,
label2, inputline2, ok, cancel;
form = newtForm( NULL, NULL, 0 );
newtFormSetTimer( form, 500 );
label1 = newtLabel( 2, 1, "First name:" );
const char *str1 = "";
inputline1 = newtEntry( 20, 1, str1, 20, NULL,
NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT );
label2 = newtLabel( 2, 2, "Second name:" );
const char *str2 = "";
inputline2 = newtEntry( 20, 2, str2, 20, NULL,
NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT );
ok = newtCompactButton( 4, 12, "Ok" );
cancel = newtCompactButton( 20, 12, "Cancel" );
newtFormAddComponents( form, label1, inputline1, label2, inputline2, ok, cancel, NULL );
// run the form up to exit states
struct newtExitStruct result;
do {
newtFormRun( form, &result );
if( result.reason == newtExitStruct::NEWT_EXIT_TIMER ) {
spinState++;
if( !*spinState ) spinState = spinner;
sprintf( spinBuffer, "%c", *spinState );
newtDrawRootText( -1, 0, spinBuffer );
}
} while( result.reason == newtExitStruct::NEWT_EXIT_TIMER );
switch( result.reason ) {
case newtExitStruct::NEWT_EXIT_COMPONENT:
cout << "COMPONENT EXIT(" << result.u.co << ")" << endl;
if( result.u.co == ok ) {
cout << "Ok" << endl;
} else if( result.u.co == cancel ) {
cout << "Cancel" << endl;
}
break;
case newtExitStruct::NEWT_EXIT_HOTKEY:
cout << "EXITKEY(" << result.u.key << ")" << endl;
break;
case newtExitStruct::NEWT_EXIT_FDREADY:
cout << "FDREADY(" << result.u.watch << ")" << endl;
break;
case newtExitStruct::NEWT_EXIT_TIMER:
break;
case newtExitStruct::NEWT_EXIT_ERROR:
break;
}
// cleanup
newtFormDestroy( form );
newtPopWindow( );
newtFinished( );
return 0;
}
|