|##########|
|#MAGIC   #|CKOLFLIB
|#PROJECT #|""
|#PATHS   #|"StdProject"
|#FLAGS   #|xx---x--x---xxx-----------------
|#USERSW  #|--------------------------------
|#USERMASK#|--------------------------------
|#SWITCHES#|xx---xxxxx-xx---
|##########|
DEFINITION MODULE OTexts;

FROM OStreams   IMPORT InStream,OutStream;
                IMPORT OLists;
FROM Resources  IMPORT ContextPtr;
FROM Exceptions IMPORT RangeViolation;

TYPE
  Text      = POINTER TO TextObj;
  Mark      = POINTER TO MarkObj;
  Line      = POINTER TO LineObj;
  Box       = RECORD
                left,top,bottom,right : INTEGER;
              END;

DEFINITION MODULE MarkLists = OLists.BiLists(Mark);
DEFINITION MODULE LineLists = OLists.BiLists(Line);

EXCEPTION
  NotFound   : "String not found";
  OutOfBound : "Mark out of bound";

TYPE
  StrPtr    = CLASSPTR TO STRING;

  LineObj   = OBJECT OF LineLists.NodeObj;
                data : POINTER TO STRING;
                CONSTRUCTOR Create(text : Text);
                DESTRUCTOR Delete;
                METHOD Destruct;
              END;

  MarkObj   = OBJECT OF MarkLists.NodeObj;
                charNo,
                colNo,
                lineNo  : INTEGER;
                linePtr : Line;
                text    : Text;
                keep    : BOOLEAN;

                CONSTRUCTOR Create(text     : Text;
                                   line,col : INTEGER := 0;
                                   keep     : BOOLEAN := FALSE);
                CONSTRUCTOR Clone(mark : Mark;keep : BOOLEAN := FALSE);
                DESTRUCTOR Delete;

                METHOD GetChar():CHAR;

                METHOD NextLine;
                METHOD PrevLine;
                METHOD Bottom;
                METHOD Top;

                METHOD LineStart;
                METHOD LineEnd;
                METHOD WordLeft;
                METHOD WordRight;
                METHOD Right(n : INTEGER := 1);
                METHOD Left(n : INTEGER := 1);

                METHOD Goto(line,col : INTEGER);
                METHOD GoMark(mark : Mark);

                METHOD NewCoords;

                METHOD Destruct;
              END;

  TextObj   = OBJECT OF LineLists.List AS lines,
                        MarkLists.List AS marks;
                changed     : BOOLEAN;
                buffer      : STRING(512);
                buffline    : Line;
                buffchanged : BOOLEAN;
                numlines    : INTEGER;
                con         : ContextPtr;
                indend      : BOOLEAN;
                tabExpand   : BOOLEAN;
                wordWrap    : BOOLEAN;
                tabSize     : INTEGER;
                leftBorder,
                rightBorder : INTEGER;

                freeze      : INTEGER;
                firstRef,
                lastRef     : Mark;

                CONSTRUCTOR Create;
                DESTRUCTOR Delete;

                METHOD Freeze;
                METHOD Warm;

                METHOD Clear;

                $$OwnHeap:=TRUE
                METHOD Get(at : Mark):STRING;
                METHOD Put(at : Mark;REF str : STRING);

                METHOD PasteBlock(at : Mark;in : InStream):Mark;
                METHOD CopyBlock(from,to : Mark;out : OutStream);
                METHOD DeleteBlock(from,to : Mark);

                METHOD ReformatParagraph(at : Mark);
                |METHOD ReformatBlock(from,to : Mark);

                METHOD Insert(at : Mark;REF str : STRING);
                METHOD Replace(at : Mark;REF str : STRING;len : INTEGER);

                METHOD InsertChar(at : Mark;c : CHAR);
                METHOD ReplaceChar(at : Mark;c : CHAR);

                METHOD DeleteChars(at : Mark;len : INTEGER);

                METHOD Split(at : Mark);
                METHOD Join(at : Mark);

                METHOD Search(    cursor   : Mark;
                              REF str      : STRING;
                                  backward,
                                  caps     : BOOLEAN := FALSE;
                                  until    : Mark    := NIL);

                METHOD RefreshViews;
                METHOD RefreshBox(REF box : Box);

                METHOD GetLine(line : Line);
                METHOD Flush;
                METHOD Destruct;
                METHOD RefreshLines(from,to : Mark);

                METHOD NewNumlines;

                METHOD SetTab(expand : BOOLEAN;size : INTEGER);
              END;

  View      = POINTER TO OBJECT OF Mark;
                height      : INTEGER;
                DEFERRED METHOD Write(    line : INTEGER;
                                      REF str  : STRING);
                DEFERRED METHOD ScrollDown(from  : INTEGER;by : INTEGER := 1);
                DEFERRED METHOD ScrollUp(to  : INTEGER;by : INTEGER := 1);

                METHOD NextLine;
                METHOD PrevLine;
                METHOD Bottom;
                METHOD Top;

                METHOD LineStart;
                METHOD LineEnd;
                METHOD Right(n : INTEGER);
                METHOD Left(n : INTEGER);
                METHOD WordLeft;
                METHOD WordRight;

                METHOD Goto(line,col : INTEGER);
                METHOD GoMark(mark : Mark);

                METHOD RefreshBox(REF box : Box);
                METHOD Refresh(topDisp : INTEGER := 0;
                               lines   : INTEGER := INTEGER'MAX);
              END;

END OTexts.
