home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ti2_099d.zip / TI2.ZIP / DEMOS / DEMO.CPP next >
C/C++ Source or Header  |  1995-05-17  |  30KB  |  942 lines

  1. /* Filename : DEMO.CPP                                                      *
  2.  * Description : Small Demo of TI/2                                         *
  3.  * Target : DEMO.OBJ -> DEMO.EXE                                            *
  4.  * Portability : OS/2, DOS                                                  *
  5.  * Creation date : 04/15/95                                                 *
  6.  * Last modified : 05/09/95                                                 *
  7.  * Copyright (c) Jonathan Tew and Revolutionary Software 1995               */
  8.  
  9. /******************************
  10.  * Predefined header includes *
  11.  ******************************/
  12.  
  13. #ifdef __OS2__
  14. #define INCL_NOPMAPI
  15. #define INCL_DOSDATETIME
  16. #define INCL_DOSPROCESS
  17. #include <os2.h>
  18. #endif
  19.  
  20. #include <stdio.h>
  21. #include <conio.h>
  22. #include <dos.h>
  23. #include <alloc.h>
  24. #include "ti2.h"
  25.  
  26. void check_heap(void)
  27.         {
  28.             if (heapcheck() == -1) {
  29.                 printf("Heap has been corrupted.\n");
  30.                 getch();
  31.             }
  32.         }
  33.  
  34. void timed_getch(void)
  35.         {
  36.             ushort millisec_passed = 0;   // Milliseconds passed counter
  37.  
  38.             /* Clear keyboard buffer */
  39.             while (kbhit()) getch();
  40.  
  41.             /* Loop until user presses a key or timer expires */
  42.             while (millisec_passed < 1500) {
  43.                 /* Check for keyboard being pressed */
  44.                 if (kbhit()) {
  45.                     /* Clear buffer and return */
  46.                     while (kbhit()) getch();
  47.                     return;
  48.                 }
  49.                 /* Pause for 100 milliseconds */
  50.                 #ifdef __OS2__
  51.                 DosSleep(100);
  52.                 #else
  53.                 delay(100);
  54.                 #endif
  55.                 /* Update counter */
  56.                 millisec_passed += 100;
  57.             }
  58.         }
  59.  
  60. void intro(void)
  61.         {
  62.             win_c win;    // Displays text that describes what TI/2 can do
  63.  
  64.             /* Create the window */
  65.             win.create(1, 1, 70, 23, CYAN, BLACK, LIGHTGRAY, BLACK, " TI/2 Demo ",
  66.                                  YELLOW, BLUE, WIN_FRAME_MIXEDBOX1, WIN_SHADOW_RIGHT,
  67.                                  WIN_TITLE_CENTER | WIN_HORIZ_CNTR | WIN_VERT_CNTR | WIN_EXPLODE | WIN_IMPLODE);
  68.  
  69.             /* Display information in window */
  70.             win.cntr_printf(2, "Text Interface/2");
  71.             win.cntr_printf(3, "Copyright (c) Jonathan Tew and Revolutionary Software 1995");
  72.             win.cntr_printf(4, "All Rights Reserved");
  73.  
  74.             win.goto_xy(1, 6);
  75.  
  76.             win.nd_puts(" This is a small demo of the Text Interface/2 development library.\n\r");
  77.             win.nd_puts(" This gives a brief overview of the various taks that can be\n\r");
  78.             win.nd_puts(" accomplished with TI/2.  These examples include windows, menus,\n\r");
  79.             win.nd_puts(" entry forms, and windowed input.\n\r\n\r");
  80.  
  81.             win.nd_puts(" TI/2 has libraries for Turbo C++ v3.0 and Borland C++ 1.5 for\n\r");
  82.             win.nd_puts(" OS/2.  Support for many more compilers will be available soon.\n\r\n\r");
  83.  
  84.             win.nd_puts(" The TI/2 order form can be found in the file ORDER.FRM.  \n\r\n\r");
  85.  
  86.             win.nd_puts(" Mail: Revolutionary Software     BBS: The Fallen Fortress\n\r");
  87.             win.nd_puts("       2689 Hickory Cove               (404) 469-6752\n\r");
  88.             win.nd_puts("       Lilburn, GA 30247\n\r");
  89.  
  90.             win.cntr_printf(win.text_height(), "Press any key to continue.");
  91.  
  92.             win.redisplay_text();
  93.  
  94.             /* Wait for key to be pressed */
  95.             while (kbhit()) getch();
  96.             while (!kbhit()) desktop.wputs(" TI/2 ");
  97.             while (kbhit()) getch();
  98.  
  99.             /* Clear the desktop */
  100.             win.destroy();
  101.         }
  102.  
  103. void creating(void)
  104.         {
  105.             win_c win1;   // Demonstration window
  106.             win_c win2;   // Demonstration window
  107.  
  108.             /* Create two example windows */
  109.             win1.create(1, 1, 30, 10, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 1 ", YELLOW, BLUE, WIN_FRAME_DOUBLEBOX,
  110.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  111.             win2.create(49, 15, 79, 24, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 2 ", YELLOW, BLUE, WIN_FRAME_DOUBLEBOX,
  112.                                     WIN_SHADOW_LEFT, WIN_TITLE_CENTER);
  113.  
  114.             /* Explain shadows */
  115.             win1.cntr_printf(win1.text_height() / 2, "Windows can have shadows...");
  116.             win2.cntr_printf(win2.text_height() / 2, "either on the top and left");
  117.             win2.cntr_printf(win2.text_height() / 2 + 1, "or bottom and right.");
  118.  
  119.             timed_getch();
  120.  
  121.             /* Display different types of frames */
  122.             win1.clr_scr();
  123.             win2.clr_scr();
  124.             win1.cntr_printf(win1.text_height() / 2, "Frames can even be changed.");
  125.             timed_getch();
  126.             win1.frame_change(WIN_FRAME_SINGLEBOX);
  127.             win2.frame_change(WIN_FRAME_MIXEDBOX1);
  128.             timed_getch();
  129.             win1.frame_change(WIN_FRAME_MIXEDBOX2);
  130.             win2.frame_change(WIN_FRAME_HATCHBOX1);
  131.             timed_getch();
  132.             win1.frame_change(WIN_FRAME_HATCHBOX2);
  133.             win2.frame_change(WIN_FRAME_HATCHBOX3);
  134.             timed_getch();
  135.             win1.frame_change(WIN_FRAME_SOLIDBOX1);
  136.             win2.frame_change(WIN_FRAME_DOTTEDLINE);
  137.  
  138.             timed_getch();
  139.             win1.frame_change(WIN_FRAME_SOLIDBOX2);
  140.             timed_getch();
  141.  
  142.             /* Show titles example */
  143.             win1.clr_scr();
  144.             win1.cntr_printf(3, "Titles can be...");
  145.             win1.cntr_printf(4, "centered.");
  146.             timed_getch();
  147.             win1.destroy();
  148.             win1.create(1, 1, 30, 10, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 1 ", YELLOW, BLUE, WIN_FRAME_DOUBLEBOX,
  149.                                     WIN_SHADOW_RIGHT, WIN_TITLE_LEFT);
  150.             win1.clr_scr();
  151.             win1.cntr_printf(3, "Titles can be...");
  152.             win1.cntr_printf(4, "left justified.");
  153.             timed_getch();
  154.             win1.destroy();
  155.             win1.create(1, 1, 30, 10, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 1 ", YELLOW, BLUE, WIN_FRAME_DOUBLEBOX,
  156.                                     WIN_SHADOW_RIGHT, WIN_TITLE_RIGHT);
  157.             win1.clr_scr();
  158.             win1.cntr_printf(3, "Titles can be...");
  159.             win1.cntr_printf(4, "right justified.");
  160.             timed_getch();
  161.  
  162.             /* Show centering demo */
  163.             win1.clr_scr();
  164.             win2.clr_scr();
  165.             win2.cntr_printf(win2.text_height() / 2, "Windows can be centered...");
  166.             win2.cntr_printf(win2.text_height() / 2 + 1, "horizontally");
  167.             win1.center(WIN_HORIZ_CNTR);
  168.             timed_getch();
  169.             win1.move(1, 1);
  170.             win2.clr_scr();
  171.             win2.cntr_printf(win2.text_height() / 2, "Windows can be centered...");
  172.             win2.cntr_printf(win2.text_height() / 2 + 1, "vertically");
  173.             win1.center(WIN_VERT_CNTR);
  174.             timed_getch();
  175.             win2.clr_scr();
  176.             win2.cntr_printf(win2.text_height() / 2, "Windows can be centered...");
  177.             win2.cntr_printf(win2.text_height() / 2 + 1, "vert. & horiz.");
  178.             win1.center(WIN_VERT_CNTR | WIN_HORIZ_CNTR);
  179.             timed_getch();
  180.  
  181.             /* Destroy two example windows */
  182.             win1.destroy();
  183.             win2.destroy();
  184.         }
  185.  
  186. #define TAB                9
  187. #define SHIFT_TAB         15  // Extended character
  188. #define ESC               27
  189. #define UPARROW           72  // Extended character
  190. #define DOWNARROW         80  // Extended character
  191. #define LEFTARROW         75  // Extended character
  192. #define RIGHTARROW        77  // Extended character
  193.  
  194. void seethru(void)
  195.         {
  196.             uchar x, y;   // Temporary coordinate
  197.             win_c win;    // Window that is slide around the screen;
  198.             uchar is_seethru = 1;   // Tells whether window is see through.
  199.             win_c desc_win;   // Window that holds instructions
  200.             uchar ch;       // Character entered by user
  201.             uchar is_on_top = 1;  // Tells which window is on top
  202.  
  203.             /* Create description window and display instructions */
  204.             desc_win.create(1, 1, 40, 9, CYAN, BLACK, LIGHTGRAY, BLACK, " Instructions ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  205.                                             WIN_SHADOW_RIGHT, WIN_TITLE_CENTER | WIN_HORIZ_CNTR | WIN_VERT_CNTR);
  206.             desc_win.wputs("\n\r");
  207.             desc_win.wputs(" Navigate the other window around\n\r");
  208.             desc_win.wputs(" with the arrow keys.  Hit TAB to\n\r");
  209.             desc_win.wputs(" toggle between normal or see-thru,\n\r");
  210.             desc_win.wputs(" SHIFT-TAB to toggle window on top,\n\r");
  211.             desc_win.wputs(" and ESC to stop.");
  212.  
  213.             /* Create see-thru window */
  214.             win.create(1, 1, 15, 15, CYAN, BLACK, LIGHTGRAY, BLACK, " See-thru ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX2,
  215.                                  WIN_SHADOW_RIGHT, WIN_TITLE_CENTER | WIN_SEETHRU);
  216.  
  217.             while ((ch = getch()) != ESC) {
  218.                 x = win.where_win_x();
  219.                 y = win.where_win_y();
  220.                 switch(ch) {
  221.                     case 0 : {
  222.                                          switch(getch()) {
  223.                                              case UPARROW : {
  224.                                                                                 y--;
  225.                                                                                 win.slide(x, y);
  226.                                                                                 break;
  227.                                                                             }
  228.                                              case DOWNARROW : {
  229.                                                                                     y++;
  230.                                                                                     win.slide(x, y);
  231.                                                                                     break;
  232.                                                                                 }
  233.                                              case LEFTARROW : {
  234.                                                                                     x--;
  235.                                                                                     win.slide(x, y);
  236.                                                                                     break;
  237.                                                                                 }
  238.                                              case RIGHTARROW : {
  239.                                                                                      x++;
  240.                                                                                      win.slide(x, y);
  241.                                                                                      break;
  242.                                                                                  }
  243.                                              case SHIFT_TAB : {
  244.                                                                                     /* Popup the correct window */
  245.                                                                                     if (is_on_top) {
  246.                                                                                         is_on_top = 0;
  247.                                                                                         desc_win.popup();
  248.                                                                                     }
  249.                                                                                         else
  250.  
  251.                                                                                     {
  252.                                                                                         is_on_top = 1;
  253.                                                                                         win.popup();
  254.                                                                                     }
  255.                                                                                 }
  256.                                          }
  257.                                          break;
  258.                                      }
  259.                     case TAB : {
  260.                                              /* Toggle window see-thru and normal and change title to reflect the state */
  261.                                              if (is_seethru) {
  262.                                                  win.make_normal();
  263.                                                  win.title_change(" Normal ");
  264.                                                  is_seethru = 0;
  265.                                              }
  266.                                                  else
  267.                                              {
  268.                                                  win.make_seethru();
  269.                                                  win.title_change( " See-thru ");
  270.                                                  is_seethru = 1;
  271.                                              }
  272.                                              break;
  273.                                          }
  274.                 }
  275.             }
  276.  
  277.             /* Destroy description and see-thru window */
  278.             desc_win.destroy();
  279.             win.destroy();
  280.         }
  281.  
  282. void output(void)
  283.         {
  284.             win_c win1;   // Demonstration window
  285.             win_c win2;   // Demonstration window
  286.             win_c win3;   // Demonstration window
  287.             uchar i;      // General counter
  288.  
  289.             /* Create windows that overlap */
  290.             win1.create(10, 5, 40, 12, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 1 ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  291.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  292.             win2.create(15, 10, 45, 17, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 2 ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  293.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  294.             win3.create(20, 15, 70, 22, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 3 ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  295.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  296.  
  297.             /* Show off regular printing */
  298.             win3.cntr_printf(1, "You can write text to a window...");
  299.             timed_getch();
  300.             win3.cntr_printf(2, "Hello World!");
  301.             timed_getch();
  302.  
  303.             /* Show changing the colors and printing */
  304.             win3.clr_scr();
  305.             win3.cntr_printf(1, "You can write text with different colors...");
  306.             timed_getch();
  307.             win3.text_color(BLACK);
  308.             win3.text_background(LIGHTGRAY);
  309.             win3.cntr_printf(2, "Hello World!");
  310.             win3.text_color(YELLOW);
  311.             win3.text_background(RED);
  312.             win3.cntr_printf(3, "Hello World!");
  313.             win3.text_color(LIGHTGRAY);
  314.             win3.text_background(BLACK);
  315.             timed_getch();
  316.  
  317.             /* Show printf function */
  318.             win3.clr_scr();
  319.             win3.cntr_printf(1, "You can even use a printf function for windows!");
  320.             win3.cntr_printf(2, "To demonstrate I will count to twenty...");
  321.             timed_getch();
  322.             win3.clr_scr();
  323.             for (i = 1; i <= 20; i++) {
  324.                 win3.wprintf("Count is now = %d\n\r", i);
  325.                 timed_getch();
  326.             }
  327.  
  328.             /* Show right justify */
  329.             win3.clr_scr();
  330.             win3.cntr_printf(1, "You can write Right Justified strings.");
  331.             timed_getch();
  332.             win3.rj_printf(20, 3, "These strings");
  333.             win3.rj_printf(20, 4, "are printed right");
  334.             win3.rj_printf(20, 5, "justified");
  335.             timed_getch();
  336.  
  337.             /* Show column centering */
  338.             win3.clr_scr();
  339.             win3.cntr_printf(1, "You can center strings on different columns...");
  340.             timed_getch();
  341.             win3.col_cntr_printf(9, 3, "These strings");
  342.             win3.col_cntr_printf(9, 4, "are centered on");
  343.             win3.col_cntr_printf(9, 5, "column 9.");
  344.             timed_getch();
  345.             win3.clr_scr();
  346.             win3.col_cntr_printf(18, 3, "These strings");
  347.             win3.col_cntr_printf(18, 4, "are centered on");
  348.             win3.col_cntr_printf(18, 5, "column 18.");
  349.             timed_getch();
  350.             win3.clr_scr();
  351.             win3.col_cntr_printf(28, 3, "These strings");
  352.             win3.col_cntr_printf(28, 4, "are centered on");
  353.             win3.col_cntr_printf(28, 5, "column 28.");
  354.             timed_getch();
  355.  
  356.             /* Show background writing */
  357.             win3.clr_scr();
  358.             win3.cntr_printf(1, "You can write strings to background windows...");
  359.             win3.cntr_printf(2, "To demonstrate we will count in all the windows.");
  360.             timed_getch();
  361.             win3.clr_scr();
  362.             for(i = 1; i <= 75; i++) {
  363.                 win1.wprintf("Count is now = %d\n\r", i);
  364.                 win2.wprintf("Count is now = %d\n\r", i);
  365.                 win3.wprintf("Count is now = %d\n\r", i);
  366.             }
  367.             timed_getch();
  368.  
  369.             /* Destroy windows */
  370.             win1.destroy();
  371.             win2.destroy();
  372.             win3.destroy();
  373.         }
  374.  
  375. void clearing(void)
  376.         {
  377.             win_c win1;   // Demonstration window
  378.             win_c win2;   // Demonstration window
  379.  
  380.             /* Create windows */
  381.             win1.create(1, 1, 40, 12, CYAN, BLACK, LIGHTGRAY, BLACK, " Window ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  382.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  383.             win2.create(10, 18, 70, 22, CYAN, BLACK, LIGHTGRAY, BLACK, " Description ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  384.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  385.  
  386.             /* Fill window so they can see it being cleared */
  387.             win1.fill('*');
  388.  
  389.             /* Show clr_eol function */
  390.             win2.cntr_printf(2, "You can clear from the cursor to the end of the line.");
  391.             timed_getch();
  392.             win1.goto_xy(10, 1);
  393.             win1.clr_eol();
  394.  
  395.             /* Demonstrate clr_region function */
  396.             win2.clr_scr();
  397.             win2.cntr_printf(2, "You can clear a region of the window.");
  398.             timed_getch();
  399.             win1.clr_region(2, 3, 10, 8);
  400.  
  401.             /* Demonstrate clr_scr function */
  402.             win2.clr_scr();
  403.             win2.cntr_printf(2, "You can clear the whole window.");
  404.             timed_getch();
  405.             win1.clr_scr();
  406.             timed_getch();
  407.  
  408.             /* Destroy windows */
  409.             win1.destroy();
  410.             win2.destroy();
  411.         }
  412.  
  413. void scroll_bar(void)
  414.         {
  415.             win_c win;    // Window that is slide around the screen;
  416.             uchar ch;       // Character entered by user
  417.             uchar done = 0; // True if ESC pressed
  418.  
  419.             /* Create description window and display instructions */
  420.             win.create(1, 1, 40, 20, CYAN, BLACK, LIGHTGRAY, BLACK, " Instructions ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  421.                                  WIN_SHADOW_RIGHT, WIN_TITLE_CENTER | WIN_HORIZ_CNTR | WIN_VERT_CNTR);
  422.             win.wputs("\n\r");
  423.             win.wputs(" Slide the scroll bars around with\n\r");
  424.             win.wputs(" the arrow keys.  Hit ESC to stop.\n\r");
  425.  
  426.             /* Create scroll bars */
  427.             win.hscroll_create(WHITE, CYAN, 1, 50);
  428.             win.vscroll_create(WHITE, CYAN, 1, 50);
  429.  
  430.             while (!done) {
  431.                 /* Check keyboard and mouse for input */
  432.                 for (;;) {
  433.                     /* Check keyboard */
  434.                     if (kbhit()) {
  435.                         ch = getch();
  436.                         break;
  437.                     }
  438.                     /* Check mouse */
  439.                     if (mouse_read_event()) {
  440.                         /* Call scroll bar mouse events */
  441.                         if (!win.hscroll_mouse_move()) win.vscroll_mouse_move();
  442.                     }
  443.                 }
  444.  
  445.                 switch(ch) {
  446.                     case 0 : {
  447.                                          switch(getch()) {
  448.                                              case UPARROW : {
  449.                                                                                 win.vscroll_up(1);
  450.                                                                                 break;
  451.                                                                             }
  452.                                              case DOWNARROW : {
  453.                                                                                     win.vscroll_down(1);
  454.                                                                                     break;
  455.                                                                                 }
  456.                                              case LEFTARROW : {
  457.                                                                                     win.hscroll_left(1);
  458.                                                                                     break;
  459.                                                                                 }
  460.                                              case RIGHTARROW : {
  461.                                                                                      win.hscroll_right(1);
  462.                                                                                      break;
  463.                                                                                  }
  464.                                          }
  465.                                          break;
  466.                                      }
  467.                     case ESC : {
  468.                                              done = 1;
  469.                                              break;
  470.                                          }
  471.                 }
  472.             }
  473.  
  474.             /* Destroy description and see-thru window */
  475.             win.destroy();
  476.         }
  477.  
  478. void scrolling(void)
  479.         {
  480.             win_c win1;   // Demonstration window
  481.             win_c win2;   // Demonstration window
  482.  
  483.             /* Create windows */
  484.             win1.create(1, 1, 40, 12, CYAN, BLACK, LIGHTGRAY, BLACK, " Window ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  485.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  486.             win2.create(10, 18, 70, 22, CYAN, BLACK, LIGHTGRAY, BLACK, " Description ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  487.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  488.  
  489.             /* Fill window so they can see it being scrolled */
  490.  
  491.             /* Demonstration */
  492.             win2.cntr_printf(2, " You can scroll windows right.");
  493.             win1.fill('*');
  494.             timed_getch();
  495.             win1.scroll_right();
  496.             timed_getch();
  497.  
  498.             win2.cntr_printf(2, " You can scroll windows left.");
  499.             win1.fill('*');
  500.             timed_getch();
  501.             win1.scroll_left();
  502.             timed_getch();
  503.  
  504.             win2.cntr_printf(2, " You can scroll windows up.");
  505.             win1.fill('*');
  506.             timed_getch();
  507.             win1.scroll_up();
  508.             timed_getch();
  509.             win2.cntr_printf(2, " You can scroll windows down.");
  510.             win1.fill('*');
  511.             timed_getch();
  512.             win1.scroll_down();
  513.             timed_getch();
  514.  
  515.             /* Destroy windows */
  516.             win1.destroy();
  517.             win2.destroy();
  518.         }
  519.  
  520. void hiding(void)
  521.         {
  522.             win_c win1;   // Demonstration window
  523.             win_c win2;   // Demonstration window
  524.             win_c win3;   // Demonstration window
  525.             uchar ch;     // General counter
  526.             uchar is_hidden = 0;    // True if window is hidden
  527.  
  528.             /* Create windows that overlap */
  529.             win1.create(10, 5, 40, 12, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 1 ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  530.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  531.             win2.create(15, 10, 45, 17, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 2 ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  532.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  533.             win3.create(20, 15, 70, 22, CYAN, BLACK, LIGHTGRAY, BLACK, " Window 3 ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  534.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER);
  535.  
  536.             /* Display instructions */
  537.             win3.wputs(" Press space to hide and unhide Window 2.\n\r");
  538.             win3.wputs(" Press ESC to stop.");
  539.  
  540.             while ((ch = getch()) != ESC) {
  541.                 if (ch == ' ') {
  542.                     /* Hide or unhide window */
  543.                     if (is_hidden) {
  544.                         is_hidden = 0;
  545.                         win2.unhide();
  546.  
  547.                     }
  548.                         else
  549.                     {
  550.                         is_hidden = 1;
  551.                         win2.hide();
  552.                     }
  553.                 }
  554.  
  555.             }
  556.  
  557.             /* Destroy windows */
  558.             win1.destroy();
  559.             win2.destroy();
  560.             win3.destroy();
  561.         }
  562.  
  563. void strings(void)
  564.         {
  565.             uchar formatted_string[21] = "(800)555-1212";
  566.             uchar normal_string[61] = "This is a very long string that you can edit :)";
  567.             uchar upcased_string[61] = "THIS IS A VERY LONG UPCASED STRING............";
  568.             uchar control_string[61] = "0fff";
  569.             win_c win;
  570.             form_c form;
  571.  
  572.             /* Defines used for entry form */
  573.             #define F_FORMATTED_STRING 1
  574.             #define F_NORMAL_STRING    2
  575.             #define F_UPCASED_STRING   3
  576.             #define F_CONTROL_STRING   4
  577.             #define B_DONE             5
  578.  
  579.             /* Create window */
  580.             win.create(1, 1, 50, 13, CYAN, BLACK, LIGHTGRAY, BLACK, " String Input ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  581.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER | WIN_HORIZ_CNTR | WIN_VERT_CNTR);
  582.  
  583.             form.create(&win);
  584.             form.button_colors(BLACK, GREEN, YELLOW, GREEN, DARKGRAY, GREEN, LIGHTGRAY, BLACK);
  585.             form.field_colors(BLACK, LIGHTGRAY, WHITE, LIGHTGRAY, DARKGRAY, LIGHTGRAY);
  586.             form.string_colors(WHITE, BLUE, WHITE, GREEN, DARKGRAY, LIGHTGRAY);
  587.  
  588.             form.add_format_string(F_FORMATTED_STRING, 2, 2, " Formatted String ", "(###)###-####", 22, 2);
  589.             form.set_format_string_var(F_FORMATTED_STRING, formatted_string, 1);
  590.             form.add_string(F_NORMAL_STRING, 2, 4, " Normal String    ", 22, 4, 20, 60);
  591.             form.set_string_var(F_NORMAL_STRING, normal_string, 1);
  592.             form.add_upcase_string(F_UPCASED_STRING, 2, 6, " Upcased String   ", 22, 6, 20, 60);
  593.             form.set_upcase_string_var(F_UPCASED_STRING, upcased_string, 1);
  594.             form.add_control_string(F_CONTROL_STRING, 2, 8, " Hex Ctrl String  ", "0123456789abcdefABCDEF", 22, 8, 20, 60);
  595.             form.set_control_string_var(F_CONTROL_STRING, control_string, 1);
  596.             form.add_button(B_DONE, 2, 10, "Done");
  597.  
  598.             /* Display form and get input */
  599.             form.display();
  600.             form.load();
  601.  
  602.             /* Cleanup memory allocated by window and entry form */
  603.             form.destroy();
  604.             win.destroy();
  605.  
  606.             /* Undefine defines used for entry form */
  607.             #undef F_FORMATTED_STRING
  608.             #undef F_NORMAL_STRING
  609.             #undef F_UPCASED_STRING
  610.             #undef F_CONTROL_STRING
  611.             #undef B_DONE
  612.         }
  613.  
  614. void radiobutton_and_checkboxs(void)
  615.         {
  616.             win_c win;
  617.             form_c form;
  618.  
  619.             /* Defines used for checkboxes and radiobuttons */
  620.             #define B_DONE             1
  621.             #define F_CHECKBOX         2
  622.                 #define CE_ENVIROMENT       1
  623.                 #define CE_DESKTOP          2
  624.                 #define CE_PROJECT          3
  625.             #define F_RADIOBUTTON      3
  626.                 #define RE_CUA              1
  627.                 #define RE_ALTERNATE        2
  628.                 #define RE_NATIVE           3
  629.  
  630.             /* Create window */
  631.             win.create(1, 1, 36, 10, CYAN, BLACK, LIGHTGRAY, BLACK, " Radio Buttons / Checkboxes ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  632.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER | WIN_HORIZ_CNTR | WIN_VERT_CNTR);
  633.  
  634.             form.create(&win);
  635.             form.button_colors(BLACK, GREEN, YELLOW, GREEN, DARKGRAY, GREEN, LIGHTGRAY, BLACK);
  636.             form.field_colors(BLACK, LIGHTGRAY, WHITE, LIGHTGRAY, DARKGRAY, LIGHTGRAY);
  637.             form.radiobutton_colors(BLACK, CYAN, WHITE, CYAN, DARKGRAY, CYAN, CYAN);
  638.             form.checkbox_colors(BLACK, CYAN, WHITE, CYAN, DARKGRAY, CYAN, CYAN);
  639.  
  640.             form.add_button(B_DONE, 2, 7, "Done");
  641.  
  642.             form.add_radiobutton(F_RADIOBUTTON, 2, 2, "Command Set", 2, 3, 16, 5);
  643.             form.add_radiobutton_entry(F_RADIOBUTTON, RE_CUA,       2, 1, "CUA", 1);
  644.             form.add_radiobutton_entry(F_RADIOBUTTON, RE_ALTERNATE, 2, 2, "Alternate", 0);
  645.             form.add_radiobutton_entry(F_RADIOBUTTON, RE_NATIVE,    2, 3, "Native", 0);
  646.  
  647.             form.add_checkbox(F_CHECKBOX, 18, 2, "Save Options", 18, 3, 33, 5);
  648.             form.add_checkbox_entry(F_CHECKBOX, CE_ENVIROMENT, 2, 1, "Enviroment", 1);
  649.             form.add_checkbox_entry(F_CHECKBOX, CE_DESKTOP,    2, 2, "Desktop", 1);
  650.             form.add_checkbox_entry(F_CHECKBOX, CE_PROJECT,    2, 3, "Project", 1);
  651.  
  652.             /* Display form and get input */
  653.             form.display();
  654.             form.load();
  655.  
  656.             /* Cleanup memory allocated by window and entry form */
  657.             form.destroy();
  658.             win.destroy();
  659.  
  660.             /* Undefine defines used for checkboxes and radiobuttons */
  661.             #undef B_DONE
  662.             #undef F_CHECKBOX
  663.             #undef CE_ENVIROMENT
  664.             #undef CE_DESKTOP
  665.             #undef CE_PROJECT
  666.             #undef F_RADIOBUTTON
  667.             #undef RE_CUA
  668.             #undef RE_ALTERNATE
  669.             #undef RE_NATIVE
  670.         }
  671.  
  672. void numbers(void)
  673.         {
  674.             uchar num_byte = 0;
  675.             ushort num_ushort = 0;
  676.             ulong num_ulong = 0;
  677.             char  num_char = 0;
  678.             int num_int = 0;
  679.             long num_long = 0;
  680.             win_c win;
  681.             form_c form;
  682.  
  683.             /* Defines used for entry form */
  684.             #define F_BYTE    1
  685.             #define F_USHORT  2
  686.             #define F_ULONG   3
  687.             #define F_CHAR    4
  688.             #define F_INT     5
  689.             #define F_LONG    6
  690.             #define B_DONE    7
  691.  
  692.             /* Create window */
  693.             win.create(1, 1, 25, 17, CYAN, BLACK, LIGHTGRAY, BLACK, " Number Input ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  694.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER | WIN_HORIZ_CNTR | WIN_VERT_CNTR);
  695.  
  696.             form.create(&win);
  697.             form.button_colors(BLACK, GREEN, YELLOW, GREEN, DARKGRAY, GREEN, LIGHTGRAY, BLACK);
  698.             form.field_colors(BLACK, LIGHTGRAY, WHITE, LIGHTGRAY, DARKGRAY, LIGHTGRAY);
  699.             form.number_colors(WHITE, BLUE, WHITE, GREEN, DARKGRAY, LIGHTGRAY);
  700.  
  701.             form.add_byte(F_BYTE, 2, 2, " byte   ", 11, 2, 0, 255);
  702.             form.set_byte_var(F_BYTE, &num_byte, 1);
  703.             form.add_ushort(F_USHORT, 2, 4, " ushort ", 11, 4, 0, 65535);
  704.             form.set_ushort_var(F_USHORT, &num_ushort, 1);
  705.             form.add_ulong(F_ULONG, 2, 6, " ulong  ", 11, 6, 0, 4294967295);
  706.             form.set_ulong_var(F_ULONG, &num_ulong, 1);
  707.  
  708.             form.add_char(F_CHAR, 2, 8, " char   ", 11, 8, -128, 127);
  709.             form.set_char_var(F_CHAR, &num_char, 1);
  710.             form.add_int(F_INT, 2, 10, " int    ", 11, 10, -32768, 32767);
  711.             form.set_int_var(F_INT, &num_int, 1);
  712.             form.add_long(F_LONG, 2, 12, " long   ", 11, 12, -2147483648, 2147647);
  713.             form.set_long_var(F_LONG, &num_long, 1);
  714.  
  715.             form.add_button(B_DONE, 2, 14, "Done");
  716.  
  717.             form.display();
  718.             form.load();
  719.  
  720.             /* Cleanup memory allocated by window and entry form */
  721.             form.destroy();
  722.             win.destroy();
  723.  
  724.             /* Undefine defines used for entry form */
  725.             #undef F_BYTE
  726.             #undef F_USHORT
  727.             #undef F_ULONG
  728.             #undef F_CHAR
  729.             #undef F_INT
  730.             #undef F_LONG
  731.             #undef B_DONE
  732.         }
  733.  
  734. void others(void)
  735.         {
  736.             ulong d = 19951225;
  737.             ulong t = 120000;
  738.             faddr_t addr = {1, 133, 5016, 0};
  739.             uchar toggle = 1;
  740.             win_c win;
  741.             form_c form;
  742.  
  743.             /* Defines used for entry form */
  744.             #define F_TIME    1
  745.             #define F_DATE    2
  746.             #define F_ADDR    3
  747.             #define F_TOGGLE  4
  748.             #define B_DONE    5
  749.  
  750.             /* Create window */
  751.             win.create(1, 1, 39, 13, CYAN, BLACK, LIGHTGRAY, BLACK, " Other Input ", YELLOW, BLUE, WIN_FRAME_MIXEDBOX1,
  752.                                     WIN_SHADOW_RIGHT, WIN_TITLE_CENTER | WIN_HORIZ_CNTR | WIN_VERT_CNTR);
  753.  
  754.             form.create(&win);
  755.             form.button_colors(BLACK, GREEN, YELLOW, GREEN, DARKGRAY, GREEN, LIGHTGRAY, BLACK);
  756.             form.field_colors(BLACK, LIGHTGRAY, WHITE, LIGHTGRAY, DARKGRAY, LIGHTGRAY);
  757.             form.string_colors(WHITE, BLUE, WHITE, GREEN, DARKGRAY, LIGHTGRAY);
  758.  
  759.             form.add_hhmmss(F_TIME, 2, 2, " Time       ", 15, 2);
  760.             form.set_hhmmss_var(F_TIME, &t, 1);
  761.  
  762.             form.add_mmddyyyy(F_DATE, 2, 4, " Date ", 15, 4);
  763.             form.set_mmddyyyy_var(F_DATE, &d, 1);
  764.  
  765.             form.add_4d_addr(F_ADDR, 2, 6, " Fido Addr. ", 15, 6, 20);
  766.             form.set_4d_addr_var(F_ADDR, &addr, 1);
  767.  
  768.             form.add_toggle_uchar(F_TOGGLE, 2, 8, " Toggle     ", 15, 8);
  769.             form.set_toggle_uchar_var(F_TOGGLE, &toggle, 1);
  770.  
  771.             form.add_button(B_DONE, 2, 10, "Done");
  772.  
  773.             form.display();
  774.             form.load();
  775.  
  776.             /* Cleanup memory allocated by window and entry form */
  777.             form.destroy();
  778.             win.destroy();
  779.  
  780.             /* Undefine defines used for entry form */
  781.             #undef F_TIME
  782.             #undef F_DATE
  783.             #undef F_ADDR
  784.             #undef F_TOGGLE
  785.             #undef B_DONE
  786.         }
  787.  
  788.  
  789. #define SM_WINDOWS    1
  790. #define SM_FORM       2
  791. #define SM_SCREEN     3
  792.  
  793. #define MC_CREATING   1
  794. #define MC_SEETHRU    2
  795. #define MC_OUTPUT     3
  796. #define MC_CLEARING   4
  797. #define MC_SCROLL_BAR 5
  798. #define MC_SCROLLING  6
  799. #define MC_HIDING     7
  800.  
  801. #define MC_STRINGS    8
  802. #define MC_NUMBERS    9
  803. #define MC_RADIOBUT   10
  804. #define MC_OTHER      11
  805.  
  806. #define MC_25_ROWS    12
  807. #define MC_50_ROWS    13
  808.  
  809. void main(void)
  810.         {
  811.             menu_c menu;      // Menu
  812.             uchar done = 0;   // True when user presses ESC to exit menu
  813.  
  814.             check_heap();
  815.  
  816.             /* Initialize TI/2 */
  817.             win_init();
  818.  
  819.             /* Call the introduction function */
  820.             intro();
  821.  
  822.             check_heap();
  823.  
  824.             /* Fill the desktop */
  825.             desktop.fill('■');
  826.  
  827.             /* Create menu */
  828.             menu.create(1, YELLOW, LIGHTGRAY, BLACK, BLUE, LIGHTGRAY, DARKGRAY, BLACK, LIGHTGRAY, BLACK);
  829.             menu.add_submenu(SM_WINDOWS, 2, " ~Windows ", 'W');
  830.             menu.add_menucmd_func(SM_WINDOWS, MC_CREATING,   " ~Creating   ", 'C');
  831.             menu.add_menucmd_func(SM_WINDOWS, MC_SEETHRU,    " ~See-thru   ", 'S');
  832.             menu.add_menucmd_func(SM_WINDOWS, MC_OUTPUT,     " ~Output     ", 'O');
  833.             menu.add_menucmd_func(SM_WINDOWS, MC_CLEARING,   " C~learing   ", 'L');
  834.             menu.add_menucmd_func(SM_WINDOWS, MC_SCROLL_BAR, " Sc~roll Bar ", 'S');
  835.             menu.add_menucmd_func(SM_WINDOWS, MC_SCROLLING,  " Scroll~ing  ", 'I');
  836.             menu.add_menucmd_func(SM_WINDOWS, MC_HIDING,     " ~Hiding     ", 'H');
  837.  
  838.             menu.add_submenu(SM_FORM, 12, " ~Form ", 'F');
  839.             menu.add_menucmd_func(SM_FORM, MC_STRINGS,  " ~String ", 'S');
  840.             menu.add_menucmd_func(SM_FORM, MC_NUMBERS,  " ~Number ", 'N');
  841.             menu.add_menucmd_func(SM_FORM, MC_RADIOBUT, " ~Radiobuttons / Checkboxes ", 'R');
  842.             menu.add_menucmd_func(SM_FORM, MC_OTHER,    " ~Other ", 'O');
  843.  
  844.             menu.add_submenu(SM_SCREEN, 19, " ~Screen ", 'S');
  845.             menu.add_menucmd_func(SM_SCREEN, MC_25_ROWS,  " ~25 Rows ", '2');
  846.             menu.add_menucmd_func(SM_SCREEN, MC_50_ROWS,  " ~50 Rows ", '5');
  847.  
  848.             check_heap();
  849.  
  850.             /* Load menu */
  851.             while (!done) {
  852.                 switch(menu.load()) {
  853.                     case 0 : {
  854.                                          /* Exit menu */
  855.                                          done = 1;
  856.                                          break;
  857.                                      }
  858.                     case MC_CREATING : {
  859.                                                              /* Give creating windows demonstartion */
  860.                                                              creating();
  861.                                                              break;
  862.                                                          }
  863.                     case MC_SEETHRU : {
  864.                                                             /* Let them play with see-thru windows */
  865.                                                             seethru();
  866.                                                             break;
  867.                                                         }
  868.                     case MC_OUTPUT : {
  869.                                                          /* Give output demonstration */
  870.                                                          output();
  871.                                                          break;
  872.                                                      }
  873.                     case MC_CLEARING : {
  874.                                                              /* Give clearing demonstration */
  875.                                                              clearing();
  876.                                                              break;
  877.                                                          }
  878.                     case MC_SCROLL_BAR : {
  879.                                                                  /* Give scroll bar demonstration */
  880.                                                                  scroll_bar();
  881.                                                                  break;
  882.                                                              }
  883.                     case MC_SCROLLING : {
  884.                                                                 /* Give scrolling demonstration */
  885.                                                                 scrolling();
  886.                                                                 break;
  887.                                                             }
  888.                     case MC_HIDING : {
  889.                                                          /* Give hiding/unhiding demonstration */
  890.                                                          hiding();
  891.                                                          break;
  892.                                                      }
  893.                     case MC_STRINGS : {
  894.                                                             /* Give string input demonstration */
  895.                                                             strings();
  896.                                                             break;
  897.                                                         }
  898.                     case MC_NUMBERS : {
  899.                                                             /* Give number input demonstration */
  900.                                                             numbers();
  901.                                                             break;
  902.                                                         }
  903.                     case MC_RADIOBUT : {
  904.                                                              /* Give radio buttons and checkboxes demonstration */
  905.                                                              radiobutton_and_checkboxs();
  906.                                                              break;
  907.                                                          }
  908.                     case MC_OTHER : {
  909.                                                         /* Give other input demonstration */
  910.                                                         others();
  911.                                                         break;
  912.                                                     }
  913.                     case MC_25_ROWS : {
  914.                                                             /* Changes text mode */
  915.                                                             win_text_mode(C80);
  916.                                                             break;
  917.                                                         }
  918.                     case MC_50_ROWS : {
  919.                                                             /* Changes text mode */
  920.                                                             win_text_mode(C4350);
  921.                                                             /* Refill desktop since we have 25 more rows */
  922.                                                             desktop.fill('■');
  923.                                                             break;
  924.                                                         }
  925.                 }
  926.             }
  927.  
  928.             /* Destroy Menu */
  929.             menu.destroy();
  930.  
  931.             /* Deinitialize TI/2 */
  932.             win_deinit();
  933.  
  934.             /* Exit gracefully */
  935.             textcolor(LIGHTGRAY);
  936.             textbackground(BLACK);
  937.             clrscr();
  938.             printf("\nThanks for testing out TI/2.  A Revolutionary Software product.\n");
  939.  
  940.             check_heap();
  941.         }
  942.