3.4.3 Active regions Preempting mouse methods

The macro with-mouse-methods-preempted allows you to specify which active regions are disabled while the argument forms are executed, as follows:

The macro with-mouse-methods-preempted-globally disables all active regions except the specified active region and expands the active area of the region to include the entire screen. Hence, a mouse event in any area of the root viewport is treated as though it happened in the specified region.

When the argument forms to either of these macros have executed, all active regions return to the state they were in before the macro invocation.

In this example, a mouse click in the given window displays a pop-up menu. An active region method in the given window triggers the display of the pop-up menu. Since displaying the pop-up window requires mouse input inside the given window's input process, you must display the pop-up menu in a separate process.

To prevent active region methods from other windows from triggering when you click the mouse in the first window, you must preempt other mouse methods for the given window.

(defun menu-demo (window)
  (let ((x 10) (y 30) (font *default-font*) (string "click here")
        (popup-menu (make-pop-up-menu '(choice1 choice2))))

;; Execute only this window's active region methods. (with-mouse-methods-preempted window (stringblt window (make-position x (1- y)) font string) (let ((region (make-region :x x :y (- y (font-height font)) :width (string-width string font) :height (font-height font))))

;; Make the active region around the string. (make-active-region region :bitmap window :mouse-documentation "Right: pop up menu" :mouse-enter-region ; Outline the string. #'(lambda (viewport region event x y) (declare (ignore event x y)) (draw-region-rect region viewport)) :mouse-exit-region ; Remove outline. #'(lambda (viewport region event x y) (declare (ignore event x y)) (draw-region-rect region viewport)) :mouse-click ; Pop up menu. #'(lambda (viewport region event x y) (declare (ignore event)) (make-process ; Must start a new process here. :name "popup menu process" :function #'(lambda () (print (pop-up-menu-choose popup-menu))))))))))

;; Invoke the function. (menu-demo *window*)

The Window Tool Kit - 9 SEP 1996

Generated with Harlequin WebMaker