home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / ve2tv103.zip / TVEDIT3.CPP < prev    next >
C/C++ Source or Header  |  1994-07-31  |  5KB  |  176 lines

  1. // File    : TVEDIT3.CPP
  2. // Author  : Eric Woodruff,  CIS ID: 72134,1150
  3. // Updated : Sun 07/31/94 15:56:28
  4. // Note    : Copyright 1994, Eric Woodruff, All rights reserved
  5. // Compiler: Borland C++ 3.1 to 4.02
  6. //
  7. // This file contains an example of the "signs of life" functions that
  8. // can be implemented with the editor.
  9. //
  10.  
  11. #include <stdarg.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14.  
  15. #define Uses_TApplication
  16. #define Uses_TDeskTop
  17. #define Uses_TDialog
  18. #define Uses_TParamText
  19. #define Uses_TProgram
  20. #define Uses_TStaticText
  21. #include <tv.h>
  22.  
  23. #include <tvmedit.h>
  24.  
  25. #include "tvedit.h"
  26.  
  27. // ***************************************************************************
  28.  
  29. #if _TV_VERSION == 0x0103
  30.  
  31. // TParamText has too many probems in TV 1.03, so this is a simple class
  32. // to handle the message display.  Under TV 2.0, TParamText is used because
  33. // it was altered significantly and no longer causes any trouble.
  34. class TMessageText : public TStaticText
  35. {
  36. private:
  37.     char *str;
  38.  
  39. public:
  40.     TMessageText(TRect &r) : TStaticText(r, NULL), str(new char [256]) {}
  41.  
  42.     ~TMessageText()
  43.         {    delete [] str;    }
  44.  
  45.     void setText(char *newMsg, ...)
  46.     {
  47.         va_list ap;
  48.         va_start(ap, newMsg);
  49.         vsprintf(str, newMsg, ap);
  50.         va_end(ap);
  51.         drawView();
  52.     }
  53.  
  54.     virtual void getText(char *s)
  55.         {    strcpy(s, str);    }
  56. };
  57.  
  58. #endif
  59.  
  60. // ***************************************************************************
  61. // This is the function that handles the various Signs of Life states.
  62. // 'lifeSign' indicates what the function is being called for.  'cmnd'
  63. // indicates which command is being executed.  'count' and 'total' represent
  64. // lines done and the total number of lines to do or, for reading text, bytes
  65. // read so far and the total number of bytes to be read.  Note that if either
  66. // GlobalOptions.initThreshold or GlobalOptions.reportInterval is zero, then
  67. // the editor classes will not issue signs of life.  This function can be as
  68. // simple or as sophisticated as you want it to be.
  69. //
  70. void doSignsOfLife(SignsOfLife lifeSign, ushort cmnd, long count, long total)
  71. {
  72.     static TDialog *msgDlg = NULL;
  73.  
  74. #if _TV_VERSION == 0x0103
  75.     static TMessageText *msgTxt;
  76. #else
  77.     static TParamText *msgTxt;
  78. #endif
  79.     static char Spinner[4] = { '\\', '|', '/', '-' }, *Operation;
  80.     static short index;
  81.  
  82.     TRect r;
  83.  
  84.     // Ignore it if the message box couldn't or wouldn't be created.
  85.     if((!msgDlg && lifeSign != slInitiate) || lowMemory())
  86.         return;
  87.  
  88.     switch(lifeSign)
  89.     {
  90.         case slInitiate:
  91.             msgDlg = new TDialog(TRect(0, 0, 50, 6), "* Working *");
  92.             msgDlg->options |= ofCentered;
  93.             r = msgDlg->getClipRect();
  94.             r.grow(-2, -2);
  95. #if _TV_VERSION == 0x0103
  96.             msgTxt = new TMessageText(r);
  97. #else
  98.             msgTxt = new TParamText(r);
  99. #endif
  100.             msgDlg->insert(msgTxt);
  101.  
  102.             // These are all the commands that issue signs of life.
  103.             switch(cmnd)
  104.             {
  105.                 case cmMoveBlock:
  106.                     Operation = "Mov";
  107.                     break;
  108.  
  109.                 case cmCopyBlock:       // Including clipboard operations.
  110.                     Operation = "Copy";
  111.                     break;
  112.  
  113.                 case cmReadFile:        // Reports progress in bytes not lines.
  114.                     Operation = "Read";
  115.                     break;
  116.  
  117.                 case cmWriteBlock:
  118.                     Operation = "Writ";
  119.                     break;
  120.  
  121.                 case cmPrintBlock:
  122.                     Operation = "Print";
  123.                     break;
  124.  
  125.                 // NOTE: If you see delete starting a clipboard copy or cut
  126.                 //       operation, don't panic!  It's just the old block
  127.                 //       of text being cleared from the clipboard.
  128.                 case cmClear:
  129.                     Operation = "Delet";
  130.                     break;
  131.  
  132.                 case cmUndo:        // Serves both undo and redo operations.
  133.                     Operation = "Undoing/Redo";
  134.                     break;
  135.  
  136.                 case cmFind:
  137.                 case cmFindMatching:
  138.                     Operation = "Search";
  139.                     break;
  140.  
  141.                 default:    // All other commands (from alterText())
  142.                     Operation = "Alter";
  143.                     break;
  144.             }
  145.  
  146.             TApplication::deskTop->insert(msgDlg);
  147.             index = -1;
  148.             // Fall through and display the message to complete the case.
  149.  
  150.         case slReporting:
  151.         case slDone:
  152.             index++;            // Turn the spinner.
  153.             if(index == 4)
  154.                 index = 0;
  155.  
  156.             msgTxt->setText("Please Wait...%c\n%sing %ld of %ld",
  157.                 Spinner[index], Operation, count, total);
  158.  
  159.             if(lifeSign == slDone)
  160.             {
  161.                 TApplication::deskTop->remove(msgDlg);
  162.                 TObject::destroy(msgDlg);
  163.                 msgDlg = NULL;      // Reset pointer ready for next time.
  164.             }
  165.             break;
  166.  
  167. //        case slHide:          // Unused by the default editor classes,
  168. //            msgDlg->hide();   // but they are here incase you need them.
  169. //            break;
  170. //
  171. //        case slShow:
  172. //            msgDlg->show();
  173. //            break;
  174.     }
  175. }
  176.