/* * 处理相关鼠标键 */ boolean VKMouseKey(FcitxVKState* vkstate, int x, int y) { int iIndex = 0; char strKey[3] = { 0, 0, 0}; char *pstr = NULL; FcitxInstance* instance = vkstate->owner; if (FcitxUIIsInBox(x, y, 1, 1, VK_WINDOW_WIDTH, 16)) ChangVK(vkstate); else { if (FcitxInstanceGetCurrentIC(instance) == NULL) return false; strKey[1] = '\0'; pstr = strKey; if (y >= 28 && y <= 55) { //第一行 if (x < 4 || x > 348) return false; x -= 4; if (x >= 313 && x <= 344) { //backspace FcitxInstanceForwardKey(instance, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, FcitxKey_BackSpace, 0); return true; } else { iIndex = x / 24; if (iIndex > 12) //避免出现错误 iIndex = 12; pstr = vkstate->vks[vkstate->iCurrentVK].strSymbol[iIndex][vkstate->bShiftPressed ^ vkstate->bVKCaps]; if (vkstate->bShiftPressed) { vkstate->bShiftPressed = false; DrawVKWindow(vkstate->vkWindow); } } } else if (y >= 56 && y <= 83) { //第二行 if (x < 4 || x > 350) return false; if (x >= 4 && x < 38) { //Tab FcitxInstanceForwardKey(instance, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, FcitxKey_Tab, 0); return true; } else { iIndex = 13 + (x - 38) / 24; pstr = vkstate->vks[vkstate->iCurrentVK].strSymbol[iIndex][vkstate->bShiftPressed ^ vkstate->bVKCaps]; if (vkstate->bShiftPressed) { vkstate->bShiftPressed = false; DrawVKWindow(vkstate->vkWindow); } } } else if (y >= 84 && y <= 111) { //第三行 if (x < 4 || x > 350) return false; if (x >= 4 && x < 44) { //Caps //改变大写键状态 vkstate->bVKCaps = !vkstate->bVKCaps; pstr = (char *) NULL; DrawVKWindow(vkstate->vkWindow); } else if (x > 308 && x <= 350) //Return strKey[0] = '\n'; else { iIndex = 26 + (x - 44) / 24; pstr = vkstate->vks[vkstate->iCurrentVK].strSymbol[iIndex][vkstate->bShiftPressed ^ vkstate->bVKCaps]; if (vkstate->bShiftPressed) { vkstate->bShiftPressed = false; DrawVKWindow(vkstate->vkWindow); } } } else if (y >= 112 && y <= 139) { //第四行 if (x < 4 || x > 302) return false; if (x >= 4 && x < 62) { //SHIFT //改变SHIFT键状态 vkstate->bShiftPressed = !vkstate->bShiftPressed; pstr = (char *) NULL; DrawVKWindow(vkstate->vkWindow); } else { iIndex = 37 + (x - 62) / 24; pstr = vkstate->vks[vkstate->iCurrentVK].strSymbol[iIndex][vkstate->bShiftPressed ^ vkstate->bVKCaps]; if (vkstate->bShiftPressed) { vkstate->bShiftPressed = false; DrawVKWindow(vkstate->vkWindow); } } } else if (y >= 140 && y <= 162) { //第五行 if (x >= 4 && x < 38) { //Ins //改变INS键状态 FcitxInstanceForwardKey(instance, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, FcitxKey_Insert, 0); return true; } else if (x >= 61 && x < 98) { //DEL FcitxInstanceForwardKey(instance, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, FcitxKey_Delete, 0); return true; } else if (x >= 99 && x < 270) //空格 strcpy(strKey, " "); else if (x >= 312 && x <= 350) { //ESC SwitchVK(vkstate); pstr = (char *) NULL; } else return false; } if (pstr) { FcitxInstanceCommitString(instance, FcitxInstanceGetCurrentIC(instance), pstr); } } return true; }
boolean ProcessPunc(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal) { FcitxPuncState* puncState = (FcitxPuncState*) arg; FcitxInstance* instance = puncState->owner; FcitxInputState* input = FcitxInstanceGetInputState(puncState->owner); FcitxProfile* profile = FcitxInstanceGetProfile(instance); FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(instance); char *pPunc = NULL; if (*retVal != IRV_TO_PROCESS) return false; FcitxCandidateWordList* candList = FcitxInputStateGetCandidateList(input); if (FcitxCandidateWordPageCount(candList) != 0 && FcitxCandidateWordGetHasGoneToNextPage(candList) ) { const FcitxHotkey* hkPrevPage = FcitxInstanceGetContextHotkey(instance, CONTEXT_ALTERNATIVE_PREVPAGE_KEY); if (hkPrevPage == NULL) hkPrevPage = config->hkPrevPage; if (FcitxHotkeyIsHotKey(sym, state, hkPrevPage)) { return false; } } /* * comparing with upper case, if paging is occupied, * punc will not let next page pass */ if (FcitxCandidateWordPageCount(candList) != 0) { const FcitxHotkey* hkNextPage = FcitxInstanceGetContextHotkey(instance, CONTEXT_ALTERNATIVE_NEXTPAGE_KEY); if (hkNextPage == NULL) hkNextPage = config->hkNextPage; if (FcitxHotkeyIsHotKey(sym, state, hkNextPage)) { return false; } } FcitxKeySym origsym = sym; sym = FcitxHotkeyPadToMain(sym); if (profile->bUseWidePunc) { if (puncState->bLastIsNumber && config->bEngPuncAfterNumber && (FcitxHotkeyIsHotKey(origsym, state, FCITX_PERIOD) || FcitxHotkeyIsHotKey(origsym, state, FCITX_SEMICOLON) || FcitxHotkeyIsHotKey(origsym, state, FCITX_COMMA))) { puncState->cLastIsAutoConvert = origsym; puncState->bLastIsNumber = false; *retVal = IRV_DONOT_PROCESS; return true; } if (FcitxHotkeyIsHotKeySimple(sym, state)) pPunc = GetPunc(puncState, origsym); } /* * 在有候选词未输入的情况下,选择第一个候选词并输入标点 */ if (IsHotKeyPunc(sym, state)) { FcitxInputStateGetOutputString(input)[0] = '\0'; INPUT_RETURN_VALUE ret = IRV_TO_PROCESS; if (!FcitxInputStateGetIsInRemind(input)) ret = FcitxCandidateWordChooseByTotalIndex(FcitxInputStateGetCandidateList(input), 0); /* if there is nothing to commit */ if (ret == IRV_TO_PROCESS) { if (pPunc) { strcat(FcitxInputStateGetOutputString(input), pPunc); *retVal = IRV_PUNC; FcitxInstanceCleanInputWindow(instance); return true; } else return false; } else { if (pPunc) strcat(FcitxInputStateGetOutputString(input), pPunc); else { char buf[2] = { sym, 0 }; strcat(FcitxInputStateGetOutputString(input), buf); } FcitxInstanceCleanInputWindow(instance); *retVal = IRV_PUNC; return true; } return false; } if (profile->bUseWidePunc) { if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE) && puncState->cLastIsAutoConvert) { char *pPunc; FcitxInstanceForwardKey(puncState->owner, FcitxInstanceGetCurrentIC(instance), FCITX_PRESS_KEY, sym, state); pPunc = GetPunc(puncState, puncState->cLastIsAutoConvert); if (pPunc) FcitxInstanceCommitString(puncState->owner, FcitxInstanceGetCurrentIC(instance), pPunc); puncState->cLastIsAutoConvert = 0; *retVal = IRV_DO_NOTHING; return true; } else if (FcitxHotkeyIsHotKeySimple(sym, state)) { if (FcitxHotkeyIsHotKeyDigit(sym, state)) puncState->bLastIsNumber = true; else { puncState->bLastIsNumber = false; } } } puncState->cLastIsAutoConvert = 0; return false; }