Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Add SDL_TEXTEDTING event to inform application about marked text.

  • Loading branch information
jjgod committed Jul 1, 2009
1 parent c7556a4 commit a6091bd43b90f341e30b6f44ed3418407b03de09
Showing with 53 additions and 3 deletions.
  1. +19 −2 include/SDL_events.h
  2. +18 −0 src/events/SDL_keyboard.c
  3. +3 −0 src/events/SDL_keyboard_c.h
  4. +2 −0 src/video/cocoa/SDL_cocoakeyboard.m
  5. +2 −1 test/Makefile.in
  6. +9 −0 test/testime.c
@@ -74,9 +74,10 @@ typedef enum
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 @@ typedef enum
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

@@ -162,6 +164,20 @@ typedef struct SDL_TextInputEvent
SDL_WindowID windowID; /**< The window with keyboard focus, if any */
} 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
*
@@ -358,6 +374,7 @@ typedef union SDL_Event
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;
@@ -852,6 +852,24 @@ SDL_SendKeyboardText(int index, const char *text)
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)
{
@@ -81,6 +81,9 @@ extern int SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode);
/* 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);

@@ -130,6 +130,8 @@ - (void) setMarkedText:(id) aString
_selectedRange = selRange;
_markedRange = NSMakeRange(0, [aString length]);

SDL_SendEditingText([aString UTF8String], selRange.location, selRange.length);

NSLog(@"setMarkedText: %@, (%d, %d)", _markedText,
selRange.location, selRange.length);
}
@@ -147,7 +147,8 @@ testmmousetablet$(EXE): $(srcdir)/testmmousetablet.c
$(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)
@@ -111,6 +111,15 @@ int main(int argc, char *argv[])
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;

0 comments on commit a6091bd

Please sign in to comment.