change NSTextInput to NSTextInputClient in Cocoa plugin

NSTextInput protocol is slated for deprecation

Task-number: QTBUG-23867
Change-Id: I3f9eadc31bdf4234c63f1bcde5172f22da8d340e
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
bb10
Tasuku Suzuki 2012-03-31 23:22:05 +09:00 committed by Qt by Nokia
parent 7bab41a681
commit f5c3226f58
2 changed files with 23 additions and 25 deletions

View File

@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE
class QCocoaWindow;
QT_END_NAMESPACE
@interface QNSView : NSView <NSTextInput> {
@interface QNSView : NSView <NSTextInputClient> {
CGImageRef m_cgImage;
QWindow *m_window;
QCocoaWindow *m_platformWindow;

View File

@ -681,8 +681,9 @@ static QTouchDevice *touchDevice = 0;
[self tryToPerform:aSelector with:self];
}
- (void) insertText:(id)aString
- (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
{
Q_UNUSED(replacementRange)
QString commitString;
if ([aString length]) {
if ([aString isKindOfClass:[NSAttributedString class]]) {
@ -707,12 +708,13 @@ static QTouchDevice *touchDevice = 0;
m_composingText.clear();
}
- (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange
- (void) setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange
{
Q_UNUSED(replacementRange)
QString preeditString;
QList<QInputMethodEvent::Attribute> attrs;
attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, selRange.location + selRange.length, 1, QVariant());
attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, selectedRange.location + selectedRange.length, 1, QVariant());
if ([aString isKindOfClass:[NSAttributedString class]]) {
// Preedit string has attribution
@ -793,13 +795,9 @@ static QTouchDevice *touchDevice = 0;
return (m_composingText.isEmpty() ? NO: YES);
}
- (NSInteger) conversationIdentifier
{
return (NSInteger)self;
}
- (NSAttributedString *) attributedSubstringFromRange:(NSRange)theRange
- (NSAttributedString *) attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
{
Q_UNUSED(actualRange)
QObject *fo = QGuiApplication::focusObject();
if (!fo)
return nil;
@ -813,7 +811,7 @@ static QTouchDevice *touchDevice = 0;
if (selectedText.isEmpty())
return nil;
QCFString string(selectedText.mid(theRange.location, theRange.length));
QCFString string(selectedText.mid(aRange.location, aRange.length));
const NSString *tmpString = reinterpret_cast<const NSString *>((CFStringRef)string);
return [[[NSAttributedString alloc] initWithString:const_cast<NSString *>(tmpString)] autorelease];
}
@ -831,34 +829,34 @@ static QTouchDevice *touchDevice = 0;
return range;
}
- (NSRange) selectedRange
{
NSRange selRange = {NSNotFound, 0};
selRange.location = NSNotFound;
selRange.length = 0;
NSRange selectedRange = {NSNotFound, 0};
selectedRange.location = NSNotFound;
selectedRange.length = 0;
QObject *fo = QGuiApplication::focusObject();
if (!fo)
return selRange;
return selectedRange;
QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImCurrentSelection);
if (!QCoreApplication::sendEvent(fo, &queryEvent))
return selRange;
return selectedRange;
if (!queryEvent.value(Qt::ImEnabled).toBool())
return selRange;
return selectedRange;
QString selectedText = queryEvent.value(Qt::ImCurrentSelection).toString();
if (!selectedText.isEmpty()) {
selRange.location = 0;
selRange.length = selectedText.length();
selectedRange.location = 0;
selectedRange.length = selectedText.length();
}
return selRange;
return selectedRange;
}
- (NSRect) firstRectForCharacterRange:(NSRange)theRange
- (NSRect) firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
{
Q_UNUSED(theRange);
Q_UNUSED(aRange)
Q_UNUSED(actualRange)
QObject *fo = QGuiApplication::focusObject();
if (!fo)
return NSZeroRect;
@ -884,10 +882,10 @@ static QTouchDevice *touchDevice = 0;
return rect;
}
- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
- (NSUInteger)characterIndexForPoint:(NSPoint)aPoint
{
// We dont support cursor movements using mouse while composing.
Q_UNUSED(thePoint);
Q_UNUSED(aPoint);
return NSNotFound;
}