# HG changeset patch # User Sam Lantinga # Date 1263886131 0 # Node ID 4c5ab6841fdc5074be2e32098128dcba2abcd86f # Parent e4009cea0e823d0c6c0de8dcf13a07311c3ede90 From: Jjgod Jiang Date: Mon, 18 Jan 2010 17:46:35 +0800 Subject: [PATCH] Polish text input handling for Mac OS X - Prevent crash caused by uninitialized video data - Prevent beeping caused by unhandled Cocoa selectors (like moveUp: moveDown:, etc.) diff -r e4009cea0e82 -r 4c5ab6841fdc src/video/SDL_video.c --- a/src/video/SDL_video.c Tue Jan 19 05:31:16 2010 +0000 +++ b/src/video/SDL_video.c Tue Jan 19 07:28:51 2010 +0000 @@ -3580,7 +3580,7 @@ void SDL_StartTextInput(void) { - if (_this->StartTextInput) { + if (_this && _this->StartTextInput) { _this->StartTextInput(_this); } SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE); @@ -3590,7 +3590,7 @@ void SDL_StopTextInput(void) { - if (_this->StopTextInput) { + if (_this && _this->StopTextInput) { _this->StopTextInput(_this); } SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE); @@ -3600,7 +3600,7 @@ void SDL_SetTextInputRect(SDL_Rect *rect) { - if (_this->SetTextInputRect) { + if (_this && _this->SetTextInputRect) { _this->SetTextInputRect(_this, rect); } } diff -r e4009cea0e82 -r 4c5ab6841fdc src/video/cocoa/SDL_cocoaevents.m --- a/src/video/cocoa/SDL_cocoaevents.m Tue Jan 19 05:31:16 2010 +0000 +++ b/src/video/cocoa/SDL_cocoaevents.m Tue Jan 19 07:28:51 2010 +0000 @@ -212,7 +212,6 @@ case NSFlagsChanged: Cocoa_HandleKeyEvent(_this, event); /* Fall through to pass event to NSApp; er, nevermind... */ - /* FIXME: Find a way to stop the beeping, using delegate */ /* Add to support system-wide keyboard shortcuts like CMD+Space */ if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged) diff -r e4009cea0e82 -r 4c5ab6841fdc src/video/cocoa/SDL_cocoakeyboard.m --- a/src/video/cocoa/SDL_cocoakeyboard.m Tue Jan 19 05:31:16 2010 +0000 +++ b/src/video/cocoa/SDL_cocoakeyboard.m Tue Jan 19 07:28:51 2010 +0000 @@ -99,7 +99,9 @@ - (void) doCommandBySelector:(SEL) myselector { - [super doCommandBySelector: myselector]; + // No need to do anything since we are not using Cocoa + // selectors to handle special keys, instead we use SDL + // key events to do the same job. } - (BOOL) hasMarkedText @@ -649,11 +651,13 @@ { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [data->fieldEdit removeFromSuperview]; - [data->fieldEdit release]; - data->fieldEdit = nil; - [pool release]; + if (data && data->fieldEdit) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [data->fieldEdit removeFromSuperview]; + [data->fieldEdit release]; + data->fieldEdit = nil; + [pool release]; + } } void