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

Commit

Permalink
Update API, first step: make it build
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgod committed Aug 6, 2009
1 parent 787cd86 commit 4478964
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 20 deletions.
27 changes: 24 additions & 3 deletions include/SDL_video.h
Expand Up @@ -1468,11 +1468,32 @@ extern DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_WindowID windowID);
extern DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context);

/**
* \fn void SDL_StartTextInput(SDL_rect *rect)
* \fn void SDL_StartTextInput(SDL_WindowID windowID)
*
* \brief Start Unicode text input within the given rectangle.
* \brief Start accepting Unicode text input events in given window.
*
* \sa SDL_StopTextInput()
* \sa SDL_SetTextInputRect()
*/
extern DECLSPEC void SDLCALL SDL_StartTextInput(SDL_WindowID windowID);

/**
* \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_StartTextInput(SDL_Rect *rect);
extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Expand Down
4 changes: 3 additions & 1 deletion src/video/SDL_sysvideo.h
Expand Up @@ -278,7 +278,9 @@ struct SDL_VideoDevice
void (*SuspendScreenSaver) (_THIS);

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

/* * * */
/* Data common to all drivers */
Expand Down
22 changes: 20 additions & 2 deletions src/video/SDL_video.c
Expand Up @@ -3068,10 +3068,28 @@ SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info)
}

void
SDL_StartTextInput(SDL_Rect *rect)
SDL_StartTextInput(SDL_WindowID windowID)
{
SDL_Window *window = SDL_GetWindowFromID(windowID);

if (_this->StartTextInput) {
_this->StartTextInput(_this, rect);
_this->StartTextInput(_this, window);
}
}

void
SDL_StopTextInput(void)
{
if (_this->StopTextInput) {
_this->StopTextInput(_this);
}
}

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

Expand Down
4 changes: 3 additions & 1 deletion src/video/cocoa/SDL_cocoakeyboard.h
Expand Up @@ -28,7 +28,9 @@ extern void Cocoa_InitKeyboard(_THIS);
extern void Cocoa_HandleKeyEvent(_THIS, NSEvent * event);
extern void Cocoa_QuitKeyboard(_THIS);

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

#endif /* _SDL_cocoakeyboard_h */

Expand Down
55 changes: 42 additions & 13 deletions src/video/cocoa/SDL_cocoakeyboard.m
Expand Up @@ -59,17 +59,24 @@ @interface SDLTranslatorResponder : NSTextView
NSString *_markedText;
NSRange _markedRange;
NSRange _selectedRange;
SDL_Rect inputRect;
SDL_Rect _inputRect;
int _keyboard;
}
- (void) doCommandBySelector:(SEL)myselector;
- (void) setInputRect:(SDL_Rect *) rect;
- (void) setKeyboard:(int) keyboard;
@end

@implementation SDLTranslatorResponder

- (void) setKeyboard:(int) keyboard
{
_keyboard = keyboard;
}

- (void) setInputRect:(SDL_Rect *) rect
{
inputRect = *rect;
_inputRect = *rect;
}

- (void) insertText:(id) aString
Expand All @@ -85,7 +92,7 @@ - (void) insertText:(id) aString
else
str = [aString UTF8String];

SDL_SendKeyboardText(0, str);
SDL_SendKeyboardText(_keyboard, str);
}

- (void) doCommandBySelector:(SEL) myselector
Expand Down Expand Up @@ -145,7 +152,7 @@ - (void) unmarkText
- (NSRect) firstRectForCharacterRange: (NSRange) theRange
{
float windowHeight = [[self window] frame].size.height;
NSRect rect = NSMakeRect(inputRect.x, windowHeight - inputRect.y, inputRect.w, inputRect.h);
NSRect rect = NSMakeRect(_inputRect.x, windowHeight - _inputRect.y, _inputRect.w, _inputRect.h);

NSLog(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
theRange.location, theRange.length, windowHeight,
Expand Down Expand Up @@ -585,6 +592,7 @@ - (NSArray *) validAttributesForMarkedText

SDL_zero(keyboard);
data->keyboard = SDL_AddKeyboard(&keyboard, -1);
[data->fieldEdit setKeyboard: data->keyboard];
UpdateKeymap(data);

/* Set our own names for the platform-dependent but layout-independent keys */
Expand All @@ -597,14 +605,42 @@ - (NSArray *) validAttributesForMarkedText
}

void
Cocoa_StartTextInput(_THIS, SDL_Rect *rect)
Cocoa_StartTextInput(_THIS, SDL_Window *window)
{
SDL_VideoData *videoData = (SDL_VideoData *) _this->driverdata;
SDL_WindowData *windowData = (SDL_WindowData *) window->driverdata;
NSView *parentView = [windowData->window contentView];

if (! [[videoData->fieldEdit superview] isEqual: parentView])
{
NSLog(@"add fieldEdit to window contentView");
[videoData->fieldEdit removeFromSuperview];
[parentView addSubview: videoData->fieldEdit];
[windowData->window makeFirstResponder: videoData->fieldEdit];
}

SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
}

void
Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;

NSLog(@"StartTextInput: (%d, %d) (w=%d, h=%d)", rect->x, rect->y, rect->w, rect->h);
[data->fieldEdit setInputRect: rect];
}

void
Cocoa_StopTextInput(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;

[data->fieldEdit removeFromSuperview];
SDL_EventState(SDL_TEXTINPUT, SDL_IGNORE);
SDL_EventState(SDL_TEXTEDITING, SDL_IGNORE);
}

void
Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
{
Expand Down Expand Up @@ -641,13 +677,6 @@ - (NSArray *) validAttributesForMarkedText
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
/* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */
NSLog(@"interpretKeyEvents");
if (! [[data->fieldEdit superview] isEqual: [[event window] contentView]])
{
NSLog(@"add fieldEdit to window contentView");
[data->fieldEdit removeFromSuperview];
[[[event window] contentView] addSubview: data->fieldEdit];
[[event window] makeFirstResponder: data->fieldEdit];
}
[data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
#if 0
text = [[event characters] UTF8String];
Expand Down
2 changes: 2 additions & 0 deletions src/video/cocoa/SDL_cocoavideo.m
Expand Up @@ -103,6 +103,8 @@
#endif

device->StartTextInput = Cocoa_StartTextInput;
device->StopTextInput = Cocoa_StopTextInput;
device->SetTextInputRect = Cocoa_SetTextInputRect;

device->free = Cocoa_DeleteDevice;

Expand Down

0 comments on commit 4478964

Please sign in to comment.