TextNodeRegistryImpl.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Doug Terry, June 26, 1987 7:09:38 pm PDT
DIRECTORY
RefTab USING [Create, Delete, EachPairAction, Fetch, Pairs, Ref, Store],
Rope USING [Size],
TextNodeRegistry;
TextNodeRegistryImpl: CEDAR PROGRAM
IMPORTS RefTab, Rope
EXPORTS TextNodeRegistry
~ BEGIN
Ref: TYPE ~ TextNodeRegistry.Ref;
ProcSet: TYPE ~ TextNodeRegistry.ProcSet;
registrationTable: RefTab.Ref = RefTab.Create[];
Register: PUBLIC PROC [activity: ATOM, procs: ProcSet] RETURNS [] ~ {
The given TransformProc will hereafter be applied to all nodes having an active property with value=activity.
[] ← RefTab.Store[registrationTable, activity, procs];
};
UnRegister: PUBLIC PROC [activity: ATOM] RETURNS [] ~ {
Removes the procedures associated with the given activity.
[] ← RefTab.Delete[registrationTable, activity];
};
GetProcs: PUBLIC PROC[activity: ATOM] RETURNS [procs: ProcSet] ~ {
Return the procedures associated with the given activity.
RETURN[NARROW[RefTab.Fetch[registrationTable, activity].val]];
};
ActivityOn: PUBLIC PROC [activity: ATOM, on: BOOLEANTRUE] RETURNS [wasOn: BOOLEAN] ~ {
Determines whether or not the registered transformations should be currently applied; if activity=NIL then activity is turned on/off for all registered clients. Registered clients are informed via callbacks when this switch is toggled so they can take appropriate action.
SetActivity: RefTab.EachPairAction = {
[key: RefTab.Key, val: RefTab.Val] RETURNS [quit: BOOLFALSE]
procs: TextNodeRegistry.ProcSet = NARROW[val];
IF procs#NIL THEN {
wasOn ← procs.activityOn;
procs.activityOn ← on;
IF wasOn#on AND procs.activityProc#NIL THEN
procs.activityProc[on, procs.activityProcData];
};
};
wasOn ← FALSE;
IF activity#NIL
THEN [] ← SetActivity[activity, RefTab.Fetch[registrationTable, activity].val]
ELSE [] ← RefTab.Pairs[registrationTable, SetActivity];
};
DoTransform: PUBLIC PROC [activity: ATOM, node: Ref, parent: Ref ← NIL, wantFirst: BOOLEANTRUE] RETURNS [new: Ref] ~ {
Force the TransformProc associated with the given activity to be applied to the node. (This is intended primarily for use by TextNodeImpl.)
procs: TextNodeRegistry.ProcSet = NARROW[RefTab.Fetch[registrationTable, activity].val];
new ← IF procs=NIL OR NOT procs.activityOn OR procs.transformProc=NIL THEN node ELSE procs.transformProc[node, parent, wantFirst, procs.transformProcData];
};
GetSize: PUBLIC PROC [activity: ATOM, node: Ref] RETURNS [size: INT] ~ {
Computes or estimates the size that the given node will be AFTER it is transformed by the specified activity. (This is intended primarily for use by TextNodeImpl.)
procs: TextNodeRegistry.ProcSet = NARROW[RefTab.Fetch[registrationTable, activity].val];
size ← IF procs=NIL OR NOT procs.activityOn OR procs.sizeProc=NIL THEN Rope.Size[node.rope] ELSE procs.sizeProc[node, procs.sizeProcData];
};
END.