[plt-scheme] on-event on snips seems a little weird

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Thu Jun 19 01:55:30 EDT 2008

I'm trying to get a snip to do something when I hover my mouse over
it; I suspect I need to have the snip somehow have keyboard focus.  Is
there a way to get a snip to get events even if it doesn't have
keyboard focus?

I cooked up a simple example that shows an editor-snip with "hi" in
it.  I'd like to see my on-event handler fire off when I hover into
and out of the editor snip.  What trick am I missing?



#lang scheme/gui

(define my-editor-snip%
  (class editor-snip%
    (define/override (on-event dc x y editorx editory event)
      (printf "I see an event~n")
      (match (send event get-event-type)
         (printf "I see enter~n")]
         (printf "I see leave~n")]
      (super on-event dc x y editorx editory event))

    (inherit set-flags get-flags)
    (set-flags (cons 'handles-events (get-flags)))))

(define f (new frame% [label ""]))
(define e (new text%))
(define c (new editor-canvas% [parent f] [editor e]))

(define snip (make-object my-editor-snip%))
(send (send snip get-editor)
      insert "hi")

(send e insert snip)

(send f show #t)

Posted on the users mailing list.