home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / lisp / mcl / 1917 < prev    next >
Encoding:
Text File  |  1992-12-30  |  3.4 KB  |  109 lines

  1. Path: sparky!uunet!cs.utexas.edu!sun-barr!olivea!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: Views and keystrokes
  5. Message-ID: <9212302215.AA25714@cambridge.apple.com>
  6. Date: 30 Dec 92 22:15:59 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 98
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. At 10:10 AM 12/28/92 -0500, Jeffrey B Kane wrote:
  12. >I've been attempting to implement my own key handlers for a new kind of
  13. >view with very little success.  These are not Fred windows or dialog
  14. >items so the limited documentation does not seem to apply.
  15. >
  16. >I defined a window class and view class that is contained in within the
  17. >window.  The view (or one of it's subviews) is to handle key strokes in
  18. >a specialized manner.
  19. >
  20. >I saw in the "windoids-key-events.lisp (MCL:examples)" file that you have
  21. >to define an (undocumented)
  22. >
  23. >(defmethod accept-key-events ((self special-view)) t)
  24. >
  25. >so that MCL knows your window wants key strokes.  
  26.  
  27. The accept-key-events method is necessary only for windoids that
  28. want to handle key events. Normally, a windoid doesn't get a chance
  29. to handle key events; they are sent to (front-window).
  30.  
  31. > The key-mixin documentation
  32. >is a bit confusing, but seems to apply only to fred-dialog-items.  The 
  33. >"add-key-handler" method seems to only deal with dialog items, not views in
  34. >general.  Any insights (so I can get on with this project) are VERY much appreciated!
  35.  
  36. The only problem is that you need to define a dialog-item-enabled-p
  37. method for your key handler class. This problem will be fixed by patch
  38. 2 for MCL (which is just about to enter its beta test period). Your view
  39. also needs to inherit from key-handler-mixin.
  40. Here's a version of your code that works for me:
  41.  
  42. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  43. ;;
  44. ;; A simple color window
  45. ;;
  46. (defclass special-window (window)  ; should NOT inherit from key-handler-mixin
  47.   (default-initarg
  48.     :color-p t))
  49.  
  50. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  51. ;;
  52. ;; A simple view
  53. ;;
  54. (defclass special-view (key-handler-mixin view)
  55.   nil)
  56.  
  57. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  58. ;;
  59. ;; This is necessary for key-handler-mixin.
  60. ;; patch 2 (which has not yet been released) will make this unnecessary.
  61. (defmethod dialog-item-enabled-p ((item special-view))
  62.   t)
  63.  
  64. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  65. ;;
  66. ;; define a method to beep when the user types a key
  67. ;;
  68. (defmethod view-key-event-handler ((self special-view) char)
  69.   "just beep if the user types a key"
  70.   (declare (ignore char))
  71.   (ed-beep)
  72.   (ed-beep))
  73.  
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  75. ;;
  76. ;; just to let us know our view exists
  77. ;;
  78. (require "QUICKDRAW")
  79.  
  80. (defmethod view-draw-contents ((self special-view))
  81.   ;frame and color the rect
  82.   (rlet ((r :rect
  83.             :topleft #@(0 0)
  84.             :bottomright (view-size self)))
  85.     (with-fore-color *yellow-color*
  86.       (paint-rect self r))
  87.     (with-pen-saved 
  88.       (set-pen-size self 2 2)
  89.       (frame-rect self r)
  90.       (move-to self (rref r :rect.topleft))
  91.       (line-to self (rref r :rect.bottomright))
  92.       (move-to self 0 (rref r :rect.right))
  93.       (line-to self (rref r :rect.bottom) 0))))
  94.  
  95.  
  96. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  97. ;;
  98. ;; create the window and it's contained view
  99. ;;
  100. (defvar temp-wind nil)
  101. (defvar temp-view nil)
  102. (setf temp-wind
  103.       (make-instance 'special-window
  104.         :view-subviews
  105.         (list (setf temp-view
  106.                     (make-instance 'special-view
  107.                       :view-position #@(40 40)
  108.                       :view-size #@(150 150))))))
  109.