1 /***************************************************************************
2  *   Copyright (C) 2004 by TAM(Teppei Tamra)                               *
3  *   tam-t@par.odn.ne.jp                                                   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef SCIM_WNN_IMENGINE_H
21 #define SCIM_WNN_IMENGINE_H
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <dlfcn.h>
28 
29 #define Uses_SCIM_UTILITY
30 #define Uses_SCIM_IMENGINE
31 #define Uses_SCIM_LOOKUP_TABLE
32 #define Uses_SCIM_CONFIG_BASE
33 #define Uses_SCIM_ICONV
34 #define Uses_SCIM_TRANS_COMMANDS
35 
36 #include <cstdio>
37 #include <cstdlib>
38 #include <vector>
39 #include <stack>
40 #include <map>
41 #include <convertor.h>
42 #include <preeditor.h>
43 #include <predictor.h>
44 #include <honokamultiplepluginbase.h>
45 #include <honokakeyeventlist.h>
46 #include <honokastatus.h>
47 #define Uses_SCIM_ICONV
48 #include <scim.h>
49 #include <scim_iconv.h>
50 #include <multiconvertor.h>
51 #include <acpredictor.h>
52 
53 typedef HonokaPluginBase* createInstanceFunc(ConfigPointer);
54 typedef void deleteInstanceFunc(HonokaPluginBase *);
55 typedef int getPluginVersionFunc();
56 
57 using namespace scim;
58 using namespace std;
59 
60 class ACPredictor;
61 
62 class HonokaFactory : public IMEngineFactoryBase
63 {
64 protected:
65     friend class HonokaInstance;
66     WideString m_name;
67 public:
68     HonokaFactory ();
69     HonokaFactory (const WideString & name, const String & languages);
70     virtual ~HonokaFactory ();
71     virtual WideString get_name () const;
72     virtual WideString get_authors () const;
73     virtual WideString get_credits () const;
74     virtual WideString get_help () const;
75     virtual String get_uuid () const;
76     virtual String get_icon_file () const;
77     virtual IMEngineInstancePointer create_instance (const String& encoding, int id = -1);
78 protected:
79 
80 };
81 
82 class HonokaPluginEntry
83 {
84 public:
85     String filename;
86     String name;
87     void *dll;
88     createInstanceFunc *createInstance;
89     deleteInstanceFunc *deleteInstance;
90     getPluginVersionFunc *getPluginVersion;
91     HonokaPluginBase *instance;
92 };
93 
94 
95 class HonokaInstance : public IMEngineInstanceBase,public HonokaStatus
96 {
97 protected:
98     friend class MultiConvertor;
99     friend class ACPredictor;
100 
101 public:
102     HonokaInstance (HonokaFactory *factory, const String  &encoding, int id = -1);
103     virtual ~HonokaInstance ();
104     virtual bool process_key_event (const KeyEvent& key);
105     virtual void move_preedit_caret (unsigned int pos);
106     virtual void select_candidate (unsigned int item);
107     virtual void update_lookup_table_page_size (unsigned int page_size);
108     virtual void lookup_table_page_up ();
109     virtual void lookup_table_page_down ();
110     virtual void reset ();
111     virtual void focus_in ();
112     virtual void focus_out ();
113     virtual void trigger_property (const String &property);
114     virtual void process_helper_event (const String &helper_uuid, const Transaction &trans);
115     void startLookup();
116 
117 protected:
118     Transaction trans;
119     CommonLookupTable m_lookup_table;
120     PreEditor *m_preeditor;
121     Convertor *m_convertor;
122     Convertor *m_def_convertor;
123     Predictor *m_predictor;
124     Convertor *m_splitter;
125     //bool m_conversion;
126     //bool m_prediction;
127     //bool m_lookup;
128     ResultList m_convList;
129     ResultList m_convListOrig;
130     PropertyList m_proplist;
131     bool m_no_update;
132     int alp;
133     int alp_count;
134     bool changeable_splitter;
135     bool numkeyselect;
136     bool mini_status;
137     bool prediction;
138     bool realtime_prediction;
139     bool auto_conversion;
140     bool save_setting;
141     bool select_prediction_direct;
142     String defaultPreEditor;
143     String defaultConvertor;
144     String defaultPredictor;
145     IConvert m_iconv;
146     //map<String,HonokaPluginEntry> plugins;
147     vector<HonokaPluginEntry> plugins;
148     vector<PreEditor *> preeditors;
149     vector<Convertor *> convertors;
150     vector<Predictor *> predictors;
151     WideString yomi;
152     stack<WideString> preeditStack;
153     Convertor *m_multi;
154     vector<Segment> segments;
155     ACPredictor *acpredictor;
156     int preeditKeyDelay;
157     uint32 predictionDelay;
158     WideString preeditCache;
159     enum convertedStringType { NORMAL , HIRA , KATA , HALF , WIDE };
160     WideString pString;
161     convertedStringType pStringType;
162 protected:
163     bool process_preedit_key_event(const KeyEvent &key);
164     bool process_conversion_key_event(const KeyEvent &key);
165     bool process_prediction_key_event(const KeyEvent &key);
166     void startConversion(WideString s = WideString(), bool multi = false);
167     void createLookupTable(ResultList cList);
168     void loadPlugins();
169     void init();
170     void unload();
171     void updatePreEditor();
172     void updateProperty();
173     void updateConversion();
174     bool changePreEditor(const String &name);
175     bool changeConvertor(const String &name);
176     bool changePredictor(const String &name);
177     bool changeSplitter(const String &name);
178     void autoConversion();
179     bool pluginCheck(HonokaPluginBase *p);
180     WideString getPosPerCount(int p,int c);
181     vector<String> split(const String &str,const char &sep = ',');
182     const WideString getConvertedText();
183     const AttributeList getConvertedAttributeList();
184     void updateConvertedString();
185     void timerEvent(int id);
186 private:
187     HonokaKeyEventList
188         k_conversion_start,     // 変換開始
189         k_multi_conversion,     // 一喝
190         k_cancel,               // キャンセルキー
191         k_delete,               // 削除
192         k_backspace,            // バックスペース
193         k_commit,               // 確定
194         k_conversion_next,      // 次候補
195         k_conversion_prev,      // 前候補
196         k_conversion_expand,    // 拡大
197         k_conversion_shrink,    // 縮小
198         k_conversion_forward,   // 次文節
199         k_conversion_backward,  // 前文節
200         k_forward,              // カーソル移動/前
201         k_backward,             // カーソル移動/後ろ
202         k_home,                 // カーソル移動/先頭
203         k_end,                  // カーソル移動/末尾
204         k_lookup_popup,         // 候補一覧表示
205         k_lookup_pageup,        // 候補一覧前項
206         k_lookup_pagedown,      // 候補一覧次項
207         k_convert_ctype,        // 文字種変換
208         k_convert_hiragana,     // ひらがな変換
209         k_convert_katakana,     // カタカナ変換
210         k_convert_half,         // 半角変換
211         k_convert_wide,         // 全角変換
212         k_auto_conversion,      // 変換モードトグル
213         k_next_convertor,       // 次の変換エンジンへ
214         k_prev_convertor,       // 前の変換エンジンへ
215         k_reconversion,         // 再変換
216         k_result_to_preedit,    // 変換結果をPreEditorにpush
217         k_furigana_commit,      // ふりがな付き確定
218         k_allreset,             // 機能全リセット
219 
220         // for Wnn7
221         k_conversion_ikeiji,    // 異形字変換
222         k_conversion_rensou,    // 連想変換
223         k_select_prediction,    // 予測選択
224         k_selection[9],         // 候補選択ショートカット
225         k_dummy;
226     vector<HonokaKeyEventList> k_convertor;
227     vector<HonokaKeyEventList> k_preeditor;
228     vector<HonokaKeyEventList> k_predictor;
229 };
230 
231 
232 #endif
233 
234