void QMaliitPlatformInputContext::setFocusObject(QObject *object)
{
    if (!d->valid)
        return;

    QWindow *window = qGuiApp->focusWindow();
    if (window != d->window.data()) {
       if (d->window)
           disconnect(d->window.data(), SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)),
                      this, SLOT(updateServerWindowOrientation(Qt::ScreenOrientation)));
        d->window = window;
        if (d->window)
            connect(d->window.data(), SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)),
                    this, SLOT(updateServerWindowOrientation(Qt::ScreenOrientation)));
    }

    d->imState["focusState"] = (object != 0);
    if (inputMethodAccepted()) {
        if (window)
            d->imState["winId"] = static_cast<qulonglong>(window->winId());

        if (!d->active) {
            d->active = true;
            d->server->activateContext();

            if (window)
                d->server->appOrientationChanged(orientationAngle(window->contentOrientation()));
        }
    }
    d->sendStateUpdate(/*focusChanged*/true);
    if (inputMethodAccepted() && window && d->visibility == InputPanelShowRequested)
        showInputPanel();
}
示例#2
0
void MInputContext::update(Qt::InputMethodQueries queries)
{
    if (debug) qDebug() << InputContextName << "in" << __PRETTY_FUNCTION__;

    Q_UNUSED(queries) // fetching everything

    if (queries & Qt::ImPlatformData) {
        updateInputMethodExtensions();
    }

    bool effectiveFocusChange = false;
    if (queries & Qt::ImEnabled) {
        bool newAcceptance = inputMethodAccepted();
        if (newAcceptance && !active) {
            setFocusObject(QGuiApplication::focusObject());
            return;
        }

        if (newAcceptance != currentFocusAcceptsInput) {
            currentFocusAcceptsInput = newAcceptance;
            effectiveFocusChange = true;
        }
    }
    // get the state information of currently focused widget, and pass it to input method server
    QMap<QString, QVariant> stateInformation = getStateInformation();
    imServer->updateWidgetInformation(stateInformation, effectiveFocusChange);
}
示例#3
0
bool MInputContext::filterEvent(const QEvent *event)
{
    bool eaten = false;

    switch (event->type()) {

    case QEvent::KeyPress:
    case QEvent::KeyRelease:
        if (!inputMethodAccepted()) {
            break;
        }

        if (redirectKeys) {
            const QKeyEvent *key = static_cast<const QKeyEvent *>(event);
            imServer->processKeyEvent(key->type(), static_cast<Qt::Key>(key->key()),
                                      key->modifiers(), key->text(), key->isAutoRepeat(),
                                      key->count(), key->nativeScanCode(),
                                      key->nativeModifiers(), 0 /* currentKeyEventTime */);
            eaten = true;
        }
        break;

    default:
        break;
    }

    return eaten;
}
示例#4
0
void MInputContext::invokeAction(QInputMethod::Action action, int x)
{
    if (debug) qDebug() << InputContextName << "in" << __PRETTY_FUNCTION__;

    if (!inputMethodAccepted())
        return;

    if (action == QInputMethod::Click) {
        if (x < 0 || x >= preedit.length()) {
            reset();
            return;
        }

        // To preserve the wire protocol, the "x" argument gets
        // transferred in widget state instead of being an extra
        // argument to mouseClickedOnPreedit().
        QMap<QString, QVariant> stateInformation = getStateInformation();
        stateInformation["preeditClickPos"] = x;
        imServer->updateWidgetInformation(stateInformation, false);

        // FIXME: proper positions and preeditClickPos
        QRect preeditRect;
        QPoint globalPos;
        imServer->mouseClickedOnPreedit(globalPos, preeditRect);

    } else {
        QPlatformInputContext::invokeAction(action, x);
    }
}
示例#5
0
void QWindowsInputContext::setFocusObject(QObject *object)
{
    // ### fixme: On Windows 8.1, it has been observed that the Input context
    // remains active when this happens resulting in a lock-up. Consecutive
    // key events still have VK_PROCESSKEY set and are thus ignored.
    if (m_compositionContext.isComposing)
        imeNotifyCancelComposition(m_compositionContext.hwnd);

    const QWindow *window = QGuiApplication::focusWindow();
    if (object && window && window->handle()) {
        QWindowsWindow *platformWindow = QWindowsWindow::baseWindowOf(window);
        if (inputMethodAccepted()) {
            // Re-enable IME by associating default context saved on first disabling.
            if (platformWindow->testFlag(QWindowsWindow::InputMethodDisabled)) {
                ImmAssociateContext(platformWindow->handle(), QWindowsInputContext::m_defaultContext);
                platformWindow->clearFlag(QWindowsWindow::InputMethodDisabled);
            }
        } else {
            // Disable IME by associating 0 context. Store context first time.
            if (!platformWindow->testFlag(QWindowsWindow::InputMethodDisabled)) {
                const HIMC oldImC = ImmAssociateContext(platformWindow->handle(), 0);
                platformWindow->setFlag(QWindowsWindow::InputMethodDisabled);
                if (!QWindowsInputContext::m_defaultContext && oldImC)
                    QWindowsInputContext::m_defaultContext = oldImC;
            }
        }
    }
}
void QMaliitPlatformInputContext::setSelection(int start, int length)
{
    if (!inputMethodAccepted())
        return;

    QList<QInputMethodEvent::Attribute> attributes;
    attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, start, length, QVariant());
    QInputMethodEvent event(QString(), attributes);
    QGuiApplication::sendEvent(qGuiApp->focusObject(), &event);
}
示例#7
0
void MInputContext::showInputPanel()
{
    if (debug) qDebug() << __PRETTY_FUNCTION__;

    if (inputMethodAccepted()) {
        sipHideTimer.stop();
    }

    if (!active || !inputMethodAccepted()) {
        // in case SIP request comes without a properly focused widget, we
        // don't ask input method server to be shown. It's done when the next widget
        // is focused, so the widget state information can be set.
        inputPanelState = InputPanelShowPending;

    } else {
        // note: could do this also if panel was hidden

        imServer->showInputMethod();
        inputPanelState = InputPanelShown;
    }
}
void QMaliitPlatformInputContext::showInputPanel()
{
    if (debug)
        qDebug() << "showInputPanel";

    if (!inputMethodAccepted())
        d->visibility = InputPanelShowRequested;
    else {
        d->server->showInputMethod();
        d->visibility = InputPanelShown;
        emitInputPanelVisibleChanged();
    }
}
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);
}
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();
}
bool QMaliitPlatformInputContext::selection(QString &selection)
{
    selection.clear();

    if (!inputMethodAccepted())
        return false;

    QInputMethodQueryEvent query(Qt::ImCurrentSelection);
    QGuiApplication::sendEvent(qGuiApp->focusObject(), &query);
    QVariant value = query.value(Qt::ImCurrentSelection);
    if (!value.isValid())
        return false;

    selection = value.toString();
    return true;
}
示例#12
0
bool QHimePlatformInputContext::filterEvent(const QEvent* event)
{
    dbg("QHimePlatformInputContext::filterEvent\n");
    if (event->type() != QEvent::KeyPress && event->type() != QEvent::KeyRelease) {
        goto ret;
    }

    const QKeyEvent* keyEvent;
    keyEvent = static_cast<const QKeyEvent*>(event);
    quint32 keysym ;
    keysym = keyEvent->nativeVirtualKey();
    quint32  state;
    state = keyEvent->nativeModifiers();

    if (!inputMethodAccepted()) {
        goto ret;
    }

    QObject *input;
    input = qApp->focusObject();

    if (!input) {
        goto ret;
    }

    int result;
    if (event->type() == QEvent::KeyPress) {
        if (send_key_press(keysym, state)) {
            update_preedit();
            return true;
        }
    } else {
        char *rstr = NULL;
        result = hime_im_client_forward_key_release(hime_ch,   keysym, state, &rstr);
        if (rstr) {
            free(rstr);
        }

        if (result) {
            return true;
        }
    }

ret:
    return QPlatformInputContext::filterEvent(event);
}
void QQnxInputContext::setFocusObject(QObject *object)
{
    qInputContextDebug() << Q_FUNC_INFO << "input item=" << object;

    if (!inputMethodAccepted()) {
        if (m_inputPanelVisible)
            hideInputPanel();
    } else {
        QInputMethodQueryEvent query(Qt::ImHints);
        QCoreApplication::sendEvent(object, &query);
        int inputHints = query.value(Qt::ImHints).toInt();

        m_virtualKeyboard.setInputHints(inputHints);

        if (!m_inputPanelVisible)
            showInputPanel();
    }
}
void QMaliitPlatformInputContext::invokeAction(QInputMethod::Action action, int x)
{
    if (!inputMethodAccepted())
        return;

    if (action == QInputMethod::Click) {
        if (x < 0 || x >= d->preedit.length()) {
            reset();
            return;
        }

        d->imState["preeditClickPos"] = x;
        d->sendStateUpdate();
        // The first argument is the mouse pos and the second is the
        // preedit rectangle. Both are unused on the server side.
        d->server->mouseClickedOnPreedit(0, 0, 0, 0, 0, 0);
    } else {
        QPlatformInputContext::invokeAction(action, x);
    }
}
void MInputContext::setFocusObject(QObject *focused)
{
    if (debug) qDebug() << InputContextName << "in" << __PRETTY_FUNCTION__ << focused;

    updateInputMethodExtensions();

    QWindow *newFocusWindow = qGuiApp->focusWindow();
    if (newFocusWindow != window.data()) {
       if (window) {
           disconnect(window.data(), SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)),
                      this, SLOT(updateServerOrientation(Qt::ScreenOrientation)));
       }

       window = newFocusWindow;
       if (window) {
           connect(window.data(), SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)),
                   this, SLOT(updateServerOrientation(Qt::ScreenOrientation)));
           updateServerOrientation(window->contentOrientation());
       }
    }

    bool oldAcceptInput = currentFocusAcceptsInput;
    currentFocusAcceptsInput = inputMethodAccepted();

    if (!active && currentFocusAcceptsInput) {
        imServer->activateContext();
        active = true;
        updateServerOrientation(newFocusWindow->contentOrientation());
    }

    if (active && (currentFocusAcceptsInput || oldAcceptInput)) {
        const QMap<QString, QVariant> stateInformation = getStateInformation();
        imServer->updateWidgetInformation(stateInformation, true);
    }

    if (inputPanelState == InputPanelShowPending && currentFocusAcceptsInput) {
        sipHideTimer.stop();
        imServer->showInputMethod();
        inputPanelState = InputPanelShown;
    }
}
void QMaliitPlatformInputContext::updatePreedit(const QDBusMessage &message)
{
    if (!inputMethodAccepted())
        return;

    QList<QVariant> arguments = message.arguments();
    if (arguments.count() != 5) {
        qWarning() << "QMaliitPlatformInputContext::updatePreedit: Received message from input method server with wrong parameters.";
        return;
    }

    d->preedit = arguments[0].toString();

    QList<QInputMethodEvent::Attribute> attributes;

    const QDBusArgument formats = arguments[1].value<QDBusArgument>();
    formats.beginArray();
    while (!formats.atEnd()) {
        formats.beginStructure();
        int start, length, preeditFace;
        formats >> start >> length >> preeditFace;
        formats.endStructure();

        QTextCharFormat format;

        enum PreeditFace {
            PreeditDefault,
            PreeditNoCandidates,
            PreeditKeyPress,      //!< Used for displaying the hwkbd key just pressed
            PreeditUnconvertible, //!< Inactive preedit region, not clickable
            PreeditActive,        //!< Preedit region with active suggestions

        };
        switch (PreeditFace(preeditFace)) {
        case PreeditDefault:
        case PreeditKeyPress:
            format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
            format.setUnderlineColor(QColor(0, 0, 0));
            break;
        case PreeditNoCandidates:
            format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
            format.setUnderlineColor(QColor(255, 0, 0));
            break;
        case PreeditUnconvertible:
            format.setForeground(QBrush(QColor(128, 128, 128)));
            break;
        case PreeditActive:
            format.setForeground(QBrush(QColor(153, 50, 204)));
            format.setFontWeight(QFont::Bold);
            break;
        default:
            break;
        }

        attributes << QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, start, length, format);
    }
    formats.endArray();

    int replacementStart = arguments[2].toInt();
    int replacementLength = arguments[3].toInt();
    int cursorPos = arguments[4].toInt();

    if (debug)
        qWarning() << "updatePreedit" << d->preedit << replacementStart << replacementLength << cursorPos;

    if (cursorPos >= 0)
        attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursorPos, 1, QVariant());

    QInputMethodEvent event(d->preedit, attributes);
    if (replacementStart || replacementLength)
        event.setCommitString(QString(), replacementStart, replacementLength);
    QCoreApplication::sendEvent(qGuiApp->focusObject(), &event);
}