home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / TVDEMOS.ZIP / FVIEWER.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  4.6 KB  |  180 lines

  1. /*---------------------------------------------------------*/
  2. /*                                                         */
  3. /*   Turbo Vision 1.0                                      */
  4. /*   Turbo Vision FileViewer Demo                          */
  5. /*   Copyright (c) 1991 by Borland International           */
  6. /*                                                         */
  7. /*---------------------------------------------------------*/
  8.  
  9. #define Uses_TKeys
  10. #define Uses_MsgBox
  11. #define Uses_TApplication
  12. #define Uses_TEvent
  13. #define Uses_TRect
  14. #define Uses_TFileDialog
  15. #define Uses_TChDirDialog
  16. #define Uses_TDeskTop
  17. #define Uses_TMenuBar
  18. #define Uses_TMenuItem
  19. #define Uses_TSubMenu
  20. #define Uses_TStatusLine
  21. #define Uses_TStatusDef
  22. #define Uses_TStatusItem
  23. #include <tv.h>
  24.  
  25. #if !defined( __STRING_H )
  26. #include <String.h>
  27. #endif  // __STRING_H
  28.  
  29. #if !defined( __FSTREAM_H )
  30. #include <Fstream.h>
  31. #endif  // __FSTREAM_H
  32.  
  33. #if !defined( __DIR_H )
  34. #include <Dir.h>
  35. #endif  // __DIR_H
  36.  
  37. #if !defined( __FILEVIEW_H )
  38. #include "FileView.h"
  39. #endif  // __FILEVIEW_H
  40.  
  41. class TFileViewerApp : public TApplication
  42. {
  43.  
  44. public:
  45.  
  46.     TFileViewerApp();
  47.  
  48.     virtual void handleEvent( TEvent& event );
  49.     static TMenuBar *initMenuBar( TRect );
  50.     static TStatusLine *initStatusLine( TRect );
  51.     virtual void outOfMemory();
  52.  
  53. private:
  54.  
  55.     void openFile();
  56.     void changeDir();
  57.     void tile();
  58.     void cascade();
  59.  
  60. };
  61.  
  62. TFileViewerApp::TFileViewerApp() :
  63.     TProgInit( &TFileViewerApp::initStatusLine,
  64.                &TFileViewerApp::initMenuBar,
  65.                &TFileViewerApp::initDeskTop
  66.              )
  67. {
  68. }
  69.  
  70.  
  71. void TFileViewerApp::openFile()
  72. {
  73.     TFileDialog *d= (TFileDialog *)validView(
  74.         new TFileDialog( "*.*", "Open a File", "~N~ame", fdOpenButton, 100 ));
  75.     if( d != 0 && deskTop->execView( d ) != cmCancel )
  76.         {
  77.         char fileName[MAXPATH];
  78.         d->getFileName( fileName );
  79.         TView *w= validView( new TFileWindow( fileName ) );
  80.         if( w != 0 )
  81.             deskTop->insert(w);
  82.         }
  83.     destroy( d );
  84. }
  85.  
  86. void TFileViewerApp::changeDir()
  87. {
  88.     TView *d = validView( new TChDirDialog( 0, hlChangeDir ) );
  89.     if( d != 0 )
  90.         {
  91.         deskTop->execView( d );
  92.         destroy( d );
  93.         }
  94. }
  95.  
  96. void TFileViewerApp::tile()
  97. {
  98.     deskTop->tile( deskTop->getExtent() );
  99. }
  100.  
  101. void TFileViewerApp::cascade()
  102. {
  103.     deskTop->cascade( deskTop->getExtent() );
  104. }
  105.  
  106. void TFileViewerApp::handleEvent( TEvent& event )
  107. {
  108.     TApplication::handleEvent( event );
  109.     if( event.what == evCommand )
  110.         {
  111.         switch( event.message.command )
  112.             {
  113.             case cmFileOpen:
  114.                 openFile();
  115.                 break;
  116.             case cmChangeDir:
  117.                 changeDir();
  118.                 break;
  119.             case cmCascade:
  120.                 cascade();
  121.                 break;
  122.             case cmTile:
  123.                 tile();
  124.                 break;
  125.             default:
  126.                 return ;
  127.         }
  128.         clearEvent( event );
  129.         }
  130. }
  131.  
  132. TMenuBar *TFileViewerApp::initMenuBar( TRect r )
  133. {
  134.     r.b.y = r.a.y+1;
  135.  
  136.     return new TMenuBar( r,
  137.       *new TSubMenu( "~F~ile", kbAltF ) +
  138.         *new TMenuItem( "~O~pen...", cmFileOpen, kbF3, hcNoContext, "F3" ) +
  139.         *new TMenuItem( "~C~hange dir...", cmChangeDir, kbNoKey ) +
  140.         *new TMenuItem( "E~x~it", cmQuit, kbAltX, hcNoContext, "Alt-X" ) +
  141.       *new TSubMenu( "~W~indows", kbAltW ) +
  142.         *new TMenuItem( "~R~esize/move", cmResize, kbCtrlF5, hcNoContext, "Ctrl-F5" ) +
  143.         *new TMenuItem( "~Z~oom", cmZoom, kbF5, hcNoContext, "F5" ) +
  144.         *new TMenuItem( "~N~ext", cmNext, kbF6, hcNoContext, "F6" ) +
  145.         *new TMenuItem( "~C~lose", cmClose, kbAltF3, hcNoContext, "Alt-F3" ) +
  146.         *new TMenuItem( "~T~ile", cmTile, kbNoKey ) +
  147.         *new TMenuItem( "C~a~scade", cmCascade, kbNoKey )
  148.         );
  149.  
  150. }
  151.  
  152. TStatusLine *TFileViewerApp::initStatusLine( TRect r )
  153. {
  154.     r.a.y = r.b.y-1;
  155.     return new TStatusLine( r,
  156.         *new TStatusDef( 0, 0xFFFF ) +
  157.             *new TStatusItem( 0, kbF10, cmMenu ) +
  158.             *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
  159.             *new TStatusItem( "~F3~ Open", kbF3, cmFileOpen ) +
  160.             *new TStatusItem( "~F5~ Zoom", kbF5, cmZoom ) +
  161.             *new TStatusItem( "~Alt-F3~ Close", kbAltF3, cmClose )
  162.         );
  163.  
  164.  
  165. }
  166.  
  167. void TFileViewerApp::outOfMemory()
  168. {
  169.     messageBox( "Not enough memory available to complete operation.",
  170.                 mfError | mfOKButton );
  171. }
  172.             
  173.  
  174. int main()
  175. {
  176.     TFileViewerApp fileViewerApp;
  177.     fileViewerApp.run();
  178.     return 0;
  179. }
  180.