mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-23 17:38:44 +00:00
merge
This commit is contained in:
commit
45b277e75f
3 changed files with 122 additions and 14 deletions
|
@ -319,7 +319,7 @@ bool isTextKeyEvent(NSEvent* event)
|
|||
|
||||
/*
|
||||
TODO check why iswprint(character) does not solve it.
|
||||
it always returns false, even for π é ...
|
||||
it always returns false, even for π, é, ...
|
||||
*/
|
||||
// > 127 but not printable
|
||||
if( nelKey == NLMISC::KeyF1 || nelKey == NLMISC::KeyF2 ||
|
||||
|
@ -408,13 +408,6 @@ void submitEvents(NLMISC::CEventServer& server,
|
|||
case NSMouseEntered:break;
|
||||
case NSMouseExited:break;
|
||||
case NSKeyDown:
|
||||
/*
|
||||
TODO dead keys
|
||||
http://developer.apple.com/mac/library/documentation/Carbon/Reference/
|
||||
Unicode_Utilities_Ref/Reference/reference.html#//apple_ref/c/func/
|
||||
UCKeyTranslate
|
||||
*/
|
||||
|
||||
// push the key press event to the new event server
|
||||
server.postEvent(new NLMISC::CEventKeyDown(
|
||||
virtualKeycodeToNelKey([event keyCode]),
|
||||
|
|
|
@ -21,12 +21,36 @@
|
|||
/**
|
||||
* derived to configure the NSOpenGLView
|
||||
*/
|
||||
@interface CocoaOpenGLView : NSOpenGLView
|
||||
@interface CocoaOpenGLView : NSOpenGLView<NSTextInputClient>
|
||||
{
|
||||
NSMutableAttributedString* backingStore;
|
||||
NSRange markedRange;
|
||||
}
|
||||
|
||||
-(id)initWithFrame:(NSRect)frame;
|
||||
-(void)dealloc;
|
||||
|
||||
-(BOOL)acceptsFirstResponder;
|
||||
-(BOOL)needsPanelToBecomeKey;
|
||||
-(void)keyDown:(NSEvent*)event;
|
||||
|
||||
/******************************************************************************/
|
||||
/* NSTextInputClient Protocol */
|
||||
|
||||
-(BOOL)hasMarkedText;
|
||||
-(NSRange)markedRange;
|
||||
-(NSRange)selectedRange;
|
||||
-(void)setMarkedText:(id)aString
|
||||
selectedRange:(NSRange)newSelection
|
||||
replacementRange:(NSRange)replacementRange;
|
||||
-(void)unmarkText;
|
||||
-(NSArray*)validAttributesForMarkedText;
|
||||
-(NSAttributedString*)attributedSubstringForProposedRange:(NSRange)aRange
|
||||
actualRange:(NSRangePointer)actualRange;
|
||||
-(void)insertText:(id)aString replacementRange:(NSRange)replacementRange;
|
||||
-(NSUInteger)characterIndexForPoint:(NSPoint)aPoint;
|
||||
-(NSRect)firstRectForCharacterRange:(NSRange)aRange
|
||||
actualRange:(NSRangePointer)actualRange;
|
||||
-(void)doCommandBySelector:(SEL)aSelector;
|
||||
|
||||
@end
|
||||
|
|
|
@ -20,6 +20,21 @@
|
|||
|
||||
@implementation CocoaOpenGLView
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame
|
||||
{
|
||||
if(self = [super initWithFrame:frame])
|
||||
{
|
||||
backingStore = [[NSMutableAttributedString alloc] initWithString:@""];
|
||||
return self;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[backingStore release];
|
||||
[super dealloc];
|
||||
}
|
||||
-(BOOL)acceptsFirstResponder
|
||||
{
|
||||
return YES;
|
||||
|
@ -32,11 +47,87 @@
|
|||
|
||||
-(void)keyDown:(NSEvent*)event
|
||||
{
|
||||
// we handle the key here, so os x does not make a sound :)
|
||||
/*
|
||||
TODO do it in the event emitter? eg do not forward key down?
|
||||
does command+q / command+m still work then?
|
||||
*/
|
||||
[[self inputContext] handleEvent:event];
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* NSTextInputClient Protocol */
|
||||
|
||||
-(BOOL)hasMarkedText
|
||||
{
|
||||
return (markedRange.location == NSNotFound ? NO : YES);
|
||||
}
|
||||
|
||||
-(NSRange)markedRange
|
||||
{
|
||||
return markedRange;
|
||||
}
|
||||
|
||||
-(NSRange)selectedRange
|
||||
{
|
||||
return NSMakeRange(NSNotFound, 0);
|
||||
}
|
||||
|
||||
-(void)setMarkedText:(id)aString
|
||||
selectedRange:(NSRange)newSelection
|
||||
replacementRange:(NSRange)replacementRange
|
||||
{
|
||||
if(replacementRange.location == NSNotFound)
|
||||
replacementRange = markedRange;
|
||||
|
||||
if([aString length] == 0)
|
||||
{
|
||||
[backingStore deleteCharactersInRange:replacementRange];
|
||||
[self unmarkText];
|
||||
}
|
||||
else
|
||||
{
|
||||
markedRange = NSMakeRange(replacementRange.location, [aString length]);
|
||||
[backingStore replaceCharactersInRange:replacementRange withString:aString];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)unmarkText
|
||||
{
|
||||
markedRange = NSMakeRange(NSNotFound, 0);
|
||||
[[self inputContext] discardMarkedText];
|
||||
}
|
||||
|
||||
-(NSArray*)validAttributesForMarkedText
|
||||
{
|
||||
return [NSArray arrayWithObjects:
|
||||
NSMarkedClauseSegmentAttributeName, NSGlyphInfoAttributeName, nil];
|
||||
}
|
||||
|
||||
-(NSAttributedString*)attributedSubstringForProposedRange:(NSRange)aRange
|
||||
actualRange:(NSRangePointer)actualRange
|
||||
{
|
||||
return [backingStore attributedSubstringFromRange:aRange];
|
||||
}
|
||||
|
||||
-(void)insertText:(id)aString
|
||||
replacementRange:(NSRange)replacementRange
|
||||
{
|
||||
if(replacementRange.location == NSNotFound)
|
||||
replacementRange = markedRange;
|
||||
|
||||
[backingStore replaceCharactersInRange:replacementRange withString:aString];
|
||||
}
|
||||
|
||||
-(NSUInteger)characterIndexForPoint:(NSPoint)aPoint
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
-(NSRect)firstRectForCharacterRange:(NSRange)aRange
|
||||
actualRange:(NSRangePointer)actualRange
|
||||
{
|
||||
return NSMakeRect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
-(void)doCommandBySelector:(SEL)aSelector
|
||||
{
|
||||
[super doCommandBySelector:aSelector];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue