home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / mess1 / myapp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-31  |  5.9 KB  |  235 lines

  1. //========================================================================
  2. //  The following example routines have been provided by the Technical
  3. //  Support staff at Borland International.  They are provided as a
  4. //  courtesy and not as part of a Borland product, and as such, are
  5. //  provided without the assurance of technical support or any specific
  6. //  guarantees.
  7. //========================================================================
  8. //  Turbo Vision - Example of message passing
  9. //
  10. //------------------------------------------------------------------------
  11. //
  12. // myapp.cpp:  The member function definition for TMyApplication.
  13. //
  14. //========================================================================
  15.  
  16. #define Uses_TKeys
  17. #define Uses_TMenuItem
  18. #define Uses_TSubMenu
  19. #define Uses_TStatusLine
  20. #define Uses_TStatusDef
  21. #define Uses_TStatusItem
  22. #define Uses_TEvent
  23. #define Uses_TDialog
  24. #define Uses_TStaticText
  25. #define Uses_TButton
  26. #define Uses_TDeskTop
  27. #define Uses_TWindow
  28. #include <tv.h>
  29. #include <strstrea.h>
  30. #include <stdlib.h>
  31. #include "cmds.h"
  32. #include "myapp.h"
  33. #include "myview.h"
  34. #include "heapview.h"
  35. #include "dialog.h"
  36.  
  37. int windowFlag = 0;
  38.  
  39. //
  40. // TMyApplication - Constructor.
  41. //
  42.  
  43. TMyApplication::TMyApplication() :
  44.     TProgInit( &TMyApplication::initStatusLine,
  45.                &TMyApplication::initMenuBar,
  46.                &TMyApplication::initDeskTop )
  47. {
  48. }
  49.  
  50.  
  51. //
  52. // initMenuBar - Initialize the menu bar. It will be called by the virtual base
  53. //               TProgInit constructor.
  54. //
  55.  
  56. TMenuBar *TMyApplication::initMenuBar( TRect bounds )
  57. {
  58.     bounds.b.y = bounds.a.y + 1;
  59.  
  60.     TMenuBar *mainMenu =
  61.         new TMenuBar (bounds,
  62.             *new TSubMenu ("~≡~", kbAltSpace) +
  63.                  *new TMenuItem ("~A~bout...", cmAboutCmd, kbAltA, hcNoContext,
  64.                                  "Alt-A") +
  65.                  newLine() +
  66.                  *new TMenuItem ("~E~xit", cmQuit, kbAltE, hcNoContext,
  67.                                  "Alt-E") +
  68.  
  69.             *new TSubMenu("~W~indow", kbAltW) +
  70.                  *new TMenuItem("~O~pen", cmOpenCmd, kbF2, hcNoContext,
  71.                                 "F2") +
  72.                  *new TMenuItem("~C~lose", cmClose, kbAltF3, hcNoContext,
  73.                                 "Alt-F3") +
  74.  
  75.             *new TSubMenu("~D~ata entry", kbAltD) +
  76.                  *new TMenuItem("~T~ech Info...", cmTechCmd, kbF3, hcNoContext,
  77.                                 "F3"));
  78.  
  79.     return ( mainMenu );
  80. }
  81.  
  82.  
  83. //
  84. // initStatusLine - Initialize the status line. It will be called by the
  85. //                  virtual base TProgInit constructor.
  86. //
  87.  
  88. TStatusLine *TMyApplication::initStatusLine( TRect bounds )
  89. {
  90.     bounds.a.y = bounds.b.y - 1;
  91.  
  92.     TStatusLine *statusLine =
  93.         new TStatusLine (bounds,
  94.             *new TStatusDef(0, 0xFFFF) +
  95.             *new TStatusItem("~Alt-X~ Exit", kbAltX, cmQuit) +
  96.             *new TStatusItem("~Alt-A~ About", kbAltA, cmAboutCmd) +
  97.  
  98.             *new TStatusItem("~F2~ Open", kbF2, cmOpenCmd) +
  99.             *new TStatusItem("~Alt-F3~ Close", kbAltF3, cmClose) +
  100.  
  101.             *new TStatusItem("~F3~ Tech", kbF3, cmTechCmd));
  102.  
  103.     return (statusLine);
  104. }
  105.  
  106.  
  107. //
  108. // handleEvent - Need to handle the event for the menu and status line choice
  109. //               cmAboutCmd.
  110. //
  111.  
  112. void TMyApplication::handleEvent(TEvent& event)
  113. {
  114.     TApplication::handleEvent(event);
  115.  
  116.     switch(event.what)
  117.     {
  118.         case evCommand:
  119.         {
  120.             switch(event.message.command)
  121.             {
  122.                 case cmAboutCmd:
  123.                 {
  124.                     aboutDlg();
  125.                     break;
  126.                 }
  127.  
  128.                 case cmOpenCmd:
  129.                 {
  130.                     window();
  131.                     break;
  132.                 }
  133.  
  134.                 case cmTechCmd:
  135.                 {
  136.                     techDlg();
  137.                     break;
  138.                 }
  139.                 default:
  140.                   return;
  141.             }
  142.             clearEvent(event);
  143.         }
  144.     }
  145. }
  146.  
  147.  
  148. //
  149. // aboutDlg - Creates a about dialog box and execute the dialog box.
  150. //
  151.  
  152. void TMyApplication::aboutDlg()
  153. {
  154.     TDialog *aboutDlgBox = new TDialog(TRect(0, 0, 47, 14),"About");
  155.     char temp[200];
  156.  
  157.     ostrstream(temp,200) << "\003message.cpp\n\003\n"
  158.                          << "\003C++ Version 1.00\n\003\n"
  159.                          << "\n\003\n"
  160.                          << ends;
  161.  
  162.  
  163.     if (aboutDlgBox)
  164.     {
  165.         aboutDlgBox->insert(new TStaticText(TRect(2,2,45,9),temp));
  166.         aboutDlgBox->insert(new TButton(TRect(18,10,29,12),"OK",cmOK,bfDefault));
  167.  
  168.         aboutDlgBox->options |= ofCentered;
  169.  
  170.         if (validView(aboutDlgBox) != 0)
  171.         {
  172.             deskTop->execView(aboutDlgBox);
  173.  
  174.             destroy(aboutDlgBox);
  175.         }
  176.     }
  177. }
  178.  
  179.  
  180. //
  181. // window() - Open a window with a view for my name in inside.
  182. //
  183.  
  184. void TMyApplication::window()
  185. {
  186.     TWindow *win = new TWindow(TRect(0,0,80,23), "Data base", wnNoNumber);
  187.  
  188.  
  189.     if (win)
  190.     {
  191.         win->eventMask |= evBroadcast;
  192.  
  193.         TRect bounds = win->getExtent();
  194.  
  195.         bounds.grow(-1,-1);
  196.  
  197.         win->insert(new TMyView(bounds));
  198.  
  199.         if (validView(win) != 0)
  200.         {
  201.             deskTop->insert(win);
  202.         }
  203.     }
  204. }
  205.  
  206.  
  207. //
  208. // techDlg - Load the data entry dialog and execute it.
  209. //
  210.  
  211. void TMyApplication::techDlg()
  212. {
  213.     TDataEntryDlg *entry = new TDataEntryDlg(TRect(0,0,56,17),"Tech Info");
  214.  
  215.     entry->options |= ofCentered;
  216.  
  217.     if (validView(entry) != 0)
  218.     {
  219.         if (execView(entry) == cmOK)
  220.         {
  221.           char *data = new char[entry->dataSize()];
  222.           entry->getData(data);
  223.  
  224.           if (!windowFlag)
  225.           {
  226.               message(deskTop->owner,evCommand,cmOpenCmd,0);
  227.           }
  228.           message(deskTop->owner,evBroadcast,cmNewRecord,data);
  229.         }
  230.  
  231.         destroy(entry);
  232.     }
  233. }
  234.  
  235.