[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Views and keystrokes



> The only problem is that you need to define a dialog-item-enabled-p
> method for your key handler class

Bill,
  Thanks for the clue.  I saw the error message complaining that no 
"dialog-item-enabled-p" was defined for my view class, but I assumed
that I was on the wrong track, since I wasn't trying to define a 
dialog item.  One last question.  After implementing the patch I get
most key strokes, but I can only get access to a #\Tab key if I hold
down the shift-tab combination.  Is this because the window now thinks
that the view is a dialog item?  Below is the code that prints out
any keys that it gets:

;;
;; A simple color window
;;
(defclass special-window (window)  ; should NOT inherit from key-handler-mixin
  (default-initarg
    :color-p t))

;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; A simple view
;;
(defclass special-view (key-handler-mixin view)
  nil)

;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This is necessary for key-handler-mixin.
;; patch 2 (which has not yet been released) will make this unnecessary.
(defmethod dialog-item-enabled-p ((item special-view))
  t)

;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; ** define a method to let us know what key is being pressed
;;
(defmethod view-key-event-handler ((self special-view) char)
  "just beep if the user types a key"
  (format t "~S" char)
  (case char
    (#\ForwardArrow (set-view-position self (add-points (view-position self) 
                                                        #@(10 0))))
    (#\BackArrow (set-view-position self (subtract-points (view-position self) 
                                                          #@(10 0))))
    (#\UpArrow (set-view-position self (subtract-points (view-position self) 
                                                        #@(0 10))))
    (#\DownArrow (set-view-position self (add-points (view-position self) 
                                                     #@(0 10))))

    (otherwise char))  ; ?prints char in the listener, even though we haven't called (call-next-method)?
  (values))
;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; just to let us know our view exists
;;
(require "QUICKDRAW")

(defmethod view-draw-contents ((self special-view))
  ;frame and color the rect
  (rlet ((r :rect
            :topleft #@(0 0)
            :bottomright (view-size self)))
    (with-fore-color *yellow-color*
      (paint-rect self r))
    (with-pen-saved 
      (set-pen-size self 2 2)
      (frame-rect self r)
      (move-to self (rref r :rect.topleft))
      (line-to self (rref r :rect.bottomright))
      (move-to self 0 (rref r :rect.right))
      (line-to self (rref r :rect.bottom) 0))))


;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; create the window and it's contained view
;;
(defvar temp-wind nil)
(defvar temp-view nil)
(setf temp-wind
      (make-instance 'special-window
        :view-subviews
        (list (setf temp-view
                    (make-instance 'special-view
                      :view-position #@(40 40)
                      :view-size #@(150 150))))))

    Jeffrey


======================================
Jeffrey Kane, MD
Kane Biomedical Systems
Boston, MA

Internet    jbk@world.std.com
Compuserve  74206,640
AppleLink   D0738

[Don't take life too seriously... it's not like anyone gets out of it alive.]