: QPlatformInputContext()
, mWindow(QGuiApplication::focusWindow())
{
- connect(qApp->inputMethod(), SIGNAL(inputItemChanged()), this, SLOT(inputItemChanged()));
+ QMetaObject::invokeMethod(this, "connectSignals", Qt::QueuedConnection);
}
QCocoaInputContext::~QCocoaInputContext()
}
}
-void QCocoaInputContext::inputItemChanged()
+void QCocoaInputContext::connectSignals()
+{
+ connect(qApp, SIGNAL(focusObjectChanged(QObject*)), this, SLOT(focusObjectChanged(QObject*)));
+ focusObjectChanged(qApp->focusObject());
+}
+
+void QCocoaInputContext::focusObjectChanged(QObject *focusObject)
{
mWindow = QGuiApplication::focusWindow();
}
QObject *fo = QGuiApplication::focusObject();
if (!m_keyEventsAccepted && fo) {
- QInputMethodQueryEvent queryEvent(Qt::ImHints);
+ QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImHints);
if (QCoreApplication::sendEvent(fo, &queryEvent)) {
+ bool imEnabled = queryEvent.value(Qt::ImEnabled).toBool();
Qt::InputMethodHints hints = static_cast<Qt::InputMethodHints>(queryEvent.value(Qt::ImHints).toUInt());
- if (!(hints & Qt::ImhDigitsOnly || hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhHiddenText))
+ if (imEnabled && !(hints & Qt::ImhDigitsOnly || hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhHiddenText))
[self interpretKeyEvents:[NSArray arrayWithObject:nsevent]];
}
}
}
QObject *fo = QGuiApplication::focusObject();
if (fo) {
- QInputMethodEvent e;
- e.setCommitString(commitString);
- QCoreApplication::sendEvent(fo, &e);
- m_keyEventsAccepted = true;
+ QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
+ if (QCoreApplication::sendEvent(fo, &queryEvent)) {
+ if (queryEvent.value(Qt::ImEnabled).toBool()) {
+ QInputMethodEvent e;
+ e.setCommitString(commitString);
+ QCoreApplication::sendEvent(fo, &e);
+ m_keyEventsAccepted = true;
+ }
+ }
}
m_composingText.clear();
QObject *fo = QGuiApplication::focusObject();
if (fo) {
- QInputMethodEvent e(preeditString, attrs);
- QCoreApplication::sendEvent(fo, &e);
- m_keyEventsAccepted = true;
+ QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
+ if (QCoreApplication::sendEvent(fo, &queryEvent)) {
+ if (queryEvent.value(Qt::ImEnabled).toBool()) {
+ QInputMethodEvent e(preeditString, attrs);
+ QCoreApplication::sendEvent(fo, &e);
+ m_keyEventsAccepted = true;
+ }
+ }
}
}
if (!m_composingText.isEmpty()) {
QObject *fo = QGuiApplication::focusObject();
if (fo) {
- QInputMethodEvent e;
- e.setCommitString(m_composingText);
- QCoreApplication::sendEvent(fo, &e);
+ QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
+ if (QCoreApplication::sendEvent(fo, &queryEvent)) {
+ if (queryEvent.value(Qt::ImEnabled).toBool()) {
+ QInputMethodEvent e;
+ e.setCommitString(m_composingText);
+ QCoreApplication::sendEvent(fo, &e);
+ }
+ }
}
}
m_composingText.clear();
QObject *fo = QGuiApplication::focusObject();
if (!fo)
return nil;
- QInputMethodQueryEvent queryEvent(Qt::ImCurrentSelection);
+ QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImCurrentSelection);
if (!QCoreApplication::sendEvent(fo, &queryEvent))
return nil;
+ if (!queryEvent.value(Qt::ImEnabled).toBool())
+ return nil;
QString selectedText = queryEvent.value(Qt::ImCurrentSelection).toString();
if (selectedText.isEmpty())
QObject *fo = QGuiApplication::focusObject();
if (!fo)
return selRange;
- QInputMethodQueryEvent queryEvent(Qt::ImCurrentSelection);
+ QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImCurrentSelection);
if (!QCoreApplication::sendEvent(fo, &queryEvent))
return selRange;
+ if (!queryEvent.value(Qt::ImEnabled).toBool())
+ return selRange;
+
QString selectedText = queryEvent.value(Qt::ImCurrentSelection).toString();
if (!selectedText.isEmpty()) {
if (!fo)
return NSZeroRect;
+ QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
+ if (!QCoreApplication::sendEvent(fo, &queryEvent))
+ return NSZeroRect;
+ if (!queryEvent.value(Qt::ImEnabled).toBool())
+ return NSZeroRect;
+
if (!m_window)
return NSZeroRect;
- (NSArray*) validAttributesForMarkedText
{
+ if (m_window != QGuiApplication::focusWindow())
+ return nil;
+
QObject *fo = QGuiApplication::focusObject();
if (!fo)
return nil;
+ QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
+ if (!QCoreApplication::sendEvent(fo, &queryEvent))
+ return nil;
+ if (!queryEvent.value(Qt::ImEnabled).toBool())
+ return nil;
+
// Support only underline color/style.
return [NSArray arrayWithObjects:NSUnderlineColorAttributeName,
NSUnderlineStyleAttributeName, nil];