home *** CD-ROM | disk | FTP | other *** search
- /*
-
- CXLDEMO.C - A demonstration program for the CXL function library.
-
- (c) 1987, 1988 by Mike Smedley
-
- */
-
-
- #include <bios.h>
- #include <conio.h>
- #include <dos.h>
- #include <process.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "cxldef.h"
- #include "cxlkey.h"
- #include "cxlmou.h"
- #include "cxlstr.h"
- #include "cxlvid.h"
- #include "cxlwin.h"
-
- #if defined(__TURBOC__)
- #include <dir.h>
- #elif defined(M_I86) && !defined(__ZTC__)
- #include <direct.h>
- #define bioskey(a) _bios_keybrd(a)
- #define findfirst(a,b,c) _dos_findfirst(a,c,b)
- #define findnext(a) _dos_findnext(a)
- #define ffblk find_t
- #define ff_name name
- #endif
-
- /* function prototypes */
-
- void activate_demo (void);
- void attr_bord_demo (void);
- void change_prompt (void);
- int check_date (char *buf);
- void copy_demo (void);
- void data_entry_demo (void);
- void directory (void);
- void edit_help (void);
- void error_exit (void);
- void execute (void);
- void exit_prog (void);
- void initialize (void);
- void line_inp_demo (void);
- void menu_demo (void);
- void move_demo (void);
- void opening_screen (void);
- void osshell (void);
- void pulldown_demo (void);
- void scrn_swap_demo (void);
- void scroll_demo (void);
- void str_select_demo (void);
- void text_line_demo (void);
- void titl_resz_demo (void);
- void update_clock (void);
- void wrap_up (void);
-
- /* global variables */
-
- WINDOW w[10];
- int row,col,*sbuf1;
- char fname[9],minit[2],lname[18],address[35],phone[12],ssan[11],
- city[16],state[3],zip[10],todate[8],password[13],balance[7];
- char *spaces=" ",*pressakey="Press a key",*p;
-
- /* main function */
-
- void main(void)
- {
- initialize();
- for(;;) {
- opening_screen();
- scroll_demo();
- attr_bord_demo();
- titl_resz_demo();
- data_entry_demo();
- line_inp_demo();
- menu_demo();
- str_select_demo();
- text_line_demo();
- scrn_swap_demo();
- activate_demo();
- move_demo();
- copy_demo();
- wrap_up();
- }
- }
-
- /*---------------------------------------------------------------------------*/
-
- void activate_demo(void)
- {
- register int i,j;
-
- /* open demo window 6 and demonstrate activating of windows */
-
- w[6]=wopen(11,48,21,77,1,LCYAN|_CYAN,LCYAN|_CYAN);
- wtextattr(WHITE|_CYAN);
- wputs("\n CXL's wactiv() is used to"
- "\n activate a window, making"
- "\n it available for windowing"
- "\n operations.");
- wprints(4,14,YELLOW|BLINK|_CYAN,pressakey);
- if(waitkey()==ESC) exit_prog();
- wprints(4,14,_CYAN,spaces);
- for(i=0;i<=6;i++) { /* activate windows 0 - 6 */
- if(bioskey(1)) { /* check for keypress */
- if(getch()==ESC) exit_prog();
- }
- wactiv(w[i]);
- delay_(10);
- }
- w[7]=wopen(6,13,16,33,0,LCYAN,LCYAN|_BLUE);
- if(!w[7]) error_exit();
- w[8]=wopen(8,38,18,58,0,LMAGENTA,LMAGENTA|_RED);
- if(!w[8]) error_exit();
- for(i=0;i<300;i++) {
- for(j=7;j<=8;j++) {
- wactiv(w[j]);
- wputs(j==7?"CXL ":"DEMO ");
- }
- }
- wclose();
- wclose();
- }
-
- /*---------------------------------------------------------------------------*/
-
- void attr_bord_demo(void)
- {
- register int i;
-
- /* open demo window 1 and demonstrate changing of
- window attribute and changing of border style */
-
- w[1]=wopen(10,35,23,65,0,YELLOW|_BLUE,YELLOW|_BLUE);
- if(!w[1]) error_exit();
- wtextattr(LCYAN|_BLUE);
- wputs("\n The wchgattr() function"
- "\n allows you to change the"
- "\n attribute of the active"
- "\n window.");
- wcenters(6,YELLOW|BLINK|_BLUE,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(6,_BLUE,spaces);
- wchgattr(LMAGENTA|_BLUE,WHITE|_GREEN);
- delay_(12);
- wchgattr(LGREEN|_LGREY,LMAGENTA|_RED);
- delay_(12);
- wchgattr(YELLOW|_BROWN,LCYAN|_BLUE);
- if(bioskey(1)) { /* check for keypress */
- if(getch()==ESC) exit_prog();
- }
- delay_(12);
- wchgattr(YELLOW|_MAGENTA,YELLOW|_MAGENTA);
- delay_(12);
- wchgattr(LRED|_MAGENTA,WHITE|_MAGENTA);
- delay_(12);
- wtextattr(LGREEN|_MAGENTA);
- wputs("\n\n The wborder() function is"
- "\n used to change the style"
- "\n of the window's border.");
- wcenters(10,YELLOW|BLINK|_MAGENTA,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(10,_MAGENTA,spaces);
- for(i=1;i<=5;i++) {
- delay_(18);
- wborder(i);
- if(bioskey(1)) {
- if(getch()==ESC) exit_prog();
- }
- }
- delay_(18);
- wborder(0);
- delay_(18);
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this function is called in opening prompt. changes colors of prompt */
-
- void change_prompt(void)
- {
- static int i=LBLUE;
-
- wgotoxy(10,7);
- setattr(i|_BLUE,23);
- delay_(2);
- i++;
- if(i>WHITE) i=LBLUE;
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this function validates the date field in the data entry window */
-
- int check_date(char *buf)
- {
- int month,day;
- char date[7];
-
- /* parse date into numeric month and day */
-
- if(!strblank(buf)) {
- strcpy(date,buf);
- *(date+4)='\0';
- day=atoi(date+2);
- *(date+2)='\0';
- month=atoi(date);
-
- /* validate numeric values */
-
- if(month<1 || month>12) {
- wperror("Invalid month");
- return(1);
- }
- if(day<1 || day>31) {
- wperror("Invalid day");
- return(3);
- }
- }
-
- /* return normally */
-
- return(0);
- }
-
- /*---------------------------------------------------------------------------*/
-
- void copy_demo(void)
- {
- /* demonstrate making copies of the same window */
-
- wtextattr(LRED|_BROWN);
- wputs("\n\n The wcopy() function will"
- "\n create a duplicate of the"
- "\n active window.");
- wprints(7,17,YELLOW|BLINK|_BROWN,pressakey);
- if(waitkey()==ESC) exit_prog();
- wprints(7,17,_BROWN,spaces);
- w[8]=wcopy(0,0);
- if(!w[8]) error_exit();
- delay_(12);
- w[9]=wcopy(1,37);
- if(!w[9]) error_exit();
- if(bioskey(1)) { /* check for keypress */
- if(getch()==ESC) exit_prog();
- }
- delay_(18);
- wclose(); /* close copies */
- delay_(12);
- wclose();
- delay_(12);
- }
-
- /*---------------------------------------------------------------------------*/
-
- void data_entry_demo(void)
- {
- register int i,mode;
-
- /* open demo window 3 and demonstrate multi-field keyboard input */
-
- w[3]=wopen(10,10,22,50,1,LCYAN|_BLUE,LCYAN|_BLUE);
- if(!w[3]) error_exit();
- wtextattr(LMAGENTA|_BLUE);
- wputs("\n The winpdef() and winpread()"
- "\n functions allow multi-field"
- "\n keyboard data entry.");
- wcenters(5,YELLOW|BLINK|_BLUE,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(5,_BLUE,spaces);
- setonkey(0x3b00,edit_help,0); /* define F1 as help key */
- for(mode=0;mode<=1;mode++) {
- if(!wopen(5,5,22,60,3,LCYAN|_BLUE,LCYAN|_BLUE)) error_exit();
- wtitle(mode?"[ Data Update Window ]":"[ Data Entry Window ]",
- TLEFT,LCYAN|_BLUE);
- wprints(1,2,WHITE|_BLUE,"First name?");
- winpdef(1,15,fname,"MMMMMMMM",0,LGREEN|_LGREY,mode,NULL);
- wprints(1,27,WHITE|_BLUE,"Initial?");
- winpdef(1,37,minit,"U'.'",0,LGREEN|_LGREY,mode,NULL);
- wprints(3,2,WHITE|_BLUE,"Last name?");
- winpdef(3,15,lname,"MMMMMMMMMMMMAAAAA",0,LGREEN|_LGREY,mode,NULL);
- wprints(5,2,WHITE|_BLUE,"Address?");
- winpdef(5,15,address,"**********************************",'M',
- LGREEN|_LGREY,mode,NULL);
- wprints(7,2,WHITE|_BLUE,"City?");
- winpdef(7,15,city,"MMMMMMMMMMMMMMM",0,LGREEN|_LGREY,mode,NULL);
- wprints(7,35,WHITE|_BLUE,"State?");
- winpdef(7,43,state,"UU",0,LGREEN|_LGREY,mode,NULL);
- wprints(9,2,WHITE|_BLUE,"Zip Code?");
- winpdef(9,15,zip,"#####'-'####",0,LGREEN|_LGREY,mode,NULL);
- wprints(9,29,WHITE|_BLUE,"Phone?");
- winpdef(9,37,phone,"'('###') '###'-'####",0,LGREEN|_LGREY,mode,NULL);
- wprints(11,2,WHITE|_BLUE,"Today's Date");
- winpdef(11,15,todate,"<01>#'/'<0123>#'/'<89>#",0,LGREEN|_LGREY,mode,
- check_date);
- wprints(11,30,WHITE|_BLUE,"SSAN?");
- winpdef(11,37,ssan,"<0123456>##'-'##'-'####",0,LGREEN|_LGREY,
- mode,NULL);
- wprints(13,2,WHITE|_BLUE,"Password?");
- winpdef(13,15,password,"UUUUUUUUUUUU",'P',LGREEN|_LGREY,mode,NULL);
- wprints(13,31,WHITE|_BLUE,"Balance?");
- winpdef(13,41,balance,"'$'< 0123456789>< 0123456789>##'.'##",0,
- LGREEN|_LGREY,mode,NULL);
- wcenters(15,LBLUE|_BLUE,
- ">>> Press F1 for Help with Editing Keys <<<");
- wtextattr(WHITE|_LGREY);
- setcursz(6,7); /* turn cursor on */
- i=winpread(); /* read all defined fields */
- setcursz(32,0); /* turn cursor back off */
- if(i) exit_prog(); /* check for Esc press */
- wclose();
- if(!mode) {
- wtextattr(LGREEN|_BLUE);
- wprintf("\n\n CXL's data entry functions"
- "\n also allow you to update"
- "\n data that already exists!");
- wcenters(9,YELLOW|BLINK|_BLUE,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(9,YELLOW|BLINK|_BLUE,spaces);
- }
- }
- setonkey(0x3b00,NULL,0); /* undefine F1 as help key */
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this is the 'Directory' function under the 'File' menu */
-
- void directory(void)
- {
- #if !defined(__ZTC__)
- char filespec[41],file1[13],file2[13];
- int i,done,lines,files;
- struct ffblk ffblk;
-
- strcpy(filespec,"*.*");
- memset(filespec+3,' ',37);
- filespec[40]='\0';
- setcursz(6,7);
- if(!wopen(4,14,20,59,0,LRED|_MAGENTA,LCYAN|_BLUE)) exit(1);
- wtitle("[ Directory ]",TCENTER,LRED|_MAGENTA);
- for(;;) {
- if(!wopen(6,6,8,49,0,LMAGENTA|_RED,LMAGENTA|_RED)) exit(1);
- wtitle("[ Filespec ]",TCENTER,LMAGENTA|_RED);
- winpdef(0,1,filespec,"****************************************",'U',
- BLUE|_LGREY,1,NULL);
- wtextattr(WHITE|_LGREY);
- i=winpread();
- wclose();
- if(i) break;
- wclear();
- wtextattr(LCYAN|_BLUE);
- files=0;
- lines=0;
- done=findfirst(filespec,&ffblk,0);
- for(;;) {
- if(done) break;
- files++;
- strcpy(file1,ffblk.ff_name);
- if(!done) done=findnext(&ffblk);
- strcpy(file2,ffblk.ff_name);
- if(done) {
- file2[0]='\0';
- }
- else {
- files++;
- done=findnext(&ffblk);
- }
- if(done) {
- ffblk.ff_name[0]='\0';
- }
- else {
- files++;
- }
- wprintf(" %-15s%-15s%s\n",file1,file2,ffblk.ff_name);
- lines++;
- if(lines>=14) {
- wtextattr(LGREEN|_BLUE);
- wprintf(" Press a key to continue....");
- wtextattr(LCYAN|_BLUE);
- i=waitkey();
- wprintf("\r");
- if(i==ESC) break;
- lines=0;
- }
- if(!done) done=findnext(&ffblk);
- }
- wtextattr(LGREEN|_BLUE);
- wprintf(" Files found: %d Press a key....",files);
- waitkey();
- }
- setcursz(32,0);
- wclose();
- #endif
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this function performs user requested help from data entry window */
-
- void edit_help(void)
- {
- int wrow,wcol;
-
- wreadcur(&wrow,&wcol);
- if(!wopen(0,13,24,66,1,YELLOW|_RED,YELLOW|_RED)) error_exit();
- wtitle("[ Editing Keys ]",TCENTER,YELLOW|_RED);
- wtextattr(WHITE|_RED);
- if(_cgasnow) waitvret(); /* if CGA, wait for vertical retrace */
- wputs("\n"
- " LeftArrow - previous position left\n"
- " RightArrow - next position right\n"
- " UpArrow - previous field up\n"
- " DownArrow - next field down\n"
- " Ctrl-LeftArrow - previous word left\n"
- " Ctrl-RightArrow - next word right\n"
- " Tab - next field right\n"
- " Shift-Tab - previous field left\n");
- if(_cgasnow) waitvret(); /* if CGA, wait for vertical retrace */
- wputs(" Enter - process field\n"
- " Ctrl-Enter - process all fields\n"
- " Home - beginning of field\n"
- " End - end of field\n"
- " Ctrl-Home - beginning of 1st field\n"
- " Ctrl-End - end of last field\n"
- " Ins - insert character\n");
- if(_cgasnow) waitvret(); /* if CGA, wait for vertical retrace */
- wputs(" Del - delete character\n"
- " BackSpace - delete character left\n"
- " Ctrl-BackSpace - delete word left\n"
- " Ctrl-T - delete word right\n"
- " Ctrl-U - delete to end of field\n"
- " Ctrl-Y - delete to end of last field\n"
- " Esc - abort data entry (and demo)");
- waitkey();
- wclose();
- wpgotoxy(wrow,wcol);
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this function will be called if an error occurs */
-
- void error_exit(void)
- {
- setcursz(6,7); /* set cursor size back to normal */
- if(_werrno) {
- printf("\nError: %s ",werrmsg()); /* display error message */
- }
- else {
- abort();
- }
- exit(1);
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this is the 'Execute' function under the 'File' menu */
-
- void execute(void)
- {
- char command[61];
- int *sptr;
-
- setcursz(6,7);
- if(!wopen(8,7,10,70,0,LMAGENTA|_RED,LMAGENTA|_RED)) exit(1);
- wtitle("[ Execute DOS Command ]",TCENTER,LMAGENTA|_RED);
- for(;;) {
- winpdef(0,1,command,"****************************************"
- "********************",0,BLUE|_LGREY,0,NULL);
- wtextattr(WHITE|_LGREY);
- if(winpread()) break;
- sptr=ssave();
- if(sptr==NULL) exit(1);
- printf(" \b");
- clrscrn();
- system(command);
- printf("\nPress any key to continue....");
- waitkey();
- srestore(sptr);
- }
- setcursz(32,0);
- wclose();
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this function will be called if Escape or Ctrl-C is pressed */
-
- void exit_prog(void)
- {
- clearkeys(); /* clear keyboard buffer */
- setcursz(6,7); /* set cursor size back to normal */
- srestore(sbuf1); /* restore original screen */
- gotoxy_(row,col); /* restore original cursor position */
- exit(0);
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this function initializes the demo (save screen, cursor) */
-
- void initialize(void)
- {
- _cgasnow=0; /* change to 1 if CGA snow */
- videoinit(); /* initialize video */
- if(msinit()) msspeed(128,64); /* initialize mouse */
- setonkey(0x2e03,exit_prog,0); /* attach Ctrl-C to exit function */
- sbuf1=ssave(); /* save current screen contents */
- if(!sbuf1) error_exit();
- readcur(&row,&col); /* save current cursor position */
- setcursz(32,0); /* turn off cursor */
- }
-
- /*---------------------------------------------------------------------------*/
-
- void line_inp_demo(void)
- {
- int i;
-
- /* open demo window 4 and demonstrate formatted line input */
-
- w[4]=wopen(8,41,20,78,3,WHITE|_MAGENTA,WHITE|_MAGENTA);
- if(!w[4]) error_exit();
- wtextattr(LGREEN|_MAGENTA);
- wputs("\n For complete control of"
- "\n keyboard line input, there"
- "\n is the winputsf() function.");
- wcenters(5,YELLOW|BLINK|_MAGENTA,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(5,YELLOW|_MAGENTA,spaces);
- wtextattr(WHITE|_MAGENTA);
- setcursz(6,7); /* turn cursor on */
- i=winputsf(phone,"'\n\n Phone Number? '!R--!"
- "'('!+!###!-!') '!+!###!-!'-'!+!####");
- if(i) exit_prog(); /* check for Esc press */
- wtextattr(WHITE|_MAGENTA);
- i=winputsf(ssan,"'\n\n Soc Sec Number? '!R-!"
- "<0123456>##!-!'-'!+!##!-!'-'!+!####");
- if(i) exit_prog(); /* check for Esc press */
- wtextattr(WHITE|_MAGENTA);
- i=winputsf(todate,"\"\n\n Today's Date? \"!R-!"
- "<01>#!-!'/'!+!<0123>#!-!'/'!+!'19'<89>#");
- if(i) exit_prog(); /* check for Esc press */
- setcursz(32,0); /* turn cursor back off */
- }
-
- /*---------------------------------------------------------------------------*/
-
- void menu_demo(void)
- {
- register int i;
-
- /* clear window 4 and demonstrate pull-down & pop-up menus */
-
- wclear();
- wtextattr(LGREEN|_MAGENTA);
- wputs("\n With the wmenudef() & wmenuget()"
- "\n functions, you can make pull-down"
- "\n and pop-up menus.");
- wcenters(5,YELLOW|BLINK|_MAGENTA,pressakey);
- if(waitkey()==ESC) exit_prog();
- pulldown_demo();
- if(waitkey()==ESC) exit_prog();
- wcenters(5,_MAGENTA,spaces);
- if(!wopen(10,35,17,51,0,YELLOW|_BLACK,YELLOW|_BLACK)) error_exit();
- wmenudef(0,0,LCYAN|_RED," Add record ",'A',WHITE|_RED,NULL);
- wmenudef(1,0,LCYAN|_RED," Show record ",'S',WHITE|_RED,NULL);
- wmenudef(2,0,LCYAN|_RED," Delete record ",'D',WHITE|_RED,NULL);
- wmenudef(3,0,LCYAN|_RED," Update record ",'U',WHITE|_RED,NULL);
- wmenudef(4,0,LCYAN|_RED," Print record ",'P',WHITE|_RED,NULL);
- wmenudef(5,0,LCYAN|_RED," Quit program ",'Q',WHITE|_RED,NULL);
- i=wmenuget(WHITE|_GREEN,'A',0);
- if(!i) exit_prog();
- wclose();
- wtextattr(WHITE|_MAGENTA);
- wgotoxy(5,9);
- wprintf("You selected %c!",i);
- delay_(18);
- wgotoxy(5,9);
- wputs(" ");
- wprints(3,22,YELLOW|_MAGENTA,"Select one:");
- wmenudef(5,3,LCYAN|_MAGENTA,"Add record",'A',LRED|_MAGENTA,NULL);
- wmenudef(5,18,LCYAN|_MAGENTA,"Show record",'S',LRED|_MAGENTA,NULL);
- wmenudef(7,3,LCYAN|_MAGENTA,"Delete record",'D',LRED|_MAGENTA,NULL);
- wmenudef(7,18,LCYAN|_MAGENTA,"Update record",'U',LRED|_MAGENTA,NULL);
- wmenudef(9,3,LCYAN|_MAGENTA,"Print record",'P',LRED|_MAGENTA,NULL);
- wmenudef(9,18,LCYAN|_MAGENTA,"Quit program",'Q',LRED|_MAGENTA,NULL);
- i=wmenuget(LCYAN|_LGREY,'A',0);
- wprints(3,22,_MAGENTA,spaces);
- if(!i) exit_prog();
- delay_(10);
- if(!wopen(7,15,10,65,0,YELLOW,LCYAN|_BLUE)) error_exit();
- wmenudef(0,0,LMAGENTA|_BLUE,"Add",'A',WHITE|_BLUE,
- "Create a new record");
- wmenudef(0,8,LMAGENTA|_BLUE,"Delete",'D',WHITE|_BLUE,
- "Delete an existing record");
- wmenudef(0,19,LMAGENTA|_BLUE,"Print",'P',WHITE|_BLUE,
- "Print hardcopy of existing record");
- wmenudef(0,28,LMAGENTA|_BLUE,"Show",'S',WHITE|_BLUE,
- "Display an existing record on screen");
- wmenudef(0,36,LMAGENTA|_BLUE,"Update",'U',WHITE|_BLUE,
- "Modify an existing record");
- wmenudef(0,45,LMAGENTA|_BLUE,"Quit",'Q',WHITE|_BLUE,
- "Quit program and return to DOS");
- wtextattr(LGREEN|_BLUE);
- if(!wmenuget(YELLOW|_LGREY,'A',0)) exit_prog();
- delay_(18);
- wclose();
- }
-
- /*---------------------------------------------------------------------------*/
-
- void move_demo(void)
- {
- /* open demo window 7 and demonstrate moving of active window */
-
- w[7]=wopen(4,2,16,35,2,LGREEN|_BROWN,LGREEN|_BROWN);
- if(!w[7]) error_exit();
- wtextattr(WHITE|_BROWN);
- wputs("\n To move the active window,"
- "\n the wmove() function is"
- "\n used.");
- wprints(3,8,YELLOW|BLINK|_BROWN,pressakey);
- if(waitkey()==ESC) exit_prog();
- wprints(3,8,_BROWN,spaces);
- if(wmove(0,0)) error_exit();
- delay_(12);
- if(wmove(10,4)) error_exit();
- delay_(12);
- if(wmove(6,19)) error_exit();
- delay_(12);
- if(bioskey(1)) { /* check for keypress */
- if(getch()==ESC) exit_prog();
- }
- if(wmove(1,13)) error_exit();
- delay_(12);
- if(wmove(2,35)) error_exit();
- delay_(12);
- if(wmove(11,35)) error_exit();
- delay_(12);
- }
-
- /*---------------------------------------------------------------------------*/
-
- void opening_screen(void)
- {
- register int i;
-
- /* open up opening screen windows */
-
- for(i=0;i<6;i++) {
- w[i]=wopen(i,i+10,i+13,i+47,3,LCYAN|_BLUE,LCYAN|_BLUE);
- if(!w[i]) error_exit();
-
- /* sound tones of increasing pitch */
-
- sound_(15000-((i+2)*1500),1);
- sound_(12000-((i+1)*1500),1);
- }
-
- wcenters(0,LRED," C X L ");
- wcenters(1,LGREEN,"An Extended C Function Library");
- wcenters(2,LGREEN,"Version 4.0");
- wcenters(4,YELLOW,"by Mike Smedley");
- wcenters(6,LMAGENTA,"(c) 1987, 1988 - All Rights Reserved");
- wcenters(8,WHITE,"Demonstration Program");
- wcenters(10,LCYAN|_BLUE,"Press any key to begin");
-
- /* change colors of prompt until a key is pressed */
-
- setkbloop(change_prompt);
- if((getxch()&0x00ff)==ESC) exit_prog();
- setkbloop(NULL);
- wcenters(10,_BLUE," ");
-
- /* scroll the window's text up and out of the window */
-
- for(i=0;i<10;i++) {
- wscroll(1,SUP);
- delay_(2);
- }
-
- /* close all open windows */
-
- for(i=5;i>=0;i--) {
- wclose();
- delay_(2);
- }
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this is the 'OS Shell' function under the 'File' menu */
-
- void osshell(void)
- {
- int *sptr;
-
- setcursz(6,7);
- sptr=ssave();
- if(sptr==NULL) exit(1);
- printf(" \b");
- clrscrn();
- printf("Type EXIT to return....\n");
- system("COMMAND");
- srestore(sptr);
- setcursz(32,0);
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* This function is the demonstration of pull-down windows */
-
- void pulldown_demo(void)
- {
- char m1; /* return value from main menu */
- char m2; /* return value from a pull-down menu */
-
- if(!wopen(0,0,24,79,2,CYAN,CYAN)) error_exit();
- setkbloop(update_clock);
- wprints(0,0,_BLUE," "
- " ");
- wprints(1,0,CYAN,"────────────────────────────────────────"
- "──────────────────────────────────────");
- wgotoxy(2,0);
- wtextattr(YELLOW);
- wputs("This is a sample editor interface to demonstrate how CXL's "
- "wmenudef()\n"
- "and wmenuget() functions can be used for pull-down menus. "
- "Use arrow keys\n"
- "to move selection bar around and use the Esc key to back up "
- "to the previous\n"
- "menu. Select 'Quit' from any menu to exit the pull-down demo. "
- "Try the\n"
- "'Directory', 'Execute' and 'OS Shell' functions under the 'File' "
- "menu.");
- if(_mouse) {
- wtextattr(WHITE);
- wputs("\nSince you have a mouse, you can use it to move around and "
- "select options!");
- }
-
- /* Initialize selection bar position to position 'F'.
- The variable m1 is used for the load position of the main menu.
- The variable m2 is used for how the main menu should act.
- When an option is selected from the main menu, the selection will
- be stored in m1 so that when the pull-down menu returns, the
- selection bar will be positioned to the right position.
- The pull-down menus will return their selection in variable m2.
- If m1 == 0 then Escape was pressed from main menu or was set to 0 by
- one of the pull-down menus. Exit pull-down demo. */
-
- m1='F';
- m2=PDMAIN;
- while(m1) {
- wmenudef(0,2,YELLOW|_BLUE,"File",'F',LCYAN|_BLUE,NULL);
- wmenudef(0,15,YELLOW|_BLUE,"Editing",'E',LCYAN|_BLUE,NULL);
- wmenudef(0,31,YELLOW|_BLUE,"Defaults",'D',LCYAN|_BLUE,NULL);
- wmenudef(0,47,YELLOW|_BLUE,"Help",'H',LCYAN|_BLUE,NULL);
- wmenudef(0,59,YELLOW|_BLUE,"Options",'O',LCYAN|_BLUE,NULL);
- if(wmenudef(0,73,YELLOW|_BLUE,"Quit",'Q',LCYAN|_BLUE,NULL))
- error_exit();
- m1=wmenuget(YELLOW|_MAGENTA,m1,m2);
- switch(m1) { /* test return value from main (horizontal) menu */
- case 'F':
-
- /* define pull-down menu for main menu option 'F' */
-
- m2='L';
- if(!wopen(2,1,11,14,0,LGREY,LGREY)) error_exit();
- while(m2>PDMENU) {
- wmenudef(0,0,YELLOW|_BLUE," Load ",'L',
- LCYAN|_BLUE,NULL);
- wmenudef(1,0,YELLOW|_BLUE," Save ",'S',
- LCYAN|_BLUE,NULL);
- wmenudef(2,0,YELLOW|_BLUE," Rename ",'R',
- LCYAN|_BLUE,NULL);
- wmenudef(3,0,YELLOW|_BLUE," New ",'N',
- LCYAN|_BLUE,NULL);
- wmenudef(4,0,YELLOW|_BLUE," Directory ",'D',
- LCYAN|_BLUE,NULL);
- wmenudef(5,0,YELLOW|_BLUE," Execute ",'E',
- LCYAN|_BLUE,NULL);
- wmenudef(6,0,YELLOW|_BLUE," OS Shell ",'O',
- LCYAN|_BLUE,NULL);
- if(wmenudef(7,0,YELLOW|_BLUE," Quit ",'Q',
- LCYAN|_BLUE,NULL)) {
- error_exit();
- }
- m2=wmenuget(YELLOW|_MAGENTA,m2,PDMENU);
- switch(m2) {
- case 'D':
- directory();
- break;
- case 'E':
- execute();
- break;
- case 'O':
- osshell();
- break;
- case 'Q':
- m1=0; /* needed to exit pull-down demo */
- m2=PDMAIN;
- break;
- }
- }
- wclose();
- break;
- case 'E':
-
- /* define pull-down menu for main menu option 'E' */
-
- m2='C';
- if(!wopen(2,14,10,28,0,LGREY,LGREY)) error_exit();
- while(m2>PDMENU) {
- wmenudef(0,0,YELLOW|_BLUE," Cut ",'C',
- LCYAN|_BLUE,NULL);
- wmenudef(1,0,YELLOW|_BLUE," Paste ",'P',
- LCYAN|_BLUE,NULL);
- wmenudef(2,0,YELLOW|_BLUE," cOpy ",'O',
- LCYAN|_BLUE,NULL);
- wmenudef(3,0,YELLOW|_BLUE," block Begin ",'B',
- LCYAN|_BLUE,NULL);
- wmenudef(4,0,YELLOW|_BLUE," block End ",'E',
- LCYAN|_BLUE,NULL);
- wmenudef(5,0,YELLOW|_BLUE," Insert line ",'I',
- LCYAN|_BLUE,NULL);
- if(wmenudef(6,0,YELLOW|_BLUE," Delete line ",'D',
- LCYAN|_BLUE,NULL)) {
- error_exit();
- }
- m2=wmenuget(YELLOW|_MAGENTA,m2,PDMENU);
- /* test m2 here */
- }
- wclose();
- break;
- case 'D':
-
- /* define pull-down menu for main menu option 'D' */
-
- m2='L';
- if(!wopen(2,30,11,52,0,LGREY,LGREY)) error_exit();
- while(m2>PDMENU) {
- wmenudef(0,0,YELLOW|_BLUE," Left margin 0 ",'L',
- LCYAN|_BLUE,NULL);
- wmenudef(1,0,YELLOW|_BLUE," Right margin 72 ",'R',
- LCYAN|_BLUE,NULL);
- wmenudef(2,0,YELLOW|_BLUE," Tab width 4 ",'T',
- LCYAN|_BLUE,NULL);
- wmenudef(3,0,YELLOW|_BLUE," tab eXpansion yes ",'X',
- LCYAN|_BLUE,NULL);
- wmenudef(4,0,YELLOW|_BLUE," Insert mode yes ",'I',
- LCYAN|_BLUE,NULL);
- wmenudef(5,0,YELLOW|_BLUE," iNdent mode yes ",'N',
- LCYAN|_BLUE,NULL);
- wmenudef(6,0,YELLOW|_BLUE," Word wrap mode no ",'W',
- LCYAN|_BLUE,NULL);
- if(wmenudef(7,0,YELLOW|_BLUE," Save defaults ",'S',
- LCYAN|_BLUE,NULL)) {
- error_exit();
- }
- m2=wmenuget(YELLOW|_MAGENTA,m2,PDMENU);
- /* test m2 here */
- }
- wclose();
- break;
- case 'H':
-
- /* define pull-down menu for main menu option 'H' */
-
- m2='H';
- if(!wopen(2,46,7,65,0,LGREY,LGREY)) error_exit();
- while(m2>PDMENU) {
- wmenudef(0,0,YELLOW|_BLUE," help on Help ",'H',
- LCYAN|_BLUE,NULL);
- wmenudef(1,0,YELLOW|_BLUE," help on Editing ",'E',
- LCYAN|_BLUE,NULL);
- wmenudef(2,0,YELLOW|_BLUE," help on Defaults ",'D',
- LCYAN|_BLUE,NULL);
- if(wmenudef(3,0,YELLOW|_BLUE," help on Options ",'O',
- LCYAN|_BLUE,NULL)) {
- error_exit();
- }
- m2=wmenuget(YELLOW|_MAGENTA,m2,PDMENU);
- /* test m2 here */
- }
- wclose();
- break;
- case 'O':
-
- /* define pull-down menu for main menu option 'O' */
-
- m2='Z';
- if(!wopen(2,56,8,77,0,LGREY,LGREY)) error_exit();
- while(m2>PDMENU) {
- wmenudef(0,0,YELLOW|_BLUE," screen siZe 43 ",'Z',
- LCYAN|_BLUE,NULL);
- wmenudef(1,0,YELLOW|_BLUE," Backup files yes ",'B',
- LCYAN|_BLUE,NULL);
- wmenudef(2,0,YELLOW|_BLUE," bOxed display no ",'O',
- LCYAN|_BLUE,NULL);
- wmenudef(3,0,YELLOW|_BLUE," Load options ",'L',
- LCYAN|_BLUE,NULL);
- if(wmenudef(4,0,YELLOW|_BLUE," Save options ",'S',
- LCYAN|_BLUE,NULL)) {
- error_exit();
- }
- m2=wmenuget(YELLOW|_MAGENTA,m2,PDMENU);
- /* test m2 here */
- }
- wclose();
- break;
- case 'Q':
-
- /* define pull-down menu for main menu option 'Q' */
-
- m2='N';
- if(!wopen(2,60,7,78,0,LGREY,LGREY)) error_exit();
- while(m2>PDMENU) {
- wcclear(BLUE|_BLUE);
- wprints(0,2,WHITE|_BLUE,"Are you sure?");
- wmenudef(2,0,YELLOW|_BLUE," No ",'N',
- LCYAN|_BLUE,NULL);
- if(wmenudef(3,0,YELLOW|_BLUE," Yes ",'Y',
- LCYAN|_BLUE,NULL)) {
- error_exit();
- }
- m2=wmenuget(YELLOW|_MAGENTA,m2,PDMENU);
- switch(m2) {
- case 'N':
- m2=PDMAIN;
- break;
- case 'Y':
- m1=0; /* needed to exit pull-down demo */
- m2=PDMAIN;
- break;
- }
- }
- wclose();
- break;
- }
- }
- wclose();
- setkbloop(NULL);
- }
-
- /*---------------------------------------------------------------------------*/
-
- void scrn_swap_demo(void)
- {
- int *sbuf2;
-
- /* open demo window 5 and demonstrate screen swapping */
-
- w[5]=wopen(3,3,12,33,0,YELLOW|_BLACK,YELLOW|_BLACK);
- if(!w[5]) error_exit();
- wtextattr(LCYAN|_BLACK);
- wputs("\n The ssave() and srestore()"
- "\n functions allow screen"
- "\n swapping to/from memory.");
- wcenters(5,LRED|BLINK|_BLACK,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(5,_BLACK,spaces);
- sbuf2=ssave();
- if(!sbuf2) error_exit();
- gotoxy_(24,79);
- clrscrn();
- prints(10,27,LMAGENTA,"Press a key to return");
- if(waitkey()==ESC) exit_prog();
- srestore(sbuf2);
- }
-
- /*---------------------------------------------------------------------------*/
-
- void scroll_demo(void)
- {
- register int i,j;
-
- /* open demo window 0 and demonstrate text wraparound and
- scrolling from within a window */
-
- w[0]=wopen(1,1,11,41,2,LMAGENTA|_RED,LMAGENTA|_RED);
- if(!w[0]) error_exit();
- wtextattr(LCYAN|_RED);
- wprintf("\n CXL's window display functions like"
- "\n wprintf() & wputs() allow wrap-around"
- "\n and scrolling from within windows.");
- wcenters(7,YELLOW|BLINK|_RED,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(7,_RED,spaces);
- wgotoxy(8,0);
- for(i=0;i<15;i++) {
- if(bioskey(1)) {
- if(getch()==ESC) exit_prog();
- break;
- }
- for(j=DGREY;j<=WHITE;j++) {
- wtextattr(j|_RED);
- wputs("CXL ");
- delay_(1);
- }
- }
- }
-
- /*---------------------------------------------------------------------------*/
-
- void str_select_demo(void)
- {
- char *p;
-
- /* clear window 4 and demonstrate string selection */
-
- wclear();
- wtextattr(LCYAN|_MAGENTA);
- wputs("\n The wsseldef() and wsselget() "
- "\n functions allow you to select a "
- "\n string by using the arrow keys.");
- wcenters(5,YELLOW|BLINK|_MAGENTA,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(5,_MAGENTA,spaces);
- wgotoxy(6,1);
- wtextattr(LGREEN|_MAGENTA);
- wprintf("Select printer device: ");
- wsseldef("PRN");
- wsseldef("LPT1");
- wsseldef("LPT2");
- wsseldef("COM1");
- wsseldef("COM2");
- wsseldef("COM3");
- wsseldef("COM4");
- setcursz(6,7);
- p=wsselget(YELLOW|_MAGENTA);
- setcursz(32,0);
- if(p==NULL) exit_prog();
- wtextattr(LRED|_MAGENTA);
- wprintf("\n\n You selected: %s",p);
- delay_(18);
- }
-
- /*---------------------------------------------------------------------------*/
-
- void text_line_demo(void)
- {
- /* clear window 4 and demonstrate text line drawing */
-
- wclear();
- wsize(22,78);
- wtextattr(LGREEN|_MAGENTA);
- wputs("\n The whline() & wvline() functions"
- "\n are used for drawing 'smart' text"
- "\n lines which will even make their "
- "\n own corners and intersections! ");
- wcenters(6,YELLOW|BLINK|_MAGENTA,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(6,_MAGENTA,spaces);
- wtextattr(LCYAN|_MAGENTA);
- whline(6,6,24,3);
- delay_(18);
- wvline(6,6,4,3);
- delay_(18);
- whline(10,6,24,3);
- delay_(18);
- wtextattr(LBLUE|_MAGENTA);
- if(bioskey(1)) { /* check for keypress */
- if(getch()==ESC) exit_prog();
- }
- wvline(6,30,5,3);
- delay_(18);
- wvline(6,18,5,3);
- delay_(18);
- whline(7,6,25,3);
- delay_(18);
- wtextattr(LGREEN|_MAGENTA);
- if(bioskey(1)) { /* check for keypress */
- if(getch()==ESC) exit_prog();
- }
- whline(9,6,25,3);
- delay_(18);
- wvline(6,11,5,3);
- delay_(18);
- wvline(6,23,5,3);
- delay_(18);
- wtextattr(LMAGENTA|_MAGENTA);
- whline(8,6,25,3);
- delay_(18);
- }
-
- /*---------------------------------------------------------------------------*/
-
- void titl_resz_demo(void)
- {
- /* open demo window 2 and demonstrate window titles
- and resizing of windows */
-
- w[2]=wopen(5,20,19,45,3,LCYAN|_GREEN,LCYAN|_GREEN);
- if(!w[2]) error_exit();
- wtextattr(WHITE|_GREEN);
- wputs("\n The wtitle() function"
- "\n allows you to give a"
- "\n window a title.");
- wcenters(5,YELLOW|BLINK|_GREEN,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(5,_GREEN,spaces);
- wtitle("[ My Title ]",TLEFT,LCYAN|_GREEN);
- delay_(18);
- wtitle("[ My Title ]",TRIGHT,LCYAN|_GREEN);
- delay_(18);
- wtitle("[ My Title ]",TCENTER,LCYAN|_GREEN);
- wtextattr(LGREEN|_GREEN);
- wputs("\n\n\n The wsize() function"
- "\n allows you to resize"
- "\n the active window.");
- wcenters(10,YELLOW|BLINK|_GREEN,pressakey);
- if(waitkey()==ESC) exit_prog();
- wcenters(10,_GREEN,spaces);
- wsize(19,60);
- delay_(12);;
- wsize(19,75);
- delay_(12);;
- wsize(24,75);
- delay_(12);;
- wsize(24,60);
- delay_(12);;
- wsize(24,45);
- delay_(12);;
- wsize(19,45);
- delay_(12);;
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* this function updates the on-screen clock in the pull-down demo */
-
- void update_clock(void)
- {
- printsd(0,70,LGREEN,systime(1));
- }
-
- /*---------------------------------------------------------------------------*/
-
- void wrap_up(void)
- {
- int ch;
-
- /* close all windows except window 0 */
-
- while(_wtotal>1) {
- if(bioskey(1)) {
- if(getch()==ESC) exit_prog();
- }
- wclose();
- delay_(6);
- }
-
-
- /* list other features of CXL */
-
- wclear();
- wputs(" Other features of CXL include:\n");
- wtextattr(LGREEN|_RED);
- wputs("\n - EGA 43 & VGA 50 line modes"
- "\n - expanded memory usage"
- "\n - screen/window swapping to disk"
- "\n - advanced string manipulation"
- "\n - equipment detection"
- "\n - mouse functions"
- "\n - printer functions");
- wprints(8,26,YELLOW|BLINK|_RED,pressakey);
- if(waitkey()==ESC) exit_prog();
- wprints(8,26,_RED,spaces);
-
- /* get response from the keyboard, controlling input */
-
- wclear();
- if(wmove(7,19)) error_exit();
- wgotoxy(3,11);
- wtextattr(WHITE|_RED);
- wputs("View demo again? ");
- setcursz(7,1); /* turn cursor on */
- clearkeys(); /* clear keyboard buffer */
- ch=wgetchf("YyNn",'Y'); /* get keyboard response */
- setcursz(32,0); /* turn cursor back off */
- if(ch==ESC) exit_prog(); /* see if Esc was pressed */
- wclose();
- if(ch=='Y'||ch=='y') {
- }
- else {
- exit_prog();
- }
- }
-
-