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

Commit

Permalink
Add SDL_TEXTEDTING event to inform application about marked text.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgod committed Jul 1, 2009
1 parent c7556a4 commit a6091bd
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
21 changes: 19 additions & 2 deletions include/SDL_events.h
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/events/SDL_keyboard.c
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions src/events/SDL_keyboard_c.h
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/video/cocoa/SDL_cocoakeyboard.m
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion test/Makefile.in
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/testime.c
Expand Up @@ -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;
Expand Down

0 comments on commit a6091bd

Please sign in to comment.