home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-05 | 7.6 KB | 310 lines | [TEXT/MSET] |
- \ Event handling.
-
- \ Nov 90 - Bob Loewenstein's improvements incorporated.
- \ Apr 91 - AppleEvents recognized.
- \ May 91 - Suspend and Resume events now deactivate/activate any Mops window
- \ June 92- Added PAUSE to WaitClick loop so we don't freeze in background
- \ July 92- Modified mouse-evt to leave wnd alone on non-window clicks
- \ 21Apr94 DBH
- \ changed all event handlers so they do not return booleans
- \ changed key: method in class event
- \ redefined key-evt to contain all key related actions
-
-
-
- \ MultiFinder/System 7 suspend and resume events are recognized. To act on
- \ these events, set the vectors SuspendVec and ResumeVec to whatever words
- \ you want to execute.
-
-
- false value SUSPEND? \ True if we've just received a Suspend event
- false value RESUME? \ Ditto for Resume. These two flags are set
- \ appropriately by the OS event handler so other
- \ code can check if the event was Suspend or
- \ Resume, without having to re-perform the
- \ long-winded check.
-
- dicaddr MBADDR \ Forward reference the menu bar
-
- : DBLTICKS $ 2f0 @ ; \ Max ticks for double click
-
- variable THEDLG
- variable THEPOINT
-
- : G->L \ ( gy:gx -- ly:lx ) Converts a global point to a local point.
- thePoint !
- thePoint call GlobalToLocal
- thePoint @ ;
-
- : L->G \ ( ly:lx -- gy:gx )
- thePoint !
- thePoint call LocalToGlobal
- thePoint @ ;
-
- : (AEErr) \ ( err# -- ) Default for error returns from AppleEvent
- \ handlers -- see AEErrorVec below.
-
- fWind? if . 2 spaces then 161 die ;
-
- ' null vect NEXT_TASK \ If multitasking installed, this will be
- \ redirected to do a task switch.
-
- ' null vect SuspendVec \ Called for suspend and resume
- ' null vect ResumeVec \ events - redirect as necessary.
- ' null vect CvtClip \ Called for clip conversion
- ' null vect MouseMoved \ Called for mouse moved
-
- ' vfalse vect HLEventVEC \ Called for generic high-level events
- ' (AEerr) vect AEErrorVec \ Called when an AppleEvent handler returns
- \ an error
-
-
- :class EVENT super{ x-array }
-
- record
- { uint WHAT
- var MSG
- var TIME
- var LOC
- int MODS
- int MASK
- }
-
- :m TYPE: get: what ;m
- :m MODS: get: mods ;m
- :m SETMASK: put: mask ;m
- :m GETMASK: get: mask ;m
- :m MSG: get: msg ;m
-
- :m WHERE: \ ( -- mpoint ) Leaves mouse loc as global toolbox point
- get: loc ;m
-
- :m MSGCLASS: \ ( -- mclass ) Gets high-level message class.
- get: msg ;m
-
- :m MSGID: \ ( -- ID ) Gets high-level message ID.
- get: loc ;m
-
- :m WHEN: \ ( -- ticks ) Returns ticks.
- get: time ;m
-
- \ 21Apr94 DBH next: no longer returns a boolean
-
- :m NEXT: \ Gets the next event and executes its handler.
- ^base get: mask nextEvent
- IF get: what ELSE 0 THEN
- exec: super ;m
-
- \ :m KEY: \ ( -- c mods ) Handles events until a key event occurs.
- \ begin next: self until ;m
-
- :m KEY: \ ( -- c ) Handles events until a key event occurs. \ 08Jan94 XXX
- BEGIN
- \ ^base get: mask nextEvent drop
- next: self
- get: what konst keyDown =
- UNTIL
- msg: self $ FF and
- ;m
-
- ;class
-
-
- fEvent ' event set_class
-
- 30 ' fEvent w! \ Offset to indexed elts - *** KLUDGE!!
-
- :f whrFEv where: fEvent ;f
-
-
- \ Define the mouse as an object:
-
- :class MOUSE super{ object }
- record
- { var LAST \ ticks when last click occurred
- var INTERVAL \ ticks between clicks
- }
-
- :m PUT: \ ( ticks -- )
- \ Updates the click interval with current system Ticks value
- dup get: last - put: interval put: last ;m
-
- :m CLICK: \ ( -- type )
- \ Returns the type of click that last occurred: 2 = double
- get: interval dup 0> swap dblTicks < and
- IF 2 ELSE 1 THEN ;m
-
- :m WHERE: \ Returns the mouse position as local Mops point
- ?terminal drop where: fEvent g->l unpack ;m
-
- :m GET: \ ( -- x y dn? )
- \ Return the current state of the mouse
- \ - position and whether down
- where: self word0 call Button word0 ;m
-
- ;class
-
-
- mouse THEMOUSE
-
-
- : WINDOWKIND \ ( wnd-ptr -- n )
- $ 6C + w@ ;
-
-
- 0 value WND \ Addr of window we're looking at, or zero if none.
- \ We need to late-bind to it since the window object
- \ may be a sub-class.
-
- : APPWIND? \ ( -- b ) True if this is an application window.
- \ This check is necessary for non-multifinder systems
- \ while calling WaitNextEvent.
-
- wnd windowKind 8 = ;
-
-
- : STILLDOWN? \ Returns true if mouse button is still down.
- word0 call StillDown word0 ;
-
-
- : WAITCLICK \ Waits until a mouse click or key event
- BEGIN pause 10 ?event UNTIL ;
-
-
- : DESK ; \ Desktop click handler - does nothing
-
- : SYS \ ( wind -- ) System click handler
- addr: fEvent swap call SystemClick ;
-
- : NULL-EVT \ Note: now we're calling WaitNextEvent
- \ instead of GetNextEvent, we shouldn't call SystemTask.
- next_task
- actW ?dup IF idle: [] THEN ;
-
-
- : (MOUSE-EVT) \ ( rgn -- )
- SELECT{
- 0 is{ desk }end
- 1 is{ get: MBaddr click: [] }end
- 2 is{ wnd sys }end
- 3 is{ appWind? 0EXIT content: [ wnd ] }end
- 4 is{ appWind? 0EXIT drag: [ wnd ] }end
- 5 is{ appWind? 0EXIT grow: [ wnd ] }end
- 6 is{ word0 wnd where: fevent
- call trackGoAway word0
- IF close: [ wnd ] THEN }end
- 7 is{ 7 zoom: [ wnd ] }end
- 8 is{ 8 zoom: [ wnd ] }end
- default{ abort
- }SELECT ;
-
-
- : MOUSE-EVT
- when: fEvent put: theMouse \ update click interval
- where: fEvent find-window -> wnd
- (mouse-evt) ;
-
-
- : KEY-EVT
-
- mods: fEvent $ 100 and \ command key?
- IF \ Yes - check for menu selection
- msg: fEvent get: MBaddr key: []
- EXIT
- THEN
- 0 call frontWindow -> wnd appWind?
- NIF EXIT THEN \ Out if not our window.
- actW
- IF \ Our window, so we send it a KEY: message:
- msg: fEvent $ FF and
- key: [ actw ]
- THEN ;
-
-
- : DISK-EVT \ Handles a disk insert event.
- watchcurs
- msg: fEvent 0<
- IF
- call DILoad
- word0 SFloc msg: fEvent call DIBadMount word0 drop
- call DIUnload
- THEN
- arrowcurs ;
-
-
- : UPD-EVT \ Causes window draw.
- msg: fEvent -> wnd
- appWind? IF draw: [ wnd ] THEN ;
-
-
- : ACTV-EVT \ Activates a window.
- msg: fEvent -> wnd
- appWind?
- IF mods: fEvent 01 and
- IF wnd -> actW enable: [ wnd ]
- ELSE 0 -> actW disable: [ wnd ]
- THEN
- THEN ;
-
-
- : OS-EVT { \ hiByte -- } \ Operating system events.
- false -> suspend? false -> resume?
- msg: fEvent 24 >> -> hiByte
- msg: fEvent 2 and if cvtClip then
- hiByte $ FA and if mouseMoved then
- hiByte 1 =
- IF \ Suspend or Resume event
- msg: fEvent 1 and
- IF \ Resume
- saveActW -> actW
- actW IF enable: [ actW ] THEN
- true -> resume? resumeVec
- ELSE \ Suspend
- word0 call HiliteMenu
- actW -> saveActW
- actW IF disable: [ actW ] 0 -> actW THEN
- true -> suspend? suspendVec
- THEN
- THEN ;
-
-
- : HL-EVT \ High-level events.
- HLeventVec \ Maybe handle as generic HL event. Done?
- IF EXIT THEN \ Out if yes. Otherwise...
- \ ... (drum roll please) ...
-
- \ It's an AppleEvent!! Now let's not panic, but just take
- \ this step by step...
-
- word0 fEvent call AEProcessAppleEvent i->l
-
- \ Several things may have happened in the AppleEvent handler,
- \ which we couldn't fully handle there. We look for them in
- \ priority order. First, we quit the application if requested,
- \ without worrying about error indications.
-
- quitApp? IF quitAppVec false -> quitApp? THEN
-
- \ Now we take a Mops error if one was signalled by the handler.
- \ We can't do this inside the handler since it's a :PROC.
- \ Penalty: CRASH!
-
- (err#) ?dup IF die THEN
-
- \ Finally, if a system error code was returned from the
- \ handler, we execute AEErrorVec to do whatever is necessary.
-
- ?dup IF AEErrorVec THEN
-
- \ If we somehow got through to here, everything is OK!!
- ;
-
-
- \ Here we set the default for KEY.
-
- : (KEY) \ ( -- c )
- key: fEvent
- ;
-
- : (KEY!) ['] (key) -> key ;
-