home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / tvme30.zip / TVMEDIT.H < prev    next >
Text File  |  1995-08-02  |  37KB  |  1,113 lines

  1. // System  : TVMEditor 3.00 - Virtual Memory Text Editor Library
  2. // File    : TVMEDIT.H
  3. // Author  : Eric Woodruff,  CIS ID: 72134,1150
  4. // Updated : Wed 08/02/95 17:54:19
  5. // Note    : Copyright 1994-95, Eric Woodruff, All rights reserved
  6. // Compiler: Borland C++ 3.1 to 4.xx
  7. //
  8. // This is the header file for the Virtual Memory Text Editor classes.
  9. // It defines the TVMEditor, TVMMemo, TVMFileEditor, TVMEditWindow,
  10. // and TVMIndicator classes as well as the supporting TVMPoint, TVMScrollBar,
  11. // TVMMemoData, TVMFindDialogRec, and TVMReplaceDialogRec structures.
  12. //
  13. // **
  14. // ** ATTENTION!!  PLEASE READ THIS!
  15. // **
  16. // **     Please be aware of the fact that most of the constants and
  17. // ** definitions below duplicate the existing names found in Borland's
  18. // ** EDITORS.H file. I did this intentionally so that the names would be
  19. // ** familiar and so that entirely new command values didn't have to be
  20. // ** created.  Many of the duplicate names have the same value assigned to
  21. // ** them as in EDITORS.H but many others don't.
  22. // **     As long as you don't define Borland's Uses_TEditor,
  23. // ** Uses_TFileEditor, Uses_TEditWindow, Uses_TMemo, Uses_TIndicator,
  24. // ** Uses_TReplaceDialogRec, or Uses_TFindDialogRec you shouldn't get any
  25. // ** compiler errors.
  26. // **     Instead, you should be using the equivalent Uses_TVMxxx definitions
  27. // ** for TVMEDIT.H because these classes are all intended as a complete
  28. // ** replacement for the Turbo Vision editor classes.  The two should not be
  29. // ** mixed.  Given the advantages offered by this set of classes, there
  30. // ** should be no reason to mix them anyway.
  31. // **
  32.  
  33. #define TVMEDITOR_VERSION   0x0300      // 3.00
  34. #define TVMVERSION_STRING   "3.00"
  35.  
  36. #if !defined(__FLAT__)
  37.  
  38. #if !defined(_NEAR)
  39. #define _NEAR   near
  40. #endif
  41.  
  42. #if !defined(_FAR)
  43. #define _FAR    far
  44. #endif
  45.  
  46. #endif
  47.  
  48. #if defined(Uses_TVMEditWindow)
  49. #define Uses_TVMFileEditor
  50. #endif
  51.  
  52. #if defined(Uses_TVMMemo)
  53. #define Uses_TVMFileEditor
  54. #endif
  55.  
  56. #if defined(Uses_TVMFileEditor)
  57. #define Uses_TVMEditor
  58. #endif
  59.  
  60. #if defined(Uses_TVMEditor)
  61. #define Uses_TVMPoint
  62. #define Uses_TVMIndicator
  63. #endif
  64.  
  65. #if defined(Uses_TVMIndicator)
  66. #define Uses_TVMPoint
  67. #endif
  68.  
  69. #if !defined(__TVMEDITOR_CODES)
  70. #define __TVMEDITOR_CODES
  71.  
  72. const ushort
  73.   kbCtrlLBrkt = 0x1A1B;         // Define Ctrl+[ key code value for the
  74.                                 // default Find Matching command key.
  75. const
  76.   ufUpdate = 0x01,              // Update attached indicators, scrollbars, etc
  77.   ufLine   = 0x02,              // Update one or more lines
  78.   ufView   = 0x04;              // Update the whole thing
  79.  
  80. const
  81.   smNone   = 0x00,              // No block selection in progress
  82.   smBlock  = 0x01,              // Block Key marking
  83.   smShift  = 0x02,              // Shift+Movement Key marking
  84.   smMouse  = 0x04,              // Mouse drag marking
  85.   smLine   = 0x08;              // Mouse drag whole line marking
  86.  
  87. const
  88. #if _TV_VERSION == 0x0103
  89.   cmSave        = 80,           // These were already defined in Turbo-Vision
  90.   cmSaveAs      = 81,           // and are kept as-is.
  91. #endif
  92.   cmFind        = 82,           // cmUndo, cmCut, cmCopy, and cmPaste
  93.   cmReplace     = 83,           // are all defined in the VIEWS.H file.
  94.   cmSearchAgain = 84,
  95.  
  96. #if _TV_VERSION == 0x0103
  97.   cmSaveAll        = 85,        // These commands are new.
  98. #endif
  99.   cmPrintFile      = 86,        // They can be disabled if necessary
  100.   cmGotoLine       = 87,        // and are in the reserved 0-99 value range
  101.   cmLocalEditorOpt = 88,        // like the ones above.
  102.   cmRedo           = 89,
  103.   cmReSynch        = 90;
  104.  
  105. const
  106.   cmBufferAlreadyPresent = 500, // The rest of the the commands can't
  107.   cmEditorPresent = 501,        // be disabled and are in the reserved
  108.   cmkbFlagChg     = 502,        // 256-999 value range.
  109.   cmSetLine       = 503,
  110.   cmResizeReformat = 504,
  111.   cmForceReformat = 505,
  112.                                 // Names may be the same, but values may not!
  113.   cmCharLeft     = 506,         // Non-destructive commands.
  114.   cmCharRight    = 507,         // These commands don't alter the text.
  115.   cmWordLeft     = 508,
  116.   cmWordRight    = 509,
  117.   cmLineStart    = 510,
  118.   cmLineEnd      = 511,
  119.   cmLineUp       = 512,
  120.   cmLineDown     = 513,
  121.   cmShiftUp      = 514,
  122.   cmShiftDown    = 515,
  123.   cmPageUp       = 516,
  124.   cmPageDown     = 517,
  125.   cmWindowTop    = 518,
  126.   cmWindowBotm   = 519,
  127.   cmTextStart    = 520,
  128.   cmTextEnd      = 521,
  129.   cmStartSelect  = 522,
  130.   cmEndSelect    = 523,
  131.   cmHideSelect   = 524,
  132.   cmWriteBlock   = 525,
  133.   cmPrevPos      = 526,
  134.   cmLastChg      = 527,
  135.   cmJumpBlkSt    = 528,
  136.   cmJumpBlkEnd   = 529,
  137.   cmSetBookmark1 = 530,
  138.   cmSetBookmark2 = 531,
  139.   cmSetBookmark3 = 532,
  140.   cmGoBookmark1  = 533,
  141.   cmGoBookmark2  = 534,
  142.   cmGoBookmark3  = 535,
  143.   cmFindMatching = 536,
  144.   cmInsMode      = 537,
  145.   cmIndentMode   = 538,
  146.   cmWrapMode     = 539,
  147.   cmAutoWrapMode = 540,
  148.   cmWrapOnResize = 541,
  149.   cmTabStyle     = 542,
  150.   cmTrailingSpc  = 543,
  151.   cmUpdateTitle  = 544,
  152.   cmPrintBlock   = 545,
  153.  
  154.   cmFirstDestructive = 546,     // These commands are destructive to
  155.   cmNewLine       = 546,        // the text and are filtered out if
  156.   cmInsertTab     = 547,        // the editor is marked Read Only.
  157.   cmInsertLine    = 548,        // Place all such default commands between
  158.   cmInsertLiteral = 549,        // cmFirstDestructive and cmLastDestructive
  159.   cmBackSpace     = 550,        // to have them filtered out.
  160.   cmDelChar       = 551,        // In derived editors, it is up to the
  161.   cmDeleteTab     = 552,        // overridden handleEvent() to also filter
  162.   cmDelWordLeft   = 553,        // out any additional destructive commands
  163.   cmDelWordRight  = 554,        // for the derived editor class.
  164.   cmDelStart      = 555,
  165.   cmDelEnd        = 556,
  166.   cmDelLine       = 557,
  167.   cmCopyBlock     = 558,
  168.   cmMoveBlock     = 559,
  169.   cmIndentBlock   = 560,
  170.   cmUnindentBlock = 561,
  171.   cmToggleCase    = 562,
  172.   cmForceUpper    = 563,
  173.   cmForceLower    = 564,
  174.   cmCenterLines   = 565,
  175.   cmAlignText     = 566,
  176.   cmWrapPara      = 567,
  177.   cmReadFile      = 568,
  178.   cmRestoreLine   = 569,
  179.   cmLastDestructive = 569;
  180.  
  181. const
  182.   edOutOfMemory   = 0,          // Editor dialog types
  183.   edReadError     = 1,
  184.   edWriteError    = 2,
  185.   edCreateError   = 3,
  186.   edSwapBadSeek   = 4,
  187.   edSwapFileFail  = 5,
  188.   edEMSXMSFailure = 6,
  189.   edGeneralMsg    = 7,          // Used by internal diagnostic messages
  190.  
  191.   edLinesSplit    = 8,          // The default editor dialog function
  192.   edLineTooLong   = 9,          // will ignore dialog requests above
  193.   edGotoLine      = 10,         // edGeneralMsg and automatically return
  194.   edChgLocalOpts  = 11,         // cmCancel.  For edGeneralMsg or below,
  195.   edFind          = 12,         // a simple message box is displayed to
  196.   edReplace       = 13,         // draw attention to the error.  They
  197.   edReplacePrompt = 14,         // are serious and should not be ignored.
  198.   edSearchFailed  = 15,
  199.   edReadBlock     = 16,
  200.   edSaveBlock     = 17,
  201.   edSaveAs        = 18,
  202.   edSaveUntitled  = 19,
  203.   edSaveModify    = 20,
  204.   edAlterText     = 21,
  205.   edReSynch       = 22;
  206.  
  207. const                           // Local editor options
  208.   efInsertMode     = 0x0001,    // Insert mode on/off
  209.   efAutoIndent     = 0x0002,    // Auto-indent mode on/off
  210.   efWordWrap       = 0x0004,    // Word wrap mode on/off
  211.   efAutoWrap       = 0x0008,    // Auto word wrap (alters efWordWrap usage)
  212.   efWrapOnResize   = 0x0010,    // Wrap on window resize on/off
  213.   efTrailingSpaces = 0x0020,    // Retain trailing spaces on/off
  214.   efUseHardTabs    = 0x0040,    // Use hard tabs on/off
  215.   efCanUndo        = 0x0080,    // Can use undo/redo
  216.  
  217.   efNonPersistentBlocks = 0x0100,   // Blocks are non-persistent
  218.   efAllowOverwrite      = 0x0200,   // Overwrite non-persistent blocks
  219.   efOverwriteBlocks     = 0x0300,   // Single constant for checking whether
  220.                                     // overwriteable blocks are allowed.
  221.  
  222.                                 // Global editor options
  223.   efExpandTabs     = 0x0400,    // Expand tabs to spaces when loaded
  224.   efBackupFiles    = 0x0800,    // Create backup file when saved
  225.   efUseLFOnly      = 0x1000,    // LF only when file is saved (UNIX style)
  226.  
  227.                                 // Other options.  These bits are inherited
  228.                                 // like local options but probably shouldn't
  229.                                 // be user-modifiable.
  230.   efReadOnly       = 0x2000,    // File is Read Only and can't be edited
  231.   efSetROonLoad    = 0x4000,    // Set efReadOnly when file's RO attrib. is on
  232.  
  233.   efUseCSH         = 0x8000;    // For use with Color Syntax Highlighter 1.00
  234.                                 // The basic editor does nothing with this.
  235. const
  236.   efParen          = 0x0001,    // Enter Matching character selections.
  237.   efBracket        = 0x0002,    // These are local to each editor.
  238.   efBrace          = 0x0004,
  239.   efSngQuote       = 0x0008,
  240.   efDblQuote       = 0x0010,
  241.   efAngBracket     = 0x0020,
  242.   efMatchAll       = 0x00FF,    // Quick way to say do it for all of the above
  243.  
  244.   efAutoEOLMark    = 0x1000;    // Automatically insert EOLMarker on cmNewLine
  245.  
  246. const                           // Find/Replace settings are global options
  247.   efCaseSensitive   = 0x0001,   // Find/Replace options
  248.   efWholeWordsOnly  = 0x0002,
  249.   efPromptOnReplace = 0x0004,
  250.  
  251.   efDoReplace       = 0x0008,   // Replace modes.  These two constants aren't
  252.   efReplaceAll      = 0x0010;   // user-selectable modes, they are internal
  253.                                 // mode flags used by the editor.
  254.  
  255. const                           // More user-selectable Find/Replace options
  256.   efForward      = 0x0000,      // Direction
  257.   efBackward     = 0x0001,
  258.  
  259.   efGlobal       = 0x0000,      // Scope
  260.   efSelectedText = 0x0001,
  261.  
  262.   efFromCursor   = 0x0000,      // Origin
  263.   efEntireScope  = 0x0001;
  264.  
  265. const                           // Other stuff
  266.   maxLineLength = 256,          // Maximum line length and search string length
  267.   maxSearchString = 80;
  268.  
  269. // Editor dialog handler definitions
  270. typedef ushort (*TVMEditorDialog)(int, ...);
  271. ushort VMdefEditorDialog(int dialog, ...);
  272.  
  273. // These are the different states that the signsOfLife() function can be
  274. // called with to handle.
  275. enum SignsOfLife { slInitiate, slReporting, slHide, slShow, slDone };
  276.  
  277. // Signs of Life handler definitions
  278. typedef void (*TVMSignsOfLife)(SignsOfLife, ushort, long, long);
  279. void VMdefSignsOfLife(SignsOfLife lifeSign, ushort cmnd, long count,
  280.     long total);
  281.  
  282. // This function returns a unique 8 character filename.
  283. extern "C" {
  284. char *unique_name(char *s);
  285. }
  286.  
  287. #if defined(__FLAT__)
  288. // This function will allocate a descriptor for TVMEditor::lowMemDesc
  289. // and register an exit function to deallocate it at program end.
  290. extern "C" {
  291. void AllocateDescriptor(void);
  292. }
  293. #endif
  294.  
  295. #endif  // __TVMEDITOR_CODES
  296.  
  297. //
  298. // Class TVMEditWindow
  299. //
  300. //  Palette layout:
  301. //      Same as TWindow
  302. //
  303. #if defined(Uses_TVMEditWindow) && !defined(__TVMEditWindow)
  304. #define __TVMEditWindow
  305.  
  306. class _FAR TEvent;
  307. class _FAR TVMFileEditor;
  308. class _FAR TVMScrollBar;
  309. class _FAR TVMIndicator;
  310.  
  311. class TVMEditWindow : public TWindow
  312. {
  313. public:
  314.     TVMFileEditor *editor;
  315.  
  316.     TVMEditWindow(const TRect &bounds, const char *aFileName, int aNumber = 0,
  317.         Boolean IndAtTop = True, short bufSizeInK = 20,
  318.         Boolean SuppressLoad = False);
  319.  
  320.     virtual const char *getTitle(short maxSize);    // Return filename.
  321.     virtual void close(void);
  322.     virtual void handleEvent(TEvent &event);
  323.     virtual void sizeLimits(TPoint &min, TPoint &max);
  324.  
  325. private:
  326.     static const char * _NEAR clipboardTitle;
  327.     static const char * _NEAR untitled;
  328.  
  329.     virtual const char *streamableName() const
  330.         { return name; }
  331.  
  332. protected:
  333.     TVMEditWindow( StreamableInit );
  334.     virtual void write( opstream& );
  335.     virtual void *read( ipstream& );
  336.  
  337. public:
  338.     static const char * const _NEAR name;
  339.     static TStreamable *build();
  340. };
  341.  
  342. inline ipstream& operator >> ( ipstream& is, TVMEditWindow& cl )
  343.     { return is >> (TStreamable&)cl; }
  344. inline ipstream& operator >> ( ipstream& is, TVMEditWindow*& cl )
  345.     { return is >> (void *&)cl; }
  346.  
  347. inline opstream& operator << ( opstream& os, TVMEditWindow& cl )
  348.     { return os << (TStreamable&)cl; }
  349. inline opstream& operator << ( opstream& os, TVMEditWindow* cl )
  350.     { return os << (TStreamable *)cl; }
  351.  
  352. #endif  // Uses_TVMEditWindow
  353.  
  354. // Class TVMPoint
  355. //  Similar in nature to a TPoint, but has a y value that is long.
  356. //  This allows the editor to load files with more than 32,767 lines.
  357. //
  358. #if defined(Uses_TVMPoint) && !defined(__TVMPoint)
  359. #define __TVMPoint
  360.  
  361. class TVMPoint
  362. {
  363. public:
  364.     TVMPoint& operator+=( const TVMPoint& adder );
  365.     TVMPoint& operator-=( const TVMPoint& subber );
  366.  
  367.     friend TVMPoint operator - ( const TVMPoint& one, const TVMPoint& two);
  368.     friend TVMPoint operator + ( const TVMPoint& one, const TVMPoint& two);
  369.     friend int operator == ( const TVMPoint& one, const TVMPoint& two);
  370.     friend int operator != ( const TVMPoint& one, const TVMPoint& two);
  371.  
  372.     short x;        // Column (limited to 0-255)
  373.     long  y;        // Line   (unlimited range)
  374. };
  375.  
  376. inline TVMPoint& TVMPoint::operator += ( const TVMPoint& adder )
  377. {
  378.     x += adder.x;
  379.     y += adder.y;
  380.     return *this;
  381. }
  382.  
  383. inline TVMPoint& TVMPoint::operator -= ( const TVMPoint& subber )
  384. {
  385.     x -= subber.x;
  386.     y -= subber.y;
  387.     return *this;
  388. }
  389.  
  390. inline ipstream& operator >> ( ipstream& is, TVMPoint& p )
  391.     { return is >> p.x >> p.y; }
  392. inline ipstream& operator >> ( ipstream& is, TVMPoint*& p )
  393.     { return is >> p->x >> p->y; }
  394. inline opstream& operator << ( opstream& os, TVMPoint& p )
  395.     { return os << p.x << p.y; }
  396. inline opstream& operator << ( opstream& os, TVMPoint* p )
  397.     { return os << p->x << p->y; }
  398.  
  399. #endif  // Uses_TVMPoint
  400.  
  401. //
  402. // Class TVMIndicator
  403. //
  404. //  Palette layout:
  405. //      1 = Edit Window  - Custom color via TVCOLR.H
  406. //      2 = Memo Field   - Custom color via TVCOLR.H
  407. //
  408. #if defined(Uses_TVMIndicator) && !defined(__TVMIndicator)
  409. #define __TVMIndicator
  410.  
  411. class _FAR TEvent;
  412. class _FAR TPalette;
  413.  
  414. class TVMIndicator : public TView
  415. {
  416. protected:
  417.     TVMPoint Location;
  418.     Boolean  ShowReadOnly, UseMemoColor, Modified;
  419.     ushort   Opts;
  420.     short    RightMargin, TabSize, Swapping;
  421.     char     Message[80];
  422.     const char *DefaultMsg;         // Default indicator message
  423.  
  424. public:
  425.  
  426.     TVMIndicator(const TRect &bounds, Boolean ShowRO = True,
  427.         Boolean IsForMemo = True);
  428.  
  429.     virtual TPalette& getPalette(void) const;
  430.     virtual void draw(void);
  431.  
  432.     // Set the default message string
  433.     inline void setDefaultMessage(const char *msg)
  434.     {
  435.         delete (void *)DefaultMsg;
  436.         DefaultMsg = newStr(msg);
  437.         drawView();
  438.     }
  439.  
  440.     // Set indicator values
  441.     void setValue(const TVMPoint &aLocation, Boolean aModified,
  442.         ushort aOpts, short RMargin, short TabSz, short SwapStatus);
  443.  
  444.     // Set and display a temporary flag message
  445.     void setMessage(const char *msg);
  446.  
  447. private:
  448.     virtual const char *streamableName() const
  449.         { return name; }
  450.  
  451. protected:
  452.     TVMIndicator(StreamableInit);
  453.     virtual void write( opstream& );
  454.     virtual void *read( ipstream& );
  455.  
  456. public:
  457.     static const char * const _NEAR name;
  458.     static TStreamable *build();
  459. };
  460.  
  461. inline ipstream& operator >> ( ipstream& is, TVMIndicator& cl )
  462.     { return is >> (TStreamable&)cl; }
  463. inline ipstream& operator >> ( ipstream& is, TVMIndicator*& cl )
  464.     { return is >> (void *&)cl; }
  465.  
  466. inline opstream& operator << ( opstream& os, TVMIndicator& cl )
  467.     { return os << (TStreamable&)cl; }
  468. inline opstream& operator << ( opstream& os, TVMIndicator* cl )
  469.     { return os << (TStreamable *)cl; }
  470.  
  471. #endif  // Uses_TVMIndicator
  472.  
  473. // Class TVMScrollBar
  474. //
  475. //  Palette Layout:
  476. //      Same as a regular TScrollBar
  477. //
  478. #if defined( Uses_TVMScrollBar ) && !defined( __TVMScrollBar )
  479. #define __TVMScrollBar
  480.  
  481. class _FAR TRect;
  482. class _FAR TEvent;
  483.  
  484. typedef char TVMScrollChars[5];
  485.  
  486. class TVMScrollBar : public TView
  487. {
  488. private:
  489.     static TVMScrollChars _NEAR vChars;
  490.     static TVMScrollChars _NEAR hChars;
  491.  
  492. public:
  493.     TVMScrollChars chars;
  494.  
  495.     long value, minVal, maxVal, pgStep, arStep;
  496.  
  497. // ****************************************************************************
  498.  
  499.     TVMScrollBar(const TRect& bounds);
  500.  
  501.     virtual void draw(void);
  502.     virtual TPalette& getPalette() const;
  503.     virtual void handleEvent(TEvent& event);
  504.     virtual void scrollDraw(void);
  505.     virtual long scrollStep(long part);
  506.  
  507.     void  setParams(long aValue, long aMin, long aMax, long aPgStep,
  508.                     long aArStep);
  509.     void  setRange(long aMin, long aMax);
  510.     void  setStep(long aPgStep, long aArStep);
  511.     void  setValue(long aValue);
  512.  
  513.     void  drawPos(long pos);
  514.     long  getPos();
  515.     long  getSize();
  516.  
  517. private:
  518.     long  getPartCode(void);
  519.  
  520.     virtual const char *streamableName() const
  521.         { return name; }
  522.  
  523. protected:
  524.     TVMScrollBar( StreamableInit );
  525.     virtual void write( opstream& );
  526.     virtual void *read( ipstream& );
  527.  
  528. public:
  529.     static const char * const _NEAR name;
  530.     static TStreamable *build();
  531. };
  532.  
  533. inline ipstream& operator >> ( ipstream& is, TVMScrollBar& cl )
  534.     { return is >> (TStreamable&)cl; }
  535. inline ipstream& operator >> ( ipstream& is, TVMScrollBar*& cl )
  536.     { return is >> (void *&)cl; }
  537.  
  538. inline opstream& operator << ( opstream& os, TVMScrollBar& cl )
  539.     { return os << (TStreamable&)cl; }
  540. inline opstream& operator << ( opstream& os, TVMScrollBar* cl )
  541.     { return os << (TStreamable *)cl; }
  542.  
  543. #endif  // Uses_TVMScrollBar
  544.  
  545. //
  546. // Class TVMEditor
  547. //
  548. //  Palette layout:
  549. //      1 = Normal Text      - Maps to owning view's color 6 (Normal Text)
  550. //      2 = Highlighted Text - Maps to owning view's color 7 (Highlighted Text)
  551. //      3 = Selected Message - Custom color via TVCOLR.H (Used by the
  552. //                             cmSetLine command.  See demo.)
  553. //
  554. #if defined(Uses_TVMEditor) && !defined(__TVMEditor)
  555. #define __TVMEditor
  556.  
  557. #if !defined(__DIR_H)
  558. #include <dir.h>        // For MAXPATH definition
  559. #endif  // __DIR_H
  560.  
  561. // TVIRTMEM.H is only distributed to registered users.
  562. #if defined(Uses_TVirtualMemory)
  563.     #include <tvirtmem.h>
  564. #else
  565.     class _FAR TVirtualMemory;
  566. #endif
  567.  
  568. class _FAR TEvent;
  569. class _FAR TPalette;
  570. class _FAR TRect;
  571. class _FAR TScrollBar;
  572. class _FAR TVMScrollBar;
  573. class _FAR TVMIndicator;
  574.  
  575. // Global editor options structure.  This structure contains options used
  576. // by all editor object instances along with the defaults for the local
  577. // options structure below.
  578. struct GlobalEditorOptions
  579. {
  580.     ushort Operation,       // Default operating modes
  581.            EnterMatch;      // Default Enter Matching characters
  582.  
  583.     short  TabSize,         // Default tab size
  584.            IndentSize,      // Default block indent size
  585.            RightMargin;     // Default right margin
  586.  
  587.     // NOTE: Any changes in the structure ABOVE this point should also
  588.     //       be taken into account for structure LocalEditorOptions below.
  589.     //       The rest of this structure is for global items only.
  590.  
  591.     // Search options
  592.     ushort Search;
  593.  
  594.     // Signs of Life.
  595.     // These two values indicate when signs of life should be issued by
  596.     // the editor.  What this means is that after initThreshold lines,
  597.     // the editor will place a call to the signsOfLife() function to let
  598.     // the user know it is still working and hasn't locked up.  After that,
  599.     // it will place a call to it every reportInterval lines.
  600.     short initThreshold;
  601.     short reportInterval;
  602.  
  603.     // Default filename extensions.  These are currently only used by
  604.     // TVMFileEditor.
  605.     char   DefaultExt[4], BackupExt[4];
  606.  
  607.     // Default drive/dir for swap files.  This can be used by virtual
  608.     // memory systems needing a swap file for each editor instance.
  609.     char   DefaultSwapDir[MAXPATH];
  610.  
  611.     // Print device (LPT1, LPT2, COM1, COM2, filename, etc).
  612.     char   PrintDevice[MAXPATH];
  613. };
  614.  
  615. // Local editor options structure.  These options are local to each
  616. // instance and can be changed for each one without affecting any of
  617. // the other objects.  As above, changes here should be taken into
  618. // acount for structure GlobalEditorOptions.
  619. struct LocalEditorOptions
  620. {
  621.     ushort Operation,       // Operating modes
  622.            EnterMatch;      // Enter Matching characters
  623.  
  624.     short  TabSize,         // Tab size
  625.            IndentSize,      // Block indent size
  626.            RightMargin;     // Right margin
  627. };
  628.  
  629. //
  630. // And now for the class itself.
  631. //
  632. class TVMEditor : public TView
  633. {
  634. public:
  635.     // TVirtualMemory is a friend of TVMEditor so that it can update some
  636.     // of the private data members to keep the editor and the buffer
  637.     // in sync.
  638.     friend TVirtualMemory;
  639.  
  640.     // Static data used by all instances.
  641.     static TVMEditorDialog _NEAR editorDialog;     // User interaction dialog.
  642.     static TVMSignsOfLife _NEAR signsOfLife;       // Signs of Life function.
  643.  
  644.     static TVMEditor * _NEAR clipboard;            // Clipboard pointer.
  645.  
  646.     static const char * _NEAR charLeft;            // Valid Enter Matching
  647.     static const char * _NEAR charRight;           // characters.
  648.  
  649.     static const char * _NEAR TwoKeyMsg;           // Indicator messages.
  650.     static const char * _NEAR LiteralMsg;
  651.  
  652.     static char _NEAR EOLMarker;    // wrapPara() line length inhibitor char.
  653.  
  654.     // Global options structure shared by all instances
  655.     // Some of these become the defaults for each new instance.
  656.     static GlobalEditorOptions _NEAR GlobalOpts;
  657.  
  658.     // Current search/replace criteria (also shared by all instances)
  659.     static ushort _NEAR searchDirection;
  660.     static ushort _NEAR searchScope;
  661.     static ushort _NEAR searchOrigin;
  662.     static char   _NEAR findStr[maxFindStrLen];
  663.     static char   _NEAR replaceStr[maxReplaceStrLen];
  664.  
  665. #if defined(__FLAT__)
  666.     // Public low memory descriptor for 32-bit PM.  You should insure that
  667.     // this is non-zero before using it.  If it is zero, place a call to
  668.     // AllocateDescriptor().
  669.     static unsigned short lowMemDesc;
  670. #endif
  671.  
  672.     // Other public variables.
  673.  
  674.     // The virtual memory buffer object.  The virtual memory manager is a
  675.     // separate entity to allow the modification of the underlying virtual
  676.     // memory engine (switch from EMS + disk to XMS + disk for example).
  677.     // Also, multiple editors can share the same buffer object to conserve
  678.     // memory.  Note that if no EMS or XMS memory is available, it will
  679.     // go straight to disk for its virtual memory.
  680.     TVirtualMemory *Buffer;
  681.  
  682.     // Flags: Is valid or not, line has been edited.
  683.     Boolean isValid, LineEdited;
  684.  
  685.     LocalEditorOptions Opts;            // Options local to each instance
  686.  
  687. protected:
  688.     TScrollBar   *hScrollBar;           // Normal horizontal scrollbar
  689.     TVMScrollBar *vScrollBar;           // Vertical scrollbar uses long values
  690.     TVMIndicator *indicator;            // Indicator for TVMEditor
  691.  
  692.     char Text[maxLineLength + 1];       // Current edit line buffer
  693.  
  694.     TVMPoint delta, limit, curPos;      // View offset, limits, cursor position
  695.  
  696.     short selStartC, selEndC;           // Block start and end columns for
  697.                                         // XY block selection.
  698.     long  selStart, selEnd,             // Block start and end lines
  699.           drawLine,                     // Current line at top of window
  700.           findLine,                     // Line where search text was found
  701.           setLine;                      // Line that was moved to by cmSetLine
  702.  
  703.     SignsOfLife sl_Type;                 // Signs of Life status variables.
  704.     long        sl_Count, sl_ReportMark, // These are used internally to
  705.                 sl_Bytes, sl_Total;      // track when they should occur.
  706.  
  707.     short curPosx_t,                    // Cursor position in edited line
  708.           keyState;                     // Two-key command state indicator
  709.  
  710.     uchar lockCount, updateFlags;       // Screen update controls
  711.  
  712.     short   selecting;                  // Type of select mode in use
  713.  
  714.     Boolean FirstLoad,                  // Signals first time file is loaded
  715.             hasChangedSize;             // Used by the Wrap On Resize code
  716.  
  717.     long    lastChg,                          // Last modified line
  718.             prevLine,                         // Previous cursor line
  719.             Bookmark1, Bookmark2, Bookmark3;  // Bookmarks
  720.  
  721. // ***************************************************************************
  722. public:
  723.     TVMEditor(const TRect &bounds, TScrollBar *aHScrollBar,
  724.         TVMScrollBar *aVScrollBar, TVMIndicator *aIndicator,
  725.         short bufSizeInK = 8);
  726.  
  727.     virtual Boolean valid(ushort command);
  728.     virtual void    shutDown(void);
  729.     virtual void    convertEvent(TEvent &event);
  730.     virtual void    handleEvent(TEvent &event);
  731.  
  732.     virtual TPalette &getPalette(void) const;
  733.  
  734.     virtual void setState(ushort aState, Boolean enable);
  735.     virtual void updateCommands(void);
  736.  
  737.     virtual void changeBounds(const TRect &bounds);
  738.     virtual void draw(void);
  739.     virtual void drawLines(short y, short count, long lineNbr);
  740.  
  741.     virtual void setXIndex(short newPos);
  742.     virtual void setScrIndex(short newPos);
  743.  
  744.     virtual const char *getSwapFileName(void);
  745.     virtual Boolean setSwapFileName(const char *aFileName);
  746.  
  747.     virtual Boolean isWordChar(int ch);
  748.  
  749.     virtual void doneBuffer(Boolean releaseMem = True);
  750.  
  751. // ***************************************************************************
  752.  
  753.     // Allow the option bits to be set externally.
  754.     inline void setOption(ushort efConst, Boolean On)
  755.         { (On) ? (Opts.Operation |= efConst) : (Opts.Operation &= ~efConst); }
  756.  
  757.     // Check undo/redo state.
  758.     inline Boolean canUndo(void)
  759.         {   return Boolean((Opts.Operation & efCanUndo) != 0);  }
  760.  
  761.     // Cursor position and limits shouldn't be modified directly so they
  762.     // are protected.  These two inline functions will let you know what
  763.     // they are currently set to.
  764.     inline void cursorPos(short &x, long &y)
  765.         {   x = curPos.x;
  766.             y = curPos.y;   }
  767.  
  768.     inline void textLimits(short &x, long &y)
  769.         {   x = limit.x;
  770.             y = limit.y;    }
  771.  
  772.     // This one is used internally for clipboard operations.
  773.     inline ushort getTextIndex()
  774.         {   return curPosx_t;   };
  775.  
  776.     // It is more expedient in an iterative, line-by-line operation to call
  777.     // the virtual memory buffer text retrieval functions directly and work
  778.     // with the Text[] line (a Compile operation for example).  This returns
  779.     // a const char * to Text[] for those cases.
  780.     inline const char *lineText(void)
  781.         {   return Text;    }
  782.  
  783.     // Other inline functions.
  784.     inline Boolean cursorVisible(void)
  785.         {   return Boolean(
  786.                 (curPos.y > delta.y && curPos.y <= delta.y + size.y) &&
  787.                 (curPos.x >= delta.x && curPos.x < delta.x + size.x) );
  788.         }
  789.  
  790.     inline void lock(void)
  791.         {   lockCount++;     }
  792.  
  793.     inline void unlock(void)
  794.     {
  795.         if(lockCount)
  796.         {
  797.             lockCount--;
  798.             if(!lockCount)
  799.                 doUpdate();
  800.         }
  801.     }
  802.  
  803.     inline Boolean isClipboard(void)
  804.         {   return Boolean(clipboard == this);  }
  805.  
  806.     // Set indicator's default message.
  807.     inline void setDefaultMessage(const char *msg)
  808.     {
  809.         if(indicator)
  810.             indicator->setDefaultMessage(msg);
  811.     }
  812.  
  813.     // This is the static function that allows changing of key maps.
  814.     static Boolean changeKeyMap(short index, const ushort *newMap);
  815.  
  816. // ***************************************************************************
  817.  
  818.     void    setCmdState(ushort command, Boolean enable);
  819.  
  820.     void    setSelect(short fromX, long fromY, short toX, long toY,
  821.                 Boolean goTop = False);
  822.     void    putCursorAt(short x, long y, Boolean center = False);
  823.     void    scrollTo(short x, long y);
  824.     void    trackCursor(Boolean center);
  825.     void    update(uchar aFlags);
  826.     void    doUpdate(void);
  827.  
  828.     long    getTextSize(void);
  829.  
  830.     short   pad(short pos);
  831.     short   trim(char *sline, char *chptr);
  832.  
  833.     void    moveChar(short move, Boolean isSelecting = False);
  834.     void    moveWord(short move, Boolean isSelecting = False);
  835.     void    moveLine(long move, Boolean isSelecting = False);
  836.  
  837.     Boolean insertChar(char ch, Boolean insChar);
  838.     void    insertTab(Boolean centerCursor);
  839.     void    insertCR(void);
  840.  
  841.     void    deleteChar(Boolean DelRight);
  842.     void    deleteTab(Boolean centerCursor);
  843.     void    deleteLine(void);
  844.  
  845.     Boolean hasSelection(void);
  846.     void    adjustBlock(short difference);
  847.  
  848.     void    deleteBlock(void);             // Non-clipboard delete, move, copy
  849.     void    moveBlock(void);
  850.     void    copyBlock(void);
  851.  
  852.     Boolean insertFrom(TVMEditor *insEd);  // Clipboard copy, cut, paste
  853.     Boolean clipCopy(void);
  854.     Boolean clipCut(void);
  855.     Boolean clipPaste(void);
  856.     Boolean insertAtCursor(const char *text);
  857.  
  858.     ushort  getSelectedTextSize(char LineTerm);
  859.     ushort  getSelectedText(char *buffer, ushort length, char LineTerm,
  860.         Boolean *NotDone);
  861.  
  862.     Boolean wrapLine(void);
  863.     void    wrapPara(void);
  864.     void    reformatAll(void);
  865.     void    doAutoWrap(void);
  866.  
  867.     void    alterText(long from, long to, ushort cmnd);
  868.  
  869.     void    SearchDialog(Boolean Replace);
  870.     void    doSearchReplace(void);
  871.     Boolean search(void);
  872.     void    FindMatching(void);
  873.  
  874. private:
  875.     virtual const char *streamableName() const
  876.         { return name; }
  877.  
  878. protected:
  879.     TVMEditor( StreamableInit );
  880.     virtual void write( opstream& );
  881.     virtual void *read( ipstream& );
  882.  
  883. public:
  884.     static const char * const _NEAR name;
  885.     static TStreamable *build();
  886. };
  887.  
  888. inline ipstream& operator >> ( ipstream& is, TVMEditor& cl )
  889.     { return is >> (TStreamable&)cl; }
  890. inline ipstream& operator >> ( ipstream& is, TVMEditor*& cl )
  891.     { return is >> (void *&)cl; }
  892.  
  893. inline opstream& operator << ( opstream& os, TVMEditor& cl )
  894.     { return os << (TStreamable&)cl; }
  895. inline opstream& operator << ( opstream& os, TVMEditor* cl )
  896.     { return os << (TStreamable *)cl; }
  897.  
  898. #endif  // Uses_TVMEditor
  899.  
  900. //
  901. // Class TVMFileEditor
  902. //
  903. //  Palette layout:
  904. //      Same as TVMEditor
  905. //
  906. #if defined(Uses_TVMFileEditor) && !defined(__TVMFileEditor)
  907. #define __TVMFileEditor
  908.  
  909. class _FAR TEvent;
  910. class _FAR TScrollBar;
  911. class _FAR TVMScrollBar;
  912. class _FAR TVMIndicator;
  913.  
  914. class TVMFileEditor : public TVMEditor
  915. {
  916. public:
  917.     char fileName[MAXPATH];
  918.  
  919.     TVMFileEditor(const TRect &bounds, TScrollBar *aHScrollBar,
  920.         TVMScrollBar *aVScrollBar, TVMIndicator *aIndicator,
  921.         const char *aFileName, short bufSizeInK = 20,
  922.         Boolean SuppressLoad = False);
  923.  
  924.     virtual Boolean valid(ushort command);
  925.     virtual void handleEvent(TEvent &event);
  926.     virtual void shutDown(void);
  927.     virtual void updateCommands(void);
  928.  
  929.     virtual void doneBuffer(Boolean releaseMem = True,
  930.         Boolean reloadFile = True);
  931.  
  932.     // Virtual function to print the buffer content.
  933.     virtual void PrintBuffer(long from, long to);
  934.  
  935.     void    loadFileNow(void);
  936.     Boolean save(void);
  937.     Boolean saveAs(void);
  938.  
  939. private:
  940.     void    readFile(char *name);
  941.     long    readText(char *name, long line, Boolean InitialLoad);
  942.     Boolean writeFile(long from, long to, char *name,
  943.         Boolean updateTimeStamp = False);
  944.  
  945.     virtual const char *streamableName() const
  946.         { return name; }
  947.  
  948. protected:
  949.     TVMFileEditor( StreamableInit );
  950.     virtual void write( opstream& );
  951.     virtual void *read( ipstream& );
  952.  
  953. public:
  954.     static const char * const _NEAR name;
  955.     static TStreamable *build();
  956. };
  957.  
  958. inline ipstream& operator >> ( ipstream& is, TVMFileEditor& cl )
  959.     { return is >> (TStreamable&)cl; }
  960. inline ipstream& operator >> ( ipstream& is, TVMFileEditor*& cl )
  961.     { return is >> (void *&)cl; }
  962.  
  963. inline opstream& operator << ( opstream& os, TVMFileEditor& cl )
  964.     { return os << (TStreamable&)cl; }
  965. inline opstream& operator << ( opstream& os, TVMFileEditor* cl )
  966.     { return os << (TStreamable *)cl; }
  967.  
  968. #endif  // Uses_TVMFileEditor
  969.  
  970. //
  971. // Class TVMMemo
  972. //
  973. //  Palette layout:
  974. //      1 = Normal Text      - Maps to owning view's color 26 (ListVwr Normal)
  975. //      2 = Highlighted Text - Maps to owning view's color 27 (ListVwr Focused)
  976. //
  977. #if defined(Uses_TVMMemo ) && !defined(__TVMMemo)
  978. #define __TVMMemo
  979.  
  980. // This is the field structure to use in the dialog's data structure.
  981. struct TVMMemoData
  982. {
  983.     // Maximum length.  Up to 60K or use 0 to signal use of
  984.     // LoadMemo/RetrieveMemo.
  985.     ushort   length;
  986.  
  987.     // NOTE: This is a pointer now, not an array!
  988.     char    *buffer;
  989.  
  990.     // The amount of data to store by setData().  This is how many
  991.     // characters are parsed when loading data into the editor.
  992.     // Also:
  993.     // The amount of data returned by getData().  This is how much text
  994.     // was retrieved from the memo editor into the buffer.
  995.     ushort  copyCount;
  996. };
  997.  
  998. class _FAR TPalette;
  999. class _FAR TScrollBar;
  1000. class _FAR TVMScrollBar;
  1001. class _FAR TVMIndicator;
  1002.  
  1003. // NOTE: Derived from TVMFileEditor to take advantage of the ability to
  1004. //       load, save, and print text.
  1005. class TVMMemo : public TVMFileEditor
  1006. {
  1007. protected:
  1008.     // Maximum allowable length.  Set to a non-zero value by setData()
  1009.     // when necessary and used by valid() to see if the text will fit
  1010.     // in the user-supplied buffer for getData().
  1011.     ushort Length;
  1012.  
  1013.     // Line terminator for load/retrieve functions.
  1014.     char   LineTerminator;
  1015.  
  1016. public:
  1017.     static const char * _NEAR MemoTooLong;       // Memo too long message.
  1018.  
  1019.     TVMMemo(const TRect &bounds, TScrollBar *aHScrollBar,
  1020.         TVMScrollBar *aVScrollBar, TVMIndicator *aIndicator,
  1021.         short bufSizeInK = 1, const char *aFileName = NULL);
  1022.  
  1023.     virtual TPalette& getPalette() const;
  1024.  
  1025.     virtual void    handleEvent(TEvent &event);
  1026.     virtual Boolean valid(ushort command);
  1027.  
  1028.     virtual void   getData(void *rec);
  1029.     virtual void   setData(void *rec);
  1030.     virtual ushort dataSize(void);
  1031.  
  1032.     virtual Boolean LoadMemo(ushort length, char *buffer,
  1033.         Boolean FirstPart);
  1034.     virtual ushort RetrieveMemo(ushort length, char *buffer,
  1035.         Boolean FirstPart, Boolean *NotDone = NULL);
  1036.  
  1037.     inline Boolean setLineTerminator(char lTerm)
  1038.     {
  1039.         // '\r' will equate to "\r\n"
  1040.         if(lTerm != EOS && lTerm != '\r' && lTerm != '\n')
  1041.             return False;
  1042.  
  1043.         LineTerminator = lTerm;
  1044.         return True;
  1045.     }
  1046.  
  1047. private:
  1048.     virtual const char *streamableName() const
  1049.         { return name; }
  1050.  
  1051. protected:
  1052.     TVMMemo( StreamableInit );
  1053.     virtual void write( opstream& );
  1054.     virtual void *read( ipstream& );
  1055.  
  1056. public:
  1057.     static const char * const _NEAR name;
  1058.     static TStreamable *build();
  1059. };
  1060.  
  1061. inline ipstream& operator >> ( ipstream& is, TVMMemo& cl )
  1062.     { return is >> (TStreamable&)cl; }
  1063. inline ipstream& operator >> ( ipstream& is, TVMMemo*& cl )
  1064.     { return is >> (void *&)cl; }
  1065.  
  1066. inline opstream& operator << ( opstream& os, TVMMemo& cl )
  1067.     { return os << (TStreamable&)cl; }
  1068. inline opstream& operator << ( opstream& os, TVMMemo* cl )
  1069.     { return os << (TStreamable *)cl; }
  1070.  
  1071. #endif  // Uses_TVMMemo
  1072.  
  1073. //
  1074. // Search and Replace data structures.
  1075. //
  1076. #if defined(Uses_TVMSearchDialogRec) && !defined(__TVMSearchDialogRec)
  1077. #define __TVMSearchDialogRec
  1078.  
  1079. struct TVMFindDialogRec
  1080. {
  1081.     char   find[maxSearchString];
  1082.     ushort options, searchDirection, searchScope, searchOrigin;
  1083.  
  1084.     TVMFindDialogRec( char *findStr, ushort editOpts, ushort searchDir,
  1085.         ushort searchSc, ushort searchOrg)
  1086.     {
  1087.         strcpy(find, findStr);
  1088.         options = editOpts;
  1089.         searchDirection = searchDir;
  1090.         searchScope = searchSc;
  1091.         searchOrigin = searchOrg;
  1092.     }
  1093. };
  1094.  
  1095. struct TVMReplaceDialogRec
  1096. {
  1097.     char   find[maxSearchString], replace[maxSearchString];
  1098.     ushort options, searchDirection, searchScope, searchOrigin;
  1099.  
  1100.     TVMReplaceDialogRec( char *findStr, char *replaceStr, ushort editOpts,
  1101.         ushort searchDir, ushort searchSc, ushort searchOrg)
  1102.     {
  1103.         strcpy(find, findStr);
  1104.         strcpy(replace, replaceStr);
  1105.         options = editOpts;
  1106.         searchDirection = searchDir;
  1107.         searchScope = searchSc;
  1108.         searchOrigin = searchOrg;
  1109.     }
  1110. };
  1111.  
  1112. #endif      // Uses_TVMSearchDialogRec
  1113.