/* * tis_text is assumed to be large enough to hold the converted string, * i.e. it must be at least pango_utf8_strlen(text, len)+1 bytes. */ static thchar_t * utf8_to_tis (const char *text, int len, thchar_t *tis_text, int *tis_cnt) { thchar_t *tis_p; const char *text_p; tis_p = tis_text; for (text_p = text; text_p < text + len; text_p = g_utf8_next_char (text_p)) *tis_p++ = th_uni2tis (g_utf8_get_char (text_p)); *tis_p++ = '\0'; *tis_cnt = tis_p - tis_text; return tis_text; }
bool ThaiInstance::process_key_event (const KeyEvent& key) { if (key.is_key_release() || key.code == 0 || __is_context_intact_key (key.code)) { return false; } if (key.mask & (SCIM_KEY_AllMasks & ~(SCIM_KEY_ShiftMask | SCIM_KEY_CapsLockMask)) || __is_context_lost_key (key.code)) { _forget_previous_chars (); return false; } KeyEvent thai_key = m_keymap.map_key (key); ucs4_t thai_uni = thai_key.get_unicode_code (); if (!th_wcistis (thai_uni)) return false; thchar_t thai_tis = th_uni2tis (thai_uni); thcell_t context_cell = _get_previous_cell (); thinpconv_t conv; if (th_validate (context_cell, thai_tis, &conv)) { if (conv.offset < 0) if (!delete_surrounding_text (conv.offset, -conv.offset)) return false; _forget_previous_chars (); _remember_previous_char (thai_tis); WideString str; for (int i = 0; conv.conv [i]; i++) str.push_back (th_tis2uni (conv.conv [i])); commit_string (str); } else { beep (); } return true; }
thcell_t ThaiInstance::_get_previous_cell () { WideString surrounding; int cursor_index; thcell_t the_cell; th_init_cell (&the_cell); if (get_surrounding_text (surrounding, cursor_index)) { thchar_t* tis_text = new thchar_t [cursor_index+1]; if (!tis_text) goto exit_point; tis_text [cursor_index] = '\0'; int begin_index = cursor_index; while (begin_index > 0) { thchar_t c = th_uni2tis (surrounding [begin_index-1]); if (c == THCHAR_ERR) break; tis_text [--begin_index] = c; } if (begin_index < cursor_index) { th_prev_cell (tis_text + begin_index, cursor_index - begin_index, &the_cell, true); } delete tis_text; } else { th_prev_cell (m_char_buff, m_buff_tail, &the_cell, true); } exit_point: return the_cell; }