void CIMIClassicView::_makeSelection (int candiIdx, unsigned& mask) { candiIdx += m_candiPageFirst; if (!m_tailSentence.empty ()) --candiIdx; if (candiIdx < 0) { // commit the best sentence mask |= PREEDIT_MASK | CANDIDATE_MASK; _doCommit (); clearIC (); } else if (candiIdx < m_candiList.size ()) { mask |= PREEDIT_MASK | CANDIDATE_MASK; CCandidate& candi = m_candiList [candiIdx]; m_pIC->makeSelection (candi); m_candiFrIdx = candi.m_end; if (m_cursorFrIdx < m_candiFrIdx) m_cursorFrIdx = m_candiFrIdx; CLattice& lattice = m_pIC->getLattice (); while (m_candiFrIdx < m_pIC->getLastFrIdx () && !lattice[m_candiFrIdx+1].isUnusedFrame () && !lattice[m_candiFrIdx+1].isSyllableFrame ()) { ++ m_candiFrIdx; lattice[m_candiFrIdx].m_bwType |= CLatticeFrame::IGNORED; } if (m_candiFrIdx == m_pIC->getLastFrIdx ()) { _doCommit (); clearIC (); } else { m_candiPageFirst = 0; _getCandidates (); } } else if (candiIdx == 0 && m_candiList.size() == 0) { // user might delete all the left over pinyin characters, this will // make m_candiList empty // 0 or space choices should commit previous selected candidates mask |= PREEDIT_MASK | CANDIDATE_MASK; _doCommit(); clearIC(); } }
bool CIMIClassicView::onKeyEvent(const CKeyEvent& key) { unsigned changeMasks = 0; unsigned keycode = key.code; unsigned keyvalue = key.value; unsigned modifiers = key.modifiers; #ifdef DEBUG printf("Classic View got a key (0x%x-0x%x-0x%x)...", keycode, keyvalue, modifiers); if (((modifiers & IM_CTRL_MASK) != 0) && (keyvalue == 'P' || keyvalue=='p')) m_pIC->printLattice(); #endif if (m_pHotkeyProfile && m_pHotkeyProfile->isModeSwitchKey(key)) { setStatusAttrValue(CIMIWinHandler::STATUS_ID_CN, (!m_bCN)?1:0); if (!m_pIC->isEmpty ()) { changeMasks |= CANDIDATE_MASK | PREEDIT_MASK; clearIC (); } } else if (m_pHotkeyProfile && m_pHotkeyProfile->isPunctSwitchKey(key)) { // On CTRL+. switch Full/Half punc changeMasks |= KEYEVENT_USED; setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLPUNC, (!m_bFullPunct)?1:0); } else if (m_pHotkeyProfile && m_pHotkeyProfile->isSymbolSwitchKey(key)) { // On SHIFT+SPACE switch Full/Half symbol changeMasks |= KEYEVENT_USED; setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLSYMBOL, (!m_bFullSymbol)?1:0); } else if (modifiers == IM_CTRL_MASK && keycode == IM_VK_LEFT) { // move left if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; _moveLeft (changeMasks); } } else if (modifiers == IM_CTRL_MASK && keycode == IM_VK_RIGHT) { // move right if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; _moveRight (changeMasks); } } else if ( ((modifiers == 0 && keycode == IM_VK_PAGE_UP) || (m_pHotkeyProfile && m_pHotkeyProfile->isPageUpKey (key))) && !m_pIC->isEmpty() ) { changeMasks |= KEYEVENT_USED; int sz = m_candiList.size() + ((m_tailSentence.size() > 0)?1:0); if (sz > 0 && m_candiPageFirst > 0) { m_candiPageFirst -= m_candiWindowSize; if (m_candiPageFirst < 0) m_candiPageFirst = 0; changeMasks |= CANDIDATE_MASK; } } else if ( ((modifiers == 0 && keycode == IM_VK_PAGE_DOWN) || (m_pHotkeyProfile && m_pHotkeyProfile->isPageDownKey (key))) && !m_pIC->isEmpty() ) { changeMasks |= KEYEVENT_USED; int sz = m_candiList.size() + ((m_tailSentence.size() > 0)?1:0); if (sz > 0 && m_candiPageFirst + m_candiWindowSize < sz) { m_candiPageFirst += m_candiWindowSize; changeMasks |= CANDIDATE_MASK; } } else if (modifiers == IM_CTRL_MASK && (keyvalue >= '0' && keyvalue <= '9') && (m_candiWindowSize >= 10 || keyvalue < ('1' + m_candiWindowSize)) && !m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; unsigned sel = (keyvalue == '0'? 9: keyvalue-'1'); _deleteCandidate (sel, changeMasks); goto PROCESSED; } else if ((modifiers & (IM_CTRL_MASK | IM_ALT_MASK | IM_RELEASE_MASK)) == 0) { if ((keyvalue >= '0' && keyvalue <= '9') && (m_candiWindowSize >= 10 || keyvalue < ('1' + m_candiWindowSize))) { // try to make selection if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; unsigned sel = (keyvalue == '0'? 9: keyvalue-'1'); _makeSelection (sel, changeMasks); } else { m_numeric_mode = true; } goto PROCESSED; } if (keyvalue == '.' && m_numeric_mode) { m_numeric_mode = false; goto PROCESSED; } m_numeric_mode = false; if (islower(keyvalue)) { changeMasks |= KEYEVENT_USED; _insert (keyvalue, changeMasks); } else if (keyvalue > 0x20 && keyvalue < 0x7f) { changeMasks |= KEYEVENT_USED; if (m_pIC->isEmpty ()) { _insert (keyvalue, changeMasks); _doCommit (); clearIC (); } else { _insert (keyvalue, changeMasks); } } else if (keycode == IM_VK_BACK_SPACE || keycode == IM_VK_DELETE) { if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; _erase (keycode == IM_VK_BACK_SPACE, changeMasks); } } else if (keycode == IM_VK_SPACE) { if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; _makeSelection (0, changeMasks); } } else if (keycode == IM_VK_ENTER) { if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED | CANDIDATE_MASK | PREEDIT_MASK; _doCommit (false); clearIC (); } } else if (keycode == IM_VK_ESCAPE) { if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED | CANDIDATE_MASK | PREEDIT_MASK; clearIC (); } } else if (keycode == IM_VK_LEFT) { // move left syllable if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; _moveLeftSyllable (changeMasks); } } else if (keycode == IM_VK_RIGHT) { // move right syllable if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; _moveRightSyllable (changeMasks); } } else if (keycode == IM_VK_HOME) { // move home if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; _moveHome (changeMasks); } } else if (keycode == IM_VK_END) { // move end if (!m_pIC->isEmpty ()) { changeMasks |= KEYEVENT_USED; _moveEnd (changeMasks); } } } else { goto RETURN; } PROCESSED:; m_pHotkeyProfile->rememberLastKey(key); RETURN:; #ifdef DEBUG printf(" |-->(Mask=0x%x)\n", changeMasks); #endif updateWindows (changeMasks); return changeMasks & KEYEVENT_USED; }
bool CIMIXhView::onKeyEvent(const CKeyEvent& key) { unsigned changeMasks = 0; unsigned keycode = key.code; unsigned keyvalue = key.value; unsigned modifiers = key.modifiers; bool isKeyStroke = false; #ifdef DEBUG printf("Xh View got a key (0x%x-0x%x-0x%x)...\n", keycode, keyvalue, modifiers); if (((modifiers & IM_CTRL_MASK) != 0) && (keyvalue == 'P' || keyvalue == 'p')) m_pIC->printLattice(); #endif if (m_pHotkeyProfile && m_pHotkeyProfile->isModeSwitchKey(key)) { setStatusAttrValue(CIMIWinHandler::STATUS_ID_CN, (!m_bCN) ? 1 : 0); if (!m_pIC->isEmpty()) { changeMasks |= CANDIDATE_MASK | PREEDIT_MASK; clearIC(); } } else if (m_pHotkeyProfile && m_pHotkeyProfile->isPunctSwitchKey(key)) { // On CTRL+. switch Full/Half punc changeMasks |= KEYEVENT_USED; setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLPUNC, (!m_bFullPunct) ? 1 : 0); } else if (m_pHotkeyProfile && m_pHotkeyProfile->isSymbolSwitchKey(key)) { // On SHIFT+SPACE switch Full/Half symbol changeMasks |= KEYEVENT_USED; setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLSYMBOL, (!m_bFullSymbol) ? 1 : 0); } else if (modifiers == IM_CTRL_MASK && keycode == IM_VK_LEFT) { // move left if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveLeft(changeMasks); } } else if (modifiers == IM_CTRL_MASK && keycode == IM_VK_RIGHT) { // move right if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveRight(changeMasks); } } else if (((modifiers == 0 && keycode == IM_VK_PAGE_UP) || (m_pHotkeyProfile && m_pHotkeyProfile->isPageUpKey(key))) && !m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; if (m_candiPageFirst > 0) { m_candiPageFirst -= m_candiWindowSize; if (m_candiPageFirst < 0) m_candiPageFirst = 0; changeMasks |= CANDIDATE_MASK; } } else if (((modifiers == 0 && keycode == IM_VK_PAGE_DOWN) || (m_pHotkeyProfile && m_pHotkeyProfile->isPageDownKey(key))) && !m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; if (m_candiPageFirst + m_candiWindowSize < candidateListSize()) { m_candiPageFirst += m_candiWindowSize; changeMasks |= CANDIDATE_MASK; } } else if (m_pHotkeyProfile && m_pHotkeyProfile->isCandiDeleteKey(key, m_candiWindowSize) && !m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; unsigned sel = (keyvalue == '0' ? 9 : keyvalue - '1'); deleteCandidate(sel, changeMasks); goto PROCESSED; } else if ((modifiers & (IM_CTRL_MASK | IM_ALT_MASK | IM_SUPER_MASK | IM_RELEASE_MASK)) == 0) { if (isKeyValueSelectNumber(keyvalue)) { // try to make selection if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; unsigned sel = getSelectionNumber(keyvalue); makeSelection(sel, changeMasks); } else if (m_smartPunct) { m_pIC->omitNextPunct(); } // using the same keys between selections isKeyStroke = true; goto PROCESSED; } if (keyvalue >= '1' && keyvalue <= '5') { changeMasks |= KEYEVENT_USED; _insert(keyvalue, changeMasks); isKeyStroke = true; } else if (keyvalue > 0x60 && keyvalue < 0x7b) { /* islower(keyvalue) */ changeMasks |= KEYEVENT_USED; _insert(keyvalue, changeMasks); isKeyStroke = true; } else if (keyvalue > 0x20 && keyvalue < 0x7f) { /* isprint(keyvalue) && !isspace(keyvalue) */ changeMasks |= KEYEVENT_USED; if (m_pIC->isEmpty()) { _insert(keyvalue, changeMasks); _doCommit(); clearIC(); } else { _insert(keyvalue, changeMasks); } isKeyStroke = true; } else if (keycode == IM_VK_BACK_SPACE || keycode == IM_VK_DELETE) { if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _erase(keycode == IM_VK_BACK_SPACE, changeMasks); } isKeyStroke = true; } else if (keycode == IM_VK_SPACE) { if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; makeSelection(0, changeMasks); } else { wstring wstr = (CFullCharManager::fullPuncOp())(keyvalue); if (wstr.size()) { _commitString(wstr); changeMasks |= KEYEVENT_USED; } } } else if (keycode == IM_VK_ENTER) { if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED | CANDIDATE_MASK | PREEDIT_MASK; _doCommit(false); clearIC(); } } else if (keycode == IM_VK_ESCAPE) { if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED | CANDIDATE_MASK | PREEDIT_MASK; clearIC(); } } else if (keycode == IM_VK_LEFT) { // move left syllable if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveLeftSyllable(changeMasks); } } else if (keycode == IM_VK_RIGHT) { // move right syllable if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveRightSyllable(changeMasks); } } else if (keycode == IM_VK_HOME) { // move home if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveHome(changeMasks); } } else if (keycode == IM_VK_END) { // move end if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveEnd(changeMasks); } } } else { goto RETURN; } PROCESSED:; m_pHotkeyProfile->rememberLastKey(key); RETURN:; if (isKeyStroke) { setOpMode(XHVOM_INPUT); } else { setOpMode(XHVOM_SELECT); } #ifdef DEBUG printf(" |-->(Mask=0x%x)\n", changeMasks); #endif updateWindows(changeMasks); return changeMasks & KEYEVENT_USED; }