10#include <QtCore/qscopedvaluerollback.h>
12#include <QtGui/qevent.h>
13#include <QtGui/qtextformat.h>
14#include <QtGui/private/qguiapplication_p.h>
15#include <QtGui/qpa/qplatformwindow.h>
32 return [pos autorelease];
41@property (nonatomic) NSRange
range;
42+ (instancetype)rangeWithNSRange:(NSRange)
range;
48+ (instancetype)rangeWithNSRange:(NSRange)nsrange
52 return [range autorelease];
55- (UITextPosition *)
start
60- (UITextPosition *)
end
72 return (self.range.
length == 0);
84- (instancetype)initWithView:(UIView *)
view
86 if (self = [self
init]) {
87 [
self addSubview:view];
89 self.autoresizingMask =
view.autoresizingMask;
99 UIView *
view = [
self.subviews firstObject];
100 view.frame = self.bounds;
107- (CGSize)sizeThatFits:(CGSize)
size
109 return [[
self.subviews firstObject] sizeThatFits:size];
119 [[
self nextResponder] retain];
121 [[
self nextResponder] autorelease];
137 if (!(self = [self
init]))
140 m_inputContext = inputContext;
141 m_configuredImeState =
static_cast<QInputMethodQueryEvent*
>(m_inputContext->imeState().currentState.clone());
149 delete m_configuredImeState;
155 return m_inputContext->imeState().currentState.value(
query);
158- (BOOL)canBecomeFirstResponder
163- (BOOL)becomeFirstResponder
167 qImDebug() <<
"self:" <<
self <<
"first:" << [UIResponder currentFirstResponder];
169 if (![super becomeFirstResponder]) {
170 qImDebug() <<
self <<
"was not allowed to become first responder";
179- (BOOL)resignFirstResponder
181 qImDebug() <<
"self:" <<
self <<
"first:" << [UIResponder currentFirstResponder];
186 qImDebug(
"not allowing parent window to steal responder");
190 if (![super resignFirstResponder])
202 m_inputContext->clearCurrentFocusObject();
203 }
else if ([UIResponder currentFirstResponder] == [self nextResponder]) {
209 qImDebug(
"no keyboard available, clearing focus object");
210 m_inputContext->clearCurrentFocusObject();
217 qImDebug(
"lost first responder, but not clearing focus object");
223- (UIResponder*)nextResponder
229 return (
qApp->focusWindow() &&
qApp->focusWindow()->handle()) ?
230 reinterpret_cast<QUIView *
>(
qApp->focusWindow()->handle()->winId()) : 0;
235- (
void)notifyInputDelegate:(
Qt::InputMethodQueries)updatedProperties
240- (BOOL)needsKeyboardReconfigure:(
Qt::InputMethodQueries)updatedProperties
243 qImDebug() <<
"Qt::ImEnabled has changed since text responder was configured, need reconfigure";
248 qImDebug() <<
"Qt::ImReadOnly has changed since text responder was configured, need reconfigure";
267#ifndef QT_NO_SHORTCUT
269- (
void)sendKeyPressRelease:(
Qt::
Key)key modifiers:(
Qt::KeyboardModifiers)modifiers
279 [
self sendKeyPressRelease:combination.key() modifiers:combination.keyboardModifiers()];
288 return anchorPos != cursorPos;
291- (BOOL)canPerformAction:(
SEL)action withSender:(
id)sender
293 const bool isSelectAction =
294 action ==
@selector(
select:) ||
297 const bool isReadAction = action ==
@selector(
copy:);
299 if (!isSelectAction && !isReadAction)
300 return [
super canPerformAction:action withSender:sender];
309 [
self sendShortcut:QKeySequence::Copy];
315 [
self sendShortcut:QKeySequence::MoveToPreviousWord];
316 [
self sendShortcut:QKeySequence::SelectNextWord];
322 [
self sendShortcut:QKeySequence::SelectAll];
338 if (!(self = [super initWithInputContext:inputContext]))
344 Qt::InputMethodHints hints = Qt::InputMethodHints(m_configuredImeState->value(
Qt::ImHints).toUInt());
347 switch (enterKeyType) {
349 self.returnKeyType = UIReturnKeyDefault;
352 self.returnKeyType = UIReturnKeyDone;
355 self.returnKeyType = UIReturnKeyGo;
358 self.returnKeyType = UIReturnKeySend;
361 self.returnKeyType = UIReturnKeySearch;
364 self.returnKeyType = UIReturnKeyNext;
367 self.returnKeyType = (hints &
Qt::ImhMultiLine) ? UIReturnKeyDefault : UIReturnKeyDone;
373 UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault;
375 UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault;
378 self.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
380 self.autocapitalizationType = UITextAutocapitalizationTypeNone;
382 self.autocapitalizationType = UITextAutocapitalizationTypeSentences;
385 self.keyboardType = UIKeyboardTypeURL;
387 self.keyboardType = UIKeyboardTypeEmailAddress;
389 self.keyboardType = UIKeyboardTypeNumberPad;
391 self.keyboardType = UIKeyboardTypePhonePad;
393 self.keyboardType = UIKeyboardTypeASCIICapable;
395 self.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
397 self.keyboardType = UIKeyboardTypeDefault;
400 self.inputView = [[[
WrapperView alloc] initWithView:inputView] autorelease];
402 self.inputAccessoryView = [[[
WrapperView alloc] initWithView:accessoryView] autorelease];
409#pragma clang diagnostic push
410#pragma clang diagnostic ignored "-Wnonnull"
411 self.inputAssistantItem.leadingBarButtonGroups = nil;
412 self.inputAssistantItem.trailingBarButtonGroups = nil;
413#pragma clang diagnostic pop
417 self.undoManager.groupsByEvent = NO;
418 [
self rebuildUndoStack];
426 self.inputAccessoryView = 0;
431- (BOOL)needsKeyboardReconfigure:(
Qt::InputMethodQueries)updatedProperties
433 Qt::InputMethodQueries relevantProperties = updatedProperties;
439 qImDebug(
"IM was turned on, we need to check hints and platform data as well");
446 if (!relevantProperties)
447 return [
super needsKeyboardReconfigure:updatedProperties];
452 qImDebug() <<
property <<
"has changed since text responder was configured, need reconfigure";
458 return [
super needsKeyboardReconfigure:updatedProperties];
463 [
self setMarkedText:@"" selectedRange:NSMakeRange(0, 0)];
464 [
self notifyInputDelegate:Qt::ImSurroundingText];
470 [
self notifyInputDelegate:Qt::ImSurroundingText];
475#ifndef QT_NO_SHORTCUT
477- (BOOL)canPerformAction:(
SEL)action withSender:(
id)sender
479 bool isEditAction = (action ==
@selector(
cut:)
480 || action ==
@selector(
copy:)
483 || action == @
selector(toggleBoldface:)
484 || action == @
selector(toggleItalics:)
485 || action == @
selector(toggleUnderline:)
489 bool isSelectAction = (action ==
@selector(
select:)
495 const bool unknownAction = !isEditAction && !isSelectAction;
499 return [
super canPerformAction:action withSender:sender];
502 if (focusObject && focusObject->
property(
"qt_im_readonly").
toBool()) {
504 if (action ==
@selector(
cut:)
508 if (action ==
@selector(
copy:))
517 [
self sendShortcut:QKeySequence::Cut];
523 [
self sendShortcut:QKeySequence::Paste];
526- (
void)delete:(
id)sender
529 [
self sendShortcut:QKeySequence::Delete];
532- (
void)toggleBoldface:(
id)sender
535 [
self sendShortcut:QKeySequence::Bold];
538- (
void)toggleItalics:(
id)sender
541 [
self sendShortcut:QKeySequence::Italic];
544- (
void)toggleUnderline:(
id)sender
547 [
self sendShortcut:QKeySequence::Underline];
554 [
self sendShortcut:QKeySequence::Undo];
555 [
self rebuildUndoStack];
560 [
self sendShortcut:QKeySequence::Redo];
561 [
self rebuildUndoStack];
566 NSUndoManager *undoMgr =
self.undoManager;
567 [undoMgr beginUndoGrouping];
568 [undoMgr registerUndoWithTarget:self selector:@selector(redo) object:nil];
569 [undoMgr endUndoGrouping];
572- (
void)rebuildUndoStack
574 dispatch_async(dispatch_get_main_queue (), ^{
579 NSUndoManager *undoMgr =
self.undoManager;
580 [undoMgr removeAllActions];
582 [undoMgr beginUndoGrouping];
583 [undoMgr registerUndoWithTarget:self selector:@selector(undo) object:nil];
584 [undoMgr endUndoGrouping];
585 [undoMgr beginUndoGrouping];
586 [undoMgr registerUndoWithTarget:self selector:@selector(undo) object:nil];
587 [undoMgr endUndoGrouping];
590 [undoMgr beginUndoGrouping];
591 [undoMgr registerUndoWithTarget:self selector:@selector(registerRedo) object:nil];
592 [undoMgr endUndoGrouping];
593 [undoMgr beginUndoGrouping];
594 [undoMgr registerUndoWithTarget:self selector:@selector(registerRedo) object:nil];
595 [undoMgr endUndoGrouping];
615- (
void)keyCommandTriggered:(UIKeyCommand *)keyCommand
620 if (keyCommand.input == UIKeyInputLeftArrow)
622 else if (keyCommand.input == UIKeyInputRightArrow)
624 else if (keyCommand.input == UIKeyInputUpArrow)
626 else if (keyCommand.input == UIKeyInputDownArrow)
631 if (keyCommand.modifierFlags & UIKeyModifierAlternate)
633 if (keyCommand.modifierFlags & UIKeyModifierShift)
635 if (keyCommand.modifierFlags & UIKeyModifierCommand)
638 [
self sendKeyPressRelease:key modifiers:modifiers];
641- (
void)addKeyCommandsToArray:(NSMutableArray<UIKeyCommand *> *)array key:(NSString *)key
643 SEL s =
@selector(keyCommandTriggered:);
644 [array addObject:[UIKeyCommand keyCommandWithInput:key modifierFlags:0 action:s]];
645 [array addObject:[UIKeyCommand keyCommandWithInput:key modifierFlags:UIKeyModifierShift action:s]];
646 [array addObject:[UIKeyCommand keyCommandWithInput:key modifierFlags:UIKeyModifierAlternate action:s]];
647 [array addObject:[UIKeyCommand keyCommandWithInput:key modifierFlags:UIKeyModifierAlternate|UIKeyModifierShift action:s]];
648 [array addObject:[UIKeyCommand keyCommandWithInput:key modifierFlags:UIKeyModifierCommand action:s]];
649 [array addObject:[UIKeyCommand keyCommandWithInput:key modifierFlags:UIKeyModifierCommand|UIKeyModifierShift action:s]];
652- (NSArray<UIKeyCommand *> *)keyCommands
656 static dispatch_once_t once;
657 static NSMutableArray<UIKeyCommand *> *
array;
659 dispatch_once(&once, ^{
664 array = [NSMutableArray<UIKeyCommand *> new];
665 [
self addKeyCommandsToArray:array key:UIKeyInputUpArrow];
666 [
self addKeyCommandsToArray:array key:UIKeyInputDownArrow];
667 [
self addKeyCommandsToArray:array key:UIKeyInputLeftArrow];
668 [
self addKeyCommandsToArray:array key:UIKeyInputRightArrow];
678- (
void)notifyInputDelegate:(
Qt::InputMethodQueries)updatedProperties
690 [
self.inputDelegate selectionWillChange:self];
691 [
self.inputDelegate selectionDidChange:self];
695 [
self.inputDelegate textWillChange:self];
696 [
self.inputDelegate textDidChange:self];
714- (
id<UITextInputTokenizer>)tokenizer
716 return [[[UITextInputStringTokenizer alloc] initWithTextInput:self] autorelease];
719- (UITextPosition *)beginningOfDocument
724- (UITextPosition *)endOfDocument
726 QString surroundingText = [
self currentImeState:Qt::ImSurroundingText].toString();
727 int endPosition = surroundingText.
length() + m_markedText.
length();
731- (
void)setSelectedTextRange:(UITextRange *)range
746 [
self sendEventToFocusObject:e];
749- (UITextRange *)selectedTextRange
751 int cursorPos = [
self currentImeState:Qt::ImCursorPosition].toInt();
752 int anchorPos = [
self currentImeState:Qt::ImAnchorPosition].toInt();
756- (NSString *)textInRange:(UITextRange *)range
758 QString text = [
self currentImeState:Qt::ImSurroundingText].toString();
759 if (!m_markedText.isEmpty()) {
763 int cursorPos = [
self currentImeState:Qt::ImCursorPosition].
toInt();
772- (
void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRange
776 m_markedText = markedText ? QString::fromNSString(markedText) :
QString();
779 if (markedTextFormat.
isEmpty()) {
788 [
self sendEventToFocusObject:e];
793 if (m_markedText.isEmpty())
797 e.setCommitString(m_markedText);
798 [
self sendEventToFocusObject:e];
800 m_markedText.clear();
803- (NSComparisonResult)comparePosition:(UITextPosition *)position toPosition:(UITextPosition *)other
808 return NSOrderedAscending;
810 return NSOrderedDescending;
811 return NSOrderedSame;
814- (UITextRange *)markedTextRange
819- (UITextRange *)textRangeFromPosition:(UITextPosition *)fromPosition toPosition:(UITextPosition *)toPosition
826- (UITextPosition *)positionFromPosition:(UITextPosition *)position offset:(
NSInteger)offset
829 const int posWithIndex =
p +
offset;
830 const int textLength = [
self currentImeState:Qt::ImSurroundingText].toString().length();
831 if (posWithIndex < 0 || posWithIndex > textLength)
836- (UITextPosition *)positionFromPosition:(UITextPosition *)position inDirection:(UITextLayoutDirection)direction offset:(
NSInteger)offset
841 case UITextLayoutDirectionLeft:
843 case UITextLayoutDirectionRight:
852- (UITextPosition *)positionWithinRange:(UITextRange *)range farthestInDirection:(UITextLayoutDirection)direction
855 if (
direction == UITextLayoutDirectionRight)
860- (
NSInteger)offsetFromPosition:(UITextPosition *)fromPosition toPosition:(UITextPosition *)toPosition
867- (UIView *)textInputView
881 return reinterpret_cast<UIView *
>(topLevel->
winId());
884- (CGRect)firstRectForRange:(UITextRange *)range
892 if (!m_markedText.isEmpty())
895 int cursorPos = [
self currentImeState:Qt::ImCursorPosition].toInt();
896 int anchorPos = [
self currentImeState:Qt::ImAnchorPosition].toInt();
903 [
self sendEventToFocusObject:e];
911 [
self sendEventToFocusObject:e];
915 if (cursorPos !=
int(
r.location +
r.length) || cursorPos != anchorPos) {
919 [
self sendEventToFocusObject:e];
922 return startRect.
united(endRect).toCGRect();
925- (NSArray<UITextSelectionRect *> *)selectionRectsForRange:(UITextRange *)range
931 return [[NSArray<UITextSelectionRect *> new] autorelease];
934- (CGRect)caretRectForPosition:(UITextPosition *)position
942- (
void)replaceRange:(UITextRange *)range withText:(NSString *)text
944 [
self setSelectedTextRange:range];
947 e.setCommitString(QString::fromNSString(
text));
948 [
self sendEventToFocusObject:e];
951- (
void)setBaseWritingDirection:(NSWritingDirection)writingDirection forRange:(UITextRange *)range
958- (NSWritingDirection)baseWritingDirectionForPosition:(UITextPosition *)position inDirection:(UITextStorageDirection)direction
963 return NSWritingDirectionRightToLeft;
964 return NSWritingDirectionLeftToRight;
967- (UITextRange *)characterRangeByExtendingPosition:(UITextPosition *)position inDirection:(UITextLayoutDirection)direction
970 if (
direction == UITextLayoutDirectionLeft)
972 int l = [
self currentImeState:Qt::ImSurroundingText].toString().length();
976- (UITextPosition *)closestPositionToPoint:(CGPoint)point
982- (UITextPosition *)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange *)range
990- (UITextRange *)characterRangeAtPoint:(CGPoint)point
997- (
void)setMarkedTextStyle:(NSDictionary *)style
1006- (NSDictionary *)textStylingAtPosition:(UITextPosition *)position inDirection:(UITextStorageDirection)direction
1020 UIFont *uifont = [UIFont fontWithName:qfont.family().toNSString() size:qfont.pointSize()];
1023 return @{NSFontAttributeName: uifont};
1027- (NSDictionary *)markedTextStyle
1029 return [NSDictionary dictionary];
1037- (
void)insertText:(NSString *)text
1043 if ([
text isEqualToString:
@"\n"]) {
1044 [
self sendKeyPressRelease:Qt::Key_Return modifiers:Qt::NoModifier];
1050 qImDebug() <<
"focusObject already changed, not resigning first responder.";
1054 if (
self.returnKeyType == UIReturnKeyDone ||
self.returnKeyType == UIReturnKeyGo
1055 ||
self.returnKeyType == UIReturnKeySend ||
self.returnKeyType == UIReturnKeySearch)
1056 [
self resignFirstResponder];
1062 e.setCommitString(QString::fromNSString(
text));
1063 [
self sendEventToFocusObject:e];
1066- (
void)deleteBackward
1070 [
self sendKeyPressRelease:Qt::Key_Backspace modifiers:Qt::NoModifier];
static UIResponder * currentCandidate()
The QColor class provides colors based on RGB, HSV or CMYK values.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
static QObject * focusObject()
Returns the QObject in currently active window that will be final receiver of events tied to focus,...
static QWindow * focusWindow()
Returns the QWindow that receives events tied to focus, such as key events.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
static QLocale system()
Returns a QLocale object initialized to the system locale.
T value(const Key &key, const T &defaultValue=T()) const
QVariant property(const char *name) const
Returns the value of the object's name property.
static QVariant queryFocusObject(Qt::InputMethodQuery query, QPointF position)
QPlatformInputContext::queryFocusObject.
static QRectF cursorRectangle()
QPlatformInputContext::cursorRectangle.
\inmodule QtCore\reentrant
QRectF united(const QRectF &other) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
int toInt(bool *ok=nullptr, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
qsizetype length() const
Returns the number of characters in this string.
void setBackground(const QBrush &brush)
Sets the brush use to paint the document's background to the brush specified.
QMap< QString, QVariant > toMap() const
Returns the variant as a QVariantMap if the variant has type() \l QMetaType::QVariantMap.
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
EGLImageKHR int int EGLuint64KHR * modifiers
instancetype positionWithIndex:(NSUInteger index)
@ ImhFormattedNumbersOnly
@ ImhDialableCharactersOnly
static jboolean cut(JNIEnv *, jobject)
static jboolean copy(JNIEnv *, jobject)
static jboolean paste(JNIEnv *, jobject)
static jboolean selectAll(JNIEnv *, jobject)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
static struct AttrInfo attrs[]
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
const char kImePlatformDataInputView[]
const char kImePlatformDataInputAccessoryView[]
const char kImePlatformDataHideShortcutsBar[]
static bool hasSelection()
BOOL m_inSendEventToFocusObject
constexpr const T & qMin(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei length
GLint GLint GLint GLint GLsizei GLsizei GLsizei GLboolean commit
GLenum GLuint GLintptr offset
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
QT_END_NAMESPACE typedef QT_PREPEND_NAMESPACE(quintptr) WId
QFileSelector selector
[1]
selection select(topLeft, bottomRight)
QT_BEGIN_NAMESPACE bool toBool(const QString &str)