-- BBFocusImpl.mesa -- Russ Atkinson, November 4, 1982 10:49 am DIRECTORY AMBridge USING [FHFromTV, RemoteFHFromTV, RemoteFrameHandle, TVForFrame, TVForGFHReferent,GetWorld, TVForRemoteFrame, TVForRemoteGFHReferent], AMTypes USING [DynamicParent, Error, TVType, TypeClass], BBAction USING [Action, NextPendingAction], BBContext USING [Context, ContextForGlobalFrame, ContextForLocalFrame, GetContents], BBFocus USING [], BBSafety USING [IsValidAddr], Rope USING [Equal, ROPE], RTBasic USING [TV], WorldVM USING [Address, CurrentIncarnation, LocalWorld, Long, World, WorldName]; BBFocusImpl: CEDAR MONITOR IMPORTS AMBridge, AMTypes, BBAction, BBContext, BBSafety, Rope, WorldVM EXPORTS BBFocus = BEGIN OPEN BBAction, BBContext, Rope, RTBasic, WorldVM; defaultAction: Action _ NIL; defaultContext: Context _ NIL; -- Focus routines GetDefaultActionAndContext: PUBLIC ENTRY PROC RETURNS [action: Action, ctx: Context] = { -- gives the current "place" for the user action _ defaultAction; ctx _ defaultContext; }; SetDefaultActionAndContext: PUBLIC ENTRY PROC [action: Action, ctx: Context] = { -- sets the default action and context defaultAction _ action; defaultContext _ ctx; }; SetOctalContextFromGF: PUBLIC PROC [gf: CARDINAL, world: World _ NIL] RETURNS [tv: TV _ NIL] = TRUSTED { -- set the context to the given global frame in the current world -- the frame also must be under some action -- if anyAction = FALSE, must be under current action -- returns NIL if given frame not valid in any way addr: Address _ 0; IF world = NIL THEN world _ GetCurrentWorld[]; addr _ WorldVM.Long[world, gf]; IF addr = 0 THEN {SetDefaultActionAndContext[NIL, NIL]; RETURN}; IF NOT BBSafety.IsValidAddr[world, addr] THEN RETURN; IF world = WorldVM.LocalWorld[] THEN tv _ AMBridge.TVForGFHReferent [LOOPHOLE[gf] ! AMTypes.Error => CONTINUE] ELSE tv _ AMBridge.TVForRemoteGFHReferent [[world, world.CurrentIncarnation[], gf] ! AMTypes.Error => CONTINUE]; IF tv # NIL THEN SetDefaultActionAndContext[NIL, BBContext.ContextForGlobalFrame[tv]]; }; SetOctalContextFromLF: PUBLIC PROC [lf: CARDINAL, world: World _ NIL, anyAction: BOOL _ TRUE] RETURNS [tv: TV _ NIL] = TRUSTED { -- set the context to the given global frame in the current world -- the frame also must be under some action -- if anyAction = FALSE, must be under current action -- returns NIL if given frame not valid in any way addr: Address _ 0; IF world = NIL THEN world _ GetCurrentWorld[]; addr _ WorldVM.Long[world, lf]; IF addr = 0 THEN {SetDefaultActionAndContext[NIL, NIL]; RETURN}; IF NOT BBSafety.IsValidAddr[world, addr] THEN RETURN; IF world = WorldVM.LocalWorld[] THEN tv _ AMBridge.TVForFrame [LOOPHOLE[lf] ! AMTypes.Error => CONTINUE] ELSE tv _ AMBridge.TVForRemoteFrame [[world, world.CurrentIncarnation[], lf] ! AMTypes.Error => CONTINUE]; IF tv = NIL THEN RETURN; FOR action: Action _ NextPendingAction[NIL], NextPendingAction[action] UNTIL action = NIL DO frame: TV _ NIL; IF action.status # pendingOut THEN LOOP; IF NOT anyAction AND action # defaultAction THEN LOOP; frame _ FrameTVFromAction[action]; WHILE frame # NIL DO -- try to find the given local frame in some pending action IF SameLocalFrame[tv, frame] THEN {-- we win! SetDefaultActionAndContext[action, BBContext.ContextForLocalFrame[tv]]; RETURN; }; frame _ AMTypes.DynamicParent[frame ! AMTypes.Error => EXIT]; ENDLOOP; ENDLOOP; }; GetCurrentWorld: PUBLIC ENTRY PROC RETURNS [world: World] = TRUSTED { -- inherits world from current action OR context ENABLE UNWIND => NULL; IF defaultAction = NIL OR defaultAction.status = dead OR defaultAction.event = NIL THEN {-- try to get it through the default context world _ defaultContext.GetContents[].world; IF world = NIL THEN world _ WorldVM.LocalWorld[]; RETURN; }; world _ IF defaultAction.event = NIL THEN NIL ELSE defaultAction.event.world; IF world = NIL THEN world _ WorldVM.LocalWorld[]; }; -- a couple of minor uilities FrameTVFromAction: PUBLIC PROC [action: Action] RETURNS [lf: TV _ NIL] = { -- get the local frame for the given action -- can be NIL if the action is no longer valid IF action # NIL AND action.status # dead AND action.event # NIL THEN lf _ action.event.frame; }; SameLocalFrame: PUBLIC PROC [lf1,lf2: TV] RETURNS [BOOL] = TRUSTED { -- tests two local frame TVs for equality IF lf1 = lf2 THEN RETURN [TRUE]; IF AMTypes.TVType[lf1] # AMTypes.TVType[lf2] THEN RETURN [FALSE]; IF AMTypes.TypeClass[AMTypes.TVType[lf1]] # localFrame THEN RETURN [FALSE]; {world1: WorldVM.World _ AMBridge.GetWorld[lf1]; world2: WorldVM.World _ AMBridge.GetWorld[lf2]; IF world1 = NIL THEN world1 _ WorldVM.LocalWorld[]; IF world2 = NIL THEN world2 _ WorldVM.LocalWorld[]; IF world1 # world2 AND NOT Rope.Equal[world1.WorldName[], world2.WorldName[], FALSE] THEN RETURN [FALSE]; IF world1 = WorldVM.LocalWorld[] THEN RETURN [AMBridge.FHFromTV[lf1] = AMBridge.FHFromTV[lf2]] ELSE {RETURN [AMBridge.RemoteFHFromTV[lf1].fh = AMBridge.RemoteFHFromTV[lf2].fh]}; }; }; END. Κ”– "Mesa" style˜Iprocš¬Οc@œΟk œ žœ”žœ7žœ*žœTžœžœžœ žœ žœžœ žœRžœžœžœCžœ žœžœIžœžœœΟnœžœžœžœžœ)*œDŸœžœžœžœ('œ@Ÿœžœžœ žœžœžœžœžœžœBœ,œ6œ3œžœ žœžœDžœ žœžœžœžœžœžœ#žœžœžœ%žœ;žœ*žœ žœŽžœžœžœžœ#žœ4Ÿœžœžœ žœžœ žœžœžœžœžœžœBœ,œ6œ3œžœ žœžœDžœ žœžœžœžœžœžœ#žœžœžœ%žœ0žœ%žœ žœ~žœžœžœžœžœžœ$žœ-žœ žœžœžœžœ žœžœžœ žœžœ žœžœžœ5žœ žœžœ <œ žœžœ œfžœVžœžœ žœŸœžœžœžœžœžœ1œžœžœžœžœžœžœžœžœžœ -œ<žœ žœžœ'žœžœžœžœžœžœ žœ žœžœ)œŸœžœžœžœžœžœ ,œ/œžœ žœžœžœžœžœ,Ÿœžœžœ žœžœžœžœ*œžœ žœžœžœžœ+žœžœžœžœ5žœžœžœržœ žœžœ%žœ žœžœ%žœžœžœ4žœ žœžœžœžœ'žœ žœ;žœ žœržœ˜Œ-J˜—…—*