|
|
@ -12,7 +12,6 @@ |
|
|
{ |
|
|
{ |
|
|
ComPtr<WindowBaseImpl> _parent; |
|
|
ComPtr<WindowBaseImpl> _parent; |
|
|
NSTrackingArea* _area; |
|
|
NSTrackingArea* _area; |
|
|
NSMutableAttributedString* _markedText; |
|
|
|
|
|
bool _isLeftPressed, _isMiddlePressed, _isRightPressed, _isXButton1Pressed, _isXButton2Pressed; |
|
|
bool _isLeftPressed, _isMiddlePressed, _isRightPressed, _isXButton1Pressed, _isXButton2Pressed; |
|
|
AvnInputModifiers _modifierState; |
|
|
AvnInputModifiers _modifierState; |
|
|
NSEvent* _lastMouseDownEvent; |
|
|
NSEvent* _lastMouseDownEvent; |
|
|
@ -22,8 +21,9 @@ |
|
|
AvnPlatformResizeReason _resizeReason; |
|
|
AvnPlatformResizeReason _resizeReason; |
|
|
AvnAccessibilityElement* _accessibilityChild; |
|
|
AvnAccessibilityElement* _accessibilityChild; |
|
|
NSRect _cursorRect; |
|
|
NSRect _cursorRect; |
|
|
NSMutableString* _text; |
|
|
NSMutableAttributedString* _text; |
|
|
NSRange _selection; |
|
|
NSRange _selectedRange; |
|
|
|
|
|
NSRange _markedRange; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void)onClosed |
|
|
- (void)onClosed |
|
|
@ -59,6 +59,11 @@ |
|
|
[self registerForDraggedTypes: @[@"public.data", GetAvnCustomDataType()]]; |
|
|
[self registerForDraggedTypes: @[@"public.data", GetAvnCustomDataType()]]; |
|
|
|
|
|
|
|
|
_modifierState = AvnInputModifiersNone; |
|
|
_modifierState = AvnInputModifiersNone; |
|
|
|
|
|
|
|
|
|
|
|
_text = [[NSMutableAttributedString alloc] initWithString:@""]; |
|
|
|
|
|
_markedRange = NSMakeRange(0, 0); |
|
|
|
|
|
_selectedRange = NSMakeRange(0, 0); |
|
|
|
|
|
|
|
|
return self; |
|
|
return self; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -521,9 +526,13 @@ |
|
|
|
|
|
|
|
|
- (void)keyDown:(NSEvent *)event |
|
|
- (void)keyDown:(NSEvent *)event |
|
|
{ |
|
|
{ |
|
|
[self keyboardEvent:event withType:KeyDown]; |
|
|
_lastKeyHandled = false; |
|
|
_lastKeyHandled = [[self inputContext] handleEvent:event]; |
|
|
|
|
|
[super keyDown:event]; |
|
|
[[self inputContext] handleEvent:event]; |
|
|
|
|
|
|
|
|
|
|
|
if(!_lastKeyHandled){ |
|
|
|
|
|
[self keyboardEvent:event withType:KeyDown]; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void)keyUp:(NSEvent *)event |
|
|
- (void)keyUp:(NSEvent *)event |
|
|
@ -532,6 +541,10 @@ |
|
|
[super keyUp:event]; |
|
|
[super keyUp:event]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void) doCommandBySelector:(SEL)selector{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
- (AvnInputModifiers)getModifiers:(NSEventModifierFlags)mod |
|
|
- (AvnInputModifiers)getModifiers:(NSEventModifierFlags)mod |
|
|
{ |
|
|
{ |
|
|
unsigned int rv = 0; |
|
|
unsigned int rv = 0; |
|
|
@ -561,50 +574,52 @@ |
|
|
|
|
|
|
|
|
- (BOOL)hasMarkedText |
|
|
- (BOOL)hasMarkedText |
|
|
{ |
|
|
{ |
|
|
return [_markedText length] > 0; |
|
|
return _markedRange.length > 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (NSRange)markedRange |
|
|
- (NSRange)markedRange |
|
|
{ |
|
|
{ |
|
|
if([_markedText length] > 0) |
|
|
return _markedRange; |
|
|
return NSMakeRange(0, [_markedText length] - 1); |
|
|
|
|
|
return NSMakeRange(NSNotFound, 0); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (NSRange)selectedRange |
|
|
- (NSRange)selectedRange |
|
|
{ |
|
|
{ |
|
|
return _selection; |
|
|
return _selectedRange; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void)setMarkedText:(id)string selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange |
|
|
- (void)setMarkedText:(id)string selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange |
|
|
{ |
|
|
{ |
|
|
|
|
|
_lastKeyHandled = true; |
|
|
|
|
|
|
|
|
|
|
|
NSString* markedText; |
|
|
|
|
|
|
|
|
if([string isKindOfClass:[NSAttributedString class]]) |
|
|
if([string isKindOfClass:[NSAttributedString class]]) |
|
|
{ |
|
|
{ |
|
|
_markedText = [[NSMutableAttributedString alloc] initWithAttributedString:string]; |
|
|
markedText = [string string]; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
_markedText = [[NSMutableAttributedString alloc] initWithString:string]; |
|
|
markedText = (NSString*) string; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(!_parent->InputMethod->IsActive()){ |
|
|
_markedRange = NSMakeRange(_selectedRange.location, [markedText length]); |
|
|
return; |
|
|
|
|
|
|
|
|
if(_parent->InputMethod->IsActive()){ |
|
|
|
|
|
_parent->InputMethod->Client->SetPreeditText((char*)[markedText UTF8String]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_parent->InputMethod->Client->SetPreeditText((char*)[_markedText.string UTF8String]); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void)unmarkText |
|
|
- (void)unmarkText |
|
|
{ |
|
|
{ |
|
|
[[_markedText mutableString] setString:@""]; |
|
|
if(_parent->InputMethod->IsActive()){ |
|
|
|
|
|
_parent->InputMethod->Client->SetPreeditText(nullptr); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[[self inputContext] discardMarkedText]; |
|
|
_markedRange = NSMakeRange(_selectedRange.location, 0); |
|
|
|
|
|
|
|
|
if(!_parent->InputMethod->IsActive()){ |
|
|
if([self inputContext]) { |
|
|
return; |
|
|
[[self inputContext] discardMarkedText]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
_parent->InputMethod->Client->SetPreeditText(nullptr); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (NSArray<NSString *> *)validAttributesForMarkedText |
|
|
- (NSArray<NSString *> *)validAttributesForMarkedText |
|
|
@ -614,19 +629,38 @@ |
|
|
|
|
|
|
|
|
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(NSRangePointer)actualRange |
|
|
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(NSRangePointer)actualRange |
|
|
{ |
|
|
{ |
|
|
return nullptr; |
|
|
if(actualRange){ |
|
|
|
|
|
range = *actualRange; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NSAttributedString* subString = [_text attributedSubstringFromRange:range]; |
|
|
|
|
|
|
|
|
|
|
|
return subString; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange |
|
|
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange |
|
|
{ |
|
|
{ |
|
|
[self unmarkText]; |
|
|
if(_parent == nullptr){ |
|
|
|
|
|
return; |
|
|
if(_parent != nullptr) |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NSString* text; |
|
|
|
|
|
|
|
|
|
|
|
if([string isKindOfClass:[NSAttributedString class]]) |
|
|
{ |
|
|
{ |
|
|
_lastKeyHandled = _parent->BaseEvents->RawTextInputEvent(0, [string UTF8String]); |
|
|
text = [string string]; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
text = (NSString*) string; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[[self inputContext] invalidateCharacterCoordinates]; |
|
|
[self unmarkText]; |
|
|
|
|
|
|
|
|
|
|
|
uint32_t timestamp = static_cast<uint32_t>([NSDate timeIntervalSinceReferenceDate] * 1000); |
|
|
|
|
|
|
|
|
|
|
|
_lastKeyHandled = _parent->BaseEvents->RawTextInputEvent(timestamp, [text UTF8String]); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (NSUInteger)characterIndexForPoint:(NSPoint)point |
|
|
- (NSUInteger)characterIndexForPoint:(NSPoint)point |
|
|
@ -746,15 +780,11 @@ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void) setText:(NSString *)text{ |
|
|
- (void) setText:(NSString *)text{ |
|
|
[_text setString:text]; |
|
|
[[_text mutableString] setString:text]; |
|
|
|
|
|
|
|
|
[[self inputContext] discardMarkedText]; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void) setSelection:(int)start :(int)end{ |
|
|
- (void) setSelection:(int)start :(int)end{ |
|
|
_selection = NSMakeRange(start, end - start); |
|
|
_selectedRange = NSMakeRange(start, end - start); |
|
|
|
|
|
|
|
|
[[self inputContext] invalidateCharacterCoordinates]; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void) setCursorRect:(AvnRect)rect{ |
|
|
- (void) setCursorRect:(AvnRect)rect{ |
|
|
@ -766,7 +796,9 @@ |
|
|
|
|
|
|
|
|
_cursorRect = windowRectOnScreen; |
|
|
_cursorRect = windowRectOnScreen; |
|
|
|
|
|
|
|
|
[[self inputContext] invalidateCharacterCoordinates]; |
|
|
if([self inputContext]) { |
|
|
|
|
|
[[self inputContext] invalidateCharacterCoordinates]; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@end |
|
|
@end |
|
|
|