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

Views and keystrokes

I've been attempting to implement my own key handlers for a new kind of
view with very little success.  These are not Fred windows or dialog
items so the limited documentation does not seem to apply.

I defined a window class and view class that is contained in within the
window.  The view (or one of it's subviews) is to handle key strokes in
a specialized manner.

I saw in the "windoids-key-events.lisp (MCL:examples)" file that you have
to define an (undocumented)

(defmethod accept-key-events ((self special-view)) t)

so that MCL knows your window wants key strokes.  The key-mixin documentation
is a bit confusing, but seems to apply only to fred-dialog-items.  The 
"add-key-handler" method seems to only deal with dialog items, not views in
general.  Any insights (so I can get on with this project) are VERY much appreciated!


;; A simple color window
(defclass special-window (window)  ; should this also inherit from key-handler-mixin?
    :color-p t))

;; A simple view
(defclass special-view (view) ; should this also inherit from key-handler-mixin?

;; Let MCL know we accept key strokes
(defmethod accept-key-events ((self special-view)) t)

;; define a method to beep when the user types a key
(defmethod view-key-event-handler ((self special-view) char)
  "just beep if the use types a key"

;; just to let us know our view exists
(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))
      (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))))))

;; NONE of this stuff seems to have any effect
(current-key-handler temp-wind) ; returns nil
(add-key-handler temp-view temp-wind) ; seems you can only add dialog items, not views
(change-key-handler temp-wind)
(key-handler-list temp-wind) ; returns nil
(defmethod key-handler-p ((self special-view)) t) ;