コード例 #1
0
void
HangulInstance::select_candidate (unsigned int index)
{
    SCIM_DEBUG_IMENGINE(2) << "select_candidate.\n";

    if ((int)index >= m_lookup_table.get_current_page_size ())
	return;

    WideString candidate = m_lookup_table.get_candidate_in_current_page(index);

    WideString commit_str = candidate;
    WideString preedit = get_preedit_string();
    if (is_hanja_mode() || m_factory->m_commit_by_word) {
	// prefix method
	int len = m_surrounding_text.length();
	if (len > 0)
	    delete_surrounding_text(-len, len);
	if (candidate.length() <= m_surrounding_text.length()) {
	    len = m_surrounding_text.length() - candidate.length();
	    commit_str.append(m_surrounding_text, candidate.length(), len);
	    m_surrounding_text.erase(0, candidate.length());
	} else if (candidate.length() <= m_surrounding_text.length() + preedit.length()) {
	    len = candidate.length() - m_surrounding_text.length();
	    if (len > (int)m_preedit.length()) {
		m_preedit.clear();
		hangul_ic_reset(m_hic);
	    } else {
		m_preedit.erase(0, len);
	    }
	    m_surrounding_text.clear();
	} else {
	    m_preedit.clear();
	    hangul_ic_reset(m_hic);
	    m_surrounding_text.clear();
	}
    } else {
	// suffix method
	if (candidate.length() > preedit.length()) {
	    int len = candidate.length() - preedit.length();
	    delete_surrounding_text(-len, len);
	}
	hangul_ic_reset(m_hic);
	m_surrounding_text.clear();
    }

    commit_string(commit_str);
    hangul_update_preedit_string ();

    if (is_hanja_mode()) {
	update_candidates();
    } else {
	delete_candidates();
    }
}
コード例 #2
0
void
HangulInstance::update_candidates ()
{
    m_lookup_table.clear ();
    m_candidate_comments.clear ();

    HanjaList* list = NULL;

    // search for symbol character
    // key string for symbol character is like:
    //  'ㄱ', 'ㄴ', 'ㄷ', etc
    WideString preeditw = get_preedit_string();
    if (preeditw.length() == 1) {
	String key = utf8_wcstombs(preeditw);
	list = hanja_table_match_suffix(m_factory->m_symbol_table, key.c_str());
    }

    // search for hanja
    if (list == NULL) {
	String str = get_candidate_string();
	SCIM_DEBUG_IMENGINE(1) << "candidate string: " << str << "\n";

	if (str.length() > 0) {
	    if (is_hanja_mode() || m_factory->m_commit_by_word) {
		list = hanja_table_match_prefix(m_factory->m_hanja_table,
						    str.c_str());
	    } else {
		list = hanja_table_match_suffix(m_factory->m_hanja_table,
						    str.c_str());
	    }
	}
    } 
    
    if (list != NULL) {
	int n = hanja_list_get_size(list);
	for (int i = 0; i < n; ++i) {
	    const char* value = hanja_list_get_nth_value(list, i);
	    const char* comment = hanja_list_get_nth_comment(list, i);
	    WideString candidate = utf8_mbstowcs(value, -1);
	    m_lookup_table.append_candidate(candidate);
	    m_candidate_comments.push_back(String(comment));
	}

	m_lookup_table.set_page_size (9);
	m_lookup_table.show_cursor ();

	update_lookup_table (m_lookup_table);
	show_lookup_table ();

	hangul_update_aux_string ();

	hanja_list_delete(list);
    }

    if (m_lookup_table.number_of_candidates() <= 0) {
	delete_candidates();
    }
}
コード例 #3
0
ファイル: scim_hangul_imengine.cpp プロジェクト: wwood/scim
void
HangulInstance::register_all_properties()
{
    PropertyList proplist;

    const char* layout_label;
    if (m_factory->m_keyboard_layout == "2") {
	layout_label = _("2bul");
    } else if (m_factory->m_keyboard_layout == "32") {
	layout_label = _("3bul 2bul-shifted");
    } else if (m_factory->m_keyboard_layout == "3f") {
	layout_label = _("3bul Final");
    } else if (m_factory->m_keyboard_layout == "39") {
	layout_label = _("3bul 390");
    } else if (m_factory->m_keyboard_layout == "3s") {
	layout_label = _("3bul No-Shift");
    } else if (m_factory->m_keyboard_layout == "3y") {
	layout_label = _("3bul Yetgeul");
    }
    keyboard_layout.set_label(layout_label);
    proplist.push_back(keyboard_layout);
    proplist.push_back(keyboard_layout_2);
    proplist.push_back(keyboard_layout_32);
    proplist.push_back(keyboard_layout_3f);
    proplist.push_back(keyboard_layout_39);
    proplist.push_back(keyboard_layout_3s);
    proplist.push_back(keyboard_layout_3y);

    if (use_ascii_mode()) {
	if (m_hangul_mode) {
	    hangul_mode.set_label("한");
	} else {
	    hangul_mode.set_label("A");
	}
	proplist.push_back(hangul_mode);
    }

    if (is_hanja_mode()) {
	hanja_mode.set_label("漢");
    } else {
	hanja_mode.set_label("韓");
    }
    proplist.push_back(hanja_mode);

    register_properties(proplist);
}
コード例 #4
0
bool
HangulInstance::process_key_event (const KeyEvent& rawkey)
{
    SCIM_DEBUG_IMENGINE(1) << "process_key_event.\n";

    KeyEvent key = rawkey.map_to_layout(SCIM_KEYBOARD_Default);

    m_prev_key = key;

    if (use_ascii_mode() && !is_hangul_mode()) {
	if (is_hangul_key(key)) {
	    toggle_hangul_mode();
	    return true;
	}

	return false;
    }

    /* ignore key release. */
    if (key.is_key_release ())
        return false;

    /* mode change */
    if (use_ascii_mode() && is_hangul_key(key)) {
	toggle_hangul_mode();
	return true;
    }

    /* hanja mode */
    if (is_hanja_mode_key (key)) {
	toggle_hanja_mode();
    }

    /* toggle candidate table */
    if (is_hanja_key (key)) {
	if (is_hanja_mode()) {
	    update_candidates ();
	} else {
	    if (m_lookup_table.number_of_candidates ())
		delete_candidates ();
	    else
		update_candidates ();
	}

        return true;
    }

    /* ignore shift keys */
    if (key.code == SCIM_KEY_Shift_L || key.code == SCIM_KEY_Shift_R)
        return false;

    /* flush on modifier-on keys */
    if (key.is_control_down() || key.is_alt_down()) {
	flush ();
        return false;
    }

    /* candidate keys */
    if (m_lookup_table.number_of_candidates ()) {
        if (candidate_key_event(key))
	    return true;
    }

    /* change to ascii mode on ESCAPE key, for vi users.
     * We should process this key after processing candidate keys,
     * or input mode will be changed to non-hangul mode when the user presses
     * escape key to close candidate window. */
    if (use_ascii_mode() && !is_hanja_mode()) {
	if (key.code == SCIM_KEY_Escape) {
	    toggle_hangul_mode();
	}
    }

    /* backspace */
    if (is_backspace_key(key)) {
        bool ret = hangul_ic_backspace(m_hic);
        if (ret) {
	    hangul_update_preedit_string ();
	} else if (m_preedit.length() > 0) {
	    ret = true;
	    m_preedit.erase(m_preedit.length() - 1, 1);
	    hangul_update_preedit_string();
	} else {
	    if (m_surrounding_text.length() > 0) {
		m_surrounding_text.erase(m_surrounding_text.length() - 1, 1);
		if (m_surrounding_text.empty()) {
		    delete_candidates();
		    return ret;
		}
	    }
	}

	if (is_hanja_mode() && m_lookup_table.number_of_candidates()) {
	    update_candidates();
	}

        return ret;
    }

    if (key.code >= SCIM_KEY_exclam && key.code <= SCIM_KEY_asciitilde) {
	/* main hangul composing process */
	int ascii = key.get_ascii_code();
	if (key.is_caps_lock_down()) {
	    if (isupper(ascii))
		ascii = tolower(ascii);
	    else if (islower(ascii))
		ascii = toupper(ascii);
	}

	bool ret = hangul_ic_process(m_hic, ascii);

	WideString wstr;
	wstr = get_commit_string ();
	if (wstr.length ()) {
	    /* Before commit, we set preedit string to null to work arround
	     * some buggy IM implementation, ex) Qt, Evolution */
	    hide_preedit_string ();
	    if (is_hanja_mode() || m_factory->m_commit_by_word) {
		m_preedit += wstr;
	    } else {
		commit_string(wstr);
	    }
	}

	if (is_hanja_mode() || m_factory->m_commit_by_word) {
	    if (hangul_ic_is_empty(m_hic)) {
		flush();
	    }
	}

	hangul_update_preedit_string ();

	if (is_hanja_mode()) {
	    update_candidates();
	}

	return ret;
    }

    flush();
    return false;
}
コード例 #5
0
bool
HangulInstance::candidate_key_event (const KeyEvent &key)
{
    switch (key.code) {
        case SCIM_KEY_Return:
        case SCIM_KEY_KP_Enter:
            select_candidate (m_lookup_table.get_cursor_pos_in_current_page ());
            break;
        case SCIM_KEY_KP_Subtract:
	    m_lookup_table.cursor_up ();
	    update_lookup_table (m_lookup_table);
	    hangul_update_aux_string ();
            break;
        case SCIM_KEY_space:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_KP_Add:
	    m_lookup_table.cursor_down ();
	    update_lookup_table (m_lookup_table);
	    hangul_update_aux_string ();
	    break;
        case SCIM_KEY_Page_Up:
	    lookup_table_page_up();
            break;
        case SCIM_KEY_Page_Down:
        case SCIM_KEY_KP_Tab:
	    lookup_table_page_down();
            break;
        case SCIM_KEY_h:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_Left:
	    if (m_factory->m_lookup_table_vertical) {
		lookup_table_page_up();
	    } else {
		m_lookup_table.cursor_up ();
		update_lookup_table (m_lookup_table);
		hangul_update_aux_string ();
	    }
            break;
        case SCIM_KEY_l:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_Right:
	    if (m_factory->m_lookup_table_vertical) {
		lookup_table_page_down();
	    } else {
		m_lookup_table.cursor_down ();
		update_lookup_table (m_lookup_table);
		hangul_update_aux_string ();
	    }
            break;
        case SCIM_KEY_k:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_Up:
	    if (m_factory->m_lookup_table_vertical) {
		m_lookup_table.cursor_up ();
		update_lookup_table (m_lookup_table);
		hangul_update_aux_string ();
	    } else {
		lookup_table_page_up();
	    }
            break;
        case SCIM_KEY_j:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_Down:
	    if (m_factory->m_lookup_table_vertical) {
		m_lookup_table.cursor_down ();
		update_lookup_table (m_lookup_table);
		hangul_update_aux_string ();
	    } else {
		lookup_table_page_down();
	    }
            break;
        case SCIM_KEY_Escape:
            delete_candidates ();
            break;
        case SCIM_KEY_1: 
        case SCIM_KEY_2: 
        case SCIM_KEY_3: 
        case SCIM_KEY_4: 
        case SCIM_KEY_5: 
        case SCIM_KEY_6: 
        case SCIM_KEY_7: 
        case SCIM_KEY_8: 
        case SCIM_KEY_9: 
            select_candidate (key.code - SCIM_KEY_1);
            break;
        default:
	    return !is_hanja_mode();
    }

    return true;
}