f)Syntax10.Scn.Fnt Syntax10i.Scn.Fnt`=IStampElemsAlloc19 Mar 98qInfoElemsAlloc#Syntax10.Scn.Fnt"Title": Formularinstaller (Forms) "Author": Stefan Aufischer "Abstract": Installs HTML-Formular-Tags to the Oberon-Webbrowser. Look for elements in FormElems.Mod "Keywords": Install "Version": "From": 10.12.97 "Until": 17.03.98 "Changes": Syntax10b.Scn.Fnt8FoldElemsNew#Syntax10.Scn.Fnt FormTags in HTML 2.0 88 ;     4     #       &  $  $ 8 8388388M8 . &8/3 , Q8 &8-8   8 +8j,$)+     &8+     =*8  888 '89 ') 8 8 <:/- 8 8 D#/C8 8 ? U S  Q P - 0  =8 8 0  88 8  #778 8  &8!(# 8 8!!8' #8*8B +5 " $#0$88#'   #88+' % "88  #8? #; 8 ( " $   $884"$69$*9@"N $889!B(ci4@ ,88!'J N "88!$J N"885!?& Z!)7  +-## 16((18 8 8* 8AMODULE Forms; (** SA  *)  IMPORT Display, Files, Texts, Strings, Web, WebElems, HTML, Elems, ButtonElems, CheckBoxElems, RadioButtonElems, TextFieldElems, TextAreaElems, ListElems, FormElems; (* "FORM" "ACTION" "METHOD" "ENCTYPE" "INPUT" "TYPE" TYPE="TEXT" "NAME" "MAXLENGTH" "SIZE" "VALUE" TYPE="PASSWORD" "NAME" "MAXLENGTH" "SIZE" "VALUE" TYPE="CHECKBOX" "NAME" "VALUE" "CHECKED" TYPE="RADIO" "NAME" "VALUE" "CHECKED" TYPE="IMAGE" "NAME" "SRC" "ALIGN" TYPE="HIDDEN" "NAME" "VALUE" TYPE="SUBMIT" "NAME" "VALUE" TYPE="RESET" "VALUE" "SELECT" "MULTIPLE" "MULTI" "NAME" "SIZE" "OPTION" "SELECTED" "VALUE" "TEXTAREA" "COLS" "NAME" "ROWS" *) CONST  (* tags *) form= "FORM"; (* one FORM is including 0, 1 or many INPUTs, TEXTAREA's *) input = "INPUT"; textArea = "TEXTAREA"; select = "SELECT"; option = "OPTION"; (* one SELECT is including (0, 1 or) many OPTIONS *) imgName = "NAME"; (* tag attributes *) action = "ACTION"; method = "METHOD"; encType = "ENCTYPE"; (* form tag *) (* tag attributes for input tags *) type = "TYPE"; value = "VALUE"; name = "NAME"; size = "SIZE"; maxLength = "MAXLENGTH"; checked = "CHECKED"; imgSource = "SRC"; (* for INPUT TYPE="IMAGE" *) (* tag attributes for textArea tags *) rows = "ROWS"; cols = "COLS"; (* tag attributes for select tags *) multiple = "MULTIPLE"; multi = "MULTI"; (* tag attributes for option tags *) selected = "SELECTED";  TYPE TextArea = POINTER TO TextAreaDesc;  TextAreaDesc = RECORD (HTML.ContainerDesc) area : FormElems.TextArea END; Selection = POINTER TO SelectionDesc;  SelectionDesc = RECORD (HTML.ContainerDesc) sel : FormElems.Selection END; VAR  handleTag : HTML.TagHandle; handleElem, handleExtElem : HTML.ElemHandle;  PROCEDURE WriteElem(w : Texts.Writer; e : Texts.Elem); BEGIN IF (e#NIL) THEN Texts.WriteElem(w, e) END END WriteElem; PROCEDURE (tA : TextArea) Handle (VAR w : Texts.Writer; txt : Texts.Text);  VAR r : Texts.Reader; buf : Texts.Buffer; ch : CHAR; BEGIN (* delete starting returns *) Texts.OpenReader(r, txt, 0); Texts.Read(r, ch); WHILE ~ r.eot & ((ch = 0DX) OR (ch = 20X)) DO Texts.Read(r, ch) END; Texts.Delete(txt, 0, Texts.Pos(r) - 1); (* set font and color of text *) Texts.ChangeLooks(txt, 0, txt.len, {0, 1}, HTML.fixedFont, Display.white, 0); (* create and write elem *) NEW(buf); Texts.OpenBuf(buf); Texts.Save(txt, 0, txt.len, buf); Texts.SetFont(w, HTML.fixedFont); WriteElem(w, FormElems.NewTextArea(tA.area, buf)) END Handle; PROCEDURE (s : Selection) Handle (VAR w : Texts.Writer; txt : Texts.Text);  VAR r : Texts.Reader; W : Texts.Writer; ch : CHAR; attr : HTML.Attribute; opt : FormElems.Option; i : INTEGER; pos : LONGINT; skipLWS : BOOLEAN; PROCEDURE SkipToOption (VAR r : Texts.Reader);  BEGIN REPEAT Texts.ReadElem(r) UNTIL r.eot OR (r.elem = NIL) OR (r.elem(HTML.TagElem).tag.name = option) END SkipToOption; BEGIN Texts.OpenWriter(W); Texts.SetFont(W, HTML.fixedFont); Texts.OpenReader(r, txt, 0); SkipToOption(r); WHILE ~ r.eot & (r.elem # NIL) DO attr := r.elem(HTML.TagElem).tag.attr; NEW(opt); FormElems.InitOption(opt); WHILE attr # NIL DO IF attr.name = selected THEN opt.selected := TRUE ELSIF attr.name = value THEN opt.value := attr.value END; attr := attr.next END; (* collect opt.text *) i := 0; skipLWS := TRUE; pos := Texts.Pos(r); (* determine length of future opt.text *) Texts.Read(r, ch); WHILE ~ r.eot & ((r.elem = NIL) OR (r.elem(HTML.TagElem).tag.name # option)) DO IF (r.elem # NIL) OR (ch = 09X) OR (ch = 0DX) OR (ch = 20X) THEN IF ~ skipLWS THEN INC(i); skipLWS := TRUE END ELSE INC(i); skipLWS := FALSE END; Texts.Read(r, ch) END; IF skipLWS & (i>0) THEN DEC(i) END; (* alloc anf fill opt.text *) NEW(opt.text, i+1); i := 0; skipLWS := TRUE; Texts.OpenReader(r, txt, pos); Texts.Read(r, ch); WHILE ~ r.eot & ((r.elem = NIL) OR (r.elem(HTML.TagElem).tag.name # option)) DO IF (r.elem # NIL) OR (ch = 09X) OR (ch = 0DX) OR (ch = 20X) THEN IF ~ skipLWS THEN opt.text[i] := 20X; INC(i); skipLWS := TRUE END ELSE opt.text[i] := ch; INC(i); skipLWS := FALSE END; Texts.Read(r, ch) END; IF skipLWS & (i>0) THEN DEC(i) END; opt.text[i] := 0X; FormElems.AddOption(W, s.sel, opt) END; WriteElem(w, FormElems.NewList(s.sel)) END Handle; PROCEDURE TagHandle (VAR w : Texts.Writer; VAR tag : HTML.Tag; VAR c : HTML.Container);  VAR  attr : HTML.Attribute; tArea : TextArea; sel : Selection; f : FormElems.FormElem; inp : FormElems.InputTag; pict : WebElems.ImageElem;  PROCEDURE WriteImage(inp : FormElems.InputTag);  BEGIN pict := FormElems.NewImage(); WriteElem(w, pict); IF inp.src # NIL THEN WebElems.SetSource(pict, inp.src^, TRUE) END; COPY(inp.name, pict.alt); pict.isMap := FALSE END WriteImage; PROCEDURE ReadInputTagAttributes;  BEGIN WHILE (attr # NIL) DO IF attr.name = type THEN COPY(attr.value^, inp.type) ELSIF attr.name = value THEN COPY(attr.value^, inp.value); inp.dynValue := attr.value ELSIF attr.name = name THEN COPY(attr.value^, inp.name); inp.dynName := attr.value ELSIF attr.name = maxLength THEN inp.maxLen := Web.Str2Int(attr.value^) ELSIF attr.name = size THEN inp.size := Web.Str2Int(attr.value^) ELSIF attr.name = checked THEN inp.checked:= TRUE ELSIF attr.name = imgSource THEN (* set source of image *) inp.src := attr.value ELSE END; attr := attr.next END; Strings.Cap(inp.type) END ReadInputTagAttributes; BEGIN attr := tag.attr; IF tag.name = form THEN  IF tag.start THEN f := FormElems.NewForm(WebElems.LeftSide, HTML.showAnchors); COPY("GET", f.method); COPY("application/x-www-form-urlencoded", f.encType); WHILE attr # NIL DO IF attr.name = action THEN f.url := attr.value; ELSIF attr.name = method THEN IF attr.value # NIL THEN COPY(attr.value^, f.method); Strings.Cap(f.method) END ELSIF attr.name = encType THEN IF (attr.value # NIL) THEN COPY(attr.value^, f.encType) END END; attr := attr.next END ELSE f := FormElems.NewForm(WebElems.RightSide, HTML.showAnchors) END; Texts.WriteElem(w, f) ELSIF tag.name = input THEN  IF tag.start THEN NEW(inp); FormElems.InitInput(inp); ReadInputTagAttributes; IF inp.type = "SUBMIT" THEN Texts.SetFont(w, HTML.fixedFont); WriteElem(w, FormElems.NewSubmitButton(inp)) ELSIF inp.type = "RESET" THEN Texts.SetFont(w, HTML.fixedFont); WriteElem(w, FormElems.NewResetButton(inp)) ELSIF (inp.type = "TEXT") OR (inp.type = "NOTYPE") THEN Texts.SetFont(w, HTML.fixedFont); WriteElem(w, FormElems.NewTextField(inp)) ELSIF inp.type = "PASSWORD" THEN Texts.SetFont(w, HTML.fixedFont); WriteElem(w, FormElems.NewPassWord(inp)) ELSIF inp.type = "CHECKBOX" THEN WriteElem(w, FormElems.NewCheckBox(inp)) ELSIF inp.type = "RADIO" THEN WriteElem(w, FormElems.NewRadioButton(inp)) ELSIF inp.type = "IMAGE" THEN WriteImage(inp) ELSIF inp.type = "HIDDEN" THEN WriteElem(w, FormElems.NewHidden(inp, HTML.showAnchors)) END END ELSIF tag.name = select THEN  IF tag.start THEN NEW(sel); sel.nested := FALSE; sel.plainText := FALSE; sel.skipComments := TRUE; NEW(sel.sel); FormElems.InitSelection(sel.sel); WHILE (attr # NIL) DO IF attr.name = name THEN COPY(attr.value^, sel.sel.name) ELSIF (attr.name = multiple) OR (attr.name = multi) THEN sel.sel.multiple := TRUE ELSIF attr.name = size THEN sel.sel.vertSize := Web.Str2Int(attr.value^) END; attr := attr.next END; c := sel END ELSIF tag.name = textArea THEN  IF tag.start THEN NEW(tArea); tArea.nested := FALSE; tArea.plainText := TRUE; tArea.skipComments := TRUE; (* <- no care *) NEW(tArea.area); WHILE (attr # NIL) DO IF attr.name = name THEN COPY(attr.value^, tArea.area.name) ELSIF attr.name = rows THEN tArea.area.rows := Web.Str2Int(attr.value^) ELSIF attr.name = cols THEN tArea.area.cols := Web.Str2Int(attr.value^) END; attr := attr.next END; c := tArea END ELSE handleTag(w, tag, c) END END TagHandle; PROCEDURE AppendAttr(VAR attr : HTML.Attribute; name, value : ARRAY OF CHAR);  BEGIN NEW(attr.next); attr := attr.next; NEW(attr.value, Strings.Length(value)+1); COPY(name, attr.name); COPY(value, attr.value^); attr.next := NIL END AppendAttr; PROCEDURE AppendNoValueAttr(VAR attr : HTML.Attribute; name : ARRAY OF CHAR);  BEGIN NEW(attr.next); attr := attr.next; COPY(name, attr.name); attr.value := NIL; attr.next := NIL END AppendNoValueAttr; (* handle extended types of WebElems *) PROCEDURE ExtendedElemHandle (VAR r : Files.Rider; e : Texts.Elem);  VAR tag : HTML.Tag; attr : HTML.Attribute; BEGIN WITH e : FormElems.FormElem DO  tag.name := form; tag.start := e.side = WebElems.LeftSide; IF tag.start THEN NEW(tag.attr); attr := tag.attr; attr.name := "dummy"; (* to avoid further costs, caused by queuehandling *) IF e.url # NIL THEN AppendAttr(attr, action, e.url^) END; IF (e.method # "") & (e. method # "GET") THEN AppendAttr(attr, method, e.method) END; IF (e.encType # "") & (e.encType # "application/x-www-form-urlencoded") THEN AppendAttr(attr, encType, e.encType) END; tag.attr := tag.attr.next; END; HTML.StoreTag(r, tag) | e : FormElems.HiddenElem DO  tag.name := input; tag.start := TRUE; NEW(tag.attr); attr := tag.attr; NEW(attr.value, 7); attr.name := type; COPY("HIDDEN", attr.value^); IF e.name # "" THEN AppendAttr(attr, name, e.name) END; IF e.value # NIL THEN AppendAttr(attr, value, e.value^) END; HTML.StoreTag(r, tag) | e : FormElems.ImageElem DO  tag.name := input; NEW(tag.attr); attr := tag.attr; tag.start := TRUE; NEW(attr.value, 6); attr.name := type; COPY("IMAGE", attr.value^); IF e.src # NIL THEN AppendAttr(attr, imgSource, e.src^) END; IF e.alt # "" THEN AppendAttr(attr, imgName, e.alt) END; HTML.StoreTag(r, tag) ELSE handleExtElem(r, e) END END ExtendedElemHandle; PROCEDURE ElemHandle (VAR r : Files.Rider; e : Texts.Elem);  (* handle new types as ButtonElems, TextFieldElems and so on *) VAR tag : HTML.Tag; attr : HTML.Attribute; inp : FormElems.InputTag; tArea : FormElems.TextArea; sel : FormElems.Selection; opt : FormElems.Option; popup, eot, eoKeyT : BOOLEAN; str : ARRAY 256 OF CHAR; key : Web.DynamicString; col : SHORTINT; rd : Texts.Reader; optT, keyT, txt : Texts.Text; ch : CHAR; i : INTEGER; keyPos, optPos : LONGINT; BEGIN tag.start := TRUE; WITH e : ButtonElems.Elem DO  NEW(inp); Elems.GetString(e, "Cmd", inp.value); IF inp.value="FormElems.SubmitForm" THEN tag.name := input; NEW(tag.attr); attr := tag.attr; NEW(attr.value, 7); attr.name := type; COPY("SUBMIT", attr.value^); attr.next := NIL; Elems.GetString(e, "Name", inp.name); IF (inp.name#"") THEN AppendAttr(attr, name, inp.name) END; Elems.GetString(e, "Value", inp.value); IF (inp.value#"Submit Query") THEN AppendAttr(attr, value, inp.value) END; HTML.StoreTag(r, tag) ELSIF inp.value="FormElems.ResetForm" THEN tag.name := input; NEW(tag.attr); attr := tag.attr; NEW(attr.value, 6); attr.name := type; COPY("RESET", attr.value^); attr.next := NIL; Elems.GetString(e, "Caption", inp.value); IF inp.value#"Reset" THEN AppendAttr(attr, value, inp.value) END; HTML.StoreTag(r, tag) END; | e : TextFieldElems.Elem DO  NEW(inp); tag.name := input; NEW(tag.attr); attr := tag.attr; Elems.GetString(e, "Name", inp.name); IF e IS TextFieldElems.PWElem THEN (* Append TYPE=... and NAME=... *) attr.name := type; attr.next := NIL; NEW(attr.value, 9); COPY("PASSWORD", attr.value^); AppendAttr(attr, name, inp.name) ELSE (* Append only NAME=... , because TYPE=TEXT is default *) attr.name := name; attr.next := NIL; NEW(attr.value, Strings.Length(inp.name)+1); COPY(inp.name, attr.value^) END; Elems.GetInteger(e, "Size", inp.size); IF inp.size#FormElems.undef THEN Web.Int2Str(inp.size, str); AppendAttr(attr, size, str) END; Elems.GetInteger(e, "MaxLen", inp.maxLen); IF inp.maxLen>0 THEN Web.Int2Str(inp.maxLen, str); AppendAttr(attr, maxLength, str) END; WITH e : TextFieldElems.PWElem DO txt := e.txt; keyPos := 0; WITH txt : TextFieldElems.PWText DO eot := FormElems.TextLineToString(txt.hidden, keyPos, inp.value, col) END ELSE Elems.GetString(e, "Value", inp.value) END; IF inp.value#"" THEN AppendAttr(attr, value, inp.value) END; HTML.StoreTag(r, tag) | e : TextAreaElems.Elem DO  NEW(tArea); tag.name := textArea; Elems.GetString(e, "Name", tArea.name); NEW(tag.attr); attr := tag.attr; NEW(attr.value, Strings.Length(tArea.name)+1); attr.name := name; COPY(tArea.name, attr.value^); attr.next := NIL; Elems.GetInteger(e, "Rows", tArea.rows); Web.Int2Str(tArea.rows, str); AppendAttr(attr, rows, str); Elems.GetInteger(e, "Cols", tArea.cols); Web.Int2Str(tArea.cols, str); AppendAttr(attr, cols, str); HTML.StoreTag(r, tag); (* text between beginning and ending textarea-tag *) Elems.GetText(e, "ValueT", txt); Texts.OpenReader(rd, txt, 0); Texts.Read(rd, ch); WHILE ~rd.eot DO IF ch#Texts.ElemChar THEN HTML.StoreChar(r, ch) END; Texts.Read(rd, ch) END; tag.name := textArea; tag.start := FALSE; HTML.StoreTag(r, tag) | e : CheckBoxElems.Elem DO  NEW(inp); tag.name := input; NEW(tag.attr); attr := tag.attr; NEW(attr.value, 9); attr.name := type; COPY("CHECKBOX", attr.value^); attr.next := NIL; Elems.GetString(e, "Name", inp.name); AppendAttr(attr, name, inp.name); Elems.GetString(e, "ValueStr", inp.value); AppendAttr(attr, value, inp.value); Elems.GetBoolean(e, "Value", inp.checked); IF inp.checked THEN AppendNoValueAttr(attr, checked) END; HTML.StoreTag(r, tag) | e : RadioButtonElems.Elem DO  NEW(inp); tag.name := input; NEW(tag.attr); attr := tag.attr; NEW(attr.value, 6); attr.name := type; COPY("RADIO", attr.value^); attr.next := NIL; Elems.GetString(e, "Name", inp.name); AppendAttr(attr, name, inp.name); Elems.GetString(e, "MyValue", inp.myValue); AppendAttr(attr, value, inp.myValue); Elems.GetString(e, "Value", inp.value); IF inp.value=inp.myValue THEN AppendNoValueAttr(attr, checked) END; HTML.StoreTag(r, tag) | e : ListElems.Elem DO  NEW(sel); tag.name := select; Elems.GetString(e, "Name", sel.name); NEW(tag.attr); attr := tag.attr; NEW(attr.value, Strings.Length(sel.name)+1); attr.name := name; COPY(sel.name, attr.value^); attr.next := NIL; Elems.GetBoolean(e, "Popup", sel.popup); IF sel.popup THEN sel.vertSize := 1 ELSE Elems.GetInteger(e, "Size", sel.vertSize) END; Web.Int2Str(sel.vertSize, str); AppendAttr(attr, size, str); Elems.GetBoolean(e, "Multi", sel.multiple); IF (sel.vertSize>1) & sel.multiple THEN AppendNoValueAttr(attr, multiple) END; HTML.StoreTag(r, tag); Elems.GetBoolean(e, "Popup", popup); IF popup THEN Elems.GetString(e, "Value", sel.defaultSel) END; Elems.GetText(e, "ValueT", optT); Elems.GetText(e, "Keywords", keyT); tag.name := option; tag.attr := NIL; NEW(opt); keyPos := 0; optPos := 0; eoKeyT := ~FormElems.TextLineToDynString(keyT, keyPos, key, col); eot := ~FormElems.TextLineToDynString(optT, optPos, opt.value, col); WHILE ~eot DO tag.name := option; NEW(attr); attr.name := "dummy"; attr.next := NIL; tag.attr := attr; (* create dummy *) IF (key^#opt.value^) & ~eoKeyT THEN AppendAttr(attr, value, key^) END; IF popup THEN COPY(opt.value^, str); (* to cut opt.value back to 256 characters *) IF str = sel.defaultSel THEN AppendNoValueAttr(attr, selected) END ELSE IF col = ListElems.SelCol THEN AppendNoValueAttr(attr, selected) END END; tag.attr := tag.attr.next; (* delete dummy *) (* Write option tag and corresponding textline *) HTML.StoreChar(r, 0DX); HTML.StoreTag(r, tag); FOR i := 0 TO Strings.Length(opt.value^)-1 DO HTML.StoreChar(r, opt.value[i]) END; eoKeyT := ~FormElems.TextLineToDynString(keyT, keyPos, key, col); eot := ~FormElems.TextLineToDynString(optT, optPos, opt.value, col) END; tag.name := select; tag.start := FALSE; tag.attr := NIL; HTML.StoreChar(r, 0DX); HTML.StoreTag(r, tag) ELSE handleElem(r, e) END END ElemHandle; PROCEDURE Install*;  BEGIN (* only used to force loading of module *) END Install; BEGIN handleTag := HTML.handleTag; HTML.handleTag := TagHandle; handleElem := HTML.handleElem; HTML.handleElem := ElemHandle; handleExtElem := HTML.handleExtElem; HTML.handleExtElem := ExtendedElemHandle END Forms.