ViewerEventsImpl.mesa;
Edited by McGregor on August 2, 1982 11:44 am
Last Edited by: Maxwell, January 11, 1983 12:27 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 ANY ← NIL, before: BOOL ← TRUE]
RETURNS [EventRegistration] = BEGIN
RETURN [eventProcs[event] ← CONS[[proc, filter, before], eventProcs[event]]];
END;
UnRegisterEventProc:
PUBLIC
PROC [proc: EventRegistration, event: ViewerEvent] =
BEGIN
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;
END;
ProcessEvent:
PUBLIC
PROC [event: ViewerEvent, viewer: ViewerClasses.Viewer, before:
BOOL]
RETURNS[abort: BOOL ← FALSE] = BEGIN
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 THEN LOOP;
abort ← l.first.proc[viewer, event, before ! ABORTED => CONTINUE].abort;
IF abort THEN RETURN;
ENDLOOP;
END;
END.