Example #1
0
unsigned
CIMIClassicView::_moveHome (unsigned& mask, bool searchAgain)
{
    if (m_cursorFrIdx == 0)
        return 0;

    mask |= PREEDIT_MASK;

    if (m_candiFrIdx != 0) {
        std::vector<unsigned>& best_path    = m_pIC->getBestPath();
        std::vector<unsigned>::iterator it  = best_path.begin();
        std::vector<unsigned>::iterator ite = best_path.end();
        CLattice& lattice = m_pIC->getLattice ();

        for (; it != ite; ++it) {
            if (lattice[*it].m_bwType & CLatticeFrame::USER_SELECTED)
                m_pIC->cancelSelection (*it, false);
        }

        mask |= CANDIDATE_MASK;
        m_candiFrIdx = 0;
        _getCandidates ();

        if (searchAgain) m_pIC->searchFrom ();
    }

    m_cursorFrIdx = 0;
    return 0;
}
Example #2
0
void
CIMIClassicView::_erase (bool backward, unsigned &changeMasks)
{
    if (backward) {
        if (m_cursorFrIdx == m_pIC->getLastFrIdx())
            m_pPySegmentor->pop();
        else if (m_cursorFrIdx > 0)
            m_pPySegmentor->deleteAt(m_cursorFrIdx-1, backward);
        else
            return;
        _moveLeft(changeMasks, true);
    } else {
        if (m_cursorFrIdx < m_pIC->getLastFrIdx ())
            m_pPySegmentor->deleteAt(m_cursorFrIdx-1, backward);
        else
            return;
    }
    
    IPySegmentor::TSegmentVec &segs = m_pPySegmentor->getSegments ();

    if (m_pIC->buildLattice (segs, m_pPySegmentor->updatedFrom()+1))
        _getCandidates ();

    changeMasks |= PREEDIT_MASK | CANDIDATE_MASK | KEYEVENT_USED;
}
Example #3
0
unsigned
CIMIClassicView::_moveLeft (unsigned& mask, bool searchAgain)
{
    if (m_cursorFrIdx == 0)
        return 0;

    mask |= PREEDIT_MASK;
    if (m_cursorFrIdx == m_candiFrIdx) {
        mask |= CANDIDATE_MASK;
        m_candiFrIdx = m_pIC->cancelSelection (m_candiFrIdx, searchAgain);
        _getCandidates ();
    }

    return --m_cursorFrIdx;
}
Example #4
0
void
CIMIClassicView::_deleteCandidate (int candiIdx, unsigned& mask)
{
    candiIdx += m_candiPageFirst;
    if (!m_tailSentence.empty ()) --candiIdx;

    // try to remove candidate 0 which is a calculated sentence
    if (candiIdx < 0) {
        return;
    }

    CCandidate& candi = m_candiList [candiIdx];
    m_pIC->deleteCandidate(candi);
    _getCandidates ();
    mask |= PREEDIT_MASK | CANDIDATE_MASK;
}
Example #5
0
unsigned
CIMIClassicView::_moveLeftSyllable (unsigned& mask, bool searchAgain)
{
    if (m_cursorFrIdx == 0)
        return 0;

    unsigned i, j;
    mask |= PREEDIT_MASK;

    if (m_cursorFrIdx == m_candiFrIdx) {
        mask |= CANDIDATE_MASK;
        m_candiFrIdx = m_pIC->cancelSelection (m_candiFrIdx, searchAgain);
        _getCandidates ();
    }

    m_pPySegmentor->locateSegment (m_cursorFrIdx-1, i, j);
    return m_cursorFrIdx = i;
}
Example #6
0
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();
    }
}
Example #7
0
void
CIMIClassicView::_insert (unsigned keyvalue, unsigned &changeMasks)
{
    changeMasks |= KEYEVENT_USED;

    if (m_pPySegmentor->getInputBuffer().size() >= MAX_LATTICE_LENGTH-1)
        return;

    if (m_cursorFrIdx == m_pIC->getLastFrIdx ())
        m_pPySegmentor->push (keyvalue);
    else
        m_pPySegmentor->insertAt (m_cursorFrIdx, keyvalue);

    m_cursorFrIdx ++;

    if (m_pIC->buildLattice (m_pPySegmentor))
        _getCandidates ();

    changeMasks |= PREEDIT_MASK | CANDIDATE_MASK;
}