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

  1. /*---------------------------------------------------------*/
  2. /*                                                         */
  3. /*   Turbo Vision 1.0                                      */
  4. /*   Copyright (c) 1991 by Borland International           */
  5. /*                                                         */
  6. /*   Budget FORM14 Editor Program File                     */
  7. /*---------------------------------------------------------*/
  8.  
  9. #define Uses_MsgBox
  10. #define Uses_TApplication
  11. #define Uses_TButton
  12. #define Uses_TDeskTop
  13. #define Uses_TDialog
  14. #define Uses_TEvent
  15. #define Uses_TEventQueue
  16. #define Uses_TFrame
  17. #define Uses_TIndicator
  18. #define Uses_TKeys
  19. #define Uses_TLabel
  20. #define Uses_TMenuBar
  21. #define Uses_TMenuItem
  22. #define Uses_TProgram
  23. #define Uses_TRect
  24. #define Uses_TStaticText
  25. #define Uses_TStatusDef
  26. #define Uses_TStatusItem
  27. #define Uses_TStatusLine
  28. #define Uses_TStreamable
  29. #define Uses_TStreamableClass
  30. #define Uses_TSubMenu
  31. #define Uses_TView
  32. #define Uses_TWindow
  33.  
  34. #define Uses_TField
  35.  
  36. #include <tv.h>
  37. #include "TField.h"
  38.  
  39. __link( RInputLine )
  40.  
  41.  
  42. #if !defined( __STRING_H )
  43. #include <string.h>
  44. #endif  // __STRING_H
  45.  
  46. #if !defined( __STDLIB_H )
  47. #include <stdlib.h>
  48. #endif  // __STDLIB_H
  49.  
  50. #if !defined( __STRSTREAM_H )
  51. #include <strstream.h>
  52. #endif  // __STRSTREAM_H
  53.  
  54.  
  55. const cmForm14 = 100;
  56. const cmScroll = 101;
  57. const cmJustify = 102;
  58.  
  59. short gWinNumber = 0; // Window Number
  60. short gForm14Active = 0; // Count of Form14 windows open
  61. TField *gfield;
  62.  
  63. #define cpForm14 "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F"\
  64.                       "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F"
  65.  
  66. struct Form14Record
  67. {
  68.      char Program[7];
  69. };
  70.  
  71. Form14Record *F14MyData;
  72.  
  73.  
  74. class TForm14Window : public TWindow // define a new window class for form 14's
  75. {
  76. public:
  77.  
  78.     TForm14Window( const TRect& r, const char *aTitle, short aNumber); // declare a constructor
  79.     ~TForm14Window(); // declare a destructor class
  80.     TPalette& getPalette() const; // override the getPalette function
  81. };
  82.  
  83. TForm14Window::TForm14Window( const TRect& r, const char *aTitle, short aNumber):
  84.     TWindow( r, aTitle, aNumber),
  85.     TWindowInit( &TForm14Window::initFrame)
  86. {
  87.     growMode = 0;                        // Window is not resizable
  88.     flags &= ~(wfGrow | wfZoom);    // set the window to non-growable & non-zoomable
  89. }
  90.  
  91. TForm14Window::~TForm14Window()
  92. {
  93.     // Enable the Forms|Form14 menu command
  94.     enableCommand( cmForm14 );
  95.  
  96.     // Decrement the gForm14Active variable
  97.     gForm14Active--;
  98.  
  99. }
  100.  
  101. TPalette& TForm14Window::getPalette() const
  102. {
  103.     static TPalette palette( cpForm14, sizeof( cpForm14 )-1 );
  104.     return palette;
  105. }
  106.  
  107.  
  108.  
  109. class TBudgetApp : public TApplication
  110. {
  111.  
  112. public:
  113.  
  114.      TBudgetApp();
  115.      ~TBudgetApp();
  116.  
  117.      virtual void handleEvent( TEvent& event );
  118.      static TMenuBar *initMenuBar( TRect );
  119.      static TStatusLine *initStatusLine( TRect );
  120.  
  121. private:
  122.  
  123.      void form14();
  124. };
  125.  
  126. TBudgetApp::TBudgetApp() :
  127.      TProgInit( &TBudgetApp::initStatusLine,
  128.                     &TBudgetApp::initMenuBar,
  129.                     &TBudgetApp::initDeskTop
  130.                  )
  131. {
  132.     // Initialize the F14MyData structure
  133.     F14MyData = new Form14Record;
  134.     strcpy( F14MyData->Program, "013003" );
  135. }
  136.  
  137. void TBudgetApp::~TBudgetApp()
  138. {
  139.     // Clear up the dynamic data storage
  140.     delete F14MyData;
  141. }
  142.  
  143. void TBudgetApp::form14()
  144. {
  145.     TView *control, *histry;
  146.     ushort value;
  147.  
  148.     // Create the new window //
  149.         TForm14Window *F14win = new TForm14Window(TRect(0, 0, 80, 23), "Test Application", wnNoNumber);
  150.  
  151.     // If unsuccessful, then return //
  152.         if (!F14win)
  153.             return;
  154.  
  155.     // Begin Inserting User-Editable Areas //
  156.  
  157.         // Insert the Program # input area //
  158.             gfield = new TField(TRect(68,3,75,4), 7);
  159.             gfield->setScroll(False);
  160.             F14win->insert(gfield);
  161.             F14win->insert(new TLabel(TRect(55,3,67,4), "~T~est Field:", gfield));
  162.  
  163.  
  164.         // Insert the Scroll Button onto the form //
  165.             control = new TButton(TRect(66,9,77,11), "~S~croll", cmScroll, bfNormal);
  166.             F14win->insert(control);
  167.  
  168.  
  169.         // Insert the Justify Button onto the form //
  170.             control = new TButton(TRect(66,13,77,15), "~J~ustify", cmJustify, bfNormal);
  171.             F14win->insert(control);
  172.  
  173.  
  174.         // Select the first field on the form
  175.         F14win->selectNext(False);
  176.  
  177.         // Insert the form onto the desktop
  178.         deskTop->insert( F14win );
  179.  
  180.         // Increment the form14 open counter
  181.         gForm14Active++;
  182.  
  183.         // Disable the Forms|Form14 command
  184.         disableCommand( cmForm14 );
  185.  
  186.         // Initialize the form's data
  187.         F14win->setData( F14MyData );
  188.  
  189.         //Return the window pointer
  190.         return;
  191. }
  192.  
  193. void TBudgetApp::handleEvent( TEvent& event )
  194. {
  195.      TApplication::handleEvent( event );
  196.      if( event.what == evCommand )
  197.           {
  198.           switch( event.message.command )
  199.                 {
  200.                 case cmForm14:
  201.                     // Open a form14 window if one is not already open
  202.                     if( gForm14Active < 1 )
  203.                         form14();
  204.                     break;
  205.                 case cmScroll:
  206.                     // Open a message dialog box
  207.                     ushort yesno = messageBox( "Allow the test field to scroll?", mfYesButton | mfNoButton );
  208.                     if (yesno != cmCancel)
  209.                         if (yesno == cmYes )
  210.                             gfield->setScroll(True);
  211.                         else
  212.                             gfield->setScroll(False);
  213.                     drawView();
  214.                     break;
  215.                 case cmJustify:
  216.                     // Open a message dialog box
  217.                     ushort yesno1 = messageBox( "Enter new justification value:\nYes = jLeft, No = jRight", mfYesButton | mfNoButton );
  218.                     if (yesno1 != cmCancel)
  219.                         if (yesno1 == cmYes )
  220.                             gfield->setJustification(jLeft);
  221.                         else
  222.                             gfield->setJustification(jRight);
  223.                     break;
  224.                 default:
  225.                      return;
  226.                 }
  227.           clearEvent( event ); // Clear the event after handling it
  228.           }
  229. }
  230.  
  231. TMenuBar *TBudgetApp::initMenuBar( TRect r )
  232. {
  233.  
  234.      r.b.y = r.a.y+1;
  235.  
  236.      return new TMenuBar( r,
  237.         *new TSubMenu( "~F~orms", kbAltF ) +
  238.           *new TMenuItem( "~T~est Form...", cmForm14, kbAltF ) +
  239.             newLine() +
  240.           *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
  241.           );
  242.  
  243. }
  244.  
  245. TStatusLine *TBudgetApp::initStatusLine( TRect r )
  246. {
  247.      r.a.y = r.b.y-1;
  248.      return new TStatusLine( r,
  249.           *new TStatusDef( 0, 0xFFFF ) +
  250.                 *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
  251.                 *new TStatusItem( "~Ctrl-F4~ Close", kbCtrlF4, cmClose ) +
  252.                 *new TStatusItem( 0, kbF10, cmMenu )
  253.                 );
  254. }
  255.  
  256. int main()
  257. {
  258.      TBudgetApp BudgetApp;
  259.      BudgetApp.run();
  260.      return 0;
  261. }
  262.