From 8a01942f1a14533de5bba3e56d6128e6223e6dba Mon Sep 17 00:00:00 2001 From: Ivan Sorokin Date: Tue, 25 Apr 2023 03:01:56 +0300 Subject: [PATCH] Add WXK_NUMPAD_CENTER to refer to numpad "5" in portable code This key produces events with different key codes in wxMSW (WXK_CLEAR) and the other ports (WXK_NUMPAD_BEGIN), so add a new constant to allow to refer to it under the same name everywhere. Also generate a key event for it in wxOSX where it previously wasn't generated at all. Closes #23478. Closes #23491. --- include/wx/defs.h | 10 +++++++++- interface/wx/defs.h | 16 +++++++++++++++- samples/keyboard/keyboard.cpp | 3 +-- src/gtk/window.cpp | 2 +- src/osx/cocoa/window.mm | 6 +++--- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index f78d5e3ba2..8612b22274 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -2363,7 +2363,15 @@ enum wxKeyCode // These constants are the same as the corresponding GTK keys, so give them // the same value, but they are also generated by wxMSW. WXK_LAUNCH_APP1 = WXK_LAUNCH_A, - WXK_LAUNCH_APP2 = WXK_LAUNCH_B + WXK_LAUNCH_APP2 = WXK_LAUNCH_B, + + // This one provides a portable way to refer to the key event generated by + // the "5" key on the numpad when Num Lock is off. +#ifdef __WXMSW__ + WXK_NUMPAD_CENTER = WXK_CLEAR +#else + WXK_NUMPAD_CENTER = WXK_NUMPAD_BEGIN +#endif }; /* This enum contains bit mask constants used in wxKeyEvent */ diff --git a/interface/wx/defs.h b/interface/wx/defs.h index e745d34c87..2e16245f3e 100644 --- a/interface/wx/defs.h +++ b/interface/wx/defs.h @@ -924,6 +924,7 @@ enum wxKeyCode WXK_RBUTTON, WXK_CANCEL, WXK_MBUTTON, + /// See WXK_NUMPAD_CENTER. WXK_CLEAR, WXK_SHIFT, WXK_ALT, @@ -1015,6 +1016,7 @@ enum wxKeyCode WXK_NUMPAD_PAGEUP, WXK_NUMPAD_PAGEDOWN, WXK_NUMPAD_END, + /// See WXK_NUMPAD_CENTER. WXK_NUMPAD_BEGIN, WXK_NUMPAD_INSERT, WXK_NUMPAD_DELETE, @@ -1107,7 +1109,19 @@ enum wxKeyCode WXK_LAUNCH_C, ///< Available since wxWidgets 3.1.6 and only generated by wxGTK. WXK_LAUNCH_D, ///< Available since wxWidgets 3.1.6 and only generated by wxGTK. WXK_LAUNCH_E, ///< Available since wxWidgets 3.1.6 and only generated by wxGTK. - WXK_LAUNCH_F ///< Available since wxWidgets 3.1.6 and only generated by wxGTK. + WXK_LAUNCH_F, ///< Available since wxWidgets 3.1.6 and only generated by wxGTK. + + /** + Key code corresponding to the event produced by the "5" key on the + numeric pad when Num Lock is off. + + This constant has the same value as WXK_CLEAR under wxMSW and + WXK_NUMPAD_BEGIN in the other ports but using it is preferable in + portable code. + + @since 3.3.0 + */ + WXK_NUMPAD_CENTER }; /** diff --git a/samples/keyboard/keyboard.cpp b/samples/keyboard/keyboard.cpp index e5b1e61afe..98f32da274 100644 --- a/samples/keyboard/keyboard.cpp +++ b/samples/keyboard/keyboard.cpp @@ -386,7 +386,7 @@ const char* GetVirtualKeyCodeName(int keycode) WXK_(RBUTTON) WXK_(CANCEL) WXK_(MBUTTON) - WXK_(CLEAR) + WXK_(NUMPAD_CENTER) WXK_(SHIFT) WXK_(ALT) WXK_(CONTROL) @@ -464,7 +464,6 @@ const char* GetVirtualKeyCodeName(int keycode) WXK_(NUMPAD_PAGEUP) WXK_(NUMPAD_PAGEDOWN) WXK_(NUMPAD_END) - WXK_(NUMPAD_BEGIN) WXK_(NUMPAD_INSERT) WXK_(NUMPAD_DELETE) WXK_(NUMPAD_EQUAL) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 811f49be21..b4e7e702d1 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -876,7 +876,7 @@ static long wxTranslateKeySymToWXKey(KeySym keysym, bool isChar) break; case GDK_KEY_KP_Begin: - key_code = isChar ? WXK_HOME : WXK_NUMPAD_BEGIN; + key_code = WXK_NUMPAD_BEGIN; break; case GDK_KEY_KP_Insert: diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 1e93d5e0b0..7990454edf 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -311,9 +311,9 @@ long wxOSXTranslateCocoaKey( NSEvent* event, int eventType ) case NSHomeFunctionKey : retval = WXK_HOME; break; - // case NSBeginFunctionKey : - // retval = WXK_BEGIN; - // break; + case NSBeginFunctionKey : + retval = WXK_NUMPAD_BEGIN; + break; case NSEndFunctionKey : retval = WXK_END; break;