home *** CD-ROM | disk | FTP | other *** search
- // Object Windows demo program demo.cpp
- // Copyright 1991 (c), Lake View Software
- // 4321 Harborough Rd.
- // Columbus, OH 43220
- // 1/2/91
-
- #include "winmenu.hpp" // Menu class header file
- #include "winpick.hpp" // Pick-List class header file
- #include <stdlib.h>
- #include <dos.h>
- #include <alloc.h>
-
- WinObj win1,win2; // Some global window objects, These will be the random windows
-
- // Declare internal functions
- int v_salary(void *num);
- int v_age(void *num);
- void rand_open (WinObj &w);
- void show_time();
- void move_windows(struct time t);
- void data_entry();
- void moving_windows();
- void random_windows();
- void menu_demo();
- void menu_demo2();
- void pick_demo();
- void help();
- void logo();
-
-
- void main(int argc,char **argv)
- {
- int arg=0;
- while (++arg < argc) { // Parse the command line
- if (argv[arg][0]=='-' || argv[arg][0]=='/') {
- switch (argv[arg][1]) {
- case 'b': Win_bios(W_ON); // Turn on use of bios writes
- break;
- case 's': Win_snow(W_ON); // Turn on use of snow suppression
- break;
- case 'm': Win_mono(W_ON); // Force black & white only
- break;
- }
- }
- }
-
- randomize(); // Start random number generator
-
- // Turn clock on
- Win_setbkloop (show_time); // Set background keyboard loop
- // This will run the clock and move win1
- // & win2
-
- Win_setonkey (F1,help); // Set F1 to function help
-
- logo(); // display logo window
-
- WinMenu m; // create Main menu
- m.open (3,26,17,52,W_SOLID,_BLUE|LGREEN,_BLUE|LGREY);
- m.title ("[ Demo Menu ]");
- m.prompt (1,4,1,"Data entry");
- m.prompt (3,4,2,"Moving windows");
- m.prompt (5,4,3,"Random windows");
- m.prompt (7,4,4,"Menu demo");
- m.prompt (9,4,5,"Pick-List demo");
- m.prompt (11,4,0,"Quit");
-
- int choice = 1; // start with menu selection ret_val = 1
- while (choice != 0) {
- choice = m.read(choice); // get menu selection
- m.hide(); // hide the menu window
- switch (choice) {
- case 1: data_entry();
- break;
- case 2: moving_windows();
- break;
- case 3: random_windows();
- break;
- case 4: menu_demo();
- break;
- case 5: pick_demo();
- break;
- }
- }
- // all windows will close automatically with there destructors
- }
-
- //*********************Pick-List Demo************************
-
- static char *list[] = { "January", "February",
- "March", "April",
- "May", "June",
- "July", "August",
- "September", "October",
- "November", "December", 0 };
-
- void pick_demo()
- {
- WinPick pl;
- pl.open (6,33,11,45,W_DOUSIN,_BLUE|WHITE,_BLUE|GREEN); // open pick window
- pl.shadow();
- pl.title ("Pick-List");
- pl.prompt (list); // assign a list
- int choice = pl.read(); // get user selection, closes window when finished
-
- // Display the results of the pick.
- if (choice != W_ESCAPE) {
- WinObj w;
- w.open (6,23,11,53,W_DOUSIN,_BLUE|GREEN,_BLUE|WHITE);
- w.shadow();
- w.printf (1,1,"You picked ");
- w.set_attr(_BLUE|YELLOW);
- w.printf ("%s.",list[choice]);
- w.set_attr(_BLUE|LGREY);
- w.printf (3,1,"Press any key to continue.");
- w.get_key();
- }
- }
-
- //**********************Menu Demo****************************
- // First level of a lotus style menu
- void menu_demo()
- {
- WinMenu m; // Create a menu object
- m.open (1,0,1,79,W_NOBORDER,_BLUE|WHITE); // init the window
- m.message_line(2); // Set message line to 2
-
- // Declare some menu selections
- m.prompt (0, 1,1,"Worksheet","Global, Column, Status, Delete");
- m.prompt (0,12,2,"Range","Format, Label, Erase, Name, Justify, Prot");
- m.prompt (0,19,3,"Copy","Copy a cell or range of cells");
- m.prompt (0,25,4,"Move","Move a cell or range of cells");
- m.prompt (0,31,5,"File","Retrieve, Save, Combine, Xtract...");
- m.prompt (0,37,6,"Print","Print a worksheet to a printer or file");
- m.prompt (0,44,0,"Quit","Quit the menu demo");
-
- int choice=1;
- while (choice != 0) {
- choice = m.read(choice); // Get a menu selection
- switch (choice) {
- case 1:
- menu_demo2(); // Goto next menu level
- break;
- case 2:
- break;
- }
- }
- // Menu object will destruct and close automatically.
- }
-
- void menu_demo2() // Second level of a lotus style menu
- {
- WinMenu m;
- m.open (1,0,1,79,W_NOBORDER,_BLUE|WHITE);
- m.message_line(2); // Set message line to 1
- m.prompt (0, 1,1,"Global","Global functions");
- m.prompt (0, 9,2,"Column","Delete, Insert");
- m.prompt (0,17,3,"Status","Display worksheet status");
- m.prompt (0,25,4,"Delete","Delete the entire worksheet");
- m.prompt (0,33,0,"Quit","Quit to the main menu");
- int choice=1;
- while (choice != 0) {
- choice = m.read(choice);
- switch (choice) {
- case 1:
- break;
- case 2:
- break;
- }
- }
- }
-
- //*************************Moving windows Demo*************************
- // Open the moving windows
- void moving_windows()
- {
- // Windows will open or close with each call
- if (!win1.is_open()) {
- win1.open (1,1,10,25,W_DOUBLE,_CYAN|BLACK,_CYAN|BLUE);
- win1.shadow();
- win1.title ("[ Moving Window 1 ]");
- win1.printf("Here is some text in a moving window.");
- win2.open (1,54,10,79,W_SOLID,_GREEN|BLACK,_GREEN|WHITE);
- win2.shadow();
- win2.title ("[ Moving Window 2 ]");
- win2.printf("Here is some text in the second moving window.");
- }
- else {
- win1.close();
- win2.close();
- }
- }
-
- // Function to move the random windows every second
- // This function is called by the clock function with the current time
- void move_windows(struct time t)
- {
- static int x=1,y=1,sec_hold=0;
- if (!win1.is_open())
- return;
-
- if (sec_hold != t.ti_sec) { // only move once a second
- sec_hold = t.ti_sec;
- x+=6; y+=2;
- if (win1.move(y,x) != W_OK) { // test for error on window move
- x=0; // this will tell us when we reach the edge
- y=0;
- win1.move(y,x);
- }
- // randomly move the second window
- win2.move(random(14),random(54));
- }
- }
-
- //**********************Random Windows Demo***************************
- void random_windows()
- {
- WinObj win1,win2,win3,win4,win5; // Create some random windows
- rand_open(win1);
- delay(250); // Pause for effect
- rand_open(win2);
- delay(250); // Pause for effect
- rand_open(win3);
- delay(250); // Pause for effect
- rand_open(win4);
- delay(250); // Pause for effect
- rand_open(win5);
- delay(250); // Pause for effect
- win1.clr_win();
- win1.printf("Press any key to continue.");
- win1.get_key(); // Wait for a key press
- }
-
- // Function to open random windows on the screen
- void rand_open (WinObj &w)
- {
- static cnt=0;
- int sr,er,sc,ec;
- int color,bcolor,btype;
- sr = random(12);
- sc = random(40);
- er = sr + 10 + random(12-sr);
- ec = sc + 15 + random(63-sc);
- color = random(8)*16 + random(16);
- bcolor = random(8)*16 + random(16);
- btype = random(6);
- w.open (sr,sc,er,ec,btype,color,bcolor);
- w.shadow();
- w.title ("[ Random Window ]");
- w.printf ("This is random window #(%d)",++cnt);
- }
-
- //************************Data Entry Demo********************************
-
- void data_entry()
- {
- // Declare data variables.
- static char lastname[16]="",firstname[16]="";
- static char add1[31]="",add2[31]="";
- static char city[16]="",state[3]="",zip[11]="";
- static char phone[15] = "";
- static char start[9]="";
- static double salary=0;
- static long age=0;
-
- WinObj w(80,80); // Create the main entry window
- w.open(2,12,12,60,W_DOUBLE,_BLUE|WHITE,_BLUE|YELLOW);
- w.shadow();
- w.title("[ Data Entry ]");
-
- w.printf(1,1," Last Name:");
- w.printf(2,1," First Name:");
- w.printf(4,1," Address:");
- w.printf(6,1,"City/St/Zip:");
- w.printf(6,29,",");
- w.printf(8,1," Phone:");
- w.printf(10,1," Start Date:");
- w.printf(12,1," Age:");
- w.printf(14,1," Salary:");
-
- str_setsz(lastname,15); // We won't use a picture for these
- str_setsz(firstname,15); // variables, so we must give the initial
- str_setsz(add1,30); // value some size.
- str_setsz(add2,30);
- str_setsz(city,15);
- str_setsz(state,2);
-
- w.get (1,14,lastname,'F'); // force first character of these fields
- w.get (2,14,firstname,'F'); // to be upper case with a 'F'orce style.
- w.get (4,14,add1,'F');
- w.get (5,14,add2,'F');
- w.get (6,14,city,'F');
-
- w.get (6,31,state,'U'); // force state to be uppercase
- w.get (6,35,zip,"99999-9999"); // use a picture for a zip code
-
- w.get (8,14,phone,'P'); // get a phone style
- w.get (10,14,start,'D'); // get a date style
- w.get (12,14,age,3); // Limit age to 3 places
- w.valid (v_age); // check age to be over 15
-
- w.get (14,14,salary,9); // limit salary to hundred thousands
- w.valid (v_salary); // check to be sure salary is over $10,000
-
- w.read(); // read the gets
- }
-
- int v_salary(void *num) // Valid function for salary
- {
- if (* (double *)num >= 10000) // Must first conver num to a double type
- return 1; // pointer. if >= 10,000 return true.
-
- WinObj error;
- error.open (1,12,3,39,W_SINGLE,_RED|WHITE,_RED|YELLOW);
- error.shadow();
- error.title ("[ Error ]");
- error.printf (" Salary must be > 10,000! ");
- Win_beep();
- error.get_key();
- // no need to close the window the distructor will do this for you
- return 0; // return false.
- }
-
- int v_age(void *num) // Valid function for age
- {
- if (* (int *)num > 15) // Must first conver age to a integer type
- return 1; // pointer. if > 15 return true.
-
- WinObj error;
- error.open (1,12,3,39,W_SINGLE,_RED|WHITE,_RED|YELLOW);
- error.shadow();
- error.title ("[ Error ]");
- error.printf (" Age must be > 15 ");
- Win_beep();
- error.get_key();
- // no need to close the window the distructor will do this for you
- return 0; // return false.
- }
-
- //**************************Clock function*******************************
-
- void show_time() // Show time in upper left corner of screen
- {
- static struct time t;
- static WinObj clock_win; // create a static window object
- static unsigned char hold;
-
- if (!clock_win.is_open()) // open small clock window once
- clock_win.open(0,0,1,7,W_NOBORDER,_BLACK|WHITE);
-
- // First show the clock
- gettime(&t);
- if (hold != t.ti_sec) {
- hold = t.ti_sec;
- clock_win.printf (0,0,"%02d:%02d:%02d",t.ti_hour,t.ti_min,t.ti_sec);
- clock_win.printf (1,0,"%ld",(long )coreleft()); // show free mem
- }
-
- move_windows(t); // Move the random windows
- }
-
- //**********************Help Function***********************************
- void help()
- {
- static int is_active=0;
- int old_x,old_y;
- if (is_active)
- return;
- is_active++;
- Win_getxy(&old_y,&old_x); // Save current cursor position
-
- WinObj help;
- help.open (1,11,21,67,W_SINGLE,_LGREY|BLACK,_LGREY|WHITE);
- help.title (" Help Window ");
- help.center(1,"Data Entry Keys");
- help.printf(3,1,"/ arrows Move cursor to next/prev field.");
- help.printf(4,1,"%c/%c arrows Move cursor to next/prev column.",26,27);
- help.printf(5,1,"Ctrl_%c/%c arrows Pan window right/left one column.",26,27);
- help.printf(6,1,"Ctrl_end/home Pan window down/up one row.");
- help.printf(7,1,"PgDn Exit read mode.");
- help.printf(8,1,"Esc Quit read mode.");
- int hold_attr = help.set_attr(_LGREY|WHITE);
- help.center(10,"Non Picture Gets Only");
- help.set_attr(hold_attr);
- help.printf(11,1,"Insert Toggle insert/overtype mode.");
- help.printf(12,1,"Delete Delete character under cursor.");
- help.printf(13,1,"Backspace Delete previous character.");
- hold_attr = help.set_attr(_LGREY|RED);
- help.center(17,"Copyright (c) 1991, Lake View Software");
- help.set_attr(hold_attr);
- help.center(18,"Press any key to exit.");
- help.get_key();
-
- Win_gotoxy(old_y,old_x); // Restore cursor position
- is_active = 0; // turn off active flag
- }
-
-
- //*****************************Logo*****************************************
- void logo()
- {
- static WinObj l;
- l.open (20,19,24,59,W_SOLID,_BLACK|WHITE,_BLACK|YELLOW);
- l.title (" Object Windows ");
- l.center(0,"The C++ window class system");
- l.center(1,"Copyright (c) 1991");
- l.center(2,"Lake View Software");
- }
-