home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / TI_BC1.ZIP / TI1707.ZIP / TI1707.ASC
Text File  |  1993-10-12  |  5KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1707
  9.   VERSION  :  All
  10.        OS  :  DOS
  11.      DATE  :  October 12, 1993                         PAGE  :  1/4
  12.  
  13.     TITLE  :  Broadcast to close a Turbo Vision Modeless Dialog
  14.  
  15.  
  16.  
  17.  
  18.   /*
  19.     This is a sample program that demonstrates how to send a
  20.     broadcast to tell a modeless view to close itself.
  21.   */
  22.  
  23.   #include <iostream.h>
  24.  
  25.   #define Uses_TApplication
  26.   #define Uses_TDeskTop
  27.   #define Uses_TMenuBar
  28.   #define Uses_TSubMenu
  29.  
  30.   #include <tv.h>
  31.   #include <tkeys.h>
  32.   #include <util.h>
  33.  
  34.   const unsigned int cmMakeView       = 100;
  35.   const unsigned int cmRemoveView     = 101;
  36.   const unsigned int cmRemoveYourself = 102;
  37.  
  38.   class TMyView : public TView
  39.   {
  40.   private:
  41.     virtual void handleEvent (TEvent& event);
  42.  
  43.   public:
  44.     TMyView (TRect r) :
  45.       TView (r)
  46.     {
  47.       // Tell this view that it can receive broadcast messages.
  48.       //
  49.       eventMask |= evBroadcast;
  50.     };
  51.   };
  52.  
  53.   void TMyView::handleEvent (TEvent& event)
  54.   {
  55.     if  (event.what == evBroadcast)
  56.     {
  57.       switch (event.message.command)
  58.       {
  59.         case  cmRemoveYourself:
  60.           // Tell this view to remove itself.  After removing this
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1707
  75.   VERSION  :  All
  76.        OS  :  DOS
  77.      DATE  :  October 12, 1993                         PAGE  :  2/4
  78.  
  79.     TITLE  :  Broadcast to close a Turbo Vision Modeless Dialog
  80.  
  81.  
  82.  
  83.  
  84.           // view, don't execute any other code that relies on
  85.           // the view - it doesn't exist anymore!
  86.           //
  87.           TProgram::deskTop->remove (this);
  88.           break;
  89.       }
  90.     }
  91.     // OK to execute this code after removing the view because it
  92.     // doesn't rely on the TMyView that we just removed.
  93.     //
  94.     TView::handleEvent (event);
  95.   }
  96.  
  97.   class TMyApplication : public TApplication
  98.   {
  99.   private:
  100.     static char nextX,  // Where to put
  101.                 nextY;  // the view next
  102.  
  103.     static TMenuBar *initMenuBar (TRect r);
  104.     virtual void handleEvent (TEvent& event);
  105.  
  106.   public:
  107.     TMyApplication () :
  108.       TProgInit (&TApplication::initStatusLine,
  109.                  &TMyApplication::initMenuBar,
  110.                  &TApplication::initDeskTop)
  111.     {
  112.     };
  113.   };
  114.   char TMyApplication::nextX = 0;
  115.   char TMyApplication::nextY = 0;
  116.  
  117.   TMenuBar  *TMyApplication::initMenuBar (TRect r)
  118.   {
  119.     r.b.y  = r.a.y + 1;
  120.     return new TMenuBar (r,
  121.       *new TSubMenu ("~E~xample", kbAltE) +
  122.         *new TMenuItem ("~M~ake Modeless View", cmMakeView,
  123.                         kbAltM, hcNoContext, "Alt-M") +
  124.         *new TMenuItem ("~R~emove All Views", cmRemoveView,
  125.                         kbAltR, hcNoContext, "Alt-R")
  126.       );
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1707
  141.   VERSION  :  All
  142.        OS  :  DOS
  143.      DATE  :  October 12, 1993                         PAGE  :  3/4
  144.  
  145.     TITLE  :  Broadcast to close a Turbo Vision Modeless Dialog
  146.  
  147.  
  148.  
  149.  
  150.   }
  151.  
  152.   void  TMyApplication::handleEvent (TEvent& event)
  153.   {
  154.     if  (event.what == evCommand)
  155.     {
  156.       switch (event.message.command)
  157.       {
  158.         case  cmMakeView:
  159.           // Insert a new TMyView into the deskTop.
  160.           //
  161.           TRect r;
  162.           r.a.x = nextX++;
  163.           r.a.y = nextY++;
  164.           r.b.x  = r.a.x + 10;
  165.           r.b.y = r.a.y + 10;
  166.  
  167.           TMyView *newView  = new TMyView (r);
  168.           TProgram::deskTop->insert (newView);
  169.           break;
  170.         case  cmRemoveView:
  171.           // Tell any TMyView objects that are inserted into the
  172.           // deskTop to remove themselves.
  173.           //
  174.           message (TProgram::deskTop, evBroadcast,
  175.                    cmRemoveYourself, this);
  176.           nextX = nextY = 0;
  177.           break;
  178.       }
  179.     }
  180.     TApplication::handleEvent (event);
  181.   };
  182.  
  183.   int  main (void)
  184.   {
  185.     TMyApplication  MyApp;
  186.  
  187.     MyApp.run();
  188.     MyApp.shutDown();
  189.     return 0;
  190.   }
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1707
  207.   VERSION  :  All
  208.        OS  :  DOS
  209.      DATE  :  October 12, 1993                         PAGE  :  4/4
  210.  
  211.     TITLE  :  Broadcast to close a Turbo Vision Modeless Dialog
  212.  
  213.  
  214.  
  215.  
  216.   DISCLAIMER: You have the right to use this technical information
  217.   subject to the terms of the No-Nonsense License Statement that
  218.   you received with the Borland product to which this information
  219.   pertains.
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.