From 3dcb02a3fce3f17765a567e4d74a5be73775a993 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 31 Aug 2014 03:56:49 -0600 Subject: [PATCH] racket/gui win32: fix Space handling of buttons and checkboxes Suppress WM_KEYDOWN messages to a button or checkbox, so that the top-level window takes care of Space and Return for a button or checkbox with the keyboard focus. Closes PR 14710 original commit: 032397d6f9694d4c3dff24e3511d51657d19cf15 --- .../gui-lib/mred/private/wx/win32/button.rkt | 7 +++++++ .../gui-lib/mred/private/wx/win32/window.rkt | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/win32/button.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/win32/button.rkt index 64334054..dc753eee 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/win32/button.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/win32/button.rkt @@ -154,6 +154,13 @@ xp-label-font)))) (super set-label s))) + ;; Avoid passing any key event to a button or checkbox. The + ;; `pre-on-char` of the frame will take care of changing space to + ;; a control action, but the control itself may use WM_KEYDOWN + ;; instead of WM_CHAR. + (define/override (capture-all-key-events?) + #t) + (define/override (is-command? cmd) (= cmd BN_CLICKED)) diff --git a/pkgs/gui-pkgs/gui-lib/mred/private/wx/win32/window.rkt b/pkgs/gui-pkgs/gui-lib/mred/private/wx/win32/window.rkt index 2d007957..5326afe5 100644 --- a/pkgs/gui-pkgs/gui-lib/mred/private/wx/win32/window.rkt +++ b/pkgs/gui-pkgs/gui-lib/mred/private/wx/win32/window.rkt @@ -549,14 +549,15 @@ (define/private (do-key w msg wParam lParam is-char? is-up? default) (let ([e (maybe-make-key-event #f wParam lParam is-char? is-up? hwnd)]) - (if (and e - (if (definitely-wants-event? w msg wParam e) - (begin - (queue-window-event this (lambda () (dispatch-on-char/sync e))) - #t) - (constrained-reply eventspace - (lambda () (dispatch-on-char e #t)) - #t))) + (if (or (and e + (if (definitely-wants-event? w msg wParam e) + (begin + (queue-window-event this (lambda () (dispatch-on-char/sync e))) + #t) + (constrained-reply eventspace + (lambda () (dispatch-on-char e #t)) + #t))) + (capture-all-key-events?)) 0 (default w msg wParam lParam)))) @@ -740,6 +741,8 @@ (define/public (definitely-wants-event? w msg wParam e) #f) + (define/public (capture-all-key-events?) + #f) (define/public (dispatch-on-char/sync e) (pre-event-refresh #t)