diff --git a/collects/mred/private/mrwindow.rkt b/collects/mred/private/mrwindow.rkt index 317b6bdd..d5d0c8c8 100644 --- a/collects/mred/private/mrwindow.rkt +++ b/collects/mred/private/mrwindow.rkt @@ -145,6 +145,7 @@ (send m on-demand) (send wx popup-menu mwx x y)))))))] [on-focus (lambda (x) (void))] + [on-subwindow-focus (lambda (win active?) (void))] [on-size (lambda (w h) (check-range-integer '(method window<%> on-size) w) (check-range-integer '(method window<%> on-size) h))] diff --git a/collects/mred/private/wxwindow.rkt b/collects/mred/private/wxwindow.rkt index b9e08623..10474533 100644 --- a/collects/mred/private/wxwindow.rkt +++ b/collects/mred/private/wxwindow.rkt @@ -143,7 +143,7 @@ (define (make-window-glue% %) ; implies make-glue% (class100 (make-glue% %) (mred proxy . args) - (inherit get-x get-y get-width get-height area-parent get-mred get-proxy skip-subwindow-events?) + (inherit get-x get-y get-width get-height area-parent get-mred get-proxy skip-subwindow-events? get-parent) (private-field [pre-wx->proxy (lambda (orig-w e k) ;; MacOS: w may not be something the user knows @@ -214,10 +214,16 @@ (as-exit (lambda () (send mred on-move x y)))))))))))] [on-set-focus (lambda () (super on-set-focus) - (when expose-focus? (send (get-proxy) on-focus #t)))] + (when expose-focus? + (let ([p (get-proxy)]) + (send p on-focus #t) + (on-subwindow-focus p #t))))] [on-kill-focus (lambda () (super on-kill-focus) - (when expose-focus? (send (get-proxy) on-focus #f)))] + (when expose-focus? + (let ([p (get-proxy)]) + (send p on-focus #f) + (on-subwindow-focus p #f))))] [pre-on-char (lambda (w e) (or (super pre-on-char w e) (if (skip-subwindow-events?) @@ -236,4 +242,11 @@ (lambda (m e) (as-exit (lambda () (send (get-proxy) on-subwindow-event m e))))))))]) + (public + [on-subwindow-focus (lambda (win on?) + (unless (or (is-a? this wx:frame%) + (is-a? this wx:dialog%)) + (send (get-parent) on-subwindow-focus win on?)) + (unless (skip-subwindow-events?) + (send (get-proxy) on-subwindow-focus win on?)))]) (sequence (apply super-init mred proxy args))))) diff --git a/collects/scribblings/gui/window-intf.scrbl b/collects/scribblings/gui/window-intf.scrbl index 6ad1f6e5..e475c3d4 100644 --- a/collects/scribblings/gui/window-intf.scrbl +++ b/collects/scribblings/gui/window-intf.scrbl @@ -338,10 +338,9 @@ Called when the window is moved. (For windows that are not top-level Does nothing. - - }} + @defmethod[(on-size [width (integer-in 0 10000)] [height (integer-in 0 10000)]) void?]{ @@ -356,8 +355,6 @@ Called when the window is resized. The window's new size (in pixels) Does nothing. - - }} @defmethod[(on-subwindow-char [receiver (is-a?/c window<%>)] @@ -428,6 +425,20 @@ Returns @racket[#f]. }} + +@defmethod[(on-subwindow-focus [receiver (is-a?/c window<%>)] + [on? boolean?]) + void?]{ + +Called when this window or a child window receives or loses the keyboard focus. + This method is called after the @method[window<%> on-focus] method of @racket[receiver]. + The +@method[window<%> on-subwindow-focus] method of the receiver's top-level window is called first (see +@method[area<%> get-top-level-window]), then the +@method[window<%> on-subwindow-focus] method is called for the next child in the path to the receiver, and + so on.} + + @defmethod[(on-superwindow-enable [enabled? any/c]) void?]{ diff --git a/collects/tests/gracket/item.rkt b/collects/tests/gracket/item.rkt index 83c08ac4..2cf0f516 100644 --- a/collects/tests/gracket/item.rkt +++ b/collects/tests/gracket/item.rkt @@ -323,6 +323,8 @@ [on-subwindow-char (lambda args (or (apply pre-on args) (super on-subwindow-char . args)))] + [on-subwindow-focus (lambda (win on?) + (printf "focus ~s ~s\n" (send win get-label) on?))] [on-activate (lambda (on?) (printf "active: ~a\n" on?))] [on-move (lambda (x y) (printf "moved: ~a ~a\n" x y))] [on-size (lambda (x y) (printf "sized: ~a ~a\n" x y))])