home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20cpp.zip / tvision / editors.h < prev    next >
C/C++ Source or Header  |  1999-06-07  |  13KB  |  533 lines

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