static PyObject *meth_QInputMethodEvent_setCommitString(PyObject *sipSelf, PyObject *sipArgs, PyObject *sipKwds) { PyObject *sipParseErr = NULL; { const QString* a0; int a0State = 0; int a1 = 0; int a2 = 0; QInputMethodEvent *sipCpp; static const char *sipKwdList[] = { NULL, sipName_from, sipName_length, }; if (sipParseKwdArgs(&sipParseErr, sipArgs, sipKwds, sipKwdList, NULL, "BJ1|ii", &sipSelf, sipType_QInputMethodEvent, &sipCpp, sipType_QString,&a0, &a0State, &a1, &a2)) { Py_BEGIN_ALLOW_THREADS sipCpp->setCommitString(*a0,a1,a2); Py_END_ALLOW_THREADS sipReleaseType(const_cast<QString *>(a0),sipType_QString,a0State); Py_INCREF(Py_None); return Py_None; } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QInputMethodEvent, sipName_setCommitString, doc_QInputMethodEvent_setCommitString); return NULL; }
//============================================================================== void DeclarativeInputEngine::sendKeyToFocusItem(const QString& text) { qDebug() << "CDeclarativeInputEngine::sendKeyToFocusItem " << text; QInputMethodEvent ev; if (text == QString("\x7F")) { //delete one char ev.setCommitString("",-1,1); } else { //add some text ev.setCommitString(text); } QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev); }
void MInputContext::commitString(const QString &string, int replacementStart, int replacementLength, int cursorPos) { if (debug) qDebug() << InputContextName << "in" << __PRETTY_FUNCTION__; if (imServer->pendingResets()) { return; } preedit.clear(); preeditCursorPos = -1; int start = -1; if (cursorPos >= 0) { bool valid = false; int currentStart = cursorStartPosition(&valid); if (valid) { start = cursorPos + currentStart + replacementStart; } } if (start >= 0) { QList<QInputMethodEvent::Attribute> attributes; attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, start, 0, QVariant()); QInputMethodEvent event("", attributes); event.setCommitString(string, replacementStart, replacementLength); QGuiApplication::sendEvent(qGuiApp->focusObject(), &event); } else { QInputMethodEvent event; event.setCommitString(string, replacementStart, replacementLength); QGuiApplication::sendEvent(qGuiApp->focusObject(), &event); } }
void IBusInputContext::commitString (QString text) { QInputMethodEvent event; event.setCommitString (text); sendEvent (event); update (); }
void InputContext::deleteKey() { // qDebug() << Q_FUNC_INFO; if (mCursorPosition > 0) { QInputMethodEvent event; event.setCommitString(QString(), -1, 1); QCoreApplication::sendEvent(QGuiApplication::focusObject(), &event); } }
void QWaylandTextInput::text_input_commit_string(uint32_t serial, const QString &text) { Q_UNUSED(serial); if (!QGuiApplication::focusObject()) return; QInputMethodEvent event; event.setCommitString(text); QCoreApplication::sendEvent(QGuiApplication::focusObject(), &event); }
//============================================================================== bool DeclarativeInputEngine::virtualKeyClick(Qt::Key key, const QString & text, Qt::KeyboardModifiers modifiers) { Q_UNUSED(key) Q_UNUSED(modifiers) QInputMethodEvent ev; if (text == QString("\x7F")) { //delete one char ev.setCommitString("",-1,1); } else { //add some text ev.setCommitString(text); } QCoreApplication::sendEvent(QGuiApplication::focusObject(),&ev); return true; }
void EmojiPanelPlatformInputContext::emojiPressed(const QString &emoji) { if (!m_focusObject) return; qDebug() << "emojiPressed : " << emoji; QInputMethodEvent event; event.setCommitString(emoji); QGuiApplication::sendEvent(m_focusObject, &event); }
void EmojiDataModel::emitIMEvent(int i) { if (i >= 0 && i < emojis.length()) { QString key = emojis[i]; Emoji data = emojiData[key]; QInputMethodEvent *e = new QInputMethodEvent( QString(), QList<QInputMethodEvent::Attribute>()); e->setCommitString(data.unicode); qApp->sendEvent(qApp->focusObject(), e); } }
void QWaylandInputContext::commit() { if (!ensureTextInput()) return; if (!QGuiApplication::focusObject()) return; QInputMethodEvent event; event.setCommitString(mTextInput->commitString()); QCoreApplication::sendEvent(QGuiApplication::focusObject(), &event); mTextInput->reset(); }
void QMaliitPlatformInputContext::commitString(const QString &string, int replacementStart, int replacementLength, int /* cursorPos */) { if (!inputMethodAccepted()) return; d->preedit.clear(); if (debug) qWarning() << "CommitString" << string; // ### start/cursorPos QInputMethodEvent event; event.setCommitString(string, replacementStart, replacementLength); QCoreApplication::sendEvent(qGuiApp->focusObject(), &event); }
/*! \qmlmethod commit(string) \inqmlmodule Qt.labs.inputcontext Commits \a text to the item with active focus and clears the current \l preeditText. The text will be inserted into the \l surroundingText at a position \a replacementStart relative to the \l cursorPosition and will replace \a replacementLength characters. */ void InputContextModule::commit(const QString &text, int replacementStart, int replacementLength) { const QString preedit = m_preeditText; m_preeditText.clear(); if (m_inputContext) { QInputMethodEvent inputEvent; inputEvent.setCommitString(text, replacementStart, replacementLength); m_inputContext->sendEvent(inputEvent); } if (m_preeditText != preedit) emit preeditTextChanged(); }
void QMeeGoPlatformInputContext::commitString(const QString &string, int replacementStart, int replacementLength, int cursorPos) { QObject *input = qApp->inputPanel()->inputItem(); if (!input) return; d->preedit.clear(); if (debug) qWarning() << "CommitString" << string; // ### start/cursorPos QInputMethodEvent event; event.setCommitString(string, replacementStart, replacementLength); QCoreApplication::sendEvent(input, &event); }
void QMaliitPlatformInputContext::reset() { const bool hadPreedit = !d->preedit.isEmpty(); if (hadPreedit && inputMethodAccepted()) { // ### selection QInputMethodEvent event; event.setCommitString(d->preedit); QGuiApplication::sendEvent(qGuiApp->focusObject(), &event); d->preedit.clear(); } QDBusPendingReply<void> reply = d->server->reset(); if (hadPreedit) reply.waitForFinished(); }
void QWindowsInputContext::reset() { QPlatformInputContext::reset(); if (!m_compositionContext.hwnd) return; qCDebug(lcQpaInputMethods) << __FUNCTION__; if (m_compositionContext.isComposing && !m_compositionContext.focusObject.isNull()) { QInputMethodEvent event; if (!m_compositionContext.composition.isEmpty()) event.setCommitString(m_compositionContext.composition); QCoreApplication::sendEvent(m_compositionContext.focusObject, &event); endContextComposition(); } imeNotifyCancelComposition(m_compositionContext.hwnd); doneContext(); }
void QMeeGoPlatformInputContext::reset() { QObject *input = qApp->inputPanel()->inputItem(); const bool hadPreedit = !d->preedit.isEmpty(); if (hadPreedit && input) { // ### selection QInputMethodEvent event; event.setCommitString(d->preedit); QGuiApplication::sendEvent(input, &event); d->preedit.clear(); } QDBusPendingReply<void> reply = d->server->reset(); if (hadPreedit) reply.waitForFinished(); }
void QMacInputContext::reset() { if (recursionGuard) return; if (!currentText.isEmpty()){ QInputMethodEvent e; e.setCommitString(currentText); qt_sendSpontaneousEvent(focusWidget(), &e); currentText = QString(); } recursionGuard = true; createTextDocument(); composing = false; ActivateTSMDocument(textDocument); FixTSMDocument(textDocument); recursionGuard = false; }
void QtopiaInputDialogPrivate::_q_submitWord(QString word) { if (qobject_cast<QSpinBox*>(m_widget) || qobject_cast<QTimeEdit*>(m_widget)) { //send key events QKeyEvent *kpe = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier, word); QKeyEvent *kre = new QKeyEvent(QEvent::KeyRelease, 0, Qt::NoModifier, word); QApplication::postEvent(m_widget, kpe); QApplication::postEvent(m_widget, kre); return; } //QInputMethodEvent *ime = new QInputMethodEvent(); //ime->setCommitString(word); //QApplication::postEvent(m_widget, ime); QInputMethodEvent ime; ime.setCommitString(word); QApplication::sendEvent(m_widget, &ime); }
void MockupKeyEventDispatcher::sendKeyToFocusItem(const QString &keyText) { if (!m_focusItem) { return; } // special handling for Backspace (send a QKeyEvent to the receiving text element) if (keyText == QString("\x7F")) { QKeyEvent event(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier); QQuickItem *receiver = qobject_cast<QQuickItem *>(m_focusItem); receiver->window()->sendEvent(receiver, &event); // send the typed character to the text field using QInputMethodEvent::setCommitString() } else { QInputMethodEvent ev; ev.setCommitString(keyText); QCoreApplication::sendEvent(m_focusItem,&ev); } }
void DashboardEditor::sendPreeditString(const QString &preedit, Model::Text::PreeditFace face, const Replacement &replacement) { QList<QInputMethodEvent::Attribute> attribute_list; QTextCharFormat char_format; const int start(0); const int length(preedit.length()); switch (face) { case Model::Text::PreeditNoCandidates: char_format.setFontUnderline(true); char_format.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline); char_format.setUnderlineColor(Qt::red); break; case Model::Text::PreeditActive: char_format.setForeground(QBrush(QColor(153, 50, 204))); char_format.setFontWeight(QFont::Bold); break; case Model::Text::PreeditDefault: default: char_format.setUnderlineStyle(QTextCharFormat::SingleUnderline); char_format.setUnderlineColor(QColor(0, 0, 0)); break; } attribute_list.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, char_format)); if (replacement.cursor_position >= 0) { attribute_list << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, replacement.cursor_position, 1, QVariant()); } QInputMethodEvent *ev = new QInputMethodEvent(preedit, attribute_list); if (replacement.start || replacement.length) { ev->setCommitString("", replacement.start, replacement.length); } qApp->postEvent(m_target, ev); }
void MInputContext::reset() { qDebug() << "MInputContext" << "in" << __PRETTY_FUNCTION__; // send existing preedit to widget, documentation unclear whether this is // allowed, but trolls gave permission to use it. Most of qt's internal // input methods do the same thing. const bool hadPreedit = !preedit.isEmpty(); if (hadPreedit) { QInputMethodEvent event; event.setCommitString(preedit); sendEvent(event); preedit.clear(); } // reset input method server, preedit requires synchronization. // rationale: input method might be autocommitting existing preedit without // user interaction. imServer->reset(hadPreedit); }
void QWindowsInputContext::reset() { QPlatformInputContext::reset(); if (!m_compositionContext.hwnd) return; QObject *fo = qApp->focusObject(); if (QWindowsContext::verboseInputMethods) qDebug() << __FUNCTION__<< fo; if (!fo) return; if (m_compositionContext.isComposing) { QInputMethodEvent event; if (!m_compositionContext.composition.isEmpty()) event.setCommitString(m_compositionContext.composition); QCoreApplication::sendEvent(fo, &event); endContextComposition(); } imeNotifyCancelComposition(m_compositionContext.hwnd); doneContext(); }
void DashboardEditor::sendCommitString(const QString &commit) { QInputMethodEvent *ev = new QInputMethodEvent; ev->setCommitString(commit); qApp->postEvent(m_target, ev); }
void QComposeInputContext::commitText(uint character) const { QInputMethodEvent event; event.setCommitString(QChar(character)); QCoreApplication::sendEvent(m_focusObject, &event); }
void InputContext::insertKey(const QString& text) { QInputMethodEvent event; event.setCommitString(text); QCoreApplication::sendEvent(QGuiApplication::focusObject(), &event); }
OSStatus QMacInputContext::globalEventProcessor(EventHandlerCallRef, EventRef event, void *) { #ifndef QT_MAC_USE_COCOA QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData); SRefCon refcon = 0; GetEventParameter(event, kEventParamTextInputSendRefCon, typeRefCon, 0, sizeof(refcon), 0, &refcon); QMacInputContext *context = reinterpret_cast<QMacInputContext*>(refcon); bool handled_event=true; UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event); switch(eclass) { case kEventClassTextInput: { handled_event = false; QWidget *widget = QApplicationPrivate::focus_widget; bool canCompose = widget && (!context || widget->inputContext() == context) && !(widget->inputMethodHints() & Qt::ImhDigitsOnly || widget->inputMethodHints() & Qt::ImhFormattedNumbersOnly || widget->inputMethodHints() & Qt::ImhHiddenText); if(!canCompose) { handled_event = false; } else if(ekind == kEventTextInputOffsetToPos) { if(!widget->testAttribute(Qt::WA_InputMethodEnabled)) { handled_event = false; break; } QRect mr(widget->inputMethodQuery(Qt::ImMicroFocus).toRect()); QPoint mp(widget->mapToGlobal(QPoint(mr.topLeft()))); Point pt; pt.h = mp.x(); pt.v = mp.y() + mr.height(); SetEventParameter(event, kEventParamTextInputReplyPoint, typeQDPoint, sizeof(pt), &pt); handled_event = true; } else if(ekind == kEventTextInputUpdateActiveInputArea) { if(!widget->testAttribute(Qt::WA_InputMethodEnabled)) { handled_event = false; break; } if (context->recursionGuard) break; ByteCount unilen = 0; GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, 0, 0, &unilen, 0); UniChar *unicode = (UniChar*)NewPtr(unilen); GetEventParameter(event, kEventParamTextInputSendText, typeUnicodeText, 0, unilen, 0, unicode); QString text((QChar*)unicode, unilen / sizeof(UniChar)); DisposePtr((char*)unicode); ByteCount fixed_length = 0; GetEventParameter(event, kEventParamTextInputSendFixLen, typeByteCount, 0, sizeof(fixed_length), 0, &fixed_length); if(fixed_length == ULONG_MAX || fixed_length == unilen) { QInputMethodEvent e; e.setCommitString(text); context->currentText = QString(); qt_sendSpontaneousEvent(context->focusWidget(), &e); handled_event = true; context->reset(); } else { ByteCount rngSize = 0; OSStatus err = GetEventParameter(event, kEventParamTextInputSendHiliteRng, typeTextRangeArray, 0, 0, &rngSize, 0); QVarLengthArray<TextRangeArray> highlight(rngSize); if (noErr == err) { err = GetEventParameter(event, kEventParamTextInputSendHiliteRng, typeTextRangeArray, 0, rngSize, &rngSize, highlight.data()); } context->composing = true; if(fixed_length > 0) { const int qFixedLength = fixed_length / sizeof(UniChar); QList<QInputMethodEvent::Attribute> attrs; attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, qFixedLength, text.length()-qFixedLength, qt_mac_compose_format()); QInputMethodEvent e(text, attrs); context->currentText = text; e.setCommitString(text.left(qFixedLength), 0, qFixedLength); qt_sendSpontaneousEvent(widget, &e); handled_event = true; } else { /* Apple's enums that they have removed from Tiger :( enum { kCaretPosition = 1, kRawText = 2, kSelectedRawText = 3, kConvertedText = 4, kSelectedConvertedText = 5, kBlockFillText = 6, kOutlineText = 7, kSelectedText = 8 }; */ #ifndef kConvertedText #define kConvertedText 4 #endif #ifndef kCaretPosition #define kCaretPosition 1 #endif QList<QInputMethodEvent::Attribute> attrs; if (!highlight.isEmpty()) { TextRangeArray *data = highlight.data(); for (int i = 0; i < data->fNumOfRanges; ++i) { int start = data->fRange[i].fStart / sizeof(UniChar); int len = (data->fRange[i].fEnd - data->fRange[i].fStart) / sizeof(UniChar); if (data->fRange[i].fHiliteStyle == kCaretPosition) { attrs << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, start, 0, QVariant()); continue; } QTextCharFormat format; format.setFontUnderline(true); if (data->fRange[i].fHiliteStyle == kConvertedText) format.setUnderlineColor(Qt::gray); else format.setUnderlineColor(Qt::black); attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, len, format); } } else { attrs << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 0, text.length(), qt_mac_compose_format()); } context->currentText = text; QInputMethodEvent e(text, attrs); qt_sendSpontaneousEvent(widget, &e); handled_event = true; } } #if 0 if(!context->composing) handled_event = false; #endif extern bool qt_mac_eat_unicode_key; //qapplication_mac.cpp qt_mac_eat_unicode_key = handled_event; } else if(ekind == kEventTextInputUnicodeForKeyEvent) { EventRef key_ev = 0; GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, typeEventRef, 0, sizeof(key_ev), 0, &key_ev); QString text; ByteCount unilen = 0; if(GetEventParameter(key_ev, kEventParamKeyUnicodes, typeUnicodeText, 0, 0, &unilen, 0) == noErr) { UniChar *unicode = (UniChar*)NewPtr(unilen); GetEventParameter(key_ev, kEventParamKeyUnicodes, typeUnicodeText, 0, unilen, 0, unicode); text = QString((QChar*)unicode, unilen / sizeof(UniChar)); DisposePtr((char*)unicode); } unsigned char chr = 0; GetEventParameter(key_ev, kEventParamKeyMacCharCodes, typeChar, 0, sizeof(chr), 0, &chr); if(!chr || chr >= 128 || (text.length() > 0 && (text.length() > 1 || text.at(0) != QLatin1Char(chr)))) handled_event = !widget->testAttribute(Qt::WA_InputMethodEnabled); QMacInputContext *context = qobject_cast<QMacInputContext*>(qApp->inputContext()); if (context && context->lastKeydownEvent()) { qt_keymapper_private()->translateKeyEvent(widget, 0, context->lastKeydownEvent(), 0, false); context->setLastKeydownEvent(0); } } break; } default: break; } if(!handled_event) //let the event go through return eventNotHandledErr; #else Q_UNUSED(event); #endif return noErr; //we eat the event }
void QHangulPlatformInputContext::commitText(const QString &str) { QInputMethodEvent e; e.setCommitString(str); if (m_focusObject) QCoreApplication::sendEvent(m_focusObject, &e); }