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

Commit

Permalink
Fixed bug 1163 (SDL_TEXTINPUT not being received on iPhoneOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Mar 10, 2011
1 parent a7bb33a commit 081098c
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 47 deletions.
98 changes: 96 additions & 2 deletions Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj
Expand Up @@ -17,6 +17,15 @@
046CEF8113254F23007AD51D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89D0E2D111A00EA573E /* Foundation.framework */; };
046CEF8213254F23007AD51D /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89E0E2D111A00EA573E /* CoreAudio.framework */; };
046CEF8A13254F63007AD51D /* testgesture.c in Sources */ = {isa = PBXBuildFile; fileRef = 046CEF8913254F63007AD51D /* testgesture.c */; };
047A63E213285C3200CD7973 /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; };
047A63E313285C3200CD7973 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; };
047A63E413285C3200CD7973 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; };
047A63E513285C3200CD7973 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; };
047A63E613285C3200CD7973 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89B0E2D111A00EA573E /* CoreGraphics.framework */; };
047A63E713285C3200CD7973 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89C0E2D111A00EA573E /* UIKit.framework */; };
047A63E813285C3200CD7973 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89D0E2D111A00EA573E /* Foundation.framework */; };
047A63E913285C3200CD7973 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89E0E2D111A00EA573E /* CoreAudio.framework */; };
047A63F113285CD100CD7973 /* checkkeys.c in Sources */ = {isa = PBXBuildFile; fileRef = 047A63F013285CD100CD7973 /* checkkeys.c */; };
56ED04FE118A8FE400A56AA6 /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AAD90E2D33B000EA573E /* icon.bmp */; };
56ED0502118A8FE400A56AA6 /* libSDL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDL.a */; };
56ED0503118A8FE400A56AA6 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; };
Expand Down Expand Up @@ -306,6 +315,8 @@
/* Begin PBXFileReference section */
046CEF8613254F23007AD51D /* testgesture.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testgesture.app; sourceTree = BUILT_PRODUCTS_DIR; };
046CEF8913254F63007AD51D /* testgesture.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testgesture.c; path = ../../test/testgesture.c; sourceTree = SOURCE_ROOT; };
047A63ED13285C3200CD7973 /* checkkeys.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = checkkeys.app; sourceTree = BUILT_PRODUCTS_DIR; };
047A63F013285CD100CD7973 /* checkkeys.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = checkkeys.c; path = ../../test/checkkeys.c; sourceTree = SOURCE_ROOT; };
1D6058910D05DD3D006BFB54 /* testwm2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testwm2.app; sourceTree = BUILT_PRODUCTS_DIR; };
56ED050D118A8FE400A56AA6 /* testpower.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testpower.app; sourceTree = BUILT_PRODUCTS_DIR; };
56ED0510118A904200A56AA6 /* testpower.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testpower.c; path = ../../test/testpower.c; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -342,7 +353,6 @@
FDA8A7840E2D0F1F00EA573E /* common.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = common.c; path = ../../test/common.c; sourceTree = SOURCE_ROOT; };
FDA8A7850E2D0F1F00EA573E /* common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = common.h; path = ../../test/common.h; sourceTree = SOURCE_ROOT; };
FDA8A7870E2D0F2700EA573E /* graywin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = graywin.c; path = ../../test/graywin.c; sourceTree = SOURCE_ROOT; };
FDA8A7890E2D0F2E00EA573E /* checkkeys.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = checkkeys.c; path = ../../test/checkkeys.c; sourceTree = SOURCE_ROOT; };
FDA8A78B0E2D0F3D00EA573E /* loopwave.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = loopwave.c; path = ../../test/loopwave.c; sourceTree = SOURCE_ROOT; };
FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
FDA8A8990E2D111A00EA573E /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -404,6 +414,21 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
047A63E113285C3200CD7973 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
047A63E213285C3200CD7973 /* libSDL.a in Frameworks */,
047A63E313285C3200CD7973 /* AudioToolbox.framework in Frameworks */,
047A63E413285C3200CD7973 /* QuartzCore.framework in Frameworks */,
047A63E513285C3200CD7973 /* OpenGLES.framework in Frameworks */,
047A63E613285C3200CD7973 /* CoreGraphics.framework in Frameworks */,
047A63E713285C3200CD7973 /* UIKit.framework in Frameworks */,
047A63E813285C3200CD7973 /* Foundation.framework in Frameworks */,
047A63E913285C3200CD7973 /* CoreAudio.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
1D60588F0D05DD3D006BFB54 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -858,6 +883,7 @@
FDC430000F0D866D009C87E1 /* torturethread.app */,
56ED050D118A8FE400A56AA6 /* testpower.app */,
046CEF8613254F23007AD51D /* testgesture.app */,
047A63ED13285C3200CD7973 /* checkkeys.app */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -888,9 +914,9 @@
children = (
FDA8A7840E2D0F1F00EA573E /* common.c */,
FDA8A7850E2D0F1F00EA573E /* common.h */,
047A63F013285CD100CD7973 /* checkkeys.c */,
FDA8A7870E2D0F2700EA573E /* graywin.c */,
FDA8A78B0E2D0F3D00EA573E /* loopwave.c */,
FDA8A7890E2D0F2E00EA573E /* checkkeys.c */,
FDA8A7400E2D0F1600EA573E /* testalpha.c */,
FDA8A7410E2D0F1600EA573E /* testaudioinfo.c */,
FDA8A7420E2D0F1600EA573E /* testbitmap.c */,
Expand Down Expand Up @@ -976,6 +1002,23 @@
productReference = 046CEF8613254F23007AD51D /* testgesture.app */;
productType = "com.apple.product-type.application";
};
047A63DD13285C3200CD7973 /* checkkeys */ = {
isa = PBXNativeTarget;
buildConfigurationList = 047A63EA13285C3200CD7973 /* Build configuration list for PBXNativeTarget "checkkeys" */;
buildPhases = (
047A63DE13285C3200CD7973 /* Resources */,
047A63DF13285C3200CD7973 /* Sources */,
047A63E113285C3200CD7973 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = checkkeys;
productName = TestiPhoneOS;
productReference = 047A63ED13285C3200CD7973 /* checkkeys.app */;
productType = "com.apple.product-type.application";
};
1D6058900D05DD3D006BFB54 /* testwm2 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "testwm2" */;
Expand Down Expand Up @@ -1477,6 +1520,7 @@
);
projectRoot = "";
targets = (
047A63DD13285C3200CD7973 /* checkkeys */,
FDA8A91D0E2D1C0B00EA573E /* graywin */,
FDAAC4300E2D4961001DB1D8 /* testbitmap */,
FDAAC5040E2D4FEB001DB1D8 /* testdyngles */,
Expand Down Expand Up @@ -1536,6 +1580,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
047A63DE13285C3200CD7973 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
1D60588D0D05DD3D006BFB54 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -1755,6 +1806,14 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
047A63DF13285C3200CD7973 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
047A63F113285CD100CD7973 /* checkkeys.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
1D60588E0D05DD3D006BFB54 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -2012,6 +2071,32 @@
};
name = Release;
};
047A63EB13285C3200CD7973 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "";
INFOPLIST_FILE = Info.plist;
PRODUCT_NAME = checkkeys;
};
name = Debug;
};
047A63EC13285C3200CD7973 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "";
INFOPLIST_FILE = Info.plist;
PRODUCT_NAME = checkkeys;
};
name = Release;
};
1D6058940D05DD3E006BFB54 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -2787,6 +2872,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
047A63EA13285C3200CD7973 /* Build configuration list for PBXNativeTarget "checkkeys" */ = {
isa = XCConfigurationList;
buildConfigurations = (
047A63EB13285C3200CD7973 /* Debug */,
047A63EC13285C3200CD7973 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1D6058960D05DD3E006BFB54 /* Build configuration list for PBXNativeTarget "testwm2" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
1 change: 1 addition & 0 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -290,6 +290,7 @@ - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRan
SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
}
}
SDL_SendKeyboardText([string UTF8String]);
}
return NO; /* don't allow the edit! (keep placeholder text there) */
}
Expand Down
123 changes: 78 additions & 45 deletions test/checkkeys.c
Expand Up @@ -19,117 +19,148 @@ quit(int rc)
}

static void
print_modifiers(void)
print_string(char **text, size_t *maxlen, const char *fmt, ...)
{
int len;
va_list ap;

va_start(ap, fmt);
len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
if (len > 0) {
*text += len;
if (len < *maxlen) {
*maxlen -= len;
} else {
*maxlen = 0;
}
}
va_end(ap);
}

static void
print_modifiers(char **text, size_t *maxlen)
{
int mod;
printf(" modifiers:");
print_string(text, maxlen, " modifiers:");
mod = SDL_GetModState();
if (!mod) {
printf(" (none)");
print_string(text, maxlen, " (none)");
return;
}
if (mod & KMOD_LSHIFT)
printf(" LSHIFT");
print_string(text, maxlen, " LSHIFT");
if (mod & KMOD_RSHIFT)
printf(" RSHIFT");
print_string(text, maxlen, " RSHIFT");
if (mod & KMOD_LCTRL)
printf(" LCTRL");
print_string(text, maxlen, " LCTRL");
if (mod & KMOD_RCTRL)
printf(" RCTRL");
print_string(text, maxlen, " RCTRL");
if (mod & KMOD_LALT)
printf(" LALT");
print_string(text, maxlen, " LALT");
if (mod & KMOD_RALT)
printf(" RALT");
print_string(text, maxlen, " RALT");
if (mod & KMOD_LGUI)
printf(" LGUI");
print_string(text, maxlen, " LGUI");
if (mod & KMOD_RGUI)
printf(" RGUI");
print_string(text, maxlen, " RGUI");
if (mod & KMOD_NUM)
printf(" NUM");
print_string(text, maxlen, " NUM");
if (mod & KMOD_CAPS)
printf(" CAPS");
print_string(text, maxlen, " CAPS");
if (mod & KMOD_MODE)
printf(" MODE");
print_string(text, maxlen, " MODE");
}

static void
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
{
char message[512];
char *spot;
size_t left;

spot = message;
left = sizeof(message);

/* Print the keycode, name and state */
if (sym->sym) {
printf("Key %s: scancode %d = %s, keycode 0x%08X = %s ",
pressed ? "pressed " : "released",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
sym->sym, SDL_GetKeyName(sym->sym));
print_string(&spot, &left,
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
pressed ? "pressed " : "released",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
sym->sym, SDL_GetKeyName(sym->sym));
} else {
printf("Unknown Key (scancode %d = %s) %s ",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
pressed ? "pressed" : "released");
print_string(&spot, &left,
"Unknown Key (scancode %d = %s) %s ",
sym->scancode,
SDL_GetScancodeName(sym->scancode),
pressed ? "pressed" : "released");
}

/* Print the translated character, if one exists */
if (sym->unicode) {
/* Is it a control-character? */
if (sym->unicode < ' ') {
printf(" (^%c)", sym->unicode + '@');
print_string(&spot, &left, " (^%c)", sym->unicode + '@');
} else {
#ifdef UNICODE
printf(" (%c)", sym->unicode);
print_string(&spot, &left, " (%c)", sym->unicode);
#else
/* This is a Latin-1 program, so only show 8-bits */
if (!(sym->unicode & 0xFF00))
printf(" (%c)", sym->unicode);
print_string(&spot, &left, " (%c)", sym->unicode);
else
printf(" (0x%X)", sym->unicode);
print_string(&spot, &left, " (0x%X)", sym->unicode);
#endif
}
}
print_modifiers();
print_modifiers(&spot, &left);
if (repeat) {
printf(" (repeat)");
print_string(&spot, &left, " (repeat)");
}
printf("\n");
SDL_Log("%s", message);
}

static void
PrintText(char *text)
{
printf("Text: %s\n", text);
SDL_Log("Text: %s", text);
}

#if __IPHONEOS__
extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_Window * window);
#endif

int
main(int argc, char *argv[])
{
SDL_Window *window;
SDL_Event event;
int done;
Uint32 videoflags;

/* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}

videoflags = SDL_SWSURFACE;
while (argc > 1) {
--argc;
if (argv[argc] && !strcmp(argv[argc], "-fullscreen")) {
videoflags |= SDL_FULLSCREEN;
} else {
fprintf(stderr, "Usage: %s [-fullscreen]\n", argv[0]);
quit(1);
}
}

/* Set 640x480 video mode */
if (SDL_SetVideoMode(640, 480, 0, videoflags) == NULL) {
fprintf(stderr, "Couldn't set 640x480 video mode: %s\n",
window = SDL_CreateWindow("CheckKeys Test",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 480, 0);
if (!window) {
fprintf(stderr, "Couldn't create 640x480 window: %s\n",
SDL_GetError());
quit(2);
}

#if __IPHONEOS__
/* Creating the context creates the view, which we need to show keyboard */
SDL_GL_CreateContext(window);
SDL_iPhoneKeyboardShow(window);
#endif


/* Watch keystrokes */
done = 0;
while (!done) {
Expand All @@ -156,3 +187,5 @@ main(int argc, char *argv[])
SDL_Quit();
return (0);
}

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit 081098c

Please sign in to comment.