Add SDL_TEXTEDTING event to inform application about marked text. gsoc2009_IME
authorJiang Jiang <gzjjgod@gmail.com>
Wed, 01 Jul 2009 07:33:58 +0000
branchgsoc2009_IME
changeset 313288861448961f
parent 3131 009bd8f81947
child 3133 84119fe89d26
Add SDL_TEXTEDTING event to inform application about marked text.
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
     1.1 --- a/include/SDL_events.h	Wed Jul 01 05:52:17 2009 +0000
     1.2 +++ b/include/SDL_events.h	Wed Jul 01 07:33:58 2009 +0000
     1.3 @@ -74,9 +74,10 @@
     1.4      SDL_SYSWMEVENT,             /**< System specific event */
     1.5      SDL_PROXIMITYIN,            /**< Proximity In event */
     1.6      SDL_PROXIMITYOUT,           /**< Proximity Out event */
     1.7 -    SDL_EVENT_RESERVED1,        /**< Reserved for future use... */
     1.8 +    SDL_EVENT_RESERVED1,
     1.9      SDL_EVENT_RESERVED2,
    1.10      SDL_EVENT_RESERVED3,
    1.11 +    SDL_TEXTEDITING,            /**< Reserved for future use... */
    1.12      /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
    1.13      SDL_USEREVENT = 24,
    1.14      /* This last event is only for bounding internal arrays
    1.15 @@ -116,7 +117,8 @@
    1.16      SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT),
    1.17      SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT),
    1.18      SDL_PROXIMITYINMASK = SDL_EVENTMASK(SDL_PROXIMITYIN),
    1.19 -    SDL_PROXIMITYOUTMASK = SDL_EVENTMASK(SDL_PROXIMITYOUT)
    1.20 +    SDL_PROXIMITYOUTMASK = SDL_EVENTMASK(SDL_PROXIMITYOUT),
    1.21 +    SDL_TEXTEDITINGMASK = SDL_EVENTMASK(SDL_TEXTEDITING)
    1.22  } SDL_EventMask;
    1.23  #define SDL_ALLEVENTS		0xFFFFFFFF
    1.24  
    1.25 @@ -163,6 +165,20 @@
    1.26  } SDL_TextInputEvent;
    1.27  
    1.28  /**
    1.29 + * \struct SDL_TextEditingEvent
    1.30 + *
    1.31 + * \brief Keyboard text editing event structure (event.edit.*)
    1.32 + */
    1.33 +#define SDL_TEXTEDITINGEVENT_TEXT_SIZE (32)
    1.34 +typedef struct SDL_TextEditingEvent
    1.35 +{
    1.36 +    Uint8 type;                                 /**< SDL_TEXTEDITING */
    1.37 +    char text[SDL_TEXTEDITINGEVENT_TEXT_SIZE];  /**< The editing text */
    1.38 +    int start;                                  /**< The start cursor of selected editing text */
    1.39 +    int length;                                 /**< The length of selected editing text */
    1.40 +} SDL_TextEditingEvent;
    1.41 +
    1.42 +/**
    1.43   * \struct SDL_MouseMotionEvent
    1.44   *
    1.45   * \brief Mouse motion event structure (event.motion.*)
    1.46 @@ -358,6 +374,7 @@
    1.47      SDL_UserEvent user;             /**< Custom event data */
    1.48      SDL_SysWMEvent syswm;           /**< System dependent window event data */
    1.49      SDL_ProximityEvent proximity;   /**< Proximity In or Out event */
    1.50 +    SDL_TextEditingEvent edit;      /**< Text editing event data */
    1.51  
    1.52      /* Temporarily here for backwards compatibility */
    1.53      SDL_ActiveEvent active;
     2.1 --- a/src/events/SDL_keyboard.c	Wed Jul 01 05:52:17 2009 +0000
     2.2 +++ b/src/events/SDL_keyboard.c	Wed Jul 01 07:33:58 2009 +0000
     2.3 @@ -852,6 +852,24 @@
     2.4      return (posted);
     2.5  }
     2.6  
     2.7 +int
     2.8 +SDL_SendEditingText(const char *text, int start, int length)
     2.9 +{
    2.10 +    int posted;
    2.11 +
    2.12 +    /* Post the event, if desired */
    2.13 +    posted = 0;
    2.14 +    if (SDL_ProcessEvents[SDL_TEXTEDITING] == SDL_ENABLE) {
    2.15 +        SDL_Event event;
    2.16 +        event.edit.type = SDL_TEXTEDITING;
    2.17 +        event.edit.start = start;
    2.18 +        event.edit.length = length;
    2.19 +        SDL_strlcpy(event.edit.text, text, SDL_arraysize(event.text.text));
    2.20 +        posted = (SDL_PushEvent(&event) > 0);
    2.21 +    }
    2.22 +    return (posted);
    2.23 +}
    2.24 +
    2.25  void
    2.26  SDL_KeyboardQuit(void)
    2.27  {
     3.1 --- a/src/events/SDL_keyboard_c.h	Wed Jul 01 05:52:17 2009 +0000
     3.2 +++ b/src/events/SDL_keyboard_c.h	Wed Jul 01 07:33:58 2009 +0000
     3.3 @@ -81,6 +81,9 @@
     3.4  /* Send keyboard text input for a keyboard at an index */
     3.5  extern int SDL_SendKeyboardText(int index, const char *text);
     3.6  
     3.7 +/* Send editing text for selected range from start to end */
     3.8 +extern int SDL_SendEditingText(const char *text, int start, int end);
     3.9 +
    3.10  /* Shutdown the keyboard subsystem */
    3.11  extern void SDL_KeyboardQuit(void);
    3.12  
     4.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Wed Jul 01 05:52:17 2009 +0000
     4.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Wed Jul 01 07:33:58 2009 +0000
     4.3 @@ -130,6 +130,8 @@
     4.4      _selectedRange = selRange;
     4.5      _markedRange = NSMakeRange(0, [aString length]);
     4.6  
     4.7 +    SDL_SendEditingText([aString UTF8String], selRange.location, selRange.length);
     4.8 +
     4.9      NSLog(@"setMarkedText: %@, (%d, %d)", _markedText,
    4.10            selRange.location, selRange.length);
    4.11  }
     5.1 --- a/test/Makefile.in	Wed Jul 01 05:52:17 2009 +0000
     5.2 +++ b/test/Makefile.in	Wed Jul 01 07:33:58 2009 +0000
     5.3 @@ -147,7 +147,8 @@
     5.4  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
     5.5  
     5.6  testime$(EXE): $(srcdir)/testime.c
     5.7 -	$(CC) -o $@ $? $(CFLAGS) -L../build/.libs $(LIBS) -lSDL_ttf
     5.8 +	$(CC) -o $@ $? -I../include $(CFLAGS) -L../build/.libs $(LIBS) -lSDL_ttf
     5.9 +	install_name_tool -change /usr/local/lib/libSDL-1.3.0.dylib ../build/.libs/libSDL-1.3.0.dylib $@
    5.10  
    5.11  clean:
    5.12  	rm -f $(TARGETS)
     6.1 --- a/test/testime.c	Wed Jul 01 05:52:17 2009 +0000
     6.2 +++ b/test/testime.c	Wed Jul 01 07:33:58 2009 +0000
     6.3 @@ -111,6 +111,15 @@
     6.4              SDL_StartTextInput(&markedRect);
     6.5              break;
     6.6  
     6.7 +        case SDL_TEXTEDITING:
     6.8 +            fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n",
     6.9 +                    event.edit.text, event.edit.start, event.edit.length);
    6.10 +
    6.11 +            SDL_FillRect(screen, &markedRect, backColor);
    6.12 +            render_text(screen, font, event.edit.text, markedRect.x, markedRect.y, textColor);
    6.13 +            SDL_Flip(screen);
    6.14 +            break;
    6.15 +
    6.16          case SDL_QUIT:
    6.17              done = 1;
    6.18              break;