Exemplo n.º 1
0
void
ArrayInstance::space_key_press()
{
    // space is the page down key when keying symbols and phrases
    if (m_lookup_table.number_of_candidates() > m_lookup_table.get_page_size())
    {
        lookup_table_page_down();
        return;
    }

    WideString inkey = m_preedit_string;
    
    // If the user is already press the space before, 
    // commit the first candidate in the lookup table
    if (commit_press_count == 1)
    {
        WideString str = m_lookup_table.get_candidate_in_current_page (0);
        if (str.compare(utf8_mbstowcs(SCIM_ARRAY_EMPTY_CHAR)) == 0) {
            hide_lookup_table();
            return;
        }
        if (str.length()) {
            send_commit_string(inkey, str);
            return;
        }
    }

    create_lookup_table(_ScimArray::Array_Table);
    update_lookup_table(m_lookup_table);
    if (m_lookup_table.number_of_candidates() > 1)
    {
        show_lookup_table();
        commit_press_count++;
        return;
    }
    hide_lookup_table();
    WideString str = m_lookup_table.get_candidate_in_current_page (0);
    if (str.length() && str.compare(utf8_mbstowcs(SCIM_ARRAY_EMPTY_CHAR))) {
        send_commit_string(inkey, str);
        return;
    }
}
Exemplo n.º 2
0
bool
ArrayInstance::process_key_event (const KeyEvent& rawkey)
{
    KeyEvent key = rawkey.map_to_layout(SCIM_KEYBOARD_Default);

    if (key.is_key_release ()) return false;

    // English/Chinese change mode key
    if ( match_key_event(m_factory->m_ench_key, key))
    {
        trigger_property(SCIM_PROP_STATUS);
        return true;
    }

    // Full/Half width chang mode key
    if ( match_key_event(m_factory->m_full_half_key, key))
    {
        trigger_property(SCIM_PROP_LETTER);
        return true;
    }

    // if in forward mode
    if (m_forward)
    {
        if ( key.code >= SCIM_KEY_space && key.code <= SCIM_KEY_asciitilde)
        {
            if (m_full_width_letter)
            {
                char widthc = key.get_ascii_code();
                WideString outws;
                outws.push_back(scim_wchar_to_full_width(widthc));
                commit_string(outws);
                return true;
            }
            else
                return false;
        }
        else 
            return false;
    }

    //reset key
    if (key.code == SCIM_KEY_Escape && key.mask == 0) {
        // Do not catch ESC while no key input for VI users
        if (m_preedit_string.size() == 0)
            return false;
        reset ();
        return true;
    }

    //delete key
    if (key.code == SCIM_KEY_BackSpace && key.mask == 0 &&
        m_preedit_string.size () != 0) 
    {
        m_preedit_string.erase (m_preedit_string.length () - 1, 1);
        pre_update_preedit_string (m_preedit_string);
        process_preedit_string ();
        commit_press_count = 0;     // reset to 0 to avoid output error
        return true;
    }

    // valid keys
    if (((key.code >= SCIM_KEY_a && key.code <= SCIM_KEY_z) ||
         (key.code == SCIM_KEY_comma) || (key.code == SCIM_KEY_period) ||
         (key.code == SCIM_KEY_semicolon) || (key.code == SCIM_KEY_slash))
            &&
        (key.mask == 0))
    {
        if (m_preedit_string.length () >=  m_max_preedit_len)
            return true;
 
        if (commit_press_count == 1)
        {
            WideString str = m_lookup_table.get_candidate_in_current_page (0);
            if (str.length() && str.compare(utf8_mbstowcs(SCIM_ARRAY_EMPTY_CHAR)) != 0 ) {
                send_commit_string(m_preedit_string,
                        m_lookup_table.get_candidate_in_current_page(0));
            }
            else
                reset();
        }

        if (m_preedit_string.length () == 0)
        {
            hide_aux_string ();
            show_preedit_string ();
        }

        ucs4_t ascii = (ucs4_t) tolower (key.get_ascii_code ());
        m_preedit_string.push_back (ascii);
        pre_update_preedit_string (m_preedit_string);
        process_preedit_string ();

        return true;
    }

    // apostrophe key for end of phrases
    if (m_use_phrases && key.code == SCIM_KEY_apostrophe 
            && m_preedit_string.length())
    {
        phrase_key_press();
        return true;
    }
    
    // wildcard keys
    if (key.code == SCIM_KEY_question || key.code == SCIM_KEY_asterisk)
    {
        hide_lookup_table();
        ucs4_t ascii = (ucs4_t) tolower (key.get_ascii_code ());
        m_preedit_string.push_back (ascii);
        pre_update_preedit_string (m_preedit_string);
        process_preedit_string ();
        return true;
    }

    // selection keys
    if (key.code >= SCIM_KEY_0 && key.code <= SCIM_KEY_9) 
    {
        if (!m_preedit_string.length())
            return false;

        WideString inkey = m_preedit_string;

        // key "w" to enable the symbol input
        if (m_preedit_string.compare(utf8_mbstowcs("w")) == 0)
        {
            ucs4_t ascii = (ucs4_t) tolower (key.get_ascii_code ());
            m_preedit_string.push_back (ascii);
            pre_update_preedit_string (m_preedit_string);
            process_symbol_preedit_string ();

            return true;
        }

        int selectnum = (int)(key.get_ascii_code() - '0' - 1);
        if (selectnum < 0)
            selectnum = 9;


        WideString cmtstr = m_lookup_table.get_candidate_in_current_page(selectnum);

        if (cmtstr.length() && cmtstr.compare(utf8_mbstowcs(SCIM_ARRAY_EMPTY_CHAR)) != 0)
        {
            send_commit_string(inkey, cmtstr);
            return true;
        }
        else
        {
            return true;
        }

    }

    // commit key
    if (key.code == SCIM_KEY_space && key.mask == 0 && m_preedit_string.length ())
    {
        space_key_press();
        return true;
    }

    //page up key.
    if (key.code == SCIM_KEY_Page_Up && key.mask == 0)
        lookup_table_page_up ();

    //page down key.
    if (key.code == SCIM_KEY_Page_Down && key.mask == 0)
        lookup_table_page_down ();

    //other keys is not allowed when preediting
    if (m_preedit_string.length ())
        return true;

    //other keys wiil be send out if the Full width mode on
    if ( (key.code >= SCIM_KEY_space && key.code <= SCIM_KEY_asciitilde) && (key.mask == 0 || key.is_shift_down()))
    {
        WideString outws;
        char widthc = key.get_ascii_code();

        if (widthc >= 'A' && widthc <= 'Z')
            if (!key.is_caps_lock_down())
                widthc = widthc - 'A' + 'a';

        if (m_full_width_letter)
            outws.push_back(scim_wchar_to_full_width(widthc));
        else
            outws.push_back(widthc);

        commit_string(outws);
        return true;
    }

    return false;
}