NSCarbonWindow incorrectly eats Cmd-Enter and Ctrl-Enter
| Originator: | dustin.norman | ||
| Number: | rdar://11659831 | Date Originated: | 13-Jun-2012 04:39 PM |
| Status: | Open | Resolved: | |
| Product: | Mac OS X | Product Version: | |
| Classification: | Other Bug | Reproducible: | Yes |
Summary: If I have a Cocoa app containing Carbon windows, kEventTextInputUnicodeForKeyEvent are not sent to the Carbon event handler if Cmd-Enter or Ctrl-Enter are pressed. Steps to Reproduce: 1) Create a Cocoa app 2) Create a plain Carbon window and register for kEventTextInputUnicodeForKeyEvent events 3) Press Cmd-Enter or Ctrl-Enter Expected Results: The kEventTextInputUnicodeForKeyEvent handler would get called. Actual Results: The kEventTextInputUnicodeForKeyEvent event is eaten by Cocoa and not passed to the Carbon event handler. Regression: Unknown. Notes: I was able to debug this enough to figure out why it's happening. The implementation of -[NSCarbonWindow performKeyEquivalent] is looking for a default button in the Carbon window so that it can simulate a button click on Cmd-Enter or Ctrl-Enter. However, if the Carbon window doesn't have a button the GetWindowDefaultButton method returns NULL. In that case, -performKeyEquivalent is return YES which prevents the event from being further processed. If GetWindowDefaultButton returns NULL, it is my opinion that NSCarbonWindow should return NO so that other event handler can process the event. I was able to workaround this problem by swizzling -[NSCarbonWindow performKeyEquivalent] and always returning NO. Attached is a sample project that demonstrates this issue. In the samepl, a message will be logged to the console when a key is pressed. However, when Cmd-Enter or Ctrl-Enter is pressed, no message appears. If you uncomment out line 107 of AppDelegate.m and run it again, the message is correctly logged when Cmd-Enter or Ctrl-Enter is pressed. I realize that the real solution here would be for me to migrate to Cocoa windows. That will happen eventually but this is a large, old project that was neglected for a long time and it's not possible for me to do that at the moment.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!