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

Further polish API, fix crash in test program.

  • Loading branch information
jjgod committed Aug 6, 2009
1 parent 4478964 commit 3ba1c8a1e3472b1949e027b076ecf22247527014
@@ -1468,14 +1468,14 @@ 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_WindowID windowID)
* \fn void SDL_StartTextInput(void)
*
* \brief Start accepting Unicode text input events in given window.
* \brief Start accepting Unicode text input events.
*
* \sa SDL_StopTextInput()
* \sa SDL_SetTextInputRect()
*/
extern DECLSPEC void SDLCALL SDL_StartTextInput(SDL_WindowID windowID);
extern DECLSPEC void SDLCALL SDL_StartTextInput(void);

/**
* \fn void SDL_StopTextInput(void)
@@ -1495,6 +1495,13 @@ extern DECLSPEC void SDLCALL SDL_StopTextInput(void);
*/
extern DECLSPEC void SDLCALL SDL_SetTextInputRect(SDL_Rect *rect);

/**
* \fn SDL_WindowID SDL_GetFocusWindow(void)
*
* \brief Get focused window.
*/
extern DECLSPEC SDL_WindowID SDLCALL SDL_GetFocusWindow(void);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
@@ -278,7 +278,7 @@ struct SDL_VideoDevice
void (*SuspendScreenSaver) (_THIS);

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

@@ -428,7 +428,6 @@ extern void SDL_OnWindowHidden(SDL_Window * window);
extern void SDL_OnWindowResized(SDL_Window * window);
extern void SDL_OnWindowFocusGained(SDL_Window * window);
extern void SDL_OnWindowFocusLost(SDL_Window * window);
extern SDL_WindowID SDL_GetFocusWindow(void);

#endif /* _SDL_sysvideo_h */

@@ -3068,12 +3068,10 @@ SDL_GetWindowWMInfo(SDL_WindowID windowID, struct SDL_SysWMinfo *info)
}

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

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

@@ -28,7 +28,7 @@ extern void Cocoa_InitKeyboard(_THIS);
extern void Cocoa_HandleKeyEvent(_THIS, NSEvent * event);
extern void Cocoa_QuitKeyboard(_THIS);

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

@@ -54,7 +54,7 @@
#define NX_DEVICERCTLKEYMASK 0x00002000
#endif

@interface SDLTranslatorResponder : NSTextView
@interface SDLTranslatorResponder : NSView <NSTextInput>
{
NSString *_markedText;
NSRange _markedRange;
@@ -97,7 +97,6 @@ - (void) insertText:(id) aString

- (void) doCommandBySelector:(SEL) myselector
{
NSLog(@"doCommandBySelector, passed down");
[super doCommandBySelector: myselector];
}

@@ -152,7 +151,8 @@ - (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.h,
_inputRect.w, _inputRect.h);

NSLog(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
theRange.location, theRange.length, windowHeight,
@@ -584,15 +584,9 @@ - (NSArray *) validAttributesForMarkedText
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
SDL_Keyboard keyboard;
NSAutoreleasePool *pool;

pool = [[NSAutoreleasePool alloc] init];
data->fieldEdit = [[SDLTranslatorResponder alloc] initWithFrame:NSMakeRect(0.0, 0.0, 0.0, 0.0)];
[pool release];

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 */
@@ -605,20 +599,25 @@ - (NSArray *) validAttributesForMarkedText
}

void
Cocoa_StartTextInput(_THIS, SDL_Window *window)
Cocoa_StartTextInput(_THIS)
{
SDL_VideoData *videoData = (SDL_VideoData *) _this->driverdata;
SDL_WindowData *windowData = (SDL_WindowData *) window->driverdata;
NSView *parentView = [windowData->window contentView];
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSView *parentView = [[NSApp keyWindow] contentView];

data->fieldEdit = [[SDLTranslatorResponder alloc] initWithFrame:NSMakeRect(0.0, 0.0, 0.0, 0.0)];
[data->fieldEdit setKeyboard: data->keyboard];

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

[pool release];

SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE);
SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE);
}
@@ -636,7 +635,12 @@ - (NSArray *) validAttributesForMarkedText
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[data->fieldEdit removeFromSuperview];
[data->fieldEdit release];
data->fieldEdit = nil;
[pool release];

SDL_EventState(SDL_TEXTINPUT, SDL_IGNORE);
SDL_EventState(SDL_TEXTEDITING, SDL_IGNORE);
}
@@ -676,7 +680,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");
[data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
#if 0
text = [[event characters] UTF8String];
@@ -706,10 +709,6 @@ - (NSArray *) validAttributesForMarkedText
NSAutoreleasePool *pool;

SDL_DelKeyboard(data->keyboard);

pool = [[NSAutoreleasePool alloc] init];
[data->fieldEdit release];
[pool release];
}

/* vi: set ts=4 sw=4 expandtab: */
@@ -248,6 +248,11 @@ - (void) setFrame:(NSRect)frame;
CGReleaseDisplayFadeReservation(fade_token);
}

NSRect frame = [[NSScreen mainScreen] frame];
NSLog(@"mainScreen frame: %gx%g", frame.size.width, frame.size.height);

[[NSApp mainWindow] makeKeyAndOrderFront: nil];

/*
There is a bug in Cocoa where NSScreen doesn't synchronize
with CGDirectDisplay, so the main screen's frame is wrong.
@@ -65,6 +65,7 @@ void InitVideo(int argc, char *argv[])

void CleanupVideo()
{
SDL_StopTextInput();
TTF_CloseFont(font);
TTF_Quit();
}
@@ -82,6 +83,8 @@ void InitInput()
text[0] = 0;
markedRect = textRect;
markedText = NULL;

SDL_StartTextInput();
}

static void RenderText(SDL_Surface *sur,
@@ -115,6 +118,8 @@ void Redraw()
if (markedRect.w < 0)
{
SDL_Flip(screen);
// Stop text input because we cannot hold any more characters
SDL_StopTextInput();
return;
}

@@ -139,7 +144,7 @@ void Redraw()

SDL_Flip(screen);

SDL_StartTextInput(&markedRect);
SDL_SetTextInputRect(&markedRect);
}

void

0 comments on commit 3ba1c8a

Please sign in to comment.