home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
VRAC
/
ZFRMS11D.ZIP
/
ZFORMS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-06
|
16KB
|
364 lines
/* Z-Forms demo source code for version 1.1 */
#include "zforms.h"
#include <stdlib.h>
/* window for foreground/background demo */
WINDOW *pBackWin;
/*****************************************************************************/
/* A demonstration of the TTY functions. Any keypresses are written */
/* into the window in TTY mode, with auto-scrolling */
void TTYDemo(int Item) {
WINDOW TTYWin = {
0, 10, 70, NULL, NULL, 5, 8, 0x0720, BS_SINGLELINE, BRIGHTWHITE, BLACK,
DS_LOWERRIGHT, DARKGREY, "TTY Test Window",
"Type any data into the window, F1 to clear, or Escape to exit"
};
WINDOW *pTTYWin;
int Key=0;
/* open the window */
pTTYWin = Z_OpenWindow(&TTYWin);
/* position the cursor */
Z_SetCursor(pTTYWin, 1, 1);
/* get data for the window */
while(Key != k_Esc) {
Key = Z_GetKey();
if(Key == k_F1) {
Z_ClearWindow(pTTYWin);
Z_SetCursor(pTTYWin, 1, 1);
}
else Z_CharOverTTY(pTTYWin, (char)Key);
}
/* close the window and exit */
Z_CloseWindow(pTTYWin);
}
/*****************************************************************************/
/* A demonstration of the updating of background windows. The function */
/* writes characters into the background window, which scrolls behind the */
/* foreground window */
void BackgroundFunc(void) {
static unsigned char i=0x20;
int j;
char String[60];
/* build string to display */
for(j=0;j<58;j++) {
String[j] = i++;
if(i >=127) i = 0x20;
}
String[j] = 0;
/* display it and scroll */
Z_TextOver(pBackWin, String, 1, 8);
Z_ScrollUp(pBackWin, 1);
}
/*****************************************************************************/
/* A demonstration of the updating of background windows, and background */
/* processes. The function sets the packground process, which writes */
/* characters into the background window, which scrolls behind the */
/* foreground window */
void BackgroundDemo(int Item) {
WINDOW BackWin = {
0, 10, 60, NULL, NULL, 10, 8, 0x2720, BS_SINGLELINE, BLACK, GREEN,
DS_LOWERRIGHT, DARKGREY, NULL, "Background Window"
};
WINDOW ForeWin = {
0, 7, 40, NULL, NULL, 5, 5, 0x1720, BS_DOUBLELINE, YELLOW, BLUE,
DS_LOWERRIGHT, DARKGREY, "Foreground Window",
"Press Escape to end the test"
};
static char ForeResp[20] = " ";
PROMPT ForePrompt[] = {
ForeResp, "Prompt: ", "##########", 10, 8, 4, YELLOW, BLUE,
BRIGHTWHITE, BLUE, BLACK, CYAN, NULL, NULL,
NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL};
int ForeExit[] = { k_Esc, k_NoKey };
WINDOW *pForeWin;
int Key=0;
/* open the window */
pBackWin = Z_OpenWindow(&BackWin);
pForeWin = Z_OpenWindow(&ForeWin);
/* put some text on the forground window */
Z_TextOut(pForeWin, "This window is the foreground window", 2, 2,
BRIGHTWHITE, BLUE);
/* position the cursor */
Z_SetCursor(pBackWin, 1, 1);
/* set the background function */
Z_SetBackgroundProcess(BackgroundFunc, 100);
/* get a key press */
/* handle the data entry fields */
Key = Z_HandleInputs(pForeWin, NULL, ForePrompt, ForeExit);
/* reset background process */
Z_SetBackgroundProcess(NULL, 50);
/* close the window and exit */
Z_CloseWindow(pForeWin);
Z_CloseWindow(pBackWin);
}
/*****************************************************************************/
/* Test the speed of window drawing. This function displays a 15X60 window, */
/* then alternately displays and removes it when a key is pressed. */
void SpeedDemo(int Item) {
WINDOW SecondWin = {
0, 15, 60, NULL, NULL, 10, 3, 0x2720, BS_SINGLELINE, BLACK, GREEN,
DS_LOWERRIGHT, DARKGREY, "Test Window", NULL
};
WINDOW InstructWin = {
0, 2, 56, NULL, NULL, 12, 19, 0x1E20, BS_DOUBLELINE, YELLOW, BLUE,
DS_LOWERRIGHT, DARKGREY, "Window Speed Demo",
"Press Any Key To Open/Close Window, or Escape To Exit"
};
WINDOW *pSecWin, *pInstructWin;
int Key=0;
/* open both windows */
pSecWin = Z_OpenWindow(&SecondWin);
pInstructWin = Z_OpenWindow(&InstructWin);
/* push one window, then pop it */
while(Key != k_Esc) {
Key = Z_GetKey();
if(pSecWin->fShown) Z_HideWindow(pSecWin);
else Z_ShowWindow(pSecWin);
}
/* close both windows and exit */
Z_CloseWindow(pInstructWin);
Z_CloseWindow(pSecWin);
}
/*****************************************************************************/
/* This is the verification function for the third line of the prompt. */
/* The response must begin with an 'A' in order to be verified */
int VerifyPrompt3(char *Line) {
if(Line[0] == 'A') return(1);
else {
Z_InformUser("Invalid Response", "This response must begin with 'A'",
" <OK> ", NULL);
return(0);
}
}
/*****************************************************************************/
/* A demo of Prompt handling */
void PromptDemo(int Item) {
WINDOW PromptWin = {
0, 10, 60, NULL, NULL, 10, 8, 0x1020, BS_DOUBLELINE, YELLOW, BLUE,
DS_LOWERRIGHT, DARKGREY, "Data Entry Demo", "F2-Exit Esc-Abort" };
WINDOW *pPromptWin;
WINDOW PromptHintWin = {
0, 1, 58, NULL, NULL, 11, 16, 0x1020, BS_NOBORDER, BLACK, BLACK,
DS_NONE, BLACK, NULL, NULL };
WINDOW *pPHWin;
int Key;
static char Response1[20] = "", Response2[15] = "", Response3[15] = "";
PROMPT TestPrompt[] = {
Response1, "Numeric Prompt: ", "(999) 999-9999", 14, 15, 2, YELLOW, BLUE,
BRIGHTWHITE, BLUE, BLACK, CYAN, NULL,
" This field will accept only numbers ",
Response2, "Upper Case Prompt: ", "UUUUUUUUUU", 10, 12, 4, YELLOW, BLUE,
YELLOW, BLUE, BLACK, CYAN, NULL,
" This prompt will accept only upper case letters ",
Response3, "Any Data: ", "##########", 10, 21, 6, YELLOW, BLUE,
YELLOW, BLUE, BLACK, CYAN, VerifyPrompt3,
" This prompt will accept any data starting with 'A'",
NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL};
int PromptExit[] = { k_F2, k_Esc, k_NoKey };
/* open prompt window */
pPromptWin = Z_OpenWindow(&PromptWin);
pPHWin = Z_OpenWindow(&PromptHintWin);
/* handle the data entry fields */
Key = Z_HandleInputs(pPromptWin, pPHWin, TestPrompt, PromptExit);
/* close the window and exit */
Z_CloseWindow(pPHWin);
Z_CloseWindow(pPromptWin);
}
/*****************************************************************************/
/* A demo of a simple picklist */
void TestPickList(void) {
PICKLIST TestPL = {
10, 5, 10, 60, 58, PLF_VERTSCROLL, YELLOW, BLUE, BLACK, CYAN,
BS_SINGLELINE, YELLOW, BLUE, 0x1020, DS_LOWERRIGHT, DARKGREY,
"PickList Demonstration" };
PICKLIST *pPL;
PICKLIST_ITEM *pPLI;
/* test the picklist */
pPL = &TestPL;
Z_AddPickListItem(pPL, "Line 1");
Z_AddPickListItem(pPL, "Line 2");
Z_AddPickListItem(pPL, "Line 3");
Z_AddPickListItem(pPL, "Line 4");
Z_AddPickListItem(pPL, "Line 5");
Z_AddPickListItem(pPL, "Line 6");
Z_AddPickListItem(pPL, "Line 7");
Z_AddPickListItem(pPL, "Line 8");
Z_AddPickListItem(pPL, "Line 9");
Z_AddPickListItem(pPL, "Line 10");
Z_AddPickListItem(pPL, "Line 11");
Z_AddPickListItem(pPL, "Line 12");
Z_AddPickListItem(pPL, "Line 13");
Z_AddPickListItem(pPL, "Line 14");
pPLI = Z_HandlePickList(pPL);
if(pPLI) Z_InformUser("PickList Choice", pPLI->ItemText, " <OK> ", NULL);
}
/*****************************************************************************/
/* Main window and main menu processing */
/* There are only 5 line of code in this function. The rest is structure */
/* initialization. The other functions in the code are called by Z-Forms as */
/* the result of some user action */
void main(void) {
/* main window, covering the whole 80X25 display */
WINDOW MainWin = {
0, 25, 80, NULL, NULL, 0, 0, 0x03b0, BS_SINGLELINE, YELLOW, BLUE,
DS_NONE, 0, " Z-Forms Demonstration Program ",
"Complete Demo Source in ZFORMS.C" };
WINDOW *pWin;
static int OneOfVar=0, CheckVar=0;
static char DataVar[35] = " ";
#ifdef __Z_INIT_EXT__
/* these initializations are for MSC6 and other compilers that allow */
/* unsized array initialzations within a structure */
static MENU VertMenu = {
33, 2, 5, 20, 18, MMF_VERTMENU | MMF_USEHINT, BRIGHTWHITE, BLUE,
LT_RED, BLUE, BLUE, CYAN, WHITE, BLUE, 1, 23, 78, BS_SINGLELINE,
YELLOW, BLUE, 0, 0, NULL,
"TTY Demo", MIF_CALLFUNC, 'T', 0, 1, 1, (void *)TTYDemo,
" TTY demo with auto-scrolling ",
"Background Demo", MIF_CALLFUNC, 'B', 0, 1, 2, (void *)BackgroundDemo,
" Demo of background processes/windows",
"Nothing", MIF_CALLEXIT, 'N', 0, 1, 3, NULL,
" Dummy option does nothing ",
NULL, 0, 0, 0, 0, 0, NULL, "" };
static DIALOG TestDialog = {
10, 5, 13, 60, DBF_USEHINT, 0x1E20, YELLOW, BLUE, 11, 16, 58,
BS_DOUBLELINE, YELLOW, BLUE, DS_LOWERRIGHT, 0x8, "Test Dialog Box", NULL,
"This is a text control", CSF_TEXT, CSS_NOACTIVATE | CSS_CALLNOTHING,
0, 0, 20, 2, 1, 22, YELLOW, BLUE, CYAN, BLUE, NULL, NULL, NULL,
"Data Entry: ", CSF_DATAENTRY, CSS_ACTIVATE | CSS_CALLNOTHING,
k_Alt_D, 0, 3, 4, 0, 0x1E0A, WHITE, BLUE, CYAN, BLUE, DataVar,
"This is a data entry control", NULL,
"Checkbox", CSF_CHECKBOX, CSS_ACTIVATE | CSS_CALLNOTHING, k_Alt_C, 3,
42, 4, 0, 0, WHITE, BLUE, BRIGHTWHITE, BLUE, &CheckVar,
"This is a check box control", NULL,
"OneOfButton1", CSF_ONEOFBUTTON, CSS_ACTIVATE | CSS_CALLNOTHING,
k_Alt_O, 0, 22, 6, 0, 0, WHITE, BLUE, BRIGHTWHITE, BLUE, &OneOfVar,
"This is a group of one-of buttons", NULL,
"OneOfButton2", CSF_ONEOFBUTTON, CSS_ACTIVATE | CSS_CALLNOTHING,
k_Alt_N, 1, 22, 7, 0, 1, WHITE, BLUE, BRIGHTWHITE, BLUE, &OneOfVar,
"This is a group of one-of buttons", NULL,
" <Exit> ", CSF_BUTTON, CSS_ACTIVATE | CSS_EXIT, k_Esc, 0, 26, 9, 0,
0, WHITE, RED, BRIGHTWHITE, RED, NULL, "This is a button control",
NULL,
NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, "", NULL};
static MENU MainMenu = {
1, 1, 1, 78, 0, MMF_HORIZMENU | MMF_USEHINT, BRIGHTWHITE, BLUE,
LT_RED, BLUE, BLUE, CYAN, YELLOW, BLUE, 1, 23, 78, BS_NOBORDER,
BLACK, BLACK, 0, 0, NULL,
"Speed Demo", MIF_CALLFUNC, 'S', 0, 3, 0, (void *)SpeedDemo,
" Display and hide a window ",
"Data Entry", MIF_CALLFUNC, 'D', 0, 18, 0, (void *)PromptDemo,
" Demonstration of Data Entry fields ",
"Menu", MIF_CALLMENU, 'M', 0, 32, 0, (void *)&VertMenu,
" Demonstration of a Vertical Menu ",
"Dialog Box", MIF_CALLDIALOG, 'I', 1, 40, 0, (void *)&TestDialog,
" Demonstration of a Dialog Box ",
"PickList", MIF_CALLFUNC, 'P', 0, 54, 0, (void *)&TestPickList,
" Demonstration of a Pick List ",
"Exit", MIF_CALLEXIT, 'X', 1, 70, 0, NULL,
" Exit the Z-Forms demo ",
NULL, 0, 0, 0, 0, 0, NULL, "" };
#else
/* these initializations are for those compilers which do not allow */
/* unsized array initializations in structures */
static MENU_ITEM VertMenuItem[] = {
"TTY Demo", MIF_CALLFUNC, 'T', 0, 1, 1, (void *)TTYDemo,
" TTY demo with auto-scrolling ",
"Background Demo", MIF_CALLFUNC, 'B', 0, 1, 2, (void *)BackgroundDemo,
" Demo of background processes/windows",
"Nothing", MIF_CALLEXIT, 'N', 0, 1, 3, NULL,
" Dummy option does nothing ",
NULL, 0, 0, 0, 0, 0, NULL, "" };
static MENU VertMenu = {
33, 2, 5, 20, 18, MMF_VERTMENU | MMF_USEHINT, BRIGHTWHITE, BLUE,
LT_RED, BLUE, BLUE, CYAN, WHITE, BLUE, 1, 23, 78, BS_SINGLELINE,
YELLOW, BLUE, 0, 0, NULL, VertMenuItem };
static DLG_CONTROL TestDialogControl[] = {
"This is a text control", CSF_TEXT, CSS_NOACTIVATE | CSS_CALLNOTHING,
0, 0, 20, 2, 1, 22, YELLOW, BLUE, CYAN, BLUE, NULL, NULL, NULL,
"Data Entry: ", CSF_DATAENTRY, CSS_ACTIVATE | CSS_CALLNOTHING,
k_Alt_D, 0, 3, 4, 0, 0x1E0A, WHITE, BLUE, CYAN, BLUE, DataVar,
"This is a data entry control", NULL,
"Checkbox", CSF_CHECKBOX, CSS_ACTIVATE | CSS_CALLNOTHING, k_Alt_C, 3,
42, 4, 0, 0, WHITE, BLUE, BRIGHTWHITE, BLUE, &CheckVar,
"This is a check box control", NULL,
"OneOfButton1", CSF_ONEOFBUTTON, CSS_ACTIVATE | CSS_CALLNOTHING,
k_Alt_O, 0, 22, 6, 0, 0, WHITE, BLUE, BRIGHTWHITE, BLUE, &OneOfVar,
"This is a group of one-of buttons", NULL,
"OneOfButton2", CSF_ONEOFBUTTON, CSS_ACTIVATE | CSS_CALLNOTHING,
k_Alt_N, 1, 22, 7, 0, 1, WHITE, BLUE, BRIGHTWHITE, BLUE, &OneOfVar,
"This is a group of one-of buttons", NULL,
" <Exit> ", CSF_BUTTON, CSS_ACTIVATE | CSS_EXIT, k_Esc, 0, 26, 9, 0,
0, WHITE, RED, BRIGHTWHITE, RED, NULL, "This is a button control",
NULL,
NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, "", NULL};
static DIALOG TestDialog = {
10, 5, 13, 60, DBF_USEHINT, 0x1E20, YELLOW, BLUE, 11, 16, 58,
BS_DOUBLELINE, YELLOW, BLUE, DS_LOWERRIGHT, 0x8, "Test Dialog Box",
NULL, TestDialogControl };
static MENU_ITEM MainMenuItem[] = {
"Speed Demo", MIF_CALLFUNC, 'S', 0, 3, 0, (void *)SpeedDemo,
" Display and hide a window ",
"Data Entry", MIF_CALLFUNC, 'D', 0, 18, 0, (void *)PromptDemo,
" Demonstration of Data Entry fields ",
"Menu", MIF_CALLMENU, 'M', 0, 32, 0, (void *)&VertMenu,
" Demonstration of a Vertical Menu ",
"Dialog Box", MIF_CALLDIALOG, 'I', 1, 40, 0, (void *)&TestDialog,
" Demonstration of a Dialog Box ",
"PickList", MIF_CALLFUNC, 'P', 0, 54, 0, (void *)&TestPickList,
" Demonstration of a Pick List ",
"Exit", MIF_CALLEXIT, 'X', 1, 70, 0, NULL,
" Exit the Z-Forms demo ",
NULL, 0, 0, 0, 0, 0, NULL, "" };
static MENU MainMenu = {
1, 1, 1, 78, 0, MMF_HORIZMENU | MMF_USEHINT, BRIGHTWHITE, BLUE,
LT_RED, BLUE, BLUE, CYAN, YELLOW, BLUE, 1, 23, 78, BS_NOBORDER,
BLACK, BLACK, 0, 0, NULL, MainMenuItem};
#endif
/* open the main window */
pWin = Z_OpenWindow(&MainWin);
/* display the welcoming dialog box */
Z_Alert(ALERT_THREEBEEP);
Z_InformUser("Z-Forms V1.1", "Welcome to the Z-Forms Demo!",
"<Continue>", NULL);
/* display and handle the main menu */
Z_HandleMenu(&MainMenu);
/* close the main window and exit */
Z_Alert(ALERT_TWOTONES);
Z_CloseWindow(pWin);
Z_ClearScreen(' ', WHITE);
}