home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / lisp / mcl / 1955 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  2.4 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!wupost!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: update events from tight loops?
  5. Message-ID: <9301082130.AA29029@cambridge.apple.com>
  6. Date: 8 Jan 93 22:36:33 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 58
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. >Hiya,
  12. >
  13. >I am creating a view item that increments or decrements a number when a
  14. >button is clicked. I would like the button (inc and dec) to behave such
  15. >that a click inc/decs by one, and holding the button continuously inc/decs
  16. >(at some rate).
  17. >
  18. >I can get the behaviour, but the view does not update. The key part is the
  19. >looping structure below:
  20. >
  21. >(defmethod view-click-event-handler ((self increment-button) where)
  22. >  (declare (ignore where))
  23. >  (let ((to-view (if (message-view self)
  24. >                   (message-view self)
  25. >                   (view-container self))))
  26. >    (when to-view
  27. >      (increment to-view)
  28. >      (let ((start (rref *current-event* :EventRecord.when)))
  29. >        ;; key bit
  30. >        (loop
  31. >          (unless (mouse-down-p)
  32. >            (return))
  33. >          (when (= (mod (- (#_TickCount) start) 20))
  34. >            (increment to-view)
  35. >            (WHAT GOES HERE????)))))))))
  36. >
  37. >The WHAT GOES HERE? is where I need something that will cause LISP to allow
  38. >invalidated views to update themselves.
  39.  
  40. The easiest thing is:
  41.  
  42. (window-update-event-handler (view-window to-view))
  43.  
  44. You should NOT call WINDOW-UPDATE-EVENT-HANDLER from anywhere but
  45. something that is called by EVENT-DISPATCH, however. Inside of
  46. VIEW-CLICK-EVENT-HANDLER is fine.
  47.  
  48. Another, slightly more Kosher way of doing this is to define a macro:
  49.  
  50. (defmacro with-event-processing-enabled (&body body)
  51.   `(let ((ccl::*interrupt-level* 0)
  52.          (ccl::*processing-events* nil))
  53.      ,@body))
  54.  
  55. Then in place of (WHAT GOES HERE????) you can say:
  56.  
  57. (with-event-processing-enabled
  58.   (event-dispatch))
  59.  
  60. Make sure to do it with the macro or your code will cease to compile
  61. correctly when MCL 2.1 is released. MCL 2.1 will have a different
  62. implementation of WITH-EVENT-PROCESSING-ENABLED that will be
  63. functionally equivalent.
  64.  
  65. Since you know which view needs to be redrawn, a third way to do
  66. your updating is to do the drawing yourself:
  67.  
  68. (view-focus-and-draw-contents to-view)
  69.