home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / demos / TVEDIT1.CPP < prev    next >
Text File  |  1999-05-26  |  4KB  |  167 lines

  1. /*----------------------------------------------------------*/
  2. /*                                                          */
  3. /*   Turbo Vision 1.0                                       */
  4. /*   Copyright (c) 1991 by Borland International            */
  5. /*                                                          */
  6. /*   Turbo Vision TVEDIT source file                        */
  7. /*----------------------------------------------------------*/
  8.  
  9. #define Uses_TEventQueue
  10. #define Uses_TApplication
  11. #define Uses_TEditWindow
  12. #define Uses_TDeskTop
  13. #define Uses_TRect
  14. #define Uses_TEditor
  15. #define Uses_TFileEditor
  16. #define Uses_TFileDialog
  17. #define Uses_TChDirDialog
  18.  
  19. #include <tv.h>
  20.  
  21. #include "tvedit.h"
  22.  
  23. #include <stdlib.h>
  24. #include <stdarg.h>
  25. #include <strstrea.h>
  26. #include <iomanip.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29.  
  30. TEditWindow *clipWindow;
  31.  
  32. TEditWindow *TEditorApp::openEditor( const char *fileName, Boolean visible )
  33. {
  34.     TRect r = deskTop->getExtent();
  35.     TView *p = validView( new TEditWindow( r, fileName, wnNoNumber ) );
  36.     if( !visible )
  37.         p->hide();
  38.     deskTop->insert( p );
  39.     return (TEditWindow *)p;
  40. }
  41.  
  42. TEditorApp::TEditorApp() :
  43.     TProgInit( TEditorApp::initStatusLine,
  44.                TEditorApp::initMenuBar,
  45.                TEditorApp::initDeskTop
  46.              ),
  47.     TApplication()
  48. {
  49.  
  50.     TCommandSet ts;
  51.     ts.enableCmd( cmSave );
  52.     ts.enableCmd( cmSaveAs );
  53.     ts.enableCmd( cmCut );
  54.     ts.enableCmd( cmCopy );
  55.     ts.enableCmd( cmPaste );
  56.     ts.enableCmd( cmClear );
  57.     ts.enableCmd( cmUndo );
  58.     ts.enableCmd( cmFind );
  59.     ts.enableCmd( cmReplace );
  60.     ts.enableCmd( cmSearchAgain );
  61.     disableCommands( ts );
  62.  
  63.     TEditor::editorDialog = doEditDialog;
  64.     clipWindow = openEditor( 0, False );
  65.     if( clipWindow != 0 )
  66.         {
  67.         TEditor::clipboard = clipWindow->editor;
  68.         TEditor::clipboard->canUndo = False;
  69.         }
  70. }
  71.  
  72. void TEditorApp::fileOpen()
  73. {
  74.     char fileName[260];
  75.     strcpy( fileName, "*.*" );
  76.  
  77.     if( execDialog( new TFileDialog( "*.*", "Open file",
  78.             "~N~ame", fdOpenButton, 100 ), fileName) != cmCancel )
  79.         openEditor( fileName, True );
  80. }
  81.  
  82. void TEditorApp::fileNew()
  83. {
  84.     openEditor( 0, True );
  85. }
  86.  
  87. void TEditorApp::changeDir()
  88. {
  89.     execDialog( new TChDirDialog( cdNormal, 0 ), 0 );
  90. }
  91.  
  92. void TEditorApp::dosShell()
  93. {
  94.     suspend();
  95.     system("cls");
  96.     cout << "Type EXIT to return...";
  97.     system( getenv( "COMSPEC") );
  98.     resume();
  99.     redraw();
  100. }
  101.  
  102. void TEditorApp::showClip()
  103. {
  104.     clipWindow->select();
  105.     clipWindow->show();
  106. }
  107.  
  108. void TEditorApp::tile()
  109. {
  110.     deskTop->tile( deskTop->getExtent() );
  111. }
  112.  
  113. void TEditorApp::cascade()
  114. {
  115.     deskTop->cascade( deskTop->getExtent() );
  116. }
  117.  
  118. void TEditorApp::handleEvent( TEvent& event )
  119. {
  120.     TApplication::handleEvent( event );
  121.     if( event.what != evCommand )
  122.         return;
  123.     else
  124.         switch( event.message.command )
  125.             {
  126.             case cmOpen:
  127.                 fileOpen();
  128.                 break;
  129.  
  130.             case cmNew:
  131.                 fileNew();
  132.                 break;
  133.  
  134.             case cmChangeDrct:
  135.                 changeDir();
  136.                 break;
  137.  
  138.             case cmDosShell:
  139.                 dosShell();
  140.                 break;
  141.  
  142.             case cmShowClip:
  143.                 showClip();
  144.                 break;
  145.  
  146.             case cmTile:
  147.                 tile();
  148.                 break;
  149.  
  150.             case cmCascade:
  151.                 cascade();
  152.                 break;
  153.  
  154.             default:
  155.                 return ;
  156.             }
  157.     clearEvent( event );
  158. }
  159. int main()
  160. {
  161.     TEditorApp editorApp;
  162.     editorApp.run();
  163.  
  164.     return 0;
  165. }
  166.  
  167.