Back to index

im-sdk  12.3.91
encode_draw.c
Go to the documentation of this file.
00001 /*
00002   Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004   Permission is hereby granted, free of charge, to any person obtaining a
00005   copy of this software and associated documentation files (the
00006   "Software"), to deal in the Software without restriction, including
00007   without limitation the rights to use, copy, modify, merge, publish,
00008   distribute, sublicense, and/or sell copies of the Software, and to
00009   permit persons to whom the Software is furnished to do so, subject to
00010   the following conditions: The above copyright notice and this
00011   permission notice shall be included in all copies or substantial
00012   portions of the Software.
00013 
00014 
00015   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018   IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019   FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020   CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021   THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022   ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025   Except as contained in this notice, the names of The Open Group and/or
00026   Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027   promote the sale, use or other dealings in this Software without prior
00028   written authorization from The Open Group and/or Sun Microsystems,
00029   Inc., as applicable.
00030 
00031 
00032   X Window System is a trademark of The Open Group
00033 
00034   OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035   logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036   Group. All other trademarks and registered trademarks mentioned herein
00037   are the property of their respective owners. No right, title or
00038   interest in or to any trademark, service mark, logo or trade name of
00039   Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #ifdef HAVE_CONFIG_H
00043 #include <config.h>
00044 #endif
00045 #ifdef HAVE_STRING_H
00046 #include <string.h>
00047 #endif
00048 
00049 #include "SunIM.h"
00050 #include "unit_input.h"
00051 #include "encode.h"
00052 #include "logf.h"
00053 #include "encode.h"
00054 #include "iml.h"
00055 
00056 int encode_to_unicode(int encode, unsigned char *from, int from_len,
00057                     UTFCHAR *to, int to_len)
00058 {
00059     int to_left, ret;
00060     char *to_ptr;
00061 
00062     log_f("encode_to_unicode: from:%s, encode:%d\n", from, encode);
00063     to_left = to_len;
00064     ret = Convert_Native_To_UTF16(encode, from, from_len, (char **)&to, (size_t *)&to_left);
00065     log_f("encode_to_unicode: return:%d, to_left:%d\n", ret, to_left);
00066     if (ret == -1) {
00067        to[0] = (UTFCHAR)0;
00068     } else {
00069        if (to_left > 2) {
00070            to_ptr = (char *)to;
00071            to_ptr[to_len - to_left] = 0;
00072            to_ptr[to_len - to_left +1] = 0;
00073        }
00074     }
00075     return(ret);
00076 }
00077 
00078 void encode_draw_preedit(iml_session_t *s, int encode, unsigned char *preedit_buf, int caret)
00079 {
00080     static UTFCHAR Preedit_Buffer[MAX_PREEDIT_CHAR_NUM * 2];
00081     int preedit_len;
00082        
00083     preedit_len = strlen((char *)preedit_buf);
00084     if (preedit_len <=0)
00085        iml_preedit_enddraw(s);
00086 
00087     encode_to_unicode(encode, preedit_buf, preedit_len, Preedit_Buffer, MAX_PREEDIT_CHAR_NUM * 2);
00088     iml_preedit_draw(s, Preedit_Buffer, caret);
00089 }
00090 
00091 void encode_draw_status(iml_session_t *s, int encode, unsigned char *status_buf)
00092 {
00093     static UTFCHAR Status_Buffer[MAX_STATUS_CHAR_NUM * 2];
00094     int status_len;
00095 
00096     status_len = strlen((char *)status_buf);
00097     if (status_len <= 0) {
00098        /* take care of the off string for IIIMF_STATUS_NO_STATUS_TEXT */
00099        Status_Buffer[0] = 0;
00100     } else {
00101        encode_to_unicode(encode, status_buf, status_len, Status_Buffer, MAX_STATUS_CHAR_NUM * 2);
00102     }
00103 
00104     iml_status_draw(s, Status_Buffer);
00105 }
00106 
00107 void encode_draw_candidates(iml_session_t *s, int encode, unsigned char **lookup_buf, int lookup_num, int lookup_label_type)
00108 {
00109     static UTFCHAR *Lookup_Buffer[MAX_CANDIDATES_NUM];
00110     static UTFCHAR Lookup_Items_Buffer[MAX_CANDIDATES_NUM][MAX_CANDIDATE_CHAR_NUM * 2];
00111     static int bLookupInited = 0;
00112 
00113     int i, lookup_len;
00114 
00115     if (bLookupInited == 0) {
00116        bLookupInited = 1;
00117        for (i=0; i<MAX_CANDIDATES_NUM; i++)
00118            Lookup_Buffer[i] = Lookup_Items_Buffer[i];
00119     }
00120 
00121     if (lookup_num <= 0)
00122        iml_lookup_enddraw(s);
00123 
00124     /* Notes that Lookup_Buffer has point to Lookup_Items_Buffer */
00125     for (i=0; i<lookup_num; i++) {
00126        lookup_len = strlen((char *)lookup_buf[i]);
00127        encode_to_unicode(encode, lookup_buf[i], lookup_len, Lookup_Items_Buffer[i], MAX_CANDIDATE_CHAR_NUM * 2);
00128     }
00129 
00130     iml_lookup_draw(s, Lookup_Buffer, lookup_num, lookup_label_type);
00131 }
00132 
00133 void encode_commit(iml_session_t *s, int encode, unsigned char *commit_buf,
00134                  int commit_len)
00135 {
00136     static UTFCHAR Commit_Buffer[MAX_COMMIT_CHAR_NUM * 2];
00137     if (commit_len <= 0)
00138        return;
00139     encode_to_unicode(encode, commit_buf, commit_len, Commit_Buffer, MAX_COMMIT_CHAR_NUM * 2);
00140     iml_commit(s, Commit_Buffer);
00141 }
00142 
00143 /* Local Variables: */
00144 /* c-file-style: "iiim-project" */
00145 /* End: */