| |
---|
| | |
---|
| | #define SCIM_CONFIG_WNN_SERVER "/IMEngine/Wnn/Server" |
---|
| | #define SCIM_CONFIG_WNN_RC "/IMEngine/Wnn/Rc" |
---|
| | #define SCIM_CONFIG_WNN_KEY "/IMEngine/Wnn/Key/" |
---|
| | #define SCIM_CONFIG_WNN_ALP "/IMEngine/Wnn/AutoLookupPopup" |
---|
| | #define SCIM_PROP_WNN_INPUTMODE "/IMEngine/Wnn/InputMode" |
---|
| | |
---|
| | static Pointer <WnnFactory> _scim_wnn_factory; |
---|
| | static ConfigPointer _scim_config; |
---|
| | |
---|
| |
---|
| | WnnInstance::WnnInstance (WnnFactory *factory, const String& encoding, int id) |
---|
| | : IMEngineInstanceBase (factory, encoding, id) |
---|
| | { |
---|
| | m_conversion = false; |
---|
| | m_lookup = false; |
---|
| | String host,rc; |
---|
| | host = _scim_config->read(String(SCIM_CONFIG_WNN_SERVER),String("localhost")); |
---|
| | rc = _scim_config->read(String(SCIM_CONFIG_WNN_RC),String("/usr/lib/wnn7/ja_JP/wnnenvrc")); |
---|
| | alp = _scim_config->read(String(SCIM_CONFIG_WNN_ALP),1); |
---|
| | |
---|
| | wnn.wnnConnect(String("test"),host,rc,10); |
---|
| | |
---|
| | // デフォルトキー設定。 |
---|
| | // 設定ファイルから読むようにしてごにょごにょ。 |
---|
| |
---|
| | String("Right"))); |
---|
| | scim_string_to_key_list(k_backward, |
---|
| | _scim_config->read(String(SCIM_CONFIG_WNN_KEY) + String("Backward"), |
---|
| | String("Left"))); |
---|
| | scim_string_to_key_list(k_lookup_popup, |
---|
| | _scim_config->read(String(SCIM_CONFIG_WNN_KEY) + String("LookupPopup"), |
---|
| | String("Alt+s"))); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | WnnInstance::~ WnnInstance() |
---|
| |
---|
| | m_conversion = true; |
---|
| | startConversion(m_rk.getText(true)); |
---|
| | show_preedit_string(); |
---|
| | update_preedit_string(wnn.getText(),wnn.getAttributeList()); |
---|
| | update_preedit_caret(wnn.getText().length()); |
---|
| | update_preedit_caret(wnn.getCaretPos()); |
---|
| | return(true); |
---|
| | } else |
---|
| | if (k_commit.comp(key)) { |
---|
| | if (!m_rk.getTextLength()) { |
---|
| |
---|
| | \fn WnnInstance::process_conversion_key_event(const KeyEvent &key) |
---|
| | */ |
---|
| | bool WnnInstance::process_conversion_key_event(const KeyEvent &key) |
---|
| | { |
---|
| | if ((alp < alp_count) && (alp != 0)) { |
---|
| | if (!m_lookup) startLookup(); |
---|
| | } |
---|
| | |
---|
| | if (k_lookup_popup.comp(key)) { |
---|
| | if (m_lookup) return(true); |
---|
| | startLookup(); |
---|
| | return(true); |
---|
| | } else |
---|
| | if (k_commit.comp(key)) { |
---|
| | commit_string(wnn.getText()); |
---|
| | wnn.updateFrequency(); |
---|
| | m_rk.reset(); |
---|
| | wnn.reset(); |
---|
| | m_conversion = false; |
---|
| | hide_preedit_string(); |
---|
| | hide_lookup_table(); |
---|
| | m_lookup = false; |
---|
| | alp_count = 0; |
---|
| | return(true); |
---|
| | } else |
---|
| | if (k_cancel.comp(key) || k_backspace.comp(key)) { |
---|
| | wnn.reset(); |
---|
| | m_conversion = false; |
---|
| | update_preedit_string(m_rk.getText()); |
---|
| | update_preedit_caret(m_rk.getPos()); |
---|
| | hide_lookup_table(); |
---|
| | m_lookup = false; |
---|
| | alp_count = 0; |
---|
| | return(true); |
---|
| | } else |
---|
| | if (k_conversion_next.comp(key) || k_conversion_prev.comp(key)) { |
---|
| | k_conversion_prev.comp(key) ? m_convList.pos --: m_convList.pos ++; |
---|
| |
---|
| | else if (m_convList.pos < 0) m_convList.pos = m_convList.count - 1; |
---|
| | |
---|
| | wnn.select(m_convList.pos); |
---|
| | update_preedit_string(wnn.getText(),wnn.getAttributeList()); |
---|
| | update_preedit_caret(wnn.getText().length()); |
---|
| | update_preedit_caret(wnn.getCaretPos()); |
---|
| | if (m_lookup) { |
---|
| | m_lookup_table.set_cursor_pos(m_convList.pos); |
---|
| | update_lookup_table(m_lookup_table); |
---|
| | } |
---|
| | alp_count ++; |
---|
| | return(true); |
---|
| | } else |
---|
| | if (k_conversion_expand.comp(key) || k_conversion_shrink.comp(key)) { |
---|
| | bool r; |
---|
| | k_conversion_shrink.comp(key) ? r = wnn.resizeRegion(-1) : r = wnn.resizeRegion(1); |
---|
| | if (!r) return(true); |
---|
| | m_convList = wnn.getConversionList(); |
---|
| | update_preedit_string(wnn.getText(),wnn.getAttributeList()); |
---|
| | update_preedit_caret(wnn.getText().length()); |
---|
| | update_preedit_caret(wnn.getCaretPos()); |
---|
| | hide_lookup_table(); |
---|
| | m_lookup = false; |
---|
| | alp_count = 0; |
---|
| | return(true); |
---|
| | } else |
---|
| | if (k_conversion_forward.comp(key) || k_conversion_backward.comp(key)) { |
---|
| | k_conversion_backward.comp(key) ? wnn.setPos(wnn.getPos() - 1) : wnn.setPos(wnn.getPos() + 1); |
---|
| | m_convList = wnn.getConversionList(); |
---|
| | update_preedit_string(wnn.getText(),wnn.getAttributeList()); |
---|
| | update_preedit_caret(wnn.getText().length()); |
---|
| | update_preedit_caret(wnn.getCaretPos()); |
---|
| | hide_lookup_table(); |
---|
| | m_lookup = false; |
---|
| | alp_count = 0; |
---|
| | return(true); |
---|
| | } else |
---|
| | if (isprint(key.code)) { |
---|
| | commit_string(wnn.getText()); |
---|
| |
---|
| | m_rk.reset(); |
---|
| | wnn.reset(); |
---|
| | m_conversion = false; |
---|
| | hide_preedit_string(); |
---|
| | hide_lookup_table(); |
---|
| | m_lookup = false; |
---|
| | alp_count = 0; |
---|
| | return(process_preedit_key_event(key)); |
---|
| | } |
---|
| | |
---|
| | |
---|
| |
---|
| | } |
---|
| | |
---|
| | void WnnInstance::select_candidate (unsigned int item) |
---|
| | { |
---|
| | if (!m_lookup_table.number_of_candidates ()) return; |
---|
| | |
---|
| | unsigned int current = m_lookup_table.get_cursor_pos_in_current_page (); |
---|
| | |
---|
| | if (current != item) { |
---|
| | m_lookup_table.set_cursor_pos_in_current_page (item); |
---|
| | update_lookup_table (m_lookup_table); |
---|
| | } |
---|
| | |
---|
| | if (!m_lookup_table.number_of_candidates()) return; |
---|
| | |
---|
| | int p = m_lookup_table.get_current_page_start() + item; |
---|
| | m_convList.pos = p; |
---|
| | wnn.select(m_convList.pos); |
---|
| | update_preedit_string(wnn.getText(),wnn.getAttributeList()); |
---|
| | update_preedit_caret(wnn.getCaretPos()); |
---|
| | m_lookup_table.set_cursor_pos(m_convList.pos); |
---|
| | update_lookup_table(m_lookup_table); |
---|
| | } |
---|
| | |
---|
| | void WnnInstance::update_lookup_table_page_size (unsigned int page_size) |
---|
| | { |
---|
| |
---|
| | { |
---|
| | wnn.setYomiText(s); |
---|
| | wnn.ren_conversion(); |
---|
| | m_convList = wnn.getConversionList(); |
---|
| | } |
---|
| | |
---|
| | alp_count = 0; |
---|
| | } |
---|
| | |
---|
| | |
---|
| | /*! |
---|
| | \fn WnnInstance::createLookupTable(WnnConversionList cList) |
---|
| | */ |
---|
| | void WnnInstance::createLookupTable(WnnConversionList cList) |
---|
| | { |
---|
| | m_lookup_table.clear(); |
---|
| | if (!cList.count) return; |
---|
| | for (unsigned int i = 0;i < cList.count;i ++) { |
---|
| | m_lookup_table.append_candidate(cList.kouho.at(i)); |
---|
| | } |
---|
| | m_lookup_table.set_cursor_pos(cList.pos); |
---|
| | update_lookup_table(m_lookup_table); |
---|
| | } |
---|
| | |
---|
| | |
---|
| | /*! |
---|
| | \fn WnnInstance::startLookup() |
---|
| | */ |
---|
| | void WnnInstance::startLookup() |
---|
| | { |
---|
| | createLookupTable(m_convList); |
---|
| | m_lookup = true; |
---|
| | show_lookup_table(); |
---|
| | } |
---|
| | |
---|
| | |