summaryrefslogtreecommitdiff
path: root/src/newt/test1.cpp
blob: cbaa2ec885d9a18950874f49d469559324980668 (plain)
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
#include <iostream>

extern "C" {
#include <newt.h>
}

using namespace std;

int main( void )
{
	// init
	newtInit( );
	newtCls( );

	// impressum on root window
	newtDrawRootText( 0, 0, "SMERP newt client" );
	newtDrawRootText( 75, 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" );

	// construct the components of the form and the form itself
	newtComponent form, label1, inputline1,
		label2, inputline2, ok, cancel;

	form = newtForm( NULL, NULL, 0 );
	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 );

	// set timeout
	newtFormSetTimer( form, 10000 );

	// run the form
	struct newtExitStruct result;
	newtFormRun( form, &result );

	// cleanup
	newtPopWindow( );
	newtFinished( );

	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:
			cout << "TIMER" << endl;
			break;
	}

	newtFormDestroy( form );

	return 0;
}