diff --git a/scim-wnn/src/Makefile.am b/scim-wnn/src/Makefile.am index 1ba2e57..d096f89 100644 --- a/scim-wnn/src/Makefile.am +++ b/scim-wnn/src/Makefile.am @@ -24,12 +24,13 @@ -DSCIM_WNN_LOCALEDIR=\"$(datadir)/locale\" \ -DSCIM_WNN_ICON_FILE=\"@SCIM_ICONDIR@/scim-wnn.png\" -noinst_HEADERS = scim_wnn_imengine.h wnnproto.h romkan.h romkan_table.h +noinst_HEADERS = scim_wnn_imengine.h wnnproto.h romkan.h romkan_table.h \ + wnnconversion.h moduledir = @SCIM_MODULEDIR@/IMEngine module_LTLIBRARIES = wnn.la -wnn_la_SOURCES = scim_wnn_imengine.cpp romkan.cpp +wnn_la_SOURCES = scim_wnn_imengine.cpp romkan.cpp wnnconversion.cpp wnn_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ wnn_la_CXXFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ diff --git a/scim-wnn/src/romkan.cpp b/scim-wnn/src/romkan.cpp index dd93fad..db4d14a 100644 --- a/scim-wnn/src/romkan.cpp +++ b/scim-wnn/src/romkan.cpp @@ -156,10 +156,17 @@ /*! - \fn Romkan::getText() + \fn Romkan::getText(bool hosei) */ -WideString Romkan::getText() +WideString Romkan::getText(bool hosei) { + if (hosei) { + if (text.substr(pos - 1,1) == utf8_mbstowcs("n")) { + WideString w; + iconvert.convert(w,String("��")); + text = text.substr(0,pos - 1) + w; + } + } return(text); } diff --git a/scim-wnn/src/romkan.h b/scim-wnn/src/romkan.h index b06f264..f0a9d89 100644 --- a/scim-wnn/src/romkan.h +++ b/scim-wnn/src/romkan.h @@ -41,7 +41,7 @@ void setPos(int p); int getTextLength(); void reset(); - WideString getText(); + WideString getText(bool hosei = false); void backspace(); void del(); diff --git a/scim-wnn/src/scim_wnn_imengine.cpp b/scim-wnn/src/scim_wnn_imengine.cpp index 9c06b2d..6e33bf7 100644 --- a/scim-wnn/src/scim_wnn_imengine.cpp +++ b/scim-wnn/src/scim_wnn_imengine.cpp @@ -165,9 +165,7 @@ WnnInstance::WnnInstance (WnnFactory *factory, const String& encoding, int id) : IMEngineInstanceBase (factory, encoding, id) { - // �Ȥꤢ������ᤦ���Ǥ����ޤ��� - wnn = jl_open_lang("test","localhost","jp_JP","/usr/lib/wnn7/ja_JP/wnnenvrc",wnn_message,wnn_message,10); - m_converter.set_encoding ("EUC-JP"); + m_conversion = false; } WnnInstance::~ WnnInstance() @@ -177,7 +175,8 @@ bool WnnInstance::process_key_event (const KeyEvent& key) { if (key.is_key_release()) return false; - return(process_preedit_key_event(key)); + if (m_conversion) return(process_conversion_key_event(key)); + else return(process_preedit_key_event(key)); } @@ -188,11 +187,19 @@ { // ���������ɤ�ľ����äƥ�������͡��ɡ��������ޤ����Ȥꤢ�������Τޤޤǡ� + if (key.code == SCIM_KEY_space) { + if (!m_rk.getTextLength()) { + return(false); + } + m_conversion = true; + startConversion(m_rk.getText(true)); + return(process_conversion_key_event(key)); + } if (key.code == SCIM_KEY_Return) { if (!m_rk.getTextLength()) { return(false); } - commit_string(m_rk.getText()); + commit_string(m_rk.getText(true)); m_rk.reset(); hide_preedit_string(); return(true); @@ -224,6 +231,34 @@ return false; } +/*! + \fn WnnInstance::process_conversion_key_event(const KeyEvent &key) + */ +bool WnnInstance::process_conversion_key_event(const KeyEvent &key) +{ + show_preedit_string(); + update_preedit_string(wnn.getText()); + update_preedit_caret(wnn.getText().length()); + + if (key.code == SCIM_KEY_Return) { + commit_string(wnn.getText()); + m_rk.reset(); + wnn.reset(); + m_conversion = false; + hide_preedit_string(); + return(true); + } + if ((key.code == SCIM_KEY_Escape) || (key.code == SCIM_KEY_BackSpace)) { + wnn.reset(); + m_conversion = false; + update_preedit_string(m_rk.getText()); + update_preedit_caret(m_rk.getPos()); + return(true); + } + return(true); +} + + void WnnInstance::move_preedit_caret (unsigned int pos) { m_rk.setPos(pos); @@ -303,11 +338,10 @@ /*! - \fn WnnInstance::wnn_message (char *s) + \fn WnnInstance::startConversion(WideString s) */ -int WnnInstance::wnn_message (char *s) +void WnnInstance::startConversion(WideString s) { - - SCIM_DEBUG_IMENGINE(1) << s << "\n"; + wnn.setYomiText(s); + wnn.ren_conversion(); } - diff --git a/scim-wnn/src/scim_wnn_imengine.h b/scim-wnn/src/scim_wnn_imengine.h index 995324c..4f263cf 100644 --- a/scim-wnn/src/scim_wnn_imengine.h +++ b/scim-wnn/src/scim_wnn_imengine.h @@ -22,8 +22,8 @@ #include #include -#include #include +#include #define Uses_SCIM_ICONV #include #include @@ -69,15 +69,14 @@ 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; - struct wnn_buf *wnn; + WnnConversion wnn; + bool m_conversion; protected: bool process_preedit_key_event(const KeyEvent &key); + bool process_conversion_key_event(const KeyEvent &key); + void startConversion(WideString s); }; diff --git a/scim-wnn/src/wnnconversion.cpp b/scim-wnn/src/wnnconversion.cpp new file mode 100644 index 0000000..4e0ff5d --- /dev/null +++ b/scim-wnn/src/wnnconversion.cpp @@ -0,0 +1,157 @@ +/*************************************************************************** + * 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 "wnnconversion.h" + +#ifdef HAVE_CONFIG_H + #include +#endif + +#ifdef HAVE_GETTEXT + #include + #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 + +WnnConversion::WnnConversion() +{ + // �Ȥꤢ������ᤦ���Ǥ����ޤ��� + wnn = jl_open_lang("test","localhost","jp_JP","/usr/lib/wnn7/ja_JP/wnnenvrc",wnn_error,wnn_message,10); + m_iconv.set_encoding ("EUC-JP"); +} + + +WnnConversion::~WnnConversion() +{ +} + + + /* w_char����EUC���Ѵ����륢�� */ +void WnnConversion::wstostr(unsigned char *e,w_char *u) { + w_char x; + for(;*u;) { + x = *u ++; + if (x & 0x8000) { + *e ++ = x >> 8; + *e ++ = x; + } else + *e++ = x; + } + *e ++ = 0; +} + + /* EUC����w_char���Ѵ�����ʥ� */ +void WnnConversion::strtows(w_char *u,unsigned char *e) { + w_char x; + for(;*e;) { + x = *e ++; + if(x & 0x80) + x = ((x << 8) & 0xff00) | *e ++; + *u ++ = x; + } + *u = 0; +} + + + +/*! + \fn WnnConversion::isConnected() + */ +bool WnnConversion::isConnected() +{ + if (wnn) return(true); + else (false); +} + + + + +/*! + \fn WnnConversion::wnn_message (char *s) + */ +int WnnConversion::wnn_message (char *s) +{ + + SCIM_DEBUG_IMENGINE(1) << s << "\n"; +} + +/*! + \fn WnnConversion::wnn_error (char *s) + */ +int WnnConversion::wnn_error (char *s) +{ + + SCIM_DEBUG_IMENGINE(1) << s << "\n"; +} + + + + +/*! + \fn WnnConversion::reset() + */ +void WnnConversion::reset() +{ + yomiText.clear(); + text.clear(); +} + + +/*! + \fn WnnConversion::setYomiText(WideString yomi) + */ +void WnnConversion::setYomiText(WideString yomi) +{ + yomiText = yomi; +} + + +/*! + \fn WnnConversion::ren_conversion() + */ +int WnnConversion::ren_conversion() +{ + convList.clear(); + w_char ws[1024]; + char c[2048]; + String y; + m_iconv.convert(y,yomiText); + strtows(ws,(unsigned char*)y.data()); + int b = jl_ren_conv(wnn,ws,0,-1,WNN_USE_ZENGO); + + wnn_get_area(wnn,0,-1,ws,1); + wstostr((unsigned char*)c,ws); + m_iconv.convert(text,c,strlen(c) + 1); + +} + + +/*! + \fn WnnConversion::getText() + */ +WideString WnnConversion::getText() +{ + return(text); +} diff --git a/scim-wnn/src/wnnconversion.h b/scim-wnn/src/wnnconversion.h new file mode 100644 index 0000000..a74b39b --- /dev/null +++ b/scim-wnn/src/wnnconversion.h @@ -0,0 +1,71 @@ +/*************************************************************************** + * 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 WNNCONVERSION_H +#define WNNCONVERSION_H + + +#include +#include +#include +#include +#define Uses_SCIM_ICONV +#include +#include + +using namespace scim; +using namespace std; + + +/** +@author TAM(Teppei Tamra) +*/ +class WnnConversionList{ +public: + WideString Yomi; + list kouho; +}; + +class WnnConversion{ +public: + WnnConversion(); + + ~WnnConversion(); + bool isConnected(); + void reset(); + void setYomiText(WideString yomi); + int ren_conversion(); + WideString getText(); + +protected: + void wstostr(unsigned char *e,w_char *u); + void strtows(w_char *u,unsigned char *e); + static int wnn_message (char *s); + static int wnn_error (char *s); + +protected: + struct wnn_buf *wnn; + IConvert m_iconv; + WideString yomiText; + WideString text; + list convList; + +}; + +#endif diff --git a/scim-wnn/src/wnnproto.h b/scim-wnn/src/wnnproto.h index 8bffa3e..b1a69db 100644 --- a/scim-wnn/src/wnnproto.h +++ b/scim-wnn/src/wnnproto.h @@ -19,6 +19,8 @@ ***************************************************************************/ /* ���������� */ +#ifndef WNNPROTO_H +#define WNNPROTO_H extern "C" { @@ -49,29 +51,7 @@ #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(unsigned char *e,w_char *u) { - w_char x; - for(;*u;) { - x = *u ++; - if (x & 0x8000) { - *e ++ = x >> 8; - *e ++ = x; - } else - *e++ = x; - } - *e ++ = 0; - } - - /* EUC����w_char���Ѵ�����ʥ� */ - void strtows(w_char *u,unsigned char *e) { - w_char x; - for(;*e;) { - x = *e ++; - if(x & 0x80) - x = ((x << 8) & 0xff00) | *e ++; - *u ++ = x; - } - *u = 0; - } } + +#endif +