/*************************************************************************** * Copyright (C) 2004 by TAM(Teppei Tamra) * * tam-t@par.odn.ne.jp * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "nicolainput.h" #include "honoka_plugin_def.h" #ifdef HAVE_CONFIG_H #include <config.h> #endif // 国際化のおまじない。 #ifdef HAVE_GETTEXT #include <libintl.h> #define _(String) dgettext(GETTEXT_PACKAGE,String) #define N_(String) (String) #else #define _(String) (String) #define N_(String) (String) #define bindtextdomain(Package,Directory) #define textdomain(domain) #define bind_textdomain_codeset(domain,codeset) #endif // プライグイン化のおまじないです。 HonokaPluginRegister(NicolaInput); namespace Honoka { struct { KeyCode key; char noShift[6]; char leftShift[6]; char rightShift[6]; } _nicolaTable[] = { {SCIM_KEY_1,"1","?",""}, {SCIM_KEY_2,"2","/",""}, {SCIM_KEY_3,"3","~",""}, {SCIM_KEY_4,"4","「",""}, {SCIM_KEY_5,"5","」",""}, {SCIM_KEY_6,"6","","["}, {SCIM_KEY_7,"7","","]"}, {SCIM_KEY_8,"8","","("}, {SCIM_KEY_9,"9","",")"}, {SCIM_KEY_0,"0","","『"}, {SCIM_KEY_minus,"-","","』"}, {SCIM_KEY_backslash,"\\","",""}, {SCIM_KEY_q,"。","ぁ",""}, {SCIM_KEY_w,"か","え","が"}, {SCIM_KEY_e,"た","り","だ"}, {SCIM_KEY_r,"こ","ゃ","ご"}, {SCIM_KEY_t,"さ","れ","ざ"}, {SCIM_KEY_y,"ら","ぱ","よ"}, {SCIM_KEY_u,"ち","ぢ","に"}, {SCIM_KEY_i,"く","ぐ","る"}, {SCIM_KEY_o,"つ","づ","ま"}, {SCIM_KEY_p,",","","ぇ"}, {SCIM_KEY_at,"、","",""}, {SCIM_KEY_bracketleft,"゛","","゜"}, {SCIM_KEY_a,"う","を",""}, {SCIM_KEY_s,"し","あ","じ"}, {SCIM_KEY_d,"て","な","で"}, {SCIM_KEY_f,"け","ゅ","げ"}, {SCIM_KEY_g,"せ","も","ぜ"}, {SCIM_KEY_h,"は","ば","み"}, {SCIM_KEY_j,"と","ど","お"}, {SCIM_KEY_k,"き","ぎ","の"}, {SCIM_KEY_l,"い","ぽ","ょ"}, {SCIM_KEY_semicolon,"ん","","っ"}, {SCIM_KEY_z,".","ぅ",""}, {SCIM_KEY_x,"ひ","ー","び"}, {SCIM_KEY_c,"す","ろ","ず"}, {SCIM_KEY_v,"ふ","や","ぶ"}, {SCIM_KEY_b,"へ","ぃ","べ"}, {SCIM_KEY_n,"め","ぷ","ぬ"}, {SCIM_KEY_m,"そ","","ゆ"}, {SCIM_KEY_comma,"ね","ぺ","む"}, {SCIM_KEY_period,"ほ","ぼ","わ"}, {SCIM_KEY_slash,"・","","ぉ"}, {SCIM_KEY_NullKey,"","",""} // terminator }; } NicolaInput::NicolaInput(ConfigPointer cfg) : PreEditor(cfg) { //fakeNicolaInput = cfg->read(HONOKA_CONFIG_KANAINPUT_FAKEKANA,HONOKA_DEFAULT_KANAINPUT_FAKEKANA); LShift = false; RShift = false; for(unsigned int i = 0;_nicolaTable[i].key != SCIM_KEY_NullKey;i ++) { NicolaKey k; iconvert.convert(k.noShift,_nicolaTable[i].noShift); iconvert.convert(k.leftShift,_nicolaTable[i].leftShift); iconvert.convert(k.rightShift,_nicolaTable[i].rightShift); keymap.insert(pair<KeyEvent,NicolaKey>(_nicolaTable[i].key,k)); } } NicolaInput::~NicolaInput() { } /*! \fn NicolaInput::getModeName() */ String NicolaInput::getModeName() { return String(_("KANA")); } /*! \fn NicolaInput::getName() */ String NicolaInput::getName() { return String("Nicola"); } /*! \fn NicolaInput::getPropertyName() */ String NicolaInput::getPropertyName() { return String(_("NICOLA")); } /*! \fn NicolaInput::inputEvent(const KeyEvent &key) */ bool NicolaInput::inputEvent(const KeyEvent &key) { // 喰っておくべきもの。 if ((key.code == SCIM_KEY_Shift_L) || (key.code == SCIM_KEY_Shift_R) || (key.code == SCIM_KEY_Control_L) || (key.code == SCIM_KEY_Control_R) || (key.code == SCIM_KEY_Alt_L) || (key.code == SCIM_KEY_Alt_R) || (key.code == SCIM_KEY_Super_L) || (key.code == SCIM_KEY_Super_R) || (key.code == SCIM_KEY_Hyper_L) || (key.code == SCIM_KEY_Hyper_R)) return true; map<KeyEvent,NicolaKey>::iterator it = keymap.find(key.code); if (it == keymap.end()) return true; WideString w; if (LShift) w = it->second.leftShift; else if (RShift) w = it->second.rightShift; else w = it->second.noShift; if (w.length()) { text = text.substr(0,pos) + w + text.substr(pos); pos ++; } return true; //return false; } /*! \fn NicolaInput::keyEventHook(const KeyEvent &key) */ bool NicolaInput::keyEventHook(const KeyEvent &key) { if (key.code == SCIM_KEY_Henkan) { if (key.is_key_press()) RShift = true; else if (key.is_key_release()) RShift = false; return true; } if (key.code == SCIM_KEY_Muhenkan) { if (key.is_key_press()) LShift = true; else if (key.is_key_release()) LShift = false; return true; } return false; }