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();
    }
}
Example #2
0
void
HangulInstance::focus_in ()
{
    SCIM_DEBUG_IMENGINE(2) << "focus_in.\n";

    register_all_properties();

    if (m_lookup_table.number_of_candidates ()) {
        update_lookup_table (m_lookup_table);
        show_lookup_table ();
    } else {
        hide_lookup_table ();
    }

    hangul_update_aux_string ();
}
void WaitZarInstance::updateGuesses()
{
    //Update aux_string
    if (wcslen(model->getParenString())==0)
        wcscpy(aux_string, typed_string);
    else
        swprintf(aux_string, 500, L"%ls(%ls)", typed_string, model->getParenString());
       update_aux_string(aux_string);
	if (wcslen(aux_string)>0) {
            show_aux_string();
            show_lookup_table();
	} else {
	    hide_aux_string();
	    hide_lookup_table();
	}

    //Update the current guess
    wcscpy(guess_string, L"");
    if (model->getPossibleWords().size()>0)
	copyStringFromKeyStrokes(guess_string, model->getWordKeyStrokes(model->getPossibleWords()[model->getCurrSelectedID()]));
    swprintf(preedit_string, 500, L"%ls%ls%ls", prefix_string, guess_string, postfix_string);
    update_preedit_string(preedit_string);
    if (wcslen(preedit_string)>0)
        show_preedit_string();
    else
        hide_preedit_string();

   /* fprintf(logFile, "now on: %ls\n", typed_string);
    fprintf(logFile, "   prefix_string: %ls\n", prefix_string);
    fprintf(logFile, "   guess_string: %ls\n", guess_string);
    fprintf(logFile, "   postfix_string: %ls\n", postfix_string);
    fflush(logFile);*/

    //Update the candidate table & cursor
    lookup.setCandidates(model);
    lookup.show_cursor(model->getPossibleWords().size()>0);
    lookup.set_cursor_pos(model->getCurrSelectedID()); //I think...
    update_lookup_table(lookup);

    //Update the caret
    update_preedit_caret(wcslen(prefix_string));

    //TEMP: Bugfix on behalf of SCIM
    if (lookup.number_of_candidates()==0) {
	update_lookup_table(blank_lookup);
    }
}
void
HangulInstance::focus_in ()
{
    SCIM_DEBUG_IMENGINE(2) << "focus_in.\n";

    register_all_properties();

    hangul_ic_select_keyboard(m_hic, m_factory->m_keyboard_layout.c_str());

    if (m_lookup_table.number_of_candidates ()) {
        update_lookup_table (m_lookup_table);
        show_lookup_table ();
    } else {
        hide_lookup_table ();
    }

    hangul_update_aux_string ();
}
Example #5
0
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;
}
Example #6
0
void
FilterInstanceBase::filter_show_lookup_table ()
{
    show_lookup_table ();
}