From 4c66d96e91ff7f27199cd2b51055a38e6651419d Mon Sep 17 00:00:00 2001 From: gcasa Date: Sun, 7 Feb 2010 08:37:04 +0000 Subject: [PATCH] * Headers/win32/WIN32Server.h: Remove HOTKEY method. * Source/win32/w32_general.m: Remove HOTKEY method. * Source/win32/WIN32Server.m: Remove call to HOTKEY method. Added function "mask_for_keystate(..)" to implement modifier mappings on Windows. Also changed process_key_event to use the new function and changed the call to ToUnicode to use a blank array instead of modifying the existing keyState array since this was returning the characters with the modifiers still applied. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@29498 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 +++++ Headers/win32/WIN32Server.h | 1 - Source/win32/WIN32Server.m | 98 +++++++++++++++++++++++++++---------- Source/win32/w32_general.m | 5 -- 4 files changed, 84 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6a95dee..a400318 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-02-07 03:37-EST Gregory John Casamento + + * Headers/win32/WIN32Server.h: Remove HOTKEY method. + * Source/win32/w32_general.m: Remove HOTKEY method. + * Source/win32/WIN32Server.m: Remove call to HOTKEY method. Added + function "mask_for_keystate(..)" to implement modifier mappings + on Windows. Also changed process_key_event to use the new function + and changed the call to ToUnicode to use a blank array instead of + modifying the existing keyState array since this was returning the + characters with the modifiers still applied. + 2010-02-05 16:31-EST Gregory John Casamento * Headers/win32/WIN32Server.h: Added declaration for decodeWM_HOTKEY:... diff --git a/Headers/win32/WIN32Server.h b/Headers/win32/WIN32Server.h index 863eba8..99e3441 100644 --- a/Headers/win32/WIN32Server.h +++ b/Headers/win32/WIN32Server.h @@ -173,7 +173,6 @@ typedef struct w32serverFlags { - (void) decodeWM_QUERYOPENParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd; - (void) decodeWM_SYSCOMMANDParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd; - (void) decodeWM_COMMANDParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd; -- (void) decodeWM_HOTKEYParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd; @end diff --git a/Source/win32/WIN32Server.m b/Source/win32/WIN32Server.m index 1c74c38..6b31ca1 100644 --- a/Source/win32/WIN32Server.m +++ b/Source/win32/WIN32Server.m @@ -671,9 +671,6 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, break; case WM_HELP: break; - case WM_HOTKEY: - [self decodeWM_HOTKEYParams: wParam : lParam : hwnd]; - break; //case WM_GETICON: //return [self decodeWM_GETICONParams: wParam : lParam : hwnd]; //break; @@ -1649,6 +1646,65 @@ process_char(WPARAM wParam, unsigned *eventModifierFlags) } } +static unsigned int +mask_for_keystate(BYTE *keyState) +{ + unsigned int eventFlags = 0; + NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; + NSString *firstCommand = [defs stringForKey: @"GSFirstCommandKey"]; + NSString *firstControl = [defs stringForKey: @"GSFirstControlKey"]; + NSString *firstAlt = [defs stringForKey: @"GSFirstAlternateKey"]; + NSString *secondCommand = [defs stringForKey: @"GSSecondCommandKey"]; + NSString *secondControl = [defs stringForKey: @"GSSecondControlKey"]; + NSString *secondAlt = [defs stringForKey: @"GSSecondAlternateKey"]; + + /* AltGr is mapped to right alt + left control */ + if (keyState[VK_RCONTROL] & 128) // && !((keyState[VK_LCONTROL] & 128) && (keyState[VK_RMENU] & 128))) + { + if([@"Control_R" isEqualToString: firstAlt] || + [@"Control_R" isEqualToString: secondAlt]) + eventFlags |= NSAlternateKeyMask; + else if([@"Control_R" isEqualToString: firstCommand] || + [@"Control_R" isEqualToString: secondCommand]) + eventFlags |= NSCommandKeyMask; + else + eventFlags |= NSControlKeyMask; + } + + if (keyState[VK_SHIFT] & 128) + eventFlags |= NSShiftKeyMask; + if (keyState[VK_CAPITAL] & 128) + eventFlags |= NSShiftKeyMask; + + if (keyState[VK_MENU] & 128) + { + if([@"Alt_R" isEqualToString: firstControl] || + [@"Alt_R" isEqualToString: secondControl]) + eventFlags |= NSControlKeyMask; + else if([@"Alt_R" isEqualToString: firstCommand] || + [@"Alt_R" isEqualToString: secondCommand]) + eventFlags |= NSCommandKeyMask; + else + eventFlags |= NSAlternateKeyMask; + } + + if (keyState[VK_HELP] & 128) + eventFlags |= NSHelpKeyMask; + + if ((keyState[VK_LCONTROL] & 128) || (keyState[VK_RWIN] & 128)) + { + if([@"Control_L" isEqualToString: firstAlt] || + [@"Control_L" isEqualToString: secondAlt]) + eventFlags |= NSAlternateKeyMask; + else if([@"Control_L" isEqualToString: firstControl] || + [@"Control_L" isEqualToString: secondControl]) + eventFlags |= NSControlKeyMask; + else + eventFlags |= NSCommandKeyMask; + } + return eventFlags; +} + static NSEvent* process_key_event(WIN32Server *svr, HWND hwnd, WPARAM wParam, LPARAM lParam, NSEventType eventType) @@ -1681,21 +1737,7 @@ process_key_event(WIN32Server *svr, HWND hwnd, WPARAM wParam, LPARAM lParam, time = ltime / 1000; GetKeyboardState(keyState); - eventFlags = 0; - /* AltGr is mapped to right alt + left control */ - if ((keyState[VK_CONTROL] & 128) && !((keyState[VK_LCONTROL] & 128) && (keyState[VK_RMENU] & 128))) - eventFlags |= NSControlKeyMask; - if (keyState[VK_SHIFT] & 128) - eventFlags |= NSShiftKeyMask; - if (keyState[VK_CAPITAL] & 128) - eventFlags |= NSShiftKeyMask; - if (keyState[VK_MENU] & 128) - eventFlags |= NSAlternateKeyMask; - if (keyState[VK_HELP] & 128) - eventFlags |= NSHelpKeyMask; - if ((keyState[VK_LWIN] & 128) || (keyState[VK_RWIN] & 128)) - eventFlags |= NSCommandKeyMask; - + eventFlags = mask_for_keystate(keyState); switch(wParam) { @@ -1732,6 +1774,13 @@ process_key_event(WIN32Server *svr, HWND hwnd, WPARAM wParam, LPARAM lParam, } else { + BYTE blankKeyState[256]; + int i = 0; + + // initialize blank key state array.... + for(i = 0; i < 256; i++) + blankKeyState[i] = 0; + scan = ((lParam >> 16) & 0xFF); //NSLog(@"Got key code %d %d", scan, wParam); result = ToUnicode(wParam, scan, keyState, unicode, 5, 0); @@ -1741,19 +1790,18 @@ process_key_event(WIN32Server *svr, HWND hwnd, WPARAM wParam, LPARAM lParam, // A non spacing accent key was found, we still try to use the result result = 1; } - keys = [NSString stringWithCharacters: unicode length: result]; - // Now switch modifiers off - keyState[VK_LCONTROL] = 0; - keyState[VK_RCONTROL] = 0; - keyState[VK_LMENU] = 0; - keyState[VK_RMENU] = 0; - result = ToUnicode(wParam, scan, keyState, unicode, 5, 0); + keys = [NSString stringWithCharacters: unicode length: result]; + + // Now get the characters with a blank keyboard state so that + // no modifiers are applied. + result = ToUnicode(wParam, scan, blankKeyState, unicode, 5, 0); //NSLog(@"To Unicode resulted in %d with %d", result, unicode[0]); if (result == -1) { // A non spacing accent key was found, we still try to use the result result = 1; } + ukeys = [NSString stringWithCharacters: unicode length: result]; } diff --git a/Source/win32/w32_general.m b/Source/win32/w32_general.m index 4fa553e..f14f662 100644 --- a/Source/win32/w32_general.m +++ b/Source/win32/w32_general.m @@ -134,10 +134,5 @@ { [[GSTheme theme] processCommand: (void *)wParam]; } - -- (void) decodeWM_HOTKEYParams: (WPARAM)wParam : (LPARAM)lParam : (HWND)hwnd -{ - [[GSTheme theme] processCommand: (void *)wParam]; -} @end