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

View-Key-Event-Handler



I'm having trouble fully understanding VIEW-KEY-EVENT-HANDLER.  I gather from
the manual that a window has a list of handlers, and one of them is current.
Furthermore, pressing TAB switches among handlers.  This is great for editable
dialog items, but what if one of my subviews isn't an editable dialog item, yet
I want it to get keystrokes?  For example:

(REQUIRE :QuickDraw)

(DEFCLASS MyWindow (WINDOW)
  ()
  (:DEFAULT-INITARGS
    :VIEW-POSITION #@(100 100)
    :VIEW-SIZE #@(280 100)
   ))

(DEFCLASS MyView (DIALOG-ITEM)
  ()
  (:DEFAULT-INITARGS
    :VIEW-POSITION #@(10 10)
    :VIEW-SIZE #@(50 50)
   ))

(DEFMETHOD View-Draw-Contents ((view MyView))
  (FRAME-RECT view 0 0 40 40))

(DEFMETHOD View-Key-Event-Handler ((window MyWindow) key)
  (FORMAT T "~%MyWindow got a key: ~S" key)
  (CALL-NEXT-METHOD))

(DEFMETHOD View-Key-Event-Handler ((view MyView) key)
  (FORMAT T "~%MyView got a key: ~S" key))

(SETF w (MAKE-INSTANCE 'MyWindow))
(SETF v (MAKE-INSTANCE 'MyView :VIEW-CONTAINER w))

This creates a window on the screen with a square view that frames itself.  How
do I get the view to get keystrokes?  How can I make it a key handler?  How do
I add it to the list of key handlers for the window?

I discovered the following way, but it doesn't satisfy my wish to understand
how this mechanism works.

(DEFMETHOD View-Key-Event-Handler ((window MyWindow) key)
  (DO-SUBVIEWS (sv window)
    (VIEW-KEY-EVENT-HANDLER sv key)))

This lets my window pass keystrokes on to all subviews so that they all get a
crack at handling them.  The View-Key-Event-Handler for MyWindow can even call
the key handler for only a certian subview based upon MyWindow's knowledge of
what it is doing and what the subviews are, but I sure would like to understand
the entire mechanism better.  Is the documentation weak in this area?  Am I
just looking in the wrong place?  Or am I just dense?  Any help appreciated.

Thanks.
Danny Brewer
danny@farallon.com