00001 #ifndef _MGUI_IME_H
00002 #define _MGUI_IME_H
00003
00004 #ifdef _MGNCSENGINE_IME
00005
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009
00010 #define IME_STOP_MSG 1
00011 #define IME_CONTINUE_MSG 0
00012
00013 typedef int (*NCSCB_LEN_FIRST_CHAR)(const unsigned char*, int len);
00014
00015 typedef int (*NCSCB_RETRIEVE_CHAR)(const char*);
00016 typedef struct _CHARSET_CONVERTER
00017 {
00018
00019 NCSCB_RETRIEVE_CHAR retrieve_char;
00020 void * conv_info;
00021 void * reserved;
00022 }CHARSET_CONVERTER;
00023
00024 MGNCS_EXPORT BOOL ncsIMInitCharsetConv(CHARSET_CONVERTER* conv, const char* from_charset, const char* to_charset, NCSCB_RETRIEVE_CHAR retrieve_char);
00025 MGNCS_EXPORT void ncsIMFreeCharsetConv(CHARSET_CONVERTER* conv);
00026 MGNCS_EXPORT unsigned int ncsIMCharsetConv(CHARSET_CONVERTER* conv, const char ** pwords);
00027 MGNCS_EXPORT char* ncsIMConvertWord(CHARSET_CONVERTER* conv, const char* word, char* out, int len);
00028
00029 MGNCS_EXPORT NCSCB_LEN_FIRST_CHAR ncsIMGetFirstCharCallback(const char* encoding);
00030
00031 typedef struct _mIMEngineClass mIMEngineClass;
00032 typedef struct _mIMEngine mIMEngine;
00033 typedef struct _mIMIteratorClass mIMIteratorClass;
00034 typedef struct _mIMIterator mIMIterator;
00035
00036 #define NCS_IM_SCANCODE_ISDIGIT(s) ((s) >= SCANCODE_1 && (s) <= SCANCODE_0)
00037 #define NCS_IM_SCANCODE_ISALPHA(s) \
00038 ( ((s) >= SCANCODE_Q && (s) <= SCANCODE_P) \
00039 || ((s) >= SCANCODE_A && (s) <= SCANCODE_L) \
00040 || ((s) >= SCANCODE_Z && (s) <= SCANCODE_M) \
00041 )
00042
00043 enum mIMIteratorProp{
00044 NCSP_IMEIT_CHARTYPE
00045 };
00046
00047 #define mIMIteratorClassHeader(clss, super) \
00048 mObjectClassHeader(clss, super) \
00049 PUBLIC void (*empty)(clss*); \
00050 PUBLIC int (*count)(clss*); \
00051 PUBLIC int (*next)(clss*); \
00052 PUBLIC int (*prev)(clss*); \
00053 PUBLIC int (*locate)(clss*,int off, int type); \
00054 PUBLIC int (*curIndex)(clss*); \
00055 PUBLIC DWORD (*setProperty)(clss*, int id, DWORD valude); \
00056 PUBLIC DWORD (*getProperty)(clss*, int id); \
00057 PUBLIC const char*(*word)(clss*);
00058
00059 #define mIMIteratorHeader(clss) \
00060 mObjectHeader(clss) \
00061 CHARSET_CONVERTER *charset_converter;
00062
00063
00064 struct _mIMIteratorClass {
00065 mIMIteratorClassHeader(mIMIterator, mObject)
00066 };
00067
00068 struct _mIMIterator {
00069 mIMIteratorHeader(mIMIterator)
00070 };
00071
00072 MGNCS_EXPORT extern mIMIteratorClass g_stmIMIteratorCls;
00073
00074 #define MAX_IME_NAME_LEN 16
00075 #define mIMEngineClassHeader(clss, super) \
00076 mObjectClassHeader(clss, super) \
00077 const char* (*imeName)(clss*); \
00078 mIMEngine * (*create)(const char* pdict, DWORD add_data); \
00079 const char* (*getEncoding)(clss*); \
00080 PROTECTED NCSCB_RETRIEVE_CHAR (*getRetrieveChar)(clss*);\
00081 mIMIterator* (*newIterator)(clss*); \
00082 mIMIterator* (*newAssocIterator)(clss*); \
00083 \
00084 BOOL (*findWords)(clss*, mIMIterator* it, const char* input, int start); \
00085 BOOL (*findAssociate)(clss*, mIMIterator* it, const char* input);
00086
00087 #define mIMEngineHeader(clss) \
00088 mObjectHeader(clss)
00089
00090 struct _mIMEngineClass{
00091 mIMEngineClassHeader(mIMEngine, mObject)
00092 };
00093
00094 struct _mIMEngine {
00095 mIMEngineHeader(mIMEngine)
00096 };
00097
00098 MGNCS_EXPORT extern mIMEngineClass g_stmIMEngineCls;
00099
00100 typedef struct _mIMEClass mIMEClass;
00101 typedef struct _mIME mIME;
00102
00103 typedef struct _mIMManagerClass mIMManagerClass;
00104 typedef struct _mIMManager mIMManager;
00105
00106
00107 #define NCS_MAX_INPUT 128
00108 #define NCS_IME_UPDATE_KEY 0x01
00109 #define NCS_IME_UPDATE_WORDS 0x02
00110 #define NCS_IME_UPDATE_FEEDBACK 0x04
00111 #define NCS_IME_UPDATE_CURSOR 0x08
00112 #define NCS_IME_UPDATE_ALL 0xFFFF
00113
00114 #define NCS_IMM_BEGIN (MSG_USER + 100)
00115 #define NCS_IMM_UPDATE (NCS_IMM_BEGIN + 1)
00116
00117 #define NCS_IMM_GETSELWORD (NCS_IMM_BEGIN + 2)
00118
00119 #define NCS_IMM_ISSELWORDCTRLACTIVE (NCS_IMM_BEGIN + 3)
00120 #define NCS_IMM_SETSELWORDACTIVE (NCS_IMM_BEGIN + 4)
00121
00122 #define mIMEClassHeader(clss, super) \
00123 mObjectClassHeader(clss, super) \
00124 \
00125 PROTECTED BOOL (*showIME)(clss*); \
00126 PROTECTED void (*hideIME)(clss*); \
00127 PROTECTED void (*update)(clss*, DWORD flfags); \
00128 PROTECTED const char* (*getSelWord)(clss*, BOOL braw); \
00129 PROTECTED DWORD (*getIMStatus)(clss*, int); \
00130 PROTECTED BOOL (*setIMStatus)(clss*,int, DWORD); \
00131 PROTECTED BOOL (*onCaretPos)(clss*, int,int); \
00132 PROTECTED BOOL (*findWords)(clss*, const char* input, int start, int len); \
00133 PROTECTED BOOL (*findAssociate)(clss*, const char* words); \
00134 PROTECTED BOOL (*emptyKey)(clss*); \
00135 PROTECTED BOOL (*setEncoding)(clss*, const char*); \
00136 PROTECTED BOOL (*addChar)(clss*, int ch); \
00137 PROTECTED BOOL (*delChar)(clss*,BOOL bback); \
00138 PROTECTED BOOL (*setInsert)(clss*, int pos, int type); \
00139 PROTECTED BOOL (*clearInput)(clss*); \
00140 PROTECTED int (*onChar)(clss*, int ch,DWORD keyflags); \
00141 PROTECTED int (*onKeyDown)(clss*,int scancode, DWORD keyflags); \
00142 PUBLIC void (*setIMEngine)(clss*, mIMEngine*); \
00143 PUBLIC void (*empty)(clss*, BOOL bUpdate);
00144
00145
00146 #define mIMEHeader(clss) \
00147 mObjectHeader(clss) \
00148 mIME* next; \
00149 char input[NCS_MAX_INPUT]; \
00150 int len; \
00151 int start:16; \
00152 int insert:16; \
00153 mIMManager *ime_manager; \
00154 mIMEngine *ime_engine; \
00155 mIMIterator *key_it; \
00156 mIMIterator *assoc_it; \
00157 CHARSET_CONVERTER charset_conv; \
00158 HWND hwnd_view; \
00159 WNDPROC old_view_proc;
00160
00161 struct _mIMEClass {
00162 mIMEClassHeader(mIME, mObject)
00163 };
00164
00165 struct _mIME {
00166 mIMEHeader(mIME)
00167 };
00168
00169 MGNCS_EXPORT extern mIMEClass g_stmIMECls;
00170
00171 #define mIME_sendWords(ime) (_c(ime->ime_manager)->sendWords(ime->ime_manager))
00172 #define mIME_sendKeys(ime) (_c(ime->ime_manager)->sendKeys(ime->ime_manager))
00173
00174 #define mIME_FromView(hwnd) ((mIME*)GetWindowAdditionalData(hwnd))
00175 MGNCS_EXPORT void mIME_attach(mIME *ime, HWND hwnd);
00176
00177 MGNCS_EXPORT void mIME_passMessage(mIME* ime, int message, WPARAM wParam, LPARAM lParam);
00178 #define mIMView_passMessage(hwnd, message, wParam, lParam) \
00179 mIME_passMessage(mIME_FromView(hwnd), (message), (wParam), (lParam))
00180
00181 #define mIMManagerClassHeader(clss, super) \
00182 mObjectClassHeader(clss, super) \
00183 PROTECTED int (*procIMMsg)(clss*,int,WPARAM,LPARAM,int*); \
00184 PROTECTED BOOL (*nextIME)(clss*); \
00185 PROTECTED BOOL (*setIME)(clss*, const char*); \
00186 PUBLIC BOOL (*addIME)(clss*, mIME *ime); \
00187 PROTECTED BOOL (*sendWords)(clss*); \
00188 PROTECTED BOOL (*sendKeys)(clss*); \
00189 PUBLIC void (*setEncoding)(clss*, const char*);
00190
00191 #define mIMManagerHeader(clss) \
00192 mObjectHeader(clss) \
00193 NCSCB_LEN_FIRST_CHAR len_first_char; \
00194 HWND hwnd; \
00195 HWND hwnd_target; \
00196 mIME * header; \
00197 mIME * cur_ime; \
00198 DWORD flags; \
00199 int ime_x:16; \
00200 int ime_y:16;
00201
00202 #define NCSF_IMM_DISABLE 0x01
00203 #define NCSF_IMM_ACTIVED 0x02
00204 #define NCSF_IMM_NULLIME 0x04
00205 #define NCSF_IMM_SETTING_IME 0x80000000
00206
00207 enum NCSIMMEvent {
00208 NCSN_IMM_IMEOPEN = 5678,
00209 NCSN_IMM_IMECHANGED,
00210 NCSN_IMM_IMECLOSE,
00211 };
00212
00213 struct _mIMManagerClass {
00214 mIMManagerClassHeader(mIMManager, mObject)
00215 };
00216 struct _mIMManager {
00217 mIMManagerHeader(mIMManager)
00218 };
00219
00220 MGNCS_EXPORT extern mIMManagerClass g_stmIMManagerCls;
00221
00222 #endif //_MGNCSENGINE_IME
00223
00227 #ifdef _MGNCSENGINE_DIGIT
00228
00229 #define NCS_DIGIT_MAX_FINDS 32
00230
00231 #define mDigitIteratorClassHeader(clss, super) \
00232 mIMIteratorClassHeader(clss, super) \
00233 PUBLIC mIMIterator* (*subIterator)(clss*);
00235 #define mDigitIteratorHeader(clss) \
00236 mIMIteratorHeader(clss) \
00237 int count; \
00238 int cur; \
00239 mIMIterator * sub_it; \
00240 const char** words; \
00241 int finds[NCS_DIGIT_MAX_FINDS][2];
00242
00243 DECLARE_CLASS(mDigitIterator, mIMIterator)
00244
00245 #define mDigitIMEClassHeader(clss, super) \
00246 mIMEClassHeader(clss, super)
00247
00248 #define mDigitIMEHeader(clss) \
00249 mIMEHeader(clss) \
00250 CHARSET_CONVERTER sub_conv;
00251
00252 DECLARE_CLASS(mDigitIME, mIME)
00253
00254
00255 #define mDigitEngineClassHeader(clss, super) \
00256 mIMEngineClassHeader(clss, super) \
00257 PROTECTED BOOL (*findRange)(clss*, \
00258 const char* input, \
00259 int start, int len, \
00260 int *pbegin, int *pend);
00261
00262 #define mDigitEngineHeader(clss) \
00263 mIMEngineHeader(clss) \
00264 mIMEngine* sub_engine;
00265
00266 DECLARE_CLASS(mDigitEngine, mIMEngine)
00267
00268 #endif //_MGNCSENGINE_DIGIT
00269
00270 #ifdef _MGNCSENGINE_DIGITPTI
00271
00272
00273 #define mDigitPtiEngineClassHeader(clss, super) \
00274 mDigitEngineClassHeader(clss, super)
00275
00276 #define mDigitPtiEngineHeader(clss) \
00277 mDigitEngineHeader(clss) \
00278 int case_type;
00279
00280 DECLARE_CLASS(mDigitPtiEngine, mDigitEngine)
00281
00282 #define mDigitPtiIteratorClassHeader(clss, super) \
00283 mDigitIteratorClassHeader(clss, super)
00284
00285 #define mDigitPtiIteratorHeader(clss) \
00286 mDigitIteratorHeader(clss) \
00287 char* letters; //only for signle letters, for example "a\0b\0\c\0"
00288
00289 DECLARE_CLASS(mDigitPtiIterator, mDigitIterator)
00290
00291 #endif //_MGNCSENGINE_DIGITPTI
00292
00294
00295
00296 #ifdef _MGNCSENGINE_DIGITPY
00297
00298 #define mDigitPyEngineClassHeader(clss, super) \
00299 mDigitEngineClassHeader(clss, super)
00300
00301 #define mDigitPyEngineHeader(clss) \
00302 mDigitEngineHeader(clss) \
00303 int py_count; \
00304 unsigned int * keys; \
00305 const char** pinyins;
00306
00307 DECLARE_CLASS(mDigitPyEngine, mDigitEngine)
00308
00309 #define mDigitPyIteratorClassHeader(clss, super) \
00310 mDigitIteratorClassHeader(clss, super)
00311
00312
00313 #define mDigitPyIteratorHeader(clss) \
00314 mDigitIteratorHeader(clss) \
00315 mIMEngine* py_engine;
00316
00317 DECLARE_CLASS(mDigitPyIterator, mDigitIterator)
00318
00319 #endif //_MGNCSENGINE_DIGITPY
00320
00322
00323 #ifdef _MGNCSENGINE_PTI
00324
00325 #define mPtiIteratorClassHeader(clss, super) \
00326 mIMIteratorClassHeader(clss, super)
00327
00328 #define mPtiIteratorHeader(clss) \
00329 mIMIteratorHeader(clss) \
00330 int cur; \
00331 const char** words; \
00332 int count; \
00333 int begin; \
00334 char upper_buffer[128]; \
00335 int char_type; \
00336 const char* lead_letter;
00337
00338 DECLARE_CLASS(mPtiIterator, mIMIterator)
00339
00340 #define mPtiEngineClassHeader(clss, super) \
00341 mIMEngineClassHeader(clss, super)
00342
00343 #define MGPTI_2ND_HASH_TABLE_SIZE 100
00344
00345 enum {
00346 MGPTI_LOWER = 100,
00347 MGPTI_UPPER
00348 };
00349
00350 typedef struct _MGPTI_2ND_HASH_BUCKET {
00351 int nr_words;
00352 int* word_indices;
00353 } MGPTI_2ND_HASH_BUCKET;
00354
00355 typedef struct _MGPTI_1ST_HASH_BUCKET {
00356 int indices [26];
00357 MGPTI_2ND_HASH_BUCKET* buckets;
00358 } MGPTI_1ST_HASH_BUCKET;
00359
00360
00361 #define mPtiEngineHeader(clss) \
00362 mIMEngineHeader(clss) \
00363 char **sorted_words; \
00364 int max_index; \
00365 MGPTI_1ST_HASH_BUCKET *buckets[26];
00366
00367
00368 DECLARE_CLASS(mPtiEngine, mIMEngine)
00369
00370 MGNCS_EXPORT BOOL mPtiEngine_findWordRange(mPtiEngine* self, int* pbegin, int* pend, const char* input, int start, int len);
00371
00372 #endif //_MGNCSENGINE_PTI
00373
00375
00376 #ifdef _MGNCSENGINE_PINYIN
00377
00378 #define PINYIN_MAGIC_NUMBER "CCEGB"
00379 #define PINYIN_ENAME_LENGTH 24
00380 #define PINYIN_CNAME_LENGTH 16
00381 #define PINYIN_WORD_LENGTH 16
00382 #define PINYIN_SELECT_KEY_LENGTH 16
00383 #define PINYIN_KEY_LENGTH 16
00384 #define PINYIN_SEL_LENGTH 58
00385
00386
00387 typedef struct {
00388 unsigned long key1;
00389 unsigned long key2;
00390 unsigned short word_offset_idx;
00391 unsigned short frequency;
00392 }NCS_PINYIN_ITEM;
00393
00394 typedef struct {
00395 unsigned int off_begin;
00396 unsigned int off_end;
00397 }NCS_PINYIN_PHOFFSET;
00398
00399 typedef struct {
00400 char magic_number[sizeof(PINYIN_MAGIC_NUMBER)];
00401 char ename[PINYIN_ENAME_LENGTH];
00402 char cname[PINYIN_CNAME_LENGTH];
00403 char selkey[PINYIN_SELECT_KEY_LENGTH];
00404
00405 char last_full;
00406 int totalKey;
00407 int maxPress;
00408 int maxDupSel;
00409 int totalChar;
00410
00411 unsigned char keyMap[128];
00412 unsigned char keyName[64];
00413 unsigned short keyIndex[64];
00414
00415 int wordNum;
00416 char* wordFile;
00417 char* assocFile;
00418 NCS_PINYIN_ITEM * item;
00419 }NCS_PINYIN_IME_TABLE;
00420
00421
00422 #define mPinyinEngineClassHeader(clss, super) \
00423 mIMEngineClassHeader(clss, super)
00424
00425 #define mPinyinEngineHeader(clss) \
00426 mIMEngineHeader(clss) \
00427 NCS_PINYIN_IME_TABLE * ime_table;
00428
00429 DECLARE_CLASS(mPinyinEngine, mIMEngine)
00430
00431 #define PINYIN_MAX_WORD 64
00432 #define PINYIN_MAX_WORDLEN 64
00433 #define PINYIN_INPUT_MAX 32
00434 typedef struct {
00435 union {
00436 char chars[4];
00437 const char* word;
00438 }word;
00439 int len;
00440 }NCS_PINYIN_WORD_INFO;
00441
00442
00443 #define mPinyinIteratorClassHeader(clss, super) \
00444 mIMIteratorClassHeader(clss, super)
00445
00446 #define mPinyinIteratorHeader(clss) \
00447 mIMIteratorHeader(clss) \
00448 int count; \
00449 int cur; \
00450 unsigned int charIndex[PINYIN_INPUT_MAX]; \
00451 unsigned int startKey; \
00452 unsigned int endKey; \
00453 unsigned long matched_key1; \
00454 unsigned long matched_key2; \
00455 NCS_PINYIN_WORD_INFO words[PINYIN_MAX_WORD]; \
00456 char word[PINYIN_MAX_WORDLEN]; \
00457 BOOL isAssociate;
00458
00459 DECLARE_CLASS(mPinyinIterator, mIMIterator)
00460
00461 #if MGUI_BYTEORDER == MGUI_BIG_ENDIAN
00462 #define ARCH_SWAP16(v16) ArchSwap16(v16)
00463 #define ARCH_SWAP32(v32) ArchSwap32(v32)
00464 #else
00465 #define ARCH_SWAP16(v16) (v16)
00466 #define ARCH_SWAP32(v32) (v32)
00467 #endif
00468
00469 #ifdef __cplusplus
00470 }
00471 #endif
00472
00473 #endif //_MGNCSENGINE_PINYIN
00474 #endif
00475
00476