home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sun-barr!olivea!apple!cambridge.apple.com!bill@cambridge.apple.com
- From: bill@cambridge.apple.com (Bill St. Clair)
- Newsgroups: comp.lang.lisp.mcl
- Subject: Re: Views and keystrokes
- Message-ID: <9212302215.AA25714@cambridge.apple.com>
- Date: 30 Dec 92 22:15:59 GMT
- Sender: info-mcl-request@cambridge.apple.com
- Lines: 98
- Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
-
- At 10:10 AM 12/28/92 -0500, Jeffrey B Kane wrote:
- >I've been attempting to implement my own key handlers for a new kind of
- >view with very little success. These are not Fred windows or dialog
- >items so the limited documentation does not seem to apply.
- >
- >I defined a window class and view class that is contained in within the
- >window. The view (or one of it's subviews) is to handle key strokes in
- >a specialized manner.
- >
- >I saw in the "windoids-key-events.lisp (MCL:examples)" file that you have
- >to define an (undocumented)
- >
- >(defmethod accept-key-events ((self special-view)) t)
- >
- >so that MCL knows your window wants key strokes.
-
- The accept-key-events method is necessary only for windoids that
- want to handle key events. Normally, a windoid doesn't get a chance
- to handle key events; they are sent to (front-window).
-
- > The key-mixin documentation
- >is a bit confusing, but seems to apply only to fred-dialog-items. The
- >"add-key-handler" method seems to only deal with dialog items, not views in
- >general. Any insights (so I can get on with this project) are VERY much appreciated!
-
- The only problem is that you need to define a dialog-item-enabled-p
- method for your key handler class. This problem will be fixed by patch
- 2 for MCL (which is just about to enter its beta test period). Your view
- also needs to inherit from key-handler-mixin.
- Here's a version of your code that works for me:
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; A simple color window
- ;;
- (defclass special-window (window) ; should NOT inherit from key-handler-mixin
- (default-initarg
- :color-p t))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; A simple view
- ;;
- (defclass special-view (key-handler-mixin view)
- nil)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; This is necessary for key-handler-mixin.
- ;; patch 2 (which has not yet been released) will make this unnecessary.
- (defmethod dialog-item-enabled-p ((item special-view))
- t)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; define a method to beep when the user types a key
- ;;
- (defmethod view-key-event-handler ((self special-view) char)
- "just beep if the user types a key"
- (declare (ignore char))
- (ed-beep)
- (ed-beep))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; just to let us know our view exists
- ;;
- (require "QUICKDRAW")
-
- (defmethod view-draw-contents ((self special-view))
- ;frame and color the rect
- (rlet ((r :rect
- :topleft #@(0 0)
- :bottomright (view-size self)))
- (with-fore-color *yellow-color*
- (paint-rect self r))
- (with-pen-saved
- (set-pen-size self 2 2)
- (frame-rect self r)
- (move-to self (rref r :rect.topleft))
- (line-to self (rref r :rect.bottomright))
- (move-to self 0 (rref r :rect.right))
- (line-to self (rref r :rect.bottom) 0))))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; create the window and it's contained view
- ;;
- (defvar temp-wind nil)
- (defvar temp-view nil)
- (setf temp-wind
- (make-instance 'special-window
- :view-subviews
- (list (setf temp-view
- (make-instance 'special-view
- :view-position #@(40 40)
- :view-size #@(150 150))))))
-