home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / lisp / mcl / 1619 < prev    next >
Encoding:
Text File  |  1992-11-18  |  2.4 KB  |  69 lines

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!data.nas.nasa.gov!taligent!apple!cambridge.apple.com!bill@cambridge.apple.com
  2. From: bill@cambridge.apple.com (Bill St. Clair)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: basic view-key-event-handler confusion
  5. Message-ID: <9211181700.AA10037@cambridge.apple.com>
  6. Date: 18 Nov 92 18:03:59 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 58
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. >Please help.
  12. >
  13. >There is something *very basic* that I don't understand about 
  14. >view-key-event-handlers, despite having read and re-read
  15. >the docs and sample code a hundred times.  Here is a simple 
  16. >example that fails to handle key events -- all keystrokes go 
  17. >to the listener:
  18. >
  19. >(defclass simple-key-handling-view (dialog-item)
  20. >  ()
  21. >  )
  22. >
  23. >;;; When you get a keystroke, draw that character.
  24. >;;;  ***BUT NOTHING HAPPENS
  25. >
  26. >(defmethod view-key-event-handler ((item simple-key-handling-view)
  27. >char)
  28. >  "Just print the character in the view."
  29. >  (when (integerp char) (setq char (code-char char)))  ; (why?)
  30. >  (move-to item 20 20)
  31. >  (format item "~c" char))
  32. >
  33. >(setq *w* (make-instance 'window))
  34. >(setq *v* (make-instance 'simple-key-handling-view
  35. >            :view-position #@(4 4)
  36. >            :view-size #@(200 200)))
  37. >
  38. >(add-subviews *w* *v*)
  39. >
  40. >;;; (key-handler-p *v*)  --> NIL
  41. >
  42. >
  43. >Please don't tell me to use an instance of some text dialog
  44. >item; I want to do something very special with the keystrokes,
  45. >and anyway there must be a simpler way...
  46. >
  47. >Many, many thanks for your kind attention.
  48.  
  49. The problem is that the window is not passing the VIEW-KEY-EVENT-HANDLER
  50. call on to your dialog item. If you mix in the KEY-HANDLER-MIXIN class, this
  51. will be done for you. It also makes KEY-HANDLER-P return true.
  52.  
  53. (defclass simple-key-handling-view (key-handler-mixin dialog-item)
  54.   ()
  55.   )
  56.  
  57. It looks a little better if you erase before drawing. Also, the CHAR arg
  58. to view-key-event-handler is a character. No need to coerce it from an
  59. integer:
  60.  
  61. (defmethod view-key-event-handler ((item simple-key-handling-view) char)
  62.   "Just print the character in the view."
  63. ;  (when (integerp char) (setq char (code-char char)))  ; (why?)
  64.   (with-focused-view (view-container item)
  65.     (rlet ((rect :rect :topleft #@(0 0) :botright #@(100 100)))
  66.       (#_EraseRect rect)))
  67.   (move-to item 20 20)
  68.   (format item "~c" char))
  69.