diff options
author | Jens Verwiebe <info@jensverwiebe.de> | 2011-11-23 11:39:59 +0400 |
---|---|---|
committer | Jens Verwiebe <info@jensverwiebe.de> | 2011-11-23 11:39:59 +0400 |
commit | 4c43a14b9f61e9e8a049299278773699fc6d7b1d (patch) | |
tree | 923ac86a1f66e71a23835494c58884c3f3b9a610 /intern | |
parent | 086e4ed825b7938400f14999acc7faf5f2594c00 (diff) |
OSX: Fix more UTF8 issues, todo: use correct font
Diffstat (limited to 'intern')
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.mm | 6 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_WindowCocoa.mm | 124 |
2 files changed, 122 insertions, 8 deletions
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 03c3427045d..12a732e59ef 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -1765,7 +1765,7 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const return NULL; } - pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSISOLatin1StringEncoding]; + pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); @@ -1774,7 +1774,7 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const return NULL; } - strncpy((char*)temp_buff, [textPasted cStringUsingEncoding:NSISOLatin1StringEncoding], pastedTextSize); + strncpy((char*)temp_buff, [textPasted cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize); temp_buff[pastedTextSize] = '\0'; @@ -1806,7 +1806,7 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const [pasteBoard declareTypes:supportedTypes owner:nil]; - textToCopy = [NSString stringWithCString:buffer encoding:NSISOLatin1StringEncoding]; + textToCopy = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding]; [pasteBoard setString:textToCopy forType:NSStringPboardType]; diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm index 7bb1913d872..01217dfd17a 100644 --- a/intern/ghost/intern/GHOST_WindowCocoa.mm +++ b/intern/ghost/intern/GHOST_WindowCocoa.mm @@ -238,10 +238,13 @@ extern "C" { #pragma mark NSOpenGLView subclass //We need to subclass it in order to give Cocoa the feeling key events are trapped -@interface CocoaOpenGLView : NSOpenGLView +@interface CocoaOpenGLView : NSOpenGLView <NSTextInput> { GHOST_SystemCocoa *systemCocoa; GHOST_WindowCocoa *associatedWindow; + + bool composing; + NSString *composing_text; } - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa; @end @@ -251,6 +254,9 @@ extern "C" { { systemCocoa = sysCocoa; associatedWindow = winCocoa; + + composing = false; + composing_text = nil; } - (BOOL)acceptsFirstResponder @@ -258,9 +264,26 @@ extern "C" { return YES; } -//The trick to prevent Cocoa from complaining (beeping) -- (void)keyDown:(NSEvent *)theEvent -{} +// The trick to prevent Cocoa from complaining (beeping) +- (void)keyDown:(NSEvent *)event +{ + // Start or continue composing? + if([[event characters] length] == 0 || + [[event charactersIgnoringModifiers] length] == 0 || + composing) { + composing = YES; + + // interpret event to call insertText + NSMutableArray *events; + events = [[NSMutableArray alloc] initWithCapacity:1]; + [events addObject:event]; + [self interpretKeyEvents:events]; // calls insertText + [events removeObject:event]; + [events release]; + + return; + } +} #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 //Cmd+key are handled differently before 10.5 @@ -306,8 +329,99 @@ extern "C" { } } -@end +// Text input + +- (void)composing_free +{ + composing = NO; + + if(composing_text) { + [composing_text release]; + composing_text = nil; + } +} + +- (void)insertText:(id)chars +{ + [self composing_free]; +} + +- (void)setMarkedText:(id)chars selectedRange:(NSRange)range +{ + [self composing_free]; + if([chars length] == 0) + return; + + // start composing + composing = YES; + composing_text = [chars copy]; + + // if empty, cancel + if([composing_text length] == 0) + [self composing_free]; +} + +- (void)unmarkText +{ + [self composing_free]; +} + +- (BOOL)hasMarkedText +{ + return (composing)? YES: NO; +} + +- (void)doCommandBySelector:(SEL)selector +{ +} + +- (BOOL)isComposing +{ + return composing; +} + +- (NSInteger)conversationIdentifier +{ + return (NSInteger)self; +} + +- (NSAttributedString *)attributedSubstringFromRange:(NSRange)range +{ + return [NSAttributedString new]; // XXX does this leak? +} + +- (NSRange)markedRange +{ + unsigned int length = (composing_text)? [composing_text length]: 0; + + if(composing) + return NSMakeRange(0, length); + + return NSMakeRange(NSNotFound, 0); +} +- (NSRange)selectedRange +{ + unsigned int length = (composing_text)? [composing_text length]: 0; + return NSMakeRange(0, length); +} + +- (NSRect)firstRectForCharacterRange:(NSRange)range +{ + return NSZeroRect; +} + +- (NSUInteger)characterIndexForPoint:(NSPoint)point +{ + return NSNotFound; +} + +- (NSArray*)validAttributesForMarkedText +{ + return [NSArray array]; // XXX does this leak? +} + +@end #pragma mark initialization / finalization |