diff --git a/scim-wnn/data/like-msime.rkt b/scim-wnn/data/like-msime.rkt index 38d5648..90dd0f0 100644 --- a/scim-wnn/data/like-msime.rkt +++ b/scim-wnn/data/like-msime.rkt @@ -8,6 +8,11 @@ # Ascii/WideAsciiモードへの移行キー。 $Key/Ascii null $Key/WideAscii null +# 全角/半角トグルキー +$Key/ToggleHalfOrWide Zenkaku_Hankaku + +!Shift+space  # 全角スペース + - ー a あ i い diff --git a/scim-wnn/src/preeditor.cpp b/scim-wnn/src/preeditor.cpp index f24c796..e628ac4 100644 --- a/scim-wnn/src/preeditor.cpp +++ b/scim-wnn/src/preeditor.cpp @@ -201,23 +201,23 @@ /*! - \fn PreEditor::convHanZen(WideString &t,int &p) + \fn PreEditor::convHanZen(WideString &t,int p) */ -void PreEditor::convHanZen(WideString &t,int &p) +int PreEditor::convHanZen(WideString &t,int p) { for(unsigned int i = 0;i < t.size();i ++) { if ((t[i] >= convChars[ASCII_START]) && (t[i] <= convChars[ASCII_END])) t[i] = t[i] - convChars[ASCII_START] + convChars[WASCII_START]; } - return; + return(p); } /*! - \fn PreEditor::convZenHan(WideString &t,int &p) + \fn PreEditor::convZenHan(WideString &t,int p) */ -void PreEditor::convZenHan(WideString &t,int &p) +int PreEditor::convZenHan(WideString &t,int p) { for(unsigned int i = 0;i < t.size();i ++) { if ((t[i] >= convChars[WASCII_START]) && (t[i] <= convChars[WASCII_END])) @@ -233,7 +233,7 @@ i += it->second.length() - 1; } } - return; + return(p); } diff --git a/scim-wnn/src/preeditor.h b/scim-wnn/src/preeditor.h index 1316f67..0444ffd 100644 --- a/scim-wnn/src/preeditor.h +++ b/scim-wnn/src/preeditor.h @@ -79,8 +79,8 @@ virtual String getModeName(); static void convHiraKata(WideString &t); static void convKataHira(WideString &t); - static void convHanZen(WideString &t,int &p); - static void convZenHan(WideString &t,int &p); + static int convHanZen(WideString &t,int p); + static int convZenHan(WideString &t,int p); virtual bool cancelEvent(); virtual bool inputEvent(const KeyEvent &key); virtual String getName(); diff --git a/scim-wnn/src/romkan.cpp b/scim-wnn/src/romkan.cpp index 34e6c1a..9c02e81 100644 --- a/scim-wnn/src/romkan.cpp +++ b/scim-wnn/src/romkan.cpp @@ -170,6 +170,8 @@ scim_string_to_key_list(key_ascii_mode,tableConfig["Key/Ascii"]); if (tableConfig.find("Key/WideAscii") != tableConfig.end()) scim_string_to_key_list(key_wascii_mode,tableConfig["Key/WideAscii"]); + if (tableConfig.find("Key/ToggleHalfOrWide") != tableConfig.end()) + scim_string_to_key_list(key_toggle_hw,tableConfig["Key/ToggleHalfOrWide"]); if (tableConfig.find("Hook") != tableConfig.end()) hookp = tableConfig["Hook"]; else hookp = ""; @@ -233,6 +235,13 @@ return(eval()); break; } + case HROMA: { + buf += s; + text = text.substr(0,pos) + utf8_mbstowcs(s) + text.substr(pos); + pos ++; + return(eval()); + break; + } } return(text); } @@ -257,14 +266,20 @@ if (buf[1] == b[i]) boin = true; } if (!boin) { - text = text.substr(0,pos - 2) + convChars[KANA_N] + text.substr(pos - 1); + WideString r; + r += convChars[KANA_N]; + if (mode == HROMA) convZenHan(r,0); + text = text.substr(0,pos - 2) + r + text.substr(pos - 1); buf = buf.substr(buf.length() - 1,1); } } // Ʊ��ʸ������ʸ��³���Ȥ���ϡ֤áסܻҲ��Ǥ��롣�첻��Ϣ�Ǥ�buf�˻ĤäƤϤ��ʤ��Ϥ��� else if (buf[0] == buf[1]) { - text = text.substr(0,pos - 2) + convChars[KANA_XTU] + text.substr(pos - 1); + WideString r; + r += convChars[KANA_XTU]; + if (mode == HROMA) convZenHan(r,0); + text = text.substr(0,pos - 2) + r + text.substr(pos - 1); buf = buf.substr(buf.length() - 1,1); return(text); } @@ -275,8 +290,11 @@ // �ơ��֥�򸡺��������Ϥ��롣 map::iterator it = RomkanTable.find(buf); if (it != RomkanTable.end()) { - text = text.substr(0,pos - buf.length()) + it->second + text.substr(pos); - pos = pos - buf.length() + it->second.length(); + WideString r; + r += it->second; + if (mode == HROMA) convZenHan(r,0); + text = text.substr(0,pos - buf.length()) + r + text.substr(pos); + pos = pos - buf.length() + r.length(); buf.clear(); return(text); } @@ -326,12 +344,18 @@ text = text.substr(0,pos - buf.length()) + text.substr(pos); pos -= buf.length(); if (buf.substr(buf.length() - 1,1) == "n") { - text = text.substr(0,pos) + convChars[KANA_N] + text.substr(pos); + WideString r; + r += convChars[KANA_N]; + if (mode == HROMA) convZenHan(r,0); + text = text.substr(0,pos) + r + text.substr(pos); pos ++; } } else if (buf.substr(buf.length() - 1,1) == "n") { - text = text.substr(0,pos - 1) + convChars[KANA_N] + text.substr(pos); + WideString r; + r += convChars[KANA_N]; + if (mode == HROMA) convZenHan(r,0); + text = text.substr(0,pos - 1) + r + text.substr(pos); } } } @@ -386,9 +410,7 @@ */ void Romkan::toHalf() { - int p = getPos(); - convZenHan(text,p); - if (p != getPos()) setPos(p); + setPos(convZenHan(text,getPos())); buf.clear(); } @@ -397,9 +419,7 @@ */ void Romkan::toWide() { - int p = getPos(); - convHanZen(text,pos); - if (p != getPos()) setPos(p); + setPos(convHanZen(text,getPos())); buf.clear(); } @@ -410,6 +430,28 @@ */ bool Romkan::keyEventHook(const KeyEvent &key) { + if (key_toggle_hw.comp(key)) { + switch (mode) { + case ASCII: { + mode = WASCII; + break; + } + case WASCII: { + mode = ASCII; + break; + } + case ROMA: { + mode = HROMA; + break; + } + case HROMA: { + mode = ROMA; + break; + } + } + return(true); + } + if ((isprint(key.code)) && ((mode == ASCII) || (mode == WASCII))) { if ((!key.is_alt_down()) && (!key.is_control_down())) { insert(key.get_ascii_code()); @@ -443,6 +485,10 @@ return(String(_("Roma-Kana"))); break; } + case HROMA: { + return(String(_("Half Roma-Kana"))); + break; + } case ASCII: { return(String(_("Ascii"))); break; diff --git a/scim-wnn/src/romkan.h b/scim-wnn/src/romkan.h index c54abdd..a9bb03e 100644 --- a/scim-wnn/src/romkan.h +++ b/scim-wnn/src/romkan.h @@ -81,12 +81,12 @@ protected: String buf; String modeName; - enum inputMode {ROMA,ASCII,WASCII}; + enum inputMode {ROMA,HROMA,ASCII,WASCII}; inputMode mode; bool nnMode; bool asciiCancel; bool removeRemainder; - PreEditorKeyEventList key_ascii_mode,key_wascii_mode; + PreEditorKeyEventList key_ascii_mode,key_wascii_mode,key_toggle_hw; map RomkanTable; set keepTable; map tableConfig;