diff src/video/cocoa/SDL_cocoakeyboard.m @ 4434:5c64052fb476

changeset: 4433:25667ea797fa tag: tip user: Jiang Jiang <gzjjgod@gmail.com> date: Thu Apr 15 12:01:46 2010 +0800 summary: Add windowID to text editing event
author Sam Lantinga <slouken@libsdl.org>
date Thu, 15 Apr 2010 22:14:26 -0700
parents 4c5ab6841fdc
children e953700da4ca
line wrap: on
line diff
--- a/src/video/cocoa/SDL_cocoakeyboard.m	Thu Apr 15 21:27:32 2010 -0700
+++ b/src/video/cocoa/SDL_cocoakeyboard.m	Thu Apr 15 22:14:26 2010 -0700
@@ -140,7 +140,8 @@
     _selectedRange = selRange;
     _markedRange = NSMakeRange(0, [aString length]);
 
-    SDL_SendEditingText([aString UTF8String], selRange.location, selRange.length);
+    SDL_SendEditingText(_keyboard, [aString UTF8String],
+                        selRange.location, selRange.length);
 
     DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText,
           selRange.location, selRange.length);
@@ -632,7 +633,15 @@
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSView *parentView = [[NSApp keyWindow] contentView];
 
-    data->fieldEdit = [[SDLTranslatorResponder alloc] initWithFrame:NSMakeRect(0.0, 0.0, 0.0, 0.0)];
+    /* We only keep one field editor per process, since only the front most
+     * window can receive text input events, so it make no sense to keep more
+     * 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)
+        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])