Example #1
0
FCITX_EXPORT_API
char* FcitxUICandidateWordToCString(FcitxInstance* instance)
{
    size_t len = 0;
    int i;
    FcitxInputState* input = instance->input;
    FcitxCandidateWord* candWord;
    for (candWord = FcitxCandidateWordGetCurrentWindow(input->candList), i = 0;
            candWord != NULL;
            candWord = FcitxCandidateWordGetCurrentWindowNext(input->candList, candWord), i ++) {
        char strTemp[3] = { '\0', '\0', '\0' };
        strTemp[0] = FcitxCandidateWordGetChoose(input->candList)[i];

        if (instance->config->bPointAfterNumber)
            strTemp[1] = '.';

        len += strlen(strTemp);
        len += strlen(candWord->strWord);

        if (candWord->strExtra && strlen(candWord->strExtra))
            len += strlen(candWord->strExtra);

        len++;
    }

    char *result = fcitx_utils_malloc0(sizeof(char) * (len + 1));

    for (candWord = FcitxCandidateWordGetCurrentWindow(input->candList), i = 0;
            candWord != NULL;
            candWord = FcitxCandidateWordGetCurrentWindowNext(input->candList, candWord), i ++) {
        char strTemp[3] = { '\0', '\0', '\0' };
        strTemp[0] = FcitxCandidateWordGetChoose(input->candList)[i];

        if (instance->config->bPointAfterNumber)
            strTemp[1] = '.';

        strcat(result, strTemp);
        strcat(result, candWord->strWord);

        if (candWord->strExtra && strlen(candWord->strExtra))
            strcat(result, candWord->strExtra);

        strcat(result, " ");
    }

    return result;
}
Example #2
0
File: ui.c Project: eguopt/fcitx
FCITX_EXPORT_API
int FcitxUINewMessageToOldStyleMessage(FcitxInstance* instance, FcitxMessages* msgUp, FcitxMessages* msgDown)
{
    int i = 0;
    FcitxInputState* input = instance->input;
    int extraLength = input->iCursorPos;
    FcitxMessagesSetMessageCount(msgUp, 0);
    FcitxMessagesSetMessageCount(msgDown, 0);

    for (i = 0; i < FcitxMessagesGetMessageCount(input->msgAuxUp) ; i ++) {
        FcitxMessagesAddMessageAtLast(msgUp, FcitxMessagesGetMessageType(input->msgAuxUp, i), "%s", FcitxMessagesGetMessageString(input->msgAuxUp, i));
        extraLength += strlen(FcitxMessagesGetMessageString(input->msgAuxUp, i));
    }

    for (i = 0; i < FcitxMessagesGetMessageCount(input->msgPreedit) ; i ++)
        FcitxMessagesAddMessageAtLast(msgUp, FcitxMessagesGetMessageType(input->msgPreedit, i), "%s", FcitxMessagesGetMessageString(input->msgPreedit, i));

    for (i = 0; i < FcitxMessagesGetMessageCount(input->msgAuxDown) ; i ++)
        FcitxMessagesAddMessageAtLast(msgDown, FcitxMessagesGetMessageType(input->msgAuxDown, i), "%s", FcitxMessagesGetMessageString(input->msgAuxDown, i));

    FcitxCandidateWord* candWord = NULL;

    for (candWord = FcitxCandidateWordGetCurrentWindow(input->candList), i = 0;
            candWord != NULL;
            candWord = FcitxCandidateWordGetCurrentWindowNext(input->candList, candWord), i ++) {
        char strTemp[3] = { '\0', '\0', '\0' };
        strTemp[0] = FcitxCandidateWordGetChoose(input->candList)[i];

        if (instance->config->bPointAfterNumber)
            strTemp[1] = '.';

        unsigned int mod = FcitxCandidateWordGetModifier(input->candList);

        FcitxMessagesAddMessageAtLast(msgDown, MSG_INDEX, "%s%s%s%s%s",
                                      (mod & FcitxKeyState_Super) ? "M-" : "",
                                      (mod & FcitxKeyState_Ctrl) ? "C-" : "",
                                      (mod & FcitxKeyState_Alt) ? "A-" : "",
                                      (mod & FcitxKeyState_Shift) ? "S-" : "",
                                      strTemp);

        FcitxMessageType type = candWord->wordType;

        if (i == 0
            && FcitxCandidateWordGetCurrentPage(input->candList) == 0
            && type == MSG_OTHER
            && !FcitxInstanceGetContextBoolean(instance, CONTEXT_DISABLE_AUTO_FIRST_CANDIDATE_HIGHTLIGHT)
        )
            type = MSG_FIRSTCAND;

        FcitxMessagesAddMessageAtLast(msgDown, type, "%s", candWord->strWord);

        if (candWord->strExtra && strlen(candWord->strExtra) != 0)
            FcitxMessagesAddMessageAtLast(msgDown, candWord->extraType, "%s", candWord->strExtra);

        FcitxMessagesAddMessageAtLast(msgDown, MSG_OTHER, " ");
    }

    return extraLength;
}
Example #3
0
File: ui.c Project: pkg-ime/fcitx
FCITX_EXPORT_API
int FcitxUINewMessageToOldStyleMessage(FcitxInstance* instance, FcitxMessages* msgUp, FcitxMessages* msgDown)
{
    int i = 0;
    FcitxInputState* input = instance->input;
    int extraLength = input->iCursorPos;
    FcitxMessagesSetMessageCount(msgUp, 0);
    FcitxMessagesSetMessageCount(msgDown, 0);

    for (i = 0; i < FcitxMessagesGetMessageCount(input->msgAuxUp) ; i ++) {
        FcitxMessagesAddMessageAtLast(msgUp, FcitxMessagesGetMessageType(input->msgAuxUp, i), "%s", FcitxMessagesGetMessageString(input->msgAuxUp, i));
        extraLength += strlen(FcitxMessagesGetMessageString(input->msgAuxUp, i));
    }

    for (i = 0; i < FcitxMessagesGetMessageCount(input->msgPreedit) ; i ++)
        FcitxMessagesAddMessageAtLast(msgUp, FcitxMessagesGetMessageType(input->msgPreedit, i), "%s", FcitxMessagesGetMessageString(input->msgPreedit, i));

    for (i = 0; i < FcitxMessagesGetMessageCount(input->msgAuxDown) ; i ++)
        FcitxMessagesAddMessageAtLast(msgDown, FcitxMessagesGetMessageType(input->msgAuxDown, i), "%s", FcitxMessagesGetMessageString(input->msgAuxDown, i));

    FcitxCandidateWord* candWord = NULL;

    for (candWord = FcitxCandidateWordGetCurrentWindow(input->candList), i = 0;
            candWord != NULL;
            candWord = FcitxCandidateWordGetCurrentWindowNext(input->candList, candWord), i ++) {
        char strTemp[3] = { '\0', '\0', '\0' };
        strTemp[0] = FcitxCandidateWordGetChoose(input->candList)[i];

        if (instance->config->bPointAfterNumber)
            strTemp[1] = '.';

        FcitxMessagesAddMessageAtLast(msgDown, MSG_INDEX, "%s", strTemp);

        FcitxMessageType type = candWord->wordType;

        if (i == 0
            && FcitxCandidateWordGetCurrentPage(input->candList) == 0
            && type == MSG_OTHER)
            type = MSG_FIRSTCAND;

        FcitxMessagesAddMessageAtLast(msgDown, type, "%s", candWord->strWord);

        if (candWord->strExtra && strlen(candWord->strExtra) != 0)
            FcitxMessagesAddMessageAtLast(msgDown, candWord->extraType, "%s", candWord->strExtra);

        FcitxMessagesAddMessageAtLast(msgDown, MSG_OTHER, " ");
    }

    return extraLength;
}
Example #4
0
boolean InputWindowEventHandler(void *arg, XEvent* event)
{
    FcitxXlibWindow* window = arg;
    InputWindow* inputWindow = arg;
    FcitxInstance* instance = window->owner->owner;
    FcitxInputState* input = FcitxInstanceGetInputState(instance);
    if (event->xany.window == window->wId) {
        switch (event->type) {
        case MotionNotify:
            {
                FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);
                int             x,
                                y;
                x = event->xbutton.x;
                y = event->xbutton.y;

                boolean flag = false;
                int i;
                FcitxCandidateWord* candWord;
                uint32_t newHighlight = 0;
                for (candWord = FcitxCandidateWordGetCurrentWindow(candList), i = 0;
                     candWord != NULL;
                     candWord = FcitxCandidateWordGetCurrentWindowNext(candList, candWord), i ++) {
                    if (IsInRect(x - window->contentX, y - window->contentY, &inputWindow->candRect[i])) {
                        newHighlight = CANDIDATE_HIGHLIGHT(i);
                        flag = true;
                        break;
                    }
                }

                if (!flag) {
                    if (IsInRect(x - window->contentX, y - window->contentY, &inputWindow->prevRect)) {
                        newHighlight = PREVNEXT_HIGHLIGHT(true);
                    } else if (IsInRect(x - window->contentX, y - window->contentY, &inputWindow->nextRect)) {
                        newHighlight = PREVNEXT_HIGHLIGHT(false);
                    }
                }

                if (newHighlight != inputWindow->highlight) {
                    inputWindow->highlight = newHighlight;
                    FcitxXlibWindowPaint(&inputWindow->parent);
                }
            }
            break;
        case Expose:
            FcitxXlibWindowPaint(&inputWindow->parent);
            break;
        case ButtonPress:
            switch (event->xbutton.button) {
                case Button1: {

                    MainWindowSetMouseStatus(window->owner->mainWindow, NULL, RELEASE, RELEASE);
                    int             x,
                                    y;
                    x = event->xbutton.x;
                    y = event->xbutton.y;

                    FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input);

                    boolean flag = false;
                    int i;
                    FcitxCandidateWord* candWord;
                    for (candWord = FcitxCandidateWordGetCurrentWindow(candList), i = 0;
                         candWord != NULL;
                         candWord = FcitxCandidateWordGetCurrentWindowNext(candList, candWord), i ++) {
                        if (IsInRect(x - window->contentX, y - window->contentY, &inputWindow->candRect[i])) {
                            FcitxInstanceChooseCandidateByIndex(instance, i);

                            flag = true;
                            break;
                        }
                    }

                    if (flag)
                        break;

                    if (IsInRect(x - window->contentX, y - window->contentY, &inputWindow->prevRect)) {
                        FcitxCandidateWordGoPrevPage(candList);
                        FcitxInstanceProcessInputReturnValue(window->owner->owner, IRV_DISPLAY_CANDWORDS);
                    } else if (IsInRect(x - window->contentX, y - window->contentY, &inputWindow->nextRect)) {
                        FcitxCandidateWordGoNextPage(candList);
                        FcitxInstanceProcessInputReturnValue(window->owner->owner, IRV_DISPLAY_CANDWORDS);
                    } else if (ClassicUIMouseClick(window->owner, window->wId, &x, &y)) {

                        FcitxInputContext* ic = FcitxInstanceGetCurrentIC(window->owner->owner);

                        if (ic) {
                            FcitxInstanceSetWindowOffset(window->owner->owner, ic, x - inputWindow->iOffsetX, y  - inputWindow->iOffsetY);
                        }

                        FcitxXlibWindowPaint(&inputWindow->parent);
                    }
                }
                break;
            }
            break;
        }
        return true;
    }
    return false;
}