diff --git a/honoka/src/Makefile.am b/honoka/src/Makefile.am index f6f2dc8..3a10a71 100644 --- a/honoka/src/Makefile.am +++ b/honoka/src/Makefile.am @@ -27,12 +27,12 @@ -DHONOKA_PLUGINDIR=\"@SCIM_MODULEDIR@/honoka\" noinst_HEADERS = honoka_imengine.h wnnproto.h romkan.h romkan_table.h \ - wnnconversion.h honoka_def.h kanainput.h anthyconversion.h + wnnconversion.h honoka_def.h kanainput.h anthyconversion.h multiconvertor.h moduledir = @SCIM_MODULEDIR@/IMEngine module_LTLIBRARIES = honoka.la -honoka_la_SOURCES = honoka_imengine.cpp +honoka_la_SOURCES = honoka_imengine.cpp multiconvertor.cpp honoka_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ honoka_la_CXXFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ diff --git a/honoka/src/anthyconversion.cpp b/honoka/src/anthyconversion.cpp index 992c401..762809d 100644 --- a/honoka/src/anthyconversion.cpp +++ b/honoka/src/anthyconversion.cpp @@ -100,6 +100,7 @@ ResultList AnthyConversion::getResultList(int p,int kt){ if (p == -1) p = pos; if ((kt != 0) || (p >= convResult.size())) return ResultList(); + setPos(p); return convResult[p]; } diff --git a/honoka/src/convertor.h b/honoka/src/convertor.h index 98b197d..852d184 100644 --- a/honoka/src/convertor.h +++ b/honoka/src/convertor.h @@ -45,6 +45,7 @@ int pos; int count; int kType; + vector label; vector kouho; }; diff --git a/honoka/src/honoka_def.h b/honoka/src/honoka_def.h index 92a4fcf..f92f850 100644 --- a/honoka/src/honoka_def.h +++ b/honoka/src/honoka_def.h @@ -23,6 +23,8 @@ #define HONOKA_CONFIG_KEY_CONVERSION_START "/IMEngine/Honoka/Key/ConversionStart" #define HONOKA_DEFAULT_KEY_CONVERSION_START "space" +#define HONOKA_CONFIG_KEY_MULTI_CONVERSION "/IMEngine/Honoka/Key/MultiConversion" +#define HONOKA_DEFAULT_KEY_MULTI_CONVERSION "Control+Alt+space" #define HONOKA_CONFIG_KEY_CANCEL "/IMEngine/Honoka/Key/Cancel" #define HONOKA_DEFAULT_KEY_CANCEL "Escape,Control+g" #define HONOKA_CONFIG_KEY_DELETE "/IMEngine/Honoka/Key/Delete" diff --git a/honoka/src/honoka_imengine.cpp b/honoka/src/honoka_imengine.cpp index cab61bf..b9c2c5b 100644 --- a/honoka/src/honoka_imengine.cpp +++ b/honoka/src/honoka_imengine.cpp @@ -18,13 +18,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - -#define Uses_SCIM_UTILITY -#define Uses_SCIM_IMENGINE -#define Uses_SCIM_LOOKUP_TABLE -#define Uses_SCIM_CONFIG_BASE -#define Uses_SCIM_ICONV - #ifdef HAVE_CONFIG_H #include #endif @@ -64,10 +57,10 @@ #define YOSOKU 3 - static Pointer _honoka_factory; static ConfigPointer _scim_config; + extern "C" { void scim_module_init (void) { @@ -233,6 +226,8 @@ m_convertor = convertors.at(0); m_preeditor = preeditors.at(0); + m_multi = new MultiConvertor(_scim_config,this); + // ������ء� init(); } @@ -367,6 +362,9 @@ scim_string_to_key_list(k_result_to_preedit, _scim_config->read(String(HONOKA_CONFIG_KEY_RESULTTOPREEDIT), String(HONOKA_DEFAULT_KEY_RESULTTOPREEDIT))); + scim_string_to_key_list(k_multi_conversion, + _scim_config->read(String(HONOKA_CONFIG_KEY_MULTI_CONVERSION), + String(HONOKA_DEFAULT_KEY_MULTI_CONVERSION))); for(unsigned i = 0;i < 10;i ++) { char a[3]; sprintf(a,"%d",i); @@ -583,6 +581,11 @@ alp_count ++; return true; } else + if (k_multi_conversion.comp(key)) { + startConversion(m_preeditor->getText(true),true); + alp_count ++; + return true; + } else if (k_commit.comp(key)) { if (auto_conversion) { commit_string(m_convertor->getText()); @@ -747,6 +750,8 @@ updatePreEditor(); m_lookup = false; alp_count = 1; + if (m_def_convertor != m_convertor) m_convertor = m_def_convertor; + updateProperty(); return true; } else if (k_result_to_preedit.comp(key)) { @@ -759,6 +764,8 @@ m_conversion = false; m_lookup = false; alp_count = 1; + if (m_def_convertor != m_convertor) m_convertor = m_def_convertor; + updateProperty(); updatePreEditor(); return true; } else @@ -767,6 +774,8 @@ m_conversion = false; m_lookup = false; alp_count = 0; + if (m_def_convertor != m_convertor) m_convertor = m_def_convertor; + updateProperty(); updatePreEditor(); return true; } else @@ -899,6 +908,8 @@ m_conversion = false; m_lookup = false; alp_count = 0; + if (m_def_convertor != m_convertor) m_convertor = m_def_convertor; + updateProperty(); updatePreEditor(); return process_preedit_key_event(key); } @@ -1080,6 +1091,7 @@ commit_string(m_convertor->getText()); m_convertor->updateFrequency(); m_convertor->reset(); + if (m_def_convertor != m_convertor) m_convertor = m_def_convertor; m_conversion = false; m_lookup = false; alp_count = 0; @@ -1121,13 +1133,14 @@ /*! - \fn HonokaInstance::startConversion(WideString s) + \fn HonokaInstance::startConversion(WideString s,bool multi) */ -void HonokaInstance::startConversion(WideString s) +void HonokaInstance::startConversion(WideString s,bool multi) { // �Ѵ����Ͻ����� // ����lookup�Ͼä��Ƥ������� m_def_convertor = m_convertor; + if (multi) m_convertor = m_multi; if (!s.length()) s = yomi; else yomi = s; m_lookup = false; @@ -1209,7 +1222,8 @@ m_lookup_table.clear(); if (!cList.count) return; for (unsigned int i = 0;i < cList.count;i ++) { - m_lookup_table.append_candidate(cList.kouho.at(i)); + if (cList.label.size() > i) m_lookup_table.append_candidate(cList.label.at(i)); + else m_lookup_table.append_candidate(cList.kouho.at(i)); } m_lookup_table.set_cursor_pos(cList.pos); update_lookup_table(m_lookup_table); diff --git a/honoka/src/honoka_imengine.h b/honoka/src/honoka_imengine.h index c662025..8e5520e 100644 --- a/honoka/src/honoka_imengine.h +++ b/honoka/src/honoka_imengine.h @@ -26,6 +26,13 @@ #include +#define Uses_SCIM_UTILITY +#define Uses_SCIM_IMENGINE +#define Uses_SCIM_LOOKUP_TABLE +#define Uses_SCIM_CONFIG_BASE +#define Uses_SCIM_ICONV + + #include #include #include @@ -37,6 +44,7 @@ #define Uses_SCIM_ICONV #include #include +#include typedef HonokaPluginBase* createInstanceFunc(ConfigPointer); typedef void deleteInstanceFunc(HonokaPluginBase *); @@ -77,6 +85,9 @@ class HonokaInstance : public IMEngineInstanceBase { +protected: + friend class MultiConvertor; + public: HonokaInstance (HonokaFactory *factory, const String &encoding, int id = -1); virtual ~HonokaInstance (); @@ -117,11 +128,12 @@ String sType; WideString yomi; stack preeditStack; + Convertor *m_multi; protected: bool process_preedit_key_event(const KeyEvent &key); bool process_conversion_key_event(const KeyEvent &key); bool process_yosoku_key_event(const KeyEvent &key); - void startConversion(WideString s = WideString()); + void startConversion(WideString s = WideString(), bool multi = false); void createLookupTable(ResultList cList); void init(); void updatePreEditor(); @@ -134,6 +146,7 @@ private: HonokaKeyEventList k_conversion_start, // �Ѵ����� + k_multi_conversion, // ��� k_cancel, // ����󥻥륭�� k_delete, // ��� k_backspace, // �Хå����ڡ��� diff --git a/honoka/src/multiconvertor.cpp b/honoka/src/multiconvertor.cpp new file mode 100644 index 0000000..e9e05a5 --- /dev/null +++ b/honoka/src/multiconvertor.cpp @@ -0,0 +1,214 @@ +/*************************************************************************** + * Copyright (C) 2005 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 "multiconvertor.h" + +MultiConvertor::MultiConvertor(ConfigPointer cfg , HonokaInstance *i) + : Convertor(cfg) +{ + instance = i; +} + + +MultiConvertor::~MultiConvertor() +{ +} + +bool MultiConvertor::isConnected() { + for(unsigned int i = 0;i < instance->convertors.size();i ++) { + if (!instance->convertors[i]->isConnected()) + return false; + } + return true; +} + +void MultiConvertor::reset(){ + for(unsigned int i = 0;i < instance->convertors.size();i ++) { + instance->convertors[i]->reset(); + } +} + +void MultiConvertor::setYomiText(WideString yomi) { + for(unsigned int i = 0;i < instance->convertors.size();i ++) { + instance->convertors[i]->setYomiText(yomi); + } +} + +int MultiConvertor::ren_conversion() { + def = instance->m_def_convertor; + texts.clear(); + int b = instance->m_def_convertor->ren_conversion(); + for(unsigned int i = 0;i < b;i ++) { + ResultList l = instance->m_def_convertor->getResultList(i); + texts.push_back(l.kouho[0]); + } + for(unsigned int i = 0;i < instance->convertors.size();i ++) { + if (instance->m_def_convertor != instance->convertors[i]) { + instance->convertors[i]->ren_conversion(); + for(unsigned int j = 0;j < b;j ++) { + int bl = instance->m_def_convertor->getResultList(j).Yomi.length(); + int cl = instance->convertors[i]->getResultList(j).Yomi.length(); + if (bl != cl) instance->convertors[i]->resizeRegion(bl - cl); + } + } + } + setPos(0); + return b; +} + +WideString MultiConvertor::getText() { + WideString t; + for(unsigned int i = 0;i < texts.size();i ++) { + t = t + texts[i]; + } + return t; +} + +int MultiConvertor::setPos(int p){ + instance->m_def_convertor->setPos(p); + for(unsigned int i = 0;i < instance->convertors.size();i ++) { + if (instance->m_def_convertor != instance->convertors[i]) + instance->convertors[i]->setPos(instance->m_def_convertor->getPos()); + } + return instance->m_def_convertor->getPos(); +} + +int MultiConvertor::getPos() { + return instance->m_def_convertor->getPos(); +} + +ResultList MultiConvertor::getResultList(int p,int kt){ + results.clear(); + result.kouho.clear(); + ResultList l = instance->m_def_convertor->getResultList(p,kt); + for(unsigned int i = 0;i < l.kouho.size();i ++) { + l.label.push_back(l.kouho[i] + utf8_mbstowcs(String(" (")) + + utf8_mbstowcs(instance->m_def_convertor->getName()) + utf8_mbstowcs(String(")"))); + } + MultiResultList m; + m.list = l; + m.convertor = instance->m_def_convertor; + results.push_back(m); + for(unsigned int i = 0;i < instance->convertors.size();i ++) { + if (instance->convertors[i] != instance->m_def_convertor) { + m.list = instance->convertors[i]->getResultList(instance->m_def_convertor->getPos(),kt); + m.convertor = instance->convertors[i]; + results.push_back(m); + } + } + for(unsigned int i = 1;i < results.size();i ++) { + for(unsigned int j = 0;j < results[i].list.kouho.size();j ++) { + l.label.push_back(results[i].list.kouho[j] + utf8_mbstowcs(String(" (")) + + utf8_mbstowcs(results[i].convertor->getName()) + utf8_mbstowcs(String(")"))); + l.kouho.push_back(results[i].list.kouho[j]); + } + } + l.count = l.kouho.size(); + result = l; + return l; +} + +ResultList MultiConvertor::getYosokuList(const WideString &str) { + return ResultList(); +} + +bool MultiConvertor::select(int p) { + if (p < result.kouho.size()) texts[getPos()] = result.kouho[p]; + return true; +} + +AttributeList MultiConvertor::getAttributeList() { + AttributeList attr; + int l = 0; + for(unsigned int i = 0;i < texts.size();i ++) { + if (getPos() == i) { + Attribute a(l,texts[i].length(),SCIM_ATTR_DECORATE,SCIM_ATTR_DECORATE_REVERSE); + attr.push_back(a); + } + l += texts[i].length(); + } + return attr; + +} + +bool MultiConvertor::resizeRegion(int w) { + return false; + + // �ʲ������档 + texts.clear(); + int p = getPos(); + vector s; + if (!instance->m_def_convertor->resizeRegion(w)) return false; + for(unsigned int i = 0;;i ++) { + ResultList l = instance->m_def_convertor->getResultList(i); + if (!l.count) break; + s.push_back(l.Yomi.length()); + texts.push_back(l.kouho[0]); + } + instance->m_def_convertor->setPos(p); + for(unsigned int i = 0;i < instance->convertors.size();i ++) { + if (instance->m_def_convertor != instance->convertors[i]) { + for(unsigned int j = 0;j < texts.size();j ++) { + int bl = s[j]; + int cl = instance->convertors[i]->getResultList(j).Yomi.length(); + if (bl != cl) instance->convertors[i]->resizeRegion(bl - cl); + } + instance->convertors[i]->setPos(p); + } + } + + return true; +} + +void MultiConvertor::updateFrequency() { + // ̤������ + return; +} + +bool MultiConvertor::connect() { + for(unsigned int i = 0;i < instance->convertors.size();i ++) { + instance->convertors[i]->connect(); + } + return true; +} +void MultiConvertor::disconnect() { + for(unsigned int i = 0;i < instance->convertors.size();i ++) { + instance->convertors[i]->disconnect(); + } + return; +} + +int MultiConvertor::getCaretPos() { + int p = 0; + for(unsigned int i = 0;i < getPos();i ++) p += texts[i].length(); + return p; +} + + +String MultiConvertor::getName() +{ + //instance->m_def_convertor->getName(); + return instance->m_def_convertor->getName() + String("(M)"); +} + +String MultiConvertor::getPropertyName() +{ + return String("MultiConvertor"); +} + diff --git a/honoka/src/multiconvertor.h b/honoka/src/multiconvertor.h new file mode 100644 index 0000000..5127829 --- /dev/null +++ b/honoka/src/multiconvertor.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (C) 2005 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 MULTICONVERTOR_H +#define MULTICONVERTOR_H + +#include +#include +#include + +/** +@author TAM (Teppei Tamra) +*/ + +class HonokaInstance; + +class MultiResultList +{ +public: + Convertor *convertor; + ResultList list; +}; + +class MultiConvertor : public Convertor +{ +public: + MultiConvertor(ConfigPointer cfg , HonokaInstance *i); + + ~MultiConvertor(); + virtual bool isConnected(); + virtual void reset(); + virtual void setYomiText(WideString yomi); + virtual int ren_conversion(); + virtual WideString getText(); + virtual int setPos(int p); + virtual int getPos(); + virtual ResultList getResultList(int p = -1 ,int kt = 0); + virtual ResultList getYosokuList(const WideString &str); + virtual bool select(int p); + virtual AttributeList getAttributeList(); + virtual bool resizeRegion(int w); + virtual void updateFrequency(); + virtual bool connect(); + virtual void disconnect(); + virtual int getCaretPos(); + virtual String getName(); + virtual String getPropertyName(); + +protected: + HonokaInstance *instance; + vector results; + ResultList result; + vector texts; + Convertor *def; +}; + +#endif