Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Minor cleanup on Jiang's patch
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Apr 16, 2010
1 parent e002202 commit aaccd99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/SDL_events.h
Expand Up @@ -139,6 +139,7 @@ typedef struct SDL_TextEditingEvent
{
Uint32 type; /**< ::SDL_TEXTEDITING */
Uint32 windowID; /**< The window with keyboard focus, if any */
Uint8 which; /**< The keyboard device index */
char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE]; /**< The editing text */
int start; /**< The start cursor of selected editing text */
int length; /**< The length of selected editing text */
Expand Down
13 changes: 9 additions & 4 deletions src/events/SDL_keyboard.c
Expand Up @@ -679,8 +679,10 @@ SDL_SetKeyboardFocus(int index, SDL_Window * window)
if (keyboard->focus) {
SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
0, 0);
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY))

if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
SDL_StartTextInput();
}
}
}

Expand Down Expand Up @@ -832,6 +834,7 @@ SDL_SendKeyboardText(int index, const char *text)
if (SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE) {
SDL_Event event;
event.text.type = SDL_TEXTINPUT;
event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
event.text.which = (Uint8) index;
SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
event.text.windowID = keyboard->focus->id;
Expand All @@ -846,18 +849,20 @@ SDL_SendEditingText(int index, const char *text, int start, int length)
SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
int posted;

if (!keyboard)
if (!keyboard) {
return 0;
}

/* Post the event, if desired */
posted = 0;
if (SDL_GetEventState(SDL_TEXTEDITING) == SDL_ENABLE) {
SDL_Event event;
event.edit.type = SDL_TEXTEDITING;
event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
event.text.which = (Uint8) index;
event.edit.start = start;
event.edit.length = length;
SDL_strlcpy(event.edit.text, text, SDL_arraysize(event.text.text));
event.edit.windowID = keyboard->focus->id;
SDL_strlcpy(event.edit.text, text, SDL_arraysize(event.edit.text));
posted = (SDL_PushEvent(&event) > 0);
}
return (posted);
Expand Down
5 changes: 3 additions & 2 deletions src/video/cocoa/SDL_cocoakeyboard.m
Expand Up @@ -638,13 +638,14 @@ - (NSArray *) validAttributesForMarkedText
* than one copy. When we switched to another window and requesting for
* text input, simply remove the field editor from its superview then add
* it to the front most window's content view */
if (! data->fieldEdit)
if (!data->fieldEdit) {
data->fieldEdit =
[[SDLTranslatorResponder alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
}

[data->fieldEdit setKeyboard: data->keyboard];

if (! [[data->fieldEdit superview] isEqual: parentView])
if (![[data->fieldEdit superview] isEqual: parentView])
{
// DEBUG_IME(@"add fieldEdit to window contentView");
[data->fieldEdit removeFromSuperview];
Expand Down

0 comments on commit aaccd99

Please sign in to comment.