DIRECTORY Buttons USING [Button, ButtonProc, Create], Containers USING [ChildXBound], EditToolBuilder USING [Layout], EditToolPrivate USING [editTool], IO USING [atom, Close, EndOfStream, Error, GetInt, int, Put, PutChar, RIS, RopeFromROS, ROS, STREAM], Labels USING [Create, Label], MessageWindow USING [Append, Blink], Rope USING [Map, ROPE], Rules USING [Create], TEditDocument USING [Selection, SelectionRec, TEditDocumentData], TEditInput USING [CheckSelection], TEditOps USING [GetSelData, SetTextContents], TEditSelection USING [MakeSelection], TextEdit USING [FetchLooks, GetRope, Size], TextLooks USING [Looks, noLooks], TextNode USING [FirstChild, NarrowToTextNode, Offset, RefTextNode], VFonts USING [StringWidth], ViewerClasses USING [Viewer], ViewerOps USING [CreateViewer], ViewerSpecs USING [openRightWidth], ViewerTools USING [SetContents, SetSelection]; EditToolBuilderImpl: CEDAR PROGRAM IMPORTS Buttons, Containers, EditToolPrivate, IO, Labels, MessageWindow, Rope, Rules, TEditInput, TEditOps, TEditSelection, TextEdit, TextNode, VFonts, ViewerOps, ViewerSpecs, ViewerTools EXPORTS EditToolBuilder, EditToolPrivate = { ROPE: TYPE = Rope.ROPE; Layout: TYPE = EditToolBuilder.Layout; ToNext: PUBLIC PROC [info: Layout, bigGap: BOOLEAN _ FALSE] = { OPEN info; entryLeft _ initLeft; heightSoFar _ heightSoFar + entryHeight + entryVSpace; IF bigGap THEN heightSoFar _ heightSoFar + entryVSpace/2 }; ToMiddle: PUBLIC PROC [info: Layout] = { OPEN info; entryLeft _ 190 }; BuildBox: PROC [info: Layout, proc: Buttons.ButtonProc, clientData: REF ANY _ NIL, fork: BOOL _ FALSE, gapAfter: BOOL _ TRUE, border: BOOL _ FALSE] RETURNS [button: Buttons.Button] = { OPEN info; button _ Buttons.Create[ info: [name: NIL, parent: container, wx: entryLeft, wy: heightSoFar+2, ww: entryHeight-2, wh: entryHeight-2, border: border], proc: proc, clientData: clientData, fork: fork, paint: FALSE]; entryLeft _ entryLeft + button.ww; IF gapAfter THEN entryLeft _ entryLeft + gapSize; }; BuildButton: PUBLIC PROC [info: Layout, name: Rope.ROPE, proc: Buttons.ButtonProc, clientData: REF ANY _ NIL, fork: BOOL _ FALSE, gapAfter: BOOL _ TRUE, border: BOOL _ FALSE] RETURNS [button: Buttons.Button] = { OPEN info; button _ Buttons.Create[ info: [name: name, parent: container, wx: entryLeft, wy: heightSoFar, border: border], proc: proc, clientData: clientData, fork: fork, paint: FALSE]; entryLeft _ entryLeft + button.ww; IF gapAfter THEN entryLeft _ entryLeft + gapSize; }; BuildLabel: PUBLIC PROC [info: Layout, name: Rope.ROPE, width: INTEGER _ 0] RETURNS [label: Labels.Label] = { OPEN info; label _ Labels.Create[info: [name: name, parent: container, border: FALSE, wx: entryLeft, wy: heightSoFar+1, ww: width, wh: entryHeight], paint: FALSE]; entryLeft _ entryLeft + label.ww; }; ---------------------------- BuildPair: PUBLIC PROC [info: Layout, proc: Buttons.ButtonProc, flag: BOOL, l1, l2: Rope.ROPE, clientData: REF ANY _ NIL, fork: BOOL _ FALSE] RETURNS [label: Labels.Label, button: Buttons.Button] = { OPEN info; w: INTEGER = MAX[ VFonts.StringWidth[l1], VFonts.StringWidth[l2]]; button _ BuildBox[info, proc, clientData, fork, FALSE, TRUE]; label _ BuildLabel[info, IF flag THEN l1 ELSE l2, w+15]; }; ---------------------------- BuildTriple: PUBLIC PROC [info: Layout, proc: Buttons.ButtonProc, state: [0..2], l0, l1, l2: Rope.ROPE, clientData: REF ANY _ NIL, fork: BOOLEAN _ FALSE] RETURNS [label: Labels.Label, button: Buttons.Button] = { OPEN info; w: INTEGER = MAX[ VFonts.StringWidth[l0], VFonts.StringWidth[l1], VFonts.StringWidth[l2]]; labelRopes: ARRAY [0..2] OF Rope.ROPE = [l0,l1,l2]; button _ BuildBox[info, proc, clientData, fork, FALSE, TRUE]; label _ BuildLabel[info, labelRopes[state], w+15]; }; ---------------------------- DataFieldButton: PUBLIC PROC [arg: ViewerClasses.Viewer, clear: BOOLEAN] = { IF clear THEN ViewerTools.SetContents[arg, NIL]; -- clear contents of field ViewerTools.SetSelection[arg, NIL]; -- make pending delete selection of field contents }; SavePSel: PUBLIC PROC = { IF ~EditToolPSel[] THEN prior^ _ TEditOps.GetSelData[]^ }; -- save it for later FixPSel: PUBLIC PROC = { -- if pSel is in data field, restore prior IF EditToolPSel[] AND TEditInput.CheckSelection[prior] THEN TEditSelection.MakeSelection[prior, primary] }; EditToolPSel: PROC RETURNS [BOOL] = { pSel: TEditDocument.Selection = TEditOps.GetSelData[]; RETURN [pSel # NIL AND pSel.viewer # NIL AND pSel.viewer.parent=EditToolPrivate.editTool] }; prior: TEditDocument.Selection _ NEW [TEditDocument.SelectionRec]; BuildDataFieldPair: PUBLIC PROC [info: Layout, buttonRope: Rope.ROPE, buttonProc: Buttons.ButtonProc, clientData: REF ANY _ NIL, lines: CARDINAL _ 2] RETURNS [button: Buttons.Button, arg: ViewerClasses.Viewer] = { OPEN info; fudge: CARDINAL = 1; button _ BuildButton[info: info, name: buttonRope, proc: buttonProc, clientData: clientData, fork: FALSE, gapAfter: FALSE]; arg _ ViewerOps.CreateViewer[flavor: $Text, info: [parent: container, wx: entryLeft, wy: heightSoFar+fudge, ww: ViewerSpecs.openRightWidth-entryLeft-5, wh: entryHeight*lines, border: FALSE], paint: FALSE]; heightSoFar _ heightSoFar + entryHeight*lines; entryLeft _ initLeft; Containers.ChildXBound[container, arg]; }; ---------------------------- GetDataNode: PUBLIC PROC [arg: ViewerClasses.Viewer] RETURNS [TextNode.RefTextNode] = { tdd: TEditDocument.TEditDocumentData = NARROW[arg.data]; IF tdd=NIL THEN RETURN [NIL]; RETURN [TextNode.NarrowToTextNode[TextNode.FirstChild[tdd.text]]] }; GetDataLooks: PUBLIC PROC [arg: ViewerClasses.Viewer, name: Rope.ROPE] RETURNS [looks: TextLooks.Looks] = { node: TextNode.RefTextNode _ GetDataNode[arg]; size: TextNode.Offset = TextEdit.Size[node]; IF size=0 THEN RETURN [TextLooks.noLooks]; looks _ TextEdit.FetchLooks[node,0]; FOR i: TextNode.Offset IN [1..size) DO IF TextEdit.FetchLooks[node,i]#looks THEN { OPEN MessageWindow; Append[name,TRUE]; Append[" does not have uniform looks. Using looks from first char."]; Blink[]; EXIT }; ENDLOOP }; BadNumber: PUBLIC SIGNAL = CODE; GetInt: PUBLIC PROC [arg: ViewerClasses.Viewer] RETURNS [num: INT] = { rope: Rope.ROPE _ TextEdit.GetRope[GetDataNode[arg]]; h: IO.STREAM _ IO.RIS[rope]; num _ IO.GetInt[h ! IO.Error, IO.EndOfStream => GOTO BadNum]; EXITS BadNum => SIGNAL BadNumber }; SetInt: PUBLIC PROC [arg: ViewerClasses.Viewer, num: INT] = { h: IO.STREAM _ IO.ROS[]; IO.Put[h,IO.int[num]]; TEditOps.SetTextContents[arg, IO.RopeFromROS[h]]; }; ConvertList: PUBLIC PROC [list: LIST OF REF ANY] RETURNS [Rope.ROPE] = { OPEN IO; h: IO.STREAM _ IO.ROS[]; doingChars: BOOLEAN _ FALSE; nospace: BOOLEAN _ TRUE; Space: PROC = { IF doingChars THEN { -- end of string PutChar[h, '"]; doingChars _ FALSE }; IF nospace THEN nospace _ FALSE ELSE PutChar[h,' ] }; AddChar: PROC [c: CHARACTER] = { IF ~doingChars THEN { -- start of string Space[]; PutChar[h, '"]; doingChars _ TRUE }; SELECT c FROM '', '", '\\ => PutChar[h, '\\]; ENDCASE; PutChar[h, c] }; { ENABLE UNWIND => h.Close[]; FOR l: LIST OF REF ANY _ list, l.rest UNTIL l=NIL DO WITH l.first SELECT FROM x: ATOM => { Space[]; Put[h,atom[x]] }; x: REF INT => { Space[]; Put[h,int[x^]] }; x: REF CHARACTER => AddChar[x^]; x: ROPE => { AddC: SAFE PROC [c: CHAR] RETURNS [BOOL] = { AddChar[c]; RETURN [FALSE] }; [] _ Rope.Map[base: x, action: AddC] }; x: REF TEXT => { FOR i: NAT IN [0..x.length) DO AddChar[x[i]]; ENDLOOP }; ENDCASE; ENDLOOP; IF doingChars THEN PutChar[h, '"]; RETURN [IO.RopeFromROS[h]]; }}; ---------------------------- HRule: PUBLIC PROC [info: Layout, thickness: CARDINAL _ 1, gapAbove, gapBelow: BOOLEAN _ TRUE] = { OPEN info; IF gapAbove THEN heightSoFar _ heightSoFar + entryVSpace*2; [] _ Rules.Create[info: [parent: container, wx: 0, wy: heightSoFar, ww: ViewerSpecs.openRightWidth, wh: thickness], paint: FALSE]; heightSoFar _ heightSoFar + thickness; IF gapBelow THEN heightSoFar _ heightSoFar + entryVSpace*2; }; }. .. @EditToolBuilderImpl.mesa Paxton on May 23, 1983 12:04 pm McGregor on September 1, 1982 3:56 pm Plass, April 15, 1983 12:53 pm Russ Atkinson, September 26, 1983 5:55 pm Doug Wyatt, January 13, 1984 2:40 pm -- change entryLeft and heightSoFar to next "line" in container -- change entryLeft to middle of container Ê š˜šÏc™Jš™Jš%™%J™J™)J™$J™—šÏk ˜ Jšœžœ˜+Jšœ žœ˜Jšœžœ ˜Jšœžœ ˜!Jš žœžœ>žœžœžœ˜eJšœžœ˜Jšœžœ˜$Jšœžœžœ˜Jšœžœ ˜Jšœžœ.˜AJšœ žœ˜"Jšœ žœ˜-Jšœžœ˜%Jšœ žœ˜+Jšœ žœ˜!Jšœ žœ5˜CJšœžœ˜Jšœžœ ˜Jšœ žœ˜Jšœ žœ˜#Jšœ žœ˜.J˜—Jšœž ˜"Jšžœ'žœ‹˜»Jšžœ!˜(Jšœžœ˜J˜Jšžœžœžœ˜J˜Jšœžœ˜&J˜š Ïnœžœžœžœžœžœ˜JJš?™?J˜J˜6Jšžœžœ-˜;J˜—šŸœžœžœžœ˜3Jš*™*J˜J˜—šŸœžœ6žœžœžœžœžœ žœžœžœžœ˜“Jšžœžœ˜/˜šœ žœ6˜FJšœ6˜6—Jšœ7žœ˜>—J˜"Jšžœ žœ!˜1J˜J˜—šŸ œžœžœžœžœ žœžœžœžœžœ žœžœžœžœ˜®Jšžœžœ˜/˜JšœV˜VJšœ7žœ˜>—J˜"Jšžœ žœ!˜1J˜J˜—š Ÿ œžœžœžœ žœ˜KJšžœžœ˜,šœDžœ˜JJšœFžœ˜M—J˜!J˜J˜—Jš˜J˜š Ÿ œžœžœ0žœžœ˜^Jš œ žœžœžœžœžœ˜.Jšžœ3žœ˜Dšœžœžœ˜J˜J˜—Jšœ0žœžœ˜=Jšœžœžœžœ ˜8J˜J˜—Jš˜J˜šŸ œžœžœJžœ˜gJš œ žœžœžœžœžœ˜1Jšžœ3žœ˜Dšœžœžœ˜J˜J˜J˜—Jšœ žœžœžœ˜3Jšœ0žœžœ˜=J˜2J˜J˜—Jš˜J˜šŸœžœžœ$žœ˜LJšžœžœžœ˜KJšœžœ2˜VJ˜J˜—šŸœžœžœ˜Jšžœžœ$˜OJ˜—šŸœžœžœ*˜Cšžœžœ"žœ˜