home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / ve2tv103.zip / TVMEDIT.H < prev   
Text File  |  1994-07-31  |  35KB  |  1,073 lines

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