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
CannaInstance::lookup_table_page_down ()
{
    SCIM_DEBUG_IMENGINE(2) << "lookup_table_page_down.\n";

    m_lookup_table.page_down ();
    update_lookup_table (m_lookup_table);
}
void
CannaInstance::select_candidate_no_direct (unsigned int item)
{
    SCIM_DEBUG_IMENGINE(2) << "select_candidate_no_direct.\n";

    m_lookup_table.set_cursor_pos_in_current_page (item);
    update_lookup_table (m_lookup_table);
}
Пример #4
0
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();
    }
}
Пример #5
0
void
HangulInstance::lookup_table_page_up ()
{
    if (!m_lookup_table.number_of_candidates () || !m_lookup_table.get_current_page_start ())
        return;

    SCIM_DEBUG_IMENGINE(2) << "lookup_table_page_up.\n";

    m_lookup_table.page_up ();

    update_lookup_table (m_lookup_table);

    hangul_update_aux_string ();
}
Пример #6
0
void
HangulInstance::lookup_table_page_down ()
{
    if (m_lookup_table.number_of_candidates () <= 0 ||
        m_lookup_table.get_current_page_start () + m_lookup_table.get_current_page_size () >=
          (int)m_lookup_table.number_of_candidates ())
        return;

    SCIM_DEBUG_IMENGINE(2) << "lookup_table_page_down.\n";

    m_lookup_table.page_down ();

    update_lookup_table (m_lookup_table);

    hangul_update_aux_string ();
}
Пример #7
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 ();
}
Пример #8
0
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 ();
}
bool WaitZarInstance::process_key_event (const KeyEvent& key)
{
    //Pass along null key presses (event generated?) and key releases.
    //Also ignore if we don't have the focus. This is included in scim_pinyin, and I see no reason to exclude it here.
    if (key.is_key_release() || key.code == 0 || !has_focus) {
        /*|| __is_context_intact_key (key.code)*/
        return false;
    }

    //Basically ignore control key masks
    if (
	   ((key.mask & SCIM_KEY_ShiftMask) != 0)
        || ((key.mask & SCIM_KEY_ControlMask) != 0)
        || ((key.mask & SCIM_KEY_AltMask) != 0)
        || ((key.mask & SCIM_KEY_MetaMask) != 0)
        || ((key.mask & SCIM_KEY_SuperMask) != 0)
        || ((key.mask & SCIM_KEY_HyperMask) != 0)
        || ((key.mask & SCIM_KEY_QuirkKanaRoMask) != 0)
    ) {
	return false;
    }


    //INPUT:
    //(a-z)
    if (key.code>='a' && key.code<='z') {
	if (model->typeLetter(key.code)) {
	    //Append this character
	    int len = wcslen(typed_string);
	    typed_string[len] = key.code;
	    typed_string[len+1] = 0x0000;

	    //Update all guesses
	    updateGuesses();
	}
	return true;
    } else if (key.code == ' ') {
	if (isGuessingWord()) {
	    if (guess_string[0] != 0x0000) {
		pickGuess(-1);
	    }
	    return true;
	} else if (isHangingPhrase()) {
	    if (sentence->getCursorIndex()==-1 || sentence->getCursorIndex()<((int)sentence->size()-1)) {
		//Advance the cursor
		sentence->moveCursorRight(1, model);
		recalcPrefixString();
		updateGuesses();
		//updateCaret();
	    } else {
		//The cursor's at the end of the line, or there's only one word
		typeSentence(L"");
	    }
	    return true;
	}
    } else if (key.code>='0' && key.code<='9') {
	int number = key.code=='0' ? 9 : key.code-'1';
	if (isGuessingWord()) {
	    //Shortcut-jump to that number.
	    pickGuess(number);
	    return true;
	} else if (typeMyanmarNumerals) {
	    //Insert that number, or its myanmar equivalent
	    sentence->insert(key.code-'0');
	    sentence->moveCursorRight(0, true, model);
	    recalcPrefixString();
	    updateGuesses();
	    return true;
	}
    } else if (key.code==SCIM_KEY_Return) {
	if (isGuessingWord()) {
	    if (guess_string[0] != 0x0000) {
		pickGuess(-1);
	    }
	    return true;
	} else if (isHangingPhrase()) {
	    typeSentence(L"");
	    return true;
	}
    } else if (key.code==SCIM_KEY_Left || key.code==SCIM_KEY_Right) {
	int amt = key.code==SCIM_KEY_Right ? 1 : -1;
	if (isGuessingWord()) {
	    moveRight(amt);
	    return true;
	} else if (isHangingPhrase()) {
	    sentence->moveCursorRight(amt, model);
	    recalcPrefixString();
	    updateGuesses();
	    //updateCaret();
	    return true;
	}
    } else if (key.code==SCIM_KEY_Up || key.code==SCIM_KEY_Down) {
	int amt = key.code==SCIM_KEY_Right ? 1 : -1;
	if (isGuessingWord()) {
	    //Page Up/Down
	    if (key.code==SCIM_KEY_Up && lookup.number_of_candidates()>0) {
		lookup.page_up();
		update_lookup_table(lookup);
	    } else if (key.code==SCIM_KEY_Down && lookup.number_of_candidates()>0)  {
		lookup.page_down();
		update_lookup_table(lookup);
	    }
	    updateGuesses();
	    return true;
	}
    } else if (key.code==',' || key.code=='.') {
	if (isGuessingWord()) {
	    //Consume input
	    return true;
	} else /*if (isHangingPhrase())*/ {
	    //Insert this character & type the sentence
	    extra_str[0] = model->getStopCharacter(key.code=='.');
	    extra_str[1] = 0x0000;
	    typeSentence(extra_str);
	    return true;
	}
    } else if (key.code==SCIM_KEY_Delete || key.code==SCIM_KEY_BackSpace) {
        if (isGuessingWord()) {
	    if (key.code==SCIM_KEY_BackSpace) {
		model->backspace();
		int len = wcslen(typed_string);
		if (len>0) {
		    typed_string[len-1] = 0x0000;
		    updateGuesses();
		}
	    }
	    return true;
	} else if (isHangingPhrase()) {
	    //Arrange the cursor properly
	    bool didDelete = false;
	    if (key.code==SCIM_KEY_BackSpace) {
		didDelete = sentence->deletePrev(model);
	    } else {
		didDelete = sentence->deleteNext();
	    }

	    //Delete this word
	    if (didDelete) {
		recalcPrefixString();
	        updateGuesses();
		//updateCaret();
	    }
	    return true;
	}
    } else if (key.code==SCIM_KEY_Escape) {
	if (isGuessingWord()) {
	    //Soft reset
	    model->reset(true);
	    wcscpy(typed_string, L"");
            recalcPrefixString();
	    updateGuesses();
	    return true;
	} else if (isHangingPhrase()) {
	    resetInstance();
	    return true;
	}
    } else if (key.code==SCIM_KEY_Home || key.code==SCIM_KEY_End) {
	if (isGuessingWord() || isHangingPhrase()) {
	    //Avoid confusion
	    return true;
	}
    }

    //Global else:
    return false;
}
Пример #10
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;
}
Пример #11
0
bool
HangulInstance::candidate_key_event (const KeyEvent &key)
{
    switch (key.code) {
        case SCIM_KEY_Return:
        case SCIM_KEY_KP_Enter:
            select_candidate (m_lookup_table.get_cursor_pos_in_current_page ());
            break;
        case SCIM_KEY_KP_Subtract:
	    m_lookup_table.cursor_up ();
	    update_lookup_table (m_lookup_table);
	    hangul_update_aux_string ();
            break;
        case SCIM_KEY_space:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_KP_Add:
	    m_lookup_table.cursor_down ();
	    update_lookup_table (m_lookup_table);
	    hangul_update_aux_string ();
	    break;
        case SCIM_KEY_Page_Up:
	    lookup_table_page_up();
            break;
        case SCIM_KEY_Page_Down:
        case SCIM_KEY_KP_Tab:
	    lookup_table_page_down();
            break;
        case SCIM_KEY_h:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_Left:
	    if (m_factory->m_lookup_table_vertical) {
		lookup_table_page_up();
	    } else {
		m_lookup_table.cursor_up ();
		update_lookup_table (m_lookup_table);
		hangul_update_aux_string ();
	    }
            break;
        case SCIM_KEY_l:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_Right:
	    if (m_factory->m_lookup_table_vertical) {
		lookup_table_page_down();
	    } else {
		m_lookup_table.cursor_down ();
		update_lookup_table (m_lookup_table);
		hangul_update_aux_string ();
	    }
            break;
        case SCIM_KEY_k:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_Up:
	    if (m_factory->m_lookup_table_vertical) {
		m_lookup_table.cursor_up ();
		update_lookup_table (m_lookup_table);
		hangul_update_aux_string ();
	    } else {
		lookup_table_page_up();
	    }
            break;
        case SCIM_KEY_j:
	    if (is_hanja_mode())
		return false;
        case SCIM_KEY_Down:
	    if (m_factory->m_lookup_table_vertical) {
		m_lookup_table.cursor_down ();
		update_lookup_table (m_lookup_table);
		hangul_update_aux_string ();
	    } else {
		lookup_table_page_down();
	    }
            break;
        case SCIM_KEY_Escape:
            delete_candidates ();
            break;
        case SCIM_KEY_1: 
        case SCIM_KEY_2: 
        case SCIM_KEY_3: 
        case SCIM_KEY_4: 
        case SCIM_KEY_5: 
        case SCIM_KEY_6: 
        case SCIM_KEY_7: 
        case SCIM_KEY_8: 
        case SCIM_KEY_9: 
            select_candidate (key.code - SCIM_KEY_1);
            break;
        default:
	    return !is_hanja_mode();
    }

    return true;
}
Пример #12
0
void
FilterInstanceBase::filter_update_lookup_table (const LookupTable &table)
{
    update_lookup_table (table);
}