comparison src/video/uikit/SDL_uikitview.m @ 4490:06c7423f8c60

Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now) Updated iPhone demos (which build and run again)
author Sam Lantinga <slouken@libsdl.org>
date Wed, 07 Jul 2010 18:58:51 -0700
parents 6dc6a2bdd55e
children 95352c671a6e 03dcb795c583
comparison
equal deleted inserted replaced
4489:2bb1bfeee9e2 4490:06c7423f8c60
20 slouken@libsdl.org 20 slouken@libsdl.org
21 */ 21 */
22 22
23 #import "SDL_uikitview.h" 23 #import "SDL_uikitview.h"
24 24
25 #include "../../events/SDL_keyboard_c.h"
26 #include "../../events/SDL_mouse_c.h"
27
25 #if SDL_IPHONE_KEYBOARD 28 #if SDL_IPHONE_KEYBOARD
26 #import "SDL_keyboard_c.h"
27 #import "keyinfotable.h" 29 #import "keyinfotable.h"
28 #import "SDL_uikitappdelegate.h" 30 #import "SDL_uikitappdelegate.h"
29 #import "SDL_uikitwindow.h" 31 #import "SDL_uikitwindow.h"
30 #endif 32 #endif
31 33
32 @implementation SDL_uikitview 34 @implementation SDL_uikitview
33 35
34 - (void)dealloc { 36 - (void)dealloc {
35 #if SDL_IPHONE_KEYBOARD 37 #if SDL_IPHONE_KEYBOARD
36 SDL_DelKeyboard(0);
37 [textField release]; 38 [textField release];
38 #endif 39 #endif
39 [super dealloc]; 40 [super dealloc];
40 } 41 }
41 42
223 224
224 textField.hidden = YES; 225 textField.hidden = YES;
225 keyboardVisible = NO; 226 keyboardVisible = NO;
226 /* add the UITextField (hidden) to our view */ 227 /* add the UITextField (hidden) to our view */
227 [self addSubview: textField]; 228 [self addSubview: textField];
228
229 /* create our SDL_Keyboard */
230 SDL_Keyboard keyboard;
231 SDL_zero(keyboard);
232 SDL_AddKeyboard(&keyboard, 0);
233 SDLKey keymap[SDL_NUM_SCANCODES];
234 SDL_GetDefaultKeymap(keymap);
235 SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
236
237 } 229 }
238 230
239 /* reveal onscreen virtual keyboard */ 231 /* reveal onscreen virtual keyboard */
240 - (void)showKeyboard { 232 - (void)showKeyboard {
241 keyboardVisible = YES; 233 keyboardVisible = YES;
251 /* UITextFieldDelegate method. Invoked when user types something. */ 243 /* UITextFieldDelegate method. Invoked when user types something. */
252 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { 244 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
253 245
254 if ([string length] == 0) { 246 if ([string length] == 0) {
255 /* it wants to replace text with nothing, ie a delete */ 247 /* it wants to replace text with nothing, ie a delete */
256 SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_DELETE); 248 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DELETE);
257 SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_DELETE); 249 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DELETE);
258 } 250 }
259 else { 251 else {
260 /* go through all the characters in the string we've been sent 252 /* go through all the characters in the string we've been sent
261 and convert them to key presses */ 253 and convert them to key presses */
262 int i; 254 int i;
278 mod = 0; 270 mod = 0;
279 } 271 }
280 272
281 if (mod & KMOD_SHIFT) { 273 if (mod & KMOD_SHIFT) {
282 /* If character uses shift, press shift down */ 274 /* If character uses shift, press shift down */
283 SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_LSHIFT); 275 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
284 } 276 }
285 /* send a keydown and keyup even for the character */ 277 /* send a keydown and keyup even for the character */
286 SDL_SendKeyboardKey( 0, SDL_PRESSED, code); 278 SDL_SendKeyboardKey(SDL_PRESSED, code);
287 SDL_SendKeyboardKey( 0, SDL_RELEASED, code); 279 SDL_SendKeyboardKey(SDL_RELEASED, code);
288 if (mod & KMOD_SHIFT) { 280 if (mod & KMOD_SHIFT) {
289 /* If character uses shift, press shift back up */ 281 /* If character uses shift, press shift back up */
290 SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT); 282 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
291 } 283 }
292 } 284 }
293 } 285 }
294 return NO; /* don't allow the edit! (keep placeholder text there) */ 286 return NO; /* don't allow the edit! (keep placeholder text there) */
295 } 287 }