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

  1. Path: sparky!uunet!munnari.oz.au!spool.mu.edu!olivea!apple!cambridge.apple.com!jbk@world.std.com
  2. From: jbk@world.std.com (Jeffrey B Kane)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Views and keystrokes
  5. Message-ID: <199212281510.AA16681@world.std.com>
  6. Date: 28 Dec 92 15:10:44 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 90
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11.  
  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.  The key-mixin documentation
  26. is a bit confusing, but seems to apply only to fred-dialog-items.  The 
  27. "add-key-handler" method seems to only deal with dialog items, not views in
  28. general.  Any insights (so I can get on with this project) are VERY much appreciated!
  29.  
  30.      Jeffrey
  31.  
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. ;;
  34. ;; A simple color window
  35. ;;
  36. (defclass special-window (window)  ; should this also inherit from key-handler-mixin?
  37.   (default-initarg
  38.     :color-p t))
  39.  
  40. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  41. ;;
  42. ;; A simple view
  43. ;;
  44. (defclass special-view (view) ; should this also inherit from key-handler-mixin?
  45.   nil)
  46.  
  47. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  48. ;;
  49. ;; Let MCL know we accept key strokes
  50. ;;
  51. (defmethod accept-key-events ((self special-view)) t)
  52.  
  53. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  54. ;;
  55. ;; define a method to beep when the user types a key
  56. ;;
  57. (defmethod view-key-event-handler ((self special-view) char)
  58.   "just beep if the use types a key"
  59.   (ed-beep)
  60.   (ed-beep))
  61.  
  62. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  63. ;;
  64. ;; just to let us know our view exists
  65. ;;
  66. (defmethod view-draw-contents ((self special-view))
  67.   ;frame and color the rect
  68.   (rlet ((r :rect
  69.             :topleft #@(0 0)
  70.             :bottomright (view-size self)))
  71.     (with-fore-color *yellow-color*
  72.       (paint-rect self r))
  73.     (with-pen-saved 
  74.       (set-pen-size self 2 2)
  75.       (frame-rect self r)
  76.       (move-to self (rref r :rect.topleft))
  77.       (line-to self (rref r :rect.bottomright))
  78.       (move-to self 0 (rref r :rect.right))
  79.       (line-to self (rref r :rect.bottom) 0))))
  80.  
  81.  
  82. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  83. ;;
  84. ;; create the window and it's contained view
  85. ;;
  86. (defvar temp-wind nil)
  87. (defvar temp-view nil)
  88. (setf temp-wind (make-instance 'special-window
  89.                   :view-subviews (list (setf temp-view (make-instance 'special-view
  90.                                                          :view-position #@(40 40)
  91.                                                          :view-size #@(150 150))))))
  92.  
  93.  
  94. ;;
  95. ;; NONE of this stuff seems to have any effect
  96. (current-key-handler temp-wind) ; returns nil
  97. (add-key-handler temp-view temp-wind) ; seems you can only add dialog items, not views
  98. (change-key-handler temp-wind)
  99. (key-handler-list temp-wind) ; returns nil
  100. (defmethod key-handler-p ((self special-view)) t) ; 
  101.