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

Commit

Permalink
Browse files Browse the repository at this point in the history
Merged a cleaned up version of Jiang's code changes from Google Summe…
…r of Code 2009
  • Loading branch information
slouken committed Sep 19, 2009
1 parent daf95ac commit f08136a
Show file tree
Hide file tree
Showing 17 changed files with 605 additions and 14 deletions.
3 changes: 3 additions & 0 deletions build-scripts/showrev.sh
Expand Up @@ -9,4 +9,7 @@ if [ -d $srcdir/.svn ]; then
(svnversion -c 2>/dev/null || svnversion .) | \
sed -e 's,\([0-9]*\)[A-Z]*,\1,' \
-e 's,[0-9]*:\([0-9]*\)[A-Z]*,\1,'
else
cd $srcdir
git svn info | grep Revision | awk '{ print $2 }'
fi
17 changes: 17 additions & 0 deletions include/SDL_events.h
Expand Up @@ -60,6 +60,7 @@ typedef enum
SDL_WINDOWEVENT, /**< Window state change */
SDL_KEYDOWN, /**< Keys pressed */
SDL_KEYUP, /**< Keys released */
SDL_TEXTEDITING, /**< Keyboard text editing (composition) */
SDL_TEXTINPUT, /**< Keyboard text input */
SDL_MOUSEMOTION, /**< Mouse moved */
SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */
Expand Down Expand Up @@ -97,6 +98,7 @@ typedef enum
SDL_KEYDOWNMASK = SDL_EVENTMASK(SDL_KEYDOWN),
SDL_KEYUPMASK = SDL_EVENTMASK(SDL_KEYUP),
SDL_KEYEVENTMASK = SDL_EVENTMASK(SDL_KEYDOWN) | SDL_EVENTMASK(SDL_KEYUP),
SDL_TEXTEDITINGMASK = SDL_EVENTMASK(SDL_TEXTEDITING),
SDL_TEXTINPUTMASK = SDL_EVENTMASK(SDL_TEXTINPUT),
SDL_MOUSEMOTIONMASK = SDL_EVENTMASK(SDL_MOUSEMOTION),
SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN),
Expand Down Expand Up @@ -148,6 +150,20 @@ typedef struct SDL_KeyboardEvent
SDL_keysym keysym; /**< The key that was pressed or released */
} SDL_KeyboardEvent;

/**
* \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_TextInputEvent
*
Expand Down Expand Up @@ -350,6 +366,7 @@ typedef union SDL_Event
Uint8 type; /**< Event type, shared with all events */
SDL_WindowEvent window; /**< Window event data */
SDL_KeyboardEvent key; /**< Keyboard event data */
SDL_TextEditingEvent edit; /**< Text editing event data */
SDL_TextInputEvent text; /**< Text input event data */
SDL_MouseMotionEvent motion; /**< Mouse motion event data */
SDL_MouseButtonEvent button; /**< Mouse button event data */
Expand Down
28 changes: 28 additions & 0 deletions include/SDL_keyboard.h
Expand Up @@ -154,6 +154,34 @@ extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_scancode
*/
extern DECLSPEC const char *SDLCALL SDL_GetKeyName(SDLKey key);

/**
* \fn void SDL_StartTextInput(void)
*
* \brief Start accepting Unicode text input events.
*
* \sa SDL_StopTextInput()
* \sa SDL_SetTextInputRect()
*/
extern DECLSPEC void SDLCALL SDL_StartTextInput(void);

/**
* \fn void SDL_StopTextInput(void)
*
* \brief Stop receiving any text input events.
*
* \sa SDL_StartTextInput()
*/
extern DECLSPEC void SDLCALL SDL_StopTextInput(void);

/**
* \fn void SDL_SetTextInputRect(SDL_Rect *rect)
*
* \brief Set the rectangle used to type Unicode text inputs.
*
* \sa SDL_StartTextInput()
*/
extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Expand Down
15 changes: 14 additions & 1 deletion src/SDL_compat.c
Expand Up @@ -40,6 +40,7 @@ static SDL_GLContext *SDL_VideoContext = NULL;
static Uint32 SDL_VideoFlags = 0;
static char *wm_title = NULL;
static SDL_Surface *SDL_VideoIcon;
static int SDL_enabled_UNICODE = 0;

char *
SDL_AudioDriverName(char *namebuf, int maxlen)
Expand Down Expand Up @@ -1720,7 +1721,19 @@ SDL_GetKeyRepeat(int *delay, int *interval)
int
SDL_EnableUNICODE(int enable)
{
return SDL_EventState(SDL_TEXTINPUT, enable);
int previous = SDL_enabled_UNICODE;

switch (enable) {
case 1:
SDL_enabled_UNICODE = 1;
SDL_StartTextInput();
break;
case 0:
SDL_enabled_UNICODE = 0;
SDL_StopTextInput();
break;
}
return previous;
}

/* vi: set ts=4 sw=4 expandtab: */
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
5 changes: 5 additions & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -277,6 +277,11 @@ struct SDL_VideoDevice
/* Suspend the screensaver */
void (*SuspendScreenSaver) (_THIS);

/* Text input */
void (*StartTextInput) (_THIS);
void (*StopTextInput) (_THIS);
void (*SetTextInputRect) (_THIS, SDL_Rect *rect);

/* * * */
/* Data common to all drivers */
SDL_bool suspend_screensaver;
Expand Down
28 changes: 28 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -3233,4 +3233,32 @@ SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info)
return (_this->GetWindowWMInfo(_this, window, info));
}

void
SDL_StartTextInput(void)
{
if (_this->StartTextInput) {
_this->StartTextInput(_this);
}
SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
}

void
SDL_StopTextInput(void)
{
if (_this->StopTextInput) {
_this->StopTextInput(_this);
}
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
}

void
SDL_SetTextInputRect(SDL_Rect *rect)
{
if (_this->SetTextInputRect) {
_this->SetTextInputRect(_this, rect);
}
}

/* vi: set ts=4 sw=4 expandtab: */
4 changes: 4 additions & 0 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -193,6 +193,10 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
Cocoa_HandleKeyEvent(_this, event);
/* Fall through to pass event to NSApp; er, nevermind... */
/* FIXME: Find a way to stop the beeping, using delegate */

/* Add to support system-wide keyboard shortcuts like CMD+Space */
if (([event modifierFlags] & NSCommandKeyMask) || [event type] == NSFlagsChanged)
[NSApp sendEvent: event];
break;
default:
[NSApp sendEvent:event];
Expand Down
4 changes: 4 additions & 0 deletions src/video/cocoa/SDL_cocoakeyboard.h
Expand Up @@ -28,6 +28,10 @@ extern void Cocoa_InitKeyboard(_THIS);
extern void Cocoa_HandleKeyEvent(_THIS, NSEvent * event);
extern void Cocoa_QuitKeyboard(_THIS);

extern void Cocoa_StartTextInput(_THIS);
extern void Cocoa_StopTextInput(_THIS);
extern void Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect);

#endif /* _SDL_cocoakeyboard_h */

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit f08136a

Please sign in to comment.