changeset 4049:60f677630282 SDL-1.2

Added key composition support, courtesy of Kuon
author Sam Lantinga <slouken@libsdl.org>
date Wed, 11 Jul 2007 07:53:12 +0000
parents 3e380b8247aa
children ef815c44c662
files src/video/quartz/SDL_QuartzEvents.m src/video/quartz/SDL_QuartzVideo.h src/video/quartz/SDL_QuartzVideo.m
diffstat 3 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/quartz/SDL_QuartzEvents.m	Wed Jul 11 07:47:47 2007 +0000
+++ b/src/video/quartz/SDL_QuartzEvents.m	Wed Jul 11 07:53:12 2007 +0000
@@ -254,7 +254,7 @@
 static void QZ_DoKey (_THIS, int state, NSEvent *event) {
 
     NSString *chars;
-    unsigned int numChars;
+    unsigned int i, numChars;
     SDL_keysym key;
     
     /* 
@@ -265,7 +265,8 @@
         contains multiple characters, we'll use 0 as
         the scancode/keysym.
     */
-    if (SDL_TranslateUNICODE) {
+    if (SDL_TranslateUNICODE && state == SDL_PRESSED) {
+        [field_edit interpretKeyEvents:[NSArray arrayWithObject:event]];
         chars = [ event characters ];
         numChars = [ chars length ];
     } else {
@@ -281,7 +282,7 @@
 
         SDL_PrivateKeyboard (state, &key);
     }
-    else if (numChars == 1) {
+    else if (numChars >= 1) {
 
         key.scancode = [ event keyCode ];
         key.sym      = keymap [ key.scancode ];
@@ -289,11 +290,8 @@
         key.mod      = KMOD_NONE;
 
         SDL_PrivateKeyboard (state, &key);
-    }
-    else /* (numChars > 1) */ {
       
-        int i;
-        for (i = 0; i < numChars; i++) {
+        for (i = 1; i < numChars; i++) {
 
             key.scancode = 0;
             key.sym      = 0;
--- a/src/video/quartz/SDL_QuartzVideo.h	Wed Jul 11 07:47:47 2007 +0000
+++ b/src/video/quartz/SDL_QuartzVideo.h	Wed Jul 11 07:53:12 2007 +0000
@@ -99,6 +99,7 @@
     SDL_Rect           **client_mode_list; /* resolution list to pass back to client */
     SDLKey             keymap[256];        /* Mac OS X to SDL key mapping */
     Uint32             current_mods;       /* current keyboard modifiers, to track modifier state */
+    NSText             *field_edit;        /* a field editor for keyboard composition processing */
     Uint32             last_virtual_button;/* last virtual mouse button pressed */
     io_connect_t       power_connection;   /* used with IOKit to detect wake from sleep */
     Uint8              expect_mouse_up;    /* used to determine when to send mouse up events */
@@ -146,6 +147,7 @@
 #define client_mode_list (this->hidden->client_mode_list)
 #define keymap (this->hidden->keymap)
 #define current_mods (this->hidden->current_mods)
+#define field_edit (this->hidden->field_edit)
 #define last_virtual_button (this->hidden->last_virtual_button)
 #define power_connection (this->hidden->power_connection)
 #define expect_mouse_up (this->hidden->expect_mouse_up)
--- a/src/video/quartz/SDL_QuartzVideo.m	Wed Jul 11 07:47:47 2007 +0000
+++ b/src/video/quartz/SDL_QuartzVideo.m	Wed Jul 11 07:53:12 2007 +0000
@@ -169,6 +169,7 @@
 
 static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
 
+    NSRect r = NSMakeRect(0.0, 0.0, 0.0, 0.0);
     const char *env = NULL;
 
     /* Initialize the video settings; this data persists between mode switches */
@@ -202,6 +203,7 @@
     cursor_should_be_visible    = YES;
     cursor_visible              = YES;
     current_mods = 0;
+    field_edit =  [[NSTextView alloc] initWithFrame:r];
     
     if ( Gestalt(gestaltSystemVersion, &system_version) != noErr )
         system_version = 0;
@@ -1456,6 +1458,11 @@
         opengl_library = NULL;
     }
     this->gl_config.driver_loaded = 0;
+
+    if (field_edit) {
+        [field_edit release];
+        field_edit = NULL;
+    }
 }
 
 #if 0 /* Not used (apparently, it's really slow) */