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