{$I OVC.INC}

{$B-} {Complete Boolean Evaluation}
{$I+} {Input/Output-Checking}
{$P+} {Open Parameters}
{$T-} {Typed @ Operator}
{$W-} {Windows Stack Frame}
{$X+} {Extended Syntax}
{$R-} {Range-Checking}
{$S-} {Stack-Overflow Checking}

{$IFNDEF Win32}
{$G+} {286 Instructions}
{$N+} {Numeric Coprocessor}
{$C MOVEABLE,DEMANDLOAD,DISCARDABLE}
{$ENDIF}

{*********************************************************}
{*                  OVCEDIT.PAS 2.00                     *}
{*     Copyright (c) TurboPower Software Co 1995-96      *}
{*                 All rights reserved.                  *}
{*********************************************************}

unit OvcEdit;

interface

uses
  {$IFDEF Win32} Windows, {$ELSE} WinTypes, WinProcs, {$ENDIF}
  Classes, Controls, Forms, Graphics, Menus, Messages, StdCtrls, SysUtils,
  OvcBase, OvcCaret, OvcColor, OvcConst, OvcCmd, OvcData,
  OvcEditN, OvcEditU, OvcExcpt, OvcFxFnt, OvcMisc, OvcStr,
  OvcEditP;

const
  {default property values}
  DefAutoIndent       = False;           {true to perform auto indentation}
  DefBackupExt        = 'BAK';           {extension used for backup files}
  DefBorderStyle      = bsSingle;        {component border style}
  DefCtl3D            = True;            {true to default to use ctl3d}
  DefHeight           = 150;             {default component height}
  DefHighlightBack    = clHighlight;     {default highlight backgrond color}
  DefHighlightText    = clHighlightText; {default highlight text color}
  DefHideSelection    = True;            {true to hide selection by default}
  DefInsertMode       = True;            {default to start in insert mode}
  DefIsOpen           = False;           {default to not open the file}
  DefParaLimit        = MaxLongInt;      {default maximum paragraphs in editor}
  DefLeftMargin       = 15;              {width of left margin}
  DefMakeBackup       = False;           {don't make backups by default}
  DefMaxBytes         = MaxLongInt;      {default maximum characters in editor}
  DefParentColor      = False;           {default to not use parent}
  DefParentCtl3D      = True;
  DefParaLengthLimit  = High(SmallInt);
  DefReadOnly         = False;
  DefRightMargin      = 5;               {width of right margin}
  DefScrollBars       = ssBoth;
  DefScrollBarsAlways = False;
  DefScrollPastEnd    = False;
  DefShowBookmarks    = True;
  DefTabSize          = 8;
  DefTabStop          = True;
  DefTabType          = ttReal;
  DefTrimWhiteSpace   = True;
  DefUndoBufferSize   = 8*1024;
  DefWantEnter        = True;
  DefWantTab          = False;
  DefWidth            = 200;
  DefWordWrap         = False;
  DefWordDelimiters   = ^I#39#13#10' ,./?;:`"<>[]{}-=\+|()%@&^$#!~*';
  DefWrapAtLeft       = True;
  DefWrapColumn       = 80;
  DefWrapToWindow     = False;

type
  TEditorErrorEvent =
    procedure(Sender : TObject; var ErrorCode : Word)
    of object;
    {-event to provide alternate handling of errors}

  TEditorDrawLineEvent =
    procedure(Sender : TObject; EditorCanvas : TCanvas; Rect : TRect;
              S : PAnsiChar; Len, Line, Pos, Count,
              HBLine, HBCol, HELine, HECol : Integer;
              var WasDrawn : Boolean)
    of object;
    {-event to provide owner-draw}

  TOvcCustomEditor = class(TOvcEditBase)
  {.Z+}
  protected {private}
    FAutoIndent       : Boolean;      {true to do auto indentation}
    FBorderStyle      : TBorderStyle; {border style to use}
    FByteLimit        : LongInt;      {max characters in editor}
    FFixedFont        : TOvcFixedFont;{fixed font}
    FHideSelection    : Boolean;      {true to hide selection with focus loss}
    FHighlightColors  : TOvcColors;   {background and text highlight colors}
    FInsertMode       : Boolean;      {if True, we're in insert mode}
    FLeftMargin       : Integer;      {width of left margin}
    FParaLengthLimit  : Integer;      {max paragraph size}
    FParaLimit        : LongInt;      {max number of paragraphs}
    FReadOnly         : Boolean;      {true if read only}
    FRightMargin      : Integer;      {width of right margin}
    FScrollBars       : TScrollStyle; {scroll bar style to use}
    FScrollBarsAlways : Boolean;      {true to force scroll bars}
    FScrollPastEnd    : Boolean;      {true to allow scroll past end}
    FShowBookmarks    : Boolean;      {true to display bookmarks}
    FTabSize          : Byte;         {tab size}
    FTabType          : TTabType;     {real, smart, or fixed tabs}
    FTrimWhiteSpace   : Boolean;      {remove white space during append}
    FUndoBufferSize   : Word;         {undo buffer size}
    FWantEnter        : Boolean;      {true to capture enter key}
    FWantTab          : Boolean;      {true to capture tab key}
    FWordDelimiters   : string;       {characters that seperate words}
    FWordWrap         : Boolean;      {true if in word wrap mode}
    FWrapAtLeft       : Boolean;      {true to wrap caret at left}
    FWrapColumn       : Integer;      {column to word wrap at}
    FWrapToWindow     : Boolean;      {true to wrap at control edge}

    FOnDrawLine       : TEditorDrawLineEvent;
    FOnError          : TEditorErrorEvent;
    FOnShowStatus     : TShowStatusEvent;
    FOnTopLineChanged : TTopLineChangedEvent;
    FOnUserCommand    : TUserCommandEvent;

    {internal variables}
    edAnchor          : TMarker;    {anchor for highlighting}
    edBMGlyphs        : TBitMap;    {marker glyphs}
    edCapture         : Boolean;    {if True, we have the capture}
    edCaret           : TOvcCaretPair; {our carets}
    edCols            : Integer;    {number of columns displayable in window}
    edColWid          : Integer;    {width of one column}
    edCurCol          : Integer;    {current column in edCurLine}
    edCurLine         : LongInt;    {current line}
    edCurPara         : LongInt;    {current paragraph}
    edDivisor         : LongInt;    {divisor for scroll bars}
    edHDelta          : Integer;    {horizontal scroll delta}
    edHltBgn          : TMarker;    {starting pos for highlight}
    edHltBgnL         : TOvcTextPos;{starting pos for highlight - Line,Col}
    edHltEnd          : TMarker;    {ending pos for highlight}
    edHltEndL         : TOvcTextPos;{ending pos for highlight - Line,Col}
    edHScroll         : Boolean;    {if True, we have a horizontal scroll bar}
    edHSMax           : Integer;    {max value for horizontal scroll bar}
    edLinePos         : Integer;    {offset into edCurPara for start of edCurLine}
    edParas           : TParaList;  {list of paragraphs}
    edPendingHSP      : Boolean;    {horizontal scroll position pending}
    edPendingVSP      : Boolean;    {vertical scroll position pending}
    edPendingVSR      : Boolean;    {vertical scroll pending}
    edPrev            : TOvcCustomEditor; {previous attached editor}
    edRedrawPending   : Boolean;    {redraw pending}
    edRowHt           : Integer;    {height of one row}
    edRows            : Integer;    {number of rows in window}
    edSelCursor       : hCursor;    {selection cursor}
    edSelCursorOn     : Boolean;    {is selection cursor in use?}
    edTopLine         : LongInt;    {line at top of window}
    edTopPara         : LongInt;    {paragraph at top of window}
    edTopPos          : Integer;    {offset into edTopPara for start of edTopLine}
    edVScroll         : Boolean;    {if True, we have a vertical scroll bar}
    edVSMax           : LongInt;    {max value for vertical scroll bar}
    edSuppressChar    : Boolean;    {suppress next character}

    {property methods}
    function GetFirstEditor : TOvcCustomEditor;
      {-return a pointer to the first attached editor}
    function GetInsCaretType : TOvcCaret;
      {-return the current caret type}
    function GetOvrCaretType : TOvcCaret;
      {-return the current caret type}
    function GetLeftColumn : Integer;
      {-return the left-most visible column number}
    function GetLineCount : LongInt;
      {-get the total number of lines}
    function GetLineLength(LineNum : LongInt) : Integer;
      {-get the length of the line LineNum}
    function GetModified : Boolean;
      {-get the value of the modified flag}
    function GetNextEditor : TOvcCustomEditor;
      {-return a pointer to the next editor}
    function GetParaPointer(ParaNum : LongInt) : PAnsiChar;
      {-get a pointer to the specified paragraph}
    function GetParaLength(ParaNum : LongInt) : Integer;
      {-get the length of the paragraph ParaNum}
    function GetPrevEditor : TOvcCustomEditor;
      {-return a pointer to the previous editor}
    function GetStringLine(LineNum : LongInt) : string;
      {-return the text for the specified line}
    function GetTopLine : LongInt;
      {-get the number of the line at the top of the window}
    function GetVisibleColumns : Integer;
      {-get the number of visible columns}
    function GetVisibleRows : Integer;
      {-get the number of visible rows}
    procedure SetBorderStyle(const Value : TBorderStyle);
      {-set the style used for the border}
    procedure SetFixedFont(Value : TOvcFixedFont);
      {-set the fixed font}
    procedure SetHideSelection(Value : Boolean);
      {-set hide selection flag}
    procedure SetInsCaretType(const Value : TOvcCaret);
      {-set the type of caret to use}
    procedure SetInsertMode(Value : Boolean);
      {-turn insert mode on or off}
    procedure SetLeftMargin(Value : Integer);
      {-set the width of the left margin}
    procedure SetModified(Value : Boolean);
      {-change the modified flag}
    procedure SetOvrCaretType(const Value : TOvcCaret);
      {-set the type of caret to use}
    procedure SetParaLengthLimit(Value : Integer);
      {-set a limit on the length of a paragraph}
    procedure SetParaLimit(Value : LongInt);
      {-set a limit on the total number of paragraphs}
    procedure SetRightMargin(Value : Integer);
      {-set the width of the right margin}
    procedure SetScrollBars(Value : TScrollStyle);
      {-set use of vertical and horizontal scroll bars}
    procedure SetScrollBarsAlways(Value : Boolean);
      {-set use of scroll bars always}
    procedure SetScrollPastEnd(Value : Boolean);
      {-set option that allows scrolling past end of text}
    procedure SetShowBookmarks(Value : Boolean);
      {-set option to display bookmarks in left margin}
    procedure SetTabSize(Value : Byte);
      {-set the distance between tab stops}
    procedure SetTabType(Value : TTabType);
      {-set the tab type}
    procedure SetTopLine(Value : LongInt);
      {-set the line to show at the top of the window}
    procedure SetUndoBufferSize(Value : Word);
      {-set the size of the undo buffer. This destroys the existing buffer}
    procedure SetWordDelimiters(Value : string);
      {set the characters that delimit words}
    procedure SetWordWrap(Value : Boolean);
      {-turn word wrap on or off}
    procedure SetWrapAtLeft(Value : Boolean);
      {-set wrap at left option}
    procedure SetWrapColumn(Value : Integer);
      {-set the column for word wrap}
    procedure SetWrapToWindow(Value : Boolean);
      {-set the option to automatically adjust the column for word wrap}

    {internal methods}
    procedure edAdjustWrapColumn;
    procedure edBackspace;
    procedure edCalcRowColInfo;
    function edCaretInWindow(var Col : Word) : Boolean;
    procedure edCaretLeft(Shift : Boolean);
    procedure edCaretRight(Shift : Boolean);
    procedure edChangeTopLine(Value : LongInt);
    procedure edColorChanged(AColor : TObject);
    procedure edDeleteLine;
    procedure edDeleteSelection;
    procedure edDeleteToEnd;
    procedure edDeleteWord;
    procedure edDetach;
    procedure edDoTab;
    procedure edFixedFontChanged(Sender : TObject);
    function edGetEditLine(LineNum : LongInt; Buf : PAnsiChar; BufLen : Word) : Integer;
    function  edGetIndentLevel(N : LongInt; Col : Integer) : Integer;
    procedure edGetMousePos(var Line : LongInt; var Col : Integer);
    function  edHaveHighlight : Boolean;
    procedure edHScrollPrim(Delta : Integer);
    procedure edInsertChar(Ch : AnsiChar);
    function edInsertTextAtCaret(P : PAnsiChar) : Word;
    function edIsWordDelim(Ch : AnsiChar) : Boolean;
    function edIsStringHighlighted(S : PAnsiChar; MatchCase : Boolean) : Boolean;
    procedure edMoveCaret(HDelta : Integer; VDelta : LongInt; MVP, DragH : Boolean);
    procedure edMoveCaretPrim(HDelta : Integer; VDelta : LongInt; MVP, DragH, AbsCol : Boolean);
    procedure edMoveCaretTo(Line : LongInt; Col : Integer; DragH : Boolean);
    procedure edMoveCaretToPP(Para : LongInt; Pos : Integer; DragH : Boolean);
    procedure edMoveToEndOfLine(Shift : Boolean);
    procedure edNewLine(BreakP, Follow : Boolean);
    procedure edPositionCaret(Col : Word);
    procedure edReadBookmarkGlyphs;
    procedure edReadMargin(Reader : TReader);
    procedure edRedraw(Now : Boolean);
    procedure edRefreshLines(Start, Stop : LongInt);
    function  edReplaceSelection(P : PAnsiChar) : Word;
    procedure edResetHighlight(Refresh : Boolean);
    procedure edScrollPrim(HDelta : Integer; VDelta : LongInt);
    function edSearchReplace(FS, RS : PAnsiChar; Options : TSearchOptionSet) : LongInt;
    procedure edSetCaretSize;
    procedure edSetHScrollPos;
    procedure edSetHScrollRange;
    procedure edSetSelectionPP(Para1 : LongInt; Pos1 : Integer;
                               Para2 : LongInt; Pos2 : Integer;
                               CaretAtEnd : Boolean);
    procedure edSetSelPrim(Para1 : LongInt; Pos1 : Integer;
                           Para2 : LongInt; Pos2 : Integer);
    procedure edSetVScrollPos;
    procedure edSetVScrollRange;
    procedure edUpdateVScrollRange;
    procedure edUpdateVScrollPos;
    procedure edUpdateHighlight(Refresh : Boolean);
    procedure edUpdateHScrollPos;
    procedure edVScrollPrim(Delta : LongInt);
    procedure edWordLeft(Shift : Boolean);
    procedure edWordRight(Shift : Boolean);

    {routines for updating attached windows}
    procedure edUpdateOnDeletedParaPrim(N : LongInt; Current : Boolean);
    procedure edUpdateOnDeletedTextPrim(N : LongInt; Pos, Count : Integer;
                                      Current : Boolean);
    procedure edUpdateOnInsertedParaPrim(N : LongInt; Pos, Indent : Integer;
                                         Current : Boolean);
    procedure edUpdateOnInsertedTextPrim(N : LongInt; Pos, Count : Integer;
                                         Current : Boolean);
    procedure edUpdateOnJoinedParasPrim(N : LongInt; Pos : Integer; Current : Boolean);

    {VCL control methods}
    procedure CMDialogChar(var Msg : TCMDialogChar);
      message CM_DIALOGCHAR;
    procedure CMFontChanged(var Msg : TMessage);
      message CM_FONTCHANGED;

    {private message handling methods}
    procedure OMShowStatus(var Msg : TOMShowStatus);
      message om_ShowStatus;

    {windows message handling methods}
    procedure WMChar(var Msg : TWMChar);
      message WM_CHAR;
    procedure WMEraseBkGnd(var Msg : TWMEraseBkGnd);
      message WM_ERASEBKGND;
    procedure WMGetDlgCode(var Msg : TWMGetDlgCode);
      message WM_GETDLGCODE;
    procedure WMHScroll(var Msg: TWMHScroll);
      message WM_HSCROLL;
    procedure WMKeyDown(var Msg : TWMKeyDown);
      message WM_KEYDOWN;
    procedure WMKillFocus(var Msg : TWMKillFocus);
      message WM_KILLFOCUS;
    procedure WMLButtonDblClk(var Msg : TWMLButtonDblClk);
      message WM_LBUTTONDBLCLK;
    procedure WMLButtonDown(var Msg : TWMLButtonDown);
      message WM_LBUTTONDOWN;
    procedure WMLButtonUp(var Msg : TWMLButtonUp);
      message WM_LBUTTONUP;
    procedure WMMouseActivate(var Msg : TWMMouseActivate);
      message WM_MOUSEACTIVATE;
    procedure WMNCHitTest(var Msg : TWMNCHitTest);
      message WM_NCHITTEST;
    procedure WMSetCursor(var Msg : TWMSetCursor);
      message WM_SETCURSOR;
    procedure WMSetFocus(var Msg : TWMSetFocus);
      message WM_SETFOCUS;
    procedure WMVScroll(var Msg: TWMVScroll);
      message WM_VSCROLL;
    procedure WMSize(var Msg : TWMSize);
      message WM_SIZE;
    procedure WMSysKeyDown(var Msg : TWMSysKeyDown);
      message WM_SYSKEYDOWN;

  protected
    {VCL methods}
    procedure CreateParams(var Params : TCreateParams);
      override;
    procedure CreateWnd;
      override;
    procedure DefineProperties(Filer : TFiler);
      override;
    procedure Paint;
      override;

    function DoOnDrawLine(EditorCanvas : TCanvas; Rect : TRect;
             S : PAnsiChar; Len, Line, Pos, Count,
             HBLine, HBCol, HELine, HECol : Integer) : Boolean;
      virtual;
      {-call the OnDrawLine method, if assigned}
    procedure DoOnError(ErrorCode : Word);
      dynamic;
      {-call the OnError method, if assigned, otherwise raise exception}
    procedure DoOnShowStatus(LineNum : LongInt; ColNum : Word);
      dynamic;
      {-call the OnShowStatus mehtod, if assigned}
    procedure DoOnTopLineChanged(Line : LongInt);
      dynamic;
      {-perform notification of a top line changed}
    procedure DoOnUserCommand(Command : Word);
      dynamic;
      {-perform notification of a user command}
    procedure edAddSampleParas;
      dynamic;
      {-add sample text, if designing}

    {virtual property mentods}
    function GetReadOnly : Boolean;
      virtual;
      {-return read-only status}
    procedure SetByteLimit(Value : LongInt);
      virtual;
      {-set a limit on the total number of bytes}
  {.Z-}

    {properties}
    property AutoIndent : Boolean
      read FAutoIndent
      write FAutoIndent
      default DefAutoIndent;

    property BorderStyle : TBorderStyle
      read FBorderStyle
      write SetBorderStyle
      default DefBorderStyle;

    property ByteLimit : LongInt
      read FByteLimit
      write SetByteLimit
      default DefMaxBytes;

    property Canvas;

    property CaretIns : TOvcCaret
      read GetInsCaretType
      write SetInsCaretType;

    property CaretOvr : TOvcCaret
      read GetOvrCaretType
      write SetOvrCaretType;

    property FixedFont : TOvcFixedFont
       read FFixedFont
       write SetFixedFont;

    property HideSelection : Boolean
      read FHideSelection
      write SetHideSelection
      default DefHideSelection;

    property HighlightColors : TOvcColors
      read FHighlightColors
      write FHighlightColors;

    property InsertMode : Boolean
      read FInsertMode
      write SetInsertMode
      default DefInsertMode;

    property LeftMargin : Integer
      read FLeftMargin
      write SetLeftMargin
      default DefLeftMargin;

    property ParaLengthLimit : Integer
      read FParaLengthLimit
      write SetParaLengthLimit
      default DefParaLengthLimit;

    property ParaLimit : LongInt
      read FParaLimit
      write SetParaLimit
      default DefParaLimit;

    property ReadOnly : Boolean
      read GetReadOnly
      write FReadOnly
      default defReadOnly;

    property RightMargin : Integer
      read FRightMargin
      write SetRightMargin
      default DefLeftMargin;

    property ScrollBars : TScrollStyle
       read FScrollBars
       write SetScrollBars
       default DefScrollBars;

    property ScrollBarsAlways : Boolean
       read FScrollBarsAlways
       write SetScrollBarsAlways
       default DefScrollBarsAlways;

    property ScrollPastEnd : Boolean
       read FScrollPastEnd
       write SetScrollPastEnd
       default DefScrollPastEnd;

    property ShowBookmarks : Boolean
      read FShowBookmarks
      write SetShowBookmarks
      default DefShowBookmarks;

    property TabSize : Byte
      read FTabSize
      write SetTabSize
      default DefTabSize;

    property TabType : TTabType
      read FTabType
      write SetTabType
      default DefTabType;

    property TrimWhiteSpace : Boolean
      read FTrimWhiteSpace
      write FTrimWhiteSpace
      default DefTrimWhiteSpace;

    property UndoBufferSize : Word
      read FUndoBufferSize
      write SetUndoBufferSize
      default DefUndoBufferSize;

    property WantEnter : Boolean
      read FWantEnter
      write FWantEnter
      default DefWantEnter;

    property WantTab : Boolean
      read FWantTab
      write FWantTab
      default DefWantTab;

    property WordWrap : Boolean
      read FWordWrap
      write SetWordWrap
      default DefWordWrap;

    property WrapAtLeft : Boolean
      read FWrapAtLeft
      write SetWrapAtLeft
      default DefWrapAtLeft;

    property WrapColumn : Integer
      read FWrapColumn
      write SetWrapColumn
      default DefWrapColumn;

    property WrapToWindow : Boolean
      read FWrapToWindow
      write SetWrapToWindow
      default DefWrapToWindow;

    {events}
    property OnDrawLine : TEditorDrawLineEvent
      read FOnDrawLine
      write FOnDrawLine;

    property OnError : TEditorErrorEvent
      read FOnError
      write FOnError;

    property OnShowStatus : TShowStatusEvent
      read FOnShowStatus
      write FOnShowStatus;

    property OnTopLineChanged : TTopLineChangedEvent
      read FOnTopLineChanged
      write FOnTopLineChanged;

    property OnUserCommand : TUserCommandEvent
      read FOnUserCommand
      write FOnUserCommand;

  public
  {.Z+}
    {public internal variables and methods}
    edNext : TOvcCustomEditor; {next attached editor}

    procedure edResetPositionInfo;
    procedure edUpdateOnDeletedPara(N : LongInt);
    procedure edUpdateOnDeletedText(N : LongInt; Pos, Count : Integer);
    procedure edUpdateOnInsertedPara(N : LongInt; Pos, Indent : Integer);
    procedure edUpdateOnInsertedText(N : LongInt; Pos, Count : Integer);
    procedure edUpdateOnJoinedParas(N : LongInt; Pos : Integer);
  {.Z-}

    constructor Create(AOwner : TComponent);
      override;
    destructor  Destroy;
      override;

    {public methods}
    function  AppendPara(Para : PAnsiChar) : Word;
      {-append Para to the list of paragraphs}
    procedure Attach(Editor : TOvcCustomEditor);
      virtual;
      {-attach this editor to another editor's text stream}
    function CanRedo : Boolean;
      {-return True if the last undo can be redone}
    function CanUndo : Boolean;
      {-return True if the last change can be undone}
    procedure Clear;
      {-delete all text and updates window}
    procedure ClearSelection;
      {-delete the current selection}
    procedure ClearMarker(N : Byte);
      {-remove the specified text marker}
    procedure CopyToClipboard;
      dynamic;
      {-copy highlighted text to the clipboard}
    procedure CutToClipboard;
      dynamic;
      {-copy highlighted text to the clipboard and then delete it}
    procedure DeleteAll(UpdateScreen : Boolean);
      {-delete all text}
    function EffectiveColumn(S : PAnsiChar; Col : Integer) : Integer;
      {-get the effective column for an actual column}
    procedure FlushUndoBuffer;
      {-flush the undo buffer}
    function GetCaretPosition(var Col : Integer) : LongInt;
      {-return the current position of the caret}
    function GetCurrentWord : string;
      {-return the word at the current caret position}
    function GetLine(LineNum : LongInt; Dest : PAnsiChar; DestLen : Integer) : PAnsiChar;
      {-get the specified line}
    function GetMarkerPosition(N : Byte; var Col : Integer) : LongInt;
      {-return the current position of the specified marker}
    procedure GetMousePos(var L : LongInt; var C : Integer; Existing : Boolean);
      {-return line and column based on current mouse position}
    function GetPara(ParaNum : LongInt; var Len : Word) : PAnsiChar;
      {-get the specified paragraph}
    function GetPrintableLine(LineNum : LongInt; Dest : PAnsiChar; DestLen : Integer) : Integer;
      {-get a line in a format suitable for printing}
    function GetSelection(var Line1 : LongInt; var Col1 : Integer; var Line2 : LongInt; var Col2 : Integer) : Boolean;
      {-return True if any text is currently selected}
    procedure GotoMarker(N : Byte);
      {-move the caret to the specified text marker}
    function GetSelTextBuf(Buffer : PAnsiChar; BufSize : Word) : Word;
      {-return the selected text in Buffer and len as Result}
    function GetSelTextLen : LongInt;
      {-return the length of the selected text}
    function GetText(P : PAnsiChar; Size : Word) : Word;
      {-copy text in editor into P; limit is Size (includes null)}
    function GetTextBuf(Buffer : PAnsiChar; BufSize : Word) : Word;
      {-copy text in editor into Buffer; limit is Size (includes null)}
    function GetTextLen : LongInt;
      {-get the total number of bytes of text}
    procedure Insert(S : PAnsiChar);
      {-replace the current selection with a text string}
    procedure InsertString(const S : string);
      {-replace the current selection with a text string}
    procedure LineToPara(var L : LongInt; var C : Integer);
      {-convert a line,column coordinate to a paragraph,position coordinate}
    function ParaCount : LongInt;
      {-return the total number of paragraphs}
    procedure ParaToLine(var L : LongInt; var C : Integer);
      {-convert a paragraph,position coordinate to a line,column coordinate}
    procedure PasteFromClipboard;
      dynamic;
      {-paste the contents of the clipboard}
    function ProcessCommand(Cmd, CharCode : Word) : Boolean;
      dynamic;
      {-process the specified command, return True if processed}
    procedure Redo;
      {-redo the last undone operation}
      dynamic;
    procedure Deselect(CaretAtEnd : Boolean);
      {-remove any text highlighing}
    function Replace(const S, R : string; Options : TSearchOptionSet) : LongInt;
      {-search for a string and replace it with another string. return count}
      dynamic;
    procedure ResetScrollBars(UpdateScreen : Boolean);
      {-reset all scroll bars}
    function Search(const S : string; Options : TSearchOptionSet) : Boolean;
      {-search for a string returning True if found}
    procedure SelectAll(CaretAtEnd : Boolean);
      {-select all text in the editor}
    procedure SetCaretPosition(Line : LongInt; Col : Integer);
      {-move the caret to a specified line and column}
    procedure SetMarker(N : Byte);
      dynamic;
      {-set a text marker at the current caret position}
    procedure SetMarkerAt(N : Byte; Line : LongInt; Col : Integer);
      dynamic;
      {-set a text marker at the specified position}
    procedure SetSelection(Line1 : LongInt; Col1 : Integer;
                           Line2 : LongInt; Col2 : Integer;
                           CaretAtEnd : Boolean);
      {-select a region of text}
    procedure SetSelTextBuf(Buffer : PAnsiChar);
      {-replace selection with Buffer}
    procedure SetText(P : PAnsiChar);
      {-set text of editor to P}
    procedure SetTextBuf(Buffer : PAnsiChar);
      {-set text of editor to Buffer}
    procedure Undo;
      {-undo the last change}
      dynamic;

    {run-time only properties}
    property FirstEditor : TOvcCustomEditor
      read GetFirstEditor;

    property LeftColumn : Integer
      read GetLeftColumn;

    property Lines[LineNum : LongInt] : string
      read GetStringLine;

    property LineCount : LongInt
      read GetLineCount;

    property LineLength[LineNum : LongInt] : Integer
      read GetLineLength;

    property MaxLength : LongInt
      read FByteLimit
      write SetByteLimit
      stored False;

    property Modified : Boolean
      read GetModified
      write SetModified
      stored False;

    property NextEditor : TOvcCustomEditor
      read GetNextEditor;

    property ParaLength[ParaNum : LongInt] : Integer
      read GetParaLength;

    property ParaPointer[ParaNum : LongInt] : PAnsiChar
      read GetParaPointer;

    property PrevEditor : TOvcCustomEditor
      read GetPrevEditor;

    property TextLength : LongInt
      read GetTextLen;

    property TopLine : LongInt
      read GetTopLine
      write SetTopLine
      stored False;

    property VisibleColumns : Integer
      read GetVisibleColumns;

    property VisibleRows : Integer
      read GetVisibleRows;

    property WordDelimiters : string
      read FWordDelimiters
      write SetWordDelimiters
      stored False;
  end;

  TOvcEditor = class(TOvcCustomEditor)
  published
    property AutoIndent;
    property BorderStyle;
    property ByteLimit;
    property CaretIns;
    property CaretOvr;
    property FixedFont;
    property HideSelection;
    property HighlightColors;
    property InsertMode;
    property LeftMargin;
    property ParaLengthLimit;
    property ParaLimit;
    property ReadOnly;
    property RightMargin;
    property ScrollBars;
    property ScrollBarsAlways;
    property ScrollPastEnd;
    property ShowBookmarks;
    property TabSize;
    property TabType;
    property TrimWhiteSpace;
    property UndoBufferSize;
    property WantEnter;
    property WantTab;
    property WordWrap;
    property WrapAtLeft;
    property WrapColumn;
    property WrapToWindow;

    property OnDrawLine;
    property OnError;
    property OnShowStatus;
    property OnTopLineChanged;
    property OnUserCommand;

    {inherited properties}
    property Align;
    property Color;
    property Controller;
    property Ctl3D default DefCtl3D;
    property DragCursor;
    property DragMode;
    property Enabled;
    property ParentColor default DefParentColor;
    property ParentCtl3D default DefParentCtl3D;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop default DefTabStop;
    property Visible;

    {inherited events}
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    {$IFDEF Win32}
    property OnStartDrag;
    {$ENDIF}
  end;

  {*** TOvcTextFileEditor ***}

  TOvcCustomTextFileEditor = class(TOvcCustomEditor)
  {.Z+}
  protected {private}
    FBackupExt  : TExtStr;
    FFileName   : string;
    FMakeBackup : Boolean;
    FIsOpen     : Boolean;

    {property methods}
    procedure SetFileName(const Value : string);
      {-set name of file being edited}
    procedure SetIsOpen(Value : Boolean);
      {-set if the file is open or not}

    {internal methods}
    function teFixFileName(const Value : string) : string;
      {-fixup file name}

  protected
    constructor Create(AOwner : TComponent);
      override;

    procedure CreateWnd;
      override;
  {.Z-}

  public
    procedure Attach(Editor : TOvcCustomEditor);
      override;
    procedure NewFile(const Name : string);
      {-create a new file}
    procedure LoadFromFile(const Name : string);
      {-open the file for editing}
      dynamic;
    procedure SaveToFile(const Name : string);
      {-write the text in the specified file}
      dynamic;

    {public properties}
    property BackupExt : TExtStr
      read FBackupExt
      write FBackupExt;

    property FileName : string
      read FFileName
      write SetFileName;

    property IsOpen : Boolean
      read FIsOpen
      write SetIsOpen
      default DefIsOpen;

    property MakeBackup : Boolean
      read FMakeBackup
      write FMakeBackup
      default DefMakeBackup;
  end;

  TOvcTextFileEditor = class(TOvcCustomTextFileEditor)
  published
    property BackupExt;
    property FileName;
    property IsOpen;
    property MakeBackup;

    property AutoIndent;
    property BorderStyle;
    property ByteLimit;
    property CaretIns;
    property CaretOvr;
    property FixedFont;
    property HideSelection;
    property HighlightColors;
    property InsertMode;
    property LeftMargin;
    property ParaLengthLimit;
    property ParaLimit;
    property ReadOnly;
    property RightMargin;
    property ScrollBars;
    property ScrollBarsAlways;
    property ScrollPastEnd;
    property ShowBookmarks;
    property TabSize;
    property TabType;
    property TrimWhiteSpace;
    property UndoBufferSize;
    property WantEnter;
    property WantTab;
    property WordWrap;
    property WrapAtLeft;
    property WrapColumn;
    property WrapToWindow;

    property OnDrawLine;
    property OnError;
    property OnShowStatus;
    property OnTopLineChanged;
    property OnUserCommand;

    {inherited properties}
    property Align;
    property Color;
    property Controller;
    property Ctl3D;
    property DragCursor;
    property DragMode;
    property Enabled;
    property ParentColor;
    property ParentCtl3D;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;

    {inherited events}
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
  end;


implementation
