3.4.3 Active regions

3.4.3.2 Multitasking and active region methods

Input in the Window Tool Kit is implemented using the Multitasking Facility of Liquid Common Lisp. In multitasking, the Lisp environment is divided into multiple processes that run independently of each other; each process maintains separate state information.

When you are using active region methods, there are two processes of interest:

Active region methods are run with scheduling inhibited. If you want to allow scheduling during an active region method, use the macrowith-scheduling-allowed with care. This macro is described in Chapter 5, "The Multitasking Facility" in The Advanced Users Guide.

Any function that you specify in make-active-region is run in the window input process, not in your process. This arrangement produces certain constraints on your function, such as those that are listed below.

To avoid these problems, you must create another process that does the work that was intended for the active region method, as the following example shows:

;;; Create a window with an active region. Any click in the active
;;; region displays a pop-up menu that allows you to set or clear
;;; all the bits in the window's bitmap.

(setq *window* (make-window :width 100 :height 100)) (defun choose-window-color-from-menu () (let* ((menu (make-pop-up-menu (list (cons "Clear all bits" :clear) (cons "Set all bits" :set)))) (item (pop-up-menu-choose menu))) (if (eq item :clear) (draw-rectangle *window* 0 0 :width 200 :height 200 :operation boole-clr) (when (eq item :set) (draw-rectangle *window* 0 0 :width 200 :height 200 :operation boole-set)))))

(defun handle-mouse-click (viewport region char x y) "handle mouse click in window" (make-process :name "Choose Color" :stack-size #x2000 :function 'choose-window-color-from-menu :args nil :restart-action :restart))

(make-active-region (make-region :width 200 :height 200) :bitmap *window* :mouse-click \#'handle-mouse-click)

There are two other ways in which multitasking can affect you: the behavior of streams in the Debugger and the behavior of the Common Lispthrow special form. For information about these behaviors, see Chapter 5, "The Multitasking Facility" in the The Advanced User's Guide.


The Window Tool Kit - 9 SEP 1996

Generated with Harlequin WebMaker