changeset 3132:88861448961f gsoc2009_IME

Add SDL_TEXTEDTING event to inform application about marked text.
author Jiang Jiang <gzjjgod@gmail.com>
date Wed, 01 Jul 2009 07:33:58 +0000
parents 009bd8f81947
children 84119fe89d26
files include/SDL_events.h src/events/SDL_keyboard.c src/events/SDL_keyboard_c.h src/video/cocoa/SDL_cocoakeyboard.m test/Makefile.in test/testime.c
diffstat 6 files changed, 53 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_events.h	Wed Jul 01 05:52:17 2009 +0000
+++ b/include/SDL_events.h	Wed Jul 01 07:33:58 2009 +0000
@@ -74,9 +74,10 @@
     SDL_SYSWMEVENT,             /**< System specific event */
     SDL_PROXIMITYIN,            /**< Proximity In event */
     SDL_PROXIMITYOUT,           /**< Proximity Out event */
-    SDL_EVENT_RESERVED1,        /**< Reserved for future use... */
+    SDL_EVENT_RESERVED1,
     SDL_EVENT_RESERVED2,
     SDL_EVENT_RESERVED3,
+    SDL_TEXTEDITING,            /**< Reserved for future use... */
     /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
     SDL_USEREVENT = 24,
     /* This last event is only for bounding internal arrays
@@ -116,7 +117,8 @@
     SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT),
     SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT),
     SDL_PROXIMITYINMASK = SDL_EVENTMASK(SDL_PROXIMITYIN),
-    SDL_PROXIMITYOUTMASK = SDL_EVENTMASK(SDL_PROXIMITYOUT)
+    SDL_PROXIMITYOUTMASK = SDL_EVENTMASK(SDL_PROXIMITYOUT),
+    SDL_TEXTEDITINGMASK = SDL_EVENTMASK(SDL_TEXTEDITING)
 } SDL_EventMask;
 #define SDL_ALLEVENTS		0xFFFFFFFF
 
@@ -163,6 +165,20 @@
 } SDL_TextInputEvent;
 
 /**
+ * \struct SDL_TextEditingEvent
+ *
+ * \brief Keyboard text editing event structure (event.edit.*)
+ */
+#define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
+typedef struct SDL_TextEditingEvent
+{
+    Uint8 type;                                 /**< SDL_TEXTEDITING */
+    char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];  /**< The editing text */
+    int start;                                  /**< The start cursor of selected editing text */
+    int length;                                 /**< The length of selected editing text */
+} SDL_TextEditingEvent;
+
+/**
  * \struct SDL_MouseMotionEvent
  *
  * \brief Mouse motion event structure (event.motion.*)
@@ -358,6 +374,7 @@
     SDL_UserEvent user;             /**< Custom event data */
     SDL_SysWMEvent syswm;           /**< System dependent window event data */
     SDL_ProximityEvent proximity;   /**< Proximity In or Out event */
+    SDL_TextEditingEvent edit;      /**< Text editing event data */
 
     /* Temporarily here for backwards compatibility */
     SDL_ActiveEvent active;
--- a/src/events/SDL_keyboard.c	Wed Jul 01 05:52:17 2009 +0000
+++ b/src/events/SDL_keyboard.c	Wed Jul 01 07:33:58 2009 +0000
@@ -852,6 +852,24 @@
     return (posted);
 }
 
+int
+SDL_SendEditingText(const char *text, int start, int length)
+{
+    int posted;
+
+    /* Post the event, if desired */
+    posted = 0;
+    if (SDL_ProcessEvents[SDL_TEXTEDITING] == SDL_ENABLE) {
+        SDL_Event event;
+        event.edit.type = SDL_TEXTEDITING;
+        event.edit.start = start;
+        event.edit.length = length;
+        SDL_strlcpy(event.edit.text, text, SDL_arraysize(event.text.text));
+        posted = (SDL_PushEvent(&event) > 0);
+    }
+    return (posted);
+}
+
 void
 SDL_KeyboardQuit(void)
 {
--- a/src/events/SDL_keyboard_c.h	Wed Jul 01 05:52:17 2009 +0000
+++ b/src/events/SDL_keyboard_c.h	Wed Jul 01 07:33:58 2009 +0000
@@ -81,6 +81,9 @@
 /* Send keyboard text input for a keyboard at an index */
 extern int SDL_SendKeyboardText(int index, const char *text);
 
+/* Send editing text for selected range from start to end */
+extern int SDL_SendEditingText(const char *text, int start, int end);
+
 /* Shutdown the keyboard subsystem */
 extern void SDL_KeyboardQuit(void);
 
--- a/src/video/cocoa/SDL_cocoakeyboard.m	Wed Jul 01 05:52:17 2009 +0000
+++ b/src/video/cocoa/SDL_cocoakeyboard.m	Wed Jul 01 07:33:58 2009 +0000
@@ -130,6 +130,8 @@
     _selectedRange = selRange;
     _markedRange = NSMakeRange(0, [aString length]);
 
+    SDL_SendEditingText([aString UTF8String], selRange.location, selRange.length);
+
     NSLog(@"setMarkedText: %@, (%d, %d)", _markedText,
           selRange.location, selRange.length);
 }
--- a/test/Makefile.in	Wed Jul 01 05:52:17 2009 +0000
+++ b/test/Makefile.in	Wed Jul 01 07:33:58 2009 +0000
@@ -147,7 +147,8 @@
 	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
 
 testime$(EXE): $(srcdir)/testime.c
-	$(CC) -o $@ $? $(CFLAGS) -L../build/.libs $(LIBS) -lSDL_ttf
+	$(CC) -o $@ $? -I../include $(CFLAGS) -L../build/.libs $(LIBS) -lSDL_ttf
+	install_name_tool -change /usr/local/lib/libSDL-1.3.0.dylib ../build/.libs/libSDL-1.3.0.dylib $@
 
 clean:
 	rm -f $(TARGETS)
--- a/test/testime.c	Wed Jul 01 05:52:17 2009 +0000
+++ b/test/testime.c	Wed Jul 01 07:33:58 2009 +0000
@@ -111,6 +111,15 @@
             SDL_StartTextInput(&markedRect);
             break;
 
+        case SDL_TEXTEDITING:
+            fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n",
+                    event.edit.text, event.edit.start, event.edit.length);
+
+            SDL_FillRect(screen, &markedRect, backColor);
+            render_text(screen, font, event.edit.text, markedRect.x, markedRect.y, textColor);
+            SDL_Flip(screen);
+            break;
+
         case SDL_QUIT:
             done = 1;
             break;