home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / TI_BC1.ZIP / TI1557.ZIP / TI1557.ASC
Text File  |  1993-08-31  |  7KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1557
  9.   VERSION  :  3.x
  10.        OS  :  DOS
  11.      DATE  :  August 31, 1993                          PAGE  :  1/5
  12.  
  13.     TITLE  :  Creating red error dialog boxes in Turbo Vision
  14.  
  15.  
  16.  
  17.  
  18.   //**********************************************************
  19.   //
  20.   //  This program declares a new type ErrorDialog, which is
  21.   //  identical to TDialog except it uses a red color scheme.
  22.   //  It is usefull for displaying error messages.
  23.   //
  24.   //**********************************************************
  25.  
  26.   #define Uses_TKeys
  27.   #define Uses_TApplication
  28.   #define Uses_TEvent
  29.   #define Uses_TRect
  30.   #define Uses_TDialog
  31.   #define Uses_TStaticText
  32.   #define Uses_TButton
  33.   #define Uses_TMenuBar
  34.   #define Uses_TSubMenu
  35.   #define Uses_TMenuItem
  36.   #define Uses_TStatusLine
  37.   #define Uses_TStatusItem
  38.   #define Uses_TStatusDef
  39.   #define Uses_TDeskTop
  40.   #include <tv.h>
  41.  
  42.   const cmTestNormalDialog = 100;
  43.   const cmTestErrorDialog  = 101;
  44.  
  45.   //
  46.   //  This is the palette that will be added to TProgram's
  47.   //  palette.  The ErrorDialog will then reference these
  48.   //  palette entries.
  49.   //
  50.  
  51.   #define cpErrorApp "\x40\x4F\x4E\x46\x46\x40\x40\x4F\x4E" \
  52.                      "\x70\x7B\x7F\x78\x7E\x40\x40\x4F\x4E" \
  53.                      "\x4F\x4F\x4E\x40\x46\x46\x46\x40\x4F" \
  54.                      "\x4E\x46\x4E\x40\x40"
  55.  
  56.   //
  57.   //  This is the palette for ErrorDialog.  It references
  58.   //  entries 64-95 (0x40 - 0x5F) in its parents dialog.
  59.   //
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1557
  75.   VERSION  :  3.x
  76.        OS  :  DOS
  77.      DATE  :  August 31, 1993                          PAGE  :  2/5
  78.  
  79.     TITLE  :  Creating red error dialog boxes in Turbo Vision
  80.  
  81.  
  82.  
  83.  
  84.   #define cpErrorDialog "\x40\x41\x42\x43\x44\x45\x46\x47\x48" \
  85.                         "\x49\x4A\x4B\x4C\x4D\x4E\x4F" \
  86.                         "\x50\x51\x52\x53\x54\x55\x56\x57\x58" \
  87.                         "\x59\x5A\x5B\x5C\x5D\x5E\x5F"
  88.  
  89.   //
  90.   //  Define a new dialog that has uses the red palette
  91.   //
  92.  
  93.   class ErrorDialog : public TDialog {
  94.   public:
  95.     ErrorDialog( TRect& r, const char *errorText );
  96.     virtual TPalette& getPalette() const;
  97.   };
  98.  
  99.   //
  100.   // constructor is identical to TDialog, so it can be used
  101.   // anywhere a TDialog is used
  102.   //
  103.  
  104.   ErrorDialog::ErrorDialog( TRect& r, const char *title ):
  105.     TDialog( r, title ),
  106.     TWindowInit( TDialog::initFrame ) {
  107.   }
  108.  
  109.   //
  110.   // use the Red palette instead of the standard TDialog palette
  111.   //
  112.   // NOTE: cpErrorDialog1 and cpErrorDialog2 define the palette
  113.   //       for an ErrorDialog.  This palette refers to entries
  114.   //       in the TApplication palette which normally are not
  115.   //       defined.  See below where TApplication adds the
  116.   //       necessary red palette entries to its palette
  117.  
  118.   TPalette& ErrorDialog::getPalette() const {
  119.     static TPalette
  120.          errorPalette( cpErrorDialog, sizeof(cpErrorDialog)-1);
  121.     return errorPalette;
  122.   }
  123.  
  124.   class TestApp : public TApplication
  125.   {
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1557
  141.   VERSION  :  3.x
  142.        OS  :  DOS
  143.      DATE  :  August 31, 1993                          PAGE  :  3/5
  144.  
  145.     TITLE  :  Creating red error dialog boxes in Turbo Vision
  146.  
  147.  
  148.  
  149.  
  150.   public:
  151.  
  152.       TestApp();
  153.  
  154.       virtual void handleEvent( TEvent& event );
  155.       static TMenuBar *initMenuBar( TRect );
  156.       static TStatusLine *initStatusLine( TRect );
  157.       TPalette& getPalette() const;
  158.  
  159.   private:
  160.       void testDialog( Boolean );
  161.   };
  162.  
  163.   //
  164.   //  The normal application palette only has 64 entries (0-63)
  165.   //
  166.   //  ErrorDialog refers to entries 64-95, so we have to add
  167.   //  those to the application palette
  168.   //
  169.   //  cpColor is the normal application palette, since cpColor,
  170.   //  cpErrorApp1 and cpErrorApp2 are string literals, we can
  171.   //  just concatenate them to  form a larger string literal
  172.   //
  173.  
  174.   TPalette& TestApp::getPalette() const {
  175.     static TPalette newColor( cpColor cpErrorApp,
  176.                               sizeof(cpColor cpErrorApp)-1 );
  177.     return newColor;
  178.   }
  179.  
  180.   TestApp::TestApp() :
  181.       TProgInit( &TestApp::initStatusLine,
  182.                  &TestApp::initMenuBar,
  183.                  &TestApp::initDeskTop
  184.                ) {
  185.   }
  186.  
  187.   void TestApp::testDialog( Boolean errorMode ) {
  188.     TDialog *d;
  189.  
  190.     if (errorMode)
  191.       d=new ErrorDialog( TRect( 25, 5, 55, 16 ), "Fatal Error!");
  192.     else
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1557
  207.   VERSION  :  3.x
  208.        OS  :  DOS
  209.      DATE  :  August 31, 1993                          PAGE  :  4/5
  210.  
  211.     TITLE  :  Creating red error dialog boxes in Turbo Vision
  212.  
  213.  
  214.  
  215.  
  216.       d=new TDialog( TRect( 25, 5, 55, 16 ), "Fatal Error!");
  217.  
  218.     d->insert( new TStaticText( TRect( 3, 5, 15, 6 ),
  219.                                  "What now?" ));
  220.     d->insert( new TButton( TRect( 16, 2, 28, 4 ), "Abort",
  221.                               cmCancel, bfNormal ) );
  222.     d->insert( new TButton( TRect( 16, 4, 28, 6 ), "Retry",
  223.                               cmCancel, bfNormal ) );
  224.     d->insert( new TButton( TRect( 16, 6, 28, 8 ), "Fail",
  225.                               cmCancel, bfNormal ) );
  226.     d->insert( new TButton( TRect( 16, 8, 28, 10 ), "FooBar",
  227.                               cmCancel, bfNormal ) );
  228.  
  229.     TProgram::deskTop->execView( d );
  230.     TObject::destroy(d);
  231.   }
  232.  
  233.   void TestApp::handleEvent( TEvent& event ) {
  234.     TApplication::handleEvent( event );
  235.     if( event.what == evCommand ) {
  236.       switch( event.message.command ) {
  237.         case cmTestErrorDialog:
  238.           testDialog( True );
  239.           clearEvent( event );
  240.           break;
  241.         case cmTestNormalDialog:
  242.           testDialog( False );
  243.           clearEvent( event );
  244.           break;
  245.         default:
  246.           break;
  247.       }
  248.     }
  249.   }
  250.  
  251.   TMenuBar *TestApp::initMenuBar( TRect r )
  252.   {
  253.     r.b.y = r.a.y+1;
  254.  
  255.     return new TMenuBar( r,
  256.       *new TSubMenu( "~D~ialogs", kbAltD ) +
  257.         *new TMenuItem( "~E~rror Dialog...",
  258.                         cmTestErrorDialog, kbAltE ) +
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                           NUMBER  :  1557
  273.   VERSION  :  3.x
  274.        OS  :  DOS
  275.      DATE  :  August 31, 1993                          PAGE  :  5/5
  276.  
  277.     TITLE  :  Creating red error dialog boxes in Turbo Vision
  278.  
  279.  
  280.  
  281.  
  282.         *new TMenuItem( "~N~ormal Dialog...",
  283.                         cmTestNormalDialog, kbAltN )+
  284.          newLine() +
  285.         *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext,
  286.                         "Alt-X" )
  287.         );
  288.   }
  289.  
  290.   TStatusLine *TestApp::initStatusLine( TRect r )
  291.   {
  292.     r.a.y = r.b.y-1;
  293.     return new TStatusLine( r,
  294.       *new TStatusDef( 0, 0xFFFF ) +
  295.         *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
  296.         *new TStatusItem( 0, kbF10, cmMenu )
  297.       );
  298.   }
  299.  
  300.   int main()
  301.   {
  302.     TestApp testApp;
  303.     testApp.run();
  304.     return 0;
  305.   }
  306.  
  307.  
  308.   DISCLAIMER: You have the right to use this technical information
  309.   subject to the terms of the No-Nonsense License Statement that
  310.   you received with the Borland product to which this information
  311.   pertains.
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.