[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42086] trunk/blender/intern/ghost/intern: OSX: Fix more UTF8 issues, todo: use correct font
jens verwiebe
info at jensverwiebe.de
Wed Nov 23 08:39:59 CET 2011
Revision: 42086
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42086
Author: jensverwiebe
Date: 2011-11-23 07:39:59 +0000 (Wed, 23 Nov 2011)
Log Message:
-----------
OSX: Fix more UTF8 issues, todo: use correct font
Modified Paths:
--------------
trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm
Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm 2011-11-22 22:02:46 UTC (rev 42085)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm 2011-11-23 07:39:59 UTC (rev 42086)
@@ -1765,7 +1765,7 @@
return NULL;
}
- pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSISOLatin1StringEncoding];
+ pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1);
@@ -1774,7 +1774,7 @@
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 @@
[pasteBoard declareTypes:supportedTypes owner:nil];
- textToCopy = [NSString stringWithCString:buffer encoding:NSISOLatin1StringEncoding];
+ textToCopy = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
[pasteBoard setString:textToCopy forType:NSStringPboardType];
Modified: trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm 2011-11-22 22:02:46 UTC (rev 42085)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm 2011-11-23 07:39:59 UTC (rev 42086)
@@ -238,10 +238,13 @@
#pragma mark NSOpenGLView subclass
//We need to subclass it in order to give Cocoa the feeling key events are trapped
- at interface CocoaOpenGLView : NSOpenGLView
+ at 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 @@
{
systemCocoa = sysCocoa;
associatedWindow = winCocoa;
+
+ composing = false;
+ composing_text = nil;
}
- (BOOL)acceptsFirstResponder
@@ -258,10 +264,27 @@
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
- (BOOL)performKeyEquivalent:(NSEvent *)theEvent
@@ -306,9 +329,100 @@
}
}
+// 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
NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;
More information about the Bf-blender-cvs
mailing list