OSX: Fix more UTF8 issues, todo: use correct font
This commit is contained in:
@@ -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];
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user