home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 26
/
CD_ASCQ_26_1295.iso
/
vrac
/
tvme30.zip
/
TVEDIT3.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-02
|
6KB
|
185 lines
// File : TVEDIT3.CPP
// Author : Eric Woodruff, CIS ID: 72134,1150
// Updated : Wed 08/02/95 17:54:19
// Note : Copyright 1994-95, Eric Woodruff, All rights reserved
// Compiler: Borland C++ 3.1 to 4.xx
//
// This file contains an example of the "signs of life" functions that
// can be implemented with the editor.
//
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#define Uses_TApplication
#define Uses_TDeskTop
#define Uses_TDialog
#define Uses_TParamText
#define Uses_TProgram
#define Uses_TStaticText
#include <tv.h>
#include <tvmedit.h>
#include "tvedit.h"
// ***************************************************************************
#if _TV_VERSION == 0x0103
// TParamText has too many probems in TV 1.03, so this is a simple class
// to handle the message display. Under TV 2.0, TParamText is used because
// it was altered significantly and no longer causes any trouble.
class TMessageText : public TStaticText
{
private:
char *str;
public:
TMessageText(TRect &r) : TStaticText(r, NULL), str(new char [256]) {}
~TMessageText()
{ delete [] str; }
void setText(char *newMsg, ...)
{
va_list ap;
va_start(ap, newMsg);
vsprintf(str, newMsg, ap);
va_end(ap);
drawView();
}
virtual void getText(char *s)
{ strcpy(s, str); }
};
#endif
// ***************************************************************************
// This is the function that handles the various Signs of Life states.
// 'lifeSign' indicates what the function is being called for. 'cmnd'
// indicates which command is being executed. 'count' and 'total' represent
// lines done and the total number of lines to do or, for reading text, bytes
// read so far and the total number of bytes to be read. Note that if either
// GlobalOptions.initThreshold or GlobalOptions.reportInterval is zero, then
// the editor classes will not issue signs of life. This function can be as
// simple or as sophisticated as you want it to be.
//
void doSignsOfLife(SignsOfLife lifeSign, ushort cmnd, long count, long total)
{
static TDialog *msgDlg = NULL;
#if _TV_VERSION == 0x0103
static TMessageText *msgTxt;
#else
static TParamText *msgTxt;
#endif
static char Spinner[4] = { '\\', '|', '/', '-' }, *Operation;
static short index;
TRect r;
// Ignore it if the message box couldn't or wouldn't be created.
if((!msgDlg && lifeSign != slInitiate) || lowMemory())
return;
switch(lifeSign)
{
case slInitiate:
msgDlg = new TDialog(TRect(0, 0, 50, 6), "* Working *");
msgDlg->options |= ofCentered;
msgDlg->flags &= ~wfClose;
#if _TV_VERSION != 0x0103
msgDlg->palette = dpBlueDialog;
#endif
r = msgDlg->getClipRect();
r.grow(-2, -2);
#if _TV_VERSION == 0x0103
msgTxt = new TMessageText(r);
#else
msgTxt = new TParamText(r);
#endif
msgDlg->insert(msgTxt);
// These are all the commands that issue signs of life.
switch(cmnd)
{
case cmMoveBlock:
Operation = "Mov";
break;
case cmCopyBlock: // Including clipboard operations.
Operation = "Copy";
break;
case cmWrapPara:
Operation = "Reformat";
break;
case cmReadFile: // Reports progress in bytes not lines.
Operation = "Read";
break;
case cmWriteBlock:
Operation = "Writ";
break;
case cmPrintBlock:
Operation = "Print";
break;
// NOTE: If you see delete starting a clipboard copy or cut
// operation, don't panic! It's just the old block
// of text being cleared from the clipboard.
case cmClear:
Operation = "Delet";
break;
case cmUndo: // Serves both undo and redo operations.
Operation = "Undoing/Redo";
break;
case cmFind:
case cmFindMatching:
Operation = "Search";
break;
default: // All other commands (from alterText())
Operation = "Alter";
break;
}
TProgram::application->insert(msgDlg);
index = -1;
// Fall through and display the message to complete the case.
case slReporting:
case slDone:
index++; // Turn the spinner.
if(index == 4)
index = 0;
msgTxt->setText("Please Wait...%c\n%sing %ld of %ld",
Spinner[index], Operation, count, total);
if(lifeSign == slDone)
{
TObject::destroy(msgDlg);
msgDlg = NULL; // Reset pointer ready for next time.
}
break;
// case slHide: // Unused by the default editor classes,
// msgDlg->hide(); // but they are here incase you need them.
// break;
//
// case slShow:
// msgDlg->show();
// break;
}
}