home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* TUI_TUT.C */
- /* */
- /* This file is the InTUItion version of the UltraWin tutorial UW_TUT10.C. */
- /* Here we show how much easier it is to use InTUItion for all the user */
- /* interface work, especially for the data entry! */
- /****************************************************************************/
- /* #define SOURCE_TRACE 1 */ /* uncomment for SOURCE_TRACE */
- #include <stdio.h>
- #include <fcntl.h>
- #include <io.h>
- #ifndef __TURBOC__
- #include <sys\types.h>
- #endif
- #include <sys\stat.h>
- #include <time.h>
- #include <ctype.h>
- #include "t.h" /* include the main TUI header */
- #include "tui_tut.def" /* include the TUI definitions */
-
- #define MAX_CUST 50
- #define TO_TUI 1
- #define FROM_TUI 2
-
- typedef struct cust
- {
- int status;
- int cust_no;
- char business[34];
- char name[34];
- char addr[34];
- char city[34];
- char state[4];
- char zip[10];
- char phone[16];
- char fax[16];
- char date[10];
- char memo[34];
- char unused[26]; /* round out to 256 bytes */
- } CUST;
-
- /*----------------------------- global vars --------------------------------*/
- PRINT Print;
- CUST Customers[MAX_CUST], *Cp;
- char Path[80], Filename[13] = "CUST.DAT", Fullname[80];
- int Print_stat, End_flag, Curr_cust;
- TUI Main_tui;
-
- /*----------------------------- prototypes ---------------------------------*/
- int main(void);
- int disp_time(void);
- void do_cust_dialog( TUI *tuip );
- void do_main_menu( TUI *tuip );
- void copy_cust( CUST *cp, TUI *tuip, int dir );
- int file_load(CUST *customers);
- int file_save(CUST *customers);
- void print_cust(CUST *cp, PRINT *p);
-
-
- /*********/
- /* ~main */
- /* ********************************************************************/
- /* The main function. Replace the call to load_tui with a call to the */
- /* appropriate register function generated by the TUICP to have your TUI */
- /* linked in. */
- /****************************************************************************/
- int main( void )
- {
- CUST *cp;
-
- if ( !load_tui(&Main_tui, "TUI_TUT.TUI") )
- {
- printf("Sorry, could not load the TUI file!\n");
- return(0);
- }
- init_tui(&Main_tui);
- init_clock(0x3333);
-
- /*------------------------ initialize the printer -------------------------*/
- if( init_printer("temp.dat", NULL, 2048L, 2048L, &Print) )
- Print_stat = 1;
-
- /*-------------- initialize first customer as EnQue Software --------------*/
- cp = &Customers[0];
- strcpy(cp->business, "EnQue Software");
- strcpy(cp->name, "Kevin Huck & Boyd Gafford");
- strcpy(cp->addr, "Rt. 1 Box 116C");
- strcpy(cp->city, "Pleasant Hill");
- strcpy(cp->state, "MO");
- strcpy(cp->zip, "64080");
- strcpy(cp->phone, "(816)987-2515");
- strcpy(cp->fax, "(816)987-2515");
- strcpy(cp->date, "09/11/92");
- strcpy(cp->memo, "BBS 816-353-0991");
- copy_cust(cp, &Main_tui, TO_TUI);
-
- set_idle_func(disp_time); /* set background clock function */
-
- do_cust_dialog(&Main_tui);
-
- end_clock();
- end_tui(&Main_tui);
- free_tui(&Main_tui);
- return(1);
- }
- /*** end of main ***/
-
- /*******************/
- /* ~do_cust_dialog */
- /* **********************************************************/
- /* Shell code for typical dialog interaction. A pointer to the TUI and the */
- /* define for the dialog are passed. */
- /* */
- /* Use DO_INPUT_ADV for forms, DO_NORMAL for normal processing, and 'or' in */
- /* DO_RETURN_EVENT to have all unprocessed events returned to you! */
- /****************************************************************************/
- void do_cust_dialog( TUI *tuip )
- {
- int old_cust = -1;
- int dlg_inx = CUSTOMER_DIALOG, ret_inx, end_flag = OFF;
- char *search;
- WINDOW *wnp;
-
- set_slider(tuip, SLIDER, (long) Curr_cust, 10L, 49L);
- draw_dialog(tuip, dlg_inx);
- wnp = get_dlg_wnp(tuip, CUSTOMER_DIALOG);
- Cp = &Customers[Curr_cust];
- while (!end_flag && !End_flag)
- {
- set_slider(tuip, SLIDER, (long) Curr_cust, 10L, 50L);
- if( Curr_cust != old_cust )
- copy_cust(Cp, tuip, FROM_TUI);
- Cp = &Customers[Curr_cust];
- if( Curr_cust != old_cust )
- {
- copy_cust(Cp, tuip, TO_TUI); /* DONT CALL DRAW DIALOG */
- refresh_dialog(tuip, dlg_inx); /* force redraw of fields */
- old_cust = Curr_cust;
- }
- mv_cs(19, 2, wnp); /* display cust number */
- wn_printf(wnp, "%3d", Curr_cust+1);
-
- ret_inx = do_dialog(tuip, dlg_inx, DO_RETURN_EVENT | DO_RETURN_CMD);
- switch( ret_inx )
- {
- /*----------------------- ESC pressed, or click off! -----------------*/
- case NO_SELECTION:
- do_main_menu(tuip);
- break;
-
- case T_MENU:
- deselect(tuip, ret_inx), draw_item(tuip, ret_inx);
- do_main_menu(tuip);
- break;
-
- /*----------------------- an event not processed ---------------------*/
- case EVENT_RETURNED:
- if (Event.is_mouse)
- do_main_menu(tuip);
- else
- switch( Event.key )
- {
- /*--------------------- process cursor keys ----------------------*/
- case KEY_HOME:
- Curr_cust = 0;
- break;
- case KEY_END:
- Curr_cust = MAX_CUST-1;
- break;
- case KEY_DN:
- if( Curr_cust < MAX_CUST-1 )
- Curr_cust++;
- break;
- case KEY_UP:
- if( Curr_cust > 0 )
- Curr_cust--;
- break;
- case KEY_PGUP:
- if( Curr_cust >= 10 )
- Curr_cust -= 10;
- else
- Curr_cust = 0;
- break;
- case KEY_PGDN:
- if( Curr_cust < MAX_CUST-11 )
- Curr_cust += 10;
- else
- Curr_cust = MAX_CUST-1;
- break;
- }
- break;
-
- case SLIDER:
- Curr_cust = (int) get_sldr_pos(tuip,SLIDER);
- break;
-
- case T_HELP:
- deselect(tuip, ret_inx), draw_item(tuip, ret_inx);
- default:
- search = "";
- switch(ret_inx)
- {
- case LABEL_BUSINESS: search = "///Business"; break;
- case LABEL_NAME: search = "///Name"; break;
- case LABEL_ADDRESS: search = "///Address"; break;
- case LABEL_CITY: search = "///City"; break;
- case LABEL_STATE: search = "///State"; break;
- case LABEL_ZIP: search = "///Zip"; break;
- case LABEL_PHONE: search = "///Phone"; break;
- case LABEL_FAX: search = "///Fax"; break;
- case LABEL_DATE: search = "///Date"; break;
- case LABEL_MEMO: search = "///Memo"; break;
- }
- tui_help(2, 3, 78, 21, "tutor.hlp", search, 0);
- break;
- }
- }
- erase_dialog(tuip, dlg_inx);
- }
- /*** end of do_cust_dialog ***/
-
- /*****************/
- /* ~do_main_menu */
- /* ************************************************************/
- /* This is the function that allows the user to interact with the main top */
- /* menu. */
- /****************************************************************************/
- void do_main_menu( TUI *tuip )
- {
- int i, dlg_inx = MAIN_MENU, ret_inx, end_flag = OFF;
-
- draw_dialog(tuip, dlg_inx);
- while (!end_flag)
- {
- ret_inx = do_dialog(tuip, dlg_inx, DO_NORMAL | DO_RETURN_EVENT);
- end_flag = ON;
- switch( ret_inx )
- {
- /*-------------------- process file menu items -----------------------*/
- case LOAD_F:
- deselect(tuip, ret_inx), draw_item(tuip, ret_inx);
- file_load(Customers);
- copy_cust(Cp, tuip, TO_TUI);
- refresh_dialog(tuip, CUSTOMER_DIALOG);
- break;
-
- case SAVE_F:
- deselect(tuip, ret_inx), draw_item(tuip, ret_inx);
- file_save(Customers);
- break;
-
- case QUIT:
- deselect(tuip, ret_inx), draw_item(tuip, ret_inx);
- End_flag = 1;
- break;
-
- /*--------------------- process edit menu items -----------------------*/
- case CLEAR_CURRENT:
- deselect(tuip, ret_inx), draw_item(tuip, ret_inx);
- setmem(Cp, sizeof(CUST), 0);
- copy_cust(Cp, tuip, TO_TUI);
- refresh_dialog(tuip, CUSTOMER_DIALOG);
- break;
- case CLEAR_ALL:
- deselect(tuip, ret_inx), draw_item(tuip, ret_inx);
- setmem(Customers, sizeof(Customers), 0);
- copy_cust(Cp, tuip, TO_TUI);
- refresh_dialog(tuip, CUSTOMER_DIALOG);
- break;
-
- /*---------------------- process print menu items --------------------*/
- case PRINT_CURRENT:
- deselect(tuip, ret_inx), draw_item(tuip, ret_inx);
- if( Print_stat )
- print_cust(Cp, &Print);
- break;
- case PRINT_ALL:
- deselect(tuip, ret_inx), draw_item(tuip, ret_inx);
- if( Print_stat )
- for( i = 0; i < MAX_CUST; i++ )
- if( strlen(Customers[i].name) ) /* not empty? */
- print_cust(&Customers[i], &Print);
- break;
-
- default:
- if( Event.is_mouse ) /* prevent dialog from redrawing */
- end_flag = OFF; /* rapidly */
- break;
- }
- }
- erase_dialog(tuip, dlg_inx);
- }
- /*** end of do_main_menu ***/
-
- /**************/
- /* ~copy_cust */
- /* ***************************************************************/
- /* copies customer info to/from customer record to tui... */
- /****************************************************************************/
- void copy_cust( CUST *cp, TUI *tuip, int dir )
- {
- if( dir == FROM_TUI )
- {
- strcpy(cp->business, get_inp_text(tuip,BUSINESS));
- strcpy(cp->name, get_inp_text(tuip,NAME));
- strcpy(cp->addr, get_inp_text(tuip,ADDRESS));
- strcpy(cp->city, get_inp_text(tuip,CITY));
- strcpy(cp->state, get_inp_text(tuip,STATE));
- strcpy(cp->zip, get_inp_text(tuip,ZIP));
- strcpy(cp->phone, get_inp_text(tuip,PHONE));
- strcpy(cp->fax, get_inp_text(tuip,FAX));
- strcpy(cp->date, get_inp_text(tuip,DATE));
- strcpy(cp->memo, get_inp_text(tuip,MEMO));
- }else{
- strcpy(get_inp_text(tuip,BUSINESS), cp->business);
- strcpy(get_inp_text(tuip,NAME ), cp->name);
- strcpy(get_inp_text(tuip,ADDRESS ), cp->addr);
- strcpy(get_inp_text(tuip,CITY ), cp->city);
- strcpy(get_inp_text(tuip,STATE ), cp->state);
- strcpy(get_inp_text(tuip,ZIP ), cp->zip);
- strcpy(get_inp_text(tuip,PHONE ), cp->phone);
- strcpy(get_inp_text(tuip,FAX ), cp->fax);
- strcpy(get_inp_text(tuip,DATE ), cp->date);
- strcpy(get_inp_text(tuip,MEMO ), cp->memo);
- }
- }
- /*** end of copy_cust ***/
-
-
- /**************/
- /* ~disp_time */
- /* ***************************************************************/
- /* This routine is called in the background by wait_event and will display */
- /* the time once per second. Notice the use of the global variables */
- /* Uw_timers. There is an array of four "countdown" timers that are user */
- /* accessible. Each "timer tic" will decrement the counts by one, until */
- /* 0 is reached. By "reloading" the timer with "Tics_per_sec", we only */
- /* display the time of day once per second. "Tics_per_sec" is set */
- /* by init_clock. */
- /****************************************************************************/
- int disp_time(void)
- {
- time_t t;
- WINDOW *wnp = Main_tui.back_wnp;
-
- print_in_bkgrnd(); /* call this to print */
- if( !Uw_timers[0] ) /* has one second passed? */
- {
- Uw_timers[0] = Tics_per_sec; /* if so, reload timer */
- t = time(NULL); /* get time */
- mv_cs(55, 24, wnp); /* move window cursor */
- wn_st_qty(ctime(&t), 24, wnp); /* output 24 characters */
- return(1);
- }
- return(0);
- }
- /*** end of disp_time ***/
-
- /**************/
- /* ~file_load */
- /* ***************************************************************/
- /* This routine loads a file from disk into the customer array... */
- /****************************************************************************/
- int file_load(CUST *customers)
- {
- FILE *fp;
-
- if ( file_selected("*.DAT", Path, Filename, Fullname) )
- {
- if( (fp = fopen(Fullname, "rb")) != NULL )
- {
- fread(customers, sizeof(CUST), MAX_CUST, fp);
- fclose(fp);
- tone(1024,10);
- return(1);
- }
- }
- return(0);
- }
- /*** end of file_load ***/
-
- /**************/
- /* ~file_save */
- /* ***************************************************************/
- /* This routine saves a file to disk from the customer array... */
- /****************************************************************************/
- int file_save(CUST *customers)
- {
- FILE *fp;
-
- if ( file_selected("*.DAT", Path, Filename, Fullname) )
- {
- if( (fp = fopen(Fullname, "wb")) != NULL )
- {
- fwrite(customers, sizeof(CUST), MAX_CUST, fp);
- fclose(fp);
- tone(1024,10);
- return(1);
- }
- }
- return(0);
- }
- /*** end of file_save ***/
-
- /***************/
- /* ~print_cust */
- /* **************************************************************/
- /* This routine prints a customer in the desired window... */
- /****************************************************************************/
- void print_cust(CUST *cp, PRINT *p)
- {
- print_printf( p, "Business: %-32s\r\n", cp->business);
- print_printf( p, "Name : %-32s\r\n", cp->name );
- print_printf( p, "Address : %-32s\r\n", cp->addr );
- print_printf( p, "City : %-32s State: %2s Zip: %5s\r\n",
- cp->city, cp->state, cp->zip );
- print_printf( p, "Phone : %-16s\r\n", cp->phone );
- print_printf( p, "Fax : %-16s\r\n", cp->fax );
- print_printf( p, "Date : %-10s\r\n", cp->date );
- print_printf( p, "Memo : %-32s\r\n", cp->memo );
- print_char(12,p); /* print form feed */
- }
- /*** end of print_cust ***/
-
- /*** END OF FILE ***/