2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2019 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2023-06-11 13:08:08 +08:00
|
|
|
#import "platform/ios/InputView-ios.h"
|
|
|
|
#import "base/IMEDispatcher.h"
|
|
|
|
#import "base/Director.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-09-07 19:32:06 +08:00
|
|
|
@interface TextInputView ()
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
@property(nonatomic) NSString* myMarkedText;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2023-09-07 19:32:06 +08:00
|
|
|
@implementation TextInputView
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
@synthesize myMarkedText;
|
|
|
|
@synthesize hasText;
|
|
|
|
@synthesize beginningOfDocument;
|
|
|
|
@synthesize endOfDocument;
|
|
|
|
@synthesize markedTextStyle;
|
|
|
|
@synthesize tokenizer;
|
|
|
|
@synthesize autocorrectionType;
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
|
|
{
|
|
|
|
if (self = [super initWithFrame:frame])
|
|
|
|
{
|
|
|
|
self.myMarkedText = nil;
|
2019-11-23 20:27:39 +08:00
|
|
|
self.autocorrectionType = UITextAutocorrectionTypeNo;
|
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self]; // remove keyboard notification
|
2019-11-23 20:27:39 +08:00
|
|
|
[self.myMarkedText release];
|
|
|
|
[self removeFromSuperview];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (BOOL)canBecomeFirstResponder
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
[self resignFirstResponder];
|
|
|
|
[self removeFromSuperview];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma TextInput protocol
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (id<UITextInputDelegate>)inputDelegate
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setInputDelegate:(id<UITextInputDelegate>)inputDelegate
|
|
|
|
{}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setSelectedTextRange:(UITextRange*)aSelectedTextRange
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("UITextRange:setSelectedTextRange");
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (UITextRange*)selectedTextRange
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
return [[[UITextRange alloc] init] autorelease];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)deleteBackward
|
|
|
|
{
|
|
|
|
if (nil != self.myMarkedText)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
[self.myMarkedText release];
|
|
|
|
self.myMarkedText = nil;
|
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)insertText:(nonnull NSString*)text
|
|
|
|
{
|
|
|
|
if (nil != self.myMarkedText)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
[self.myMarkedText release];
|
|
|
|
self.myMarkedText = nil;
|
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
const char* pszText = [text cStringUsingEncoding:NSUTF8StringEncoding];
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (NSWritingDirection)baseWritingDirectionForPosition:(nonnull UITextPosition*)position
|
|
|
|
inDirection:(UITextStorageDirection)direction
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("baseWritingDirectionForPosition");
|
2019-11-23 20:27:39 +08:00
|
|
|
return NSWritingDirectionLeftToRight;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (CGRect)caretRectForPosition:(nonnull UITextPosition*)position
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("caretRectForPosition");
|
2019-11-23 20:27:39 +08:00
|
|
|
return CGRectZero;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nullable UITextRange*)characterRangeAtPoint:(CGPoint)point
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("characterRangeAtPoint");
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nullable UITextRange*)characterRangeByExtendingPosition:(nonnull UITextPosition*)position
|
|
|
|
inDirection:(UITextLayoutDirection)direction
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("characterRangeByExtendingPosition");
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nullable UITextPosition*)closestPositionToPoint:(CGPoint)point
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("closestPositionToPoint");
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nullable UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(nonnull UITextRange*)range
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("closestPositionToPoint");
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (NSComparisonResult)comparePosition:(nonnull UITextPosition*)position toPosition:(nonnull UITextPosition*)other
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("comparePosition");
|
2019-11-23 20:27:39 +08:00
|
|
|
return (NSComparisonResult)0;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (CGRect)firstRectForRange:(nonnull UITextRange*)range
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("firstRectForRange");
|
2019-11-23 20:27:39 +08:00
|
|
|
return CGRectNull;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (NSInteger)offsetFromPosition:(nonnull UITextPosition*)from toPosition:(nonnull UITextPosition*)toPosition
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("offsetFromPosition");
|
2019-11-23 20:27:39 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nullable UITextPosition*)positionFromPosition:(nonnull UITextPosition*)position
|
|
|
|
inDirection:(UITextLayoutDirection)direction
|
|
|
|
offset:(NSInteger)offset
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("positionFromPosition");
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nullable UITextPosition*)positionFromPosition:(nonnull UITextPosition*)position offset:(NSInteger)offset
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("positionFromPosition");
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nullable UITextPosition*)positionWithinRange:(nonnull UITextRange*)range
|
|
|
|
farthestInDirection:(UITextLayoutDirection)direction
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("positionWithinRange");
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)replaceRange:(nonnull UITextRange*)range withText:(nonnull NSString*)text
|
|
|
|
{}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nonnull NSArray<UITextSelectionRect*>*)selectionRectsForRange:(nonnull UITextRange*)range
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("selectionRectsForRange");
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setBaseWritingDirection:(NSWritingDirection)writingDirection forRange:(nonnull UITextRange*)range
|
|
|
|
{}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)setMarkedText:(nullable NSString*)markedText selectedRange:(NSRange)selectedRange
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("setMarkedText");
|
2021-12-31 12:12:40 +08:00
|
|
|
if (markedText == self.myMarkedText)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
if (nil != self.myMarkedText)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
[self.myMarkedText release];
|
|
|
|
}
|
|
|
|
self.myMarkedText = markedText;
|
|
|
|
[self.myMarkedText retain];
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (UITextRange*)markedTextRange
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("markedTextRange");
|
2021-12-31 12:12:40 +08:00
|
|
|
if (nil != self.myMarkedText)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
return [[[UITextRange alloc] init] autorelease];
|
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
return nil; // Nil if no marked text.
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nullable NSString*)textInRange:(nonnull UITextRange*)range
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("textInRange");
|
2021-12-31 12:12:40 +08:00
|
|
|
if (nil != self.myMarkedText)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
return self.myMarkedText;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (nullable UITextRange*)textRangeFromPosition:(nonnull UITextPosition*)fromPosition
|
|
|
|
toPosition:(nonnull UITextPosition*)toPosition
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("textRangeFromPosition");
|
2019-11-23 20:27:39 +08:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)unmarkText
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("unmarkText");
|
2019-11-23 20:27:39 +08:00
|
|
|
if (nil == self.myMarkedText)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
const char* pszText = [self.myMarkedText cStringUsingEncoding:NSUTF8StringEncoding];
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText));
|
2019-11-23 20:27:39 +08:00
|
|
|
[self.myMarkedText release];
|
|
|
|
self.myMarkedText = nil;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
- (void)encodeWithCoder:(nonnull NSCoder*)coder
|
|
|
|
{}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
@end
|