diff --git a/scim-wnn/src/scim_wnn_imengine.cpp b/scim-wnn/src/scim_wnn_imengine.cpp index 6e33bf7..6582a16 100644 --- a/scim-wnn/src/scim_wnn_imengine.cpp +++ b/scim-wnn/src/scim_wnn_imengine.cpp @@ -193,7 +193,10 @@ } m_conversion = true; startConversion(m_rk.getText(true)); - return(process_conversion_key_event(key)); + show_preedit_string(); + update_preedit_string(wnn.getText(),wnn.getAttributeList()); + update_preedit_caret(wnn.getText().length()); + return(true); } if (key.code == SCIM_KEY_Return) { if (!m_rk.getTextLength()) { @@ -236,10 +239,6 @@ */ 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(); @@ -255,13 +254,28 @@ update_preedit_caret(m_rk.getPos()); return(true); } + if (key.code == SCIM_KEY_space) { + m_convList.pos ++; + if (m_convList.pos >= m_convList.count) m_convList.pos = 0; + + wnn.select(m_convList.pos); + update_preedit_string(wnn.getText(),wnn.getAttributeList()); + update_preedit_caret(wnn.getText().length()); + } + if ((key.code == SCIM_KEY_Left) || (key.code == SCIM_KEY_Right)) { + key.code == SCIM_KEY_Left ? wnn.setPos(wnn.getPos() - 1) : wnn.setPos(wnn.getPos() + 1); + m_convList = wnn.getConversionList(); + update_preedit_string(wnn.getText(),wnn.getAttributeList()); + return(true); + } + return(true); } void WnnInstance::move_preedit_caret (unsigned int pos) { - m_rk.setPos(pos); + if (!m_conversion) m_rk.setPos(pos); update_preedit_caret(pos); } @@ -344,4 +358,5 @@ { wnn.setYomiText(s); wnn.ren_conversion(); + m_convList = wnn.getConversionList(); } diff --git a/scim-wnn/src/scim_wnn_imengine.h b/scim-wnn/src/scim_wnn_imengine.h index 4f263cf..fdf8ffc 100644 --- a/scim-wnn/src/scim_wnn_imengine.h +++ b/scim-wnn/src/scim_wnn_imengine.h @@ -73,6 +73,7 @@ Romkan m_rk; WnnConversion wnn; bool m_conversion; + WnnConversionList m_convList; protected: bool process_preedit_key_event(const KeyEvent &key); bool process_conversion_key_event(const KeyEvent &key); diff --git a/scim-wnn/src/wnnconversion.cpp b/scim-wnn/src/wnnconversion.cpp index 4e0ff5d..93226e9 100644 --- a/scim-wnn/src/wnnconversion.cpp +++ b/scim-wnn/src/wnnconversion.cpp @@ -40,6 +40,8 @@ // �Ȥꤢ������ᤦ���Ǥ����ޤ��� 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"); + pos = 0; + bunsetu = 0; } @@ -115,7 +117,10 @@ void WnnConversion::reset() { yomiText.clear(); + bunList.clear(); text.clear(); + attr.clear(); + pos = 0; } @@ -133,21 +138,47 @@ */ int WnnConversion::ren_conversion() { - convList.clear(); + convList.Yomi.clear(); + convList.kouho.clear(); + bunList.clear(); + pos = 0; 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); - + bunsetu = jl_ren_conv(wnn,ws,0,-1,WNN_USE_ATO); + bunList.resize(bunsetu); + for(unsigned int i = 0;i < bunsetu;i ++) { + WideString w; + wnn_get_area(wnn,i,i + 1,ws,1); + wstostr((unsigned char*)c,ws); + m_iconv.convert(w,c,strlen(c)); + bunList[i] = w; + } + return(bunsetu); } + +/*! + \fn WnnConversion::createText() + */ +void WnnConversion::createText() +{ + WideString w; + int len = 0; + for(unsigned int i = 0;i < bunsetu;i ++) { + if (pos == i) { + attr.clear(); + Attribute a(w.length(),bunList[i].length(),SCIM_ATTR_DECORATE,SCIM_ATTR_DECORATE_REVERSE); + attr.push_back(a); + } + w = w + bunList[i]; + } + text = w; +} + /*! \fn WnnConversion::getText() */ @@ -155,3 +186,82 @@ { return(text); } + + +/*! + \fn WnnConversion::getAttributeList() + */ +AttributeList WnnConversion::getAttributeList() +{ + return(attr); +} + + +/*! + \fn WnnConversion::setPos(int p) + */ +int WnnConversion::setPos(int p) +{ + if (p >= bunsetu) p = bunsetu - 1; + else if (p < 0) p = 0; + + pos = p; + createText(); + return(pos); +} + + +/*! + \fn WnnConversion::getPos() + */ +int WnnConversion::getPos() +{ + return(pos); +} + + +/*! + \fn WnnConversion::getConversionList(int p) + */ +WnnConversionList WnnConversion::getConversionList(int p) +{ + convList.kouho.clear(); + convList.pos = 0; + convList.count = 0; + if (p == -1) p = pos; + if ((p >= bunsetu) || (p < 0)) return(convList); + pos = p; + convList.pos = jl_zenkouho(wnn,pos,WNN_USE_ATO,WNN_UNIQ); + convList.count = jl_zenkouho_suu(wnn); + convList.kouho.resize(convList.count); + for (unsigned int i = 0;i < convList.count; i ++) { + w_char k[1024]; + char buf[2048]; + WideString u; + jl_get_zenkouho_kanji(wnn,i,k); + wstostr((unsigned char*)buf,k); + m_iconv.convert(u,buf,strlen(buf)); + convList.kouho[i] = u; + } + createText(); + return(convList); + +} + + +/*! + \fn WnnConversion::select(int p) + */ +bool WnnConversion::select(int p) +{ + if (p > convList.count) p = 0; + convList.pos = p;//jl_set_jikouho(wnn,p); + + bunList.at(pos) = convList.kouho.at(p); + createText(); + + return(true); + +} + + diff --git a/scim-wnn/src/wnnconversion.h b/scim-wnn/src/wnnconversion.h index a74b39b..5b8e9e3 100644 --- a/scim-wnn/src/wnnconversion.h +++ b/scim-wnn/src/wnnconversion.h @@ -23,11 +23,12 @@ #include #include -#include +#include #include #define Uses_SCIM_ICONV #include #include +#include using namespace scim; using namespace std; @@ -39,7 +40,9 @@ class WnnConversionList{ public: WideString Yomi; - list kouho; + int pos; + int count; + vector kouho; }; class WnnConversion{ @@ -52,19 +55,30 @@ void setYomiText(WideString yomi); int ren_conversion(); WideString getText(); + int setPos(int p); + int getPos(); + WnnConversionList getConversionList(int p = -1); + bool select(int p); + AttributeList getAttributeList(); 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); + void createText(); protected: struct wnn_buf *wnn; IConvert m_iconv; WideString yomiText; + //WideString text; + int pos; + int bunsetu; WideString text; - list convList; + vector bunList; + AttributeList attr; + WnnConversionList convList; }; diff --git a/scim-wnn/src/wnnproto.h b/scim-wnn/src/wnnproto.h index b1a69db..b89c5c6 100644 --- a/scim-wnn/src/wnnproto.h +++ b/scim-wnn/src/wnnproto.h @@ -32,9 +32,10 @@ /* �Ѵ��˴ؤ��뤽�� */ 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); - int jl_zenkouho_dai(struct wnn_buf*,int,int,int,int); + int jl_zenkouho(struct wnn_buf*,int,int,int); int jl_zenkouho_suu(struct wnn_buf*); void jl_get_zenkouho_kanji(struct wnn_buf*,int ,w_char *); + int jl_set_jikouho(struct wnn_buf*,int); #define WNN_NO_USE 0 #define WNN_USE_MAE 1