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(); } }
static void on_candidate_clicked (NimfEngine *engine, NimfServiceIC *target, gchar *text, gint index) { g_debug (G_STRLOC ": %s", G_STRFUNC); NimfLibhangul *hangul = NIMF_LIBHANGUL (engine); if (text) { /* commit text inside hangul_ic disappears */ hangul_ic_reset (hangul->context); if (hangul->preedit_string[0] == 0) nimf_engine_emit_delete_surrounding (engine, target, -1, 1); nimf_libhangul_emit_commit (engine, target, text); if (hangul->preedit_string[0] != 0) nimf_libhangul_update_preedit (engine, target, g_strdup ("")); } nimf_candidatable_hide (hangul->candidatable); }
/* ic option을 바꾸면서 테스트하는걸 손쉽게 하기 위해서 * static ic를 하나 두고 이것으로 테스트를 진행하게 코드를 * 바꾼다. */ static HangulInputContext* get_ic(const char* keyboard) { if (global_ic == NULL) { global_ic = hangul_ic_new("2"); } hangul_ic_select_keyboard(global_ic, keyboard); hangul_ic_reset(global_ic); return global_ic; }
static void ibus_hangul_engine_focus_out (IBusEngine *engine) { IBusHangulEngine *hangul = (IBusHangulEngine *) engine; if (hangul->hanja_list == NULL) { // ibus-hangul uses // ibus_engine_update_preedit_text_with_mode() function which makes // the preedit string committed automatically when the focus is out. // So we don't need to commit the preedit here. hangul_ic_reset (hangul->context); } else { ibus_engine_hide_lookup_table (engine); ibus_engine_hide_auxiliary_text (engine); } parent_class->focus_out ((IBusEngine *) hangul); }
bool QHangulPlatformInputContext::filterEvent(const QEvent *event) { if (event->type() != QEvent::KeyPress) return false; const QKeyEvent *keyevent = static_cast<const QKeyEvent*>(event); if (m_candidateList != NULL && m_candidateList->isVisible()) { if (m_candidateList->filterEvent(keyevent)) { if (m_candidateList->isSelected()) { hangul_ic_reset(m_hic); QString candidate(m_candidateList->getCandidate()); commitText(candidate); } m_candidateList->close(); } return true; } if (keyevent->key() == Qt::Key_Shift) return false; if (keyevent->key() == Qt::Key_Backspace) return backspace(); if (isTriggerKey(keyevent)) { if (m_mode == MODE_DIRECT) { m_mode = MODE_HANGUL; } else { reset(); m_mode = MODE_DIRECT; } setModeInfo(m_mode); return true; } if (isCandidateKey(keyevent)) { return popupCandidateList(); } if (keyevent->modifiers() & Qt::ControlModifier || keyevent->modifiers() & Qt::AltModifier || keyevent->modifiers() & Qt::MetaModifier) { reset(); return false; } if (m_mode == MODE_HANGUL) { QString text = keyevent->text(); if (keyevent->modifiers() & Qt::ShiftModifier) text = text.toUpper(); else text = text.toLower(); int ascii = 0; if (!text.isEmpty()) ascii = text[0].unicode(); bool ret = hangul_ic_process(m_hic, ascii); QString commitString = getCommitString(); if (!commitString.isEmpty()) commitText(commitString); QString preeditString = getPreeditString(); if (!preeditString.isEmpty()) updatePreedit(preeditString); return ret; } return false; }
END_TEST START_TEST(test_hangul_ic_process_romaja) { HangulInputContext* ic; const ucschar* preedit; const ucschar* commit; // romaja keyboard test ic = hangul_ic_new("ro"); // basic test: han produces 한 hangul_ic_process(ic, 'h'); hangul_ic_process(ic, 'a'); hangul_ic_process(ic, 'n'); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == L'한'); fail_unless(commit[0] == 0); hangul_ic_reset(ic); // insert ㅇ when a syllable is not started with consonant hangul_ic_process(ic, 'a'); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == L'아'); fail_unless(commit[0] == 0); // remove correctly when automatically ㅇ was inserted hangul_ic_backspace(ic); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == 0); fail_unless(commit[0] == 0); // append ㅡ when a syllable is not ended with vowel hangul_ic_process(ic, 't'); hangul_ic_process(ic, 't'); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == 0x314c); // ㅌ fail_unless(commit[0] == L'트'); // ng makes trailing ㅇ hangul_ic_reset(ic); hangul_ic_process(ic, 'g'); hangul_ic_process(ic, 'a'); hangul_ic_process(ic, 'n'); hangul_ic_process(ic, 'g'); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == L'강'); // 강 fail_unless(commit[0] == 0); // gangi makes 강이 hangul_ic_process(ic, 'i'); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == L'이'); fail_unless(commit[0] == L'강'); // 강 // nanG makes 난ㄱ // uppercase makes new syllable hangul_ic_process(ic, 'n'); hangul_ic_process(ic, 'a'); hangul_ic_process(ic, 'n'); hangul_ic_process(ic, 'G'); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == 0x3131); // ㄱ fail_unless(commit[0] == L'난'); // 난 // special operation for x // x generate ㅈ for leading consonant hangul_ic_reset(ic); hangul_ic_process(ic, 'x'); hangul_ic_process(ic, 'x'); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == 0x3148); // 지 fail_unless(commit[0] == L'즈'); hangul_ic_reset(ic); hangul_ic_process(ic, 'x'); hangul_ic_process(ic, 'y'); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == L'지'); // 지 fail_unless(commit[0] == 0x0); // x generate ㄱㅅ for trailing consonant // and ㅅ will be transferred to next syllable when next input // character is vowel. hangul_ic_reset(ic); hangul_ic_process(ic, 's'); hangul_ic_process(ic, 'e'); hangul_ic_process(ic, 'x'); hangul_ic_process(ic, 'y'); preedit = hangul_ic_get_preedit_string(ic); commit = hangul_ic_get_commit_string(ic); fail_unless(preedit[0] == L'시'); // 시 fail_unless(commit[0] == L'섹'); // 섹 hangul_ic_delete(ic); }
static PyObject *_pyhangulic_reset(PY_HANGULIC *self, PyObject *args) { hangul_ic_reset(self->hic); return Py_None; }
static void ibus_hangul_engine_commit_current_candidate (IBusHangulEngine *hangul) { guint cursor_pos; const char* key; const char* value; const ucschar* hic_preedit; glong key_len; glong hic_preedit_len; glong preedit_len; IBusText* text; cursor_pos = ibus_lookup_table_get_cursor_pos (hangul->table); key = hanja_list_get_nth_key (hangul->hanja_list, cursor_pos); value = hanja_list_get_nth_value (hangul->hanja_list, cursor_pos); hic_preedit = hangul_ic_get_preedit_string (hangul->context); key_len = g_utf8_strlen(key, -1); preedit_len = ustring_length(hangul->preedit); hic_preedit_len = ucschar_strlen (hic_preedit); if (hangul->last_lookup_method == LOOKUP_METHOD_PREFIX) { if (preedit_len == 0 && hic_preedit_len == 0) { /* remove surrounding_text */ if (key_len > 0) { ibus_engine_delete_surrounding_text ((IBusEngine *)hangul, -key_len , key_len); } } else { /* remove ibus preedit text */ if (key_len > 0) { glong n = MIN(key_len, preedit_len); ustring_erase (hangul->preedit, 0, n); key_len -= preedit_len; } /* remove hic preedit text */ if (key_len > 0) { hangul_ic_reset (hangul->context); key_len -= hic_preedit_len; } } } else { /* remove hic preedit text */ if (hic_preedit_len > 0) { hangul_ic_reset (hangul->context); key_len -= hic_preedit_len; } /* remove ibus preedit text */ if (key_len > preedit_len) { ustring_erase (hangul->preedit, 0, preedit_len); key_len -= preedit_len; } else if (key_len > 0) { ustring_erase (hangul->preedit, 0, key_len); key_len = 0; } /* remove surrounding_text */ if (key_len > 0) { ibus_engine_delete_surrounding_text ((IBusEngine *)hangul, -key_len , key_len); } } /* clear preedit text before commit */ ibus_hangul_engine_clear_preedit_text (hangul); text = ibus_text_new_from_string (value); ibus_engine_commit_text ((IBusEngine *)hangul, text); ibus_hangul_engine_update_preedit_text (hangul); }