home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / wrdwrp / tvedit1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  4.2 KB  |  187 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_TApplication
  10. #define Uses_TEditWindow
  11. #define Uses_TDeskTop
  12. #define Uses_TRect
  13. #define Uses_TEditor
  14. #define Uses_TFileEditor
  15. #define Uses_TFileDialog
  16. #define Uses_TChDirDialog
  17.  
  18. #include <tv.h>
  19.  
  20. #include "tvedit.h"
  21.  
  22. #include <stdlib.h>
  23. #include <stdarg.h>
  24. #include <strstrea.h>
  25. #include <iomanip.h>
  26.  
  27. TEditWindow *clipWindow;
  28.  
  29. TEditWindow *TEditorApp::openEditor( const char *fileName, Boolean visible )
  30. {
  31.     TRect r = deskTop->getExtent();
  32.     TEditWindow *p = (TEditWindow*)validView( new TEditWindow( r, fileName, wnNoNumber ) );
  33.  
  34.     //??
  35.     p->editor->wordWrap = True;         // ???????????
  36.     p->editor->autosizeMargin = True;   // ???????????
  37.  
  38.     if( !visible )
  39.         p->hide();
  40.     deskTop->insert( p );
  41.     return p;
  42. }
  43.  
  44. TEditorApp::TEditorApp() :
  45.     TProgInit( TEditorApp::initStatusLine,
  46.                TEditorApp::initMenuBar,
  47.                TEditorApp::initDeskTop
  48.              ),
  49.     TApplication()
  50. {
  51.  
  52.     TCommandSet ts;
  53.     ts.enableCmd( cmSave );
  54.     ts.enableCmd( cmSaveAs );
  55.     ts.enableCmd( cmCut );
  56.     ts.enableCmd( cmCopy );
  57.     ts.enableCmd( cmPaste );
  58.     ts.enableCmd( cmClear );
  59.     ts.enableCmd( cmUndo );
  60.     ts.enableCmd( cmFind );
  61.     ts.enableCmd( cmReplace );
  62.     ts.enableCmd( cmSearchAgain );
  63.     disableCommands( ts );
  64.  
  65.     TEditor::editorDialog = doEditDialog;
  66.     clipWindow = openEditor( 0, False );
  67.     if( clipWindow != 0 )
  68.         {
  69.         TEditor::clipboard = clipWindow->editor;
  70.         TEditor::clipboard->canUndo = False;
  71.         }
  72. }
  73.  
  74. void TEditorApp::fileOpen()
  75. {
  76.     char fileName[MAXPATH];
  77.     strcpy( fileName, "*.*" );
  78.  
  79.     if( execDialog( new TFileDialog( "*.*", "Open file",
  80.             "~N~ame", fdOpenButton, 100 ), fileName) != cmCancel )
  81.         openEditor( fileName, True );
  82. }
  83.  
  84. void TEditorApp::fileNew()
  85. {
  86.     openEditor( 0, True );
  87. }
  88.  
  89. void TEditorApp::changeDir()
  90. {
  91.     execDialog( new TChDirDialog( cdNormal, 0 ), 0 );
  92. }
  93.  
  94. void TEditorApp::dosShell()
  95. {
  96.     suspend();
  97.     system("cls");
  98.     cout << "Type EXIT to return...";
  99.     system( getenv( "COMSPEC"));
  100.     resume();
  101.     redraw();
  102. }
  103.  
  104. void TEditorApp::showClip()
  105. {
  106.     clipWindow->select();
  107.     clipWindow->show();
  108. }
  109.  
  110. void TEditorApp::tile()
  111. {
  112.     deskTop->tile( deskTop->getExtent() );
  113. }
  114.  
  115. void TEditorApp::cascade()
  116. {
  117.     deskTop->cascade( deskTop->getExtent() );
  118. }
  119.  
  120. void TEditorApp::handleEvent( TEvent& event )
  121. {
  122.     TApplication::handleEvent( event );
  123.     if( event.what != evCommand )
  124.         return;
  125.     else
  126.         switch( event.message.command )
  127.             {
  128.             case cmOpen:
  129.                 fileOpen();
  130.                 break;
  131.  
  132.             case cmNew:
  133.                 fileNew();
  134.                 break;
  135.  
  136.             case cmChangeDrct:
  137.                 changeDir();
  138.                 break;
  139.  
  140.             case cmDosShell:
  141.                 dosShell();
  142.                 break;
  143.  
  144.             case cmShowClip:
  145.                 showClip();
  146.                 break;
  147.  
  148.             case cmTile:
  149.                 tile();
  150.                 break;
  151.  
  152.             case cmCascade:
  153.                 cascade();
  154.                 break;
  155.  
  156.             default:
  157.                 return ;
  158.             }
  159.     clearEvent( event );
  160. }
  161.  
  162.  
  163.  
  164. int main(int argc, char** argv)
  165. {
  166.     TEditorApp editorApp;
  167.  
  168.     if (argc > 1) {
  169.         TEvent event;
  170.  
  171.         if (stricmp(argv[1], "Play") == 0) {
  172.             event.what = evCommand;
  173.             event.message.command = cmPlay;
  174.             editorApp.putEvent(event);
  175.  
  176.         } else if (stricmp(argv[1], "Record") == 0) {
  177.             event.what = evCommand;
  178.             event.message.command = cmRecord;
  179.             editorApp.putEvent(event);
  180.         }
  181.     }
  182.  
  183.     editorApp.run();
  184.     return 0;
  185. }
  186.  
  187.