home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / helpde / helpdemo.cpp
Encoding:
C/C++ Source or Header  |  1991-11-14  |  4.8 KB  |  187 lines

  1. #define Uses_TApplication
  2. #define Uses_TDeskTop
  3. #define Uses_TMenuItem
  4. #define Uses_TMenu
  5. #define Uses_TMenuBar
  6. #define Uses_TStatusItem
  7. #define Uses_TStatusDef
  8. #define Uses_TStatusLine
  9. #define Uses_TKeys
  10. #define Uses_TRect
  11. #define Uses_TEvent
  12. #define Uses_TButton
  13. #define Uses_TStaticText
  14. #define Uses_TDialog
  15. #include <tv.h>
  16.  
  17. const unsigned short cmHelpDemoCmd = 100;
  18.  
  19. const unsigned short hcFirst        = 100;      // First context
  20. const unsigned short hcButtonOne    = 100;
  21. const unsigned short hcButtonTwo    = 101;
  22. const unsigned short hcButtonHelp   = 102;
  23. const unsigned short hcHelpDemo     = 103;
  24. const unsigned short hcExit         = 104;
  25. const unsigned short hcDemoMenu     = 105;
  26. const unsigned short hcLast         = 104;      // Last context
  27.  
  28. char *helpString[] = {
  29.     "Button One!",
  30.     "Button Two",
  31.     "Button Help",
  32.     "Help Demo Window",
  33.     "Exit program",
  34.     "Demo menu"
  35. };
  36.  
  37. TMenuItem& operator+ (TMenuItem& one, TMenuItem& two)
  38. {
  39.     TMenuItem *p = &one;
  40.     while( p->next != NULL )
  41.         p = p->next;
  42.     p->next = &two;
  43.     return( one );
  44. }
  45.  
  46.  
  47. //
  48. // ---------------------> Classes
  49. //
  50. class THintStatusLine : public TStatusLine
  51. {
  52.  
  53. public:
  54.  
  55.     THintStatusLine(TRect r, TStatusDef& def) : TStatusLine( r, def ) { }
  56.     virtual const char *hint(ushort aHelpCtx)
  57.         {
  58.         if( aHelpCtx >= hcFirst && aHelpCtx <= hcLast )
  59.             return( helpString[aHelpCtx-100] );
  60.         else
  61.             return( "" );           // Don't return 0 here.
  62.         }
  63. };
  64.  
  65. class TMyApp : public TApplication
  66. {
  67.  
  68. public:
  69.  
  70.     TMyApp() : TProgInit(&TMyApp::initStatusLine,
  71.                          &TMyApp::initMenuBar,
  72.                          &TMyApp::initDeskTop ) { }
  73.     static TMenuBar *initMenuBar( TRect r );
  74.     static TStatusLine *initStatusLine( TRect r );
  75.     virtual void handleEvent( TEvent& event);
  76. };
  77.  
  78. class THelpDemo : public TDialog
  79. {
  80. public:
  81.     THelpDemo();
  82. };
  83.  
  84.  
  85. //
  86. // Member functions of TMyApp
  87. //
  88. TMenuBar *TMyApp::initMenuBar( TRect bounds )
  89. {
  90.     bounds.b.y = bounds.a.y + 1;
  91.  
  92.     TMenuBar *mainMenu = new TMenuBar (bounds, new TMenu(
  93.         *new TMenuItem("~D~emos", kbAltD, new TMenu(
  94.             *new TMenuItem("~H~elp Demo", cmHelpDemoCmd, kbAltH, hcHelpDemo) +
  95.              newLine() +
  96.             *new TMenuItem("E~x~it", cmQuit, kbAltX, hcExit, "Alt-X")
  97.             ), hcDemoMenu)
  98.         ));
  99.  
  100.     return( mainMenu );
  101. }
  102.  
  103. TStatusLine *TMyApp::initStatusLine( TRect bounds )
  104. {
  105.     bounds.a.y = bounds.b.y - 1;
  106.  
  107.     THintStatusLine *statusLine = new THintStatusLine (bounds,
  108.         *new TStatusDef(0, hcFirst-1) +
  109.             *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
  110.             *new TStatusItem("~Alt-H~ Help Demo", kbAltH, cmHelpDemoCmd) +
  111.         *new TStatusDef(hcFirst, hcButtonHelp) +
  112.             *new TStatusItem("~Alt-F3~ Close", kbAltF3, cmClose) +
  113.             *new TStatusItem("~Alt-O~ Open", kbAltO, cmClose) +
  114.             *new TStatusItem("~Alt-C~ Cancel", kbAltC, cmClose) +
  115.             *new TStatusItem("~Alt-H~ Help", kbAltH, cmHelp) +
  116.         *new TStatusDef(hcButtonHelp + 1, 0xFFFF) +
  117.             *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
  118.             *new TStatusItem("~Alt-H~ Help Demo", kbAltH, cmHelpDemoCmd)
  119.         );
  120.  
  121.     return (statusLine);
  122. }
  123.  
  124. void TMyApp::handleEvent(TEvent& event)
  125. {
  126.     TApplication::handleEvent(event);
  127.  
  128.     switch(event.what)
  129.     {
  130.         case evCommand:             // handle COMMAND events
  131.         {
  132.             switch(event.message.command)
  133.             {
  134.                 case cmHelpDemoCmd:
  135.                 {
  136.                     TView *helpBox = new THelpDemo;
  137.                     if( validView(helpBox) )
  138.                         deskTop->insert( helpBox );
  139.                     break;
  140.                 }
  141.                 default:
  142.                     return;
  143.             }
  144.             clearEvent(event);      // Clear the event we handled
  145.         }
  146.     }
  147. }
  148.  
  149.  
  150. THelpDemo::THelpDemo() :
  151.     TDialog(TRect(0, 0, 30, 12), "Help Demo Box"),
  152.     TWindowInit(&THelpDemo::initFrame)
  153. {
  154.     TView *control = new TStaticText(TRect(2, 5, 17, 7), "Example of help contexts");
  155.     insert(control);
  156.  
  157.     TView *defControl = new TButton(TRect(18,2,28,4), "~O~K", cmClose, bfDefault);
  158.     defControl->helpCtx = hcButtonOne;
  159.     insert(defControl);
  160.  
  161.     control = new TButton(TRect(18,5,28,7), "~C~ancel", cmClose, bfNormal);
  162.     control->helpCtx = hcButtonTwo;
  163.     insert(control);
  164.  
  165.     control = new TButton(TRect(18,8,28,10), "~H~elp", cmHelp, bfNormal);
  166.     control->helpCtx = hcButtonHelp;
  167.     insert(control);
  168.  
  169.     setCurrent(defControl, normalSelect);
  170.     options |= ofCentered;
  171. }
  172.  
  173.  
  174. //
  175. //---------------   MAIN   ------------------
  176. //
  177. int main()
  178. {
  179.     TMyApp myApp;
  180.  
  181.     myApp.run();
  182.  
  183.     return( 0 );
  184. }
  185.  
  186.  
  187.