DEFINITION HTMLDocs; (* portable *)

 IMPORT Objects, HyperDocs, Texts, Gadgets, Documents, HTTPDocs0,
  TextGadgets, Lists, Streams;

 CONST
  WhiteSpace = 0; OpenTag = 1; OpenEndTag = 2; CloseTag = 3; CharRef = 4; Character = 5; Value = 6; Undef = 7;
  TextPlain = 1; TextHtml = 2; InTag = 3; End = 4;

 TYPE
  DocURL = POINTER TO DocURLDesc;
  DocURLDesc = RECORD ( HyperDocs.DefURLDesc ) 
   dockey: LONGINT
  END;

  Page = POINTER TO PageDesc;
  Scanner = RECORD
   page: Page;
   S: Streams.Stream;
   class, state: INTEGER;
   value: ARRAY 1024 OF CHAR;
   pre, end: BOOLEAN;
   ch, next, char: CHAR;
  END;

  Form = POINTER TO FormDesc;
  FormDesc = RECORD ( TextGadgets.ControlDesc ) 
   elems: HTTPDocs0.ObjList
  END;

  PageDesc = RECORD ( Gadgets.ObjDesc ) 
   W, Ws: Texts.Writer;
   T, source: Texts.Text;
   D: Documents.Document;
   alink: Objects.Object;
   base: DocURL;
   linkkey, docKey: LONGINT;
   next: Page;
   textC, linkC, oldLinkC, textbackC, lines: INTEGER;
   left, blank, cacheSource: BOOLEAN
  END;

  Item = POINTER TO ItemDesc;
  ItemDesc = RECORD ( Lists.ItemDesc ) 
   value: ARRAY 64 OF CHAR;
   oldSel, hasVal: BOOLEAN
  END;

  TagHandler = PROCEDURE (VAR S: Scanner; on: BOOLEAN);
  ExtTag = POINTER TO ExtTagDesc;
  ExtTagDesc = RECORD
   handle: TagHandler;
   start, stop: PROCEDURE (P: Page);
  END;

  TagAttr = POINTER TO TagAttrDesc;
  TagAttrDesc = RECORD
   value: ARRAY 512 OF CHAR;
  END;

 VAR 
  Wr: Texts.Writer;
  imgs: BOOLEAN;
  newTag: ExtTag;
  entities: ARRAY 69, 7 OF CHAR;
  entityEncoding: ARRAY 69 OF CHAR;
  pages: Page;
 PROCEDURE WriteLn (P: Page);
 PROCEDURE WriteSpace (P: Page);
 PROCEDURE WriteObj (P: Page; obj: Objects.Object);
 PROCEDURE PushTextAttrs (P: Page);
 PROCEDURE PopTextAttrs (P: Page);
 PROCEDURE GetFontSize (P: Page): INTEGER;
 PROCEDURE SetFontSize (P: Page; size: INTEGER);
 PROCEDURE HorzRule (P: Page; w, h: INTEGER);
 PROCEDURE TextAlign (VAR align: ARRAY OF CHAR): TextGadgets.Style;
 PROCEDURE CloseA (P: Page);
 PROCEDURE FindFormObj (form: Form; name: ARRAY OF CHAR): Objects.Object;
 PROCEDURE RememberValue (obj: Objects.Object);
 PROCEDURE AddFormObj (P: Page; form: Form; obj: Objects.Object; name: ARRAY OF CHAR; storeVal, write: BOOLEAN);
 PROCEDURE GetText (view: Objects.Object): Texts.Text;

(* HTMLDocs.Locate label
  Used for hyperlinks within the same page. *)
 PROCEDURE Locate;

(* HTMLDocs.ExecNext
  Used by clickable images to activate the surrounding hyperlink. *)
 PROCEDURE ExecNext;

(* HTMLDocs.Reset
  Used by the "Reset" button in forms. *)
 PROCEDURE Reset;
 PROCEDURE NewForm;

(* HTMLDocs.SubmitQuery
  Used by the "Submit" button in forms. *)
 PROCEDURE SubmitQuery;
 PROCEDURE Read (VAR S: Scanner);
 PROCEDURE WriteCharRef (P: Page; VAR S: Scanner);
 PROCEDURE CharRefStr (P: Page; VAR S: Scanner; VAR str: ARRAY OF CHAR);
 PROCEDURE Next (VAR S: Scanner);
 PROCEDURE NextAttr (VAR S: Scanner; VAR name: ARRAY OF CHAR): BOOLEAN;
 PROCEDURE GetAttrs (VAR S: Scanner; VAR attrs: TagAttr);
 PROCEDURE FindAttr (attrs: TagAttr; name: ARRAY OF CHAR): TagAttr;
 PROCEDURE OpenScanner (VAR S: Scanner; St: Streams.Stream);
 PROCEDURE SplitHostPort (VAR url, host: ARRAY OF CHAR; VAR port: INTEGER);
 PROCEDURE ExecAttrs;
 PROCEDURE Parse (D: Documents.Document; basekey: LONGINT; S: Streams.Stream; head, cache, blocking: BOOLEAN);
 PROCEDURE Show;

(* HTMLDocs.Stop *
 Stop all background task for the marked html document. *)
 PROCEDURE Stop;
 PROCEDURE NewDoc;

(* HTMLDocs.ShowHTML
  Display the HTML-source of the marked page. *)
 PROCEDURE ShowHTML;

(* HTMLDocs.SetImages
 Switch image loading on or off. *)
 PROCEDURE SetImages;
END HTMLDocs.