Back to index

im-sdk  12.3.91
encode_draw.c
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <strings.h>
00006 #include "SunIM.h"
00007 #include "kole.h"
00008 #include "koinput.h"
00009 #include "encode.h"
00010 #include "iml.h"
00011 #include "kolelog.h"
00012 
00013 int encode_to_unicode(int encode, unsigned char *from, int from_len,
00014                               UTFCHAR *to, int to_len)
00015 {
00016        int to_left, ret;
00017        char *to_ptr;
00018 
00019        KOLE_LOG (LOGDEST_STDOUT,
00020                 "encode_to_unicode: from:%s, encode:%d\n", from, encode);
00021        to_left = to_len;
00022        ret = Convert_Native_To_UTF16(encode, (char *)from, from_len, (char **)&to, (size_t *)&to_left);
00023        KOLE_LOG (LOGDEST_STDOUT,
00024                 "encode_to_unicode: return:%d, to_left:%d\n", ret, to_left);
00025        if (ret == -1) {
00026               to[0] = (UTFCHAR)0;
00027        } else {
00028               if (to_left > 2) {
00029                      to_ptr = (char *)to;
00030                      to_ptr[to_len - to_left] = 0;
00031                      to_ptr[to_len - to_left +1] = 0;
00032               }
00033        }
00034        return(ret);
00035 }
00036 
00037 void encode_draw_preedit(iml_session_t *s, int encode, unsigned char *preedit_buf, int caret)
00038 {
00039        static UTFCHAR Preedit_Buffer[MAX_PREEDIT_CHAR_NUM * 2];
00040        int preedit_len, caret_pos;
00041        
00042        preedit_len = strlen((char *)preedit_buf);
00043        if (preedit_len <=0)
00044               iml_preedit_enddraw(s);
00045        /*
00046         The value of encode is from IMEBuffer->encode member, which is
00047         default encoding the language engine is using internally
00048        */
00049        encode_to_unicode(encode, preedit_buf, preedit_len, Preedit_Buffer, MAX_PREEDIT_CHAR_NUM * 2);
00050        iml_preedit_draw(s, Preedit_Buffer, caret);
00051 }
00052 
00053 void encode_draw_status(iml_session_t *s, int encode, unsigned char *status_buf)
00054 {
00055        static UTFCHAR Status_Buffer[MAX_STATUS_CHAR_NUM * 2];
00056        int status_len;
00057        int i, len;
00058 
00059        status_len = strlen((char *)status_buf);
00060        if (status_len <= 0)
00061               return;
00062 
00063        encode_to_unicode(encode, status_buf, status_len, Status_Buffer, MAX_STATUS_CHAR_NUM * 2);
00064        iml_status_draw(s, Status_Buffer);
00065 }
00066 
00067 void encode_draw_candidates(iml_session_t *s, int encode, unsigned char **lookup_buf, int lookup_num, int lookup_label_type)
00068 {
00069        static UTFCHAR *Lookup_Buffer[MAX_CANDIDATES_NUM];
00070        static UTFCHAR Lookup_Items_Buffer[MAX_CANDIDATES_NUM][MAX_CANDIDATE_CHAR_NUM * 2];
00071        static int bLookupInited = 0;
00072 
00073        int i, lookup_len;
00074 
00075        if (bLookupInited == 0) {
00076               bLookupInited = 1;
00077               for (i=0; i<MAX_CANDIDATES_NUM; i++)
00078                      Lookup_Buffer[i] = Lookup_Items_Buffer[i];
00079        }
00080 
00081        if (lookup_num <= 0)
00082               iml_lookup_enddraw(s);
00083 
00084        /* Notes that Lookup_Buffer has point to Lookup_Items_Buffer */
00085        for (i=0; i<lookup_num; i++) {
00086               lookup_len = strlen((char *)lookup_buf[i]);
00087               encode_to_unicode(encode, lookup_buf[i], lookup_len, Lookup_Items_Buffer[i], MAX_CANDIDATE_CHAR_NUM * 2);
00088        }
00089 
00090        iml_lookup_draw(s, Lookup_Buffer, lookup_num, lookup_label_type);
00091 }
00092 
00093 void encode_commit(iml_session_t *s, int encode, unsigned char *commit_buf)
00094 {
00095        static UTFCHAR Commit_Buffer[MAX_COMMIT_CHAR_NUM * 2];
00096        int commit_len;
00097 
00098        commit_len = strlen((char *)commit_buf);
00099        if (commit_len <= 0)
00100               return;
00101 
00102        encode_to_unicode(encode, commit_buf, commit_len, Commit_Buffer, MAX_COMMIT_CHAR_NUM * 2);
00103        iml_commit(s, Commit_Buffer);
00104 }
00105