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;
}
Exemplo n.º 2
0
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);
    }
}
Exemplo n.º 3
0
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);
    }
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
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 EmojiPanelPlatformInputContext::emojiPressed(const QString &emoji)
{
    if (!m_focusObject)
        return;

    qDebug() << "emojiPressed : " << emoji;

    QInputMethodEvent event;
    event.setCommitString(emoji);

    QGuiApplication::sendEvent(m_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();
}
Exemplo n.º 9
0
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);
}
Exemplo n.º 10
0
void QWaylandInputContext::commit()
{
    if (!ensureTextInput())
        return;

    if (!QGuiApplication::focusObject())
        return;

    QInputMethodEvent event;
    event.setCommitString(mTextInput->commitString());
    QCoreApplication::sendEvent(QGuiApplication::focusObject(), &event);

    mTextInput->reset();
}
Exemplo n.º 11
0
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();
}
Exemplo n.º 12
0
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 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);
}
Exemplo n.º 14
0
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 Ut_MInputContext::testReset()
{
    WidgetStub widget(0);
    QInputMethodEvent event;
    QString preeditString("");
    QList<MInputMethod::PreeditTextFormat> preeditFormats;
    MInputMethod::PreeditTextFormat preeditFormat;

    preeditFormat.start = 0;
    preeditFormat.preeditFace = MInputMethod::PreeditDefault;
    m_subject->setFocusWidget(&widget);
    gFocusedWidget = &widget;

    // Reset with empty pre-edit
    preeditFormat.length = preeditString.length();
    preeditFormats << preeditFormat;
    m_subject->updatePreedit(preeditString, preeditFormats, -1);
    widget.resetCounters();

    m_subject->reset();

    waitAndProcessEvents(500);

    QCOMPARE(m_stub->resetCount(), 1);
    QCOMPARE(widget.inputMethodEventCount(), 0);

    m_stub->resetCallCounts();
    widget.resetCounters();
    preeditFormats.clear();

    // Reset with non-empty pre-edit
    preeditString = "some string";
    preeditFormat.length = preeditString.length();
    preeditFormats << preeditFormat;
    m_subject->updatePreedit(preeditString, preeditFormats, -1);
    widget.resetCounters();

    m_subject->reset();

    waitAndProcessEvents(500);

    QCOMPARE(m_stub->resetCount(), 1);
    QCOMPARE(widget.inputMethodEventCount(), 1);
    event = widget.lastInputMethodEvent();
    QCOMPARE(event.preeditString(), QString(""));
    QCOMPARE(event.commitString(),  preeditString);
}
Exemplo n.º 16
0
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();
}
Exemplo n.º 17
0
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 Ut_MInputContext::testCommitString()
{
    WidgetStub widget(0);
    QString commitString("committed string");
    m_subject->setFocusWidget(&widget);
    gFocusedWidget = &widget;
    m_subject->commitString(commitString);

    waitAndProcessEvents(0);

    QCOMPARE(widget.inputMethodEventCount(), 1);
    QInputMethodEvent event = widget.lastInputMethodEvent();
    QVERIFY(event.preeditString() == ""); // check that event doesn't contain wrong information
    QCOMPARE(event.commitString(), commitString);

    gFocusedWidget = 0;
}
Exemplo n.º 19
0
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;
}
bool MDeclarativeIMObserver::sceneEventFilter(QGraphicsItem * watched, QEvent * event)
{
    if (event->type()==QEvent::InputMethod) {        
        if (m_omitInputMethodEvents) {
            return true;
        }

        QInputMethodEvent *ime = static_cast<QInputMethodEvent*>(event);
		QString newPreedit = ime->preeditString();
		
        QGraphicsObject *g = parentObject();
        if (g != 0 && g->property("maximumLength").isValid()) {
            int maximumTextLength = g->property("maximumLength").toInt();
            int textLength = g->property("text").toString().length();
            int selectedTextLength = g->property("selectedText").toString().length();
            if (textLength == maximumTextLength &&
                newPreedit.length() - ime->replacementLength() > 0 &&
                selectedTextLength == 0) {
                    m_omitInputMethodEvents = true;
                    QInputContext *ic = qApp->inputContext();
                    ic->reset();
                    m_omitInputMethodEvents = false;
                    return true;
            }				
        }

        if (newPreedit!=m_preedit) {
            m_preedit = newPreedit;
            emit preeditChanged();
        }
        
        QList<QInputMethodEvent::Attribute> attributes = ime->attributes();
        QList<QInputMethodEvent::Attribute>::iterator i;
        for (i = attributes.begin(); i != attributes.end(); ++i) {
            QInputMethodEvent::Attribute attribute = *i;
            if (attribute.type == QInputMethodEvent::Cursor) {
                m_preeditCursorPosition = attribute.start;
                emit preeditCursorPositionChanged();
            }
        }
    }

    return QDeclarativeItem::sceneEventFilter(watched,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 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);
    }
}
Exemplo n.º 23
0
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);
}
Exemplo n.º 25
0
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 Ut_MInputContext::testUpdatePreedit()
{
    WidgetStub widget(0);
    QList<QInputMethodEvent::Attribute> attributes;
    QInputMethodEvent event;
    QString updateString("preedit string");

    //test preedit with traditional style
    m_subject->setFocusWidget(&widget);
    gFocusedWidget = &widget;
    QList<MInputMethod::PreeditTextFormat> preeditFormats;
    MInputMethod::PreeditTextFormat preeditFormat(0, updateString.length(),
                                                  MInputMethod::PreeditDefault);
    preeditFormats << preeditFormat;
    m_subject->updatePreedit(updateString, preeditFormats, -1);

    waitAndProcessEvents(0);

    QCOMPARE(widget.inputMethodEventCount(), 1);
    event = widget.lastInputMethodEvent();
    QVERIFY(event.preeditString() == updateString);
    QVERIFY(event.commitString() == "");
    attributes = event.attributes();
    QVERIFY(attributes.count() > 0);

    //test preedit with alternate style
    preeditFormats.clear();
    preeditFormat.start = 0;
    preeditFormat.length = updateString.length();
    preeditFormat.preeditFace = MInputMethod::PreeditNoCandidates;
    preeditFormats << preeditFormat;
    m_subject->updatePreedit(updateString, preeditFormats, -1);

    waitAndProcessEvents(50);

    QCOMPARE(widget.inputMethodEventCount(), 2);
    event = widget.lastInputMethodEvent();
    QVERIFY(event.preeditString() == updateString);
    QVERIFY(event.commitString() == "");
    attributes = event.attributes();
    QVERIFY(attributes.count() > 0);

    gFocusedWidget = 0;
}
void QComposeInputContext::commitText(uint character) const
{
    QInputMethodEvent event;
    event.setCommitString(QChar(character));
    QCoreApplication::sendEvent(m_focusObject, &event);
}
Exemplo n.º 28
0
bool ChatTextEdit::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::KeyPress)
    {
        QKeyEvent *keyEvent = (QKeyEvent *) event;

        if (keyEvent->key() == Qt::Key_Up)
        {
            // Key up
            QTextCursor cursor = textCursor();
            int pos = cursor.position();
            bool sel = keyEvent->modifiers() == Qt::ShiftModifier;
            cursor.movePosition(QTextCursor::Up, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));

            if (pos == cursor.position())
                cursor.movePosition(QTextCursor::Start, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));

            setTextCursor(cursor);

            return true;
        }
        else  if (keyEvent->key() == Qt::Key_Down)
        {
            // Key down
            QTextCursor cursor = textCursor();
            int pos = cursor.position();
            bool sel = keyEvent->modifiers() == Qt::ShiftModifier;
            cursor.movePosition(QTextCursor::Down, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));

            if (pos == cursor.position())
                cursor.movePosition(QTextCursor::End, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));

            setTextCursor(cursor);
            return true;
        }
        else if (keyEvent->nativeScanCode() == 36)
        {
            // Return pressed
            if (Client::enterIsSend && !(keyEvent->modifiers() & Qt::ShiftModifier))
            {
                isComposing = false;
                emit returnPressed();
                return true;
            }
        }
        else if (keyEvent->nativeScanCode() == 54 &&
                 keyEvent->modifiers() == Qt::ControlModifier)
        {
            // Copy
            QTextCursor cursor = textCursor();
            if (cursor.hasSelection())
            {
                QTextDocumentFragment selection = cursor.selection();
                QClipboard *clipboard = QApplication::clipboard();
                clipboard->setText(Utilities::htmlToWAText(selection.toHtml()));

                QMaemo5InformationBox::information(this,"Copied");
                return true;
            }
        }
        else if (keyEvent->nativeScanCode() == 55 &&
                 keyEvent->modifiers() == Qt::ControlModifier)
        {
            // Paste event
            QTextCursor cursor = textCursor();
            QClipboard *clipboard = QApplication::clipboard();

            cursor.insertHtml(Utilities::WATextToHtml(clipboard->text(),32,false));

            return true;
        }
        else if (!isComposing)
        {
            isComposing = true;
            emit composing();
        }
        else
        {
            lastKeyPressed = QDateTime::currentMSecsSinceEpoch();
            composingTimer.start(2000);
        }
    }
    else if (event->type() == QEvent::InputMethod)
    {
        QInputMethodEvent *inputEvent = (QInputMethodEvent *) event;

        //Utilities::logData("Commit String: '" + inputEvent->commitString() + "'");
        if (inputEvent->commitString() == "\n" && Client::enterIsSend)
        {
            // Let's hide the keyboard if it was shown
            QTimer::singleShot(0,this,SLOT(closeKB()));
            isComposing = false;
            emit returnPressed();
            return true;
        }
    }

    return QTextEdit::eventFilter(obj,event);
}
Exemplo n.º 29
0
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);
}