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; }
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; }
FCITX_EXPORT_API FcitxCandidateWord* FcitxCandidateWordGetCurrentWindowNext(FcitxCandidateWordList* candList, FcitxCandidateWord* candWord) { FcitxCandidateWord* nextCandWord = (FcitxCandidateWord*) utarray_next(&candList->candWords, candWord); FcitxCandidateWord* startCandWord = FcitxCandidateWordGetCurrentWindow(candList); if (nextCandWord == NULL) return NULL; int delta = utarray_eltidx(&candList->candWords, nextCandWord) - utarray_eltidx(&candList->candWords, startCandWord); if (delta < 0 || delta >= candList->wordPerPage) return NULL; return nextCandWord; }
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; }
static boolean ClipboardPreHook(void *arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE *ret_val) { FcitxClipboard *clipboard = arg; FcitxInstance *instance = clipboard->owner; if (!clipboard->active) return false; FcitxInputState *input = FcitxInstanceGetInputState(instance); FcitxCandidateWordList *cand_list = FcitxInputStateGetCandidateList(input); FcitxGlobalConfig *fc = FcitxInstanceGetGlobalConfig(instance); *ret_val = IRV_TO_PROCESS; int key; FcitxCandidateWord *cand_word; if (FcitxHotkeyIsHotKey(sym, state, fc->nextWord)) { cand_word = FcitxCandidateWordGetFocus(cand_list, true); cand_word = FcitxCandidateWordGetNext(cand_list, cand_word); if (!cand_word) { FcitxCandidateWordSetPage(cand_list, 0); cand_word = FcitxCandidateWordGetFirst(cand_list); } else { FcitxCandidateWordSetFocus( cand_list, FcitxCandidateWordGetIndex(cand_list, cand_word)); } } else if (FcitxHotkeyIsHotKey(sym, state, fc->prevWord)) { cand_word = FcitxCandidateWordGetFocus(cand_list, true); cand_word = FcitxCandidateWordGetPrev(cand_list, cand_word); if (!cand_word) { FcitxCandidateWordSetPage( cand_list, FcitxCandidateWordPageCount(cand_list) - 1); cand_word = FcitxCandidateWordGetLast(cand_list); } else { FcitxCandidateWordSetFocus( cand_list, FcitxCandidateWordGetIndex(cand_list, cand_word)); } } else if (FcitxHotkeyIsHotKey(sym, state, FcitxConfigPrevPageKey(instance, fc))) { cand_word = FcitxCandidateWordGetFocus(cand_list, true); if (!FcitxCandidateWordGoPrevPage(cand_list)) { FcitxCandidateWordSetType(cand_word, MSG_CANDIATE_CURSOR); *ret_val = IRV_DO_NOTHING; return true; } cand_word = FcitxCandidateWordGetCurrentWindow(cand_list) + FcitxCandidateWordGetCurrentWindowSize(cand_list) - 1; } else if (FcitxHotkeyIsHotKey(sym, state, FcitxConfigNextPageKey(instance, fc))) { cand_word = FcitxCandidateWordGetFocus(cand_list, true); if (!FcitxCandidateWordGoNextPage(cand_list)) { FcitxCandidateWordSetType(cand_word, MSG_CANDIATE_CURSOR); *ret_val = IRV_DO_NOTHING; return true; } cand_word = FcitxCandidateWordGetCurrentWindow(cand_list); } else if ((key = FcitxCandidateWordCheckChooseKey(cand_list, sym, state)) >= 0) { *ret_val = FcitxCandidateWordChooseByIndex(cand_list, key); return true; } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) { cand_word = FcitxCandidateWordGetFocus(cand_list, true); *ret_val = FcitxCandidateWordChooseByTotalIndex( cand_list, FcitxCandidateWordGetIndex(cand_list, cand_word)); return true; } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) { *ret_val = IRV_FLAG_RESET_INPUT | IRV_FLAG_UPDATE_INPUT_WINDOW; return true; } else { *ret_val = IRV_DO_NOTHING; return true; } FcitxCandidateWordSetType(cand_word, MSG_CANDIATE_CURSOR); *ret_val = IRV_FLAG_UPDATE_INPUT_WINDOW; return true; }
static INPUT_RETURN_VALUE AutoEngCheckSelect(FcitxAutoEngState *autoEngState, FcitxKeySym sym, unsigned int state) { FcitxInstance *instance = autoEngState->owner; FcitxCandidateWordList *cand_list = FcitxInputStateGetCandidateList( FcitxInstanceGetInputState(autoEngState->owner)); if (!FcitxCandidateWordGetListSize(cand_list)) return IRV_TO_PROCESS; FcitxInputState *input = FcitxInstanceGetInputState(instance); FcitxGlobalConfig *fc = FcitxInstanceGetGlobalConfig(instance); int key; FcitxCandidateWord *cand_word; if (FcitxHotkeyIsHotKey(sym, state, fc->nextWord)) { if (!autoEngState->cursor_moved) { cand_word = FcitxCandidateWordGetCurrentWindow(cand_list); } else { cand_word = FcitxCandidateWordGetFocus(cand_list, true); cand_word = FcitxCandidateWordGetNext(cand_list, cand_word); if (!cand_word) { FcitxCandidateWordSetPage(cand_list, 0); } else { FcitxCandidateWordSetFocus( cand_list, FcitxCandidateWordGetIndex(cand_list, cand_word)); } } } else if (FcitxHotkeyIsHotKey(sym, state, fc->prevWord)) { if (!autoEngState->cursor_moved) { cand_word = FcitxCandidateWordGetByIndex( cand_list, FcitxCandidateWordGetCurrentWindowSize(cand_list) - 1); } else { cand_word = FcitxCandidateWordGetFocus(cand_list, true); cand_word = FcitxCandidateWordGetPrev(cand_list, cand_word); if (cand_word) { FcitxCandidateWordSetFocus( cand_list, FcitxCandidateWordGetIndex(cand_list, cand_word)); } } } else if (FcitxHotkeyIsHotKey(sym, state, FcitxConfigPrevPageKey(instance, fc))) { boolean has_prev_page; cand_word = FcitxCandidateWordGetFocus(cand_list, true); has_prev_page = FcitxCandidateWordGoPrevPage(cand_list); if (!autoEngState->cursor_moved) { cand_word = NULL; } else if (has_prev_page) { cand_word = FcitxCandidateWordGetCurrentWindow(cand_list) + FcitxCandidateWordGetCurrentWindowSize(cand_list) - 1; } } else if (FcitxHotkeyIsHotKey(sym, state, FcitxConfigNextPageKey(instance, fc))) { boolean has_next_page; cand_word = FcitxCandidateWordGetFocus(cand_list, true); has_next_page = FcitxCandidateWordGoNextPage(cand_list); if (!autoEngState->cursor_moved) { cand_word = NULL; } else if (has_next_page) { cand_word = FcitxCandidateWordGetCurrentWindow(cand_list); } } else if ((key = FcitxCandidateWordCheckChooseKey(cand_list, sym, state)) >= 0) { return FcitxCandidateWordChooseByIndex(cand_list, key); } else { return IRV_TO_PROCESS; } if (cand_word) { FcitxCandidateWordSetType(cand_word, MSG_CANDIATE_CURSOR); if (!autoEngState->cursor_moved) AutoEngSwapBuff(autoEngState); AutoEngSetBuff(autoEngState, cand_word->strWord, '\0'); autoEngState->cursor_moved = true; } else if (autoEngState->cursor_moved) { AutoEngSwapBuff(autoEngState); autoEngState->cursor_moved = false; } else { return IRV_FLAG_UPDATE_INPUT_WINDOW; } FcitxMessages *client_preedit = FcitxInputStateGetClientPreedit(input); FcitxMessages *preedit = FcitxInputStateGetPreedit(input); FcitxMessagesSetMessageCount(client_preedit, 0); FcitxMessagesSetMessageCount(preedit, 0); FcitxMessagesAddMessageStringsAtLast(client_preedit, MSG_INPUT, autoEngState->buf); FcitxMessagesAddMessageStringsAtLast(preedit, MSG_INPUT, autoEngState->buf); FcitxInputStateSetCursorPos(input, autoEngState->index); FcitxInputStateSetClientCursorPos(input, autoEngState->index); return IRV_FLAG_UPDATE_INPUT_WINDOW; }
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; }