DIRECTORY Rope USING [ROPE], TextLooks USING [Runs]; TextNode: CEDAR DEFINITIONS = BEGIN Offset: TYPE = INT _ 0; MaxLen: INT = LAST[INT]; ROPE: TYPE = Rope.ROPE; Ref: TYPE = REF Body; RefTextNode: TYPE = Ref; -- a synonym for backwards compatibility. Body: TYPE = RECORD [ next: Ref, -- points to next sibling, or if last=true, to parent child: Ref, -- points to first child, if any, of this node props: NodeProps, -- points to node property list formatName: ATOM _ NIL, -- name of format for the node last: BOOL _ FALSE, -- true if this is last sibling hasstyledef: BOOL _ FALSE, -- true if node has StyleDef prop (accelerator) hasprefix: BOOL _ FALSE, -- true if node has Prefix prop (accelerator) haspostfix: BOOL _ FALSE, -- true if node has Postfix prop (accelerator) hascharprops: BOOL _ FALSE, -- true if node has CharProps prop (accelerator) hascharsets: BOOL _ FALSE, -- true if node has CharSets prop (accelerator) hasartwork: BOOL _ FALSE, -- true if node has Artwork prop (accelerator) deleted: BOOL _ FALSE, -- true if has been deleted or is root pending delete dirty: BOOL _ FALSE, -- true if has been edited (contents, or children moved, inserted, ...) new: BOOL _ FALSE, -- true if created during this editing session (i.e., not from file) comment: BOOL _ FALSE, -- true if node is a comment count: [0..countMax] _ 0, -- incremented by text edit routines rope: ROPE, runs: TextLooks.Runs ]; Location: TYPE = RECORD [node: Ref, where: INT]; NodeItself: INT = -1; nullLocation: Location = [node: NIL, where: NodeItself]; MakeNodeLoc: PROC [n: Ref] RETURNS [Location]; Span: TYPE = RECORD [start, end: Location _ nullLocation]; nullSpan: Span = [nullLocation,nullLocation]; MakeNodeSpan: PROC [first, last: Ref] RETURNS [Span]; countMax: NAT = 31; -- 5 bits for count OfNode: TYPE = {text, other}; NodeList: TYPE = REF NodeListBody; NodeListBody: TYPE = RECORD [node: Ref, next: NodeList]; NodeProps: TYPE = REF NodePropsBody; NodePropsBody: TYPE; -- exported by NodePropsImpl NewTextNode: PROC RETURNS [txt: RefTextNode]; NarrowToTextNode: PROC [n: Ref] RETURNS [txt: RefTextNode]; Parent: PROC [n: Ref] RETURNS [Ref]; Root: PROC [n: Ref] RETURNS [Ref]; Next: PROC [n: Ref] RETURNS [Ref]; Previous: PROC [n: Ref, parent: Ref _ NIL] RETURNS [nx: Ref]; Forward: PROC [node: Ref] RETURNS [nx: Ref, levelDelta: INTEGER]; Backward: PROC [node: Ref, parent: Ref _ NIL] RETURNS [back, backparent: Ref, levelDelta: INTEGER]; StepForward: PROC [node: Ref] RETURNS [Ref]; StepBackward: PROC [node: Ref, parent: Ref _ NIL] RETURNS [Ref]; Level: PROC [node: Ref] RETURNS [level: INTEGER]; ForwardClipped: PROC [node: Ref, maxLevel: INTEGER, nodeLevel: INTEGER _ 0] RETURNS [nx: Ref, nxLevel: INTEGER]; BackwardClipped: PROC [node: Ref, maxLevel: INTEGER, parent: Ref _ NIL, nodeLevel: INTEGER _ 0] RETURNS [back, backparent: Ref, backLevel: INTEGER]; LocRelative: PROC [location: Location, count: INT, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [Location]; LocWithin: PROC [n: Ref, count: INT, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [Location]; LocOffset: PROC [loc1, loc2: Location, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [count: INT]; BadArgs: ERROR; LocNumber: PROC [at: Location, break: NAT _ 1, skipCommentNodes: BOOL _ FALSE] RETURNS [count: INT]; FirstSibling: PROC [n: Ref] RETURNS [Ref]; LastSibling: PROC [n: Ref] RETURNS [Ref]; LastWithin: PROC [n: Ref] RETURNS [Ref]; LastLocWithin: PROC [n: Ref] RETURNS [Location]; FirstChild: PROC [n: Ref] RETURNS [Ref]; LastChild: PROC [n: Ref] RETURNS [Ref]; NthChild: PROC [n: Ref, location: INT _ 0] RETURNS [child: Ref]; NthSibling: PROC [n: Ref, cnt: INT _ 0] RETURNS [Ref]; CountChildren: PROC [n: Ref] RETURNS [count: INT]; CountFollowing: PROC [n: Ref] RETURNS [count: INT]; CountToParent: PROC [n: Ref] RETURNS [count: INT, parent: Ref]; CountToChild: PROC [parent, child: Ref] RETURNS [count: INT]; NodeRope: PROC [n: RefTextNode] RETURNS [ROPE]; NodeRuns: PROC [n: RefTextNode] RETURNS [TextLooks.Runs]; Props: PROC [n: Ref] RETURNS [NodeProps]; NodeFormat: PROC [n: Ref] RETURNS [ATOM]; IsLastSibling: PROC [n: Ref] RETURNS [BOOL]; EndPos: PROC [n: Ref] RETURNS [INT]; END. zTextNode.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. written by Bill Paxton. December 1980 last written by Paxton. December 21, 1982 9:46 am Last Edited by: Maxwell, January 5, 1983 12:37 pm Rick Beach, March 27, 1985 1:08:21 pm PST Michael Plass, March 26, 1985 12:18:42 pm PST Doug Wyatt, March 2, 1985 3:27:50 pm PST where >= length of text means at end where = loc in [0..length) means before that character e.g., where = 0 means at start of text where = NodeItself means location is the node itself rather than in its contents start.node can equal end.node in which case either both start.where and end.where = NodeItself, or neither do and start.where <= end.where otherwise, end.node should follow start.node in the tree nodes need not be siblings no restrictions on start.where or end.where For backwards compatability. returns next sibling of n returns NIL if n is last sibling returns previous sibling of n returns NIL if n is first sibling runs faster if can supply parent returns next node in standard tree walk order levelDelta is level(node)-level(nx), where level is depth in tree levelDelta = 0 if nx and node are siblings levelDelta = 1 if nx is child of node levelDelta < 0 if do Parent* and Next to reach nx from node for backing through tree runs faster if can supply parent levelDelta same as for Forward returns next node in standard tree walk order returns preceding node in standard tree walk order Level[Root[x]] == 0; Level[FirstChild[n]]=Level[n]+1 like Forward, but limits how deep will go in tree if pass nodeLevel=0, correct value will be computed nxLevel = Level[nx] <= MAX[maxLevel,Level[node]] like Backward, but limits how deep will go in tree backLevel = Level[back] <= MAX[maxLevel,Level[node]] count is interpreted as a character offset from given location returns location corresponding to count adds in break at the end of each text subnode if skipCommentNodes is true, then ignores them in walking the tree returns character offset of location2 relative to location1 loc1 and loc2 can be in same node but loc2 must not be in node before loc1 or get ERROR BadArgs if skipCommentNodes is true, then ignores them in walking the tree returns character offset of location relative to root returns the last node within the branch i.e., goes to last child of last child of last child ... until no child returns the last location within the branch ΚΖ˜codešœ ™ Kšœ Οmœ1™Kšœžœ˜ K˜šœ˜K˜——šœ žœžœžœ˜0Kšœ$™$šœ6™6Kšœ&™&—KšœP™PK˜—Kšœ žœ˜K˜Kšœ žœ˜8K˜KšΟn œžœ žœ ˜.K˜šœžœžœ'˜:šœ™KšœD™DKšœ'™'—šœ8™8Kšœ™Kšœ+™+K˜——K˜-K˜š‘ œžœžœ˜5K˜—Kšœ žœ ˜'Kšœžœ˜K˜K˜Kšœ žœžœ˜"Kšœžœžœ˜8K˜Kšœ žœžœ˜$Kšœžœ ˜1K˜š‘ œžœžœ˜-K˜—š‘œžœ žœ˜;K™K˜—š‘œžœ žœ˜$K˜—š‘œžœ žœ˜"K˜—š‘œžœ žœ˜"Kšœ™Kšœžœ™ K˜—š‘œžœžœžœ ˜=Kšœ™Kšœžœ™!Kšœ ™ K˜—š‘œžœ žœžœ˜AKšœ-™-šœA™AKšœ*™*Kšœ%™%Kšœ;™;K˜——š‘œžœžœ˜-Kšžœ%žœ˜5Kšœ™Kšœ ™ Kšœ™K˜—š‘ œžœ žœ˜,Kšœ-™-K˜—š‘ œžœžœžœ˜@Kšœ2™2K˜—K˜š‘œžœ žœ žœ˜1Kšœ4™4K˜—š ‘œžœžœ žœžœžœ˜pKšœ1™1Kšœ4™4Kšœžœ™0K˜—š‘œžœžœžœžœžœ$žœ˜•Kšœ2™2Kšœžœ™4K˜—K˜š‘ œžœžœ žœžœžœžœ ˜wKšœ>™>Kšœ5™5Kšœ-™-KšœB™BK˜—š‘ œžœžœ žœžœžœžœ ˜hK˜—š‘ œžœžœžœžœžœ žœ˜lKšœ;™;Kšœ!™!Kšœ0žœ™=KšœB™BK˜—šœ žœ˜K˜—š‘ œžœžœžœžœžœ žœ˜dKšœ5™5K˜—K˜š‘ œžœ žœ˜*K˜—š‘ œžœ žœ˜)K˜—š‘ œžœ žœ˜(Kšœ(™(KšœG™GK˜—š‘ œžœ žœ ˜0Kšœ,™,K˜—K˜š‘ œžœ žœ˜(K˜—š‘ œžœ žœ˜'K˜—š‘œžœžœžœ˜@K˜—š‘ œžœžœžœ˜6K˜—K˜š‘ œžœ žœ žœ˜2K˜—š‘œžœ žœ žœ˜3K˜—š‘ œžœ žœ žœ˜?K˜—š‘ œžœžœ žœ˜=K˜—K˜š‘œžœžœžœ˜/K˜—š‘œžœžœ˜9K˜—š‘œžœ žœ ˜)K˜—š‘ œžœ žœžœ˜)K˜—š‘ œžœ žœžœ˜,K˜—š‘œžœ žœžœ˜$K˜——Kšžœ˜—…—–!Φ