String HangulInstance::get_candidate_string() { int cursor = 0; if (m_surrounding_text.empty()) get_surrounding_text(m_surrounding_text, cursor, 10, 0); int i; for (i = m_surrounding_text.length() - 1; i >= 0; i--) { if (!hangul_is_syllable(m_surrounding_text[i])) break; } if (i >= 0) m_surrounding_text.erase(0, i + 1); return utf8_wcstombs(m_surrounding_text + get_preedit_string()); }
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; }
bool SocketInstance::do_transaction (Transaction &trans, bool &ret) { int cmd = -1; bool cont = false; ret = false; SCIM_DEBUG_IMENGINE(2) << " Do transaction:\n"; if (trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY) { while (trans.get_command (cmd)) { switch (cmd) { case SCIM_TRANS_CMD_SHOW_PREEDIT_STRING: { SCIM_DEBUG_IMENGINE(3) << " show_preedit_string ()\n"; show_preedit_string (); break; } case SCIM_TRANS_CMD_SHOW_AUX_STRING: { SCIM_DEBUG_IMENGINE(3) << " show_aux_string ()\n"; show_aux_string (); break; } case SCIM_TRANS_CMD_SHOW_LOOKUP_TABLE: { SCIM_DEBUG_IMENGINE(3) << " show_lookup_table ()\n"; show_lookup_table (); break; } case SCIM_TRANS_CMD_HIDE_PREEDIT_STRING: { SCIM_DEBUG_IMENGINE(3) << " hide_preedit_string ()\n"; hide_preedit_string (); break; } case SCIM_TRANS_CMD_HIDE_AUX_STRING: { SCIM_DEBUG_IMENGINE(3) << " hide_aux_string ()\n"; hide_aux_string (); break; } case SCIM_TRANS_CMD_HIDE_LOOKUP_TABLE: { SCIM_DEBUG_IMENGINE(3) << " hide_lookup_table ()\n"; hide_lookup_table (); break; } case SCIM_TRANS_CMD_UPDATE_PREEDIT_CARET: { uint32 caret; if (trans.get_data (caret)) { SCIM_DEBUG_IMENGINE(3) << " update_preedit_caret (" << caret << ")\n"; update_preedit_caret (caret); } break; } case SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING: { WideString str; AttributeList attrs; if (trans.get_data (str) && trans.get_data (attrs)) { SCIM_DEBUG_IMENGINE(3) << " update_preedit_string ()\n"; update_preedit_string (str, attrs); } break; } case SCIM_TRANS_CMD_UPDATE_AUX_STRING: { WideString str; AttributeList attrs; if (trans.get_data (str) && trans.get_data (attrs)) { SCIM_DEBUG_IMENGINE(3) << " update_aux_string ()\n"; update_aux_string (str, attrs); } break; } case SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE: { CommonLookupTable table; if (trans.get_data (table)) { SCIM_DEBUG_IMENGINE(3) << " update_lookup_table ()\n"; update_lookup_table (table); } break; } case SCIM_TRANS_CMD_COMMIT_STRING: { WideString str; if (trans.get_data (str)) { SCIM_DEBUG_IMENGINE(3) << " commit_string ()\n"; commit_string (str); } break; } case SCIM_TRANS_CMD_FORWARD_KEY_EVENT: { KeyEvent key; if (trans.get_data (key)) { SCIM_DEBUG_IMENGINE(3) << " forward_key_event ()\n"; forward_key_event (key); } break; } case SCIM_TRANS_CMD_REGISTER_PROPERTIES: { PropertyList proplist; if (trans.get_data (proplist)) { SCIM_DEBUG_IMENGINE(3) << " register_properties ()\n"; // Load icon files of these properties from remote SocketFrontEnd. for (PropertyList::iterator it = proplist.begin (); it != proplist.end (); ++it) it->set_icon (global->load_icon (it->get_icon ())); register_properties (proplist); } break; } case SCIM_TRANS_CMD_UPDATE_PROPERTY: { Property prop; if (trans.get_data (prop)) { SCIM_DEBUG_IMENGINE(3) << " update_property ()\n"; // Load the icon file of this property from remote SocketFrontEnd. prop.set_icon (global->load_icon (prop.get_icon ())); update_property (prop); } break; } case SCIM_TRANS_CMD_BEEP: { SCIM_DEBUG_IMENGINE(3) << " beep ()\n"; beep (); break; } case SCIM_TRANS_CMD_START_HELPER: { String helper_uuid; if (trans.get_data (helper_uuid)) { SCIM_DEBUG_IMENGINE(3) << " start_helper (" << helper_uuid << ")\n"; start_helper (helper_uuid); } break; } case SCIM_TRANS_CMD_STOP_HELPER: { String helper_uuid; if (trans.get_data (helper_uuid)) { SCIM_DEBUG_IMENGINE(3) << " stop_helper (" << helper_uuid << ")\n"; stop_helper (helper_uuid); } break; } case SCIM_TRANS_CMD_SEND_HELPER_EVENT: { String helper_uuid; Transaction temp_trans; if (trans.get_data (helper_uuid) && trans.get_data (temp_trans)) { SCIM_DEBUG_IMENGINE(3) << " send_helper_event (" << helper_uuid << ")\n"; send_helper_event (helper_uuid, temp_trans); } break; } case SCIM_TRANS_CMD_OK: { SCIM_DEBUG_IMENGINE(3) << " ret = true\n"; ret = true; break; } case SCIM_TRANS_CMD_GET_SURROUNDING_TEXT: { WideString text; int cursor; uint32 maxlen_before; uint32 maxlen_after; Transaction temp_trans; if (trans.get_data (maxlen_before) && trans.get_data (maxlen_after)) { global->init_transaction (temp_trans); if (get_surrounding_text (text, cursor, (int) maxlen_before, (int) maxlen_after)) { temp_trans.put_command (SCIM_TRANS_CMD_GET_SURROUNDING_TEXT); temp_trans.put_data (text); temp_trans.put_data ((uint32) cursor); } else { temp_trans.put_command (SCIM_TRANS_CMD_FAIL); } global->send_transaction (temp_trans); } cont = true; break; } case SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT: { uint32 offset; uint32 len; Transaction temp_trans; if (trans.get_data (offset) && trans.get_data (len)) { global->init_transaction (temp_trans); if (delete_surrounding_text ((int) offset, (int) len)) { temp_trans.put_command (SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT); temp_trans.put_command (SCIM_TRANS_CMD_OK); } else { temp_trans.put_command (SCIM_TRANS_CMD_FAIL); } global->send_transaction (temp_trans); } cont = true; break; } default: SCIM_DEBUG_IMENGINE(3) << " Strange cmd: " << cmd << "\n";; } } } else { SCIM_DEBUG_IMENGINE(3) << " Failed to get cmd: " << cmd << "\n"; } SCIM_DEBUG_IMENGINE(2) << " End of Do transaction\n"; return cont; }
bool FilterInstanceBase::filter_get_surrounding_text (WideString &text, int &cursor, int maxlen_before, int maxlen_after) { return get_surrounding_text (text, cursor, maxlen_before, maxlen_after); }