home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / wrdwrp / editors.h next >
Encoding:
C/C++ Source or Header  |  1992-01-02  |  15.3 KB  |  563 lines

  1. /* ------------------------------------------------------------------------*/
  2. /*                                                                         */
  3. /*   EDITORS.H                                                             */
  4. /*                                                                         */
  5. /*   Copyright (c) Borland International 1991                              */
  6. /*   All Rights Reserved.                                                  */
  7. /*                                                                         */
  8. /*   defines the classes TIndicator, TEditor, TMemo, TFileEditor,          */
  9. /*   and TEditWindow                                                       */
  10. /*                                                                         */
  11. /*  Primatech Modification History:                                        */
  12. /*                                                                         */
  13. /*      11-06-91 JLS  Made following changes to TEditor:                   */
  14. /*                      Made some functions inline                         */
  15. /*                      Made data members private or protected             */
  16. /*                      Made setBufLen() protected                         */
  17. /*                                                                         */
  18. /*      11-07-91 JLS  Made the following changes to TEditor:               */
  19. /*                      Made the Boolean flags public again                */
  20. /*                                                                         */
  21. /*      11-12-91 JLS  Made insertText() into an inline function in the     */
  22. /*                      TEditor class.                                     */
  23. /*                                                                         */
  24. /*      11-19-91 JLS  Added alwaysWrap parm to insertBuffer() and          */
  25. /*                      deleteSelect()                                     */
  26. /*                                                                         */
  27. /*      12-02-91 JLS  Made scrollTo(int,int) into a virtual function       */
  28. /*                                                                         */
  29. /*      01-02-91 JLS  Added shutDown() to TFileEditor as in BC++ 3.0       */
  30. /*                                                                         */
  31. /* ------------------------------------------------------------------------*/
  32.  
  33. #if !defined( __DIR_H )
  34. #include <dir.h>
  35. #endif  // __DIR_H
  36.  
  37. #if !defined( __STRING_H )
  38. #include <string.h>
  39. #endif  // __STRING_H
  40.  
  41. #if !defined( __LIMITS_H )
  42. #include <limits.h>
  43. #endif  // __LIMITS_H
  44.  
  45. #if !defined( __EDIT_COMMAND_CODES )
  46. #define __EDIT_COMMAND_CODES
  47.  
  48. const
  49.   ufUpdate = 0x01,
  50.   ufLine   = 0x02,
  51.   ufView   = 0x04;
  52.  
  53. const
  54.   smExtend = 0x01,
  55.   smDouble = 0x02;
  56.  
  57. const unsigned
  58.   sfSearchFailed = 0xFFFF;
  59.  
  60. const
  61.   cmSave        = 80,
  62.   cmSaveAs      = 81,
  63.   cmFind        = 82,
  64.   cmReplace     = 83,
  65.   cmSearchAgain = 84,
  66.   cmReplaceAgain = 85,
  67.   cmToggleWrap  = 86,
  68.   cmToggleAutoMargin = 87;
  69.  
  70. const
  71.   cmCharLeft    = 500,
  72.   cmCharRight   = 501,
  73.   cmWordLeft    = 502,
  74.   cmWordRight   = 503,
  75.   cmLineStart   = 504,
  76.   cmLineEnd     = 505,
  77.   cmLineUp      = 506,
  78.   cmLineDown    = 507,
  79.   cmPageUp      = 508,
  80.   cmPageDown    = 509,
  81.   cmTextStart   = 510,
  82.   cmTextEnd     = 511,
  83.   cmNewLine     = 512,
  84.   cmBackSpace   = 513,
  85.   cmDelChar     = 514,
  86.   cmDelWord     = 515,
  87.   cmDelStart    = 516,
  88.   cmDelEnd      = 517,
  89.   cmDelLine     = 518,
  90.   cmInsMode     = 519,
  91.   cmStartSelect = 520,
  92.   cmHideSelect  = 521,
  93.   cmIndentMode  = 522,
  94.   cmUpdateTitle = 523,
  95.   cmWindowStart = 524,
  96.   cmWindowEnd   = 525;
  97.  
  98. const
  99.   edOutOfMemory   = 0,
  100.   edReadError     = 1,
  101.   edWriteError    = 2,
  102.   edCreateError   = 3,
  103.   edSaveModify    = 4,
  104.   edSaveUntitled  = 5,
  105.   edSaveAs        = 6,
  106.   edFind          = 7,
  107.   edSearchFailed  = 8,
  108.   edReplace       = 9,
  109.   edReplacePrompt = 10;
  110.  
  111. const
  112.   efCaseSensitive   = 0x0001,
  113.   efWholeWordsOnly  = 0x0002,
  114.   efPromptOnReplace = 0x0004,
  115.   efReplaceAll      = 0x0008,
  116.   efDoReplace       = 0x0010,
  117.   efBackupFiles     = 0x0100;
  118.  
  119. const
  120.   maxLineLength = 256;
  121.  
  122. #endif  // __EDIT_COMMAND_CODES
  123.  
  124. typedef ushort (*TEditorDialog)( int, ... );
  125. ushort defEditorDialog( int dialog, ... );
  126.  
  127. #if defined( Uses_TIndicator ) && !defined( __TIndicator )
  128. #define __TIndicator
  129.  
  130. class far TRect;
  131.  
  132. class TIndicator : public TView
  133. {
  134.  
  135. public:
  136.  
  137.     TIndicator( const TRect& );
  138.  
  139.     virtual void draw();
  140.     virtual TPalette& getPalette() const;
  141.     virtual void setState( ushort, Boolean );
  142.     void setValue( const TPoint&, Boolean );
  143.  
  144. protected:
  145.  
  146.     TPoint location;
  147.     Boolean modified;
  148.  
  149. private:
  150.  
  151.     static const char near dragFrame;
  152.     static const char near normalFrame;
  153.  
  154.     virtual const char *streamableName() const
  155.         { return name; }
  156.  
  157. protected:
  158.  
  159.     TIndicator( StreamableInit );
  160.  
  161. public:
  162.  
  163.     static const char * const near name;
  164.     static TStreamable *build();
  165.  
  166. };
  167.  
  168. inline ipstream& operator >> ( ipstream& is, TIndicator& cl )
  169.     { return is >> (TStreamable&)cl; }
  170. inline ipstream& operator >> ( ipstream& is, TIndicator*& cl )
  171.     { return is >> (void *&)cl; }
  172.  
  173. inline opstream& operator << ( opstream& os, TIndicator& cl )
  174.     { return os << (TStreamable&)cl; }
  175. inline opstream& operator << ( opstream& os, TIndicator* cl )
  176.     { return os << (TStreamable *)cl; }
  177.  
  178. #endif  // Uses_TIndicator
  179.  
  180.  
  181. #if defined( Uses_TEditor ) && !defined( __TEditor )
  182. #define __TEditor
  183.  
  184. class far TRect;
  185. class far TScrollBar;
  186. class far TIndicator;
  187. class far TEvent;
  188.  
  189. enum WordWrapState {wwsError, wwsNoWrap, wwsDidWrap};
  190.  
  191. class TEditor : public TView
  192. {
  193.  
  194. public:
  195.  
  196.     friend void genRefs();
  197.  
  198.     TEditor( const TRect&, TScrollBar *, TScrollBar *, TIndicator *, ushort );
  199.     virtual ~TEditor();
  200.  
  201.     virtual void shutDown();
  202.  
  203.     char bufChar( ushort );
  204.     ushort bufPtr( ushort );
  205.     virtual void changeBounds( const TRect& );
  206.     virtual void convertEvent( TEvent& );
  207.     Boolean cursorVisible();
  208.     void deleteSelect(Boolean alwaysWrap=False);
  209.     virtual void doneBuffer();
  210.     virtual void draw();
  211.     virtual TPalette& getPalette() const;
  212.     virtual void handleEvent( TEvent& );
  213.     virtual void initBuffer();
  214.     Boolean insertBuffer( char *, ushort, ushort, Boolean, Boolean, Boolean alwaysWrap=False );
  215.     virtual Boolean insertFrom( TEditor * );
  216.     Boolean insertText( const void *, ushort, Boolean );
  217.     virtual void scrollTo( int, int );
  218.     Boolean search( const char *, ushort );
  219.     virtual Boolean setBufSize( ushort );
  220.     void setCmdState( ushort, Boolean );
  221.     void setSelect( ushort, ushort, Boolean);
  222.     virtual void setState( ushort, Boolean );
  223.     void trackCursor( Boolean );
  224.     void undo();
  225.     virtual void updateCommands();
  226.     virtual Boolean valid( ushort );
  227.  
  228.     int charPos( ushort, ushort );
  229.     ushort charPtr( ushort, int );
  230.     Boolean clipCopy();
  231.     void clipCut();
  232.     void clipPaste();
  233.     void deleteRange( ushort, ushort, Boolean );
  234.     void doUpdate();
  235.     void doSearchReplace();
  236.     void drawLines( int, int, ushort );
  237.     void formatLine(void *, ushort, int, ushort );
  238.     void find();
  239.     ushort getMousePtr( TPoint );
  240.     Boolean hasSelection() {return Boolean(selStart != selEnd);}
  241.     void hideSelect();
  242.     Boolean isClipboard() const {return Boolean(clipboard == this);}
  243.     ushort lineEnd( ushort );
  244.     ushort lineMove( ushort, int );
  245.     ushort lineStart( ushort );
  246.     void lock() {lockCount++;}
  247.     void newLine();
  248.     ushort nextChar( ushort );
  249.     ushort nextLine( ushort p ) {return nextChar(lineEnd(p));}
  250.     ushort nextWord( ushort );
  251.     ushort prevChar( ushort );
  252.     ushort prevLine( ushort p ) {return lineStart(prevChar(p));}
  253.     ushort prevWord( ushort );
  254.     void replace();
  255.     void setCurPtr( ushort, uchar );
  256.     void startSelect();
  257.     void toggleInsMode();
  258.     void unlock();
  259.     void update( uchar );
  260.     void checkScrollBar( const TEvent&, TScrollBar *, int& );
  261.  
  262. private:
  263.     uchar lockCount;
  264.     int keyState;
  265.  
  266. protected:
  267.     TScrollBar *hScrollBar;
  268.     TScrollBar *vScrollBar;
  269.     TIndicator *indicator;
  270.     char *buffer;
  271.     ushort bufSize;
  272.     ushort bufLen;
  273.     ushort gapLen;
  274.     ushort selStart;
  275.     ushort selEnd;
  276.     ushort curPtr;
  277.     TPoint curPos;
  278.     TPoint delta;
  279.     TPoint limit;
  280.     int drawLine;
  281.     ushort drawPtr;
  282.     ushort delCount;
  283.     ushort insCount;
  284.     ushort rMargin;
  285.  
  286. public:
  287.     Boolean isValid;
  288.     Boolean canUndo;
  289.     Boolean modified;
  290.     Boolean selecting;
  291.     Boolean overwrite;
  292.     Boolean autoIndent;
  293.     Boolean wordWrap;
  294.     Boolean autosizeMargin;     // Change margin when editor is resized
  295.  
  296.     static TEditorDialog near editorDialog;
  297.     static ushort near editorFlags;
  298.     static char near findStr[maxFindStrLen];
  299.     static char near replaceStr[maxReplaceStrLen];
  300.     static TEditor * near clipboard;
  301.     uchar updateFlags;
  302.     uchar tabSize;
  303.  
  304. private:
  305.  
  306.     virtual const char *streamableName() const { return name; }
  307.  
  308. protected:
  309.     static int countLines( void *buf, ushort count );
  310.  
  311. protected:
  312.  
  313.     TEditor( StreamableInit );
  314.     virtual void write( opstream& );
  315.     virtual void *read( ipstream& );
  316.     void setBufLen( ushort );       // What does this really do ??
  317.     Boolean normalizeBuffer( ushort );  // reset bufSize and gapLen without changing actual buffer size.  Only call from setBufSize()!!
  318.     WordWrapState doWordWrapBuffer( ushort, ushort, short* );
  319.     WordWrapState wordWrapBuffer(ushort, ushort);
  320.     Boolean changeBufSize( short change ); // calls setBufSize().  Used by assembly
  321.  
  322. public:
  323.  
  324.     static const char * const near name;
  325.     static TStreamable *build();
  326.  
  327. };
  328.  
  329. inline ipstream& operator >> ( ipstream& is, TEditor& cl )
  330.     { return is >> (TStreamable&)cl; }
  331. inline ipstream& operator >> ( ipstream& is, TEditor*& cl )
  332.     { return is >> (void *&)cl; }
  333.  
  334. inline opstream& operator << ( opstream& os, TEditor& cl )
  335.     { return os << (TStreamable&)cl; }
  336. inline opstream& operator << ( opstream& os, TEditor* cl )
  337.     { return os << (TStreamable *)cl; }
  338.  
  339. inline Boolean TEditor::insertText( const void *text, ushort length, Boolean selectText )
  340.     {return insertBuffer( (char *)text, 0, length, canUndo, selectText);}
  341.  
  342. inline void TEditor::deleteSelect(Boolean alwaysWrap)
  343.     {insertBuffer( (char*)0, 0, 0, canUndo, False, alwaysWrap );}
  344.  
  345. #endif  // Uses_TEditor
  346.  
  347. #if defined( Uses_TMemo ) && !defined( __TMemo )
  348. #define __TMemo
  349.  
  350. class far TEvent;
  351.  
  352. struct TMemoData
  353. {
  354.     ushort length;
  355.     char buffer[INT_MAX];
  356. };
  357.  
  358. class TMemo : public TEditor
  359. {
  360.  
  361. public:
  362.  
  363.     TMemo( const TRect&, TScrollBar *, TScrollBar *, TIndicator *, ushort );
  364.     virtual void getData( void *rec );
  365.     virtual void setData( void *rec );
  366.     virtual ushort dataSize();
  367.     virtual TPalette& getPalette() const;
  368.     virtual void handleEvent( TEvent& );
  369.  
  370. private:
  371.  
  372.     virtual const char *streamableName() const
  373.         { return name; }
  374.  
  375. protected:
  376.  
  377.     TMemo( StreamableInit );
  378.     virtual void write( opstream& );
  379.     virtual void *read( ipstream& );
  380.  
  381. public:
  382.  
  383.     static const char * const near name;
  384.     static TStreamable *build();
  385.  
  386. };
  387.  
  388. inline ipstream& operator >> ( ipstream& is, TMemo& cl )
  389.     { return is >> (TStreamable&)cl; }
  390. inline ipstream& operator >> ( ipstream& is, TMemo*& cl )
  391.     { return is >> (void *&)cl; }
  392.  
  393. inline opstream& operator << ( opstream& os, TMemo& cl )
  394.     { return os << (TStreamable&)cl; }
  395. inline opstream& operator << ( opstream& os, TMemo* cl )
  396.     { return os << (TStreamable *)cl; }
  397.  
  398. #endif  // Uses_TMemo
  399.  
  400.  
  401. #if defined( Uses_TFileEditor ) && !defined( __TFileEditor )
  402. #define __TFileEditor
  403.  
  404. #if !defined( __DIR_H )
  405. #include <Dir.h>
  406. #endif  // __DIR_H
  407.  
  408. class far TRect;
  409. class far TScrollBar;
  410. class far TIndicator;
  411. class far TEvent;
  412.  
  413. class TFileEditor : public TEditor
  414. {
  415.  
  416. public:
  417.  
  418.     char fileName[MAXPATH];
  419.     TFileEditor( const TRect&,
  420.                  TScrollBar *,
  421.                  TScrollBar *,
  422.                  TIndicator *,
  423.                  const char *
  424.                );
  425.     virtual void doneBuffer();
  426.     virtual void handleEvent( TEvent& );
  427.     virtual void initBuffer();
  428.     Boolean loadFile();
  429.     Boolean save();
  430.     Boolean saveAs();
  431.     Boolean saveFile();
  432.     virtual Boolean setBufSize( ushort );
  433.     virtual void shutDown();
  434.     virtual void updateCommands();
  435.     virtual Boolean valid( ushort );
  436.  
  437. private:
  438.  
  439.     static const char * near backupExt;
  440.     
  441.     virtual const char *streamableName() const
  442.         { return name; }
  443.  
  444. protected:
  445.  
  446.     TFileEditor( StreamableInit );
  447.     virtual void write( opstream& );
  448.     virtual void *read( ipstream& );
  449.  
  450. public:
  451.  
  452.     static const char * const near name;
  453.     static TStreamable *build();
  454.  
  455. };
  456.  
  457. inline ipstream& operator >> ( ipstream& is, TFileEditor& cl )
  458.     { return is >> (TStreamable&)cl; }
  459. inline ipstream& operator >> ( ipstream& is, TFileEditor*& cl )
  460.     { return is >> (void *&)cl; }
  461.  
  462. inline opstream& operator << ( opstream& os, TFileEditor& cl )
  463.     { return os << (TStreamable&)cl; }
  464. inline opstream& operator << ( opstream& os, TFileEditor* cl )
  465.     { return os << (TStreamable *)cl; }
  466.  
  467. #endif  // Uses_TFileEditor
  468.  
  469.  
  470. #if defined( Uses_TEditWindow ) && !defined( __TEditWindow )
  471. #define __TEditWindow
  472.  
  473. class far TFileEditor;
  474.  
  475. class TEditWindow : public TWindow
  476. {
  477.  
  478. public:
  479.  
  480.     TEditWindow( const TRect&, const char *, int );
  481.     virtual void close();
  482.     virtual const char *getTitle( short );
  483.     virtual void handleEvent( TEvent& );
  484.     virtual void sizeLimits( TPoint& min, TPoint& max );
  485.  
  486.     TFileEditor *editor;
  487.  
  488. private:
  489.  
  490.     static const char * near clipboardTitle;
  491.     static const char * near untitled;
  492.     
  493.     virtual const char *streamableName() const
  494.         { return name; }
  495.  
  496. protected:
  497.  
  498.     TEditWindow( StreamableInit );
  499.     virtual void write( opstream& );
  500.     virtual void *read( ipstream& );
  501.  
  502. public:
  503.  
  504.     static const char * const near name;
  505.     static TStreamable *build();
  506.  
  507. };
  508.  
  509. inline ipstream& operator >> ( ipstream& is, TEditWindow& cl )
  510.     { return is >> (TStreamable&)cl; }
  511. inline ipstream& operator >> ( ipstream& is, TEditWindow*& cl )
  512.     { return is >> (void *&)cl; }
  513.  
  514. inline opstream& operator << ( opstream& os, TEditWindow& cl )
  515.     { return os << (TStreamable&)cl; }
  516. inline opstream& operator << ( opstream& os, TEditWindow* cl )
  517.     { return os << (TStreamable *)cl; }
  518.  
  519. #endif  // Uses_TEditWindow
  520.  
  521.  
  522. #if defined( Uses_TFindDialogRec ) && !defined( __TFindDialogRec )
  523. #define __TFindDialogRec
  524.  
  525. #if !defined( __STRING_H )
  526. #include <String.h>
  527. #endif  // __STRING_H
  528.  
  529. struct TFindDialogRec
  530. {
  531.     TFindDialogRec( const char *str, ushort flgs )
  532.         {
  533.         strcpy( find, str );
  534.         options = flgs;
  535.         }
  536.     char find[maxFindStrLen];
  537.     ushort options;
  538. };
  539.  
  540. #endif  // Uses_TFindDialogRec
  541.  
  542. #if defined( Uses_TReplaceDialogRec ) && !defined( __TReplaceDialogRec )
  543. #define __TReplaceDialogRec
  544.  
  545. #if !defined( __STRING_H )
  546. #include <String.h>
  547. #endif  // __STRING_H
  548.  
  549. struct TReplaceDialogRec
  550. {
  551.     TReplaceDialogRec( const char *str, const char *rep, ushort flgs )
  552.         {
  553.         strcpy( find, str );
  554.         strcpy( replace, rep );
  555.         options = flgs;
  556.         }
  557.     char find[maxFindStrLen];
  558.     char replace[maxReplaceStrLen];
  559.     ushort options;
  560. };
  561.  
  562. #endif  // Uses_TReplaceDialogRec
  563.