]> git.saurik.com Git - wxWidgets.git/commitdiff
misc key-event fixes, see #10876
authorStefan Csomor <csomor@advancedconcepts.ch>
Wed, 10 Jun 2009 06:10:33 +0000 (06:10 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Wed, 10 Jun 2009 06:10:33 +0000 (06:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60969 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/cocoa/window.mm

index 593016173a63de26bb13cfb445cecd1cf5f587eb..9a10b8874352f5d695f992aa415c9bfc75bc8968 100644 (file)
@@ -204,7 +204,56 @@ long wxOSXTranslateCocoaKey( NSEvent* event )
             retval = WXK_TAB;
             break;
 
-        default :
+        case 75: // /
+            retval = WXK_NUMPAD_DIVIDE;
+            break;            
+        case 67: // *
+            retval = WXK_NUMPAD_MULTIPLY;
+            break;
+        case 78: // -
+            retval = WXK_NUMPAD_SUBTRACT;
+            break;
+        case 69: // +
+            retval = WXK_NUMPAD_ADD;
+            break;
+        case 76: // Enter
+            retval = WXK_NUMPAD_ENTER;
+            break;
+        case 65: // .
+            retval = WXK_NUMPAD_DECIMAL;
+            break;
+        case 82: // 0
+            retval = WXK_NUMPAD0;
+            break;
+        case 83: // 1
+            retval = WXK_NUMPAD1;
+            break;
+        case 84: // 2
+            retval = WXK_NUMPAD2;
+            break;
+        case 85: // 3
+            retval = WXK_NUMPAD3;
+            break;
+        case 86: // 4
+            retval = WXK_NUMPAD4;
+            break;
+        case 87: // 5
+            retval = WXK_NUMPAD5;
+            break;
+        case 88: // 6
+            retval = WXK_NUMPAD6;
+            break;
+        case 89: // 7
+            retval = WXK_NUMPAD7;
+            break;
+        case 91: // 8
+            retval = WXK_NUMPAD8;
+            break;
+        case 92: // 9
+            retval = WXK_NUMPAD9;
+            break;
+        default:
+            //retval = [event keyCode];
             break;
     }
     return retval;
@@ -224,25 +273,11 @@ void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charStrin
     wxevent.m_rawFlags = modifiers;
     
     wxevent.SetTimestamp( [nsEvent timestamp] * 1000.0 ) ;
-    switch (eventType)
-    {
-        case NSKeyDown :
-            wxevent.SetEventType( wxEVT_KEY_DOWN )  ;
-            break;
-        case NSKeyUp :
-            wxevent.SetEventType( wxEVT_KEY_UP )  ;
-            break;
-        case NSFlagsChanged :
-            // setup common code here
-            break;
-        default :
-            break ;
-    }
 
     wxString chars;
     if ( eventType != NSFlagsChanged )
     {
-        NSString* nschars = [nsEvent characters];
+        NSString* nschars = (wxevent.GetEventType() != wxEVT_CHAR) ? [nsEvent charactersIgnoringModifiers] : [nsEvent characters];
         if ( charString )
         {
             // if charString is set, it did not come from key up / key down
@@ -261,7 +296,37 @@ void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charStrin
     long keyval = 0;
     
     if (wxevent.GetEventType() != wxEVT_CHAR)
+    {
         keyval = wxOSXTranslateCocoaKey(nsEvent) ;
+        switch (eventType)
+        {
+            case NSKeyDown :
+                wxevent.SetEventType( wxEVT_KEY_DOWN )  ;
+                break;
+            case NSKeyUp :
+                wxevent.SetEventType( wxEVT_KEY_UP )  ;
+                break;
+            case NSFlagsChanged :
+                switch (keyval)
+                {
+                    case WXK_CONTROL:
+                        wxevent.SetEventType( wxevent.m_controlDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
+                        break;
+                    case WXK_SHIFT:
+                        wxevent.SetEventType( wxevent.m_shiftDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
+                        break;
+                    case WXK_ALT:
+                        wxevent.SetEventType( wxevent.m_altDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
+                        break;
+                    case WXK_COMMAND:
+                        wxevent.SetEventType( wxevent.m_metaDown ? wxEVT_KEY_DOWN : wxEVT_KEY_UP);
+                        break;
+                }
+                break;
+            default :
+                break ;
+        }
+    }
 
     if ( !keyval )
     {
@@ -1397,7 +1462,7 @@ void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
 
 bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
 {
-    wxKeyEvent wxevent(wxEVT_KEY_DOWN);
+    wxKeyEvent wxevent(wxEVT_CHAR);
     SetupKeyEvent( wxevent, event, text );
     wxevent.SetEventObject(GetWXPeer());  
 
@@ -1416,7 +1481,8 @@ bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
     if ([event type] == NSKeyDown)
     {
         m_lastKeyDownEvent = event;
-        [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
+        if ( !result )
+            [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
     }
     return result;
 }