mirror of https://github.com/encounter/SDL.git
Cocoa: Use NSTextInputClient instead of NSTextInput for text input handling. The latter was deprecated in OS X 10.6.
This commit is contained in:
parent
0c463d770b
commit
a2235d7b29
|
@ -33,7 +33,7 @@
|
||||||
/*#define DEBUG_IME NSLog */
|
/*#define DEBUG_IME NSLog */
|
||||||
#define DEBUG_IME(...)
|
#define DEBUG_IME(...)
|
||||||
|
|
||||||
@interface SDLTranslatorResponder : NSView <NSTextInput> {
|
@interface SDLTranslatorResponder : NSView <NSTextInputClient> {
|
||||||
NSString *_markedText;
|
NSString *_markedText;
|
||||||
NSRange _markedRange;
|
NSRange _markedRange;
|
||||||
NSRange _selectedRange;
|
NSRange _selectedRange;
|
||||||
|
@ -50,8 +50,10 @@
|
||||||
_inputRect = *rect;
|
_inputRect = *rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) insertText:(id) aString
|
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
|
||||||
{
|
{
|
||||||
|
/* TODO: Make use of replacementRange? */
|
||||||
|
|
||||||
const char *str;
|
const char *str;
|
||||||
|
|
||||||
DEBUG_IME(@"insertText: %@", aString);
|
DEBUG_IME(@"insertText: %@", aString);
|
||||||
|
@ -67,6 +69,14 @@
|
||||||
SDL_SendKeyboardText(str);
|
SDL_SendKeyboardText(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)insertText:(id)insertString
|
||||||
|
{
|
||||||
|
/* This method is part of NSTextInput and not NSTextInputClient, but
|
||||||
|
* apparently it still might be called in OS X 10.5 and can cause beeps if
|
||||||
|
* the implementation is missing: http://crbug.com/47890 */
|
||||||
|
[self insertText:insertString replacementRange:NSMakeRange(0, 0)];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)doCommandBySelector:(SEL)myselector
|
- (void)doCommandBySelector:(SEL)myselector
|
||||||
{
|
{
|
||||||
/* No need to do anything since we are not using Cocoa
|
/* No need to do anything since we are not using Cocoa
|
||||||
|
@ -90,8 +100,7 @@
|
||||||
return _selectedRange;
|
return _selectedRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setMarkedText:(id) aString
|
- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange;
|
||||||
selectedRange:(NSRange) selRange
|
|
||||||
{
|
{
|
||||||
if ([aString isKindOfClass: [NSAttributedString class]]) {
|
if ([aString isKindOfClass: [NSAttributedString class]]) {
|
||||||
aString = [aString string];
|
aString = [aString string];
|
||||||
|
@ -107,11 +116,11 @@
|
||||||
_markedText = [aString retain];
|
_markedText = [aString retain];
|
||||||
}
|
}
|
||||||
|
|
||||||
_selectedRange = selRange;
|
_selectedRange = selectedRange;
|
||||||
_markedRange = NSMakeRange(0, [aString length]);
|
_markedRange = NSMakeRange(0, [aString length]);
|
||||||
|
|
||||||
SDL_SendEditingText([aString UTF8String],
|
SDL_SendEditingText([aString UTF8String],
|
||||||
selRange.location, selRange.length);
|
selectedRange.location, selectedRange.length);
|
||||||
|
|
||||||
DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText,
|
DEBUG_IME(@"setMarkedText: %@, (%d, %d)", _markedText,
|
||||||
selRange.location, selRange.length);
|
selRange.location, selRange.length);
|
||||||
|
@ -125,7 +134,7 @@
|
||||||
SDL_SendEditingText("", 0, 0);
|
SDL_SendEditingText("", 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRect) firstRectForCharacterRange: (NSRange) theRange
|
- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange;
|
||||||
{
|
{
|
||||||
NSWindow *window = [self window];
|
NSWindow *window = [self window];
|
||||||
NSRect contentRect = [window contentRectForFrameRect:[window frame]];
|
NSRect contentRect = [window contentRectForFrameRect:[window frame]];
|
||||||
|
@ -133,17 +142,26 @@
|
||||||
NSRect rect = NSMakeRect(_inputRect.x, windowHeight - _inputRect.y - _inputRect.h,
|
NSRect rect = NSMakeRect(_inputRect.x, windowHeight - _inputRect.y - _inputRect.h,
|
||||||
_inputRect.w, _inputRect.h);
|
_inputRect.w, _inputRect.h);
|
||||||
|
|
||||||
|
if (actualRange) {
|
||||||
|
*actualRange = aRange;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG_IME(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
|
DEBUG_IME(@"firstRectForCharacterRange: (%d, %d): windowHeight = %g, rect = %@",
|
||||||
theRange.location, theRange.length, windowHeight,
|
aRange.location, aRange.length, windowHeight,
|
||||||
NSStringFromRect(rect));
|
NSStringFromRect(rect));
|
||||||
|
|
||||||
|
if ([[self window] respondsToSelector:@selector(convertRectToScreen:)]) {
|
||||||
|
rect = [[self window] convertRectToScreen:rect];
|
||||||
|
} else {
|
||||||
rect.origin = [[self window] convertBaseToScreen:rect.origin];
|
rect.origin = [[self window] convertBaseToScreen:rect.origin];
|
||||||
|
}
|
||||||
|
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSAttributedString *) attributedSubstringFromRange: (NSRange) theRange
|
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange;
|
||||||
{
|
{
|
||||||
DEBUG_IME(@"attributedSubstringFromRange: (%d, %d)", theRange.location, theRange.length);
|
DEBUG_IME(@"attributedSubstringFromRange: (%d, %d)", aRange.location, aRange.length);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue