Minor cleanup on Jiang's patch
authorSam Lantinga <slouken@libsdl.org>
Thu, 15 Apr 2010 22:27:01 -0700
changeset 4435e953700da4ca
parent 4434 5c64052fb476
child 4436 d3c193100522
Minor cleanup on Jiang's patch
include/SDL_events.h
src/events/SDL_keyboard.c
src/video/cocoa/SDL_cocoakeyboard.m
     1.1 --- a/include/SDL_events.h	Thu Apr 15 22:14:26 2010 -0700
     1.2 +++ b/include/SDL_events.h	Thu Apr 15 22:27:01 2010 -0700
     1.3 @@ -139,6 +139,7 @@
     1.4  {
     1.5      Uint32 type;                                /**< ::SDL_TEXTEDITING */
     1.6      Uint32 windowID;                            /**< The window with keyboard focus, if any */
     1.7 +    Uint8 which;                                /**< The keyboard device index */
     1.8      char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];  /**< The editing text */
     1.9      int start;                                  /**< The start cursor of selected editing text */
    1.10      int length;                                 /**< The length of selected editing text */
     2.1 --- a/src/events/SDL_keyboard.c	Thu Apr 15 22:14:26 2010 -0700
     2.2 +++ b/src/events/SDL_keyboard.c	Thu Apr 15 22:27:01 2010 -0700
     2.3 @@ -679,8 +679,10 @@
     2.4      if (keyboard->focus) {
     2.5          SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
     2.6                              0, 0);
     2.7 -        if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY))
     2.8 +
     2.9 +        if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
    2.10              SDL_StartTextInput();
    2.11 +        }
    2.12      }
    2.13  }
    2.14  
    2.15 @@ -832,6 +834,7 @@
    2.16      if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) {
    2.17          SDL_Event event;
    2.18          event.text.type = SDL_TEXTINPUT;
    2.19 +        event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
    2.20          event.text.which = (Uint8) index;
    2.21          SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
    2.22          event.text.windowID = keyboard->focus->id;
    2.23 @@ -846,18 +849,20 @@
    2.24      SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
    2.25      int posted;
    2.26  
    2.27 -    if (!keyboard)
    2.28 +    if (!keyboard) {
    2.29          return 0;
    2.30 +    }
    2.31  
    2.32      /* Post the event, if desired */
    2.33      posted = 0;
    2.34      if (SDL_GetEventState(SDL_TEXTEDITING) == SDL_ENABLE) {
    2.35          SDL_Event event;
    2.36          event.edit.type = SDL_TEXTEDITING;
    2.37 +        event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
    2.38 +        event.text.which = (Uint8) index;
    2.39          event.edit.start = start;
    2.40          event.edit.length = length;
    2.41 -        SDL_strlcpy(event.edit.text, text, SDL_arraysize(event.text.text));
    2.42 -        event.edit.windowID = keyboard->focus->id;
    2.43 +        SDL_strlcpy(event.edit.text, text, SDL_arraysize(event.edit.text));
    2.44          posted = (SDL_PushEvent(&event) > 0);
    2.45      }
    2.46      return (posted);
     3.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Thu Apr 15 22:14:26 2010 -0700
     3.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Thu Apr 15 22:27:01 2010 -0700
     3.3 @@ -638,13 +638,14 @@
     3.4       * than one copy. When we switched to another window and requesting for
     3.5       * text input, simply remove the field editor from its superview then add
     3.6       * it to the front most window's content view */
     3.7 -    if (! data->fieldEdit)
     3.8 +    if (!data->fieldEdit) {
     3.9          data->fieldEdit =
    3.10              [[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
    3.11 +    }
    3.12  
    3.13      [data->fieldEdit setKeyboard: data->keyboard];
    3.14  
    3.15 -    if (! [[data->fieldEdit superview] isEqual: parentView])
    3.16 +    if (![[data->fieldEdit superview] isEqual: parentView])
    3.17      {
    3.18          // DEBUG_IME(@"add fieldEdit to window contentView");
    3.19          [data->fieldEdit removeFromSuperview];