ViewerEventsImpl.mesa;
Edited by McGregor on August 2, 1982 11:44 am
Last Edited by: Maxwell, January 11, 1983 12:27 pm
Last Edited by: Wyatt, October 26, 1983 4:23 pm
DIRECTORY
ViewerClasses USING [Viewer],
ViewerEvents;
ViewerEventsImpl: CEDAR PROGRAM
EXPORTS ViewerEvents
= BEGIN OPEN ViewerEvents;
EventProcs: TYPE = LIST OF RECORD[proc: EventProc, filter: REF, before: BOOL] ;
eventProcs: ARRAY ViewerEvent OF EventProcs ;
RegisterEventProc: PUBLIC PROC [proc: EventProc, event: ViewerEvent,
filter: REF ANYNIL, before: BOOLTRUE]
RETURNS [EventRegistration] = {
RETURN [eventProcs[event] ← CONS[[proc, filter, before], eventProcs[event]]];
};
UnRegisterEventProc: PUBLIC PROC [proc: EventRegistration, event: ViewerEvent] = {
prev: EventProcs ← eventProcs[event];
IF prev = NIL THEN RETURN;
IF proc=prev THEN { -- its the first one on the list
eventProcs[event] ← eventProcs[event].rest;
RETURN };
FOR l: EventProcs ← prev.rest, l.rest UNTIL l=NIL DO
IF l=proc THEN { prev.rest ← l.rest; RETURN };
prev ← l;
ENDLOOP;
};
ProcessEvent: PUBLIC PROC [event: ViewerEvent, viewer: ViewerClasses.Viewer, before: BOOL]
RETURNS[abort: BOOL ← FALSE] = {
FOR l: EventProcs ← eventProcs[event], l.rest UNTIL l=NIL DO
IF l.first.before # before THEN LOOP;
IF l.first.filter # NIL
AND l.first.filter # viewer
AND l.first.filter # viewer.class.flavor
AND l.first.filter # viewer.class THEN LOOP;
abort ← l.first.proc[viewer, event, before ! ABORTED => CONTINUE].abort;
IF abort THEN RETURN;
ENDLOOP;
};
END.