home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 17
/
CD_ASCQ_17_101194.iso
/
vrac
/
ve2tv103.zip
/
TVMEDIT.H
< prev
Wrap
Text File
|
1994-07-31
|
35KB
|
1,073 lines
// File : TVMEDIT.H
// Author : Eric Woodruff, CIS ID: 72134,1150
// Updated : Sun 07/31/94 15:56:28
// Note : Copyright 1994, Eric Woodruff, All rights reserved
// Compiler: Borland C++ 3.1 to 4.02
//
// This is the header file for the Virtual Memory Text Editor classes.
// It defines the TVMEditor, TVMMemo, TVMFileEditor, TVMEditWindow,
// and TVMIndicator classes as well as the supporting TVMPoint, TVMScrollBar,
// TVMMemoData, TVMFindDialogRec, and TVMReplaceDialogRec structures.
//
// **
// ** ATTENTION!! PLEASE READ THIS!
// **
// ** Please be aware of the fact that most of the constants and
// ** definitions below duplicate the existing names found in Borland's
// ** EDITORS.H file. I did this intentionally so that the names would be
// ** familiar and so that entirely new command values didn't have to be
// ** created. Many of the duplicate names have the same value assigned to
// ** them as in EDITORS.H but many others don't.
// ** As long as you don't define Borland's Uses_TEditor,
// ** Uses_TFileEditor, Uses_TEditWindow, Uses_TMemo, Uses_TIndicator,
// ** Uses_TReplaceDialogRec, or Uses_TFindDialogRec you shouldn't get any
// ** compiler errors.
// ** Instead, you should be using the equivalent Uses_TVMxxx definitions
// ** for TVMEDIT.H because these classes are all intended as a complete
// ** replacement for the Turbo Vision editor classes. The two should not be
// ** mixed. Given the advantages offered by this set of classes, there
// ** should be no reason to mix them anyway.
// **
#define TVMEDITOR_VERSION 0x0200
#if !defined(__FLAT__)
#if !defined(_NEAR)
#define _NEAR near
#endif
#if !defined(_FAR)
#define _FAR far
#endif
#endif
#if defined(Uses_TVMEditWindow)
#define Uses_TVMFileEditor
#endif
#if defined(Uses_TVMMemo)
#define Uses_TVMFileEditor
#endif
#if defined(Uses_TVMFileEditor)
#define Uses_TVMEditor
#endif
#if defined(Uses_TVMEditor)
#define Uses_TVMPoint
#define Uses_TVMIndicator
#endif
#if defined(Uses_TVMIndicator)
#define Uses_TVMPoint
#endif
#if !defined(__TVMEDITOR_CODES)
#define __TVMEDITOR_CODES
const ushort
kbCtrlLBrkt = 0x1A1B; // Define Ctrl+[ key code value for the
// default Find Matching command key.
const
ufUpdate = 0x01, // Update attached indicators, scrollbars, etc
ufLine = 0x02, // Update one or more lines
ufView = 0x04; // Update the whole thing
const
smNone = 0x00, // No block selection in progress
smBlock = 0x01, // Block Key marking
smShift = 0x02, // Shift+Movement Key marking
smMouse = 0x04, // Mouse drag marking
smLine = 0x08; // Mouse drag whole line marking
const
#if _TV_VERSION == 0x0103
cmSave = 80, // These were already defined in Turbo-Vision
cmSaveAs = 81, // and are kept as-is.
#endif
cmFind = 82, // cmUndo, cmCut, cmCopy, and cmPaste
cmReplace = 83, // are all defined in the VIEWS.H file.
cmSearchAgain = 84,
#if _TV_VERSION == 0x0103
cmSaveAll = 85, // These commands are new.
#endif
cmPrintFile = 86, // They can be disabled if necessary
cmGotoLine = 87, // and are in the reserved 0-99 value range
cmLocalEditorOpt = 88, // like the ones above.
cmRedo = 89,
cmReSynch = 90;
const
cmBufferAlreadyPresent = 500, // The rest of the the commands can't
cmEditorPresent = 501, // be disabled and are in the reserved
cmkbFlagChg = 502, // 256-999 value range.
cmSetLine = 503,
// Names may be the same, but values may not!
cmCharLeft = 504, // Non-destructive commands.
cmCharRight = 505, // These commands don't alter the text.
cmWordLeft = 506,
cmWordRight = 507,
cmLineStart = 508,
cmLineEnd = 509,
cmLineUp = 510,
cmLineDown = 511,
cmShiftUp = 512,
cmShiftDown = 513,
cmPageUp = 514,
cmPageDown = 515,
cmWindowTop = 516,
cmWindowBotm = 517,
cmTextStart = 518,
cmTextEnd = 519,
cmStartSelect = 520,
cmEndSelect = 521,
cmHideSelect = 522,
cmWriteBlock = 523,
cmPrevPos = 524,
cmLastChg = 525,
cmJumpBlkSt = 526,
cmJumpBlkEnd = 527,
cmSetBookmark1 = 528,
cmSetBookmark2 = 529,
cmSetBookmark3 = 530,
cmGoBookmark1 = 531,
cmGoBookmark2 = 532,
cmGoBookmark3 = 533,
cmFindMatching = 534,
cmInsMode = 535,
cmIndentMode = 536,
cmWrapMode = 537,
cmTabStyle = 538,
cmTrailingSpc = 539,
cmUpdateTitle = 540,
cmPrintBlock = 541,
cmFirstDestructive = 542, // These commands are destructive to
cmNewLine = 542, // the text and are filtered out if
cmInsertTab = 543, // the editor is marked Read Only.
cmInsertLine = 544, // Place all such default commands between
cmInsertLiteral = 545, // cmFirstDestructive and cmLastDestructive
cmBackSpace = 546, // to have them filtered out.
cmDelChar = 547, // In derived editors, it is up to the
cmDeleteTab = 548, // overridden handleEvent() to also filter
cmDelWordLeft = 549, // out any additional destructive commands
cmDelWordRight = 550, // for the derived editor class.
cmDelStart = 551,
cmDelEnd = 552,
cmDelLine = 553,
cmCopyBlock = 554,
cmMoveBlock = 555,
cmIndentBlock = 556,
cmUnindentBlock = 557,
cmToggleCase = 558,
cmForceUpper = 559,
cmForceLower = 560,
cmCenterLines = 561,
cmAlignText = 562,
cmWrapPara = 563,
cmReadFile = 564,
cmRestoreLine = 565,
cmLastDestructive = 565;
const
edOutOfMemory = 0, // Editor dialog types
edReadError = 1,
edWriteError = 2,
edCreateError = 3,
edSwapBadSeek = 4,
edSwapFileFail = 5,
edEMSXMSFailure = 6,
edGeneralMsg = 7, // Used by internal diagnostic messages
edLinesSplit = 8, // The default editor dialog function
edLineTooLong = 9, // will ignore dialog requests above
edGotoLine = 10, // edGeneralMsg and automatically return
edChgLocalOpts = 11, // cmCancel. For edGeneralMsg or below,
edFind = 12, // a simple message box is displayed to
edReplace = 13, // draw attention to the error. They
edReplacePrompt = 14, // are serious and should not be ignored.
edSearchFailed = 15,
edReadBlock = 16,
edSaveBlock = 17,
edSaveAs = 18,
edSaveUntitled = 19,
edSaveModify = 20,
edAlterText = 21,
edReSynch = 22;
const // Local editor options
efInsertMode = 0x0001, // Insert mode on/off
efAutoIndent = 0x0002, // Auto-indent mode on/off
efWordWrap = 0x0004, // Word wrap mode on/off
efTrailingSpaces = 0x0008, // Retain trailing spaces on/off
efUseHardTabs = 0x0010, // Use hard tabs on/off
efCanUndo = 0x0020, // Can use undo/redo
// Global editor options
efExpandTabs = 0x0040, // Expand tabs to spaces when loaded
efBackupFiles = 0x0080, // Create backup file when saved
efUseLFOnly = 0x0100, // LF only when file is saved (UNIX style)
efReadOnly = 0x0200; // File is Read Only and can't be edited
const
efParen = 0x0001, // Enter Matching character selections.
efBracket = 0x0002, // These are local to each editor.
efBrace = 0x0004,
efSngQuote = 0x0008,
efDblQuote = 0x0010,
efAngBracket = 0x0020,
efMatchAll = 0xFFFF; // Quick way to say do it for all of the above
const // Find/Replace settings are global options
efCaseSensitive = 0x0001, // Find/Replace options
efWholeWordsOnly = 0x0002,
efPromptOnReplace = 0x0004,
efDoReplace = 0x0008, // Replace modes. These two constants aren't
efReplaceAll = 0x0010; // user-selectable modes, they are internal
// mode flags used by the editor.
const // More user-selectable Find/Replace options
efForward = 0x0000, // Direction
efBackward = 0x0001,
efGlobal = 0x0000, // Scope
efSelectedText = 0x0001,
efFromCursor = 0x0000, // Origin
efEntireScope = 0x0001;
const // Other stuff
maxLineLength = 256, // Maximum line length and search string length
maxSearchString = 80;
// Editor dialog handler definitions
typedef ushort (*TVMEditorDialog)(int, ...);
ushort VMdefEditorDialog(int dialog, ...);
// These are the different states that the signsOfLife() function can be
// called with to handle.
enum SignsOfLife { slInitiate, slReporting, slHide, slShow, slDone };
// Signs of Life handler definitions
typedef void (*TVMSignsOfLife)(SignsOfLife, ushort, long, long);
void VMdefSignsOfLife(SignsOfLife lifeSign, ushort cmnd, long count,
long total);
// This function returns a unique 8 character filename.
extern "C" {
char *unique_name(char *s);
}
#if defined(__FLAT__)
// This function will allocate a descriptor for TVMEditor::lowMemDesc
// and register an exit function to deallocate it at program end.
extern "C" {
void AllocateDescriptor(void);
}
#endif
#endif // __TVMEDITOR_CODES
//
// Class TVMEditWindow
//
// Palette layout:
// Same as TWindow
//
#if defined(Uses_TVMEditWindow) && !defined(__TVMEditWindow)
#define __TVMEditWindow
class _FAR TEvent;
class _FAR TVMFileEditor;
class TVMEditWindow : public TWindow
{
public:
TVMFileEditor *editor;
TVMEditWindow(const TRect &bounds, const char *aFileName, int aNumber = 0,
Boolean IndAtTop = True, short bufSizeInK = 20,
Boolean SuppressLoad = False);
virtual const char *getTitle(short maxSize); // Return filename.
virtual void close(void);
virtual void handleEvent(TEvent &event);
virtual void sizeLimits(TPoint &min, TPoint &max);
private:
static const char * _NEAR clipboardTitle;
static const char * _NEAR untitled;
virtual const char *streamableName() const
{ return name; }
protected:
TVMEditWindow( StreamableInit );
virtual void write( opstream& );
virtual void *read( ipstream& );
public:
static const char * const _NEAR name;
static TStreamable *build();
};
inline ipstream& operator >> ( ipstream& is, TVMEditWindow& cl )
{ return is >> (TStreamable&)cl; }
inline ipstream& operator >> ( ipstream& is, TVMEditWindow*& cl )
{ return is >> (void *&)cl; }
inline opstream& operator << ( opstream& os, TVMEditWindow& cl )
{ return os << (TStreamable&)cl; }
inline opstream& operator << ( opstream& os, TVMEditWindow* cl )
{ return os << (TStreamable *)cl; }
#endif // Uses_TVMEditWindow
// Class TVMPoint
// Similar in nature to a TPoint, but has a y value that is long.
// This allows the editor to load files with more than 32,767 lines.
//
#if defined(Uses_TVMPoint) && !defined(__TVMPoint)
#define __TVMPoint
class TVMPoint
{
public:
TVMPoint& operator+=( const TVMPoint& adder );
TVMPoint& operator-=( const TVMPoint& subber );
friend TVMPoint operator - ( const TVMPoint& one, const TVMPoint& two);
friend TVMPoint operator + ( const TVMPoint& one, const TVMPoint& two);
friend int operator == ( const TVMPoint& one, const TVMPoint& two);
friend int operator != ( const TVMPoint& one, const TVMPoint& two);
short x; // Column (limited to 0-255)
long y; // Line (unlimited range)
};
inline TVMPoint& TVMPoint::operator += ( const TVMPoint& adder )
{
x += adder.x;
y += adder.y;
return *this;
}
inline TVMPoint& TVMPoint::operator -= ( const TVMPoint& subber )
{
x -= subber.x;
y -= subber.y;
return *this;
}
inline ipstream& operator >> ( ipstream& is, TVMPoint& p )
{ return is >> p.x >> p.y; }
inline ipstream& operator >> ( ipstream& is, TVMPoint*& p )
{ return is >> p->x >> p->y; }
inline opstream& operator << ( opstream& os, TVMPoint& p )
{ return os << p.x << p.y; }
inline opstream& operator << ( opstream& os, TVMPoint* p )
{ return os << p->x << p->y; }
#endif // Uses_TVMPoint
//
// Class TVMIndicator
//
// Palette layout:
// 1 = Edit Window - Custom color via TVCOLR.H
// 2 = Memo Field - Custom color via TVCOLR.H
//
#if defined(Uses_TVMIndicator) && !defined(__TVMIndicator)
#define __TVMIndicator
class _FAR TEvent;
class _FAR TPalette;
class TVMIndicator : public TView
{
protected:
TVMPoint Location;
Boolean ShowReadOnly, UseMemoColor, Modified;
ushort Opts;
short RightMargin, TabSize, Swapping;
char Message[80];
const char *DefaultMsg; // Default indicator message
public:
TVMIndicator(const TRect &bounds, Boolean ShowRO = True,
Boolean IsForMemo = True);
virtual TPalette& getPalette(void) const;
virtual void draw(void);
// Set the default message string
inline void setDefaultMessage(const char *msg)
{
delete (void *)DefaultMsg;
DefaultMsg = newStr(msg);
}
// Set indicator values
void setValue(const TVMPoint &aLocation, Boolean aModified,
ushort aOpts, short RMargin, short TabSz, short SwapStatus);
// Set and display a temporary flag message
void setMessage(const char *msg);
private:
virtual const char *streamableName() const
{ return name; }
protected:
TVMIndicator(StreamableInit);
virtual void write( opstream& );
virtual void *read( ipstream& );
public:
static const char * const _NEAR name;
static TStreamable *build();
};
inline ipstream& operator >> ( ipstream& is, TVMIndicator& cl )
{ return is >> (TStreamable&)cl; }
inline ipstream& operator >> ( ipstream& is, TVMIndicator*& cl )
{ return is >> (void *&)cl; }
inline opstream& operator << ( opstream& os, TVMIndicator& cl )
{ return os << (TStreamable&)cl; }
inline opstream& operator << ( opstream& os, TVMIndicator* cl )
{ return os << (TStreamable *)cl; }
#endif // Uses_TVMIndicator
// Class TVMScrollBar
//
// Palette Layout:
// Same as a regular TScrollBar
//
#if defined( Uses_TVMScrollBar ) && !defined( __TVMScrollBar )
#define __TVMScrollBar
class _FAR TRect;
class _FAR TEvent;
typedef char TVMScrollChars[5];
class TVMScrollBar : public TView
{
private:
static TVMScrollChars _NEAR vChars;
static TVMScrollChars _NEAR hChars;
public:
TVMScrollChars chars;
long value, minVal, maxVal, pgStep, arStep;
// ****************************************************************************
TVMScrollBar(const TRect& bounds);
virtual void draw(void);
virtual TPalette& getPalette() const;
virtual void handleEvent(TEvent& event);
virtual void scrollDraw(void);
virtual long scrollStep(long part);
void setParams(long aValue, long aMin, long aMax, long aPgStep,
long aArStep);
void setRange(long aMin, long aMax);
void setStep(long aPgStep, long aArStep);
void setValue(long aValue);
void drawPos(long pos);
long getPos();
long getSize();
private:
long getPartCode(void);
virtual const char *streamableName() const
{ return name; }
protected:
TVMScrollBar( StreamableInit );
virtual void write( opstream& );
virtual void *read( ipstream& );
public:
static const char * const _NEAR name;
static TStreamable *build();
};
inline ipstream& operator >> ( ipstream& is, TVMScrollBar& cl )
{ return is >> (TStreamable&)cl; }
inline ipstream& operator >> ( ipstream& is, TVMScrollBar*& cl )
{ return is >> (void *&)cl; }
inline opstream& operator << ( opstream& os, TVMScrollBar& cl )
{ return os << (TStreamable&)cl; }
inline opstream& operator << ( opstream& os, TVMScrollBar* cl )
{ return os << (TStreamable *)cl; }
#endif // Uses_TVMScrollBar
//
// Class TVMEditor
//
// Palette layout:
// 1 = Normal Text - Maps to owning view's color 6 (Normal Text)
// 2 = Highlighted Text - Maps to owning view's color 7 (Highlighted Text)
// 3 = Selected Message - Custom color via TVCOLR.H (Used by the
// cmSetLine command. See demo.)
//
#if defined(Uses_TVMEditor) && !defined(__TVMEditor)
#define __TVMEditor
#if !defined(__DIR_H)
#include <dir.h> // For MAXPATH definition
#endif // __DIR_H
// TVIRTMEM.H and TVIRTM32.H are only distributed to registered users.
#if defined(Uses_TVirtualMemory)
#include <tvirtmem.h>
#else
class _FAR TVirtualMemory;
#endif
class _FAR TEvent;
class _FAR TPalette;
class _FAR TRect;
class _FAR TScrollBar;
class _FAR TVMScrollBar;
class _FAR TVMIndicator;
// Global editor options structure. This structure contains options used
// by all editor object instances along with the defaults for the local
// options structure below.
struct GlobalEditorOptions
{
ushort Operation, // Default operating modes
EnterMatch; // Default Enter Matching characters
short TabSize, // Default tab size
IndentSize, // Default block indent size
RightMargin; // Default right margin
// NOTE: Any changes in the structure ABOVE this point should also
// be taken into account for structure LocalEditorOptions below.
// The rest of this structure is for global items only.
// Search options
ushort Search;
// Signs of Life.
// These two values indicate when signs of life should be issued by
// the editor. What this means is that after initThreshold lines,
// the editor will place a call to the signsOfLife() function to let
// the user know it is still working and hasn't locked up. After that,
// it will place a call to it every reportInterval lines.
short initThreshold;
short reportInterval;
// Default filename extensions. These are currently only used by
// TVMFileEditor.
char DefaultExt[4], BackupExt[4];
// Default drive/dir for swap files. This can be used by virtual
// memory systems needing a swap file for each editor instance.
char DefaultSwapDir[MAXPATH];
// Print device (LPT1, LPT2, COM1, COM2, filename, etc).
char PrintDevice[MAXPATH];
};
// Local editor options structure. These options are local to each
// instance and can be changed for each one without affecting any of
// the other objects. As above, changes here should be taken into
// acount for structure GlobalEditorOptions.
struct LocalEditorOptions
{
ushort Operation, // Operating modes
EnterMatch; // Enter Matching characters
short TabSize, // Tab size
IndentSize, // Block indent size
RightMargin; // Right margin
};
//
// And now for the class itself.
//
class TVMEditor : public TView
{
public:
// TVirtualMemory is a friend of TVMEditor so that it can update some
// of the private data members to keep the editor and the buffer
// in sync.
friend TVirtualMemory;
// Static data used by all instances.
static TVMEditorDialog _NEAR editorDialog; // User interaction dialog.
static TVMSignsOfLife _NEAR signsOfLife; // Signs of Life function.
static TVMEditor * _NEAR clipboard; // Clipboard pointer.
static const char * _NEAR charLeft; // Valid Enter Matching
static const char * _NEAR charRight; // characters.
static const char * _NEAR TwoKeyMsg; // Indicator messages.
static const char * _NEAR LiteralMsg;
// Global options structure shared by all instances
// Some of these become the defaults for each new instance.
static GlobalEditorOptions _NEAR GlobalOpts;
// Current search/replace criteria (also shared by all instances)
static ushort _NEAR searchDirection;
static ushort _NEAR searchScope;
static ushort _NEAR searchOrigin;
static char _NEAR findStr[maxFindStrLen];
static char _NEAR replaceStr[maxReplaceStrLen];
#if defined(__FLAT__)
// Public low memory descriptor for 32-bit PM. You should insure that
// this is non-zero before using it. If it is zero, place a call to
// AllocateDescriptor().
static unsigned short lowMemDesc;
#endif
// Other public variables.
// The virtual memory buffer object. The virtual memory manager is a
// separate entity to allow the modification of the underlying virtual
// memory engine (switch from EMS + disk to XMS + disk for example).
// Also, multiple editors can share the same buffer object to conserve
// memory. Note that if no EMS or XMS memory is available, it will
// go straight to disk for its virtual memory.
TVirtualMemory *Buffer;
// Flags: Is valid or not, line has been edited.
Boolean isValid, LineEdited;
LocalEditorOptions Opts; // Options local to each instance
protected:
TScrollBar *hScrollBar; // Normal horizontal scrollbar
TVMScrollBar *vScrollBar; // Vertical scrollbar uses long values
TVMIndicator *indicator; // Indicator for TVMEditor
char Text[maxLineLength + 1]; // Current edit line buffer
TVMPoint delta, limit, curPos; // View offset, limits, cursor position
short selStartC, selEndC; // Block start and end columns for
// XY block selection.
long selStart, selEnd, // Block start and end lines
drawLine, // Current line at top of window
findLine, // Line where search text was found
setLine; // Line that was moved to by cmSetLine
SignsOfLife sl_Type; // Signs of Life status variables.
long sl_Count, sl_ReportMark, // These are used internally to
sl_Bytes, sl_Total; // track when they should occur.
short curPosx_t, // Cursor position in edited line
keyState; // Two-key command state indicator
uchar lockCount, updateFlags; // Screen update controls
short selecting; // Type of select mode in use
Boolean FirstLoad; // Signals first time file is loaded
long lastChg, // Last modified line
prevLine, // Previous cursor line
Bookmark1, Bookmark2, Bookmark3; // Bookmarks
// ***************************************************************************
public:
TVMEditor(const TRect &bounds, TScrollBar *aHScrollBar,
TVMScrollBar *aVScrollBar, TVMIndicator *aIndicator,
short bufSizeInK = 8);
virtual Boolean valid(ushort command);
virtual void shutDown(void);
virtual void convertEvent(TEvent &event);
virtual void handleEvent(TEvent &event);
virtual TPalette &getPalette(void) const;
virtual void setState(ushort aState, Boolean enable);
virtual void updateCommands(void);
virtual void changeBounds(const TRect &bounds);
virtual void draw(void);
virtual void drawLines(short y, short count, long lineNbr);
virtual void setXIndex(short newPos);
virtual void setScrIndex(short newPos);
virtual const char *getSwapFileName(void);
virtual Boolean setSwapFileName(const char *aFileName);
virtual Boolean isWordChar(int ch);
virtual void doneBuffer(void);
// ***************************************************************************
// Allow the option bits to be set externally.
inline void setOption(ushort efConst, Boolean On)
{ (On) ? (Opts.Operation |= efConst) : (Opts.Operation &= ~efConst); }
// Check undo/redo state.
inline Boolean canUndo(void)
{ return Boolean((Opts.Operation & efCanUndo) != 0); }
// Cursor position and limits shouldn't be modified directly so they
// are protected. These two inline functions will let you know what
// they are currently set to.
inline void cursorPos(short &x, long &y)
{ x = curPos.x;
y = curPos.y; }
inline void textLimits(short &x, long &y)
{ x = limit.x;
y = limit.y; }
// This one is used internally for clipboard operations.
inline ushort getTextIndex()
{ return curPosx_t; };
// It is more expedient in an iterative, line-by-line operation to call
// the virtual memory buffer text retrieval functions directly and work
// with the Text[] line (a Compile operation for example). This returns
// a const char * to Text[] for those cases.
inline const char *lineText(void)
{ return Text; }
// Other inline functions.
inline Boolean cursorVisible(void)
{ return Boolean(
(curPos.y > delta.y && curPos.y <= delta.y + size.y) &&
(curPos.x >= delta.x && curPos.x < delta.x + size.x) );
}
inline void lock(void)
{ lockCount++; }
inline void unlock(void)
{
if(lockCount)
{
lockCount--;
if(!lockCount)
doUpdate();
}
}
inline Boolean isClipboard(void)
{ return Boolean(clipboard == this); }
// Set indicator's default message.
inline void setDefaultMessage(const char *msg)
{
if(indicator)
indicator->setDefaultMessage(msg);
}
// This is the static function that allows changing of key maps.
static Boolean changeKeyMap(short index, const ushort *newMap);
// ***************************************************************************
void setCmdState(ushort command, Boolean enable);
void setSelect(short fromX, long fromY, short toX, long toY,
Boolean goTop = False);
void putCursorAt(short x, long y, Boolean center = False);
void scrollTo(short x, long y);
void trackCursor(Boolean center);
void update(uchar aFlags);
void doUpdate(void);
short pad(short pos);
short trim(char *sline, char *chptr);
void moveChar(short move, Boolean isSelecting = False);
void moveWord(short move, Boolean isSelecting = False);
void moveLine(long move, Boolean isSelecting = False);
Boolean insertChar(char ch, Boolean insChar);
void insertTab(Boolean centerCursor);
void insertCR(void);
void deleteChar(Boolean DelRight);
void deleteTab(Boolean centerCursor);
void deleteLine(void);
Boolean hasSelection(void);
void adjustBlock(short difference);
void deleteBlock(void); // Non-clipboard delete, move, copy
void moveBlock(void);
void copyBlock(void);
Boolean insertFrom(TVMEditor *insEd); // Clipboard copy, cut, paste
Boolean clipCopy(void);
Boolean clipCut(void);
Boolean clipPaste(void);
Boolean wrapLine(void);
void wrapPara(void);
void alterText(long from, long to, ushort cmnd);
void SearchDialog(Boolean Replace);
void doSearchReplace(void);
Boolean search(void);
void FindMatching(void);
private:
virtual const char *streamableName() const
{ return name; }
protected:
TVMEditor( StreamableInit );
virtual void write( opstream& );
virtual void *read( ipstream& );
public:
static const char * const _NEAR name;
static TStreamable *build();
};
inline ipstream& operator >> ( ipstream& is, TVMEditor& cl )
{ return is >> (TStreamable&)cl; }
inline ipstream& operator >> ( ipstream& is, TVMEditor*& cl )
{ return is >> (void *&)cl; }
inline opstream& operator << ( opstream& os, TVMEditor& cl )
{ return os << (TStreamable&)cl; }
inline opstream& operator << ( opstream& os, TVMEditor* cl )
{ return os << (TStreamable *)cl; }
#endif // Uses_TVMEditor
//
// Class TVMFileEditor
//
// Palette layout:
// Same as TVMEditor
//
#if defined(Uses_TVMFileEditor) && !defined(__TVMFileEditor)
#define __TVMFileEditor
class _FAR TEvent;
class _FAR TScrollBar;
class _FAR TVMScrollBar;
class _FAR TVMIndicator;
class TVMFileEditor : public TVMEditor
{
public:
char fileName[MAXPATH];
TVMFileEditor(const TRect &bounds, TScrollBar *aHScrollBar,
TVMScrollBar *aVScrollBar, TVMIndicator *aIndicator,
const char *aFileName, short bufSizeInK = 20,
Boolean SuppressLoad = False);
virtual Boolean valid(ushort command);
virtual void handleEvent(TEvent &event);
virtual void shutDown(void);
virtual void updateCommands(void);
virtual void doneBuffer(Boolean reloadFile);
// Virtual function to print the buffer content.
virtual void PrintBuffer(long from, long to);
void loadFileNow(void);
Boolean save(void);
Boolean saveAs(void);
private:
void readFile(char *name);
long readText(char *name, long line, Boolean InitialLoad);
Boolean writeFile(long from, long to, char *name);
virtual const char *streamableName() const
{ return name; }
protected:
TVMFileEditor( StreamableInit );
virtual void write( opstream& );
virtual void *read( ipstream& );
public:
static const char * const _NEAR name;
static TStreamable *build();
};
inline ipstream& operator >> ( ipstream& is, TVMFileEditor& cl )
{ return is >> (TStreamable&)cl; }
inline ipstream& operator >> ( ipstream& is, TVMFileEditor*& cl )
{ return is >> (void *&)cl; }
inline opstream& operator << ( opstream& os, TVMFileEditor& cl )
{ return os << (TStreamable&)cl; }
inline opstream& operator << ( opstream& os, TVMFileEditor* cl )
{ return os << (TStreamable *)cl; }
#endif // Uses_TVMFileEditor
//
// Class TVMMemo
//
// Palette layout:
// 1 = Normal Text - Maps to owning view's color 26 (ListVwr Normal)
// 2 = Highlighted Text - Maps to owning view's color 27 (ListVwr Focused)
//
#if defined(Uses_TVMMemo ) && !defined(__TVMMemo)
#define __TVMMemo
// This is the field structure to use in the dialog's data structure.
struct TVMMemoData
{
// Maximum length. Up to 60K or use 0 to signal use of
// LoadMemo/RetrieveMemo.
ushort length;
// NOTE: This is a pointer now, not an array!
char *buffer;
// The amount of data to store by setData(). This is how many
// characters are parsed when loading data into the editor.
// Also:
// The amount of data returned by getData(). This is how much text
// was retrieved from the memo editor into the buffer.
ushort copyCount;
};
class _FAR TPalette;
class _FAR TScrollBar;
class _FAR TVMScrollBar;
class _FAR TVMIndicator;
// NOTE: Derived from TVMFileEditor to take advantage of the ability to
// load, save, and print text.
class TVMMemo : public TVMFileEditor
{
protected:
// Maximum allowable length. Set to a non-zero value by setData()
// when necessary and used by valid() to see if the text will fit
// in the user-supplied buffer for getData().
ushort Length;
// Line terminator for load/retrieve functions.
char LineTerminator;
public:
static const char * _NEAR MemoTooLong; // Memo too long message.
TVMMemo(const TRect &bounds, TScrollBar *aHScrollBar,
TVMScrollBar *aVScrollBar, TVMIndicator *aIndicator,
short bufSizeInK = 4, const char *aFileName = NULL);
virtual TPalette& getPalette() const;
virtual void handleEvent(TEvent &event);
virtual Boolean valid(ushort command);
virtual void getData(void *rec);
virtual void setData(void *rec);
virtual ushort dataSize(void);
virtual Boolean LoadMemo(ushort length, char *buffer,
Boolean FirstPart);
virtual ushort RetrieveMemo(ushort length, char *buffer,
Boolean FirstPart, Boolean *NotDone = NULL);
inline Boolean setLineTerminator(char lTerm)
{
// '\r' will equate to "\r\n"
if(lTerm != EOS || lTerm != '\r' || lTerm != '\n')
return False;
LineTerminator = lTerm;
return True;
}
private:
virtual const char *streamableName() const
{ return name; }
protected:
TVMMemo( StreamableInit );
virtual void write( opstream& );
virtual void *read( ipstream& );
public:
static const char * const _NEAR name;
static TStreamable *build();
};
inline ipstream& operator >> ( ipstream& is, TVMMemo& cl )
{ return is >> (TStreamable&)cl; }
inline ipstream& operator >> ( ipstream& is, TVMMemo*& cl )
{ return is >> (void *&)cl; }
inline opstream& operator << ( opstream& os, TVMMemo& cl )
{ return os << (TStreamable&)cl; }
inline opstream& operator << ( opstream& os, TVMMemo* cl )
{ return os << (TStreamable *)cl; }
#endif // Uses_TVMMemo
//
// Search and Replace data structures.
//
#if defined(Uses_TVMSearchDialogRec) && !defined(__TVMSearchDialogRec)
#define __TVMSearchDialogRec
struct TVMFindDialogRec
{
char find[maxSearchString];
ushort options, searchDirection, searchScope, searchOrigin;
TVMFindDialogRec( char *findStr, ushort editOpts, ushort searchDir,
ushort searchSc, ushort searchOrg)
{
strcpy(find, findStr);
options = editOpts;
searchDirection = searchDir;
searchScope = searchSc;
searchOrigin = searchOrg;
}
};
struct TVMReplaceDialogRec
{
char find[maxSearchString], replace[maxSearchString];
ushort options, searchDirection, searchScope, searchOrigin;
TVMReplaceDialogRec( char *findStr, char *replaceStr, ushort editOpts,
ushort searchDir, ushort searchSc, ushort searchOrg)
{
strcpy(find, findStr);
strcpy(replace, replaceStr);
options = editOpts;
searchDirection = searchDir;
searchScope = searchSc;
searchOrigin = searchOrg;
}
};
#endif // Uses_TVMSearchDialogRec