[racket] Focus
The `focus` method is supposed to work, but it looks like there's a
problem with the Cocoa-backed implementation, which confuses "should
the Tab key advance the focus to this window?" with "can this window
have the focus?".
If it happens that you want Tab to move the keyboard focus among the
canvases, then `(send c2 accept-tab-focus #t)` will work around the
problem. Otherwise, you'll need a repair that I push sometime soon.
At Sun, 11 Jan 2015 18:30:20 +0100, Jens Axel Søgaard wrote:
> How does one move the keyboard focus from one canvas to another?
>
> My attempts with (send a-canvas focus) were not successful.
>
> Below is a program with two canvases c1 and c2.
> For each key press they respectively print A and B followed
> by the key pressed. Initially c1 has focus.
>
> A (send c2 focus) does not move the focus.
>
> Welcome to DrRacket, version 6.1.1.6--2015-01-03(-/f) [3m].
> Language: racket; memory limit: 256 MB.
> A got focus!
> Aa Ab A got focus!
> > (send c2 focus)
> A got focus! (consequece of key press, not from send focus)
> Ax A got focus!
>
> This is on OS X.
>
> /Jens Axel
>
>
> #lang racket
> (require racket/gui)
>
> (define f (new frame% [label "Test"] [style '(fullscreen-button)]))
>
> (define (new-canvas name)
> (define named-canvas%
> (class canvas%
> ;; Buffer
> (define the-buffer #f)
> (define (set-buffer b) (set! the-buffer b))
> (define (get-buffer b) the-buffer)
> ;;; Focus Events
> (define/override (on-focus event)
> (displayln (~a name " got focus! ")))
> ;; Key Events
> (define/override (on-char event)
> (define k (send event get-key-code))
> (when (char? k)
> (display (~a name k " "))))
> (super-new)))
> (new named-canvas%
> [parent f]
> [min-width 100]
> [min-height 100]))
>
> (define c1 (new-canvas "A"))
> (define c2 (new-canvas "B"))
>
> (send f show #t)
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users