#include extern "C" { #include #include } 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( "/ between elements | 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; }