diff --git a/scim-wnn/configure.ac b/scim-wnn/configure.ac index 595b6c8..63a1da0 100644 --- a/scim-wnn/configure.ac +++ b/scim-wnn/configure.ac @@ -67,6 +67,14 @@ AC_SUBST(SCIM_BUILD_SETUP) +AC_CHECK_LIB(crypt, crypt) +AC_CHECK_LIB(wnn6, jl_optimize_fi,, [AC_MSG_RESULT(libwnn6 not found.)]) + +if echo $LIBS | grep -v "wnn6" > /dev/null; then + AC_CHECK_LIB(wnn, jl_optimize_fi,, [AC_MSG_ERROR(Expected alternative libwnn not found.)]) +fi + + # Checks for header files. AC_HEADER_STDC diff --git a/scim-wnn/src/Makefile.am b/scim-wnn/src/Makefile.am index f567179..1ba2e57 100644 --- a/scim-wnn/src/Makefile.am +++ b/scim-wnn/src/Makefile.am @@ -24,22 +24,18 @@ -DSCIM_WNN_LOCALEDIR=\"$(datadir)/locale\" \ -DSCIM_WNN_ICON_FILE=\"@SCIM_ICONDIR@/scim-wnn.png\" -noinst_HEADERS = scim_wnn_imengine.h +noinst_HEADERS = scim_wnn_imengine.h wnnproto.h romkan.h romkan_table.h moduledir = @SCIM_MODULEDIR@/IMEngine module_LTLIBRARIES = wnn.la -wnn_la_SOURCES = scim_wnn_imengine.cpp +wnn_la_SOURCES = scim_wnn_imengine.cpp romkan.cpp wnn_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ wnn_la_CXXFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ -wnn_la_LDFLAGS = -avoid-version \ - -rpath $(moduledir) \ - -module \ - @LIBTOOL_EXPORT_OPTIONS@ \ - @INTLLIBS@ \ - @SCIM_LIBS@ +wnn_la_LDFLAGS = -avoid-version -module -rpath $(moduledir) \ + @LIBTOOL_EXPORT_OPTIONS@ @INTLLIBS@ @SCIM_LIBS@ if SCIM_BUILD_SETUP SETUP_MODULE = wnn-imengine-setup.la @@ -61,3 +57,4 @@ @SCIM_GTKUTILS_LIBS@ \ @INTLLIBS@ \ @SCIM_LIBS@ +wnn_la_LIBADD = diff --git a/scim-wnn/src/romkan.cpp b/scim-wnn/src/romkan.cpp new file mode 100644 index 0000000..dd93fad --- /dev/null +++ b/scim-wnn/src/romkan.cpp @@ -0,0 +1,188 @@ +/*************************************************************************** + * 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 "romkan.h" +#include "romkan_table.h" + +Romkan::Romkan() +{ + reset(); + iconvert.set_encoding ("EUC-JP"); +} + + +Romkan::~Romkan() +{ +} + + + +/*! + \fn Romkan::getPos() + */ +int Romkan::getPos() +{ + return(pos); +} + + +/*! + \fn Romkan::getTextLength() + */ +int Romkan::getTextLength() +{ + return(text.length()); +} + + +/*! + \fn Romkan::setPos(int p) + */ +void Romkan::setPos(int p) +{ + if (p < 0) p = 0; + if (p > getTextLength()) p = getTextLength(); + pos = p; + buf.clear(); +} + + +/*! + \fn Romkan::clear() + */ +void Romkan::clear() +{ + text.clear(); + buf.clear(); +} + + +/*! + \fn Romkan::insert(char k) + */ +WideString Romkan::insert(char k) +{ + buf += k; + String s; + s = k; + text = text.substr(0,pos) + utf8_mbstowcs(s) + text.substr(pos ++); + //return(text); + return(eval()); +} + + +/*! + \fn Romkan::eval() + */ +WideString Romkan::eval() +{ + // �������롣 + + if (buf.length() == 2) { + + // n���첻�ʳ��ϡ֤�סܻҲ��Ǥ��� + // ��������ny�Ͻ����Ǥ��롣 + if (buf[0] == 'n') { + String b = "aiueoy"; + bool boin = false; + for(unsigned int i = 0;i < b.length();i ++) { + if (buf[1] == b[i]) boin = true; + } + if (!boin) { + WideString w; + iconvert.convert(w,String("��")); + text = text.substr(0,pos - 2) + w + text.substr(pos - 1); + buf = buf.substr(buf.length() - 1,1); + } + } + + // Ʊ��ʸ������ʸ��³���Ȥ���ϡ֤áסܻҲ��Ǥ��롣�첻��Ϣ�Ǥ�buf�˻ĤäƤϤ��ʤ��Ϥ��� + else if (buf[0] == buf[1]) { + WideString w; + iconvert.convert(w,String("��")); + text = text.substr(0,pos - 2) + w + text.substr(pos - 1); + buf = buf.substr(buf.length() - 1,1); + return(text); + } + } + + // �ơ��֥�򸡺��������Ϥ��롣 + unsigned int i = 0; + while(RomkanTable[i] != "") { + if (buf == RomkanTable[i]) { + if (RomkanTable[i + 1] == "") { + return(text); // ��α���롣 + } + WideString w; + iconvert.convert(w,RomkanTable[i + 1]); + text = text.substr(0,pos - buf.length()) + w + text.substr(pos); + pos = pos - buf.length() + w.length(); + buf.clear(); + return(text); + } + i += 2; + } + buf.clear(); + return(text); +} + + + + +/*! + \fn Romkan::reset() + */ +void Romkan::reset() +{ + clear(); + pos = 0; +} + + +/*! + \fn Romkan::getText() + */ +WideString Romkan::getText() +{ + return(text); +} + + +/*! + \fn Romkan::backspace() + */ +void Romkan::backspace() +{ + if (getPos() == 0); + text = text.substr(0,pos - 1) + text.substr(pos); + setPos(pos - 1); + // BS�Ͼ��Хåե���BS���륾�� + if (buf.length()) buf = buf.substr(0,buf.length() - 1); +} + + + +/*! + \fn Romkan::del() + */ +void Romkan::del() +{ + if (getPos() == getTextLength()) return; + text = text.substr(0,pos) + text.substr(pos + 1); +} diff --git a/scim-wnn/src/romkan.h b/scim-wnn/src/romkan.h new file mode 100644 index 0000000..b06f264 --- /dev/null +++ b/scim-wnn/src/romkan.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ +#ifndef ROMKAN_H +#define ROMKAN_H + +#define Uses_SCIM_ICONV +#include +#include + +using namespace scim; + +/** +@author TAM(Teppei Tamra) +*/ +class Romkan{ +public: + Romkan(); + + ~Romkan(); + void clear(); + WideString insert(char k); + WideString eval(); + int getPos(); + void setPos(int p); + int getTextLength(); + void reset(); + WideString getText(); + void backspace(); + void del(); + +protected: + WideString text; + String buf; + int pos; + IConvert iconvert; +}; + +#endif diff --git a/scim-wnn/src/romkan_table.h b/scim-wnn/src/romkan_table.h new file mode 100644 index 0000000..3a153dc --- /dev/null +++ b/scim-wnn/src/romkan_table.h @@ -0,0 +1,189 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +// ���޻������Ѵ��ơ��֥롣 +// �������ʤΤǥߥ�/��­�β�ǽ�����ꡣ + +String RomkanTable[] = { +// "�ɤ�", "�Ѵ�", +// ("�Ѵ�"������ξ�����α��"�ɤ�"����ϥ����ߥ͡���) + "a", "��", + "i", "��", + "u", "��", + "e", "��", + "o", "��", + "k", "", + "ka", "��", + "ki", "��", + "ku", "��", + "ke", "��", + "ko", "��", + "s", "", + "sa", "��", + "si", "��", + "su", "��", + "se", "��", + "so", "��", + "t", "", + "ta", "��", + "ti", "��", + "tu", "��", + "te", "��", + "to", "��", + "n", "", + "na", "��", + "ni", "��", + "nu", "��", + "ne", "��", + "no", "��", + "h", "", + "ha", "��", + "hi", "��", + "hu", "��", + "he", "��", + "ho", "��", + "m", "", + "ma", "��", + "mi", "��", + "mu", "��", + "me", "��", + "mo", "��", + "y", "", + "ya", "��", + "yi", "��", + "yu", "��", + "ye", "����", + "yo", "��", + "r", "", + "ra", "��", + "ri", "��", + "ru", "��", + "re", "��", + "ro", "��", + "l", "", + "la", "��", + "li", "��", + "lu", "��", + "le", "��", + "lo", "��", + "w", "", + "wa", "��", + "wi", "��", + "wu", "��", + "we", "��", + "wo", "��", + "N", "��", // ��ʸ����N���� + "x", "", + "xa", "��", + "xi", "��", + "xu", "��", + "xe", "��", + "xo", "��", + "g", "", + "ga", "��", + "gi", "��", + "gu", "��", + "ge", "��", + "go", "��", + "z", "", + "za", "��", + "zi", "��", + "zu", "��", + "ze", "��", + "zo", "��", + "d", "", + "da", "��", + "di", "��", + "du", "��", + "de", "��", + "do", "��", + "b", "", + "ba", "��", + "bi", "��", + "bu", "��", + "be", "��", + "bo", "��", + "p", "", + "pa", "��", + "pi", "��", + "pu", "��", + "pe", "��", + "po", "��", + "ky", "", + "kya", "����", + "kyi", "����", + "kyu", "����", + "kye", "����", + "kyo", "����", + "sy", "", + "sya", "����", + "syi", "��", + "syu", "����", + "sye", "����", + "syo", "����", + "sh", "", + "sha", "����", + "shi", "��", + "shu", "����", + "she", "����", + "sho", "����", + "c", "", + "ch", "", + "cha", "����", + "chi", "��", + "chu", "����", + "che", "����", + "cho", "����", + "zy", "", + "zya", "����", + "zyi", "����", + "zyu", "����", + "zye", "����", + "zyo", "����", + "f", "", + "fa", "�դ�", + "fi", "�դ�", + "fu", "��", + "fe", "�դ�", + "fo", "�դ�", + "hy", "", + "hya", "�Ҥ�", + "hyi", "�Ҥ�", + "hyu", "�Ҥ�", + "hye", "�Ҥ�", + "hyo", "�Ҥ�", + "ry", "", + "rya", "���", + "ryi", "�ꤣ", + "ryu", "���", + "rye", "�ꤧ", + "ryo", "���", + "ny", "", + "nya", "�ˤ�", + "nyi", "�ˤ�", + "nyu", "�ˤ�", + "nye", "�ˤ�", + "nyo", "�ˤ�", + + "-", "��", + "[", "��", + "]", "��", + "" +}; diff --git a/scim-wnn/src/scim_wnn_imengine.cpp b/scim-wnn/src/scim_wnn_imengine.cpp index 207a418..ca2a2af 100644 --- a/scim-wnn/src/scim_wnn_imengine.cpp +++ b/scim-wnn/src/scim_wnn_imengine.cpp @@ -25,6 +25,7 @@ #define Uses_SCIM_IMENGINE #define Uses_SCIM_LOOKUP_TABLE #define Uses_SCIM_CONFIG_BASE +#define Uses_SCIM_ICONV #ifdef HAVE_CONFIG_H #include @@ -48,14 +49,15 @@ // scim�Τ��ޤ��ʤ��� // ����Ǹ����С����ɤ�s -#include #include "scim_wnn_imengine.h" #define scim_module_init wnn_LTX_scim_module_init #define scim_module_exit wnn_LTX_scim_module_exit #define scim_imengine_module_init wnn_LTX_scim_imengine_module_init #define scim_imengine_module_create_factory wnn_LTX_scim_imengine_module_create_factory -#define SCIM_WNN_ICON_FILE (SCIM_ICONDIR "/scim-wnn.png") +#ifndef SCIM_WNN_ICON_FILE + #define SCIM_WNN_ICON_FILE (SCIM_ICONDIR "/scim-wnn.png") +#endif static Pointer _scim_wnn_factory; static ConfigPointer _scim_config; @@ -149,12 +151,6 @@ return String (SCIM_WNN_ICON_FILE); } -String WnnFactory::get_language () const -{ - // ͭ��locale?���Ȥꤢ�������ܸ�˸��ꤷ�Ȥ������� - return scim_validate_language ("ja_JP"); -} - IMEngineInstancePointer WnnFactory::create_instance (const String& encoding, int id) { // �ºݤ˥��󥹥��󥹤��롣 @@ -169,6 +165,9 @@ WnnInstance::WnnInstance (WnnFactory *factory, const String& encoding, int id) : IMEngineInstanceBase (factory, encoding, id) { + // �Ȥꤢ������ᤦ���Ǥ����ޤ��� + jl_open_lang("test","localhost","jp_JP","/usr/lib/wnn7/ja_JP/wnnenvrc",wnn_message,wnn_message,10); + m_converter.set_encoding ("EUC-JP"); } WnnInstance::~ WnnInstance() @@ -177,34 +176,114 @@ bool WnnInstance::process_key_event (const KeyEvent& key) { + if (key.is_key_release()) return false; + return(process_preedit_key_event(key)); +} + + +/*! + \fn WnnInstance::process_preedit_key_event(const KeyEvent &key) + */ +bool WnnInstance::process_preedit_key_event(const KeyEvent &key) +{ + if (key.code == SCIM_KEY_Return) { + if (!m_rk.getTextLength()) { + return(false); + } + commit_string(m_rk.getText()); + m_rk.reset(); + hide_preedit_string(); + return(true); + } + if ((key.code == SCIM_KEY_Left) || (key.code == SCIM_KEY_Right)) { + if (!m_rk.getTextLength()) { + return(false); + } + key.code == SCIM_KEY_Left ? m_rk.setPos(m_rk.getPos() - 1) : m_rk.setPos(m_rk.getPos() + 1); + update_preedit_caret(m_rk.getPos()); + return(true); + } + if (key.code == SCIM_KEY_BackSpace) { + if (!m_rk.getTextLength()) { + return(false); + } + m_rk.backspace(); + update_preedit_string(m_rk.getText()); + update_preedit_caret(m_rk.getPos()); + } + if (isprint(key.code)) { + show_preedit_string(); + SCIM_DEBUG_IMENGINE(1) << key.get_key_string() << "\n"; + update_preedit_string(m_rk.insert(key.get_ascii_code())); + update_preedit_caret(m_rk.getPos()); + return true; + } + return false; } void WnnInstance::move_preedit_caret (unsigned int pos) { + m_rk.setPos(pos); + update_preedit_caret(pos); } 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); + } + } void WnnInstance::update_lookup_table_page_size (unsigned int page_size) { + m_lookup_table.set_page_size (page_size); } void WnnInstance::lookup_table_page_up () { + if (!m_lookup_table.number_of_candidates () || !m_lookup_table.get_current_page_start ()) return; + + m_lookup_table.page_up (); + + update_lookup_table (m_lookup_table); + } void WnnInstance::lookup_table_page_down () { + if (!m_lookup_table.number_of_candidates () || + m_lookup_table.get_current_page_start () + m_lookup_table.get_current_page_size () >= + m_lookup_table.number_of_candidates ()) + return; + + m_lookup_table.page_down (); + + update_lookup_table (m_lookup_table); + } void WnnInstance::reset () { + } void WnnInstance::focus_in () { + hide_aux_string (); + + if (m_lookup_table.number_of_candidates ()) { + update_lookup_table (m_lookup_table); + show_lookup_table (); + } else { + hide_lookup_table (); + } + } void WnnInstance::focus_out () @@ -218,3 +297,14 @@ + + +/*! + \fn WnnInstance::wnn_message (char *s) + */ +int WnnInstance::wnn_message (char *s) +{ + + SCIM_DEBUG_IMENGINE(1) << s << "\n"; +} + diff --git a/scim-wnn/src/scim_wnn_imengine.h b/scim-wnn/src/scim_wnn_imengine.h index 88223b7..9d7e39e 100644 --- a/scim-wnn/src/scim_wnn_imengine.h +++ b/scim-wnn/src/scim_wnn_imengine.h @@ -17,10 +17,19 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef SCIMSCIM_WNN_IMENGINE_H -#define SCIMSCIM_WNN_IMENGINE_H +#ifndef SCIM_WNN_IMENGINE_H +#define SCIM_WNN_IMENGINE_H + +#include +#include +#include +#include +#define Uses_SCIM_ICONV +#include +#include using namespace scim; +using namespace std; class WnnFactory : public IMEngineFactoryBase { @@ -37,8 +46,8 @@ virtual WideString get_help () const; virtual String get_uuid () const; virtual String get_icon_file () const; - virtual String get_language() const; virtual IMEngineInstancePointer create_instance (const String& encoding, int id = -1); +protected: }; @@ -59,7 +68,17 @@ virtual void focus_out (); virtual void trigger_property (const String &property); +protected: + static int wnn_message (char *s); + +protected: + IConvert m_converter; + CommonLookupTable m_lookup_table; + Romkan m_rk; +protected: + bool process_preedit_key_event(const KeyEvent &key); }; -#endif \ No newline at end of file +#endif + diff --git a/scim-wnn/src/wnnproto.h b/scim-wnn/src/wnnproto.h new file mode 100644 index 0000000..2be7e17 --- /dev/null +++ b/scim-wnn/src/wnnproto.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +/* ���������� */ + +extern "C" { + + /* ����Ū�ʤ� */ + #define w_char unsigned short + struct wnn_buf *jl_open_lang(char *,char *,char *,char *,int (*)(char *),int(*)(char *),int); + int jl_isconnect(struct wnn_buf*); + + /* �Ѵ��˴ؤ��뤽�� */ + int jl_ren_conv(struct wnn_buf*,w_char*,int,int,int); /*jl_fi_ren_conv�Ȥ��⤢�ä��ʤ� */ + int wnn_get_area(struct wnn_buf*,int,int,w_char*,int); + #define jl_get_kanji(buf,bun1,bun2,area) wnn_get_area(buf,bun1,bun2,area,1) + #define jl_get_yomi(buf,bun1,bun2,area) wnn_get_area(buf,bun1,bun2,area,0) + + /* w_char����EUC���Ѵ����륢�� */ + void wstostr(char *e,w_char *u) { + int x; + for(;*u;) { + x = *u ++; + *e ++ = x >> 8; + *e ++ = x; + } + *e ++ = 0; + } + /* EUC����w_char���Ѵ�����ʥ� */ + void strtows(w_char *u,char *e) { + int x; + for(;*e;) { + x = *e ++; + if(x & 0x80) + x = (x << 8) | *e ++; + *u ++ = x; + } + *u = 0; + } + +}