/*------------------------- DEMOWIND.C -------------------------*/
/*                                                              */
/* This file contains the VISIONS LIBRARY WINDOW DEMO software. */
/*                                                              */
/*         Copyright 1990 Dan Vogel & David Bernazzani          */
/*                                                              */
/*   Date        Initials        Comments                       */
/*                                                              */
/*  03/07/90       DCV       Initial Release 0.00               */
/*--------------------------------------------------------------*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "USERLIST.H"
#include "USERWIND.H"
#include "USERMENU.H"
#include "USERFORM.H"
#include "USERCOMP.H"
#include "DEMOPROT.H"

LOCAL TEXT *cnotice="VISIONS Copyright 1990 Dan Vogel & David Bernazzani";

/*--------------------------------------------------------------*/




/*-----------------------------------------------------*/
/*                  Run_Window                         */
/*  This is the window library demonstration code.     */
/* The window library demonstration consists of three  */
/* parts, first an introduction to the windows library */
/* demonstration, second a display of multiple windows */
/* of many colors, sizes, and types, and finally an    */
/* interactive window developer and display.           */
/*  NOTE: In general, error checking has been removed  */
/* for the sake of code clarity.  Users should check   */
/* return values for errors!                           */
/*-----------------------------------------------------*/

WORD Run_Window()
{
   WINDOW_HEAD *clear_window;      /* Window to clear screen. */
   MENU_HEAD *new_menu;

   /*-------------------------------------------*/
   /* Create a window just to clear the screen. */
   /*-------------------------------------------*/
   Window_Define(&clear_window, 1, 1, 24, 80,
      TEXT_BLACK, TEXT_WHITE, "", POPUP_BIT);
   Window_Display(clear_window);

   /*-------------------------------------------*/ 
   /* Tell the user what this routine is about. */
   /*-------------------------------------------*/
   Window_Intro();

   /*--------------------------------------------------------*/
   /*  First build the window demonstration selection menu.  */
   /*--------------------------------------------------------*/
   Menu_Define(&new_menu, 7,7,1,1,
        TEXT_BLUE, TEXT_WHITE, TEXT_WHITE, TEXT_BLUE,
        "SELECT WINDOW DEMONSTRATION",
        HOT_EXEC_BIT | POPUP_BIT | SINGLE_BORDER_BIT | MOUSE_ENABLE_BIT);

   Menu_Add(new_menu, "Colors of Windows", 'C', 0, *Colors_Window);
   Menu_Add(new_menu, "Borders of Windows", 'B', 0, *Borders_Window);
   Menu_Add(new_menu, "Exploding/Imploding Windows",
        'E', 0, *Exploding_Window);
   Menu_Add(new_menu, "MultiWindow Display", 'M', 0, *Multiple_Window);
   Menu_Add(new_menu, "43 Line Mode Demonstration", '4', 0, *Demo_43);
   Menu_Add(new_menu, "50 Line Mode Demonstration", '5', 0, *Demo_50);
   Menu_Add(new_menu, "Time in Background Demonstration",
        'T', 0, *Back_Window);
   Menu_Add(new_menu, "Interactive Window Demo",
        'I', 0, *Interactive_Windows);
   Menu_Add(new_menu, "Exit Window Demonstration", 'E', 1, NULL);

   /*---------------------------------*/
   /* Get and execute user selection. */
   /*---------------------------------*/
   Menu_AutoDisplay(new_menu);

   /*---------------------------------*/
   /* And return menu memory to heap. */
   /*---------------------------------*/
   Menu_Delete(new_menu);

   Window_Remove(clear_window);
   Window_Delete(clear_window);

   return(0);
}




/*-----------------------------------*/
/*    Demonstration of background    */
/* processing within VISIONS windows */
/*-----------------------------------*/
WINDOW_HEAD *time_window;

WORD Back_Window()
{
   MENU_HEAD *bk_menu;

   Window_Define(&time_window, 1, 48, 2, 30,
      TEXT_BLUE, TEXT_WHITE, "", POPUP_BIT);
   Window_Display(time_window);
   Window_MesgPtr(time_window, 1, 9, "Current time:");

   Menu_Define(&bk_menu, 12,47,1,1,
        TEXT_BLUE, TEXT_WHITE, TEXT_WHITE, TEXT_BLUE,
        "Background Process Demo",
        HOT_EXEC_BIT | SINGLE_BORDER_BIT | POPUP_BIT | MOUSE_ENABLE_BIT);
   Menu_Add(bk_menu, "Install Background Process", 'I', 0, *prinstall);
   Menu_Add(bk_menu, "Remove Background Process", 'R', 0, *prremove);
   Menu_Add(bk_menu, "Exit", 'E', 1, NULL);

   Menu_AutoDisplay(bk_menu);

   /*------------------------------*/
   /* Make sure it is de-installed */
   /*------------------------------*/
   prremove();
   /*---------------------------------*/
   /* And return menu memory to heap. */
   /*---------------------------------*/
   Menu_Delete(bk_menu);
   Window_Remove(time_window);
   Window_Delete(time_window);

   return(0);
}

/*-------------------------------*/
/* Background process to display */
/*    the time once per second   */
/*-------------------------------*/
VOID show_time()
{
  static time_t last_time;
  time_t the_time;
  TEXT temp[9];

  time(&the_time);
  if (the_time != last_time)
  {
     _strtime(temp);
     Window_MesgPtr(time_window, 2, 11, temp);
     last_time = the_time;
  }
}

/*--------------------------------*/
/* Install the background process */
/*--------------------------------*/
WORD prinstall()
{
   Comp_InstallBkProc(*show_time);
   return(0);
}

/*-------------------------------*/
/* Remove the background process */
/*-------------------------------*/
WORD prremove()
{
   Comp_InstallBkProc(NULL);
   return(0);
}







/*-----------------------------------------------------*/
/* Short Demonstration of a 43 row mode for EGA or VGA */
/*-----------------------------------------------------*/
WORD Demo_43()
{
   WINDOW_HEAD *demo_window;
   TEXT buffer[81];
   UBYTE rows;
   WORD i;

   Window_SetScreenRows(43);
   rows = Window_ScreenHeight();
   if (rows != 43)
      Window_Err("43 line mode not possible with this display!");
   else
   {
      Window_Define(&demo_window, 1, 1, rows, 80,
         TEXT_BLUE, TEXT_WHITE, "", POPUP_BIT);
      Window_Display(demo_window);

      for (i = 1; i <= (WORD)rows; i++)
      {
         sprintf(buffer,"This is line %2d.",i);
         Window_Mesg((UBYTE)i, 2, buffer);
      }

      Window_Mesg( 23, 32, "Hit any key to continue.");

      Comp_GetAnyKey();

      Window_Remove(demo_window);
      Window_Delete(demo_window);

      Window_SetScreenRows(25);
   }
   return(0);
}


/*-----------------------------------------------------*/
/* Short Demonstration of a 43 row mode for EGA or VGA */
/*-----------------------------------------------------*/
WORD Demo_50()
{
   WINDOW_HEAD *demo_window;
   TEXT buffer[81];
   UBYTE rows;
   int i;

   Window_SetScreenRows(50);
   rows = Window_ScreenHeight();
   if (rows != 50)
      Window_Err("50 line mode not possible with this display!");
   else
   {
      Window_Define(&demo_window, 1, 1, rows, 80,
         TEXT_BLUE, TEXT_WHITE, "", POPUP_BIT);
      Window_Display(demo_window);

      for (i = 1; i <= rows; i++)
      {
         sprintf(buffer,"This is line %2d.",i);
         Window_Mesg((UBYTE)i, 2, buffer);
      }

      Window_Mesg( 25, 32, "Hit any key to continue.");

      Comp_GetAnyKey();

      Window_Remove(demo_window);
      Window_Delete(demo_window);

      Window_SetScreenRows(25);
   }
   return(0);
}



/*-----------------------------------------------------*/
/*                 Colors_Window                       */
/* This routine displays a full screen window showing  */
/* all possible colors available in VISIONS for        */
/* backgrounds and text.  This is also useful for      */
/* determining the mappings of different color values  */
/* on a monochrome adaptor!  Note that VISIONS will    */
/* automatically convert colors to monochrome if there */
/* is no color adaptor.  Furthermore, VISIONS disables */
/* background color blinking in color systems in order */
/* to provide eight more colors.                       */
/*-----------------------------------------------------*/
WORD Colors_Window()
{
   WINDOW_HEAD *window_ptr;

   /*-----------------------------------*/
   /* Set up the window and display it. */
   /*-----------------------------------*/
   Window_Define(&window_ptr, 1, 1, 24, 80,
        TEXT_BLACK, TEXT_WHITE, "Colors Display",
        DOUBLE_BORDER_BIT | POPUP_BIT);
   Window_Display(window_ptr);

   /*------------------------------------------------*/
   /* Now fill in the window with color information. */
   /*------------------------------------------------*/
   Comp_SetTextColor(TEXT_WHITE);  Comp_SetBkColor(TEXT_BLACK);
   Window_Mesg(4,13,"Background Colors");
   Window_Mesg(4,53,"Text Colors");

   Comp_SetTextColor(TEXT_WHITE);  Comp_SetBkColor(TEXT_BLACK);
   Window_Mesg(6,13,"Black Background");
   Comp_SetBkColor(TEXT_BLUE);     Window_Mesg(7,13,"Blue Background");
   Comp_SetBkColor(TEXT_GREEN);    Window_Mesg(8,13,"Green Background");
   Comp_SetBkColor(TEXT_CYAN);     Window_Mesg(9,13,"Cyan Background");
   Comp_SetBkColor(TEXT_RED);      Window_Mesg(10,13,"Red Background");
   Comp_SetBkColor(TEXT_MAGENTA);  Window_Mesg(11,13,"Magenta Background");
   Comp_SetBkColor(TEXT_BROWN);    Window_Mesg(12,13,"Brown Background");
   Comp_SetBkColor(TEXT_WHITE);    Comp_SetTextColor(TEXT_BLACK);
   Window_Mesg(13,13,"White Background");
   Comp_SetTextColor(TEXT_WHITE);  Comp_SetBkColor(TEXT_DGREY);
   Window_Mesg(14,13,"Dark Grey Background");
   Comp_SetTextColor(TEXT_BLACK);
   Comp_SetBkColor(TEXT_LBLUE);    Window_Mesg(15,13,"Light Blue Background");
   Comp_SetBkColor(TEXT_LGREEN);   Window_Mesg(16,13,"Light Green Background");
   Comp_SetBkColor(TEXT_LCYAN);    Window_Mesg(17,13,"Light Cyan Background");
   Comp_SetBkColor(TEXT_LRED);     Window_Mesg(18,13,"Light Red Background");
   Comp_SetBkColor(TEXT_LMAGENTA); Window_Mesg(19,13,"Light Magenta Background");
   Comp_SetBkColor(TEXT_YELLOW);   Window_Mesg(20,13,"Yellow Background");
   Comp_SetBkColor(TEXT_BWHITE);   Comp_SetTextColor(TEXT_BLACK);
   Window_Mesg(21,13,"Bright White Background");

   Comp_SetBkColor(TEXT_WHITE);
   Comp_SetTextColor(TEXT_BLACK);    Window_Mesg(6,53,"Black Text");
   Comp_SetTextColor(TEXT_BLUE);     Window_Mesg(7,53,"Blue Text");
   Comp_SetTextColor(TEXT_GREEN);    Window_Mesg(8,53,"Green Text");
   Comp_SetTextColor(TEXT_CYAN);     Window_Mesg(9,53,"Cyan Text");
   Comp_SetTextColor(TEXT_RED);      Window_Mesg(10,53,"Red Text");
   Comp_SetTextColor(TEXT_MAGENTA);
   Window_Mesg(11,53,"Magenta Text");
   Comp_SetTextColor(TEXT_BROWN);
   Comp_SetBkColor(TEXT_WHITE);      Window_Mesg(12,53,"Brown Text");
   Comp_SetBkColor(TEXT_BLACK);
   Comp_SetTextColor(TEXT_WHITE);    Window_Mesg(13,53,"White Text");
   Comp_SetBkColor(TEXT_WHITE);
   Comp_SetTextColor(TEXT_DGREY);    Window_Mesg(14,53,"Dark Grey Text");
   Comp_SetBkColor(TEXT_BLACK);
   Comp_SetTextColor(TEXT_LBLUE);    Window_Mesg(15,53,"Light Blue Text");
   Comp_SetTextColor(TEXT_LGREEN);   Window_Mesg(16,53,"Light Green Text");
   Comp_SetTextColor(TEXT_LCYAN);    Window_Mesg(17,53,"Light Cyan Text");
   Comp_SetTextColor(TEXT_LRED);     Window_Mesg(18,53,"Light Red Text");
   Comp_SetTextColor(TEXT_LMAGENTA); Window_Mesg(19,53,"Light Magenta Text");
   Comp_SetTextColor(TEXT_YELLOW);   Window_Mesg(20,53,"Yellow Text");
   Comp_SetTextColor(TEXT_BWHITE);   Window_Mesg(21,53,"Bright White Text");

   Window_Mesg(24,28,"Hit any key to continue.");

   Comp_GetAnyKey();        /* Wait for a user keystroke. */

   Window_Remove(window_ptr);        /* And finally destroy the window. */
   Window_Delete(window_ptr);

   return(0);
}




/*-----------------------------------------------*/
/*                Borders_Window                 */
/* This routine displays three separate windows, */ 
/* each with a different style of border in      */
/* order to show the user the different border   */
/* options, No Border, Single Line Border, and   */
/* Double Line Border.                           */
/*-----------------------------------------------*/
WORD Borders_Window()
{
   WINDOW_HEAD *w_ptr1, *w_ptr2, *w_ptr3;

   /*---------------------------------------------------------*/
   /* Define windows portraying the different border choices. */
   /*---------------------------------------------------------*/
   Window_Define(&w_ptr1, 8, 1, 7, 39,
        TEXT_BLUE, TEXT_BWHITE, "No Border Window",
        POPUP_BIT);
   Window_Define(&w_ptr2, 8, 41, 7, 39,
        TEXT_BLUE, TEXT_BWHITE, "Single Border Window",
        SINGLE_BORDER_BIT | POPUP_BIT | IMPLODE_BIT);
   Window_Define(&w_ptr3, 16, 20, 7, 39,
        TEXT_BLUE, TEXT_BWHITE, "Double Border Window",
        DOUBLE_BORDER_BIT | POPUP_BIT | EXPLODE_BIT);

   /*----------------------------*/
   /* Display the three windows. */
   /*----------------------------*/
   Window_Display(w_ptr1);
   Window_Display(w_ptr2);
   Window_Display(w_ptr3);

   Window_Mesg(7,7,"Hit any key to continue.");

   Comp_GetAnyKey();        /* Wait for a user keystroke. */

   Window_Remove(w_ptr1);   /* And destroy the border demo windows. */
   Window_Delete(w_ptr1);
   Window_Remove(w_ptr2);
   Window_Delete(w_ptr2);
   Window_Remove(w_ptr3);
   Window_Delete(w_ptr3);

   return(0);
}




/*------------------------------------------------------*/
/*                 Exploding_Window                     */
/* This routine demonstrates the difference between     */
/* an exploding/imploding window, and a 'normal'        */
/* window.  This is accomplished by displaying both     */
/* types of windows at the same time, and then removing */
/* them.  This is done repeatedly to allow the user     */
/* to more clearly see the difference.                  */
/*------------------------------------------------------*/
WORD Exploding_Window()
{
   WINDOW_HEAD *(window_ptr[2]);
   WORD i;

   /*----------------------*/
   /* Define both windows. */
   /*----------------------*/
   Window_Define(&(window_ptr[0]), 2, 2, 11, 40,
        TEXT_CYAN, TEXT_LGREEN, "EXPLODING AND IMPLODING WINDOW",
        SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[1]), 15, 45, 7, 34,
        TEXT_BLUE, TEXT_WHITE, "NON-EXPLODING/IMPLODING WINDOW",
        SINGLE_BORDER_BIT | POPUP_BIT);


   /*--------------------------------------------*/
   /* Now display and remove both several times. */
   /*--------------------------------------------*/
   for (i=1;i<6;i++)
   {
      Window_Display(window_ptr[0]);
      Window_Display(window_ptr[1]);
      Comp_Delay(100);
      Window_Remove(window_ptr[0]);
      Window_Remove(window_ptr[1]);
   }

   /*-----------------------------*/
   /* Finally delete the windows. */
   /*-----------------------------*/
   Window_Delete(window_ptr[0]);
   Window_Delete(window_ptr[1]);

   return(0);
}





/*-------------------------------------------------*/
/*               Multiple_Window                   */
/* This routine is intended to show the user the   */
/* ability of VISIONS to display numerous windows. */
/* In this routine 28 windows are displayed on the */
/* screen.  The maximum number of windows that can */
/* be defined at any one time is dependent on the  */
/* size of the windows, whether or not they are    */
/* popup windows, and how much of the heap is being*/
/* used for other purposes.  Over 100 medium size  */
/* popup windows is easily attained.               */
/*-------------------------------------------------*/
WORD Multiple_Window()
{
   WINDOW_HEAD *(window_ptr[28]);
   WORD i;

   /*---------------------------------------------------*/
   /* Define all the windows using a variety of colors. */
   /*---------------------------------------------------*/
   Window_Define(&(window_ptr[0]), 7, 64, 5, 15,
        TEXT_LBLUE, TEXT_BLACK, "WINDOW # 1",
        SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[1]), 20, 3, 5, 20,
        TEXT_BROWN, TEXT_LBLUE, "WINDOW # 2",
        DOUBLE_BORDER_BIT | EXPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[2]), 14, 34, 8, 18,
        TEXT_BLUE, TEXT_LRED, "WINDOW # 3",
        EXPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[3]), 17, 59, 5, 20,
        TEXT_BLACK, TEXT_LCYAN, "WINDOW # 4",
        DOUBLE_BORDER_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[4]), 1, 12, 5, 35,
        TEXT_GREEN, TEXT_LMAGENTA, "WINDOW # 5",
        IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[5]), 4, 44, 6, 16,
        TEXT_RED, TEXT_BWHITE, "WINDOW # 6",
        SINGLE_BORDER_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[6]), 20, 55, 5, 21,
        TEXT_BLUE, TEXT_BWHITE, "WINDOW # 7",
        DOUBLE_BORDER_BIT | EXPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[7]), 19, 21, 5, 17,
        TEXT_RED, TEXT_WHITE, "WINDOW # 8",
        SINGLE_BORDER_BIT | EXPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[8]), 9, 23, 6, 18,
        TEXT_BLACK, TEXT_YELLOW, "WINDOW # 9",
        IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[9]), 14, 31, 5, 20,
        TEXT_WHITE, TEXT_GREEN, "WINDOW # 10",
        DOUBLE_BORDER_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[10]), 17, 2, 6, 19,
        TEXT_YELLOW, TEXT_BLACK, "WINDOW # 11",
        SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[11]), 18, 16, 4, 17,
        TEXT_WHITE, TEXT_CYAN, "WINDOW # 12",
        EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[12]), 13, 61, 6, 20,
        TEXT_WHITE, TEXT_BROWN, "WINDOW # 13",
        SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[13]), 1, 63, 7, 16,
        TEXT_BLUE, TEXT_BWHITE, "WINDOW # 14",
        SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[14]), 1, 1, 5, 15,
        TEXT_LBLUE, TEXT_BLACK, "WINDOW # 15",
        SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[15]), 5, 5, 5, 20,
        TEXT_BROWN, TEXT_LBLUE, "WINDOW # 16",
        DOUBLE_BORDER_BIT | EXPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[16]), 2, 8, 8, 18,
        TEXT_BLUE, TEXT_LRED, "WINDOW # 17",
        EXPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[17]), 10, 59, 5, 20,
        TEXT_BLACK, TEXT_LCYAN, "WINDOW # 18",
        DOUBLE_BORDER_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[18]), 19, 32, 5, 35,
        TEXT_GREEN, TEXT_LMAGENTA, "WINDOW # 19",
        IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[19]), 8, 24, 6, 16,
        TEXT_RED, TEXT_BWHITE, "WINDOW # 20",
        SINGLE_BORDER_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[20]), 10, 1, 5, 21,
        TEXT_BLUE, TEXT_BWHITE, "WINDOW # 21",
        DOUBLE_BORDER_BIT | EXPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[21]), 19, 61, 5, 17,
        TEXT_RED, TEXT_WHITE, "WINDOW # 22",
        SINGLE_BORDER_BIT | EXPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[22]), 10, 35, 6, 18,
        TEXT_BLACK, TEXT_YELLOW, "WINDOW # 23",
        IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[23]), 4, 11, 5, 20,
        TEXT_WHITE, TEXT_GREEN, "WINDOW # 24",
        DOUBLE_BORDER_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[24]), 6, 52, 6, 19,
        TEXT_YELLOW, TEXT_BLACK, "WINDOW # 25",
        SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[25]), 18, 36, 4, 17,
        TEXT_WHITE, TEXT_CYAN, "WINDOW # 26",
        EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[26]), 16, 61, 6, 20,
        TEXT_WHITE, TEXT_BROWN, "WINDOW # 27",
        SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);
   Window_Define(&(window_ptr[27]), 5, 63, 7, 16,
        TEXT_BLUE, TEXT_BWHITE, "WINDOW # 28",
        SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);

   /*------------------------------*/
   /* Now display all the windows. */
   /*------------------------------*/
   for (i=0;i<28;i++)
   {
      Window_Display(window_ptr[i]);
      Comp_Delay(100);         /* Slight pause between window displays. */
   }

   /*-----------------------------------------*/
   /* Big pause before we remove the windows. */
   /*-----------------------------------------*/
   Comp_Delay(3000);

   /*-----------------------------*/
   /* Now remove all the windows. */
   /*-----------------------------*/
   for (i=27;i>=0;i--)
   {
      Comp_Delay(100);         /* Slight pause between window removals. */
      Window_Remove(window_ptr[i]);
      Window_Delete(window_ptr[i]);
   }

   return(0);
}



/*-------------------------------------------------*/
/*              Interactive_Windows                */
/* This routine allows the user to define a window */
/* including colors, sizes, borders, titles, and   */
/* screen positions in an interactive way.         */
/*-------------------------------------------------*/
WORD Interactive_Windows()
{
   WINDOW_HEAD *window_ptr;
   MENU_HEAD *bkcol_menu, *txtcol_menu, *border_menu;
   MENU_HEAD *popup_menu, *implode_menu, *explode_menu;
   FORM_HEAD *coord_form;
   UBYTE row, col, heighth, width;
   DWORD bkcol, txtcol;
   TEXT title[81];
   TEXT s_row[3], s_col[3], s_heighth[3], s_width[3];
   BITS border;
   BITS explode, implode, popup;
   WORD key=0;


   Interactive_Info();     /* Tell the user what's about to happen. */

   /*---------------------------------------*/
   /* Create the text color selection menu. */
   /*---------------------------------------*/
   MakeColorMenu(&txtcol_menu,"Select Text Color");

   /*---------------------------------------------*/
   /* Create the background color selection menu. */
   /*---------------------------------------------*/
   MakeColorMenu(&bkcol_menu,"Select Background Color");

   /*-----------------------------------------*/
   /* Create the border style selection menu. */
   /*-----------------------------------------*/
   Menu_Define(&border_menu,12,12,1,1,
        TEXT_BLUE,TEXT_WHITE,TEXT_WHITE,TEXT_BLUE,"Select Border",
        SINGLE_BORDER_BIT | HOT_EXEC_BIT | MOUSE_ENABLE_BIT);
   Menu_Add(border_menu, "No Border", 'N', 0x7f, NULL);
   Menu_Add(border_menu, "Single Line Border", 'S', SINGLE_BORDER_BIT, NULL);
   Menu_Add(border_menu, "Double Line Border", 'D', DOUBLE_BORDER_BIT, NULL);

   /*--------------------------------*/
   /* Create the pop-up enable menu. */
   /*--------------------------------*/
   Menu_Define(&popup_menu,14,14,1,1,
        TEXT_BLUE,TEXT_WHITE,TEXT_WHITE,TEXT_BLUE,"Popup Style",
        SINGLE_BORDER_BIT | HOT_EXEC_BIT | MOUSE_ENABLE_BIT);
   Menu_Add(popup_menu, "TRUE", 'T', POPUP_BIT, NULL);
   Menu_Add(popup_menu, "FALSE", 'F', 0x7f, NULL);

   /*------------------------------------------*/
   /* Create the exploding window enable menu. */
   /*------------------------------------------*/
   Menu_Define(&explode_menu,14,14,1,1,
        TEXT_BLUE,TEXT_WHITE,TEXT_WHITE,TEXT_BLUE,"Exploding Style",
        SINGLE_BORDER_BIT | HOT_EXEC_BIT | MOUSE_ENABLE_BIT);
   Menu_Add(explode_menu, "TRUE", 'T', EXPLODE_BIT, NULL);
   Menu_Add(explode_menu, "FALSE", 'F', 0x7f, NULL);

   /*------------------------------------------*/
   /* Create the imploding window enable menu. */
   /*------------------------------------------*/
   Menu_Define(&implode_menu,14,14,1,1,
        TEXT_BLUE,TEXT_WHITE,TEXT_WHITE,TEXT_BLUE,"Imploding Style",
        SINGLE_BORDER_BIT | HOT_EXEC_BIT | MOUSE_ENABLE_BIT);
   Menu_Add(implode_menu, "TRUE", 'T', IMPLODE_BIT, NULL);
   Menu_Add(implode_menu, "FALSE", 'F', 0x7f, NULL);

   /*-----------------------------------------------------*/
   /* Create the window coordinates and title entry form. */
   /*-----------------------------------------------------*/
   MakeCoordForm(&coord_form, title, s_row, s_col, s_heighth, s_width);

   while (key != ESC)
   {

      /*--------------------------------------------------------*/
      /* Execute all the menus and forms to specify the window. */
      /*--------------------------------------------------------*/
      if (Form_Entry(coord_form) == -1) goto exit;
      /*---------------------------------*/
      /* Convert the inputs to integers. */
      /*---------------------------------*/
      row = (UBYTE)atoi(s_row);       col = (UBYTE)atoi(s_col);
      width = (UBYTE)atoi(s_width);   heighth = (UBYTE)atoi(s_heighth);

      if ((bkcol = Menu_AutoDisplay(bkcol_menu)) == -1) goto exit;
      bkcol = ColorConvert((WORD)bkcol);   /* Convert colors to numbers. */
      if ((txtcol = Menu_AutoDisplay(txtcol_menu)) == -1) goto exit;
      txtcol = ColorConvert((WORD)txtcol);
      if ((border = (BITS)Menu_AutoDisplay(border_menu)) == -1) goto exit;
      if (border == 0x7f)
         border = 0;
      if ((popup = (BITS)Menu_AutoDisplay(popup_menu)) == -1) goto exit;
      if (popup == 0x7f)
         popup = 0;
      if ((explode = (BITS)Menu_AutoDisplay(explode_menu)) == -1) goto exit;
      if (explode == 0x7f)
         explode = 0;
      if ((implode = (BITS)Menu_AutoDisplay(implode_menu)) == -1) goto exit;
      if (implode == 0x7f)
         implode = 0;

      /*----------------------------------------*/
      /* Tell the user to hit keys to continue. */
      /*----------------------------------------*/
      Window_Err(
       "Hit any key to see your window, and then another key to continue.");

      /*------------------------------------*/
      /* Display the user's defined window. */
      /*------------------------------------*/
      Window_Define(&window_ptr, row, col, heighth, width,
        bkcol, txtcol, title, border | explode | implode | popup);

      Window_Display(window_ptr);

      /*---------------------------------*/
      /* Force a key strike to continue. */
      /*---------------------------------*/
      Comp_GetAnyKey();

      Window_Remove(window_ptr);  /* And destroy the user's window. */
      Window_Delete(window_ptr);

   }

   /*-------------------------------------------------------*/
   /* Destroy all the window specification forms and menus. */
   /*-------------------------------------------------------*/
   Menu_Delete(txtcol_menu);
   Menu_Delete(bkcol_menu);
   Menu_Delete(border_menu);
   Form_Delete(coord_form);
exit:
   return(0);
}




/*------------------------------------------------------*/
/*                 Interactive_Info                     */
/* This routine displays a window of information to the */
/* user, telling him what is about to happen with the   */
/* interactive window demonstration.                    */
/*------------------------------------------------------*/
WORD Interactive_Info()
{
   WINDOW_HEAD *info_window;

   /*--------------------------------*/
   /* Define and display the window. */
   /*--------------------------------*/
   Window_Define(&info_window, 5, 3, 17, 67, TEXT_BLUE, TEXT_WHITE,
     "Interactive VISIONS Window Demonstration Introduction", 
     SINGLE_BORDER_BIT | EXPLODE_BIT | IMPLODE_BIT | POPUP_BIT);

   Window_Display(info_window);

   Window_Mesg(5,3,"The following is an interactive window display routine.  This");
   Window_Mesg(6,3,"routine allows you to specify a window's coordinates, size, ");
   Window_Mesg(7,3,"title, borders, colors, and display options, and then see the ");
   Window_Mesg(8,3,"result interactively.  A series of forms and menus is used ");
   Window_Mesg(9,3,"to allow you to enter your window's specifications.  Failing ");
   Window_Mesg(10,3,"to correctly specify a window's coordinates or size may cause ");
   Window_Mesg(11,3,"the window to be undisplayable.  Should this happen, just ");
   Window_Mesg(12,3,"change your specifications and try again.  The interactive ");
   Window_Mesg(13,3,"window demonstration preserves all your choices between ");
   Window_Mesg(14,3,"window displays, so that you can default a specification to");
   Window_Mesg(15,3,"your last selection.");

   Window_Mesg(17,21,"Hit any key to continue.");

   Comp_GetAnyKey();   /* Force a keystrike to continue. */

   Window_Remove(info_window);        /* And destroy the window. */
   Window_Delete(info_window);

   return(0);
}



/*-----------------------------------*/
/*           MakeColorMenu           */
/* Create the color selection menu   */
/* for the interactive windows demo. */
/*-----------------------------------*/
WORD MakeColorMenu(col_menu,title)
   MENU_HEAD **col_menu;
   TEXT *title;
{

   Menu_Define(col_menu,4,4,1,1,
        TEXT_BLUE,TEXT_WHITE,TEXT_WHITE,TEXT_BLUE,title,
        SINGLE_BORDER_BIT | HOT_EXEC_BIT | MOUSE_ENABLE_BIT);
   Menu_Add(*col_menu, "BLACK", 'B', 1, NULL);
   Menu_Add(*col_menu, "BLUE", 'B', 2, NULL);
   Menu_Add(*col_menu, "GREEN", 'G', 3, NULL);
   Menu_Add(*col_menu, "CYAN", 'C', 4, NULL);
   Menu_Add(*col_menu, "RED", 'R', 5, NULL);
   Menu_Add(*col_menu, "MAGENTA", 'M', 6, NULL);
   Menu_Add(*col_menu, "BROWN", 'B', 7, NULL);
   Menu_Add(*col_menu, "WHITE", 'W', 8, NULL);
   Menu_Add(*col_menu, "DARK GREY", 'D', 9, NULL);
   Menu_Add(*col_menu, "LIGHT BLUE", 'L', 10, NULL);
   Menu_Add(*col_menu, "LIGHT GREEN", 'L', 11, NULL);
   Menu_Add(*col_menu, "LIGHT CYAN", 'L', 12, NULL);
   Menu_Add(*col_menu, "LIGHT RED", 'L', 13, NULL);
   Menu_Add(*col_menu, "LIGHT MAGENTA", 'L', 14, NULL);
   Menu_Add(*col_menu, "YELLOW", 'Y', 15, NULL);
   Menu_Add(*col_menu, "BRIGHT WHITE", 'B', 16, NULL);

   return(0);
}



/*----------------------------------------------*/
/*                MakeCoordForm                 */
/* Create the coordinate selection and title    */
/* entry form for the interactive windows demo. */
/*----------------------------------------------*/
WORD MakeCoordForm(coord_form, title, s_row, s_col, s_heighth, s_width)
   FORM_HEAD **coord_form;
   TEXT *title;
   TEXT *s_row, *s_col, *s_heighth, *s_width;
{
   FORM_FIELD *field_ptr;

   Form_Define(coord_form,2,5,12,60,
      TEXT_BLUE,TEXT_WHITE,"Window Title and Coordinates",
      SINGLE_BORDER_BIT | MOUSE_ENABLE_BIT);
   Form_Add(*coord_form, *IntOnly, &field_ptr);
   Form_PromptAdd(field_ptr, 5, 2, 21, TEXT_BLUE,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLUE,"Top Left Corner  Row:");
   strcpy(s_row,"");
   Form_TextAdd(field_ptr, 5, 27, 2, TEXT_BLACK,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLACK,s_row);

   Form_Add(*coord_form, *IntOnly, &field_ptr);
   Form_PromptAdd(field_ptr, 6, 19, 7, TEXT_BLUE,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLUE,"Column:");
   strcpy(s_col,"");
   Form_TextAdd(field_ptr, 6, 27, 2, TEXT_BLACK,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLACK,s_col);

   Form_Add(*coord_form, *IntOnly, &field_ptr);
   Form_PromptAdd(field_ptr, 7, 19, 7, TEXT_BLUE,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLUE,"Height:");
   strcpy(s_heighth,"");
   Form_TextAdd(field_ptr, 7, 27, 2, TEXT_BLACK,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLACK,s_heighth);

   Form_Add(*coord_form, *IntOnly, &field_ptr);
   Form_PromptAdd(field_ptr, 8, 19, 7, TEXT_BLUE,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLUE,"Width:");
   strcpy(s_width,"");
   Form_TextAdd(field_ptr, 8, 27, 2, TEXT_BLACK,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLACK,s_width);

   Form_Add(*coord_form, NULL, &field_ptr);
   Form_PromptAdd(field_ptr, 10, 2, 6, TEXT_BLUE,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLUE,"Title:");
   strcpy(title,"");
   Form_TextAdd(field_ptr, 10, 9, 45, TEXT_BLACK,TEXT_WHITE,
      TEXT_WHITE,TEXT_BLACK,title);

   return(0);
}



/*-----------------------------------------------*/
/*               Window_Intro                    */
/* Introduce the user to this demonstration,     */
/* explaining the purpose and what is happening. */
/*-----------------------------------------------*/
WORD Window_Intro()
{
   WINDOW_HEAD *intro_window;

   Window_Define(&intro_window, 1, 1, 24, 80,
        TEXT_BLUE, TEXT_WHITE, "VISIONS Window Demonstration Introduction",
        SINGLE_BORDER_BIT | POPUP_BIT);
   Window_Display(intro_window);
   Window_Mesg(9,5,"   The VISIONS window library demonstration is intended to introduce ");
   Window_Mesg(10,5," the user to the window library concepts and functions through the ");
   Window_Mesg(11,5," use of several separate window examples.  The first examples are user ");
   Window_Mesg(12,5," passive demonstrations, where all the possible window colors and types");
   Window_Mesg(13,5," are displayed.  The last demonstration is user interactive, allowing");
   Window_Mesg(14,5," the user to set all the parameters associated with a window, and then");
   Window_Mesg(15,5," display the result.  The source code used to create this demonstration");
   Window_Mesg(16,5," is supplied with the executable.  Please remember that all VISIONS");
   Window_Mesg(17,5," windows are text windows, graphics windows are not supported.");

   Window_Mesg(24,28,"Hit any key to continue.");

   Comp_GetAnyKey();        /* Wait for a user keystroke. */

   Window_Remove(intro_window);    /* And destroy the window. */
   Window_Delete(intro_window);

   return(0);
}



/*-----------------------------------------------*/
/*               ColorConvert                    */
/* This routine converts integer values returned */
/* from a menu, to long integer colors used by   */
/* the interactive window demonstration.         */
/*-----------------------------------------------*/
DWORD ColorConvert(color)
   WORD color;
{
   DWORD retcolor;

   switch (color)
   {
   case 1:
        retcolor = TEXT_BLACK;
        break;
   case 2:
        retcolor = TEXT_BLUE;
        break;
   case 3:
        retcolor = TEXT_GREEN;
        break;
   case 4:
        retcolor = TEXT_CYAN;
        break;
   case 5:
        retcolor = TEXT_RED;
        break;
   case 6:
        retcolor = TEXT_MAGENTA;
        break;
   case 7:
        retcolor = TEXT_BROWN;
        break;
   case 8:
        retcolor = TEXT_WHITE;
        break;
   case 9:
        retcolor = TEXT_DGREY;
        break;
   case 10:
        retcolor = TEXT_LBLUE;
        break;
   case 11:
        retcolor = TEXT_LGREEN;
        break;
   case 12:
        retcolor = TEXT_LCYAN;
        break;
   case 13:
        retcolor = TEXT_LRED;
        break;
   case 14:
        retcolor = TEXT_LMAGENTA;
        break;
   case 15:
        retcolor = TEXT_YELLOW;
        break;
   case 16:
   default:
        retcolor = TEXT_BWHITE;
        break;
   }

   return(retcolor);
}
