static void FcitxThaiGetPrevCell(FcitxThai* thai, struct thcell_t* res) { th_init_cell(res); if (is_client_support_surrounding(IBUS_ENGINE(libthai_engine))) { IBusText* surrounding; guint cursor_pos; guint anchor_pos; const gchar* s; gchar* tis_text = NULL; ibus_engine_get_surrounding_text(IBUS_ENGINE(libthai_engine), &surrounding, &cursor_pos, &anchor_pos); s = ibus_text_get_text(surrounding); cursor_pos = g_utf8_offset_to_pointer(s, cursor_pos) - s; while (*s) { const gchar* t; tis_text = g_convert(s, cursor_pos, "TIS-620", "UTF-8", NULL, NULL, NULL); if (tis_text) break; t = g_utf8_next_char(s); cursor_pos -= (t - s); s = t; } if (tis_text) { gint char_index; char_index = g_utf8_pointer_to_offset(s, s + cursor_pos); th_prev_cell((thchar_t*) tis_text, char_index, res, TRUE); g_free(tis_text); } } else { /* retrieve from the fallback buffer */ th_prev_cell(libthai_engine->char_buff, libthai_engine->buff_tail, res, 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; }