/* ------------------------------------------------------------------------ */
/*                                  demo.c                                  */
/*                       main demo of the SST toolkit                       */
/* ------------------------------------------------------------------------ */
#include <dos.h>
#include <stdio.h>
#include <string.h>
#include <mem.h>
#include <stdlib.h>
#include <conio.h>
#include <alloc.h>

#include "sstvid.h"
#include "sstkey.h"
#include "sstwin.h"
#include "sstmnu.h"
#include "ssthlp.h"
#include "sstedt.h"

/* ------------------------------------------------------------------------ */
/*                            functions prototypes                          */
/* ------------------------------------------------------------------------ */
void wtitles     (void);
void waccent	 (void);
void wfast	 (void);
void wmove	 (void);
void editor	 (void);
void entry	 (void);
void entryall    (void);
void video	 (void);
void lists	 (void);
void mainmenu	 (void);

static void help_date    (char *bf);
static void get_list     (int s);
static void help_state   (char *bf);

/* ------------------------------------------------------------------------ */
int randx(int min, int max)
{
    int x;

    while ( (x = rand() % max+1) < min);
    return(x);
}

/* ------------------------------------------------------------------------ */
/*                         demo on windows titles                           */
/* ------------------------------------------------------------------------ */
void wtitles(void)
{
	WINDOW *wnd;
	int t, c = 0;


	Hset("wtitles ", 20, 15);
	wnd = Westablish(5, 4, 5, 51);
	Wsetcolour(wnd,WIN_BORDER, LIGHTGRAY, WHITE, DIM);
	Wsetcolour(wnd,WIN_TITLE , LIGHTGRAY, RED,BRIGHT);
	Wsetcolour(wnd,WIN_ACCENT, GREEN,     BLACK, DIM);
	Wsetcolour(wnd,WIN_FACE,   LIGHTGRAY, BLACK, DIM);
	Wsettitle(wnd,"[Window Title Demo]",JUST_L);
	Wprintf(wnd,"\n    Window Titles may be modified at any time\n");
	Wprintf(wnd,"            and the title string may be \n");
	Wprintf(wnd,"          LEFT RIGHT or CENTRE  justified");
	Wshow(wnd);
	while (c != ESC)  {
	  if (kbhit())
		     c = kgetch();
	  delay(400);
	  t = randx(0,4);
	     while ( (t = randx(0,4)) == 3);
	  Wsettitle(wnd,"[Window Title Demo]",t);
	}
     Wdelete(wnd);
}

/* ------------------------------------------------------------------------ */
/*                         demo on windows borders                          */
/* ------------------------------------------------------------------------ */
void wborders(void)
{
	WINDOW *wnd;
	int t = 0, c = 0;


	Hset("wtitles ", 20, 15);
	wnd = Westablish(5, 4, 11, 60);
	Wsetcolour(wnd,WIN_BORDER, BLACK,     WHITE, BRIGHT);
	Wsetcolour(wnd,WIN_TITLE , BLACK,     CYAN,  BRIGHT);
	Wsetcolour(wnd,WIN_FACE,   LIGHTGRAY, BLACK, DIM);
	Wsettitle(wnd,"[Window Border Demo]",JUST_L);
	Wprintf(wnd,"      Window Borders may be modified at any time\n\n");
	Wprintf(wnd,"      BRD_SINGLE        - Single line border \n");
	Wprintf(wnd,"      BRD_DOUBLE        - Double line border \n");
	Wprintf(wnd,"      BRD_DOUBLETOP     - Single sides & Double top\n");
	Wprintf(wnd,"      BRD_DOUBLESIDES   - Single top & Double sides\n");
	Wprintf(wnd,"      BRD_SPACES        - Border made of spaces\n");
	Wprintf(wnd,"      BRD_NOBORDER      - No border, uses full window");
	Wshow(wnd);
	while (c != ESC)  {
	  if (kbhit())
		     c = kgetch();
	  delay(400);
	  t++;
	  if (t > 4)
	     t = 0;
	  Wsetborder(wnd,t);

	}
     Wdelete(wnd);
}

/* ------------------------------------------------------------------------ */
/*                          demo on windows colours                         */
/* ------------------------------------------------------------------------ */
void wcolours(void)
{
    WINDOW *wnd[3];
	int c = 0;
	int bg, fg;


	Hset("wtitles ", 20, 15);
	wnd[0] = Westablish(5, 4, 8, 30);
	wnd[1] = Westablish(45, 4, 8, 30);
	wnd[2] = Westablish(5, 14, 8, 30);
	Wsettitle(wnd[0],"[Window 0]",JUST_L);
	Wsettitle(wnd[1],"[Window 1]",JUST_C);
	Wsettitle(wnd[2],"[Window 2]",JUST_R);
	Wshow(wnd[0]);
	Wshow(wnd[1]);
	Wshow(wnd[2]);
	Wprintf(wnd[0],"Demo of Window\n");
	Wprintf(wnd[1],"Demo of Window\n");
	Wprintf(wnd[2],"Demo of Window\n");
	Wprintf(wnd[0],"FACE colour\n");
	Wprintf(wnd[1],"BORDER colour\n");
	Wprintf(wnd[2],"TITLE colour\n");
	while (c != ESC)  {
	  if (kbhit())
		     c = kgetch();
	  delay(400);
	  fg = randx(0,7);
	     while ( (bg = randx(0,7)) == fg);
	  Wsetcolour(wnd[0], WIN_FACE, fg, bg, BRIGHT);
	  fg = randx(0,7);
	     while ( (bg = randx(0,7)) == fg);
	  Wsetcolour(wnd[1], WIN_BORDER, fg, bg, BRIGHT);
	  fg = randx(0,7);
	     while ( (bg = randx(0,7)) == fg);
	  Wsetcolour(wnd[2], WIN_TITLE, fg, bg, BRIGHT);
	}

    Wdelete(wnd[0]);
    Wdelete(wnd[1]);
    Wdelete(wnd[2]);
}


char *cols[] = {
      "BLACK","BLUE","GREEN","CYAN","RED","MAGENTA","BROWN",
      "LIGHTGRAY","DARKGRAY","LIGHTBLUE","LIGHTGREEN",
      "LIGHTCYAN","LIGHTRED","LIGHTMAGENTA","YELLOW","WHITE"
};

/* ------------------------------------------------------------------------ */
/*                           demo on windows                                */
/* ------------------------------------------------------------------------ */
void windowsdemo(void)
{
    WINDOW *wnd;
    int cc,c;
    char **s;

    Hset("wtitles ", 20, 15);
    wnd = Westablish(1, 1, 4, 40);
    Wshow(wnd);
    for (cc = 1 ; cc < 8 ; cc++)  {
	s = cols;
	for (c = 1 ; c < 16 ; c++)  {
	       Wsetcolour(wnd, WIN_FACE, c, cc, DIM);
	       Wsetcolour(wnd, WIN_BORDER, c, cc, DIM);
	       Wsettitle(wnd, *++s,JUST_C);
	}
    }
    kgetch();
    Wdelete(wnd);
}

/* ------------------------------------------------------------------------ */
void waccent(void)
{
	WINDOW *wndA, *wndB, *wndC;
	int c;

	Hset("waccent ", 20, 15);
	wndA = Westablish(5, 5, 9, 28);
	wndB = Westablish(10, 3, 9, 24);
	wndC = Westablish(13, 8, 9, 31);
	Wsetcolour(wndA, WIN_ALL, RED, YELLOW, DIM);
	Wsetcolour(wndB, WIN_ALL, CYAN, YELLOW, DIM);
	Wsetcolour(wndC, WIN_ALL, LIGHTGRAY, YELLOW, DIM);
	Wshow(wndA);
	Wshow(wndB);
	Wshow(wndC);
	Wprintf(wndA, "\n\n Press A to promote me");
	Wprintf(wndB, "\n\n Press B to promote me");
	Wprintf(wndC, "\n\n Press C to promote me");
	do	{
		c = kgetch();
		switch (c)	{
			case 'a':	Wforefront(wndA);
						break;
			case 'b':	Wforefront(wndB);
						break;
			case 'c':	Wforefront(wndC);
						break;
			case 'A':	Wrear(wndA);
						break;
			case 'B':	Wrear(wndB);
						break;
			case 'C':	Wrear(wndC);
						break;
			default:	break;
		}
	} while (c != ESC);
	Wdelete(wndA);
	kgetch();
	Wdelete(wndC);
	kgetch();
	Wdelete(wndB);
}


#define MAXWINS    120

/* ------------------------------------------------------------------------ */
void wfast(void)
{
    int x, xx, y, yy ,l;
    int fg, bg;
    unsigned ram;
    char s[13];
    WINDOW *wnd[MAXWINS];

    Hset("wfast   ", 20, 15);
    for (l = 0 ; l < MAXWINS ; l++) {
	  ram = (unsigned) coreleft();
	  x = randx(0,67);
	  y = randx(0,21);
	  xx = randx(12,80-(x+1));
	  yy = randx(3,25-(y+1));
	  sprintf(s,"[Win %3d]",l);
	  if ((wnd[l] = Westablish(x, y, yy, xx)) == NULL)
	      break;                   /* break when no RAM free */
	  fg = randx(0,7);
	     while ( (bg = randx(0,7)) == fg);
	  Wsetcolour(wnd[l], WIN_ALL, fg, bg, BRIGHT);
	  Wsettitle(wnd[l],s,JUST_L);
	  Wsetborder(wnd[l],randx(0,4));
	  Wprintf(wnd[l],"%u bytes free.",ram);
	  Wshow(wnd[l]);
    }
    kgetch();
    Wdelete(wnd[l]);
    while(l--) {
	Wdelete(wnd[l]);
    }
}
#define  MAXWINS2    8

/* ------------------------------------------------------------------------ */
void wfast2(void)
{
      int x = 0, c = 0, a = 7;
      int l;
      char s[7];
      WINDOW *wnd[MAXWINS2];

      Hset("wfast   ", 20, 15);
      vblinkbit(0);
      for (l = 0 ; l < MAXWINS2 ; l++) 	{
		sprintf(s,"[Win %1d]",l);
		wnd[l] = Westablish(x, c, 4, 24);
		Wsetcolour(wnd[l], WIN_ALL, a++, BLACK, BRIGHT);
		Wsettitle(wnd[l],s,JUST_L);
		Wshow(wnd[l]);
		Wprintf(wnd[l],"Press +- to toggle\nblink bit.");
		c += 3;
		x += 8;
      }
      while ((c = kgetch()) != ESC)  {
	    switch (c)   {
	     case  '+'  :  vblinkbit(1);
			   break;
	     case  '-'  :  vblinkbit(0);
			   break;
	    }
      }

      while (l--)
		Wdelete(wnd[l]);
      vblinkbit(1);
}


/* ------------------------------------------------------------------------ */
/*                             demo on editor                               */
/* ------------------------------------------------------------------------ */
void editor(void)

#define LWID      (int)80
#define WHT       (int)14
#define PADHT          20

{
  char bf [PADHT] [LWID];
  char notefile [] = "test.txt";
  WINDOW *wnd;
  FILE *fp, *fopen();
  int i, ctr = 0;

	vshowcur();
	Hset("editor  ", 20, 15);
	setmem(bf, sizeof bf, ' ');
	if ((fp = fopen(notefile, "rt")) != NULL)	{
		while (fread(bf [ctr], LWID, 1, fp))
			ctr++;
		fclose(fp);
	}
	wnd = Westablish
		((80-(LWID+2))/2, (25-(WHT+2))/2, WHT+2, LWID+2);
	Wsetborder(wnd, 3);
	Wsettitle(wnd, "  Note Pad  ",JUST_C);
	Wsetcolour(wnd, WIN_ALL, BLUE, CYAN, DIM);
	Wsetcolour(wnd, WIN_ACCENT, CYAN, BLUE, DIM);
	Wsetcolour(wnd, WIN_FACE, BLUE, WHITE, DIM);
	Wshow(wnd);
	Eopen(wnd, (char*) bf, LWID * PADHT);
	Wdelete(wnd);
	ctr = PADHT;
	while (--ctr)	{
		for (i = 0; i < LWID; i++)
			if (bf [ctr] [i] != ' ')
				break;
		if (i < LWID)
			break;
	}
	fp = fopen(notefile, "w");
	for (i = 0; i < ctr+1; i++)
		fwrite(bf[i], LWID, 1, fp);
	fclose(fp);
}

struct {
	char name [31];
	char addr [41];
	char city [26];
	char state [3];
	char pcode [4];
	char amt [6];
	char dt [7];
	char phone [11];
} rcd;

char msk40     [] = "________________________________________";
char msk30     [] = "_______________________________";
char msk25     [] = "__________________________";
char mskamt    [] = "$___.__";
char mskdate   [] = "__/__/__";
char mskphone  [] = "(___) ___-____";
char mskst     [] = "___";
char mskpcode  [] = "____";

char *states[] = {
      "WA ","NT ","QLD","NSW","VIC","TAS","SA ",NULL,
};
static int c = 5;

/* ------------------------------------------------------------------------ */
/*                             select a state                               */
/* ------------------------------------------------------------------------ */
static void help_state(char *bf)

{
   WINDOW *wnd;
   char **s = states;

   if ((wnd = Westablish(58, 3, 9, 8)) == NULL)
       return;
   Wsettitle(wnd, "[States]", JUST_L);
   Wsetcolour(wnd,WIN_BORDER,LIGHTGRAY,BLACK,DIM);
   Wsetcolour(wnd,WIN_TITLE ,LIGHTGRAY,RED,DIM);
   Wsetcolour(wnd,WIN_ACCENT,GREEN,BLACK,DIM);
   Wsetcolour(wnd,WIN_FACE,LIGHTGRAY,BLACK,DIM);
   Wshow(wnd);
   while (*s)
	Wprintf(wnd, "\n%s",*s++);
   vhidecur();
   c = Wgetsel(wnd, c, "1234567");
   if (c)
       memmove(bf,*(states+c-1),3);
   Wdelete(wnd);
   vshowcur();
}

/* ------------------------------------------------------------------------ */
/*                         demo on entry fields                             */
/* ------------------------------------------------------------------------ */
void entry(void)
{
    WINDOW *wnd;
    FIELD *fld;

    vshowcur();
    Hset("eorder  ", 20, 15);
    wnd = Westablish(10, 5, 12, 56);
    Wsettitle(wnd, "[ Order Entry ]",JUST_C);
    Wsetfooter(wnd, "[ Footer ]",JUST_L);
    Wsetcolour(wnd, WIN_BORDER,  LIGHTGRAY, WHITE, BRIGHT);
    Wsetcolour(wnd, WIN_TITLE,   LIGHTGRAY, RED, DIM);
    Wsetcolour(wnd, WIN_FACE,    LIGHTGRAY, BLACK, DIM);
    Wsetcolour(wnd, WIN_ACCENT,  BLUE,      LIGHTGRAY, DIM);
    Wsetcolour(wnd, WIN_FLDFACE, GREEN    , BLACK,  DIM);
    Wshow(wnd);
    Wprompt(wnd, 1, 1, "Name    ");
    Wprompt(wnd, 1, 2, "Address ");
    Wprompt(wnd, 1, 3, "City    ");
    Wprompt(wnd, 1, 4, "State   ");
    Wprompt(wnd, 14, 4, "Post code ");
    Wprompt(wnd, 1, 6, "Amount  ");
    Wprompt(wnd, 1, 7, "Date    ");
    Wprompt(wnd, 1, 8, "Phone   ");
    Finittemplate(wnd);
    fld = Festablish(wnd, 9, 1, msk30, rcd.name, FLD_ALNUM,FLD_LJUST |
							   FLD_TOPROPER);
    fld = Festablish(wnd, 9, 2, msk40, rcd.addr, FLD_ALNUM,FLD_LJUST |
							   FLD_TOPROPER);
    fld = Festablish(wnd, 9 ,3, msk25, rcd.city, FLD_ALNUM,FLD_LJUST);
    fld = Festablish(wnd, 9, 4, mskst, rcd.state, FLD_ALNUM,FLD_LJUST |
							    FLD_TOUPPER);
    Fhelpfunc(fld, help_state,HELP_ALWAYS);
    fld = Festablish(wnd, 24, 4, mskpcode, rcd.pcode, FLD_INT,FLD_LJUST);
    fld = Festablish(wnd, 9, 6, mskamt, rcd.amt, FLD_CURR,FLD_ZFILL);
    fld = Festablish(wnd, 9, 7, mskdate, rcd.dt, FLD_DATE,FLD_LJUST);
    Fhelpfunc(fld, help_date,HELP_INITIAL);
    fld = Festablish(wnd, 9, 8,mskphone,rcd.phone, FLD_INT,FLD_LJUST);
    Fcleartemplate(wnd);
    Fdataentry(wnd,0);
    Wdelete(wnd);
}

/* ------------------------------------------------------------------------ */
/*                           provide today's date                           */
/* ------------------------------------------------------------------------ */
static void help_date(char *bf)
{
    struct date dat;

    getdate(&dat);
    sprintf(bf, "%02d%02d%02d",dat.da_day, dat.da_mon, dat.da_year % 100);
}

/* ------------------------------------------------------------------------ */
/*                         demo 2 on entry fields                           */
/* ------------------------------------------------------------------------ */
void entryall(void)
{

struct {
	char alphanum [10];
	char alpha [10];
	char digit [10];
	char ascii [10];
	char print [10];
	char xdigit [10];
	char lower [10];
	char upper [10];
	char date [10];
	char integer [4];
	char curr    [5];
} r;

char msk10  []    = "__________";
char msk4   []    = "____";
char mskcurr[]    = "$___.__";

	WINDOW *wnd;

	Hset("eall    ", 20, 15);
	wnd = Westablish(10, 5, 18, 50);
	Wsettitle(wnd, " Order Entry ",JUST_C);
	Wsetcolour(wnd, WIN_ALL, BLUE, CYAN, DIM);
	Wsetcolour(wnd, WIN_ACCENT, CYAN, BLACK, DIM);
	Wshow(wnd);
	Wprompt(wnd, 5, 2, "Alnum  :");
	Wprompt(wnd, 5, 3, "Alpha  :");
	Wprompt(wnd, 5, 4, "Digit  :");
	Wprompt(wnd, 5, 5, "Ascii  :");
	Wprompt(wnd, 5, 6, "Print  :");
	Wprompt(wnd, 5, 7, "XDigit :");
	Wprompt(wnd, 5, 8, "Lower  :");
	Wprompt(wnd, 5, 9, "Upper  :");
	Wprompt(wnd, 5, 10, "Date   :");
	Wprompt(wnd, 5, 11, "Int    :");
	Wprompt(wnd, 5, 12, "Curr   :");
	Finittemplate(wnd);
	Festablish(wnd, 15, 2,  msk10, r.alphanum, FLD_ALNUM,FLD_TOUPPER);
	Festablish(wnd, 15, 3,  msk10, r.alpha, FLD_ALNUM,FLD_TOLOWER);
	Festablish(wnd, 15, 4,  msk10, r.digit, FLD_DIGIT,JUST_R);
	Festablish(wnd, 15, 5,  msk10, r.ascii, FLD_ASCII,JUST_L);
	Festablish(wnd, 15, 6,  msk10, r.print, FLD_PRINT,0);
	Festablish(wnd, 15, 7,  msk10, r.xdigit, FLD_XDIGIT,0);
	Festablish(wnd, 15, 8,  msk10, r.lower, FLD_ALNUM,FLD_TOLOWER);
	Festablish(wnd, 15, 9,  msk10, r.upper, FLD_ALNUM,FLD_TOUPPER);
	Festablish(wnd, 15, 10, msk10, r.date, FLD_DATE,0);
	Festablish(wnd, 15, 11, msk4,  r.integer, FLD_INT,0);
	Festablish(wnd, 15, 12, mskcurr,  r.curr, FLD_CURR,0);
	Fcleartemplate(wnd);
	Fdataentry(wnd,0);
	Wdelete(wnd);
}

/* ------------------------------------------------------------------------ */
/*                        show how a window can be moved                    */
/* ------------------------------------------------------------------------ */
void wmove(void)
{
	WINDOW *wndA, *wndB, *wndC;
	int c;

	Hset("wmove   ", 20, 15);
	wndA = Westablish(5, 5, 9, 31);
	wndB = Westablish(10, 3, 9, 29);
	wndC = Westablish(13, 8, 9, 32);
	Wsetcolour(wndA, WIN_ALL, RED, YELLOW, BRIGHT);
	Wsetcolour(wndB, WIN_ALL, CYAN, YELLOW, BRIGHT);
	Wsetcolour(wndC, WIN_ALL, LIGHTGRAY, YELLOW, BRIGHT);
	Wshow(wndA);
	Wshow(wndB);
	Wshow(wndC);
	Wprintf(wndA, "\n I'm a less important window");
	Wprintf(wndC, "\n I'm a more important window");
	Wprintf(wndB, "\n     Actually a green");
	Wprintf(wndB, "\n    caterpillar is the");
	Wprintf(wndB, "\n ultimate visual evidence");
	Wprintf(wndB, "\n  of a nasty virus attack");
	Wprintf(wndB, "\n     on your computer.");
	do	{
		int x = 0, y = 0;
		c = kgetch();
		switch (c)	{
			case RIGHT:	x++;
						break;
			case LEFT:	--x;
						break;
			case UP:	--y;
						break;
			case DOWN:	y++;
			default:	break;
		}
		if (x || y)
			Wrmove(wndB, x, y);
	} while (c != ESC);
	Wdelete(wndA);
	kgetch();
	Wdelete(wndC);
	kgetch();
	Wdelete(wndB);
}

/* ------------------------------------------------------------------------ */
/*                            show direct video writes                      */
/* ------------------------------------------------------------------------ */
void video(void)
{
   int  x;

   Hset("dvideo  ", 20, 15);
   vputs(0,0,CYAN,"Look at this cyan title");
   for (x=1 ; x < 16 ; x++)
      vputf(0,5+x,x,"This is attribute %d",x);
}



static void get_list   (int s);
static int ht          (char **tb);
static int wd          (char **tb);

char *titles [] = {
	" 1 - int ",
	" 2 - char ",
	" 3 - float ",
	" 4 - unsigned ",
	" 5 - double ",0
};
WINDOW *pno [] = {0, 0, 0, 0, 0};
static int x [] = {20, 15, 29, 10, 17};
static int y [] = {5, 10, 13, 18, 6};
static int wcl [] [2] = {	{BLUE, WHITE},
				{MAGENTA, WHITE},
				{RED, WHITE},
				{GREEN, WHITE},
				{CYAN, WHITE}	};
char *sel1 [] = {
	 "Integer data type",
	 " ",
	 "Variables of type int are one word in length.",
	 "They can be signed (default) or unsigned,",
	 "which means they have a range of -32,768 to",
	 "32,767 and 0 to 65,535, respectively.",
	 0
};

char *sel2 [] = {

	"Character data type",
	" ",
	"Variables of type char are 1 byte in length.",
	"They can be signed (default) or unsigned,",
	"which means they have a range of -128 to 127",
	"and 0 to 255, respectively.",
	0
};

char *sel3 [] = {
	"Real number data type",
	" ",
	"Variables of type float are two words in",
	"length. Their range is 3.4E-38 to 3.4E+38.",
	" ",
	"Use of float or double requires linking in the",
	"floating-point math package. Turbo C++ will do",
	"this automatically if you use floating point",
	"in your program.",
	0
};

char *sel4 [] = {
	"A type modifier alters the meaning of the base",
	"type to yield a new type.",
	" ",
	"Each of these type modifiers can be applied to",
	"the base type int.",
	" ",
	"The modifiers signed and unsigned can be",
	"applied to the base type char.",
	0
};

char *sel5 [] = {
	"Real number data types",
	" ",
	"Variables of type double are four words in",
	"length. Their range is 1.7E-308 to 1.7E+308.",
	"Variables of type long double are five words",
	"in length. Their range is 3.4E-4932 to",
	"1.1E+4932",
	0
};
char **sel[] = {sel1,sel2,sel3,sel4,sel5,0};

/* ------------------------------------------------------------------------ */
/*                           show how to make a list box                    */
/* ------------------------------------------------------------------------ */
void lists(void)

{
	int s = 0, i, c;
	WINDOW *mn;
	char **cp;

	vsetcur(0, 25);
	Hset("list    ", 20, 15);
	mn = Westablish(0, 0, 7, 18);
	Wsettitle(mn, " Select A Type ",JUST_C);
	Wsetcolour(mn,WIN_BORDER,LIGHTGRAY,BLACK,DIM);
	Wsetcolour(mn,WIN_TITLE ,LIGHTGRAY,RED,DIM);
	Wsetcolour(mn,WIN_ACCENT,GREEN,BLACK,DIM);
	Wsetcolour(mn,WIN_FACE,LIGHTGRAY,BLACK,DIM);
	Wshow(mn);
	cp = titles;
	while (*cp)
		Wprintf(mn, "\n%s", *cp++);
	while (1)	{
		Hset("listtest", 40, 10);
		s = Wgetsel(mn, s+1, "12345");
		if (s == 0)
			break;
		if (s == RIGHT || s == LEFT)	{
			s = 0;
			continue;
		}
		Whide(mn);
		get_list(--s);
		c = 0;
		Hset("lists    ", 5, 15);
		while (c != ESC)	{
			c = kgetch();
			switch (c)	{
				case RIGHT:	Wrmove(pno[s], 1, 0);
							break;
				case LEFT:	Wrmove(pno[s], -1, 0);
							break;
				case UP:	Wrmove(pno[s], 0, -1);
							break;
				case DOWN:	Wrmove(pno[s], 0, 1);
							break;
				case DEL:	Wdelete(pno[s]);
							pno[s] = NULL;
							break;
				case '+':	Wforefront(pno[s]);
							break;
				case '-':	Wrear(pno[s]);
				default:	break;
			}
			if (c > '0' && c < '6')
				get_list(s = c - '1');
		}
		Wforefront(mn);
		Wshow(mn);
	}
	Wdeleteall();
	for (i = 0; i < 5; i++)
		pno[i] = NULL;
}

/* ------------------------------------------------------------------------ */
/*                           activate a list by number                      */
/* ------------------------------------------------------------------------ */
static void get_list(int s)
{
	char **cp;
	static int lastp = -1;
	if (lastp != -1)
		Wsetintensity(pno[lastp], DIM);
	lastp = s;
	if (pno [s])
		Wsetintensity(pno[s], BRIGHT);
	else	{
		pno [s] = Westablish
			(x[s], y[s], ht(sel[s]), wd(sel[s]));
		Wsettitle(pno[s], titles[s],JUST_C);
		Wsetcolour(pno[s],WIN_ALL,wcl[s][0],wcl[s][1],BRIGHT);
		Wsetborder(pno[s], 1);
		Wshow(pno[s]);
		cp = sel[s];
		while (*cp)
			Wprintf(pno[s], "\n %s", *cp++);
	}
}
/* ------------------------------------------------------------------------ */
/*                   compute height of a window display table               */
/* ------------------------------------------------------------------------ */
static int ht(char **tb)
{
	int h = 0;
	while (*(tb + h++))	;
	return h + 3;
}
/* ------------------------------------------------------------------------ */
/*                    compute width of a window display table               */
/* ------------------------------------------------------------------------ */
static int wd(char **tb)
{
	int w = 0;
	while (*tb)		{
		w = max(w, strlen(*tb));
		tb++;
	}
	return w + 4;
}



/* ------------------------------------------------------------------------ */
/*                        pull down  menu tests                             */
/* ------------------------------------------------------------------------ */

char *wselcs[] = {
	" Flash Demo  ",
	" Colour Demo ",
	" Title Demo ",
	" Border Demo ",
	" Select Demo ",
	" LotsaWindows Demo ",
	" Blink bits ",
	" Move Demo ",
	NULL
};
char *wtselcs[] = {
	" Lists ",
	NULL
};
char *eselcs[] = {
	" Orders ",
	" All Orders ",
	NULL
};
char *dselcs[] = {
	" Editor ",
	NULL
};
char *mselcs[] = {
	" Direct Video ",
	" Set 50 lines ",
	" Set 43 lines ",
	" Set 25 lines ",
	NULL
};

static void (*wfuncs[])()={windowsdemo,wcolours,wtitles,wborders,waccent,
			   wfast,wfast2,wmove};
static void (*wtfuncs[])()={lists};
static void (*efuncs[])()={entry,entryall};
static void (*dfuncs[])()={editor};
static void (*mfuncs[])()={video,vset50,vset43,vset25};
static MENU mnu [] = {
	{" Windows ", 	  wselcs,  wfuncs},
	{" Window Tools ", wtselcs, wtfuncs},
	{" Entrys ",	  eselcs,  efuncs},
	{" Editor ",      dselcs,  dfuncs},
	{" Misc  ",       mselcs,  mfuncs},
	{NULL,NULL,NULL}
};


void mainmenu(void)
{
    Hset("menu    ", 20, 15);
    Msetcolour(WIN_BORDER,LIGHTGRAY,WHITE,DIM);
    Msetcolour(WIN_TITLE ,LIGHTGRAY,YELLOW,DIM);
    Msetcolour(WIN_ACCENT,GREEN,BLACK,DIM);
    Msetcolour(WIN_FACE,LIGHTGRAY,BLACK,DIM);
    Msettitle("[ SST Demo ]",JUST_C);
    Msetfullwidth(1);
    Msetspace(3, SPC_BETWEEN);
    Mselect(mnu,TRUE);
}


extern int help_key = F1;

/* ------------------------------------------------------------------------ */
void main(void)

{
 vpushscreen();
 vpushcur();
 vfill(0,0,25,80,177,CYAN);
 Hload("demo.hlp");
 Hsettitle("[SST Help System]",JUST_L);
 Hsetcolour(WIN_BORDER,GREEN,WHITE,BRIGHT);
 Hsetcolour(WIN_TITLE,GREEN,YELLOW,DIM);
 Hsetcolour(WIN_FACE,GREEN,BLACK,DIM);
 Hsetborder(BRD_DOUBLE);
 mainmenu();
 vpopcur();
 vshowcur();
 vpopscreen();
}

