home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / tvme30.zip / TVEDIT3.CPP < prev    next >
C/C++ Source or Header  |  1995-08-02  |  6KB  |  185 lines

  1. // File    : TVEDIT3.CPP
  2. // Author  : Eric Woodruff,  CIS ID: 72134,1150
  3. // Updated : Wed 08/02/95 17:54:19
  4. // Note    : Copyright 1994-95, Eric Woodruff, All rights reserved
  5. // Compiler: Borland C++ 3.1 to 4.xx
  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.             msgDlg->flags &= ~wfClose;
  94.  
  95. #if _TV_VERSION != 0x0103
  96.             msgDlg->palette = dpBlueDialog;
  97. #endif
  98.             r = msgDlg->getClipRect();
  99.             r.grow(-2, -2);
  100.  
  101. #if _TV_VERSION == 0x0103
  102.             msgTxt = new TMessageText(r);
  103. #else
  104.             msgTxt = new TParamText(r);
  105. #endif
  106.             msgDlg->insert(msgTxt);
  107.  
  108.             // These are all the commands that issue signs of life.
  109.             switch(cmnd)
  110.             {
  111.                 case cmMoveBlock:
  112.                     Operation = "Mov";
  113.                     break;
  114.  
  115.                 case cmCopyBlock:       // Including clipboard operations.
  116.                     Operation = "Copy";
  117.                     break;
  118.  
  119.                 case cmWrapPara:
  120.                     Operation = "Reformat";
  121.                     break;
  122.  
  123.                 case cmReadFile:        // Reports progress in bytes not lines.
  124.                     Operation = "Read";
  125.                     break;
  126.  
  127.                 case cmWriteBlock:
  128.                     Operation = "Writ";
  129.                     break;
  130.  
  131.                 case cmPrintBlock:
  132.                     Operation = "Print";
  133.                     break;
  134.  
  135.                 // NOTE: If you see delete starting a clipboard copy or cut
  136.                 //       operation, don't panic!  It's just the old block
  137.                 //       of text being cleared from the clipboard.
  138.                 case cmClear:
  139.                     Operation = "Delet";
  140.                     break;
  141.  
  142.                 case cmUndo:        // Serves both undo and redo operations.
  143.                     Operation = "Undoing/Redo";
  144.                     break;
  145.  
  146.                 case cmFind:
  147.                 case cmFindMatching:
  148.                     Operation = "Search";
  149.                     break;
  150.  
  151.                 default:    // All other commands (from alterText())
  152.                     Operation = "Alter";
  153.                     break;
  154.             }
  155.  
  156.             TProgram::application->insert(msgDlg);
  157.             index = -1;
  158.             // Fall through and display the message to complete the case.
  159.  
  160.         case slReporting:
  161.         case slDone:
  162.             index++;            // Turn the spinner.
  163.             if(index == 4)
  164.                 index = 0;
  165.  
  166.             msgTxt->setText("Please Wait...%c\n%sing %ld of %ld",
  167.                 Spinner[index], Operation, count, total);
  168.  
  169.             if(lifeSign == slDone)
  170.             {
  171.                 TObject::destroy(msgDlg);
  172.                 msgDlg = NULL;      // Reset pointer ready for next time.
  173.             }
  174.             break;
  175.  
  176. //        case slHide:          // Unused by the default editor classes,
  177. //            msgDlg->hide();   // but they are here incase you need them.
  178. //            break;
  179. //
  180. //        case slShow:
  181. //            msgDlg->show();
  182. //            break;
  183.     }
  184. }
  185.