From: Jjgod Jiang
authorSam Lantinga <slouken@libsdl.org>
Tue, 19 Jan 2010 07:28:51 +0000
changeset 36834c5ab6841fdc
parent 3682 e4009cea0e82
child 3684 cc564f08884f
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.)
src/video/SDL_video.c
src/video/cocoa/SDL_cocoaevents.m
src/video/cocoa/SDL_cocoakeyboard.m
     1.1 --- a/src/video/SDL_video.c	Tue Jan 19 05:31:16 2010 +0000
     1.2 +++ b/src/video/SDL_video.c	Tue Jan 19 07:28:51 2010 +0000
     1.3 @@ -3580,7 +3580,7 @@
     1.4  void
     1.5  SDL_StartTextInput(void)
     1.6  {
     1.7 -    if (_this->StartTextInput) {
     1.8 +    if (_this && _this->StartTextInput) {
     1.9          _this->StartTextInput(_this);
    1.10      }
    1.11      SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
    1.12 @@ -3590,7 +3590,7 @@
    1.13  void
    1.14  SDL_StopTextInput(void)
    1.15  {
    1.16 -    if (_this->StopTextInput) {
    1.17 +    if (_this && _this->StopTextInput) {
    1.18          _this->StopTextInput(_this);
    1.19      }
    1.20      SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
    1.21 @@ -3600,7 +3600,7 @@
    1.22  void
    1.23  SDL_SetTextInputRect(SDL_Rect *rect)
    1.24  {
    1.25 -    if (_this->SetTextInputRect) {
    1.26 +    if (_this && _this->SetTextInputRect) {
    1.27          _this->SetTextInputRect(_this, rect);
    1.28      }
    1.29  }
     2.1 --- a/src/video/cocoa/SDL_cocoaevents.m	Tue Jan 19 05:31:16 2010 +0000
     2.2 +++ b/src/video/cocoa/SDL_cocoaevents.m	Tue Jan 19 07:28:51 2010 +0000
     2.3 @@ -212,7 +212,6 @@
     2.4          case NSFlagsChanged:
     2.5              Cocoa_HandleKeyEvent(_this, event);
     2.6              /* Fall through to pass event to NSApp; er, nevermind... */
     2.7 -            /* FIXME: Find a way to stop the beeping, using delegate */
     2.8  
     2.9              /* Add to support system-wide keyboard shortcuts like CMD+Space */
    2.10              if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged)
     3.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Tue Jan 19 05:31:16 2010 +0000
     3.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Tue Jan 19 07:28:51 2010 +0000
     3.3 @@ -99,7 +99,9 @@
     3.4  
     3.5  - (void) doCommandBySelector:(SEL) myselector
     3.6  {
     3.7 -    [super doCommandBySelector: myselector];
     3.8 +    // No need to do anything since we are not using Cocoa
     3.9 +    // selectors to handle special keys, instead we use SDL
    3.10 +    // key events to do the same job.
    3.11  }
    3.12  
    3.13  - (BOOL) hasMarkedText
    3.14 @@ -649,11 +651,13 @@
    3.15  {
    3.16      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    3.17  
    3.18 -    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    3.19 -    [data->fieldEdit removeFromSuperview];
    3.20 -    [data->fieldEdit release];
    3.21 -    data->fieldEdit = nil;
    3.22 -    [pool release];
    3.23 +    if (data && data->fieldEdit) {
    3.24 +        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    3.25 +        [data->fieldEdit removeFromSuperview];
    3.26 +        [data->fieldEdit release];
    3.27 +        data->fieldEdit = nil;
    3.28 +        [pool release];
    3.29 +    }
    3.30  }
    3.31  
    3.32  void