Fixed Chinese IME support (thanks ???!)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m
index 2962742..49a39b6 100644
--- a/src/video/uikit/SDL_uikitviewcontroller.m
+++ b/src/video/uikit/SDL_uikitviewcontroller.m
@@ -74,6 +74,8 @@ SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *o
#if SDL_IPHONE_KEYBOARD
UITextField *textField;
BOOL rotatingOrientation;
+ NSString *changeText;
+ NSString *obligateForBackspace;
#endif
}
@@ -250,10 +252,12 @@ SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *o
/* Set ourselves up as a UITextFieldDelegate */
- (void)initKeyboard
{
+ changeText = nil;
+ obligateForBackspace = @" "; /* 64 space */
textField = [[UITextField alloc] initWithFrame:CGRectZero];
textField.delegate = self;
/* placeholder so there is something to delete! */
- textField.text = @" ";
+ textField.text = obligateForBackspace;
/* set UITextInputTrait properties, mostly to defaults */
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
@@ -267,11 +271,12 @@ SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *o
textField.hidden = YES;
keyboardVisible = NO;
-#if !TARGET_OS_TV
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+#if !TARGET_OS_TV
[center addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[center addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
#endif
+ [center addObserver:self selector:@selector(textFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
}
- (void)setView:(UIView *)view
@@ -310,11 +315,12 @@ SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *o
- (void)deinitKeyboard
{
-#if !TARGET_OS_TV
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+#if !TARGET_OS_TV
[center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
#endif
+ [center removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
}
/* reveal onscreen virtual keyboard */
@@ -354,6 +360,50 @@ SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *o
[self setKeyboardHeight:0];
}
+- (void)textFieldTextDidChange:(NSNotification *)notification
+{
+ if (changeText!=nil && textField.markedTextRange == nil)
+ {
+ NSUInteger len = changeText.length;
+ if (len > 0) {
+ /* Go through all the characters in the string we've been sent and
+ * convert them to key presses */
+ int i;
+ for (i = 0; i < len; i++) {
+ unichar c = [changeText characterAtIndex:i];
+ SDL_Scancode code;
+ Uint16 mod;
+
+ if (c < 127) {
+ /* Figure out the SDL_Scancode and SDL_keymod for this unichar */
+ code = unicharToUIKeyInfoTable[c].code;
+ mod = unicharToUIKeyInfoTable[c].mod;
+ } else {
+ /* We only deal with ASCII right now */
+ code = SDL_SCANCODE_UNKNOWN;
+ mod = 0;
+ }
+
+ if (mod & KMOD_SHIFT) {
+ /* If character uses shift, press shift down */
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
+ }
+
+ /* send a keydown and keyup even for the character */
+ SDL_SendKeyboardKey(SDL_PRESSED, code);
+ SDL_SendKeyboardKey(SDL_RELEASED, code);
+
+ if (mod & KMOD_SHIFT) {
+ /* If character uses shift, press shift back up */
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
+ }
+ }
+ SDL_SendKeyboardText([changeText UTF8String]);
+ }
+ changeText = nil;
+ }
+}
+
- (void)updateKeyboard
{
CGAffineTransform t = self.view.transform;
@@ -392,49 +442,20 @@ SDL_HideHomeIndicatorHintChanged(void *userdata, const char *name, const char *o
- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSUInteger len = string.length;
-
if (len == 0) {
- /* it wants to replace text with nothing, ie a delete */
- SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
- SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
- } else {
- /* go through all the characters in the string we've been sent and
- * convert them to key presses */
- int i;
- for (i = 0; i < len; i++) {
- unichar c = [string characterAtIndex:i];
- Uint16 mod = 0;
- SDL_Scancode code;
-
- if (c < 127) {
- /* figure out the SDL_Scancode and SDL_keymod for this unichar */
- code = unicharToUIKeyInfoTable[c].code;
- mod = unicharToUIKeyInfoTable[c].mod;
- } else {
- /* we only deal with ASCII right now */
- code = SDL_SCANCODE_UNKNOWN;
- mod = 0;
- }
-
- if (mod & KMOD_SHIFT) {
- /* If character uses shift, press shift down */
- SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
- }
-
- /* send a keydown and keyup even for the character */
- SDL_SendKeyboardKey(SDL_PRESSED, code);
- SDL_SendKeyboardKey(SDL_RELEASED, code);
-
- if (mod & KMOD_SHIFT) {
- /* If character uses shift, press shift back up */
- SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
- }
+ changeText = nil;
+ if (textField.markedTextRange == nil) {
+ /* it wants to replace text with nothing, ie a delete */
+ SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_BACKSPACE);
+ SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_BACKSPACE);
}
-
- SDL_SendKeyboardText([string UTF8String]);
+ if (textField.text.length < 16) {
+ textField.text = obligateForBackspace;
+ }
+ } else {
+ changeText = string;
}
-
- return NO; /* don't allow the edit! (keep placeholder text there) */
+ return YES;
}
/* Terminates the editing session */
@@ -498,7 +519,7 @@ UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
@autoreleasepool {
SDL_uikitviewcontroller *vc = GetWindowViewController(window);
if (vc != nil) {
- return vc.isKeyboardVisible;
+ return vc.keyboardVisible;
}
return SDL_FALSE;
}