home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / TCXOS2.ZIP / DEMO / WIN_DEMO.C < prev   
Text File  |  1991-11-05  |  16KB  |  443 lines

  1. /*=====[ The TesSeRact(TM) CXL User Interface Development System ]======*
  2.  | Copyright (c) 1987-1991, Innovative Data Concepts, Inc.
  3.  | All Rights Reserved.
  4.  |
  5.  | This Library is part of IDC's TesSeRact Development Tools product
  6.  | line. For information about other IDC products, call  1-215-443-9705.
  7.  *-V--------------------------------------------------------------------*
  8.  | $Header:   D:/beta/version/win_demo.c_v   552.3   22 Jun 1991 14:03:50  $
  9.  |
  10.  | $Log:   D:/beta/version/win_demo.c_v  $
  11.  | 
  12.  |    Rev 552.3   22 Jun 1991 14:03:50
  13.  | check correct return value from Wopen
  14.  | 
  15.  |    Rev 552.2   21 Apr 1991 12:02:02
  16.  | add unix compatibility updates
  17.  | 
  18.  |    Rev 552.1   17 Mar 1991 20:02:50
  19.  | Version 5.52 (after unlog/build)
  20.  *-D--------------------------------------------------------------------*
  21.  | Win_Demo.C : Demonstration of the TCXL window system. The demo is run
  22.  | twice, once with delays, once without and shows some of the many
  23.  | things that can be done with TCXL windows. WinDemo() is invoked from
  24.  | the main menu of Mid_Demo.C.
  25.  *-N-----------------------[ Notes and Caveats ]------------------------*
  26.  | 1) Use the MakeDemo.Bat file to compile this file.
  27.  *======================================================================*/
  28. #include "demo\TCXLdemo.h"
  29.  
  30. /*----------------------------[ Local data ]----------------------------*/
  31.  
  32. LCL   WndT  CDC   w[10];               /* window handle array           */
  33.  
  34. LCL   IntT  CDC   Siz1[] =             /* window sizes                  */
  35. {  19, 19, 24, 24, 24, 19
  36. };
  37. LCL   IntT  CDC   Siz2[] =
  38. {  60, 75, 75, 60, 45, 45
  39. };
  40. LCL   IntT  CDC   Siz3[] =
  41. {   0, 8,  6,  1, 8,  2                /* fix screen overrun        jpl */
  42. };
  43. LCL   IntT  CDC   Siz4[] =
  44. {   0,  4, 19, 13, 35, 39
  45. };
  46. LCL   ChrP  CDC   Wdm =                /* delay/no-delay pause message  */
  47.    "Now that you've had a chance to see the various features "
  48.    "of the TCXL Window System, we'd like to give you a chance "
  49.    "to see the SAME demonstation again . . . this "
  50.    "time, without the built-in delays.  Press any key to "
  51.    "start this one running.  Watch out!";
  52.  
  53. /*---------------------[ Local function prototypes ]--------------------*/
  54.  
  55. LCL   VOID  CTYP  ActivDemo(NOARG);
  56. LCL   VOID  CTYP  AttrDemo(NOARG);
  57. LCL   VOID  CTYP  BordDemo(NOARG);
  58. LCL   VOID  CTYP  ChgWindAttr(AtrT battr, AtrT wattr);
  59. LCL   VOID  CTYP  CloseWinDemo(NOARG);
  60. LCL   VOID  CTYP  CopyDemo(NOARG);
  61. LCL   VOID  CTYP  DemoWait(NOARG);
  62. LCL   VOID  CTYP  DisplayTitle(BytT tpos);
  63. LCL   VOID  CTYP  DragWindow(IntT nsrow, IntT nscol);
  64. LCL   VOID  CTYP  HideDemo(NOARG);
  65. LCL   VOID  CTYP  HorzLine(BytT wrow, BytT wcol, IntT count, AtrT attr);
  66. LCL   VOID  CTYP  MoveDemo(NOARG);
  67. LCL   VOID  CTYP  MoveWindow(IntT nsrow, IntT nscol);
  68. LCL   VOID  CTYP  ResizeDemo(NOARG);
  69. LCL   VOID  CTYP  ScrollDemo(NOARG);
  70. LCL   VOID  CTYP  SizeWindow(IntT nerow, IntT necol);
  71. LCL   VOID  CTYP  TLineDemo(NOARG);
  72. LCL   VOID  CTYP  TitleDemo(NOARG);
  73. LCL   VOID  CTYP  VertLine(BytT wrow, BytT wcol, IntT count, AtrT attr);
  74.  
  75. /*=======================[ The TCXL window demo ]=======================*
  76.  | Called from the [W]indow item of the Mid_Demo.C main menu.
  77.  *----------------------------------------------------------------------*/
  78.  
  79. VOID  CTYP  WinDemo(NOARG)
  80. {
  81.    VcelFP   s;
  82.  
  83.    s = FarVsave(LGREY|_BLUE);          /* save screen                   */
  84.    MouPush(MOU_FULL);                  /* full mouse support            */
  85.                                        /* slowly, first, then FAST      */
  86.    for(DemoFast = 0; DemoFast < 2; DemoFast++)
  87.    {  ScrollDemo();                    /* scrolling                     */
  88.       AttrDemo();                      /* attributes                    */
  89.       BordDemo();                      /* borders                       */
  90.       TitleDemo();                     /* titles                        */
  91.       ResizeDemo();                    /* resizing                      */
  92.       TLineDemo();                     /* text lines                    */
  93.       MoveDemo();                      /* moving/dragging               */
  94.       HideDemo();                      /* hiding/unhiding               */
  95.       ActivDemo();                     /* activation                    */
  96.       CopyDemo();                      /* copying                       */
  97.       CloseWinDemo();                  /* close it down                 */
  98.       if(!DemoFast)                    /* warn user not to blink ;-)    */
  99.       {  WpopUp(CNT_CNT, 0, 0, 9, 35, 0, WHITE|_CYAN, YELLOW|_RED);
  100.          Wputsw(Wdm);
  101.          KeyWait();
  102.       }
  103.       else                             /* ask user if he/she missed it  */
  104.       {  WpopUp(CNT_CNT, 0, 0, 2, 25, 0, WHITE|_CYAN, YELLOW|_RED);
  105.          WputCen("Fast enough for you?");
  106.          KeyTime(54);
  107.       }
  108.       Wclose();                        /* close the pop-up              */
  109.    }
  110.    DemoFast = 0;
  111.    MouPop();                           /* restore mouse, screen         */
  112.    FarVrestore(s);
  113.    KeyClear();                         /* clear lurking keys            */
  114.    MoveBarDn();                        /* next main-menu item           */
  115. }  /* WinDemo() */
  116.  
  117. /*-----------------------[ Window scrolling demo ]----------------------*/
  118.  
  119. LCL   VOID  CTYP  ScrollDemo(NOARG)
  120. {
  121.    REG IntT    i, j;
  122.  
  123.    if(ERR_ARG == (w[0] = Wopen(1, 1, 11, 41, 2, LMAGENTA|_RED, LCYAN|_RED)))
  124.       ErrorExit(1);                    /* windowing error!              */
  125.  
  126.    HlpSet(H_SCROLL);                   /* set help category             */
  127.  
  128.    Wputf("\n  TCXL's window TTY output functions"
  129.          "\n  such as Wputs() and Wputf() allow"
  130.          "\n  scrolling and ANSI-like Escape code"
  131.          "\n  sequences from inside of windows.");
  132.    PressAKey(6);                       /* pause for a keypress          */
  133.  
  134.    Wgotoxy(8, 0);                      /* set cursor position           */
  135.    for(i = 0; i < 10; i++)
  136.    {  for(j = DGREY; j <= WHITE; j++)
  137.       {  Wputf("\033F%cTCXL  ", j);    /* display "TCXL" over and over  */
  138.          if(!DemoFast)                 /* changing attributes each time */
  139.             _Delay(1);
  140.       }
  141.    }
  142. }  /* ScrollDemo() */
  143.  
  144. /*-----------------------[ Window attribute demo ]----------------------*/
  145.  
  146. LCL   VOID  CTYP  AttrDemo(NOARG)
  147. {
  148.    if(ERR_ARG == (w[1] = Wopen(9, 35, 22, 65, 0, YELLOW|_BLUE, LCYAN|_BLUE)))
  149.       ErrorExit(1);                    /* windowing error!              */
  150.  
  151.    HlpSet(H_CHGATTR);                  /* set help category             */
  152.  
  153.    Wputs("\n  The WchgAtr() function"
  154.         "\n  allows you to change the"
  155.         "\n  attribute of the active"
  156.         "\n  window.");
  157.    PressAKey(6);                       /* pause for a keypress          */
  158.  
  159.    ChgWindAttr(LMAGENTA|_BLUE, WHITE|_GREEN);   /* change attributes    */
  160.    ChgWindAttr(GREEN|_LGREY, LMAGENTA|_RED);
  161.    ChgWindAttr(YELLOW|_BROWN, LCYAN|_BLUE);
  162.    ChgWindAttr(YELLOW|_MAGENTA, YELLOW|_MAGENTA);
  163.    ChgWindAttr(LCYAN|_MAGENTA, WHITE|_MAGENTA);
  164. }  /* AttrDemo() */
  165.  
  166. /*---------------------[ Change window attributes ]---------------------*/
  167.  
  168. LCL   VOID  CTYP  ChgWindAttr(AtrT battr, AtrT wattr)
  169. {
  170.    WchgAtr(battr, wattr);              /* set attributes                */
  171.  
  172.    DemoWait();
  173. }  /* ChgWindAttr() */
  174.  
  175. /*------------------------[ Window border demo ]------------------------*/
  176.  
  177. LCL   VOID  CTYP  BordDemo(NOARG)
  178. {
  179.    REG IntT i;
  180.  
  181.    HlpSet(H_CHGBORD);                  /* set help category             */
  182.    WsetTxt(LGREEN|_MAGENTA);           /* text attribute                */
  183.  
  184.    Wputs("\n\n  The Wborder() function is"
  185.            "\n  used to change the style"
  186.            "\n  of the window's border.");
  187.    PressAKey(10);                      /* pause for a keypress          */
  188.  
  189.    for(i = 5; i >= 0; i--)
  190.    {  Wborder(MsByt(i));               /* keep changing border types    */
  191.       DemoWait();
  192.    }
  193. }  /* BordDemo() */
  194.  
  195. /*-------------------------[ Window title demo ]------------------------*/
  196.  
  197. LCL   VOID  CTYP  TitleDemo(NOARG)
  198. {
  199.    if(ERR_ARG == (w[2] = Wopen(5, 20, 19, 45, 3, LCYAN|_GREEN, WHITE|_GREEN)))
  200.       ErrorExit(1);                    /* windowing error!              */
  201.  
  202.    HlpSet(H_WINTITLE);                 /* set help category             */
  203.  
  204.    Wputs("\n  The Wtitle() function"
  205.          "\n  allows you to give a"
  206.          "\n  window a title.");
  207.    PressAKey(5);                       /* pause for a keypress          */
  208.  
  209.    DisplayTitle(TTL_LFT);              /* show off titles               */
  210.    DisplayTitle(TTL_RGT);
  211.    DisplayTitle(TTL_CNT);
  212. }  /* TitleDemo() */
  213.  
  214. /*-----------------------[ Display window title ]-----------------------*/
  215.  
  216. LCL   VOID  CTYP  DisplayTitle(BytT tpos)
  217. {
  218.    Wtitle("[ My Title ]", tpos, LCYAN|_GREEN);
  219.  
  220.    DemoWait();
  221. }  /* DisplayTitle() */
  222.  
  223. /*------------------------[ Window resize demo ]------------------------*/
  224.  
  225. LCL   VOID  CTYP  ResizeDemo(NOARG)
  226. {
  227.    IntT i;
  228.  
  229.    HlpSet(H_RESIZE);                   /* set help category             */
  230.    WsetTxt(BLUE|_GREEN);               /* text attribute                */
  231.  
  232.    Wputs("\n\n\n  The Wsize() function"
  233.              "\n  allows you to resize"
  234.              "\n  the active window.");
  235.    PressAKey(10);                      /* wait for a keypress           */
  236.  
  237.    for(i = 0; i < 6; i++)              /* resize the window             */
  238.       SizeWindow(Siz1[i], Siz2[i]);
  239. }  /* ResizeDemo() */
  240.  
  241. /*--------------------------[ Resize a window ]-------------------------*/
  242.  
  243. LCL   VOID  CTYP  SizeWindow(IntT r, IntT c)
  244. {
  245.    Wsize(r, c);
  246.    DemoWait();
  247. }  /* SizeWindow() */
  248.  
  249. /*-----------------------[ Window text-line demo ]----------------------*/
  250.  
  251. LCL   VOID  CTYP  TLineDemo(NOARG)
  252. {
  253.    if(ERR_ARG == (w[3] = Wopen(10, 3, 23, 41, 3, YELLOW|_BLUE, LMAGENTA|_BLUE)))
  254.       ErrorExit(1);                    /* windowing error!              */
  255.  
  256.    HlpSet(H_TEXTLINE);                 /* set help category             */
  257.  
  258.    Wputs("\n The WdrwHor() & WdrwVer() functions"
  259.          "\n are used for drawing \"smart\" text"
  260.          "\n lines which will even make their "
  261.          "\n own corners and intersections!   ");
  262.    PressAKey(6);                       /* pause for a keypress          */
  263.  
  264.    HorzLine( 6,  6, 24, LCYAN|_BLUE);  /* draw a fancy box with joins   */
  265.    VertLine( 6,  6,  4, LCYAN|_BLUE);
  266.    HorzLine(10,  6, 24, LCYAN|_BLUE);
  267.    VertLine( 6, 30,  5, LRED|_BLUE);
  268.    VertLine( 6, 18,  5, LRED|_BLUE);
  269.    HorzLine( 7,  6, 25, LRED|_BLUE);
  270.    HorzLine( 9,  6, 25, LGREEN|_BLUE);
  271.    VertLine( 6, 11,  5, LGREEN|_BLUE);
  272.    VertLine( 6, 23,  5, LGREEN|_BLUE);
  273.    HorzLine( 8,  6, 25, LMAGENTA|_BLUE);
  274. }  /* TLineDemo() */
  275.  
  276. /*----------------------[ Draw a horizontal line ]----------------------*/
  277.  
  278. LCL   VOID  CTYP  HorzLine(BytT r, BytT c, IntT n, AtrT a)
  279. {
  280.    WdrwHor(r, c, MsByt(n), 3, a);
  281.    DemoWait();
  282. }  /* HorzLine() */
  283.  
  284. /*-----------------------[ Draw a vertical line ]-----------------------*/
  285.  
  286. LCL   VOID  CTYP  VertLine(BytT r, BytT c, IntT n, AtrT a)
  287. {
  288.    WdrwVer(r, c, MsByt(n), 3, a);
  289.    DemoWait();
  290. }  /* VertLine() */
  291.  
  292. /*-------------------------[ Window move demo ]-------------------------*/
  293.  
  294. LCL   VOID  CTYP  MoveDemo(NOARG)
  295. {
  296.    IntT i;
  297.  
  298.    if(ERR_ARG == (w[4] = Wopen(4, 2, 20, 35, 2, YELLOW|_CYAN, YELLOW|_CYAN)))
  299.       ErrorExit(1);                    /* windowing error!              */
  300.  
  301.    HlpSet(H_WINMOVE);                  /* set help category             */
  302.  
  303.    Wputs("\n   To move the active window,"
  304.          "\n   the Wmove() function is"
  305.          "\n   used.");
  306.    PressAKey(5);                       /* pause for a keypress          */
  307.  
  308.    for(i = 0; i < 6; i++)              /* move it around                */
  309.       MoveWindow(Siz3[i], Siz4[i]);
  310.  
  311.    Wputs("\n\n   Or if you prefer flashier,"
  312.            "\n   window movement, try"
  313.            "\n   Wslide() instead.");
  314.    PressAKey(9);                       /* pause for a keypress          */
  315.  
  316.    for(i = 0; i < 6; i++)              /* drag it around                */
  317.       DragWindow(Siz3[i], Siz4[i]);
  318. }  /* MoveDemo() */
  319.  
  320. /*---------------------------[ Move a window ]--------------------------*/
  321.  
  322. LCL   VOID  CTYP  MoveWindow(IntT r, IntT c)
  323. {
  324.    if (r+16 >= VidDep)                 /* make Window address       jpl */
  325.       r = VidDep - 17;                 /*   adjust for smaller screens  */
  326.  
  327.    if(Wmove(r, c))
  328.       ErrorExit(1);                    /* windowing error!              */
  329.  
  330.    DemoWait();
  331. }  /* MoveWindow() */
  332.  
  333. /*---------------------------[ Drag a window ]--------------------------*/
  334.  
  335. LCL   VOID  CTYP  DragWindow(IntT r, IntT c)
  336. {
  337.    if(Wslide(r, c))
  338.       ErrorExit(1);                    /* windowing error!              */
  339.  
  340.    DemoWait();
  341. }  /* DragWindow() */
  342.  
  343. /*-----------------------[ Window hide/show demo ]----------------------*/
  344.  
  345. LCL   VOID  CTYP  HideDemo(NOARG)
  346. {
  347.    REG IntT i;
  348.  
  349.    HlpSet(H_WINHIDE);                  /* set help category             */
  350.    WsetTxt(YELLOW|_CYAN);              /* text attribute                */
  351.  
  352.    Wputs("\n\n   The Whide() and Wunhide()"
  353.            "\n   functions are used to hide"
  354.            "\n   and unhide windows.");
  355.    PressAKey(13);                      /* pause for a keypress          */
  356.  
  357.    for(i = 0; i < 5; i++)
  358.    {  if(Whide())                      /* hide all, front to back       */
  359.          ErrorExit(1);                 /* windowing error!              */
  360.  
  361.       DemoWait();
  362.    }
  363.    for(i = 0; i < 5; i++)
  364.    {  if(Wunhide(0))                   /* unhide all, back to front     */
  365.          ErrorExit(1);                 /* windowing error!              */
  366.  
  367.       DemoWait();
  368.    }
  369. }  /* HideDemo() */
  370.  
  371. /*-----------------------[ Window activate demo ]-----------------------*/
  372.  
  373. LCL   VOID  CTYP  ActivDemo(NOARG)
  374. {
  375.    REG IntT    i;
  376.  
  377.    if(ERR_ARG == (w[5] = Wopen(9, 44, 22, 78, 1, LCYAN|_CYAN, WHITE|_CYAN)))
  378.       ErrorExit(1);                    /* windowing error!              */
  379.  
  380.    HlpSet(H_ACTIVATE);                 /* set help category             */
  381.  
  382.    Wputs("\n  TCXL's Wactiv() is used to"
  383.         "\n  activate a window, making"
  384.         "\n  it available for windowing"
  385.         "\n  operations.");
  386.    PressAKey(6);                       /* pause for a keypress          */
  387.  
  388.    for(i = 0; i < 6; i++)
  389.    {  Wactiv(w[i]);                    /* activate windows 0 thru 5    */
  390.       DemoWait();                      /* in order, back to front      */
  391.    }
  392. }  /* ActivDemo() */
  393.  
  394. /*-------------------------[ Window copy demo ]-------------------------*/
  395.  
  396. LCL   VOID  CTYP  CopyDemo(NOARG)
  397. {
  398.    HlpSet(H_WINCOPY);                  /* set help category             */
  399.    WsetTxt(LCYAN|_CYAN);               /* text attribute                */
  400.  
  401.    Wputs("\n\n  The Wcopy() function is used"
  402.            "\n  to copy the active window.");
  403.    PressAKey(9);                       /* pause for a keypress          */
  404.  
  405.    if(!Wcopy(1, 1))
  406.       ErrorExit(1);                    /* windowing error!              */
  407.  
  408.    DemoWait();
  409.    if(!Wcopy(3, 40))
  410.       ErrorExit(1);                    /* windowing error!              */
  411.  
  412.    DemoWait();
  413. }  /* CopyDemo() */
  414.  
  415. /*---------------------[ Close out the window demo ]--------------------*/
  416.  
  417. LCL   VOID  CTYP  CloseWinDemo(NOARG)
  418. {
  419.    REG IntT    i;
  420.  
  421.    for(i = 0; i < 8; i++)
  422.    {  Wclose();                        /* close all windows             */
  423.       DemoWait();
  424.    }
  425. }  /* CloseWinDemo() */
  426.  
  427. /*-------------------[ Control delay in window demo ]-------------------*/
  428.  
  429. LCL   VOID  CTYP  DemoWait(NOARG)
  430. {
  431.    if(DemoFast)
  432. #if   defined(__TERMINAL__)            /* if running to TTY         jpl */
  433.       _TTYupdate();                    /* make sure up to date      jpl */
  434. #else                                  /*                           jpl */
  435.       return;                          /* no delay                      */
  436. #endif                                 /*                           jpl */
  437.    else
  438.       _Delay(5);                       /* delay for 5 clock-ticks       */
  439. }
  440.  
  441. /*- end of Win_Demo.C --------------------------------------------------*/
  442.  
  443.