home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / bcpp / file18 / expdemo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  8.5 KB  |  297 lines

  1. // Program : EXPDEMO.CPP
  2. // Author  : Eric Woodruff,  CIS ID: 72134,1150
  3. // Updated : Wed 08/25/93 10:02:42
  4. // Note    : Copyright 1993, Eric Woodruff, All rights reserved
  5. // Compiler: Borland C++ 3.1
  6. //
  7. // This is a demonstration program that puts the TExplodeWindow
  8. // and TExplodeDialog classes through their paces.  One demo lets you see
  9. // an exploding window while another lets you see an exploding dialog box.
  10. // The last two demonstrations are streamable variations on the first two
  11. // from a resource file.
  12. //
  13. // NOTE: Change the IDE Compiler Directories if necessary and turn on the
  14. //       debugger options if needed when using the supplied EXPDEMO.PRJ.
  15. //
  16.  
  17. #include <conio.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21.  
  22. #define Uses_MsgBox
  23. #define Uses_TApplication
  24. #define Uses_TButton
  25. #define Uses_TDeskTop
  26. #define Uses_TCheckBoxes
  27. #define Uses_TDialog
  28. #define Uses_TEvent
  29. #define Uses_TInputLine
  30. #define Uses_TKeys
  31. #define Uses_TLabel
  32. #define Uses_TMenuBar
  33. #define Uses_TMenuItem
  34. #define Uses_TProgram
  35. #define Uses_TRadioButtons
  36. #define Uses_TRect
  37. #define Uses_TResourceFile
  38. #define Uses_TScreen
  39. #define Uses_TSItem
  40. #define Uses_TStaticText
  41. #define Uses_TStatusDef
  42. #define Uses_TStatusItem
  43. #define Uses_TStatusLine
  44. #define Uses_TSubMenu
  45. #define Uses_fpstream
  46. #include <tv.h>
  47.  
  48. extern TPoint shadowSize;       // Used for changing screen modes.
  49.  
  50. __link(RButton)
  51. __link(RCheckBoxes)
  52. __link(RCluster )
  53. __link(RInputLine)
  54. __link(RLabel)
  55. __link(RMenuBar)
  56. __link(RRadioButtons)
  57. __link(RResourceCollection)
  58. __link(RStaticText)
  59. __link(RStatusLine)
  60.  
  61. #define Uses_TExplodeWindow
  62. #define Uses_TExplodeDialog
  63. #include <texplode.h>           // TExplodeWindow/TExplodeDialog header file.
  64. #include <expdemo.h>            // Demo header file
  65.  
  66. // NOTE: Always be sure to include these two lines somewhere in your
  67. //       program if you are using streamed TExplodeWindow and/or
  68. //       TExplodeDialog objects (i.e. loading them from a resource file)!
  69. __link(RExplodeWindow)
  70. __link(RExplodeDialog)
  71.  
  72. // Function that returns True when there is a tileable window in the desktop.
  73. static Boolean isTileable(TView *p, void *);
  74.  
  75. // ****************************************************************************
  76. // Demonstration declarations and variables.
  77.  
  78. // Resource file pointers.
  79. fpstream *s;
  80. TResourceFile *rsc;
  81.  
  82. // ****************************************************************************
  83. // Application declarations.
  84. //
  85. TMyApplication::TMyApplication(void) :
  86.     TProgInit(&TMyApplication::initStatusLine, &TMyApplication::initMenuBar,
  87.               &TMyApplication::initDeskTop)
  88. {
  89.     TEvent event;
  90.  
  91. // If you haven't got the Turbo Vision source code or don't want to
  92. // modify it, uncomment this line to speed up the screen updates.
  93. //
  94. //    TScreen::checkSnow = False;        // Turn off snow checking.
  95.  
  96.     event.what = evCommand;
  97.     event.message.command = cmAboutCmd;
  98.     putEvent(event);
  99. }
  100.  
  101. #pragma argsused
  102. TMenuBar *TMyApplication::initMenuBar(TRect r)
  103. {
  104.     return (TMenuBar *)rsc->get("MenuBar");
  105. }
  106.  
  107. #pragma argsused
  108. TStatusLine *TMyApplication::initStatusLine(TRect r)
  109. {
  110.     return (TStatusLine *)rsc->get("StatusLine");
  111. }
  112.  
  113. void TMyApplication::handleEvent(TEvent &event)
  114. {
  115.     TApplication::handleEvent(event);
  116.  
  117.     if(event.what == evCommand)
  118.     {
  119.         switch (event.message.command)
  120.         {
  121.             case cmAboutCmd:
  122.                 deskTop->execView((TDialog *)rsc->get("AboutBox"));
  123.                 break;
  124.  
  125.             case cmCloseTileable:
  126.                 while(deskTop->firstThat(isTileable, 0))
  127.                     message(deskTop, evCommand, cmClose, NULL);
  128.                 break;
  129.  
  130.             case cmScreenSize:      // Change screen modes.
  131.                 ushort NewSize = TScreen::screenMode ^ TDisplay::smFont8x8;
  132.  
  133.                 if(NewSize & TDisplay::smFont8x8)
  134.                     shadowSize.x = 1;
  135.                 else
  136.                     shadowSize.x = 2;
  137.  
  138.                 setScreenMode(NewSize);
  139.  
  140.                 // Adjust mouse limits if present.
  141.                 if(TMouse::present())
  142.                     TMouse::setRange(TScreen::screenWidth - 1,
  143.                         TScreen::screenHeight - 1);
  144.                 break;
  145.  
  146.             case cmTile:                //  Tile current windows
  147.                 deskTop->tile(deskTop->getExtent());
  148.                 break;
  149.  
  150.             case cmCascade:             //  Cascade current windows
  151.                 deskTop->cascade(deskTop->getExtent());
  152.                 break;
  153.  
  154.             case cmDemo1:           // TExplodeWindow demo.
  155.                 Demo1();
  156.                 break;
  157.  
  158.             case cmDemo2:           // TExplodeDialog demo.
  159.                 Demo2();
  160.                 break;
  161.  
  162.             case cmDemo3:
  163.                 // Get TExplodeWindow from stream.  Does what Demo1() does
  164.                 // but restores objects from the resource file.
  165.                 TExplodeWindow *xw = (TExplodeWindow *)rsc->get("Demo3");
  166.  
  167.                 if(validView(xw))
  168.                     deskTop->insert(xw);
  169.                 break;
  170.  
  171.             case cmDemo4:
  172.                 // Get TExplodeDialog from stream.  Does what Demo2() does
  173.                 // but restores objects from the resource file.
  174.                 TExplodeDialog *xd = (TExplodeDialog *)rsc->get("Demo4");
  175.  
  176.                 if(validView(xd))
  177.                 {
  178.                     deskTop->execView(xd);
  179.                     destroy(xd);
  180.                 }
  181.                 break;
  182.  
  183.             default:
  184.                 return;
  185.         }
  186.         clearEvent(event);
  187.     }
  188. }
  189.  
  190. void TMyApplication::Demo1(void)
  191. {
  192.     randomize();
  193.  
  194.     // Randomly select an initial size and position.
  195.     TRect r(0, 0, 20 + rand() % 53, 6 + rand() % 16);
  196.  
  197.     r.move(rand() % 30, rand() % 10);
  198.  
  199.     TExplodeWindow *xw = new TExplodeWindow(r, "Demo Exploding Window", 0);
  200.     xw->MakeItExplode(rand() % 50);     // Random delay.
  201.  
  202.     // Make it tileable and let it grow and shrink with the screen mode.
  203.     xw->options |= ofTileable;
  204.     xw->growMode = gfGrowAll | gfGrowRel;
  205.  
  206.     r = xw->getExtent();
  207.     r.grow(-1, -1);
  208.  
  209.     TStaticText *s = new TStaticText(r, "This is a test.");
  210.     s->growMode = gfGrowHiX | gfGrowHiY;
  211.     xw->insert(s);
  212.  
  213.     if(validView(xw))
  214.         deskTop->insert(xw);
  215. }
  216.  
  217. void TMyApplication::Demo2(void)
  218. {
  219.     TExplodeDialog *dlg = new TExplodeDialog(TRect(4,0,76,22),
  220.         "General Information");
  221.  
  222.     if(!dlg)
  223.         return;
  224.  
  225.     dlg->options = ofCentered;
  226.  
  227.     TButton *b = new TButton(TRect(30,19,42,21), "O~K~", cmOK, bfDefault);
  228.     b->options = ofCenterX;
  229.     dlg->insert(b);
  230.  
  231.     TStaticText *s = new TStaticText(TRect(15,2,56,4),
  232.         "\003TExplodeWindow and TExplodeDialog Classes\n"
  233.         "\003by Eric Woodruff");
  234.     s->options = ofCenterX;
  235.     dlg->insert(s);
  236.  
  237.     s = new TStaticText(TRect(3,5,69,11),
  238.         "\003If you use these classes in your own programs, please send"
  239.         " $10 to:\n\003\n\003Eric Woodruff\n"
  240.         "\00316719 Lakeside Drive\n"
  241.         "\003Medical Lake WA 99022");
  242.     s->options = ofCenterX;
  243.     dlg->insert(s);
  244.  
  245.     s = new TStaticText(TRect(3,11,69,15),
  246.         "Feel free to distribute these files to anyone but please distribute"
  247.         " all of them in UNMODIFIED form.  If you find any bugs or make any"
  248.         " interesting changes, please let me know so that I can maintain"
  249.         " these classes and distribute updates.");
  250.     s->options = ofCenterX;
  251.     dlg->insert(s);
  252.  
  253.     s = new TStaticText(TRect(8,16,64,18),
  254.         "\003I can also be reached on CompuServe at 72134,1150\n"
  255.         "\003Thanks for trying them out!");
  256.     s->options = ofCenterX;
  257.     dlg->insert(s);
  258.  
  259.     dlg->selectNext(False);
  260.     if(validView(dlg))
  261.     {
  262.         deskTop->execView(dlg);
  263.         destroy(dlg);
  264.     }
  265. }
  266.  
  267. // ****************************************************************************
  268. void main(void)
  269. {
  270.     s = new fpstream("EXPDEMO.RSC", ios::in | ios::nocreate | ios::binary);
  271.     if(!s->good())
  272.     {
  273.         cerr << "Error opening resource file EXPDEMO.RSC!  Press any key.";
  274.         getch();
  275.         exit(1);
  276.     }
  277.  
  278.     rsc = (TResourceFile *)new TResourceFile(s);
  279.     if(!rsc)
  280.     {
  281.         cerr << "Could not allocate resource file memory!";
  282.         exit(1);
  283.     }
  284.  
  285.     TMyApplication MyApp;
  286.     MyApp.run();
  287.     exit(0);
  288. }
  289.  
  290. //
  291. // The isTileable() function checks for a tileable view on the desktop.
  292. //
  293. static Boolean isTileable(TView *p, void *)
  294. {
  295.     return (p->options & ofTileable) ? True : False;
  296. }
  297.